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
-Wno-override-init
-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
)
26 $(call quiet-command
,$(CC
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," CC $(TARGET_DIR)$@")
28 $(call quiet-command
,$(WINDRES
) -I.
-o
$@
$<," RC $(TARGET_DIR)$@")
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
))
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)$@")
39 LIBTOOL
+= $(if
$(V
),,--quiet
)
41 $(call quiet-command
,$(LIBTOOL
) --mode
=compile
--tag
=CC
$(CC
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," lt CC $@")
43 $(call quiet-command
,$(LIBTOOL
) --mode
=compile
--tag
=RC
$(WINDRES
) -I.
-o
$@
$<,"lt RC $(TARGET_DIR)$@")
45 $(call quiet-command
,$(LIBTOOL
) --mode
=compile
--tag
=CC dtrace
-o
$@
-G
-s
$<, " lt GEN $(TARGET_DIR)$@")
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)$@")
57 $(call quiet-command
,$(CPP
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -o
$@
$<," CPP $(TARGET_DIR)$@")
60 $(call quiet-command
,$(AS
) $(ASFLAGS
) -o
$@
$<," AS $(TARGET_DIR)$@")
63 $(call quiet-command
,$(CXX
) $(QEMU_INCLUDES
) $(QEMU_CXXFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," CXX $(TARGET_DIR)$@")
66 $(call quiet-command
,$(CXX
) $(QEMU_INCLUDES
) $(QEMU_CXXFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," CXX $(TARGET_DIR)$@")
69 $(call quiet-command
,$(OBJCC
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," OBJC $(TARGET_DIR)$@")
72 $(call quiet-command
,dtrace
-o
$@
-G
-s
$<, " GEN $(TARGET_DIR)$@")
78 $(call quiet-command
,rm -f
$@
&& $(AR
) rcs
$@
$^
," AR $(TARGET_DIR)$@")
80 quiet-command
= $(if
$(V
),$1,$(if
$(2),@echo
$2 && $1, @
$1))
83 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
85 cc-option
= $(if
$(shell $(CC
) $1 $2 -S
-o
/dev
/null
-xc
/dev
/null \
86 >/dev
/null
2>&1 && echo OK
), $2, $3)
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)))
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
96 find-in-path
= $(if
$(find-string
/, $1), \
98 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH
)))))
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))
105 lnot
= $(if
$(subst n
,,$1),n
,y
)
107 land
= $(if
$(findstring yy
,$1$2),y
,n
)
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)
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.
121 eq
= $(if
$(subst $2,,$1)$(subst $1,,$2),n
,y
)
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
)
128 # Generate files with tracetool
129 TRACETOOL
=$(PYTHON
) $(SRC_PATH
)/scripts
/tracetool.py
131 # Generate timestamp files for .h include files
133 config-
%.h
: config-
%.h-timestamp
134 @cmp
$< $@
>/dev
/null
2>&1 || cp
$< $@
136 config-
%.h-timestamp
: config-
%.mak
137 $(call quiet-command
, sh
$(SRC_PATH
)/scripts
/create_config
< $< > $@
, " GEN $(TARGET_DIR)config-$*.h")
139 .PHONY
: clean-timestamp
142 clean: clean-timestamp
144 # will delete the target of a rule if commands exit with a nonzero exit status
147 # magic to descend into other directories
153 $(eval save-
$2-$1 = $(value
$1))
158 $(eval subdir-
$2-$1 := $(if
$(filter $2,$(save-
$2-$1)),$(addprefix $2,$($1))))
159 $(eval
$1 = $(value save-
$2-$1) $$(subdir-
$2-$1))
160 $(eval save-
$2-$1 :=)
164 $(foreach var
,$(nested-vars
),$(call push-var
,$(var
),$1/))
165 $(eval obj
:= $(obj
)/$1)
166 $(eval
include $(SRC_PATH
)/$1/Makefile.objs
)
167 $(eval obj
:= $(patsubst %/$1,%,$(obj
)))
168 $(foreach var
,$(nested-vars
),$(call pop-var
,$(var
),$1/))
172 $(eval nested-dirs
:= $(filter-out \
173 $(old-nested-dirs
), \
174 $(sort $(foreach var
,$(nested-vars
), $(filter %/, $($(var
)))))))
176 $(foreach dir,$(nested-dirs
),$(call unnest-dir
,$(patsubst %/,%,$(dir))))
177 $(eval old-nested-dirs
:= $(old-nested-dirs
) $(nested-dirs
))
178 $(call unnest-vars-1
))
182 $(call unnest-vars-1
)
183 $(foreach var
,$(nested-vars
),$(eval
$(var
) := $(filter-out %/, $($(var
)))))
184 $(shell mkdir
-p
$(sort $(foreach var
,$(nested-vars
),$(dir $($(var
))))))
185 $(foreach var
,$(nested-vars
), $(eval \
186 -include $(addsuffix *.d
, $(sort $(dir $($(var
)))))))