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