2 # These are used when we want to do substitutions without confusing Make
7 # Don't use implicit rules or variables
8 # we have explicit rules for everything
11 # Files with this suffixes are final, don't try to generate them
12 # using implicit rules
25 # Flags for dependency generation
26 QEMU_DGFLAGS
+= -MMD
-MP
-MT
$@
-MF
$(@D
)/$(*F
).d
28 # Compiler searches the source file dir first, but in vpath builds
29 # we need to make it search the build dir too, before any other
30 # explicit search paths. There are two search locations in the build
31 # dir, one absolute and the other relative to the compiler working
32 # directory. These are the same for target-independent files, but
33 # different for target-dependent ones.
34 QEMU_LOCAL_INCLUDES
= -iquote
$(BUILD_DIR
) -iquote
$(BUILD_DIR
)/$(@D
) -iquote
$(@D
)
38 whole-archive
= $(WL
)-force_load
,$1
40 whole-archive
= $(WL
)--whole-archive
$1 $(WL
)--no-whole-archive
43 extract-libs
= $(strip $(foreach o
,$1,$($o-libs
)))
47 $(call quiet-command
,$(CC
) $(QEMU_LOCAL_INCLUDES
) $(QEMU_INCLUDES
) \
48 $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) $($@
-cflags) \
49 -c
-o
$@
$<,"CC","$(TARGET_DIR)$@")
51 # If we have a CXX we might have some C++ objects, in which case we
52 # must link with the C++ compiler, not the plain C compiler.
53 LINKPROG
= $(or
$(CXX
),$(CC
))
55 LINK
= $(call quiet-command
, $(LINKPROG
) $(CFLAGS
) $(QEMU_LDFLAGS
) -o
$@ \
56 $(filter-out %.a
%.fa
,$1) \
57 $(foreach l
,$(filter %.fa
,$1),$(call whole-archive
,$l)) \
59 $(call extract-libs
,$1) $(LIBS
),"LINK","$(TARGET_DIR)$@")
62 $(call quiet-command
,$(CCAS
) $(QEMU_LOCAL_INCLUDES
) $(QEMU_INCLUDES
) \
63 $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) \
64 -c
-o
$@
$<,"CCAS","$(TARGET_DIR)$@")
67 $(call quiet-command
,$(CXX
) $(QEMU_LOCAL_INCLUDES
) $(QEMU_INCLUDES
) \
68 $(QEMU_CXXFLAGS
) $(QEMU_DGFLAGS
) $(CXXFLAGS
) $($@
-cflags) \
69 -c
-o
$@
$<,"CXX","$(TARGET_DIR)$@")
72 $(call quiet-command
,$(CXX
) $(QEMU_LOCAL_INCLUDES
) $(QEMU_INCLUDES
) \
73 $(QEMU_CXXFLAGS
) $(QEMU_DGFLAGS
) $(CXXFLAGS
) $($@
-cflags) \
74 -c
-o
$@
$<,"CXX","$(TARGET_DIR)$@")
77 $(call quiet-command
,$(OBJCC
) $(QEMU_LOCAL_INCLUDES
) $(QEMU_INCLUDES
) \
78 $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) $($@
-cflags) \
79 -c
-o
$@
$<,"OBJC","$(TARGET_DIR)$@")
82 $(call quiet-command
,dtrace
-o
$@
-G
-s
$<,"GEN","$(TARGET_DIR)$@")
88 $(call LINK
,$(filter %.o
%.a
%.fa
, $^
))
91 $(call quiet-command
,rm -f
$@
&& $(AR
) rcs
$@
$^
,"AR","$(TARGET_DIR)$@")
93 # Usage: $(call quiet-command,command and args,"NAME","args to print")
94 # This will run "command and args", and either:
95 # if V=1 just print the whole command and args
96 # otherwise print the 'quiet' output in the format " NAME args to print"
97 # NAME should be a short name of the command, 7 letters or fewer.
98 # If called with only a single argument, will print nothing in quiet mode.
99 quiet-command-run
= $(if
$(V
),,$(if
$2,printf
" %-7s %s\n" $2 $3 && ))$1
100 quiet-@
= $(if
$(V
),,@
)
101 quiet-command
= $(quiet-@
)$(call quiet-command-run
,$1,$2,$3)
104 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
106 cc-option
= $(if
$(shell $(CC
) $1 $2 -S
-o
/dev
/null
-xc
/dev
/null \
107 >/dev
/null
2>&1 && echo OK
), $2, $3)
108 cc-c-option
= $(if
$(shell $(CC
) $1 $2 -c
-o
/dev
/null
-xc
/dev
/null \
109 >/dev
/null
2>&1 && echo OK
), $2, $3)
111 VPATH_SUFFIXES
= %.c
%.h
%.S
%.
cc %.
cpp %.m
%.mak
%.texi
%.sh
%.rc Kconfig
% %.json.in
112 set-vpath
= $(if
$1,$(foreach PATTERN
,$(VPATH_SUFFIXES
),$(eval vpath
$(PATTERN
) $1)))
114 # install-prog list, dir
117 $(INSTALL_PROG
) $1 "$2"
118 $(if
$(STRIP
),$(STRIP
) $(foreach T
,$1,"$2/$(notdir $T)"),)
121 # Logical functions (for operating on y/n values like CONFIG_FOO vars)
122 # Inputs to these must be either "y" (true) or "n" or "" (both false)
123 # Output is always either "y" or "n".
124 # Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
126 lnot
= $(if
$(subst n
,,$1),n
,y
)
128 land
= $(if
$(findstring yy
,$1$2),y
,n
)
130 lor
= $(if
$(findstring y
,$1$2),y
,n
)
131 # Logical XOR (note that this is the inverse of leqv)
132 lxor
= $(if
$(filter $(call lnot
,$1),$(call lnot
,$2)),n
,y
)
133 # Logical equivalence (note that leqv "","n" is true)
134 leqv
= $(if
$(filter $(call lnot
,$1),$(call lnot
,$2)),y
,n
)
135 # Logical if: like make's $(if) but with an leqv-like test
136 lif
= $(if
$(subst n
,,$1),$2,$3)
138 # String testing functions: inputs to these can be any string;
139 # the output is always either "y" or "n". Leading and trailing whitespace
140 # is ignored when comparing strings.
142 eq
= $(if
$(subst $2,,$1)$(subst $1,,$2),n
,y
)
144 ne
= $(if
$(subst $2,,$1)$(subst $1,,$2),y
,n
)
145 # Emptiness/non-emptiness tests:
146 isempty
= $(if
$1,n
,y
)
147 notempty
= $(if
$1,y
,n
)
149 .PHONY
: clean-timestamp
152 clean: clean-timestamp
154 # will delete the target of a rule if commands exit with a nonzero exit status