blob: 49edb9bf07eca605858f5070b9db2340346b7ffd [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:
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -040011%.cpp:
Juan Quintela5ab28862009-10-06 21:11:14 +020012%.m:
13%.mak:
14
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -040015# Flags for C++ compilation
16QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
17
Stefan Weil7ebf54b2009-11-19 20:07:52 +010018# Flags for dependency generation
Jan Kiszkaa71cd2a2010-05-15 13:03:28 +020019QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
malc02d54672009-10-11 17:08:57 +040020
Paolo Bonzini9d9199a2012-09-17 10:21:52 +020021# Same as -I$(SRC_PATH) -I., but for the nested source/object directories
Dunrong Huang7e7da8e2013-04-29 22:52:12 +080022QEMU_INCLUDES += -I$(<D) -I$(@D)
Paolo Bonzini9d9199a2012-09-17 10:21:52 +020023
Andreas Färber0e8c9212010-01-06 20:24:05 +010024%.o: %.c
Jiri Denemark76dc3cf2011-08-10 12:04:34 +020025 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
Paolo Bonzini6821cdc2013-04-27 00:25:31 +020026%.o: %.rc
27 $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000028
Alon Levy44dc0ca2011-05-15 11:51:28 +030029ifeq ($(LIBTOOL),)
Paolo Bonzini21655882012-12-20 18:57:45 +010030LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
Paolo Bonzinibf0842b2012-12-20 17:36:35 +010031 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
Paolo Bonzini21655882012-12-20 18:57:45 +010032 $(LIBS)," LINK $(TARGET_DIR)$@")
Alon Levy44dc0ca2011-05-15 11:51:28 +030033else
Paolo Bonzinif141ccf2012-12-20 18:32:53 +010034LIBTOOL += $(if $(V),,--quiet)
Alon Levy44dc0ca2011-05-15 11:51:28 +030035%.lo: %.c
Paolo Bonzinif141ccf2012-12-20 18:32:53 +010036 $(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 +020037%.lo: %.rc
38 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
Paolo Bonzini2c13ec52012-12-21 09:23:18 +010039%.lo: %.dtrace
40 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
41
Paolo Bonzini21655882012-12-20 18:57:45 +010042LINK = $(call quiet-command,\
43 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
44 )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
Marc-André Lureau5354e4d2013-02-25 23:31:13 +010045 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
46 $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
Marc-André Lureau37746c52013-02-25 23:31:12 +010047 $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
Paolo Bonzini21655882012-12-20 18:57:45 +010048 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
Alon Levy44dc0ca2011-05-15 11:51:28 +030049endif
50
Blue Swirl3dd46c72013-01-05 10:10:27 +000051%.asm: %.S
52 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
53
54%.o: %.asm
55 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000056
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -040057%.o: %.cpp
58 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
59
aliguori17759182009-01-21 18:12:52 +000060%.o: %.m
Peter Maydell3c4a4d02012-08-11 22:34:40 +010061 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000062
Paolo Bonzini2c13ec52012-12-21 09:23:18 +010063%.o: %.dtrace
64 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
65
aliguori3aa892d2009-01-21 18:13:02 +000066%$(EXESUF): %.o
Anthony Liguori0bfe3ca2009-05-14 19:29:53 +010067 $(call LINK,$^)
aliguori4f188f82009-01-21 18:13:09 +000068
aliguori93a0dba2009-01-21 18:13:16 +000069%.a:
aliguori28c699a2009-01-26 17:07:46 +000070 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
aliguori93a0dba2009-01-21 18:13:16 +000071
aliguori28c699a2009-01-26 17:07:46 +000072quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
Juan Quintela70071e12009-07-21 14:11:18 +020073
74# cc-option
Juan Quintela8a2e6ab2009-08-31 00:48:45 +020075# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
Juan Quintela70071e12009-07-21 14:11:18 +020076
Thomas Monjalonfc3baad2009-09-11 18:45:40 +020077cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
78 >/dev/null 2>&1 && echo OK), $2, $3)
Juan Quintela1215c6e2009-10-07 02:40:58 +020079
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -040080VPATH_SUFFIXES = %.c %.h %.S %.cpp %.m %.mak %.texi %.sh %.rc
Nathan Froyd288e7bc2010-04-26 14:52:23 -070081set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
Paolo Bonzini076d2472009-12-21 10:06:55 +010082
Paolo Bonzini2b2e59e2010-10-21 10:18:40 +020083# find-in-path
84# Usage: $(call find-in-path, prog)
85# Looks in the PATH if the argument contains no slash, else only considers one
86# specific directory. Returns an # empty string if the program doesn't exist
87# there.
88find-in-path = $(if $(find-string /, $1), \
89 $(wildcard $1), \
90 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
91
Peter Maydell837a2e22013-09-13 18:25:51 +010092# Logical functions (for operating on y/n values like CONFIG_FOO vars)
93# Inputs to these must be either "y" (true) or "n" or "" (both false)
94# Output is always either "y" or "n".
95# Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
96# Logical NOT
97lnot = $(if $(subst n,,$1),n,y)
98# Logical AND
99land = $(if $(findstring yy,$1$2),y,n)
100# Logical OR
101lor = $(if $(findstring y,$1$2),y,n)
102# Logical XOR (note that this is the inverse of leqv)
103lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y)
104# Logical equivalence (note that leqv "","n" is true)
105leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n)
106# Logical if: like make's $(if) but with an leqv-like test
107lif = $(if $(subst n,,$1),$2,$3)
108
Peter Maydell9ef622e2013-09-13 18:25:52 +0100109# String testing functions: inputs to these can be any string;
110# the output is always either "y" or "n". Leading and trailing whitespace
111# is ignored when comparing strings.
112# String equality
113eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
114# String inequality
115ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n)
116# Emptiness/non-emptiness tests:
117isempty = $(if $1,n,y)
118notempty = $(if $1,y,n)
119
Lluís Vilanovac0424932012-04-18 20:15:45 +0200120# Generate files with tracetool
121TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
122
Juan Quintela1215c6e2009-10-07 02:40:58 +0200123# Generate timestamp files for .h include files
124
Michael S. Tsirkin4b259662013-01-15 13:12:35 +0200125config-%.h: config-%.h-timestamp
126 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
Juan Quintela1215c6e2009-10-07 02:40:58 +0200127
Michael S. Tsirkin4b259662013-01-15 13:12:35 +0200128config-%.h-timestamp: config-%.mak
129 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
Michael S. Tsirkin7dbbbb02009-12-07 21:04:52 +0200130
Michael S. Tsirkin75863172013-01-15 13:27:54 +0200131.PHONY: clean-timestamp
132clean-timestamp:
133 rm -f *.timestamp
134clean: clean-timestamp
135
Michael S. Tsirkin7dbbbb02009-12-07 21:04:52 +0200136# will delete the target of a rule if commands exit with a nonzero exit status
137.DELETE_ON_ERROR:
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200138
139# magic to descend into other directories
140
141obj := .
142old-nested-dirs :=
143
144define push-var
145$(eval save-$2-$1 = $(value $1))
146$(eval $1 :=)
147endef
148
149define pop-var
150$(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
151$(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
152$(eval save-$2-$1 :=)
153endef
154
155define unnest-dir
156$(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
157$(eval obj := $(obj)/$1)
158$(eval include $(SRC_PATH)/$1/Makefile.objs)
159$(eval obj := $(patsubst %/$1,%,$(obj)))
160$(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
161endef
162
163define unnest-vars-1
164$(eval nested-dirs := $(filter-out \
165 $(old-nested-dirs), \
166 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
167$(if $(nested-dirs),
168 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
169 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
170 $(call unnest-vars-1))
171endef
172
173define unnest-vars
174$(call unnest-vars-1)
175$(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
Paolo Bonzini2dee8d52012-06-04 09:15:43 +0200176$(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
Paolo Bonzini1435ddb2012-07-11 16:40:21 +0200177$(foreach var,$(nested-vars), $(eval \
178 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200179endef