2 # Don't use implicit rules or variables
3 # we have explicit rules for everything
6 # Files with this suffixes are final, don't try to generate them
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
))
19 # Flags for dependency generation
20 QEMU_DGFLAGS
+= -MMD
-MP
-MT
$@
-MF
$(*D
)/$(*F
).d
22 # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
23 QEMU_INCLUDES
+= -I
$(<D
) -I
$(@D
)
25 maybe-add
= $(filter-out $1, $2) $1
26 extract-libs
= $(strip $(sort $(foreach o
,$1,$($o-libs
)) \
27 $(foreach o
,$(call expand-objs
,$1),$($o-libs
))))
28 expand-objs
= $(strip $(sort $(filter %.o
,$1)) \
29 $(foreach o
,$(filter %.mo
,$1),$($o-objs
)) \
30 $(filter-out %.o
%.mo
,$1))
33 $(call quiet-command
,$(CC
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) $($@
-cflags) -c
-o
$@
$<," CC $(TARGET_DIR)$@")
35 $(call quiet-command
,$(WINDRES
) -I.
-o
$@
$<," RC $(TARGET_DIR)$@")
37 # If we have a CXX we might have some C++ objects, in which case we
38 # must link with the C++ compiler, not the plain C compiler.
39 LINKPROG
= $(or
$(CXX
),$(CC
))
42 LINK
= $(call quiet-command
,$(LINKPROG
) $(QEMU_CFLAGS
) $(CFLAGS
) $(LDFLAGS
) -o
$@ \
43 $(call expand-objs
,$1) $(version-obj-y
) \
44 $(call extract-libs
,$1) $(LIBS
)," LINK $(TARGET_DIR)$@")
46 LIBTOOL
+= $(if
$(V
),,--quiet
)
48 $(call quiet-command
,$(LIBTOOL
) --mode
=compile
--tag
=CC
$(CC
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," lt CC $@")
50 $(call quiet-command
,$(LIBTOOL
) --mode
=compile
--tag
=RC
$(WINDRES
) -I.
-o
$@
$<,"lt RC $(TARGET_DIR)$@")
52 $(call quiet-command
,$(LIBTOOL
) --mode
=compile
--tag
=CC dtrace
-o
$@
-G
-s
$<, " lt GEN $(TARGET_DIR)$@")
54 LINK
= $(call quiet-command
,\
55 $(if
$(filter %.lo
%.la
,$1),$(LIBTOOL
) --mode
=link
--tag
=CC \
56 )$(LINKPROG
) $(QEMU_CFLAGS
) $(CFLAGS
) $(LDFLAGS
) -o
$@ \
57 $(call expand-objs
,$1) \
58 $(if
$(filter %.lo
%.la
,$1),$(version-lobj-y
),$(version-obj-y
)) \
59 $(if
$(filter %.lo
%.la
,$1),$(LIBTOOLFLAGS
)) \
60 $(call extract-libs
,$1) $(LIBS
),$(if
$(filter %.lo
%.la
,$1),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
64 $(call quiet-command
,$(CPP
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -o
$@
$<," CPP $(TARGET_DIR)$@")
67 $(call quiet-command
,$(AS
) $(ASFLAGS
) -o
$@
$<," AS $(TARGET_DIR)$@")
70 $(call quiet-command
,$(CXX
) $(QEMU_INCLUDES
) $(QEMU_CXXFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," CXX $(TARGET_DIR)$@")
73 $(call quiet-command
,$(CXX
) $(QEMU_INCLUDES
) $(QEMU_CXXFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," CXX $(TARGET_DIR)$@")
76 $(call quiet-command
,$(OBJCC
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," OBJC $(TARGET_DIR)$@")
79 $(call quiet-command
,dtrace
-o
$@
-G
-s
$<, " GEN $(TARGET_DIR)$@")
81 DSO_CFLAGS
:= -fPIC
-DBUILD_DSO
82 %$(DSOSUF
): LDFLAGS
+= $(LDFLAGS_SHARED
)
83 %$(DSOSUF
): %.mo libqemustub.a
85 @
# Copy to build root so modules can be loaded when program started without install
86 $(if
$(findstring /,$@
),$(call quiet-command
,cp
$@
$(subst /,-,$@
), " CP $(subst /,-,$@)"))
95 $(call quiet-command
,rm -f
$@
&& $(AR
) rcs
$@
$^
," AR $(TARGET_DIR)$@")
97 quiet-command
= $(if
$(V
),$1,$(if
$(2),@echo
$2 && $1, @
$1))
100 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
102 cc-option
= $(if
$(shell $(CC
) $1 $2 -S
-o
/dev
/null
-xc
/dev
/null \
103 >/dev
/null
2>&1 && echo OK
), $2, $3)
105 VPATH_SUFFIXES
= %.c
%.h
%.S
%.
cc %.
cpp %.m
%.mak
%.texi
%.sh
%.rc
106 set-vpath
= $(if
$1,$(foreach PATTERN
,$(VPATH_SUFFIXES
),$(eval vpath
$(PATTERN
) $1)))
109 # Usage: $(call find-in-path, prog)
110 # Looks in the PATH if the argument contains no slash, else only considers one
111 # specific directory. Returns an # empty string if the program doesn't exist
113 find-in-path
= $(if
$(find-string
/, $1), \
115 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH
)))))
117 # Logical functions (for operating on y/n values like CONFIG_FOO vars)
118 # Inputs to these must be either "y" (true) or "n" or "" (both false)
119 # Output is always either "y" or "n".
120 # Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
122 lnot
= $(if
$(subst n
,,$1),n
,y
)
124 land
= $(if
$(findstring yy
,$1$2),y
,n
)
126 lor
= $(if
$(findstring y
,$1$2),y
,n
)
127 # Logical XOR (note that this is the inverse of leqv)
128 lxor
= $(if
$(filter $(call lnot
,$1),$(call lnot
,$2)),n
,y
)
129 # Logical equivalence (note that leqv "","n" is true)
130 leqv
= $(if
$(filter $(call lnot
,$1),$(call lnot
,$2)),y
,n
)
131 # Logical if: like make's $(if) but with an leqv-like test
132 lif
= $(if
$(subst n
,,$1),$2,$3)
134 # String testing functions: inputs to these can be any string;
135 # the output is always either "y" or "n". Leading and trailing whitespace
136 # is ignored when comparing strings.
138 eq
= $(if
$(subst $2,,$1)$(subst $1,,$2),n
,y
)
140 ne
= $(if
$(subst $2,,$1)$(subst $1,,$2),y
,n
)
141 # Emptiness/non-emptiness tests:
142 isempty
= $(if
$1,n
,y
)
143 notempty
= $(if
$1,y
,n
)
145 # Generate files with tracetool
146 TRACETOOL
=$(PYTHON
) $(SRC_PATH
)/scripts
/tracetool.py
148 # Generate timestamp files for .h include files
150 config-
%.h
: config-
%.h-timestamp
151 @cmp
$< $@
>/dev
/null
2>&1 || cp
$< $@
153 config-
%.h-timestamp
: config-
%.mak
154 $(call quiet-command
, sh
$(SRC_PATH
)/scripts
/create_config
< $< > $@
, " GEN $(TARGET_DIR)config-$*.h")
156 .PHONY
: clean-timestamp
159 clean: clean-timestamp
161 # will delete the target of a rule if commands exit with a nonzero exit status
164 # magic to descend into other directories
167 $(eval save-
$2-$1 = $(value
$1))
172 $(eval subdir-
$2-$1 := $(if
$(filter $2,$(save-
$2-$1)),$(addprefix $2,$($1))))
173 $(eval
$1 = $(value save-
$2-$1) $$(subdir-
$2-$1))
174 $(eval save-
$2-$1 :=)
180 $(eval
$2$v-cflags
:= $($v-cflags
)) \
181 $(eval
$v-cflags
:= )) \
183 $(eval
$2$v-libs
:= $($v-libs
)) \
184 $(eval
$v-libs
:= )) \
186 $(eval
$2$v-objs
:= $(addprefix $2,$($v-objs
))) \
187 $(eval
$v-objs
:= )))
191 $(foreach var
,$(nested-vars
),$(call push-var
,$(var
),$1/))
192 $(eval obj-parent-
$1 := $(obj
))
193 $(eval obj
:= $(if
$(obj
),$(obj
)/$1,$1))
194 $(eval
include $(SRC_PATH
)/$1/Makefile.objs
)
195 $(foreach v
,$(nested-vars
),$(call fix-obj-vars
,$v,$(if
$(obj
),$(obj
)/)))
196 $(eval obj
:= $(obj-parent-
$1))
197 $(eval obj-parent-
$1 := )
198 $(foreach var
,$(nested-vars
),$(call pop-var
,$(var
),$1/))
202 $(eval nested-dirs
:= $(filter-out \
203 $(old-nested-dirs
), \
204 $(sort $(foreach var
,$(nested-vars
), $(filter %/, $($(var
)))))))
206 $(foreach dir,$(nested-dirs
),$(call unnest-dir
,$(patsubst %/,%,$(dir))))
207 $(eval old-nested-dirs
:= $(old-nested-dirs
) $(nested-dirs
))
208 $(call unnest-vars-1
))
211 define process-modules
212 $(foreach o
,$(filter %.o
,$($1)),
213 $(eval
$(patsubst %.o
,%.mo
,$o): $o) \
214 $(eval
$(patsubst %.o
,%.mo
,$o)-objs
:= $o))
215 $(foreach o
,$(filter-out $(modules-m
), $(patsubst %.o
,%.mo
,$($1))), \
216 $(eval
$o-objs
+= module-common.o
)
217 $(eval
$o: $($o-objs
))
218 $(eval modules-objs-m
+= $($o-objs
))
219 $(eval modules-m
+= $o)
220 $(eval
$o:; $$(call quiet-command
,touch
$$@
," GEN $$(TARGET_DIR)$$@"))
221 $(if
$(CONFIG_MODULES
),$(eval modules
: $(patsubst %.mo
,%$(DSOSUF
),$o)))) \
222 $(eval modules-objs-m
:= $(sort $(modules-objs-m
)))
223 $(foreach o
,$(modules-objs-m
), \
224 $(if
$(CONFIG_MODULES
),$(eval
$o-cflags
:= $(call maybe-add
, $(DSO_CFLAGS
), $($o-cflags
)))))
225 $(eval
$(patsubst %-m
,%-$(call lnot
,$(CONFIG_MODULES
)),$1) += $($1))
230 $(eval nested-vars
:= $2)
231 $(eval old-nested-dirs
:= )
232 $(call unnest-vars-1
)
233 $(if
$1,$(foreach v
,$(nested-vars
),$(eval \
234 $v := $(addprefix $1/,$($v)))))
235 $(foreach var
,$(nested-vars
),$(eval
$(var
) := $(filter-out %/, $($(var
)))))
236 $(shell mkdir
-p
$(sort $(foreach var
,$(nested-vars
),$(dir $($(var
))))))
237 $(foreach var
,$(nested-vars
), $(eval \
238 -include $(addsuffix *.d
, $(sort $(dir $($(var
)))))))
239 $(foreach v
,$(filter %-m
,$(nested-vars
)), \
240 $(call process-modules
,$v))