blob: 391d6eb8e612e5f7361249fe68040f50eb1c7bcc [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
Andreas Färber0e8c9212010-01-06 20:24:05 +010025%.o: %.c
Jiri Denemark76dc3cf2011-08-10 12:04:34 +020026 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
Paolo Bonzini6821cdc2013-04-27 00:25:31 +020027%.o: %.rc
28 $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000029
Peter Maydell3144f782014-02-05 17:27:27 +000030# 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
Alon Levy44dc0ca2011-05-15 11:51:28 +030034ifeq ($(LIBTOOL),)
Peter Maydell3144f782014-02-05 17:27:27 +000035LINK = $(call quiet-command,$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
Paolo Bonzinibf0842b2012-12-20 17:36:35 +010036 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
Paolo Bonzini21655882012-12-20 18:57:45 +010037 $(LIBS)," LINK $(TARGET_DIR)$@")
Alon Levy44dc0ca2011-05-15 11:51:28 +030038else
Paolo Bonzinif141ccf2012-12-20 18:32:53 +010039LIBTOOL += $(if $(V),,--quiet)
Alon Levy44dc0ca2011-05-15 11:51:28 +030040%.lo: %.c
Paolo Bonzinif141ccf2012-12-20 18:32:53 +010041 $(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 +020042%.lo: %.rc
43 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
Paolo Bonzini2c13ec52012-12-21 09:23:18 +010044%.lo: %.dtrace
45 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
46
Paolo Bonzini21655882012-12-20 18:57:45 +010047LINK = $(call quiet-command,\
48 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
Peter Maydell3144f782014-02-05 17:27:27 +000049 )$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
Marc-André Lureau5354e4d2013-02-25 23:31:13 +010050 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
51 $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
Marc-André Lureau37746c52013-02-25 23:31:12 +010052 $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
Paolo Bonzini21655882012-12-20 18:57:45 +010053 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
Alon Levy44dc0ca2011-05-15 11:51:28 +030054endif
55
Blue Swirl3dd46c72013-01-05 10:10:27 +000056%.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)$@")
aliguori17759182009-01-21 18:12:52 +000061
Peter Maydellc3dc9fd2014-02-05 17:27:27 +000062%.o: %.cc
63 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
64
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -040065%.o: %.cpp
66 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
67
aliguori17759182009-01-21 18:12:52 +000068%.o: %.m
Peter Maydell3c4a4d02012-08-11 22:34:40 +010069 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000070
Paolo Bonzini2c13ec52012-12-21 09:23:18 +010071%.o: %.dtrace
72 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
73
aliguori3aa892d2009-01-21 18:13:02 +000074%$(EXESUF): %.o
Anthony Liguori0bfe3ca2009-05-14 19:29:53 +010075 $(call LINK,$^)
aliguori4f188f82009-01-21 18:13:09 +000076
aliguori93a0dba2009-01-21 18:13:16 +000077%.a:
aliguori28c699a2009-01-26 17:07:46 +000078 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
aliguori93a0dba2009-01-21 18:13:16 +000079
aliguori28c699a2009-01-26 17:07:46 +000080quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
Juan Quintela70071e12009-07-21 14:11:18 +020081
82# cc-option
Juan Quintela8a2e6ab2009-08-31 00:48:45 +020083# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
Juan Quintela70071e12009-07-21 14:11:18 +020084
Thomas Monjalonfc3baad2009-09-11 18:45:40 +020085cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
86 >/dev/null 2>&1 && echo OK), $2, $3)
Juan Quintela1215c6e2009-10-07 02:40:58 +020087
Peter Maydellc3dc9fd2014-02-05 17:27:27 +000088VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc
Nathan Froyd288e7bc2010-04-26 14:52:23 -070089set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
Paolo Bonzini076d2472009-12-21 10:06:55 +010090
Paolo Bonzini2b2e59e2010-10-21 10:18:40 +020091# 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
Peter Maydell837a2e22013-09-13 18:25:51 +0100100# 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
Peter Maydell9ef622e2013-09-13 18:25:52 +0100117# 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
Lluís Vilanovac0424932012-04-18 20:15:45 +0200128# Generate files with tracetool
129TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
130
Juan Quintela1215c6e2009-10-07 02:40:58 +0200131# Generate timestamp files for .h include files
132
Michael S. Tsirkin4b259662013-01-15 13:12:35 +0200133config-%.h: config-%.h-timestamp
134 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
Juan Quintela1215c6e2009-10-07 02:40:58 +0200135
Michael S. Tsirkin4b259662013-01-15 13:12:35 +0200136config-%.h-timestamp: config-%.mak
137 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
Michael S. Tsirkin7dbbbb02009-12-07 21:04:52 +0200138
Michael S. Tsirkin75863172013-01-15 13:27:54 +0200139.PHONY: clean-timestamp
140clean-timestamp:
141 rm -f *.timestamp
142clean: clean-timestamp
143
Michael S. Tsirkin7dbbbb02009-12-07 21:04:52 +0200144# will delete the target of a rule if commands exit with a nonzero exit status
145.DELETE_ON_ERROR:
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200146
147# magic to descend into other directories
148
149obj := .
150old-nested-dirs :=
151
152define push-var
153$(eval save-$2-$1 = $(value $1))
154$(eval $1 :=)
155endef
156
157define pop-var
158$(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
159$(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
160$(eval save-$2-$1 :=)
161endef
162
163define unnest-dir
164$(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
165$(eval obj := $(obj)/$1)
166$(eval include $(SRC_PATH)/$1/Makefile.objs)
167$(eval obj := $(patsubst %/$1,%,$(obj)))
168$(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
169endef
170
171define unnest-vars-1
172$(eval nested-dirs := $(filter-out \
173 $(old-nested-dirs), \
174 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
175$(if $(nested-dirs),
176 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
177 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
178 $(call unnest-vars-1))
179endef
180
181define unnest-vars
182$(call unnest-vars-1)
183$(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
Paolo Bonzini2dee8d52012-06-04 09:15:43 +0200184$(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
Paolo Bonzini1435ddb2012-07-11 16:40:21 +0200185$(foreach var,$(nested-vars), $(eval \
186 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200187endef