aliguori | 1775918 | 2009-01-21 18:12:52 +0000 | [diff] [blame] | 1 | |
Fam Zheng | 2f4e4dc | 2016-06-01 12:25:15 +0800 | [diff] [blame] | 2 | COMMA := , |
| 3 | |
Juan Quintela | 5ab2886 | 2009-10-06 21:11:14 +0200 | [diff] [blame] | 4 | # Don't use implicit rules or variables |
| 5 | # we have explicit rules for everything |
| 6 | MAKEFLAGS += -rR |
| 7 | |
| 8 | # Files with this suffixes are final, don't try to generate them |
| 9 | # using implicit rules |
| 10 | %.d: |
| 11 | %.h: |
| 12 | %.c: |
Peter Maydell | c3dc9fd | 2014-02-05 17:27:27 +0000 | [diff] [blame] | 13 | %.cc: |
Tomoki Sekiyama | 83f73fc | 2013-08-07 11:39:36 -0400 | [diff] [blame] | 14 | %.cpp: |
Juan Quintela | 5ab2886 | 2009-10-06 21:11:14 +0200 | [diff] [blame] | 15 | %.m: |
| 16 | %.mak: |
| 17 | |
Tomoki Sekiyama | 83f73fc | 2013-08-07 11:39:36 -0400 | [diff] [blame] | 18 | # Flags for C++ compilation |
| 19 | QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS)) |
| 20 | |
Stefan Weil | 7ebf54b | 2009-11-19 20:07:52 +0100 | [diff] [blame] | 21 | # Flags for dependency generation |
Victor Kaplansky | 998b7b1 | 2015-08-09 12:39:53 +0300 | [diff] [blame] | 22 | QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d |
malc | 02d5467 | 2009-10-11 17:08:57 +0400 | [diff] [blame] | 23 | |
Paolo Bonzini | 9d9199a | 2012-09-17 10:21:52 +0200 | [diff] [blame] | 24 | # Same as -I$(SRC_PATH) -I., but for the nested source/object directories |
Dunrong Huang | 7e7da8e | 2013-04-29 22:52:12 +0800 | [diff] [blame] | 25 | QEMU_INCLUDES += -I$(<D) -I$(@D) |
Paolo Bonzini | 9d9199a | 2012-09-17 10:21:52 +0200 | [diff] [blame] | 26 | |
Fam Zheng | c261d77 | 2014-09-01 18:35:10 +0800 | [diff] [blame] | 27 | WL_U := -Wl,-u, |
Stefan Weil | 4852ee9 | 2014-09-18 21:55:08 +0200 | [diff] [blame] | 28 | find-symbols = $(if $1, $(sort $(shell $(NM) -P -g $1 | $2))) |
Fam Zheng | c261d77 | 2014-09-01 18:35:10 +0800 | [diff] [blame] | 29 | defined-symbols = $(call find-symbols,$1,awk '$$2!="U"{print $$1}') |
| 30 | undefined-symbols = $(call find-symbols,$1,awk '$$2=="U"{print $$1}') |
| 31 | |
| 32 | # All the .mo objects in -m variables are also added into corresponding -y |
| 33 | # variable in unnest-vars, but filtered out here, when LINK is called. |
| 34 | # |
| 35 | # The .mo objects are supposed to be linked as a DSO, for module build. So here |
| 36 | # they are only used as a placeholders to generate those "archive undefined" |
| 37 | # symbol options (-Wl,-u,$symbol_name), which are the archive functions |
| 38 | # referenced by the code in the DSO. |
| 39 | # |
| 40 | # Also the presence in -y variables will also guarantee they are built before |
| 41 | # linking executables that will load them. So we can look up symbol reference |
| 42 | # in LINK. |
| 43 | # |
| 44 | # This is necessary because the exectuable itself may not use the function, in |
| 45 | # which case the function would not be linked in. Then the DSO loading will |
| 46 | # fail because of the missing symbol. |
| 47 | process-archive-undefs = $(filter-out %.a %.mo,$1) \ |
| 48 | $(addprefix $(WL_U), \ |
| 49 | $(filter $(call defined-symbols,$(filter %.a, $1)), \ |
| 50 | $(call undefined-symbols,$(filter %.mo,$1)))) \ |
| 51 | $(filter %.a,$1) |
| 52 | |
Paolo Bonzini | f277015 | 2014-06-16 16:43:25 +0200 | [diff] [blame] | 53 | extract-libs = $(strip $(foreach o,$1,$($o-libs))) |
Fam Zheng | 1796926 | 2014-02-10 14:48:56 +0800 | [diff] [blame] | 54 | expand-objs = $(strip $(sort $(filter %.o,$1)) \ |
| 55 | $(foreach o,$(filter %.mo,$1),$($o-objs)) \ |
| 56 | $(filter-out %.o %.mo,$1)) |
Fam Zheng | 5c0d52b | 2014-02-10 14:48:53 +0800 | [diff] [blame] | 57 | |
Andreas Färber | 0e8c921 | 2010-01-06 20:24:05 +0100 | [diff] [blame] | 58 | %.o: %.c |
Fam Zheng | 5c0d52b | 2014-02-10 14:48:53 +0800 | [diff] [blame] | 59 | $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CC $(TARGET_DIR)$@") |
Paolo Bonzini | 6821cdc | 2013-04-27 00:25:31 +0200 | [diff] [blame] | 60 | %.o: %.rc |
| 61 | $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@") |
aliguori | 1775918 | 2009-01-21 18:12:52 +0000 | [diff] [blame] | 62 | |
Peter Maydell | 3144f78 | 2014-02-05 17:27:27 +0000 | [diff] [blame] | 63 | # If we have a CXX we might have some C++ objects, in which case we |
| 64 | # must link with the C++ compiler, not the plain C compiler. |
| 65 | LINKPROG = $(or $(CXX),$(CC)) |
| 66 | |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 67 | LINK = $(call quiet-command, $(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ |
Fam Zheng | c261d77 | 2014-09-01 18:35:10 +0800 | [diff] [blame] | 68 | $(call process-archive-undefs, $1) \ |
| 69 | $(version-obj-y) $(call extract-libs,$1) $(LIBS)," LINK $(TARGET_DIR)$@") |
Alon Levy | 44dc0ca | 2011-05-15 11:51:28 +0300 | [diff] [blame] | 70 | |
Blue Swirl | 3dd46c7 | 2013-01-05 10:10:27 +0000 | [diff] [blame] | 71 | %.asm: %.S |
| 72 | $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@") |
| 73 | |
| 74 | %.o: %.asm |
| 75 | $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@") |
aliguori | 1775918 | 2009-01-21 18:12:52 +0000 | [diff] [blame] | 76 | |
Peter Maydell | c3dc9fd | 2014-02-05 17:27:27 +0000 | [diff] [blame] | 77 | %.o: %.cc |
Paolo Bonzini | 0db564e | 2014-05-08 14:34:09 +0200 | [diff] [blame] | 78 | $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CXX $(TARGET_DIR)$@") |
Peter Maydell | c3dc9fd | 2014-02-05 17:27:27 +0000 | [diff] [blame] | 79 | |
Tomoki Sekiyama | 83f73fc | 2013-08-07 11:39:36 -0400 | [diff] [blame] | 80 | %.o: %.cpp |
Paolo Bonzini | 0db564e | 2014-05-08 14:34:09 +0200 | [diff] [blame] | 81 | $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CXX $(TARGET_DIR)$@") |
Tomoki Sekiyama | 83f73fc | 2013-08-07 11:39:36 -0400 | [diff] [blame] | 82 | |
aliguori | 1775918 | 2009-01-21 18:12:52 +0000 | [diff] [blame] | 83 | %.o: %.m |
Paolo Bonzini | 0db564e | 2014-05-08 14:34:09 +0200 | [diff] [blame] | 84 | $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," OBJC $(TARGET_DIR)$@") |
aliguori | 1775918 | 2009-01-21 18:12:52 +0000 | [diff] [blame] | 85 | |
Paolo Bonzini | 2c13ec5 | 2012-12-21 09:23:18 +0100 | [diff] [blame] | 86 | %.o: %.dtrace |
| 87 | $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@") |
| 88 | |
Fam Zheng | d24697e | 2015-05-07 14:55:15 +0800 | [diff] [blame] | 89 | DSO_OBJ_CFLAGS := -fPIC -DBUILD_DSO |
| 90 | module-common.o: CFLAGS += $(DSO_OBJ_CFLAGS) |
Fam Zheng | 1796926 | 2014-02-10 14:48:56 +0800 | [diff] [blame] | 91 | %$(DSOSUF): LDFLAGS += $(LDFLAGS_SHARED) |
Fam Zheng | c261d77 | 2014-09-01 18:35:10 +0800 | [diff] [blame] | 92 | %$(DSOSUF): %.mo |
Fam Zheng | 1796926 | 2014-02-10 14:48:56 +0800 | [diff] [blame] | 93 | $(call LINK,$^) |
Fam Zheng | e26110c | 2014-02-10 14:48:57 +0800 | [diff] [blame] | 94 | @# Copy to build root so modules can be loaded when program started without install |
| 95 | $(if $(findstring /,$@),$(call quiet-command,cp $@ $(subst /,-,$@), " CP $(subst /,-,$@)")) |
Fam Zheng | 1796926 | 2014-02-10 14:48:56 +0800 | [diff] [blame] | 96 | |
Fam Zheng | c261d77 | 2014-09-01 18:35:10 +0800 | [diff] [blame] | 97 | |
James Clarke | 6969ec6 | 2016-06-06 12:02:50 +0100 | [diff] [blame] | 98 | LD_REL := $(CC) -nostdlib -Wl,-r $(LD_REL_FLAGS) |
Fam Zheng | c261d77 | 2014-09-01 18:35:10 +0800 | [diff] [blame] | 99 | |
| 100 | %.mo: |
| 101 | $(call quiet-command,$(LD_REL) -o $@ $^," LD -r $(TARGET_DIR)$@") |
| 102 | |
Fam Zheng | 1796926 | 2014-02-10 14:48:56 +0800 | [diff] [blame] | 103 | .PHONY: modules |
| 104 | modules: |
| 105 | |
aliguori | 3aa892d | 2009-01-21 18:13:02 +0000 | [diff] [blame] | 106 | %$(EXESUF): %.o |
Michael S. Tsirkin | cefa2bb | 2016-02-17 16:59:36 +0200 | [diff] [blame] | 107 | $(call LINK,$(filter %.o %.a %.mo, $^)) |
aliguori | 4f188f8 | 2009-01-21 18:13:09 +0000 | [diff] [blame] | 108 | |
aliguori | 93a0dba | 2009-01-21 18:13:16 +0000 | [diff] [blame] | 109 | %.a: |
aliguori | 28c699a | 2009-01-26 17:07:46 +0000 | [diff] [blame] | 110 | $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@") |
aliguori | 93a0dba | 2009-01-21 18:13:16 +0000 | [diff] [blame] | 111 | |
aliguori | 28c699a | 2009-01-26 17:07:46 +0000 | [diff] [blame] | 112 | quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1)) |
Juan Quintela | 70071e1 | 2009-07-21 14:11:18 +0200 | [diff] [blame] | 113 | |
| 114 | # cc-option |
Juan Quintela | 8a2e6ab | 2009-08-31 00:48:45 +0200 | [diff] [blame] | 115 | # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0) |
Juan Quintela | 70071e1 | 2009-07-21 14:11:18 +0200 | [diff] [blame] | 116 | |
Thomas Monjalon | fc3baad | 2009-09-11 18:45:40 +0200 | [diff] [blame] | 117 | cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \ |
| 118 | >/dev/null 2>&1 && echo OK), $2, $3) |
Juan Quintela | 1215c6e | 2009-10-07 02:40:58 +0200 | [diff] [blame] | 119 | |
Peter Maydell | c3dc9fd | 2014-02-05 17:27:27 +0000 | [diff] [blame] | 120 | VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc |
Nathan Froyd | 288e7bc | 2010-04-26 14:52:23 -0700 | [diff] [blame] | 121 | set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1))) |
Paolo Bonzini | 076d247 | 2009-12-21 10:06:55 +0100 | [diff] [blame] | 122 | |
Michael Tokarev | 0d65942 | 2014-06-22 10:55:23 +0400 | [diff] [blame] | 123 | # install-prog list, dir |
| 124 | define install-prog |
| 125 | $(INSTALL_DIR) "$2" |
| 126 | $(INSTALL_PROG) $1 "$2" |
| 127 | $(if $(STRIP),$(STRIP) $(foreach T,$1,"$2/$(notdir $T)"),) |
| 128 | endef |
| 129 | |
Paolo Bonzini | 2b2e59e | 2010-10-21 10:18:40 +0200 | [diff] [blame] | 130 | # find-in-path |
| 131 | # Usage: $(call find-in-path, prog) |
| 132 | # Looks in the PATH if the argument contains no slash, else only considers one |
| 133 | # specific directory. Returns an # empty string if the program doesn't exist |
| 134 | # there. |
| 135 | find-in-path = $(if $(find-string /, $1), \ |
| 136 | $(wildcard $1), \ |
| 137 | $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH))))) |
| 138 | |
Peter Maydell | 837a2e2 | 2013-09-13 18:25:51 +0100 | [diff] [blame] | 139 | # Logical functions (for operating on y/n values like CONFIG_FOO vars) |
| 140 | # Inputs to these must be either "y" (true) or "n" or "" (both false) |
| 141 | # Output is always either "y" or "n". |
| 142 | # Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR)) |
| 143 | # Logical NOT |
| 144 | lnot = $(if $(subst n,,$1),n,y) |
| 145 | # Logical AND |
| 146 | land = $(if $(findstring yy,$1$2),y,n) |
| 147 | # Logical OR |
| 148 | lor = $(if $(findstring y,$1$2),y,n) |
| 149 | # Logical XOR (note that this is the inverse of leqv) |
| 150 | lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y) |
| 151 | # Logical equivalence (note that leqv "","n" is true) |
| 152 | leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n) |
| 153 | # Logical if: like make's $(if) but with an leqv-like test |
| 154 | lif = $(if $(subst n,,$1),$2,$3) |
| 155 | |
Peter Maydell | 9ef622e | 2013-09-13 18:25:52 +0100 | [diff] [blame] | 156 | # String testing functions: inputs to these can be any string; |
| 157 | # the output is always either "y" or "n". Leading and trailing whitespace |
| 158 | # is ignored when comparing strings. |
| 159 | # String equality |
| 160 | eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y) |
| 161 | # String inequality |
| 162 | ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n) |
| 163 | # Emptiness/non-emptiness tests: |
| 164 | isempty = $(if $1,n,y) |
| 165 | notempty = $(if $1,y,n) |
| 166 | |
Lluís Vilanova | c042493 | 2012-04-18 20:15:45 +0200 | [diff] [blame] | 167 | # Generate files with tracetool |
| 168 | TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py |
| 169 | |
Juan Quintela | 1215c6e | 2009-10-07 02:40:58 +0200 | [diff] [blame] | 170 | # Generate timestamp files for .h include files |
| 171 | |
Michael S. Tsirkin | 4b25966 | 2013-01-15 13:12:35 +0200 | [diff] [blame] | 172 | config-%.h: config-%.h-timestamp |
| 173 | @cmp $< $@ >/dev/null 2>&1 || cp $< $@ |
Juan Quintela | 1215c6e | 2009-10-07 02:40:58 +0200 | [diff] [blame] | 174 | |
Paolo Bonzini | 5533501 | 2016-06-07 13:25:24 +0200 | [diff] [blame] | 175 | config-%.h-timestamp: config-%.mak $(SRC_PATH)/scripts/create_config |
Michael S. Tsirkin | 4b25966 | 2013-01-15 13:12:35 +0200 | [diff] [blame] | 176 | $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h") |
Michael S. Tsirkin | 7dbbbb0 | 2009-12-07 21:04:52 +0200 | [diff] [blame] | 177 | |
Michael S. Tsirkin | 7586317 | 2013-01-15 13:27:54 +0200 | [diff] [blame] | 178 | .PHONY: clean-timestamp |
| 179 | clean-timestamp: |
| 180 | rm -f *.timestamp |
| 181 | clean: clean-timestamp |
| 182 | |
Michael S. Tsirkin | 7dbbbb0 | 2009-12-07 21:04:52 +0200 | [diff] [blame] | 183 | # will delete the target of a rule if commands exit with a nonzero exit status |
| 184 | .DELETE_ON_ERROR: |
Paolo Bonzini | e05804e | 2012-05-22 13:41:27 +0200 | [diff] [blame] | 185 | |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 186 | # save-vars |
| 187 | # Usage: $(call save-vars, vars) |
| 188 | # Save each variable $v in $vars as save-vars-$v, save their object's |
| 189 | # variables, then clear $v. |
| 190 | define save-vars |
| 191 | $(foreach v,$1, |
| 192 | $(eval save-vars-$v := $(value $v)) |
| 193 | $(foreach o,$($v), |
| 194 | $(foreach k,cflags libs objs, |
| 195 | $(if $($o-$k), |
| 196 | $(eval save-vars-$o-$k := $($o-$k)) |
| 197 | $(eval $o-$k := )))) |
| 198 | $(eval $v := )) |
Paolo Bonzini | e05804e | 2012-05-22 13:41:27 +0200 | [diff] [blame] | 199 | endef |
| 200 | |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 201 | # load-vars |
| 202 | # Usage: $(call load-vars, vars, add_var) |
| 203 | # Load the saved value for each variable in @vars, and the per object |
| 204 | # variables. |
| 205 | # Append @add_var's current value to the loaded value. |
| 206 | define load-vars |
| 207 | $(eval $2-new-value := $(value $2)) |
| 208 | $(foreach v,$1, |
| 209 | $(eval $v := $(value save-vars-$v)) |
| 210 | $(foreach o,$($v), |
| 211 | $(foreach k,cflags libs objs, |
| 212 | $(if $(save-vars-$o-$k), |
| 213 | $(eval $o-$k := $(save-vars-$o-$k)) |
| 214 | $(eval save-vars-$o-$k := )))) |
| 215 | $(eval save-vars-$v := )) |
| 216 | $(eval $2 := $(value $2) $($2-new-value)) |
Paolo Bonzini | e05804e | 2012-05-22 13:41:27 +0200 | [diff] [blame] | 217 | endef |
| 218 | |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 219 | # fix-paths |
| 220 | # Usage: $(call fix-paths, obj_path, src_path, vars) |
| 221 | # Add prefix @obj_path to all objects in @vars, and add prefix @src_path to all |
| 222 | # directories in @vars. |
| 223 | define fix-paths |
| 224 | $(foreach v,$3, |
| 225 | $(foreach o,$($v), |
| 226 | $(if $($o-libs), |
| 227 | $(eval $1$o-libs := $($o-libs))) |
| 228 | $(if $($o-cflags), |
| 229 | $(eval $1$o-cflags := $($o-cflags))) |
| 230 | $(if $($o-objs), |
| 231 | $(eval $1$o-objs := $(addprefix $1,$($o-objs))))) |
| 232 | $(eval $v := $(addprefix $1,$(filter-out %/,$($v))) \ |
| 233 | $(addprefix $2,$(filter %/,$($v))))) |
Fam Zheng | 5c0d52b | 2014-02-10 14:48:53 +0800 | [diff] [blame] | 234 | endef |
| 235 | |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 236 | # unnest-var-recursive |
| 237 | # Usage: $(call unnest-var-recursive, obj_prefix, vars, var) |
| 238 | # |
| 239 | # Unnest @var by including subdir Makefile.objs, while protect others in @vars |
| 240 | # unchanged. |
| 241 | # |
| 242 | # @obj_prefix is the starting point of object path prefix. |
| 243 | # |
| 244 | define unnest-var-recursive |
| 245 | $(eval dirs := $(sort $(filter %/,$($3)))) |
| 246 | $(eval $3 := $(filter-out %/,$($3))) |
| 247 | $(foreach d,$(dirs:%/=%), |
| 248 | $(call save-vars,$2) |
| 249 | $(eval obj := $(if $1,$1/)$d) |
| 250 | $(eval -include $(SRC_PATH)/$d/Makefile.objs) |
| 251 | $(call fix-paths,$(if $1,$1/)$d/,$d/,$2) |
| 252 | $(call load-vars,$2,$3) |
| 253 | $(call unnest-var-recursive,$1,$2,$3)) |
Paolo Bonzini | e05804e | 2012-05-22 13:41:27 +0200 | [diff] [blame] | 254 | endef |
| 255 | |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 256 | # unnest-vars |
| 257 | # Usage: $(call unnest-vars, obj_prefix, vars) |
| 258 | # |
| 259 | # @obj_prefix: object path prefix, can be empty, or '..', etc. Don't include |
| 260 | # ending '/'. |
| 261 | # |
| 262 | # @vars: the list of variable names to unnest. |
| 263 | # |
| 264 | # This macro will scan subdirectories's Makefile.objs, include them, to build |
| 265 | # up each variable listed in @vars. |
| 266 | # |
| 267 | # Per object and per module cflags and libs are saved with relative path fixed |
| 268 | # as well, those variables include -libs, -cflags and -objs. Items in -objs are |
| 269 | # also fixed to relative path against SRC_PATH plus the prefix @obj_prefix. |
| 270 | # |
| 271 | # All nested variables postfixed by -m in names are treated as DSO variables, |
| 272 | # and will be built as modules, if enabled. |
| 273 | # |
| 274 | # A simple example of the unnest: |
| 275 | # |
| 276 | # obj_prefix = .. |
| 277 | # vars = hot cold |
| 278 | # hot = fire.o sun.o season/ |
| 279 | # cold = snow.o water/ season/ |
| 280 | # |
| 281 | # Unnest through a faked source directory structure: |
| 282 | # |
| 283 | # SRC_PATH |
| 284 | # ├── water |
| 285 | # │ └── Makefile.objs──────────────────┐ |
| 286 | # │ │ hot += steam.o │ |
| 287 | # │ │ cold += ice.mo │ |
| 288 | # │ │ ice.mo-libs := -licemaker │ |
| 289 | # │ │ ice.mo-objs := ice1.o ice2.o │ |
| 290 | # │ └──────────────────────────────┘ |
| 291 | # │ |
| 292 | # └── season |
| 293 | # └── Makefile.objs──────┐ |
| 294 | # │ hot += summer.o │ |
| 295 | # │ cold += winter.o │ |
| 296 | # └──────────────────┘ |
| 297 | # |
| 298 | # In the end, the result will be: |
| 299 | # |
| 300 | # hot = ../fire.o ../sun.o ../season/summer.o |
| 301 | # cold = ../snow.o ../water/ice.mo ../season/winter.o |
| 302 | # ../water/ice.mo-libs = -licemaker |
| 303 | # ../water/ice.mo-objs = ../water/ice1.o ../water/ice2.o |
| 304 | # |
| 305 | # Note that 'hot' didn't include 'season/' in the input, so 'summer.o' is not |
| 306 | # included. |
| 307 | # |
Paolo Bonzini | e05804e | 2012-05-22 13:41:27 +0200 | [diff] [blame] | 308 | define unnest-vars |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 309 | # In the case of target build (i.e. $1 == ..), fix path for top level |
| 310 | # Makefile.objs objects |
| 311 | $(if $1,$(call fix-paths,$1/,,$2)) |
| 312 | |
| 313 | # Descend and include every subdir Makefile.objs |
Fam Zheng | c88f68e | 2015-01-12 12:43:09 +0800 | [diff] [blame] | 314 | $(foreach v, $2, |
| 315 | $(call unnest-var-recursive,$1,$2,$v) |
| 316 | # Pass the .mo-cflags and .mo-libs along to its member objects |
| 317 | $(foreach o, $(filter %.mo,$($v)), |
| 318 | $(foreach p,$($o-objs), |
| 319 | $(if $($o-cflags), $(eval $p-cflags += $($o-cflags))) |
| 320 | $(if $($o-libs), $(eval $p-libs += $($o-libs)))))) |
| 321 | |
| 322 | # For all %.mo objects that are directly added into -y, just expand them |
| 323 | $(foreach v,$(filter %-y,$2), |
| 324 | $(eval $v := $(foreach o,$($v),$(if $($o-objs),$($o-objs),$o)))) |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 325 | |
| 326 | $(foreach v,$(filter %-m,$2), |
| 327 | # All .o found in *-m variables are single object modules, create .mo |
| 328 | # for them |
| 329 | $(foreach o,$(filter %.o,$($v)), |
| 330 | $(eval $(o:%.o=%.mo)-objs := $o)) |
| 331 | # Now unify .o in -m variable to .mo |
| 332 | $(eval $v := $($v:%.o=%.mo)) |
| 333 | $(eval modules-m += $($v)) |
| 334 | |
| 335 | # For module build, build shared libraries during "make modules" |
| 336 | # For non-module build, add -m to -y |
| 337 | $(if $(CONFIG_MODULES), |
Fam Zheng | c261d77 | 2014-09-01 18:35:10 +0800 | [diff] [blame] | 338 | $(foreach o,$($v), |
Fam Zheng | d24697e | 2015-05-07 14:55:15 +0800 | [diff] [blame] | 339 | $(eval $($o-objs): CFLAGS += $(DSO_OBJ_CFLAGS)) |
Fam Zheng | c261d77 | 2014-09-01 18:35:10 +0800 | [diff] [blame] | 340 | $(eval $o: $($o-objs))) |
| 341 | $(eval $(patsubst %-m,%-y,$v) += $($v)) |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 342 | $(eval modules: $($v:%.mo=%$(DSOSUF))), |
| 343 | $(eval $(patsubst %-m,%-y,$v) += $(call expand-objs, $($v))))) |
| 344 | |
| 345 | # Post-process all the unnested vars |
| 346 | $(foreach v,$2, |
| 347 | $(foreach o, $(filter %.mo,$($v)), |
| 348 | # Find all the .mo objects in variables and add dependency rules |
| 349 | # according to .mo-objs. Report error if not set |
| 350 | $(if $($o-objs), |
| 351 | $(eval $(o:%.mo=%$(DSOSUF)): module-common.o $($o-objs)), |
Fam Zheng | c88f68e | 2015-01-12 12:43:09 +0800 | [diff] [blame] | 352 | $(error $o added in $v but $o-objs is not set))) |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 353 | $(shell mkdir -p ./ $(sort $(dir $($v)))) |
| 354 | # Include all the .d files |
Victor Kaplansky | 27fa747 | 2015-08-09 12:39:59 +0300 | [diff] [blame] | 355 | $(eval -include $(patsubst %.o,%.d,$(patsubst %.mo,%.d,$($v)))) |
Fam Zheng | 1c33ac5 | 2014-05-27 15:54:19 +0800 | [diff] [blame] | 356 | $(eval $v := $(filter-out %/,$($v)))) |
Paolo Bonzini | e05804e | 2012-05-22 13:41:27 +0200 | [diff] [blame] | 357 | endef |