]> git.proxmox.com Git - mirror_qemu.git/blame - rules.mak
TCG: Fix tcg_gen_extr_i64_tl for 32bit
[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
17969268 25maybe-add = $(filter-out $1, $2) $1
6295b98d
FZ
26extract-libs = $(strip $(sort $(foreach o,$1,$($o-libs))) \
27 $(foreach o,$(call expand-objs,$1),$($o-libs)))
17969268
FZ
28expand-objs = $(strip $(sort $(filter %.o,$1)) \
29 $(foreach o,$(filter %.mo,$1),$($o-objs)) \
30 $(filter-out %.o %.mo,$1))
5c0d52bc 31
0e8c9214 32%.o: %.c
5c0d52bc 33 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CC $(TARGET_DIR)$@")
6821cdc7
PB
34%.o: %.rc
35 $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
17759187 36
3144f78b
PM
37# If we have a CXX we might have some C++ objects, in which case we
38# must link with the C++ compiler, not the plain C compiler.
39LINKPROG = $(or $(CXX),$(CC))
40
44dc0ca3 41ifeq ($(LIBTOOL),)
3144f78b 42LINK = $(call quiet-command,$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
17969268
FZ
43 $(call expand-objs,$1) $(version-obj-y) \
44 $(call extract-libs,$1) $(LIBS)," LINK $(TARGET_DIR)$@")
44dc0ca3 45else
f141ccfa 46LIBTOOL += $(if $(V),,--quiet)
44dc0ca3 47%.lo: %.c
0db564ee 48 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($*.o-cflags) -c -o $@ $<," lt CC $@")
6821cdc7
PB
49%.lo: %.rc
50 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
2c13ec50
PB
51%.lo: %.dtrace
52 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
53
21655882 54LINK = $(call quiet-command,\
17969268 55 $(if $(filter %.lo %.la,$1),$(LIBTOOL) --mode=link --tag=CC \
3144f78b 56 )$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
17969268
FZ
57 $(call expand-objs,$1) \
58 $(if $(filter %.lo %.la,$1),$(version-lobj-y),$(version-obj-y)) \
59 $(if $(filter %.lo %.la,$1),$(LIBTOOLFLAGS)) \
0db564ee 60 $(call extract-libs,$(1:.lo=.o)) $(LIBS),$(if $(filter %.lo %.la,$1),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
44dc0ca3
AL
61endif
62
3dd46c78
BS
63%.asm: %.S
64 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
65
66%.o: %.asm
67 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
17759187 68
c3dc9fd5 69%.o: %.cc
0db564ee 70 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CXX $(TARGET_DIR)$@")
c3dc9fd5 71
83f73fce 72%.o: %.cpp
0db564ee 73 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CXX $(TARGET_DIR)$@")
83f73fce 74
17759187 75%.o: %.m
0db564ee 76 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
17759187 77
2c13ec50
PB
78%.o: %.dtrace
79 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
80
17969268
FZ
81DSO_CFLAGS := -fPIC -DBUILD_DSO
82%$(DSOSUF): LDFLAGS += $(LDFLAGS_SHARED)
83%$(DSOSUF): %.mo libqemustub.a
84 $(call LINK,$^)
e26110cf
FZ
85 @# Copy to build root so modules can be loaded when program started without install
86 $(if $(findstring /,$@),$(call quiet-command,cp $@ $(subst /,-,$@), " CP $(subst /,-,$@)"))
17969268
FZ
87
88.PHONY: modules
89modules:
90
3aa892d7 91%$(EXESUF): %.o
0bfe3ca5 92 $(call LINK,$^)
4f188f88 93
93a0dba7 94%.a:
28c699a2 95 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
93a0dba7 96
28c699a2 97quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
70071e17
JQ
98
99# cc-option
8a2e6ab5 100# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
70071e17 101
fc3baad7
TM
102cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
103 >/dev/null 2>&1 && echo OK), $2, $3)
1215c6e7 104
c3dc9fd5 105VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc
288e7bcc 106set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
076d2471 107
2b2e59e6
PB
108# find-in-path
109# Usage: $(call find-in-path, prog)
110# Looks in the PATH if the argument contains no slash, else only considers one
111# specific directory. Returns an # empty string if the program doesn't exist
112# there.
113find-in-path = $(if $(find-string /, $1), \
114 $(wildcard $1), \
115 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
116
837a2e26
PM
117# Logical functions (for operating on y/n values like CONFIG_FOO vars)
118# Inputs to these must be either "y" (true) or "n" or "" (both false)
119# Output is always either "y" or "n".
120# Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
121# Logical NOT
122lnot = $(if $(subst n,,$1),n,y)
123# Logical AND
124land = $(if $(findstring yy,$1$2),y,n)
125# Logical OR
126lor = $(if $(findstring y,$1$2),y,n)
127# Logical XOR (note that this is the inverse of leqv)
128lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y)
129# Logical equivalence (note that leqv "","n" is true)
130leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n)
131# Logical if: like make's $(if) but with an leqv-like test
132lif = $(if $(subst n,,$1),$2,$3)
133
9ef622e3
PM
134# String testing functions: inputs to these can be any string;
135# the output is always either "y" or "n". Leading and trailing whitespace
136# is ignored when comparing strings.
137# String equality
138eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
139# String inequality
140ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n)
141# Emptiness/non-emptiness tests:
142isempty = $(if $1,n,y)
143notempty = $(if $1,y,n)
144
c0424934
LV
145# Generate files with tracetool
146TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
147
1215c6e7
JQ
148# Generate timestamp files for .h include files
149
4b25966a
MT
150config-%.h: config-%.h-timestamp
151 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
1215c6e7 152
4b25966a
MT
153config-%.h-timestamp: config-%.mak
154 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
7dbbbb0c 155
7586317b
MT
156.PHONY: clean-timestamp
157clean-timestamp:
158 rm -f *.timestamp
159clean: clean-timestamp
160
7dbbbb0c
MT
161# will delete the target of a rule if commands exit with a nonzero exit status
162.DELETE_ON_ERROR:
e05804ee
PB
163
164# magic to descend into other directories
165
e05804ee
PB
166define push-var
167$(eval save-$2-$1 = $(value $1))
168$(eval $1 :=)
169endef
170
171define pop-var
172$(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
173$(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
174$(eval save-$2-$1 :=)
175endef
176
5c0d52bc 177define fix-obj-vars
2a8e6c7a 178$(if $2, $(foreach v,$($1), \
5c0d52bc 179 $(if $($v-cflags), \
2a8e6c7a 180 $(eval $2/$v-cflags := $($v-cflags)) \
5c0d52bc
FZ
181 $(eval $v-cflags := )) \
182 $(if $($v-libs), \
2a8e6c7a 183 $(eval $2/$v-libs := $($v-libs)) \
17969268
FZ
184 $(eval $v-libs := )) \
185 $(if $($v-objs), \
2a8e6c7a
PB
186 $(eval $2/$v-objs := $(addprefix $2/,$($v-objs))) \
187 $(eval $v-objs := ))))
5c0d52bc
FZ
188endef
189
e05804ee
PB
190define unnest-dir
191$(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
ba1183da
FZ
192$(eval obj-parent-$1 := $(obj))
193$(eval obj := $(if $(obj),$(obj)/$1,$1))
e05804ee 194$(eval include $(SRC_PATH)/$1/Makefile.objs)
2a8e6c7a 195$(foreach v,$(nested-vars),$(call fix-obj-vars,$v,$(obj)))
ba1183da
FZ
196$(eval obj := $(obj-parent-$1))
197$(eval obj-parent-$1 := )
e05804ee
PB
198$(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
199endef
200
201define unnest-vars-1
202$(eval nested-dirs := $(filter-out \
203 $(old-nested-dirs), \
204 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
205$(if $(nested-dirs),
206 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
207 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
208 $(call unnest-vars-1))
209endef
210
17969268
FZ
211define process-modules
212$(foreach o,$(filter %.o,$($1)),
213 $(eval $(patsubst %.o,%.mo,$o): $o) \
214 $(eval $(patsubst %.o,%.mo,$o)-objs := $o))
215$(foreach o,$(filter-out $(modules-m), $(patsubst %.o,%.mo,$($1))), \
e26110cf 216 $(eval $o-objs += module-common.o)
17969268
FZ
217 $(eval $o: $($o-objs))
218 $(eval modules-objs-m += $($o-objs))
219 $(eval modules-m += $o)
220 $(eval $o:; $$(call quiet-command,touch $$@," GEN $$(TARGET_DIR)$$@"))
221 $(if $(CONFIG_MODULES),$(eval modules: $(patsubst %.mo,%$(DSOSUF),$o)))) \
222$(eval modules-objs-m := $(sort $(modules-objs-m)))
223$(foreach o,$(modules-objs-m), \
224 $(if $(CONFIG_MODULES),$(eval $o-cflags := $(call maybe-add, $(DSO_CFLAGS), $($o-cflags)))))
225$(eval $(patsubst %-m,%-$(call lnot,$(CONFIG_MODULES)),$1) += $($1))
226endef
227
e05804ee 228define unnest-vars
ba1183da
FZ
229$(eval obj := $1)
230$(eval nested-vars := $2)
2a8e6c7a 231$(foreach v,$(nested-vars),$(call fix-obj-vars,$v,$(obj)))
ba1183da 232$(eval old-nested-dirs := )
e05804ee 233$(call unnest-vars-1)
ba1183da
FZ
234$(if $1,$(foreach v,$(nested-vars),$(eval \
235 $v := $(addprefix $1/,$($v)))))
e05804ee 236$(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
2dee8d54 237$(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
1435ddb8
PB
238$(foreach var,$(nested-vars), $(eval \
239 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
17969268
FZ
240$(foreach v,$(filter %-m,$(nested-vars)), \
241 $(call process-modules,$v))
e05804ee 242endef