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