]> git.proxmox.com Git - mirror_qemu.git/blame - rules.mak
tcg: mark tcg_out* and tcg_patch* with attribute 'unused'
[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
f2770151 25extract-libs = $(strip $(foreach o,$1,$($o-libs)))
17969268
FZ
26expand-objs = $(strip $(sort $(filter %.o,$1)) \
27 $(foreach o,$(filter %.mo,$1),$($o-objs)) \
28 $(filter-out %.o %.mo,$1))
5c0d52bc 29
0e8c9214 30%.o: %.c
5c0d52bc 31 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CC $(TARGET_DIR)$@")
6821cdc7
PB
32%.o: %.rc
33 $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
17759187 34
3144f78b
PM
35# If we have a CXX we might have some C++ objects, in which case we
36# must link with the C++ compiler, not the plain C compiler.
37LINKPROG = $(or $(CXX),$(CC))
38
44dc0ca3 39ifeq ($(LIBTOOL),)
1c33ac57
FZ
40LINK = $(call quiet-command, $(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
41 $1 $(version-obj-y) $(call extract-libs,$1) $(LIBS)," LINK $(TARGET_DIR)$@")
44dc0ca3 42else
f141ccfa 43LIBTOOL += $(if $(V),,--quiet)
44dc0ca3 44%.lo: %.c
0db564ee 45 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($*.o-cflags) -c -o $@ $<," lt CC $@")
6821cdc7
PB
46%.lo: %.rc
47 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
2c13ec50
PB
48%.lo: %.dtrace
49 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
50
21655882 51LINK = $(call quiet-command,\
17969268 52 $(if $(filter %.lo %.la,$1),$(LIBTOOL) --mode=link --tag=CC \
1c33ac57 53 )$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $1 \
17969268
FZ
54 $(if $(filter %.lo %.la,$1),$(version-lobj-y),$(version-obj-y)) \
55 $(if $(filter %.lo %.la,$1),$(LIBTOOLFLAGS)) \
0db564ee 56 $(call extract-libs,$(1:.lo=.o)) $(LIBS),$(if $(filter %.lo %.la,$1),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
44dc0ca3
AL
57endif
58
3dd46c78
BS
59%.asm: %.S
60 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
61
62%.o: %.asm
63 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
17759187 64
c3dc9fd5 65%.o: %.cc
0db564ee 66 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CXX $(TARGET_DIR)$@")
c3dc9fd5 67
83f73fce 68%.o: %.cpp
0db564ee 69 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CXX $(TARGET_DIR)$@")
83f73fce 70
17759187 71%.o: %.m
0db564ee 72 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
17759187 73
2c13ec50
PB
74%.o: %.dtrace
75 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
76
1c33ac57 77%$(DSOSUF): CFLAGS += -fPIC -DBUILD_DSO
17969268 78%$(DSOSUF): LDFLAGS += $(LDFLAGS_SHARED)
1c33ac57 79%$(DSOSUF):
17969268 80 $(call LINK,$^)
e26110cf
FZ
81 @# Copy to build root so modules can be loaded when program started without install
82 $(if $(findstring /,$@),$(call quiet-command,cp $@ $(subst /,-,$@), " CP $(subst /,-,$@)"))
17969268
FZ
83
84.PHONY: modules
85modules:
86
3aa892d7 87%$(EXESUF): %.o
0bfe3ca5 88 $(call LINK,$^)
4f188f88 89
93a0dba7 90%.a:
28c699a2 91 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
93a0dba7 92
28c699a2 93quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
70071e17
JQ
94
95# cc-option
8a2e6ab5 96# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
70071e17 97
fc3baad7
TM
98cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
99 >/dev/null 2>&1 && echo OK), $2, $3)
1215c6e7 100
c3dc9fd5 101VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc
288e7bcc 102set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
076d2471 103
2b2e59e6
PB
104# find-in-path
105# Usage: $(call find-in-path, prog)
106# Looks in the PATH if the argument contains no slash, else only considers one
107# specific directory. Returns an # empty string if the program doesn't exist
108# there.
109find-in-path = $(if $(find-string /, $1), \
110 $(wildcard $1), \
111 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
112
837a2e26
PM
113# Logical functions (for operating on y/n values like CONFIG_FOO vars)
114# Inputs to these must be either "y" (true) or "n" or "" (both false)
115# Output is always either "y" or "n".
116# Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
117# Logical NOT
118lnot = $(if $(subst n,,$1),n,y)
119# Logical AND
120land = $(if $(findstring yy,$1$2),y,n)
121# Logical OR
122lor = $(if $(findstring y,$1$2),y,n)
123# Logical XOR (note that this is the inverse of leqv)
124lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y)
125# Logical equivalence (note that leqv "","n" is true)
126leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n)
127# Logical if: like make's $(if) but with an leqv-like test
128lif = $(if $(subst n,,$1),$2,$3)
129
9ef622e3
PM
130# String testing functions: inputs to these can be any string;
131# the output is always either "y" or "n". Leading and trailing whitespace
132# is ignored when comparing strings.
133# String equality
134eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
135# String inequality
136ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n)
137# Emptiness/non-emptiness tests:
138isempty = $(if $1,n,y)
139notempty = $(if $1,y,n)
140
c0424934
LV
141# Generate files with tracetool
142TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
143
1215c6e7
JQ
144# Generate timestamp files for .h include files
145
4b25966a
MT
146config-%.h: config-%.h-timestamp
147 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
1215c6e7 148
4b25966a
MT
149config-%.h-timestamp: config-%.mak
150 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
7dbbbb0c 151
7586317b
MT
152.PHONY: clean-timestamp
153clean-timestamp:
154 rm -f *.timestamp
155clean: clean-timestamp
156
7dbbbb0c
MT
157# will delete the target of a rule if commands exit with a nonzero exit status
158.DELETE_ON_ERROR:
e05804ee 159
1c33ac57
FZ
160# save-vars
161# Usage: $(call save-vars, vars)
162# Save each variable $v in $vars as save-vars-$v, save their object's
163# variables, then clear $v.
164define save-vars
165 $(foreach v,$1,
166 $(eval save-vars-$v := $(value $v))
167 $(foreach o,$($v),
168 $(foreach k,cflags libs objs,
169 $(if $($o-$k),
170 $(eval save-vars-$o-$k := $($o-$k))
171 $(eval $o-$k := ))))
172 $(eval $v := ))
5c0d52bc
FZ
173endef
174
1c33ac57
FZ
175# load-vars
176# Usage: $(call load-vars, vars, add_var)
177# Load the saved value for each variable in @vars, and the per object
178# variables.
179# Append @add_var's current value to the loaded value.
180define load-vars
181 $(eval $2-new-value := $(value $2))
182 $(foreach v,$1,
183 $(eval $v := $(value save-vars-$v))
184 $(foreach o,$($v),
185 $(foreach k,cflags libs objs,
186 $(if $(save-vars-$o-$k),
187 $(eval $o-$k := $(save-vars-$o-$k))
188 $(eval save-vars-$o-$k := ))))
189 $(eval save-vars-$v := ))
190 $(eval $2 := $(value $2) $($2-new-value))
e05804ee
PB
191endef
192
1c33ac57
FZ
193# fix-paths
194# Usage: $(call fix-paths, obj_path, src_path, vars)
195# Add prefix @obj_path to all objects in @vars, and add prefix @src_path to all
196# directories in @vars.
197define fix-paths
198 $(foreach v,$3,
199 $(foreach o,$($v),
200 $(if $($o-libs),
201 $(eval $1$o-libs := $($o-libs)))
202 $(if $($o-cflags),
203 $(eval $1$o-cflags := $($o-cflags)))
204 $(if $($o-objs),
205 $(eval $1$o-objs := $(addprefix $1,$($o-objs)))))
206 $(eval $v := $(addprefix $1,$(filter-out %/,$($v))) \
207 $(addprefix $2,$(filter %/,$($v)))))
e05804ee
PB
208endef
209
1c33ac57
FZ
210# unnest-var-recursive
211# Usage: $(call unnest-var-recursive, obj_prefix, vars, var)
212#
213# Unnest @var by including subdir Makefile.objs, while protect others in @vars
214# unchanged.
215#
216# @obj_prefix is the starting point of object path prefix.
217#
218define unnest-var-recursive
219 $(eval dirs := $(sort $(filter %/,$($3))))
220 $(eval $3 := $(filter-out %/,$($3)))
221 $(foreach d,$(dirs:%/=%),
222 $(call save-vars,$2)
223 $(eval obj := $(if $1,$1/)$d)
224 $(eval -include $(SRC_PATH)/$d/Makefile.objs)
225 $(call fix-paths,$(if $1,$1/)$d/,$d/,$2)
226 $(call load-vars,$2,$3)
227 $(call unnest-var-recursive,$1,$2,$3))
17969268
FZ
228endef
229
1c33ac57
FZ
230# unnest-vars
231# Usage: $(call unnest-vars, obj_prefix, vars)
232#
233# @obj_prefix: object path prefix, can be empty, or '..', etc. Don't include
234# ending '/'.
235#
236# @vars: the list of variable names to unnest.
237#
238# This macro will scan subdirectories's Makefile.objs, include them, to build
239# up each variable listed in @vars.
240#
241# Per object and per module cflags and libs are saved with relative path fixed
242# as well, those variables include -libs, -cflags and -objs. Items in -objs are
243# also fixed to relative path against SRC_PATH plus the prefix @obj_prefix.
244#
245# All nested variables postfixed by -m in names are treated as DSO variables,
246# and will be built as modules, if enabled.
247#
248# A simple example of the unnest:
249#
250# obj_prefix = ..
251# vars = hot cold
252# hot = fire.o sun.o season/
253# cold = snow.o water/ season/
254#
255# Unnest through a faked source directory structure:
256#
257# SRC_PATH
258# ├── water
259# │ └── Makefile.objs──────────────────┐
260# │ │ hot += steam.o │
261# │ │ cold += ice.mo │
262# │ │ ice.mo-libs := -licemaker │
263# │ │ ice.mo-objs := ice1.o ice2.o │
264# │ └──────────────────────────────┘
265# │
266# └── season
267# └── Makefile.objs──────┐
268# │ hot += summer.o │
269# │ cold += winter.o │
270# └──────────────────┘
271#
272# In the end, the result will be:
273#
274# hot = ../fire.o ../sun.o ../season/summer.o
275# cold = ../snow.o ../water/ice.mo ../season/winter.o
276# ../water/ice.mo-libs = -licemaker
277# ../water/ice.mo-objs = ../water/ice1.o ../water/ice2.o
278#
279# Note that 'hot' didn't include 'season/' in the input, so 'summer.o' is not
280# included.
281#
e05804ee 282define unnest-vars
1c33ac57
FZ
283 # In the case of target build (i.e. $1 == ..), fix path for top level
284 # Makefile.objs objects
285 $(if $1,$(call fix-paths,$1/,,$2))
286
287 # Descend and include every subdir Makefile.objs
288 $(foreach v, $2, $(call unnest-var-recursive,$1,$2,$v))
289
290 $(foreach v,$(filter %-m,$2),
291 # All .o found in *-m variables are single object modules, create .mo
292 # for them
293 $(foreach o,$(filter %.o,$($v)),
294 $(eval $(o:%.o=%.mo)-objs := $o))
295 # Now unify .o in -m variable to .mo
296 $(eval $v := $($v:%.o=%.mo))
297 $(eval modules-m += $($v))
298
299 # For module build, build shared libraries during "make modules"
300 # For non-module build, add -m to -y
301 $(if $(CONFIG_MODULES),
302 $(eval modules: $($v:%.mo=%$(DSOSUF))),
303 $(eval $(patsubst %-m,%-y,$v) += $(call expand-objs, $($v)))))
304
305 # Post-process all the unnested vars
306 $(foreach v,$2,
307 $(foreach o, $(filter %.mo,$($v)),
308 # Find all the .mo objects in variables and add dependency rules
309 # according to .mo-objs. Report error if not set
310 $(if $($o-objs),
311 $(eval $(o:%.mo=%$(DSOSUF)): module-common.o $($o-objs)),
312 $(error $o added in $v but $o-objs is not set))
313 # Pass the .mo-cflags and .mo-libs along to member objects
314 $(foreach p,$($o-objs),
315 $(if $($o-cflags), $(eval $p-cflags += $($o-cflags)))
316 $(if $($o-libs), $(eval $p-libs += $($o-libs)))))
317 $(shell mkdir -p ./ $(sort $(dir $($v))))
318 # Include all the .d files
319 $(eval -include $(addsuffix *.d, $(sort $(dir $($v)))))
320 $(eval $v := $(filter-out %/,$($v))))
e05804ee 321endef