blob: 0db703129ac28e1138410e5769285a3e6dbb34c3 [file] [log] [blame]
aliguori17759182009-01-21 18:12:52 +00001
Juan Quintela5ab28862009-10-06 21:11:14 +02002# 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:
Peter Maydellc3dc9fd2014-02-05 17:27:27 +000011%.cc:
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -040012%.cpp:
Juan Quintela5ab28862009-10-06 21:11:14 +020013%.m:
14%.mak:
15
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -040016# 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
Stefan Weil7ebf54b2009-11-19 20:07:52 +010019# Flags for dependency generation
Jan Kiszkaa71cd2a2010-05-15 13:03:28 +020020QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
malc02d54672009-10-11 17:08:57 +040021
Paolo Bonzini9d9199a2012-09-17 10:21:52 +020022# Same as -I$(SRC_PATH) -I., but for the nested source/object directories
Dunrong Huang7e7da8e2013-04-29 22:52:12 +080023QEMU_INCLUDES += -I$(<D) -I$(@D)
Paolo Bonzini9d9199a2012-09-17 10:21:52 +020024
Fam Zheng5c0d52b2014-02-10 14:48:53 +080025extract-libs = $(strip $(foreach o,$1,$($o-libs)))
26
Andreas Färber0e8c9212010-01-06 20:24:05 +010027%.o: %.c
Fam Zheng5c0d52b2014-02-10 14:48:53 +080028 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CC $(TARGET_DIR)$@")
Paolo Bonzini6821cdc2013-04-27 00:25:31 +020029%.o: %.rc
30 $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000031
Peter Maydell3144f782014-02-05 17:27:27 +000032# If we have a CXX we might have some C++ objects, in which case we
33# must link with the C++ compiler, not the plain C compiler.
34LINKPROG = $(or $(CXX),$(CC))
35
Alon Levy44dc0ca2011-05-15 11:51:28 +030036ifeq ($(LIBTOOL),)
Peter Maydell3144f782014-02-05 17:27:27 +000037LINK = $(call quiet-command,$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
Paolo Bonzinibf0842b2012-12-20 17:36:35 +010038 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
Fam Zheng5c0d52b2014-02-10 14:48:53 +080039 $(call extract-libs,$^) $(LIBS)," LINK $(TARGET_DIR)$@")
Alon Levy44dc0ca2011-05-15 11:51:28 +030040else
Paolo Bonzinif141ccf2012-12-20 18:32:53 +010041LIBTOOL += $(if $(V),,--quiet)
Alon Levy44dc0ca2011-05-15 11:51:28 +030042%.lo: %.c
Paolo Bonzinif141ccf2012-12-20 18:32:53 +010043 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
Paolo Bonzini6821cdc2013-04-27 00:25:31 +020044%.lo: %.rc
45 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
Paolo Bonzini2c13ec52012-12-21 09:23:18 +010046%.lo: %.dtrace
47 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
48
Paolo Bonzini21655882012-12-20 18:57:45 +010049LINK = $(call quiet-command,\
50 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
Peter Maydell3144f782014-02-05 17:27:27 +000051 )$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
Marc-André Lureau5354e4d2013-02-25 23:31:13 +010052 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
53 $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
Marc-André Lureau37746c52013-02-25 23:31:12 +010054 $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
Fam Zheng5c0d52b2014-02-10 14:48:53 +080055 $(call extract-libs,$^) $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
Alon Levy44dc0ca2011-05-15 11:51:28 +030056endif
57
Blue Swirl3dd46c72013-01-05 10:10:27 +000058%.asm: %.S
59 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
60
61%.o: %.asm
62 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000063
Peter Maydellc3dc9fd2014-02-05 17:27:27 +000064%.o: %.cc
65 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
66
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -040067%.o: %.cpp
68 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
69
aliguori17759182009-01-21 18:12:52 +000070%.o: %.m
Peter Maydell3c4a4d02012-08-11 22:34:40 +010071 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000072
Paolo Bonzini2c13ec52012-12-21 09:23:18 +010073%.o: %.dtrace
74 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
75
aliguori3aa892d2009-01-21 18:13:02 +000076%$(EXESUF): %.o
Anthony Liguori0bfe3ca2009-05-14 19:29:53 +010077 $(call LINK,$^)
aliguori4f188f82009-01-21 18:13:09 +000078
aliguori93a0dba2009-01-21 18:13:16 +000079%.a:
aliguori28c699a2009-01-26 17:07:46 +000080 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
aliguori93a0dba2009-01-21 18:13:16 +000081
aliguori28c699a2009-01-26 17:07:46 +000082quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
Juan Quintela70071e12009-07-21 14:11:18 +020083
84# cc-option
Juan Quintela8a2e6ab2009-08-31 00:48:45 +020085# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
Juan Quintela70071e12009-07-21 14:11:18 +020086
Thomas Monjalonfc3baad2009-09-11 18:45:40 +020087cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
88 >/dev/null 2>&1 && echo OK), $2, $3)
Juan Quintela1215c6e2009-10-07 02:40:58 +020089
Peter Maydellc3dc9fd2014-02-05 17:27:27 +000090VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc
Nathan Froyd288e7bc2010-04-26 14:52:23 -070091set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
Paolo Bonzini076d2472009-12-21 10:06:55 +010092
Paolo Bonzini2b2e59e2010-10-21 10:18:40 +020093# find-in-path
94# Usage: $(call find-in-path, prog)
95# Looks in the PATH if the argument contains no slash, else only considers one
96# specific directory. Returns an # empty string if the program doesn't exist
97# there.
98find-in-path = $(if $(find-string /, $1), \
99 $(wildcard $1), \
100 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
101
Peter Maydell837a2e22013-09-13 18:25:51 +0100102# Logical functions (for operating on y/n values like CONFIG_FOO vars)
103# Inputs to these must be either "y" (true) or "n" or "" (both false)
104# Output is always either "y" or "n".
105# Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
106# Logical NOT
107lnot = $(if $(subst n,,$1),n,y)
108# Logical AND
109land = $(if $(findstring yy,$1$2),y,n)
110# Logical OR
111lor = $(if $(findstring y,$1$2),y,n)
112# Logical XOR (note that this is the inverse of leqv)
113lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y)
114# Logical equivalence (note that leqv "","n" is true)
115leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n)
116# Logical if: like make's $(if) but with an leqv-like test
117lif = $(if $(subst n,,$1),$2,$3)
118
Peter Maydell9ef622e2013-09-13 18:25:52 +0100119# String testing functions: inputs to these can be any string;
120# the output is always either "y" or "n". Leading and trailing whitespace
121# is ignored when comparing strings.
122# String equality
123eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
124# String inequality
125ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n)
126# Emptiness/non-emptiness tests:
127isempty = $(if $1,n,y)
128notempty = $(if $1,y,n)
129
Lluís Vilanovac0424932012-04-18 20:15:45 +0200130# Generate files with tracetool
131TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
132
Juan Quintela1215c6e2009-10-07 02:40:58 +0200133# Generate timestamp files for .h include files
134
Michael S. Tsirkin4b259662013-01-15 13:12:35 +0200135config-%.h: config-%.h-timestamp
136 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
Juan Quintela1215c6e2009-10-07 02:40:58 +0200137
Michael S. Tsirkin4b259662013-01-15 13:12:35 +0200138config-%.h-timestamp: config-%.mak
139 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
Michael S. Tsirkin7dbbbb02009-12-07 21:04:52 +0200140
Michael S. Tsirkin75863172013-01-15 13:27:54 +0200141.PHONY: clean-timestamp
142clean-timestamp:
143 rm -f *.timestamp
144clean: clean-timestamp
145
Michael S. Tsirkin7dbbbb02009-12-07 21:04:52 +0200146# will delete the target of a rule if commands exit with a nonzero exit status
147.DELETE_ON_ERROR:
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200148
149# magic to descend into other directories
150
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200151define push-var
152$(eval save-$2-$1 = $(value $1))
153$(eval $1 :=)
154endef
155
156define pop-var
157$(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
158$(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
159$(eval save-$2-$1 :=)
160endef
161
Fam Zheng5c0d52b2014-02-10 14:48:53 +0800162define fix-obj-vars
163$(foreach v,$($1), \
164 $(if $($v-cflags), \
165 $(eval $2$v-cflags := $($v-cflags)) \
166 $(eval $v-cflags := )) \
167 $(if $($v-libs), \
168 $(eval $2$v-libs := $($v-libs)) \
169 $(eval $v-libs := )))
170endef
171
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200172define unnest-dir
173$(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
Fam Zhengba1183d2014-02-10 14:48:52 +0800174$(eval obj-parent-$1 := $(obj))
175$(eval obj := $(if $(obj),$(obj)/$1,$1))
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200176$(eval include $(SRC_PATH)/$1/Makefile.objs)
Fam Zheng5c0d52b2014-02-10 14:48:53 +0800177$(foreach v,$(nested-vars),$(call fix-obj-vars,$v,$(if $(obj),$(obj)/)))
Fam Zhengba1183d2014-02-10 14:48:52 +0800178$(eval obj := $(obj-parent-$1))
179$(eval obj-parent-$1 := )
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200180$(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
181endef
182
183define unnest-vars-1
184$(eval nested-dirs := $(filter-out \
185 $(old-nested-dirs), \
186 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
187$(if $(nested-dirs),
188 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
189 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
190 $(call unnest-vars-1))
191endef
192
193define unnest-vars
Fam Zhengba1183d2014-02-10 14:48:52 +0800194$(eval obj := $1)
195$(eval nested-vars := $2)
196$(eval old-nested-dirs := )
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200197$(call unnest-vars-1)
Fam Zhengba1183d2014-02-10 14:48:52 +0800198$(if $1,$(foreach v,$(nested-vars),$(eval \
199 $v := $(addprefix $1/,$($v)))))
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200200$(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
Paolo Bonzini2dee8d52012-06-04 09:15:43 +0200201$(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
Paolo Bonzini1435ddb2012-07-11 16:40:21 +0200202$(foreach var,$(nested-vars), $(eval \
203 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200204endef