]> git.proxmox.com Git - mirror_qemu.git/blame - rules.mak
rules.mak: Support .cc as a C++ source file suffix
[mirror_qemu.git] / rules.mak
CommitLineData
17759187 1
5ab28867
JQ
2# 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:
c3dc9fd5 11%.cc:
83f73fce 12%.cpp:
5ab28867
JQ
13%.m:
14%.mak:
15
83f73fce
TS
16# 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
7ebf54bc 19# Flags for dependency generation
a71cd2a5 20QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
02d5467e 21
9d9199a0 22# Same as -I$(SRC_PATH) -I., but for the nested source/object directories
7e7da8e3 23QEMU_INCLUDES += -I$(<D) -I$(@D)
9d9199a0 24
0e8c9214 25%.o: %.c
76dc3cf8 26 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
6821cdc7
PB
27%.o: %.rc
28 $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
17759187 29
44dc0ca3 30ifeq ($(LIBTOOL),)
21655882 31LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
bf0842b7 32 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
21655882 33 $(LIBS)," LINK $(TARGET_DIR)$@")
44dc0ca3 34else
f141ccfa 35LIBTOOL += $(if $(V),,--quiet)
44dc0ca3 36%.lo: %.c
f141ccfa 37 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
6821cdc7
PB
38%.lo: %.rc
39 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
2c13ec50
PB
40%.lo: %.dtrace
41 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
42
21655882
PB
43LINK = $(call quiet-command,\
44 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
45 )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
5354e4d2
MAL
46 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
47 $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
37746c5e 48 $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
21655882 49 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
44dc0ca3
AL
50endif
51
3dd46c78
BS
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)$@")
17759187 57
c3dc9fd5
PM
58%.o: %.cc
59 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
60
83f73fce
TS
61%.o: %.cpp
62 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
63
17759187 64%.o: %.m
3c4a4d0d 65 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
17759187 66
2c13ec50
PB
67%.o: %.dtrace
68 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
69
3aa892d7 70%$(EXESUF): %.o
0bfe3ca5 71 $(call LINK,$^)
4f188f88 72
93a0dba7 73%.a:
28c699a2 74 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
93a0dba7 75
28c699a2 76quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
70071e17
JQ
77
78# cc-option
8a2e6ab5 79# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
70071e17 80
fc3baad7
TM
81cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
82 >/dev/null 2>&1 && echo OK), $2, $3)
1215c6e7 83
c3dc9fd5 84VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc
288e7bcc 85set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
076d2471 86
2b2e59e6
PB
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.
92find-in-path = $(if $(find-string /, $1), \
93 $(wildcard $1), \
94 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
95
837a2e26
PM
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
101lnot = $(if $(subst n,,$1),n,y)
102# Logical AND
103land = $(if $(findstring yy,$1$2),y,n)
104# Logical OR
105lor = $(if $(findstring y,$1$2),y,n)
106# Logical XOR (note that this is the inverse of leqv)
107lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y)
108# Logical equivalence (note that leqv "","n" is true)
109leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n)
110# Logical if: like make's $(if) but with an leqv-like test
111lif = $(if $(subst n,,$1),$2,$3)
112
9ef622e3
PM
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
117eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
118# String inequality
119ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n)
120# Emptiness/non-emptiness tests:
121isempty = $(if $1,n,y)
122notempty = $(if $1,y,n)
123
c0424934
LV
124# Generate files with tracetool
125TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
126
1215c6e7
JQ
127# Generate timestamp files for .h include files
128
4b25966a
MT
129config-%.h: config-%.h-timestamp
130 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
1215c6e7 131
4b25966a
MT
132config-%.h-timestamp: config-%.mak
133 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
7dbbbb0c 134
7586317b
MT
135.PHONY: clean-timestamp
136clean-timestamp:
137 rm -f *.timestamp
138clean: clean-timestamp
139
7dbbbb0c
MT
140# will delete the target of a rule if commands exit with a nonzero exit status
141.DELETE_ON_ERROR:
e05804ee
PB
142
143# magic to descend into other directories
144
145obj := .
146old-nested-dirs :=
147
148define push-var
149$(eval save-$2-$1 = $(value $1))
150$(eval $1 :=)
151endef
152
153define 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 :=)
157endef
158
159define 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/))
165endef
166
167define 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))
175endef
176
177define unnest-vars
178$(call unnest-vars-1)
179$(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
2dee8d54 180$(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
1435ddb8
PB
181$(foreach var,$(nested-vars), $(eval \
182 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
e05804ee 183endef