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