Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 2 | # ========================================================================== |
| 3 | # Building |
| 4 | # ========================================================================== |
| 5 | |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 6 | # Modified for U-Boot |
Masahiro Yamada | 60bb734 | 2014-07-30 14:08:17 +0900 | [diff] [blame] | 7 | prefix := tpl |
| 8 | src := $(patsubst $(prefix)/%,%,$(obj)) |
| 9 | ifeq ($(obj),$(src)) |
| 10 | prefix := spl |
| 11 | src := $(patsubst $(prefix)/%,%,$(obj)) |
| 12 | ifeq ($(obj),$(src)) |
| 13 | prefix := . |
| 14 | endif |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 15 | endif |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 16 | |
| 17 | PHONY := __build |
| 18 | __build: |
| 19 | |
| 20 | # Init all relevant variables used in kbuild files so |
| 21 | # 1) they have correct type |
| 22 | # 2) they do not inherit any value from the environment |
| 23 | obj-y := |
| 24 | obj-m := |
| 25 | lib-y := |
| 26 | lib-m := |
| 27 | always := |
| 28 | targets := |
| 29 | subdir-y := |
| 30 | subdir-m := |
| 31 | EXTRA_AFLAGS := |
| 32 | EXTRA_CFLAGS := |
| 33 | EXTRA_CPPFLAGS := |
| 34 | EXTRA_LDFLAGS := |
| 35 | asflags-y := |
| 36 | ccflags-y := |
| 37 | cppflags-y := |
| 38 | ldflags-y := |
| 39 | |
| 40 | subdir-asflags-y := |
| 41 | subdir-ccflags-y := |
| 42 | |
| 43 | # Read auto.conf if it exists, otherwise ignore |
Masahiro Yamada | 60bb734 | 2014-07-30 14:08:17 +0900 | [diff] [blame] | 44 | # Modified for U-Boot |
Masahiro Yamada | 72fb32b | 2015-02-24 22:26:20 +0900 | [diff] [blame] | 45 | -include include/config/auto.conf |
Masahiro Yamada | 60bb734 | 2014-07-30 14:08:17 +0900 | [diff] [blame] | 46 | -include $(prefix)/include/autoconf.mk |
Masahiro Yamada | 72fb32b | 2015-02-24 22:26:20 +0900 | [diff] [blame] | 47 | include scripts/Makefile.uncmd_spl |
Masahiro Yamada | 5ac303c | 2014-02-04 17:24:32 +0900 | [diff] [blame] | 48 | |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 49 | include scripts/Kbuild.include |
| 50 | |
| 51 | # For backward compatibility check that these variables do not change |
| 52 | save-cflags := $(CFLAGS) |
| 53 | |
| 54 | # The filename Kbuild has precedence over Makefile |
| 55 | kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) |
| 56 | kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) |
| 57 | include $(kbuild-file) |
| 58 | |
Masahiro Yamada | 958fe8f | 2014-03-05 16:59:40 +0900 | [diff] [blame] | 59 | # Added for U-Boot |
| 60 | asflags-y += $(PLATFORM_CPPFLAGS) |
| 61 | ccflags-y += $(PLATFORM_CPPFLAGS) |
| 62 | cppflags-y += $(PLATFORM_CPPFLAGS) |
| 63 | |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 64 | # If the save-* variables changed error out |
| 65 | ifeq ($(KBUILD_NOPEDANTIC),) |
| 66 | ifneq ("$(save-cflags)","$(CFLAGS)") |
| 67 | $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use ccflags-y) |
| 68 | endif |
| 69 | endif |
| 70 | |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 71 | include scripts/Makefile.lib |
| 72 | |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 73 | # Do not include host rules unless needed |
Tom Rini | 5d4ecf2 | 2020-03-27 11:46:27 -0400 | [diff] [blame] | 74 | ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),) |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 75 | include scripts/Makefile.host |
| 76 | endif |
| 77 | |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 78 | ifndef obj |
| 79 | $(warning kbuild: Makefile.build is included improperly) |
| 80 | endif |
| 81 | |
| 82 | # =========================================================================== |
| 83 | |
Masahiro Yamada | ede865b | 2014-10-30 11:06:13 +0900 | [diff] [blame] | 84 | ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),) |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 85 | lib-target := $(obj)/lib.a |
| 86 | endif |
| 87 | |
Masahiro Yamada | ede865b | 2014-10-30 11:06:13 +0900 | [diff] [blame] | 88 | ifneq ($(strip $(obj-y) $(obj-m) $(obj-) $(subdir-m) $(lib-target)),) |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 89 | builtin-target := $(obj)/built-in.o |
| 90 | endif |
| 91 | |
| 92 | modorder-target := $(obj)/modules.order |
| 93 | |
| 94 | # We keep a list of all modules in $(MODVERDIR) |
| 95 | |
| 96 | __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ |
| 97 | $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \ |
| 98 | $(subdir-ym) $(always) |
| 99 | @: |
| 100 | |
| 101 | # Linus' kernel sanity checking tool |
| 102 | ifneq ($(KBUILD_CHECKSRC),0) |
| 103 | ifeq ($(KBUILD_CHECKSRC),2) |
| 104 | quiet_cmd_force_checksrc = CHECK $< |
| 105 | cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ; |
| 106 | else |
| 107 | quiet_cmd_checksrc = CHECK $< |
| 108 | cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ; |
| 109 | endif |
| 110 | endif |
| 111 | |
| 112 | # Do section mismatch analysis for each module/built-in.o |
| 113 | ifdef CONFIG_DEBUG_SECTION_MISMATCH |
| 114 | cmd_secanalysis = ; scripts/mod/modpost $@ |
| 115 | endif |
| 116 | |
| 117 | # Compile C sources (.c) |
| 118 | # --------------------------------------------------------------------------- |
| 119 | |
| 120 | # Default is built-in, unless we know otherwise |
| 121 | modkern_cflags = \ |
| 122 | $(if $(part-of-module), \ |
| 123 | $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ |
| 124 | $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL)) |
| 125 | quiet_modtag := $(empty) $(empty) |
| 126 | |
| 127 | $(real-objs-m) : part-of-module := y |
| 128 | $(real-objs-m:.o=.i) : part-of-module := y |
| 129 | $(real-objs-m:.o=.s) : part-of-module := y |
| 130 | $(real-objs-m:.o=.lst): part-of-module := y |
| 131 | |
| 132 | $(real-objs-m) : quiet_modtag := [M] |
| 133 | $(real-objs-m:.o=.i) : quiet_modtag := [M] |
| 134 | $(real-objs-m:.o=.s) : quiet_modtag := [M] |
| 135 | $(real-objs-m:.o=.lst): quiet_modtag := [M] |
| 136 | |
| 137 | $(obj-m) : quiet_modtag := [M] |
| 138 | |
| 139 | # Default for not multi-part modules |
| 140 | modname = $(basetarget) |
| 141 | |
| 142 | $(multi-objs-m) : modname = $(modname-multi) |
| 143 | $(multi-objs-m:.o=.i) : modname = $(modname-multi) |
| 144 | $(multi-objs-m:.o=.s) : modname = $(modname-multi) |
| 145 | $(multi-objs-m:.o=.lst) : modname = $(modname-multi) |
| 146 | $(multi-objs-y) : modname = $(modname-multi) |
| 147 | $(multi-objs-y:.o=.i) : modname = $(modname-multi) |
| 148 | $(multi-objs-y:.o=.s) : modname = $(modname-multi) |
| 149 | $(multi-objs-y:.o=.lst) : modname = $(modname-multi) |
| 150 | |
| 151 | quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ |
Masahiro Yamada | 9cf2a45 | 2014-04-15 13:29:00 +0900 | [diff] [blame] | 152 | cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 153 | |
| 154 | $(obj)/%.s: $(src)/%.c FORCE |
| 155 | $(call if_changed_dep,cc_s_c) |
| 156 | |
| 157 | quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@ |
| 158 | cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $< |
| 159 | |
| 160 | $(obj)/%.i: $(src)/%.c FORCE |
| 161 | $(call if_changed_dep,cc_i_c) |
| 162 | |
| 163 | cmd_gensymtypes = \ |
| 164 | $(CPP) -D__GENKSYMS__ $(c_flags) $< | \ |
| 165 | $(GENKSYMS) $(if $(1), -T $(2)) \ |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 166 | $(if $(KBUILD_PRESERVE),-p) \ |
| 167 | -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null)) |
| 168 | |
| 169 | quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ |
| 170 | cmd_cc_symtypes_c = \ |
| 171 | set -e; \ |
| 172 | $(call cmd_gensymtypes,true,$@) >/dev/null; \ |
| 173 | test -s $@ || rm -f $@ |
| 174 | |
| 175 | $(obj)/%.symtypes : $(src)/%.c FORCE |
| 176 | $(call cmd,cc_symtypes_c) |
| 177 | |
| 178 | # C (.c) files |
| 179 | # The C file is compiled and updated dependency information is generated. |
| 180 | # (See cmd_cc_o_c + relevant part of rule_cc_o_c) |
| 181 | |
| 182 | quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ |
| 183 | |
| 184 | ifndef CONFIG_MODVERSIONS |
| 185 | cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< |
| 186 | |
| 187 | else |
| 188 | # When module versioning is enabled the following steps are executed: |
| 189 | # o compile a .tmp_<file>.o from <file>.c |
| 190 | # o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does |
| 191 | # not export symbols, we just rename .tmp_<file>.o to <file>.o and |
| 192 | # are done. |
| 193 | # o otherwise, we calculate symbol versions using the good old |
| 194 | # genksyms on the preprocessed source and postprocess them in a way |
| 195 | # that they are usable as a linker script |
| 196 | # o generate <file>.o from .tmp_<file>.o using the linker to |
| 197 | # replace the unresolved symbols __crc_exported_symbol with |
| 198 | # the actual value of the checksum generated by genksyms |
| 199 | |
| 200 | cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $< |
| 201 | cmd_modversions = \ |
| 202 | if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ |
| 203 | $(call cmd_gensymtypes,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ |
| 204 | > $(@D)/.tmp_$(@F:.o=.ver); \ |
| 205 | \ |
Tom Rini | 5d4ecf2 | 2020-03-27 11:46:27 -0400 | [diff] [blame] | 206 | $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 207 | -T $(@D)/.tmp_$(@F:.o=.ver); \ |
| 208 | rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ |
| 209 | else \ |
| 210 | mv -f $(@D)/.tmp_$(@F) $@; \ |
| 211 | fi; |
| 212 | endif |
| 213 | |
| 214 | ifdef CONFIG_FTRACE_MCOUNT_RECORD |
Tom Rini | 40f1170 | 2020-03-11 18:11:17 -0400 | [diff] [blame] | 215 | # gcc 5 supports generating the mcount tables directly |
| 216 | ifneq ($(call cc-option,-mrecord-mcount,y),y) |
| 217 | KBUILD_CFLAGS += -mrecord-mcount |
| 218 | else |
| 219 | # else do it all manually |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 220 | ifdef BUILD_C_RECORDMCOUNT |
| 221 | ifeq ("$(origin RECORDMCOUNT_WARN)", "command line") |
| 222 | RECORDMCOUNT_FLAGS = -w |
| 223 | endif |
| 224 | # Due to recursion, we must skip empty.o. |
| 225 | # The empty.o file is created in the make process in order to determine |
| 226 | # the target endianness and word size. It is made before all other C |
| 227 | # files, including recordmcount. |
| 228 | sub_cmd_record_mcount = \ |
| 229 | if [ $(@) != "scripts/mod/empty.o" ]; then \ |
| 230 | $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \ |
| 231 | fi; |
| 232 | recordmcount_source := $(srctree)/scripts/recordmcount.c \ |
| 233 | $(srctree)/scripts/recordmcount.h |
| 234 | else |
| 235 | sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ |
| 236 | "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ |
| 237 | "$(if $(CONFIG_64BIT),64,32)" \ |
Tom Rini | 5d4ecf2 | 2020-03-27 11:46:27 -0400 | [diff] [blame] | 238 | "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \ |
| 239 | "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \ |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 240 | "$(if $(part-of-module),1,0)" "$(@)"; |
| 241 | recordmcount_source := $(srctree)/scripts/recordmcount.pl |
| 242 | endif |
Masahiro Yamada | 56fc3ba | 2015-07-05 01:56:55 +0900 | [diff] [blame] | 243 | cmd_record_mcount = \ |
| 244 | if [ "$(findstring $(CC_FLAGS_FTRACE),$(_c_flags))" = \ |
| 245 | "$(CC_FLAGS_FTRACE)" ]; then \ |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 246 | $(sub_cmd_record_mcount) \ |
| 247 | fi; |
Tom Rini | 40f1170 | 2020-03-11 18:11:17 -0400 | [diff] [blame] | 248 | endif # -record-mcount |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 249 | endif |
| 250 | |
| 251 | define rule_cc_o_c |
| 252 | $(call echo-cmd,checksrc) $(cmd_checksrc) \ |
| 253 | $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ |
| 254 | $(cmd_modversions) \ |
| 255 | $(call echo-cmd,record_mcount) \ |
| 256 | $(cmd_record_mcount) \ |
| 257 | scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \ |
| 258 | $(dot-target).tmp; \ |
| 259 | rm -f $(depfile); \ |
| 260 | mv -f $(dot-target).tmp $(dot-target).cmd |
| 261 | endef |
| 262 | |
| 263 | # Built-in and composite module parts |
| 264 | $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE |
| 265 | $(call cmd,force_checksrc) |
| 266 | $(call if_changed_rule,cc_o_c) |
| 267 | |
| 268 | # Single-part modules are special since we need to mark them in $(MODVERDIR) |
| 269 | |
| 270 | $(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE |
| 271 | $(call cmd,force_checksrc) |
| 272 | $(call if_changed_rule,cc_o_c) |
| 273 | @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod) |
| 274 | |
| 275 | quiet_cmd_cc_lst_c = MKLST $@ |
| 276 | cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ |
| 277 | $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ |
| 278 | System.map $(OBJDUMP) > $@ |
| 279 | |
| 280 | $(obj)/%.lst: $(src)/%.c FORCE |
| 281 | $(call if_changed_dep,cc_lst_c) |
| 282 | |
| 283 | # Compile assembler sources (.S) |
| 284 | # --------------------------------------------------------------------------- |
| 285 | |
| 286 | modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) |
| 287 | |
| 288 | $(real-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) |
| 289 | $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) |
| 290 | |
| 291 | quiet_cmd_as_s_S = CPP $(quiet_modtag) $@ |
Masahiro Yamada | 33eb5e7 | 2014-06-16 18:56:38 +0900 | [diff] [blame] | 292 | cmd_as_s_S = $(CPP) $(a_flags) -o $@ $< |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 293 | |
| 294 | $(obj)/%.s: $(src)/%.S FORCE |
| 295 | $(call if_changed_dep,as_s_S) |
| 296 | |
| 297 | quiet_cmd_as_o_S = AS $(quiet_modtag) $@ |
| 298 | cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< |
| 299 | |
| 300 | $(obj)/%.o: $(src)/%.S FORCE |
| 301 | $(call if_changed_dep,as_o_S) |
| 302 | |
| 303 | targets += $(real-objs-y) $(real-objs-m) $(lib-y) |
| 304 | targets += $(extra-y) $(MAKECMDGOALS) $(always) |
| 305 | |
| 306 | # Linker scripts preprocessor (.lds.S -> .lds) |
| 307 | # --------------------------------------------------------------------------- |
| 308 | quiet_cmd_cpp_lds_S = LDS $@ |
| 309 | cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \ |
| 310 | -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $< |
| 311 | |
| 312 | $(obj)/%.lds: $(src)/%.lds.S FORCE |
| 313 | $(call if_changed_dep,cpp_lds_S) |
| 314 | |
| 315 | # ASN.1 grammar |
| 316 | # --------------------------------------------------------------------------- |
| 317 | quiet_cmd_asn1_compiler = ASN.1 $@ |
AKASHI Takahiro | f702526 | 2019-11-13 09:44:53 +0900 | [diff] [blame] | 318 | cmd_asn1_compiler = $(objtree)/tools/asn1_compiler $< \ |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 319 | $(subst .h,.c,$@) $(subst .c,.h,$@) |
| 320 | |
AKASHI Takahiro | f702526 | 2019-11-13 09:44:53 +0900 | [diff] [blame] | 321 | $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/tools/asn1_compiler |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 322 | $(call cmd,asn1_compiler) |
| 323 | |
| 324 | # Build the compiled-in targets |
| 325 | # --------------------------------------------------------------------------- |
| 326 | |
| 327 | # To build objects in subdirs, we need to descend into the directories |
| 328 | $(sort $(subdir-obj-y)): $(subdir-ym) ; |
| 329 | |
| 330 | # |
| 331 | # Rule to compile a set of .o files into one .o file |
| 332 | # |
| 333 | ifdef builtin-target |
Marek Behún | f872685 | 2021-05-20 13:24:02 +0200 | [diff] [blame] | 334 | quiet_cmd_link_o_target = AR $@ |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 335 | # If the list of objects to link is empty, just create an empty built-in.o |
| 336 | cmd_link_o_target = $(if $(strip $(obj-y)),\ |
Marek Behún | f872685 | 2021-05-20 13:24:02 +0200 | [diff] [blame] | 337 | rm -f $@; $(AR) cDPrsT $@ $(filter $(obj-y), $^), \ |
| 338 | rm -f $@; $(AR) cDPrsT$(KBUILD_ARFLAGS) $@) |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 339 | |
| 340 | $(builtin-target): $(obj-y) FORCE |
| 341 | $(call if_changed,link_o_target) |
| 342 | |
| 343 | targets += $(builtin-target) |
| 344 | endif # builtin-target |
| 345 | |
| 346 | # |
| 347 | # Rule to create modules.order file |
| 348 | # |
| 349 | # Create commands to either record .ko file or cat modules.order from |
| 350 | # a subdirectory |
| 351 | modorder-cmds = \ |
| 352 | $(foreach m, $(modorder), \ |
| 353 | $(if $(filter %/modules.order, $m), \ |
| 354 | cat $m;, echo kernel/$m;)) |
| 355 | |
| 356 | $(modorder-target): $(subdir-ym) FORCE |
| 357 | $(Q)(cat /dev/null; $(modorder-cmds)) > $@ |
| 358 | |
| 359 | # |
| 360 | # Rule to compile a set of .o files into one .a file |
| 361 | # |
| 362 | ifdef lib-target |
| 363 | quiet_cmd_link_l_target = AR $@ |
Marek Behún | f872685 | 2021-05-20 13:24:02 +0200 | [diff] [blame] | 364 | cmd_link_l_target = rm -f $@; $(AR) cDPrsT$(KBUILD_ARFLAGS) $@ $(lib-y) |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 365 | |
| 366 | $(lib-target): $(lib-y) FORCE |
| 367 | $(call if_changed,link_l_target) |
| 368 | |
| 369 | targets += $(lib-target) |
| 370 | endif |
| 371 | |
| 372 | # |
| 373 | # Rule to link composite objects |
| 374 | # |
| 375 | # Composite objects are specified in kbuild makefile as follows: |
| 376 | # <composite-object>-objs := <list of .o files> |
| 377 | # or |
| 378 | # <composite-object>-y := <list of .o files> |
| 379 | link_multi_deps = \ |
| 380 | $(filter $(addprefix $(obj)/, \ |
| 381 | $($(subst $(obj)/,,$(@:.o=-objs))) \ |
| 382 | $($(subst $(obj)/,,$(@:.o=-y)))), $^) |
Masahiro Yamada | 33eb5e7 | 2014-06-16 18:56:38 +0900 | [diff] [blame] | 383 | |
Marek Behún | f872685 | 2021-05-20 13:24:02 +0200 | [diff] [blame] | 384 | |
| 385 | quiet_cmd_link_multi-y = AR $@ |
| 386 | cmd_link_multi-y = rm -f $@; $(AR) cDPrsT$(KBUILD_ARFLAGS) $@ $(link_multi_deps) |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 387 | |
Marek Behún | f872685 | 2021-05-20 13:24:02 +0200 | [diff] [blame] | 388 | quiet_cmd_link_multi-m = AR [M] $@ |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 389 | cmd_link_multi-m = $(cmd_link_multi-y) |
| 390 | |
Masahiro Yamada | 8c4532f | 2014-10-30 11:06:10 +0900 | [diff] [blame] | 391 | $(multi-used-y): FORCE |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 392 | $(call if_changed,link_multi-y) |
Masahiro Yamada | 8c4532f | 2014-10-30 11:06:10 +0900 | [diff] [blame] | 393 | $(call multi_depend, $(multi-used-y), .o, -objs -y) |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 394 | |
Masahiro Yamada | 8c4532f | 2014-10-30 11:06:10 +0900 | [diff] [blame] | 395 | $(multi-used-m): FORCE |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 396 | $(call if_changed,link_multi-m) |
| 397 | @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod) |
Masahiro Yamada | 8c4532f | 2014-10-30 11:06:10 +0900 | [diff] [blame] | 398 | $(call multi_depend, $(multi-used-m), .o, -objs -y) |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 399 | |
| 400 | targets += $(multi-used-y) $(multi-used-m) |
| 401 | |
| 402 | |
Eugeniu Rosca | d57dd94 | 2018-05-19 14:13:50 +0200 | [diff] [blame] | 403 | # Add intermediate targets: |
| 404 | # When building objects with specific suffix patterns, add intermediate |
| 405 | # targets that the final targets are derived from. |
| 406 | intermediate_targets = $(foreach sfx, $(2), \ |
| 407 | $(patsubst %$(strip $(1)),%$(sfx), \ |
| 408 | $(filter %$(strip $(1)), $(targets)))) |
| 409 | # %.lex.o <- %.lex.c <- %.l |
| 410 | # %.tab.o <- %.tab.[ch] <- %.y |
AKASHI Takahiro | 5ace6ff | 2019-11-13 09:45:01 +0900 | [diff] [blame] | 411 | targets += $(call intermediate_targets, .lex.o, .lex.c) \ |
Eugeniu Rosca | d57dd94 | 2018-05-19 14:13:50 +0200 | [diff] [blame] | 412 | $(call intermediate_targets, .tab.o, .tab.c .tab.h) |
| 413 | |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 414 | # Descending |
| 415 | # --------------------------------------------------------------------------- |
| 416 | |
| 417 | PHONY += $(subdir-ym) |
| 418 | $(subdir-ym): |
| 419 | $(Q)$(MAKE) $(build)=$@ |
| 420 | |
| 421 | # Add FORCE to the prequisites of a target to force it to be always rebuilt. |
| 422 | # --------------------------------------------------------------------------- |
| 423 | |
| 424 | PHONY += FORCE |
| 425 | |
| 426 | FORCE: |
| 427 | |
| 428 | # Read all saved command lines and dependencies for the $(targets) we |
| 429 | # may be building above, using $(if_changed{,_dep}). As an |
| 430 | # optimization, we don't need to read them if the target does not |
| 431 | # exist, we will rebuild anyway in that case. |
| 432 | |
Masahiro Yamada | 77ddac8 | 2020-04-17 16:21:36 +0900 | [diff] [blame] | 433 | cmd_files := $(wildcard $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd)) |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 434 | |
| 435 | ifneq ($(cmd_files),) |
| 436 | include $(cmd_files) |
| 437 | endif |
| 438 | |
Masahiro Yamada | 77ddac8 | 2020-04-17 16:21:36 +0900 | [diff] [blame] | 439 | # Create directories for object files if they do not exist |
| 440 | obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets)))) |
| 441 | $(shell mkdir -p $(obj-dirs)) |
| 442 | |
Masahiro Yamada | 47b65f7 | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 443 | .PHONY: $(PHONY) |