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