]> git.proxmox.com Git - mirror_qemu.git/blob - rules.mak
rules.mak: Support .cc as a C++ source file suffix
[mirror_qemu.git] / rules.mak
1
2 # Don't use implicit rules or variables
3 # we have explicit rules for everything
4 MAKEFLAGS += -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 %.cc:
12 %.cpp:
13 %.m:
14 %.mak:
15
16 # Flags for C++ compilation
17 QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
18
19 # Flags for dependency generation
20 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
21
22 # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
23 QEMU_INCLUDES += -I$(<D) -I$(@D)
24
25 %.o: %.c
26 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
27 %.o: %.rc
28 $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
29
30 ifeq ($(LIBTOOL),)
31 LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
32 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
33 $(LIBS)," LINK $(TARGET_DIR)$@")
34 else
35 LIBTOOL += $(if $(V),,--quiet)
36 %.lo: %.c
37 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
38 %.lo: %.rc
39 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
40 %.lo: %.dtrace
41 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
42
43 LINK = $(call quiet-command,\
44 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
45 )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
46 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
47 $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
48 $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
49 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
50 endif
51
52 %.asm: %.S
53 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
54
55 %.o: %.asm
56 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
57
58 %.o: %.cc
59 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
60
61 %.o: %.cpp
62 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
63
64 %.o: %.m
65 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
66
67 %.o: %.dtrace
68 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
69
70 %$(EXESUF): %.o
71 $(call LINK,$^)
72
73 %.a:
74 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
75
76 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
77
78 # cc-option
79 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
80
81 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
82 >/dev/null 2>&1 && echo OK), $2, $3)
83
84 VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc
85 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
86
87 # find-in-path
88 # Usage: $(call find-in-path, prog)
89 # Looks in the PATH if the argument contains no slash, else only considers one
90 # specific directory. Returns an # empty string if the program doesn't exist
91 # there.
92 find-in-path = $(if $(find-string /, $1), \
93 $(wildcard $1), \
94 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
95
96 # Logical functions (for operating on y/n values like CONFIG_FOO vars)
97 # Inputs to these must be either "y" (true) or "n" or "" (both false)
98 # Output is always either "y" or "n".
99 # Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
100 # Logical NOT
101 lnot = $(if $(subst n,,$1),n,y)
102 # Logical AND
103 land = $(if $(findstring yy,$1$2),y,n)
104 # Logical OR
105 lor = $(if $(findstring y,$1$2),y,n)
106 # Logical XOR (note that this is the inverse of leqv)
107 lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y)
108 # Logical equivalence (note that leqv "","n" is true)
109 leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n)
110 # Logical if: like make's $(if) but with an leqv-like test
111 lif = $(if $(subst n,,$1),$2,$3)
112
113 # String testing functions: inputs to these can be any string;
114 # the output is always either "y" or "n". Leading and trailing whitespace
115 # is ignored when comparing strings.
116 # String equality
117 eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
118 # String inequality
119 ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n)
120 # Emptiness/non-emptiness tests:
121 isempty = $(if $1,n,y)
122 notempty = $(if $1,y,n)
123
124 # Generate files with tracetool
125 TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
126
127 # Generate timestamp files for .h include files
128
129 config-%.h: config-%.h-timestamp
130 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
131
132 config-%.h-timestamp: config-%.mak
133 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
134
135 .PHONY: clean-timestamp
136 clean-timestamp:
137 rm -f *.timestamp
138 clean: clean-timestamp
139
140 # will delete the target of a rule if commands exit with a nonzero exit status
141 .DELETE_ON_ERROR:
142
143 # magic to descend into other directories
144
145 obj := .
146 old-nested-dirs :=
147
148 define push-var
149 $(eval save-$2-$1 = $(value $1))
150 $(eval $1 :=)
151 endef
152
153 define pop-var
154 $(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
155 $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
156 $(eval save-$2-$1 :=)
157 endef
158
159 define unnest-dir
160 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
161 $(eval obj := $(obj)/$1)
162 $(eval include $(SRC_PATH)/$1/Makefile.objs)
163 $(eval obj := $(patsubst %/$1,%,$(obj)))
164 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
165 endef
166
167 define unnest-vars-1
168 $(eval nested-dirs := $(filter-out \
169 $(old-nested-dirs), \
170 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
171 $(if $(nested-dirs),
172 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
173 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
174 $(call unnest-vars-1))
175 endef
176
177 define unnest-vars
178 $(call unnest-vars-1)
179 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
180 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
181 $(foreach var,$(nested-vars), $(eval \
182 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
183 endef