meson: Fix meson build with --enable-libdaxctl
[qemu/ar7.git] / rules.mak
blob83aaf57f0958c4e70dee4f36afc8df6a77ace2cb
2 # These are used when we want to do substitutions without confusing Make
3 NULL :=
4 SPACE := $(NULL) #
5 COMMA := ,
7 # Don't use implicit rules or variables
8 # we have explicit rules for everything
9 MAKEFLAGS += -rR
11 # Files with this suffixes are final, don't try to generate them
12 # using implicit rules
13 %/trace-events:
14 %.hx:
15 %.py:
16 %.objs:
17 %.d:
18 %.h:
19 %.c:
20 %.cc:
21 %.cpp:
22 %.m:
23 %.mak:
25 # Flags for C++ compilation
26 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_CXXFLAGS})
28 # Flags for dependency generation
29 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d
31 # Compiler searches the source file dir first, but in vpath builds
32 # we need to make it search the build dir too, before any other
33 # explicit search paths. There are two search locations in the build
34 # dir, one absolute and the other relative to the compiler working
35 # directory. These are the same for target-independent files, but
36 # different for target-dependent ones.
37 QEMU_LOCAL_INCLUDES = -iquote $(BUILD_DIR) -iquote $(BUILD_DIR)/$(@D) -iquote $(@D)
39 WL := -Wl,
40 ifdef CONFIG_DARWIN
41 whole-archive = $(WL)-force_load,$1
42 else
43 whole-archive = $(WL)--whole-archive $1 $(WL)--no-whole-archive
44 endif
46 extract-libs = $(strip $(foreach o,$1,$($o-libs)))
48 %.o: %.c
49 @mkdir -p $(dir $@)
50 $(call quiet-command,$(CC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
51 $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \
52 -c -o $@ $<,"CC","$(TARGET_DIR)$@")
54 # If we have a CXX we might have some C++ objects, in which case we
55 # must link with the C++ compiler, not the plain C compiler.
56 LINKPROG = $(or $(CXX),$(CC))
58 LINK = $(call quiet-command, $(LINKPROG) $(CFLAGS) $(QEMU_LDFLAGS) -o $@ \
59 $(filter-out %.a %.fa,$1) \
60 $(foreach l,$(filter %.fa,$1),$(call whole-archive,$l)) \
61 $(filter %.a,$1) \
62 $(call extract-libs,$1) $(LIBS),"LINK","$(TARGET_DIR)$@")
64 %.o: %.S
65 $(call quiet-command,$(CCAS) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
66 $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) \
67 -c -o $@ $<,"CCAS","$(TARGET_DIR)$@")
69 %.o: %.cc
70 $(call quiet-command,$(CXX) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
71 $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CXXFLAGS) $($@-cflags) \
72 -c -o $@ $<,"CXX","$(TARGET_DIR)$@")
74 %.o: %.cpp
75 $(call quiet-command,$(CXX) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
76 $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CXXFLAGS) $($@-cflags) \
77 -c -o $@ $<,"CXX","$(TARGET_DIR)$@")
79 %.o: %.m
80 $(call quiet-command,$(OBJCC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
81 $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \
82 -c -o $@ $<,"OBJC","$(TARGET_DIR)$@")
84 %.o: %.dtrace
85 $(call quiet-command,dtrace -o $@ -G -s $<,"GEN","$(TARGET_DIR)$@")
87 .PHONY: modules
88 modules:
90 %$(EXESUF): %.o
91 $(call LINK,$(filter %.o %.a %.fa, $^))
93 %.a:
94 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"AR","$(TARGET_DIR)$@")
96 # Usage: $(call quiet-command,command and args,"NAME","args to print")
97 # This will run "command and args", and either:
98 # if V=1 just print the whole command and args
99 # otherwise print the 'quiet' output in the format " NAME args to print"
100 # NAME should be a short name of the command, 7 letters or fewer.
101 # If called with only a single argument, will print nothing in quiet mode.
102 quiet-command-run = $(if $(V),,$(if $2,printf " %-7s %s\n" $2 $3 && ))$1
103 quiet-@ = $(if $(V),,@)
104 quiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3)
106 # cc-option
107 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
109 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
110 >/dev/null 2>&1 && echo OK), $2, $3)
111 cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \
112 >/dev/null 2>&1 && echo OK), $2, $3)
114 VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc Kconfig% %.json.in
115 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
117 # install-prog list, dir
118 define install-prog
119 $(INSTALL_DIR) "$2"
120 $(INSTALL_PROG) $1 "$2"
121 $(if $(STRIP),$(STRIP) $(foreach T,$1,"$2/$(notdir $T)"),)
122 endef
124 # Logical functions (for operating on y/n values like CONFIG_FOO vars)
125 # Inputs to these must be either "y" (true) or "n" or "" (both false)
126 # Output is always either "y" or "n".
127 # Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
128 # Logical NOT
129 lnot = $(if $(subst n,,$1),n,y)
130 # Logical AND
131 land = $(if $(findstring yy,$1$2),y,n)
132 # Logical OR
133 lor = $(if $(findstring y,$1$2),y,n)
134 # Logical XOR (note that this is the inverse of leqv)
135 lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y)
136 # Logical equivalence (note that leqv "","n" is true)
137 leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n)
138 # Logical if: like make's $(if) but with an leqv-like test
139 lif = $(if $(subst n,,$1),$2,$3)
141 # String testing functions: inputs to these can be any string;
142 # the output is always either "y" or "n". Leading and trailing whitespace
143 # is ignored when comparing strings.
144 # String equality
145 eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
146 # String inequality
147 ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n)
148 # Emptiness/non-emptiness tests:
149 isempty = $(if $1,n,y)
150 notempty = $(if $1,y,n)
152 .PHONY: clean-timestamp
153 clean-timestamp:
154 rm -f *.timestamp
155 clean: clean-timestamp
157 # will delete the target of a rule if commands exit with a nonzero exit status
158 .DELETE_ON_ERROR:
160 print-%:
161 @echo '$*=$($*)'