]>
Commit | Line | Data |
---|---|---|
17759187 | 1 | |
5ab28867 JQ |
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: | |
83f73fce | 11 | %.cpp: |
5ab28867 JQ |
12 | %.m: |
13 | %.mak: | |
14 | ||
83f73fce TS |
15 | # Flags for C++ compilation |
16 | QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS)) | |
17 | ||
7ebf54bc | 18 | # Flags for dependency generation |
a71cd2a5 | 19 | QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d |
02d5467e | 20 | |
9d9199a0 | 21 | # Same as -I$(SRC_PATH) -I., but for the nested source/object directories |
7e7da8e3 | 22 | QEMU_INCLUDES += -I$(<D) -I$(@D) |
9d9199a0 | 23 | |
0e8c9214 | 24 | %.o: %.c |
76dc3cf8 | 25 | $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@") |
6821cdc7 PB |
26 | %.o: %.rc |
27 | $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@") | |
17759187 | 28 | |
44dc0ca3 | 29 | ifeq ($(LIBTOOL),) |
21655882 | 30 | LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ |
bf0842b7 | 31 | $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \ |
21655882 | 32 | $(LIBS)," LINK $(TARGET_DIR)$@") |
44dc0ca3 | 33 | else |
f141ccfa | 34 | LIBTOOL += $(if $(V),,--quiet) |
44dc0ca3 | 35 | %.lo: %.c |
f141ccfa | 36 | $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@") |
6821cdc7 PB |
37 | %.lo: %.rc |
38 | $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@") | |
2c13ec50 PB |
39 | %.lo: %.dtrace |
40 | $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@") | |
41 | ||
21655882 PB |
42 | LINK = $(call quiet-command,\ |
43 | $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \ | |
44 | )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ | |
5354e4d2 MAL |
45 | $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \ |
46 | $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \ | |
37746c5e | 47 | $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \ |
21655882 | 48 | $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@") |
44dc0ca3 AL |
49 | endif |
50 | ||
3dd46c78 BS |
51 | %.asm: %.S |
52 | $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@") | |
53 | ||
54 | %.o: %.asm | |
55 | $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@") | |
17759187 | 56 | |
83f73fce TS |
57 | %.o: %.cpp |
58 | $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@") | |
59 | ||
17759187 | 60 | %.o: %.m |
3c4a4d0d | 61 | $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@") |
17759187 | 62 | |
2c13ec50 PB |
63 | %.o: %.dtrace |
64 | $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@") | |
65 | ||
3aa892d7 | 66 | %$(EXESUF): %.o |
0bfe3ca5 | 67 | $(call LINK,$^) |
4f188f88 | 68 | |
93a0dba7 | 69 | %.a: |
28c699a2 | 70 | $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@") |
93a0dba7 | 71 | |
28c699a2 | 72 | quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1)) |
70071e17 JQ |
73 | |
74 | # cc-option | |
8a2e6ab5 | 75 | # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0) |
70071e17 | 76 | |
fc3baad7 TM |
77 | cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \ |
78 | >/dev/null 2>&1 && echo OK), $2, $3) | |
1215c6e7 | 79 | |
83f73fce | 80 | VPATH_SUFFIXES = %.c %.h %.S %.cpp %.m %.mak %.texi %.sh %.rc |
288e7bcc | 81 | set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1))) |
076d2471 | 82 | |
2b2e59e6 PB |
83 | # find-in-path |
84 | # Usage: $(call find-in-path, prog) | |
85 | # Looks in the PATH if the argument contains no slash, else only considers one | |
86 | # specific directory. Returns an # empty string if the program doesn't exist | |
87 | # there. | |
88 | find-in-path = $(if $(find-string /, $1), \ | |
89 | $(wildcard $1), \ | |
90 | $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH))))) | |
91 | ||
837a2e26 PM |
92 | # Logical functions (for operating on y/n values like CONFIG_FOO vars) |
93 | # Inputs to these must be either "y" (true) or "n" or "" (both false) | |
94 | # Output is always either "y" or "n". | |
95 | # Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR)) | |
96 | # Logical NOT | |
97 | lnot = $(if $(subst n,,$1),n,y) | |
98 | # Logical AND | |
99 | land = $(if $(findstring yy,$1$2),y,n) | |
100 | # Logical OR | |
101 | lor = $(if $(findstring y,$1$2),y,n) | |
102 | # Logical XOR (note that this is the inverse of leqv) | |
103 | lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y) | |
104 | # Logical equivalence (note that leqv "","n" is true) | |
105 | leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n) | |
106 | # Logical if: like make's $(if) but with an leqv-like test | |
107 | lif = $(if $(subst n,,$1),$2,$3) | |
108 | ||
9ef622e3 PM |
109 | # String testing functions: inputs to these can be any string; |
110 | # the output is always either "y" or "n". Leading and trailing whitespace | |
111 | # is ignored when comparing strings. | |
112 | # String equality | |
113 | eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y) | |
114 | # String inequality | |
115 | ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n) | |
116 | # Emptiness/non-emptiness tests: | |
117 | isempty = $(if $1,n,y) | |
118 | notempty = $(if $1,y,n) | |
119 | ||
c0424934 LV |
120 | # Generate files with tracetool |
121 | TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py | |
122 | ||
1215c6e7 JQ |
123 | # Generate timestamp files for .h include files |
124 | ||
4b25966a MT |
125 | config-%.h: config-%.h-timestamp |
126 | @cmp $< $@ >/dev/null 2>&1 || cp $< $@ | |
1215c6e7 | 127 | |
4b25966a MT |
128 | config-%.h-timestamp: config-%.mak |
129 | $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h") | |
7dbbbb0c | 130 | |
7586317b MT |
131 | .PHONY: clean-timestamp |
132 | clean-timestamp: | |
133 | rm -f *.timestamp | |
134 | clean: clean-timestamp | |
135 | ||
7dbbbb0c MT |
136 | # will delete the target of a rule if commands exit with a nonzero exit status |
137 | .DELETE_ON_ERROR: | |
e05804ee PB |
138 | |
139 | # magic to descend into other directories | |
140 | ||
141 | obj := . | |
142 | old-nested-dirs := | |
143 | ||
144 | define push-var | |
145 | $(eval save-$2-$1 = $(value $1)) | |
146 | $(eval $1 :=) | |
147 | endef | |
148 | ||
149 | define pop-var | |
150 | $(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1)))) | |
151 | $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1)) | |
152 | $(eval save-$2-$1 :=) | |
153 | endef | |
154 | ||
155 | define unnest-dir | |
156 | $(foreach var,$(nested-vars),$(call push-var,$(var),$1/)) | |
157 | $(eval obj := $(obj)/$1) | |
158 | $(eval include $(SRC_PATH)/$1/Makefile.objs) | |
159 | $(eval obj := $(patsubst %/$1,%,$(obj))) | |
160 | $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/)) | |
161 | endef | |
162 | ||
163 | define unnest-vars-1 | |
164 | $(eval nested-dirs := $(filter-out \ | |
165 | $(old-nested-dirs), \ | |
166 | $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var))))))) | |
167 | $(if $(nested-dirs), | |
168 | $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir)))) | |
169 | $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs)) | |
170 | $(call unnest-vars-1)) | |
171 | endef | |
172 | ||
173 | define unnest-vars | |
174 | $(call unnest-vars-1) | |
175 | $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var))))) | |
2dee8d54 | 176 | $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var)))))) |
1435ddb8 PB |
177 | $(foreach var,$(nested-vars), $(eval \ |
178 | -include $(addsuffix *.d, $(sort $(dir $($(var))))))) | |
e05804ee | 179 | endef |