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