]> git.proxmox.com Git - qemu.git/blob - rules.mak
fe0c881a3a091741032b71e31c3218cba84c167a
[qemu.git] / rules.mak
1
2 # Don't use implicit rules or variables
3 # we have explicit rules for everything
4 MAKEFLAGS += -rR
5
6 # Files with this suffixes are final, don't try to generate them
7 # using implicit rules
8 %.d:
9 %.h:
10 %.c:
11 %.m:
12 %.mak:
13
14 # Flags for dependency generation
15 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
16
17 # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
18 QEMU_CFLAGS += -I$(<D) -I$(@D)
19
20 %.o: %.c
21 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
22
23 ifeq ($(LIBTOOL),)
24 %.lo: %.c
25 @echo "missing libtool. please install and rerun configure"; exit 1
26 else
27 %.lo: %.c
28 $(call quiet-command,$(LIBTOOL) --mode=compile --quiet --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
29 endif
30
31 %.asm: %.S
32 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
33
34 %.o: %.asm
35 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
36
37 %.o: %.m
38 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
39
40 LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(LIBS)," LINK $(TARGET_DIR)$@")
41
42 %$(EXESUF): %.o
43 $(call LINK,$^)
44
45 %.a:
46 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
47
48 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
49
50 # cc-option
51 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
52
53 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
54 >/dev/null 2>&1 && echo OK), $2, $3)
55
56 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh
57 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
58
59 # find-in-path
60 # Usage: $(call find-in-path, prog)
61 # Looks in the PATH if the argument contains no slash, else only considers one
62 # specific directory. Returns an # empty string if the program doesn't exist
63 # there.
64 find-in-path = $(if $(find-string /, $1), \
65 $(wildcard $1), \
66 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
67
68 # Generate files with tracetool
69 TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
70
71 # Generate timestamp files for .h include files
72
73 %.h: %.h-timestamp
74 @test -f $@ || cp $< $@
75
76 %.h-timestamp: %.mak
77 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)$*.h")
78 @cmp $@ $*.h >/dev/null 2>&1 || cp $@ $*.h
79
80 # will delete the target of a rule if commands exit with a nonzero exit status
81 .DELETE_ON_ERROR:
82
83 # magic to descend into other directories
84
85 obj := .
86 old-nested-dirs :=
87
88 define push-var
89 $(eval save-$2-$1 = $(value $1))
90 $(eval $1 :=)
91 endef
92
93 define pop-var
94 $(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
95 $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
96 $(eval save-$2-$1 :=)
97 endef
98
99 define unnest-dir
100 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
101 $(eval obj := $(obj)/$1)
102 $(eval include $(SRC_PATH)/$1/Makefile.objs)
103 $(eval obj := $(patsubst %/$1,%,$(obj)))
104 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
105 endef
106
107 define unnest-vars-1
108 $(eval nested-dirs := $(filter-out \
109 $(old-nested-dirs), \
110 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
111 $(if $(nested-dirs),
112 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
113 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
114 $(call unnest-vars-1))
115 endef
116
117 define unnest-vars
118 $(call unnest-vars-1)
119 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
120 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
121 $(foreach var,$(nested-vars), $(eval \
122 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
123 endef