]> git.proxmox.com Git - mirror_qemu.git/blame - rules.mak
build-sys: remove dvi doc generation
[mirror_qemu.git] / rules.mak
CommitLineData
17759187 1
2f4e4dc2
FZ
2COMMA := ,
3
5ab28867
JQ
4# Don't use implicit rules or variables
5# we have explicit rules for everything
6MAKEFLAGS += -rR
7
8# Files with this suffixes are final, don't try to generate them
9# using implicit rules
a273f4ce
PB
10%/trace-events:
11%.hx:
12%.py:
13%.objs:
5ab28867
JQ
14%.d:
15%.h:
16%.c:
c3dc9fd5 17%.cc:
83f73fce 18%.cpp:
5ab28867
JQ
19%.m:
20%.mak:
dced7eec 21clean-target:
5ab28867 22
83f73fce
TS
23# Flags for C++ compilation
24QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
25
7ebf54bc 26# Flags for dependency generation
998b7b1d 27QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d
02d5467e 28
9d9199a0 29# Same as -I$(SRC_PATH) -I., but for the nested source/object directories
7e7da8e3 30QEMU_INCLUDES += -I$(<D) -I$(@D)
9d9199a0 31
c261d774 32WL_U := -Wl,-u,
4852ee95 33find-symbols = $(if $1, $(sort $(shell $(NM) -P -g $1 | $2)))
c261d774
FZ
34defined-symbols = $(call find-symbols,$1,awk '$$2!="U"{print $$1}')
35undefined-symbols = $(call find-symbols,$1,awk '$$2=="U"{print $$1}')
36
37# All the .mo objects in -m variables are also added into corresponding -y
38# variable in unnest-vars, but filtered out here, when LINK is called.
39#
40# The .mo objects are supposed to be linked as a DSO, for module build. So here
41# they are only used as a placeholders to generate those "archive undefined"
42# symbol options (-Wl,-u,$symbol_name), which are the archive functions
43# referenced by the code in the DSO.
44#
45# Also the presence in -y variables will also guarantee they are built before
46# linking executables that will load them. So we can look up symbol reference
47# in LINK.
48#
49# This is necessary because the exectuable itself may not use the function, in
50# which case the function would not be linked in. Then the DSO loading will
51# fail because of the missing symbol.
52process-archive-undefs = $(filter-out %.a %.mo,$1) \
53 $(addprefix $(WL_U), \
54 $(filter $(call defined-symbols,$(filter %.a, $1)), \
55 $(call undefined-symbols,$(filter %.mo,$1)))) \
56 $(filter %.a,$1)
57
5b1b6dbd 58extract-libs = $(strip $(foreach o,$(filter-out %.mo,$1),$($o-libs)))
17969268
FZ
59expand-objs = $(strip $(sort $(filter %.o,$1)) \
60 $(foreach o,$(filter %.mo,$1),$($o-objs)) \
61 $(filter-out %.o %.mo,$1))
5c0d52bc 62
0e8c9214 63%.o: %.c
0bdb12c7 64 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
6821cdc7 65%.o: %.rc
0bdb12c7 66 $(call quiet-command,$(WINDRES) -I. -o $@ $<,"RC","$(TARGET_DIR)$@")
17759187 67
3144f78b
PM
68# If we have a CXX we might have some C++ objects, in which case we
69# must link with the C++ compiler, not the plain C compiler.
70LINKPROG = $(or $(CXX),$(CC))
71
1c33ac57 72LINK = $(call quiet-command, $(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
c261d774 73 $(call process-archive-undefs, $1) \
0bdb12c7 74 $(version-obj-y) $(call extract-libs,$1) $(LIBS),"LINK","$(TARGET_DIR)$@")
44dc0ca3 75
5f6f0e27 76%.o: %.S
0bdb12c7 77 $(call quiet-command,$(CCAS) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"CCAS","$(TARGET_DIR)$@")
17759187 78
c3dc9fd5 79%.o: %.cc
0bdb12c7 80 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<,"CXX","$(TARGET_DIR)$@")
c3dc9fd5 81
83f73fce 82%.o: %.cpp
0bdb12c7 83 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<,"CXX","$(TARGET_DIR)$@")
83f73fce 84
17759187 85%.o: %.m
0bdb12c7 86 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<,"OBJC","$(TARGET_DIR)$@")
17759187 87
2c13ec50 88%.o: %.dtrace
0bdb12c7 89 $(call quiet-command,dtrace -o $@ -G -s $<,"GEN","$(TARGET_DIR)$@")
2c13ec50 90
d24697e1
FZ
91DSO_OBJ_CFLAGS := -fPIC -DBUILD_DSO
92module-common.o: CFLAGS += $(DSO_OBJ_CFLAGS)
17969268 93%$(DSOSUF): LDFLAGS += $(LDFLAGS_SHARED)
c261d774 94%$(DSOSUF): %.mo
17969268 95 $(call LINK,$^)
e26110cf 96 @# Copy to build root so modules can be loaded when program started without install
0bdb12c7 97 $(if $(findstring /,$@),$(call quiet-command,cp $@ $(subst /,-,$@),"CP","$(subst /,-,$@)"))
17969268 98
c261d774 99
7ecf44a5 100LD_REL := $(CC) -nostdlib $(LD_REL_FLAGS)
c261d774
FZ
101
102%.mo:
0bdb12c7 103 $(call quiet-command,$(LD_REL) -o $@ $^,"LD","$(TARGET_DIR)$@")
c261d774 104
17969268
FZ
105.PHONY: modules
106modules:
107
3aa892d7 108%$(EXESUF): %.o
cefa2bbd 109 $(call LINK,$(filter %.o %.a %.mo, $^))
4f188f88 110
93a0dba7 111%.a:
0bdb12c7 112 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"AR","$(TARGET_DIR)$@")
93a0dba7 113
0bdb12c7
PM
114# Usage: $(call quiet-command,command and args,"NAME","args to print")
115# This will run "command and args", and either:
116# if V=1 just print the whole command and args
117# otherwise print the 'quiet' output in the format " NAME args to print"
118# NAME should be a short name of the command, 7 letters or fewer.
119# If called with only a single argument, will print nothing in quiet mode.
120quiet-command = $(if $(V),$1,$(if $(2),@printf " %-7s %s\n" $2 $3 && $1, @$1))
70071e17
JQ
121
122# cc-option
8a2e6ab5 123# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
70071e17 124
fc3baad7
TM
125cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
126 >/dev/null 2>&1 && echo OK), $2, $3)
036999e9
PB
127cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \
128 >/dev/null 2>&1 && echo OK), $2, $3)
1215c6e7 129
c3dc9fd5 130VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc
288e7bcc 131set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
076d2471 132
0d659426
MT
133# install-prog list, dir
134define install-prog
135 $(INSTALL_DIR) "$2"
136 $(INSTALL_PROG) $1 "$2"
137 $(if $(STRIP),$(STRIP) $(foreach T,$1,"$2/$(notdir $T)"),)
138endef
139
2b2e59e6
PB
140# find-in-path
141# Usage: $(call find-in-path, prog)
142# Looks in the PATH if the argument contains no slash, else only considers one
143# specific directory. Returns an # empty string if the program doesn't exist
144# there.
88071589 145find-in-path = $(if $(findstring /, $1), \
2b2e59e6
PB
146 $(wildcard $1), \
147 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
148
837a2e26
PM
149# Logical functions (for operating on y/n values like CONFIG_FOO vars)
150# Inputs to these must be either "y" (true) or "n" or "" (both false)
151# Output is always either "y" or "n".
152# Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
153# Logical NOT
154lnot = $(if $(subst n,,$1),n,y)
155# Logical AND
156land = $(if $(findstring yy,$1$2),y,n)
157# Logical OR
158lor = $(if $(findstring y,$1$2),y,n)
159# Logical XOR (note that this is the inverse of leqv)
160lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y)
161# Logical equivalence (note that leqv "","n" is true)
162leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n)
163# Logical if: like make's $(if) but with an leqv-like test
164lif = $(if $(subst n,,$1),$2,$3)
165
9ef622e3
PM
166# String testing functions: inputs to these can be any string;
167# the output is always either "y" or "n". Leading and trailing whitespace
168# is ignored when comparing strings.
169# String equality
170eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
171# String inequality
172ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n)
173# Emptiness/non-emptiness tests:
174isempty = $(if $1,n,y)
175notempty = $(if $1,y,n)
176
c0424934
LV
177# Generate files with tracetool
178TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
179
1215c6e7
JQ
180# Generate timestamp files for .h include files
181
4b25966a
MT
182config-%.h: config-%.h-timestamp
183 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
1215c6e7 184
55335015 185config-%.h-timestamp: config-%.mak $(SRC_PATH)/scripts/create_config
0bdb12c7 186 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@,"GEN","$(TARGET_DIR)config-$*.h")
7dbbbb0c 187
7586317b
MT
188.PHONY: clean-timestamp
189clean-timestamp:
190 rm -f *.timestamp
191clean: clean-timestamp
192
7dbbbb0c
MT
193# will delete the target of a rule if commands exit with a nonzero exit status
194.DELETE_ON_ERROR:
e05804ee 195
1c33ac57
FZ
196# save-vars
197# Usage: $(call save-vars, vars)
198# Save each variable $v in $vars as save-vars-$v, save their object's
5ffb3505
PB
199# variables, then clear $v. saved-vars-$v contains the variables that
200# where saved for the objects, in order to speedup load-vars.
1c33ac57
FZ
201define save-vars
202 $(foreach v,$1,
203 $(eval save-vars-$v := $(value $v))
5ffb3505
PB
204 $(eval saved-vars-$v := $(foreach o,$($v), \
205 $(if $($o-cflags), $o-cflags $(eval save-vars-$o-cflags := $($o-cflags))$(eval $o-cflags := )) \
206 $(if $($o-libs), $o-libs $(eval save-vars-$o-libs := $($o-libs))$(eval $o-libs := )) \
207 $(if $($o-objs), $o-objs $(eval save-vars-$o-objs := $($o-objs))$(eval $o-objs := ))))
1c33ac57 208 $(eval $v := ))
5c0d52bc
FZ
209endef
210
1c33ac57
FZ
211# load-vars
212# Usage: $(call load-vars, vars, add_var)
213# Load the saved value for each variable in @vars, and the per object
214# variables.
215# Append @add_var's current value to the loaded value.
216define load-vars
217 $(eval $2-new-value := $(value $2))
218 $(foreach v,$1,
219 $(eval $v := $(value save-vars-$v))
5ffb3505
PB
220 $(foreach o,$(saved-vars-$v),
221 $(eval $o := $(save-vars-$o)) $(eval save-vars-$o := ))
222 $(eval save-vars-$v := )
223 $(eval saved-vars-$v := ))
1c33ac57 224 $(eval $2 := $(value $2) $($2-new-value))
e05804ee
PB
225endef
226
1c33ac57
FZ
227# fix-paths
228# Usage: $(call fix-paths, obj_path, src_path, vars)
229# Add prefix @obj_path to all objects in @vars, and add prefix @src_path to all
230# directories in @vars.
231define fix-paths
232 $(foreach v,$3,
233 $(foreach o,$($v),
234 $(if $($o-libs),
235 $(eval $1$o-libs := $($o-libs)))
236 $(if $($o-cflags),
237 $(eval $1$o-cflags := $($o-cflags)))
238 $(if $($o-objs),
239 $(eval $1$o-objs := $(addprefix $1,$($o-objs)))))
240 $(eval $v := $(addprefix $1,$(filter-out %/,$($v))) \
241 $(addprefix $2,$(filter %/,$($v)))))
e05804ee
PB
242endef
243
1c33ac57
FZ
244# unnest-var-recursive
245# Usage: $(call unnest-var-recursive, obj_prefix, vars, var)
246#
247# Unnest @var by including subdir Makefile.objs, while protect others in @vars
248# unchanged.
249#
250# @obj_prefix is the starting point of object path prefix.
251#
252define unnest-var-recursive
253 $(eval dirs := $(sort $(filter %/,$($3))))
254 $(eval $3 := $(filter-out %/,$($3)))
255 $(foreach d,$(dirs:%/=%),
256 $(call save-vars,$2)
257 $(eval obj := $(if $1,$1/)$d)
258 $(eval -include $(SRC_PATH)/$d/Makefile.objs)
259 $(call fix-paths,$(if $1,$1/)$d/,$d/,$2)
260 $(call load-vars,$2,$3)
261 $(call unnest-var-recursive,$1,$2,$3))
17969268
FZ
262endef
263
1c33ac57
FZ
264# unnest-vars
265# Usage: $(call unnest-vars, obj_prefix, vars)
266#
267# @obj_prefix: object path prefix, can be empty, or '..', etc. Don't include
268# ending '/'.
269#
270# @vars: the list of variable names to unnest.
271#
272# This macro will scan subdirectories's Makefile.objs, include them, to build
273# up each variable listed in @vars.
274#
275# Per object and per module cflags and libs are saved with relative path fixed
276# as well, those variables include -libs, -cflags and -objs. Items in -objs are
277# also fixed to relative path against SRC_PATH plus the prefix @obj_prefix.
278#
279# All nested variables postfixed by -m in names are treated as DSO variables,
280# and will be built as modules, if enabled.
281#
282# A simple example of the unnest:
283#
284# obj_prefix = ..
285# vars = hot cold
286# hot = fire.o sun.o season/
287# cold = snow.o water/ season/
288#
289# Unnest through a faked source directory structure:
290#
291# SRC_PATH
292# ├── water
293# │ └── Makefile.objs──────────────────┐
294# │ │ hot += steam.o │
295# │ │ cold += ice.mo │
296# │ │ ice.mo-libs := -licemaker │
297# │ │ ice.mo-objs := ice1.o ice2.o │
298# │ └──────────────────────────────┘
299# │
300# └── season
301# └── Makefile.objs──────┐
302# │ hot += summer.o │
303# │ cold += winter.o │
304# └──────────────────┘
305#
306# In the end, the result will be:
307#
308# hot = ../fire.o ../sun.o ../season/summer.o
309# cold = ../snow.o ../water/ice.mo ../season/winter.o
310# ../water/ice.mo-libs = -licemaker
311# ../water/ice.mo-objs = ../water/ice1.o ../water/ice2.o
312#
313# Note that 'hot' didn't include 'season/' in the input, so 'summer.o' is not
314# included.
315#
e05804ee 316define unnest-vars
1c33ac57
FZ
317 # In the case of target build (i.e. $1 == ..), fix path for top level
318 # Makefile.objs objects
319 $(if $1,$(call fix-paths,$1/,,$2))
320
321 # Descend and include every subdir Makefile.objs
c88f68ec
FZ
322 $(foreach v, $2,
323 $(call unnest-var-recursive,$1,$2,$v)
324 # Pass the .mo-cflags and .mo-libs along to its member objects
325 $(foreach o, $(filter %.mo,$($v)),
326 $(foreach p,$($o-objs),
327 $(if $($o-cflags), $(eval $p-cflags += $($o-cflags)))
328 $(if $($o-libs), $(eval $p-libs += $($o-libs))))))
329
330 # For all %.mo objects that are directly added into -y, just expand them
331 $(foreach v,$(filter %-y,$2),
332 $(eval $v := $(foreach o,$($v),$(if $($o-objs),$($o-objs),$o))))
1c33ac57
FZ
333
334 $(foreach v,$(filter %-m,$2),
335 # All .o found in *-m variables are single object modules, create .mo
336 # for them
337 $(foreach o,$(filter %.o,$($v)),
338 $(eval $(o:%.o=%.mo)-objs := $o))
339 # Now unify .o in -m variable to .mo
340 $(eval $v := $($v:%.o=%.mo))
341 $(eval modules-m += $($v))
342
343 # For module build, build shared libraries during "make modules"
344 # For non-module build, add -m to -y
345 $(if $(CONFIG_MODULES),
c261d774 346 $(foreach o,$($v),
d24697e1 347 $(eval $($o-objs): CFLAGS += $(DSO_OBJ_CFLAGS))
c261d774
FZ
348 $(eval $o: $($o-objs)))
349 $(eval $(patsubst %-m,%-y,$v) += $($v))
1c33ac57
FZ
350 $(eval modules: $($v:%.mo=%$(DSOSUF))),
351 $(eval $(patsubst %-m,%-y,$v) += $(call expand-objs, $($v)))))
352
353 # Post-process all the unnested vars
354 $(foreach v,$2,
355 $(foreach o, $(filter %.mo,$($v)),
356 # Find all the .mo objects in variables and add dependency rules
357 # according to .mo-objs. Report error if not set
358 $(if $($o-objs),
359 $(eval $(o:%.mo=%$(DSOSUF)): module-common.o $($o-objs)),
c88f68ec 360 $(error $o added in $v but $o-objs is not set)))
1c33ac57
FZ
361 $(shell mkdir -p ./ $(sort $(dir $($v))))
362 # Include all the .d files
27fa7479 363 $(eval -include $(patsubst %.o,%.d,$(patsubst %.mo,%.d,$($v))))
1c33ac57 364 $(eval $v := $(filter-out %/,$($v))))
e05804ee 365endef