blob: 279525d3d37defa3d2fda4fef6030f72ae5ab8e4 [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:
11%.m:
12%.mak:
13
Stefan Weil7ebf54b2009-11-19 20:07:52 +010014# Flags for dependency generation
Jan Kiszkaa71cd2a2010-05-15 13:03:28 +020015QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
malc02d54672009-10-11 17:08:57 +040016
Paolo Bonzini9d9199a2012-09-17 10:21:52 +020017# Same as -I$(SRC_PATH) -I., but for the nested source/object directories
18QEMU_CFLAGS += -I$(<D) -I$(@D)
19
Andreas Färber0e8c9212010-01-06 20:24:05 +010020%.o: %.c
Jiri Denemark76dc3cf2011-08-10 12:04:34 +020021 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
Paolo Bonzini6821cdc2013-04-27 00:25:31 +020022%.o: %.rc
23 $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000024
Alon Levy44dc0ca2011-05-15 11:51:28 +030025ifeq ($(LIBTOOL),)
Paolo Bonzinib6fc6752012-12-20 20:40:35 +010026LIBTOOL = /bin/false
Paolo Bonzini21655882012-12-20 18:57:45 +010027LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
Paolo Bonzinibf0842b2012-12-20 17:36:35 +010028 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
Paolo Bonzini21655882012-12-20 18:57:45 +010029 $(LIBS)," LINK $(TARGET_DIR)$@")
Alon Levy44dc0ca2011-05-15 11:51:28 +030030else
Paolo Bonzinif141ccf2012-12-20 18:32:53 +010031LIBTOOL += $(if $(V),,--quiet)
Alon Levy44dc0ca2011-05-15 11:51:28 +030032%.lo: %.c
Paolo Bonzinif141ccf2012-12-20 18:32:53 +010033 $(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 +020034%.lo: %.rc
35 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
Paolo Bonzini2c13ec52012-12-21 09:23:18 +010036%.lo: %.dtrace
37 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
38
Paolo Bonzini21655882012-12-20 18:57:45 +010039LINK = $(call quiet-command,\
40 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
41 )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
Marc-André Lureau5354e4d2013-02-25 23:31:13 +010042 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
43 $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
Marc-André Lureau37746c52013-02-25 23:31:12 +010044 $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
Paolo Bonzini21655882012-12-20 18:57:45 +010045 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
Alon Levy44dc0ca2011-05-15 11:51:28 +030046endif
47
Blue Swirl3dd46c72013-01-05 10:10:27 +000048%.asm: %.S
49 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
50
51%.o: %.asm
52 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000053
54%.o: %.m
Peter Maydell3c4a4d02012-08-11 22:34:40 +010055 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
aliguori17759182009-01-21 18:12:52 +000056
Paolo Bonzini2c13ec52012-12-21 09:23:18 +010057%.o: %.dtrace
58 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
59
aliguori3aa892d2009-01-21 18:13:02 +000060%$(EXESUF): %.o
Anthony Liguori0bfe3ca2009-05-14 19:29:53 +010061 $(call LINK,$^)
aliguori4f188f82009-01-21 18:13:09 +000062
aliguori93a0dba2009-01-21 18:13:16 +000063%.a:
aliguori28c699a2009-01-26 17:07:46 +000064 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
aliguori93a0dba2009-01-21 18:13:16 +000065
aliguori28c699a2009-01-26 17:07:46 +000066quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
Juan Quintela70071e12009-07-21 14:11:18 +020067
68# cc-option
Juan Quintela8a2e6ab2009-08-31 00:48:45 +020069# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
Juan Quintela70071e12009-07-21 14:11:18 +020070
Thomas Monjalonfc3baad2009-09-11 18:45:40 +020071cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
72 >/dev/null 2>&1 && echo OK), $2, $3)
Juan Quintela1215c6e2009-10-07 02:40:58 +020073
Paolo Bonzinib93b63f2012-03-28 15:42:01 +020074VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh
Nathan Froyd288e7bc2010-04-26 14:52:23 -070075set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
Paolo Bonzini076d2472009-12-21 10:06:55 +010076
Paolo Bonzini2b2e59e2010-10-21 10:18:40 +020077# find-in-path
78# Usage: $(call find-in-path, prog)
79# Looks in the PATH if the argument contains no slash, else only considers one
80# specific directory. Returns an # empty string if the program doesn't exist
81# there.
82find-in-path = $(if $(find-string /, $1), \
83 $(wildcard $1), \
84 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
85
Lluís Vilanovac0424932012-04-18 20:15:45 +020086# Generate files with tracetool
87TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
88
Juan Quintela1215c6e2009-10-07 02:40:58 +020089# Generate timestamp files for .h include files
90
Michael S. Tsirkin4b259662013-01-15 13:12:35 +020091config-%.h: config-%.h-timestamp
92 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
Juan Quintela1215c6e2009-10-07 02:40:58 +020093
Michael S. Tsirkin4b259662013-01-15 13:12:35 +020094config-%.h-timestamp: config-%.mak
95 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
Michael S. Tsirkin7dbbbb02009-12-07 21:04:52 +020096
Michael S. Tsirkin75863172013-01-15 13:27:54 +020097.PHONY: clean-timestamp
98clean-timestamp:
99 rm -f *.timestamp
100clean: clean-timestamp
101
Michael S. Tsirkin7dbbbb02009-12-07 21:04:52 +0200102# will delete the target of a rule if commands exit with a nonzero exit status
103.DELETE_ON_ERROR:
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200104
105# magic to descend into other directories
106
107obj := .
108old-nested-dirs :=
109
110define push-var
111$(eval save-$2-$1 = $(value $1))
112$(eval $1 :=)
113endef
114
115define pop-var
116$(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
117$(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
118$(eval save-$2-$1 :=)
119endef
120
121define unnest-dir
122$(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
123$(eval obj := $(obj)/$1)
124$(eval include $(SRC_PATH)/$1/Makefile.objs)
125$(eval obj := $(patsubst %/$1,%,$(obj)))
126$(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
127endef
128
129define unnest-vars-1
130$(eval nested-dirs := $(filter-out \
131 $(old-nested-dirs), \
132 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
133$(if $(nested-dirs),
134 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
135 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
136 $(call unnest-vars-1))
137endef
138
139define unnest-vars
140$(call unnest-vars-1)
141$(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
Paolo Bonzini2dee8d52012-06-04 09:15:43 +0200142$(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
Paolo Bonzini1435ddb2012-07-11 16:40:21 +0200143$(foreach var,$(nested-vars), $(eval \
144 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
Paolo Bonzinie05804e2012-05-22 13:41:27 +0200145endef