]>
Commit | Line | Data |
---|---|---|
17759187 | 1 | |
5609c512 AB |
2 | # These are used when we want to do substitutions without confusing Make |
3 | NULL := | |
4 | SPACE := $(NULL) # | |
2f4e4dc2 FZ |
5 | COMMA := , |
6 | ||
5ab28867 JQ |
7 | # Don't use implicit rules or variables |
8 | # we have explicit rules for everything | |
9 | MAKEFLAGS += -rR | |
10 | ||
11 | # Files with this suffixes are final, don't try to generate them | |
12 | # using implicit rules | |
a273f4ce PB |
13 | %/trace-events: |
14 | %.hx: | |
15 | %.py: | |
16 | %.objs: | |
5ab28867 JQ |
17 | %.d: |
18 | %.h: | |
19 | %.c: | |
c3dc9fd5 | 20 | %.cc: |
83f73fce | 21 | %.cpp: |
5ab28867 JQ |
22 | %.m: |
23 | %.mak: | |
24 | ||
7ebf54bc | 25 | # Flags for dependency generation |
998b7b1d | 26 | QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d |
02d5467e | 27 | |
ba78db44 DB |
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. | |
a81df1b6 | 34 | QEMU_LOCAL_INCLUDES = -iquote $(BUILD_DIR) -iquote $(BUILD_DIR)/$(@D) -iquote $(@D) |
9d9199a0 | 35 | |
1f0a1d8a MAL |
36 | WL := -Wl, |
37 | ifdef CONFIG_DARWIN | |
38 | whole-archive = $(WL)-force_load,$1 | |
39 | else | |
40 | whole-archive = $(WL)--whole-archive $1 $(WL)--no-whole-archive | |
41 | endif | |
42 | ||
484e2cc7 | 43 | extract-libs = $(strip $(foreach o,$1,$($o-libs))) |
5c0d52bc | 44 | |
0e8c9214 | 45 | %.o: %.c |
ac76f9d1 | 46 | @mkdir -p $(dir $@) |
ba78db44 DB |
47 | $(call quiet-command,$(CC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ |
48 | $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \ | |
49 | -c -o $@ $<,"CC","$(TARGET_DIR)$@") | |
17759187 | 50 | |
3144f78b PM |
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)) | |
54 | ||
db5adeaa | 55 | LINK = $(call quiet-command, $(LINKPROG) $(CFLAGS) $(QEMU_LDFLAGS) -o $@ \ |
484e2cc7 PB |
56 | $(filter-out %.a %.fa,$1) \ |
57 | $(foreach l,$(filter %.fa,$1),$(call whole-archive,$l)) \ | |
58 | $(filter %.a,$1) \ | |
8000047e | 59 | $(call extract-libs,$1) $(LIBS),"LINK","$(TARGET_DIR)$@") |
44dc0ca3 | 60 | |
5f6f0e27 | 61 | %.o: %.S |
ba78db44 DB |
62 | $(call quiet-command,$(CCAS) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ |
63 | $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) \ | |
64 | -c -o $@ $<,"CCAS","$(TARGET_DIR)$@") | |
17759187 | 65 | |
c3dc9fd5 | 66 | %.o: %.cc |
ba78db44 | 67 | $(call quiet-command,$(CXX) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ |
086d5f75 | 68 | $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CXXFLAGS) $($@-cflags) \ |
ba78db44 | 69 | -c -o $@ $<,"CXX","$(TARGET_DIR)$@") |
c3dc9fd5 | 70 | |
83f73fce | 71 | %.o: %.cpp |
ba78db44 | 72 | $(call quiet-command,$(CXX) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ |
086d5f75 | 73 | $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CXXFLAGS) $($@-cflags) \ |
ba78db44 | 74 | -c -o $@ $<,"CXX","$(TARGET_DIR)$@") |
83f73fce | 75 | |
17759187 | 76 | %.o: %.m |
ba78db44 DB |
77 | $(call quiet-command,$(OBJCC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ |
78 | $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \ | |
79 | -c -o $@ $<,"OBJC","$(TARGET_DIR)$@") | |
17759187 | 80 | |
2c13ec50 | 81 | %.o: %.dtrace |
0bdb12c7 | 82 | $(call quiet-command,dtrace -o $@ -G -s $<,"GEN","$(TARGET_DIR)$@") |
2c13ec50 | 83 | |
17969268 FZ |
84 | .PHONY: modules |
85 | modules: | |
86 | ||
3aa892d7 | 87 | %$(EXESUF): %.o |
484e2cc7 | 88 | $(call LINK,$(filter %.o %.a %.fa, $^)) |
4f188f88 | 89 | |
93a0dba7 | 90 | %.a: |
0bdb12c7 | 91 | $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"AR","$(TARGET_DIR)$@") |
93a0dba7 | 92 | |
0bdb12c7 PM |
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. | |
9df43317 PB |
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) | |
70071e17 JQ |
102 | |
103 | # cc-option | |
8a2e6ab5 | 104 | # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0) |
70071e17 | 105 | |
fc3baad7 TM |
106 | cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \ |
107 | >/dev/null 2>&1 && echo OK), $2, $3) | |
036999e9 PB |
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) | |
1215c6e7 | 110 | |
d52c454a | 111 | VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc Kconfig% %.json.in |
288e7bcc | 112 | set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1))) |
076d2471 | 113 | |
0d659426 MT |
114 | # install-prog list, dir |
115 | define install-prog | |
116 | $(INSTALL_DIR) "$2" | |
117 | $(INSTALL_PROG) $1 "$2" | |
118 | $(if $(STRIP),$(STRIP) $(foreach T,$1,"$2/$(notdir $T)"),) | |
119 | endef | |
120 | ||
837a2e26 PM |
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)) | |
125 | # Logical NOT | |
126 | lnot = $(if $(subst n,,$1),n,y) | |
127 | # Logical AND | |
128 | land = $(if $(findstring yy,$1$2),y,n) | |
129 | # Logical OR | |
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) | |
137 | ||
9ef622e3 PM |
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. | |
141 | # String equality | |
142 | eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y) | |
143 | # String inequality | |
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) | |
148 | ||
7586317b MT |
149 | .PHONY: clean-timestamp |
150 | clean-timestamp: | |
151 | rm -f *.timestamp | |
152 | clean: clean-timestamp | |
153 | ||
7dbbbb0c MT |
154 | # will delete the target of a rule if commands exit with a nonzero exit status |
155 | .DELETE_ON_ERROR: | |
e05804ee | 156 | |
1a28f878 PMD |
157 | print-%: |
158 | @echo '$*=$($*)' |