root / rules.mak @ ba1183da
History | View | Annotate | Download (6.6 kB)
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 |
# 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. |
32 |
LINKPROG = $(or $(CXX),$(CC)) |
33 |
|
34 |
ifeq ($(LIBTOOL),) |
35 |
LINK = $(call quiet-command,$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ |
36 |
$(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \ |
37 |
$(LIBS)," LINK $(TARGET_DIR)$@") |
38 |
else |
39 |
LIBTOOL += $(if $(V),,--quiet) |
40 |
%.lo: %.c |
41 |
$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@") |
42 |
%.lo: %.rc |
43 |
$(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@") |
44 |
%.lo: %.dtrace |
45 |
$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@") |
46 |
|
47 |
LINK = $(call quiet-command,\ |
48 |
$(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \ |
49 |
)$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ |
50 |
$(sort $(filter %.o, $1)) $(filter-out %.o, $1) \ |
51 |
$(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \ |
52 |
$(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \ |
53 |
$(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@") |
54 |
endif |
55 |
|
56 |
%.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)$@") |
61 |
|
62 |
%.o: %.cc |
63 |
$(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@") |
64 |
|
65 |
%.o: %.cpp |
66 |
$(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@") |
67 |
|
68 |
%.o: %.m |
69 |
$(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@") |
70 |
|
71 |
%.o: %.dtrace |
72 |
$(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@") |
73 |
|
74 |
%$(EXESUF): %.o |
75 |
$(call LINK,$^) |
76 |
|
77 |
%.a: |
78 |
$(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@") |
79 |
|
80 |
quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1)) |
81 |
|
82 |
# cc-option |
83 |
# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0) |
84 |
|
85 |
cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \ |
86 |
>/dev/null 2>&1 && echo OK), $2, $3) |
87 |
|
88 |
VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc |
89 |
set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1))) |
90 |
|
91 |
# 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. |
96 |
find-in-path = $(if $(find-string /, $1), \ |
97 |
$(wildcard $1), \ |
98 |
$(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH))))) |
99 |
|
100 |
# 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 |
105 |
lnot = $(if $(subst n,,$1),n,y) |
106 |
# Logical AND |
107 |
land = $(if $(findstring yy,$1$2),y,n) |
108 |
# Logical OR |
109 |
lor = $(if $(findstring y,$1$2),y,n) |
110 |
# Logical XOR (note that this is the inverse of leqv) |
111 |
lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y) |
112 |
# Logical equivalence (note that leqv "","n" is true) |
113 |
leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n) |
114 |
# Logical if: like make's $(if) but with an leqv-like test |
115 |
lif = $(if $(subst n,,$1),$2,$3) |
116 |
|
117 |
# 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 |
121 |
eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y) |
122 |
# String inequality |
123 |
ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n) |
124 |
# Emptiness/non-emptiness tests: |
125 |
isempty = $(if $1,n,y) |
126 |
notempty = $(if $1,y,n) |
127 |
|
128 |
# Generate files with tracetool |
129 |
TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py |
130 |
|
131 |
# Generate timestamp files for .h include files |
132 |
|
133 |
config-%.h: config-%.h-timestamp |
134 |
@cmp $< $@ >/dev/null 2>&1 || cp $< $@ |
135 |
|
136 |
config-%.h-timestamp: config-%.mak |
137 |
$(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h") |
138 |
|
139 |
.PHONY: clean-timestamp |
140 |
clean-timestamp: |
141 |
rm -f *.timestamp |
142 |
clean: clean-timestamp |
143 |
|
144 |
# will delete the target of a rule if commands exit with a nonzero exit status |
145 |
.DELETE_ON_ERROR: |
146 |
|
147 |
# magic to descend into other directories |
148 |
|
149 |
define push-var |
150 |
$(eval save-$2-$1 = $(value $1)) |
151 |
$(eval $1 :=) |
152 |
endef |
153 |
|
154 |
define pop-var |
155 |
$(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1)))) |
156 |
$(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1)) |
157 |
$(eval save-$2-$1 :=) |
158 |
endef |
159 |
|
160 |
define unnest-dir |
161 |
$(foreach var,$(nested-vars),$(call push-var,$(var),$1/)) |
162 |
$(eval obj-parent-$1 := $(obj)) |
163 |
$(eval obj := $(if $(obj),$(obj)/$1,$1)) |
164 |
$(eval include $(SRC_PATH)/$1/Makefile.objs) |
165 |
$(eval obj := $(obj-parent-$1)) |
166 |
$(eval obj-parent-$1 := ) |
167 |
$(foreach var,$(nested-vars),$(call pop-var,$(var),$1/)) |
168 |
endef |
169 |
|
170 |
define unnest-vars-1 |
171 |
$(eval nested-dirs := $(filter-out \ |
172 |
$(old-nested-dirs), \ |
173 |
$(sort $(foreach var,$(nested-vars), $(filter %/, $($(var))))))) |
174 |
$(if $(nested-dirs), |
175 |
$(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir)))) |
176 |
$(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs)) |
177 |
$(call unnest-vars-1)) |
178 |
endef |
179 |
|
180 |
define unnest-vars |
181 |
$(eval obj := $1) |
182 |
$(eval nested-vars := $2) |
183 |
$(eval old-nested-dirs := ) |
184 |
$(call unnest-vars-1) |
185 |
$(if $1,$(foreach v,$(nested-vars),$(eval \ |
186 |
$v := $(addprefix $1/,$($v))))) |
187 |
$(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var))))) |
188 |
$(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var)))))) |
189 |
$(foreach var,$(nested-vars), $(eval \ |
190 |
-include $(addsuffix *.d, $(sort $(dir $($(var))))))) |
191 |
endef |