Masahiro Yamada | 22433fc | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 1 | # ========================================================================== |
| 2 | # Building |
| 3 | # ========================================================================== |
| 4 | |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 5 | # Modified for U-Boot |
| 6 | ifeq ($(CONFIG_TPL_BUILD),y) |
| 7 | src := $(patsubst tpl/%,%,$(obj)) |
| 8 | else |
| 9 | ifeq ($(CONFIG_SPL_BUILD),y) |
| 10 | src := $(patsubst spl/%,%,$(obj)) |
| 11 | else |
| 12 | src := $(obj) |
| 13 | endif |
| 14 | endif |
Masahiro Yamada | 22433fc | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 15 | |
| 16 | PHONY := __build |
| 17 | __build: |
| 18 | |
| 19 | # Init all relevant variables used in kbuild files so |
| 20 | # 1) they have correct type |
| 21 | # 2) they do not inherit any value from the environment |
| 22 | obj-y := |
| 23 | obj-m := |
| 24 | lib-y := |
| 25 | lib-m := |
| 26 | always := |
| 27 | targets := |
| 28 | subdir-y := |
| 29 | subdir-m := |
| 30 | EXTRA_AFLAGS := |
| 31 | EXTRA_CFLAGS := |
| 32 | EXTRA_CPPFLAGS := |
| 33 | EXTRA_LDFLAGS := |
| 34 | asflags-y := |
| 35 | ccflags-y := |
| 36 | cppflags-y := |
| 37 | ldflags-y := |
| 38 | |
| 39 | subdir-asflags-y := |
| 40 | subdir-ccflags-y := |
| 41 | |
| 42 | # Read auto.conf if it exists, otherwise ignore |
| 43 | -include include/config/auto.conf |
| 44 | |
Masahiro Yamada | 01072b4 | 2014-02-04 17:24:32 +0900 | [diff] [blame] | 45 | # Added for U-Boot: Load U-Boot configuration |
| 46 | ifeq ($(CONFIG_TPL_BUILD),y) |
| 47 | -include include/tpl-autoconf.mk |
| 48 | else |
| 49 | ifeq ($(CONFIG_SPL_BUILD),y) |
| 50 | -include include/spl-autoconf.mk |
| 51 | else |
| 52 | -include include/autoconf.mk |
| 53 | endif |
| 54 | endif |
| 55 | |
Masahiro Yamada | 22433fc | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 56 | include scripts/Kbuild.include |
| 57 | |
| 58 | # For backward compatibility check that these variables do not change |
| 59 | save-cflags := $(CFLAGS) |
| 60 | |
| 61 | # The filename Kbuild has precedence over Makefile |
| 62 | kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) |
| 63 | kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) |
| 64 | include $(kbuild-file) |
| 65 | |
Masahiro Yamada | 026f9cf | 2014-03-05 16:59:40 +0900 | [diff] [blame] | 66 | # Added for U-Boot |
| 67 | asflags-y += $(PLATFORM_CPPFLAGS) |
| 68 | ccflags-y += $(PLATFORM_CPPFLAGS) |
| 69 | cppflags-y += $(PLATFORM_CPPFLAGS) |
| 70 | |
Masahiro Yamada | 22433fc | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 71 | # If the save-* variables changed error out |
| 72 | ifeq ($(KBUILD_NOPEDANTIC),) |
| 73 | ifneq ("$(save-cflags)","$(CFLAGS)") |
| 74 | $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use ccflags-y) |
| 75 | endif |
| 76 | endif |
| 77 | |
| 78 | # |
| 79 | # make W=... settings |
| 80 | # |
| 81 | # W=1 - warnings that may be relevant and does not occur too often |
| 82 | # W=2 - warnings that occur quite often but may still be relevant |
| 83 | # W=3 - the more obscure warnings, can most likely be ignored |
| 84 | # |
| 85 | # $(call cc-option, -W...) handles gcc -W.. options which |
| 86 | # are not supported by all versions of the compiler |
| 87 | ifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS |
| 88 | warning- := $(empty) |
| 89 | |
| 90 | warning-1 := -Wextra -Wunused -Wno-unused-parameter |
| 91 | warning-1 += -Wmissing-declarations |
| 92 | warning-1 += -Wmissing-format-attribute |
Masahiro Yamada | 598e2d3 | 2014-04-15 13:29:00 +0900 | [diff] [blame] | 93 | warning-1 += $(call cc-option, -Wmissing-prototypes) |
Masahiro Yamada | 22433fc | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 94 | warning-1 += -Wold-style-definition |
| 95 | warning-1 += $(call cc-option, -Wmissing-include-dirs) |
| 96 | warning-1 += $(call cc-option, -Wunused-but-set-variable) |
| 97 | warning-1 += $(call cc-disable-warning, missing-field-initializers) |
| 98 | |
Masahiro Yamada | 598e2d3 | 2014-04-15 13:29:00 +0900 | [diff] [blame] | 99 | # Clang |
| 100 | warning-1 += $(call cc-disable-warning, initializer-overrides) |
| 101 | warning-1 += $(call cc-disable-warning, unused-value) |
| 102 | warning-1 += $(call cc-disable-warning, format) |
| 103 | warning-1 += $(call cc-disable-warning, unknown-warning-option) |
| 104 | warning-1 += $(call cc-disable-warning, sign-compare) |
| 105 | warning-1 += $(call cc-disable-warning, format-zero-length) |
| 106 | warning-1 += $(call cc-disable-warning, uninitialized) |
| 107 | warning-1 += $(call cc-option, -fcatch-undefined-behavior) |
| 108 | |
Masahiro Yamada | 22433fc | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 109 | warning-2 := -Waggregate-return |
| 110 | warning-2 += -Wcast-align |
| 111 | warning-2 += -Wdisabled-optimization |
| 112 | warning-2 += -Wnested-externs |
| 113 | warning-2 += -Wshadow |
| 114 | warning-2 += $(call cc-option, -Wlogical-op) |
| 115 | warning-2 += $(call cc-option, -Wmissing-field-initializers) |
| 116 | |
| 117 | warning-3 := -Wbad-function-cast |
| 118 | warning-3 += -Wcast-qual |
| 119 | warning-3 += -Wconversion |
| 120 | warning-3 += -Wpacked |
| 121 | warning-3 += -Wpadded |
| 122 | warning-3 += -Wpointer-arith |
| 123 | warning-3 += -Wredundant-decls |
| 124 | warning-3 += -Wswitch-default |
| 125 | warning-3 += $(call cc-option, -Wpacked-bitfield-compat) |
| 126 | warning-3 += $(call cc-option, -Wvla) |
| 127 | |
| 128 | warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) |
| 129 | warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) |
| 130 | warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) |
| 131 | |
| 132 | ifeq ("$(strip $(warning))","") |
| 133 | $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown) |
| 134 | endif |
| 135 | |
| 136 | KBUILD_CFLAGS += $(warning) |
| 137 | endif |
| 138 | |
| 139 | include scripts/Makefile.lib |
| 140 | |
| 141 | ifdef host-progs |
| 142 | ifneq ($(hostprogs-y),$(host-progs)) |
| 143 | $(warning kbuild: $(obj)/Makefile - Usage of host-progs is deprecated. Please replace with hostprogs-y!) |
| 144 | hostprogs-y += $(host-progs) |
| 145 | endif |
| 146 | endif |
| 147 | |
| 148 | # Do not include host rules unless needed |
| 149 | ifneq ($(hostprogs-y)$(hostprogs-m),) |
| 150 | include scripts/Makefile.host |
| 151 | endif |
| 152 | |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 153 | # Uncommented for U-Boot |
| 154 | # We need to create output dicrectory for SPL and TPL even for in-tree build |
| 155 | #ifneq ($(KBUILD_SRC),) |
Masahiro Yamada | 22433fc | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 156 | # Create output directory if not already present |
| 157 | _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) |
| 158 | |
| 159 | # Create directories for object files if directory does not exist |
| 160 | # Needed when obj-y := dir/file.o syntax is used |
| 161 | _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 162 | #endif |
Masahiro Yamada | 22433fc | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 163 | |
| 164 | ifndef obj |
| 165 | $(warning kbuild: Makefile.build is included improperly) |
| 166 | endif |
| 167 | |
| 168 | # =========================================================================== |
| 169 | |
| 170 | ifneq ($(strip $(lib-y) $(lib-m) $(lib-n) $(lib-)),) |
| 171 | lib-target := $(obj)/lib.a |
| 172 | endif |
| 173 | |
| 174 | ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(subdir-m) $(lib-target)),) |
| 175 | builtin-target := $(obj)/built-in.o |
| 176 | endif |
| 177 | |
| 178 | modorder-target := $(obj)/modules.order |
| 179 | |
| 180 | # We keep a list of all modules in $(MODVERDIR) |
| 181 | |
| 182 | __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ |
| 183 | $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \ |
| 184 | $(subdir-ym) $(always) |
| 185 | @: |
| 186 | |
| 187 | # Linus' kernel sanity checking tool |
| 188 | ifneq ($(KBUILD_CHECKSRC),0) |
| 189 | ifeq ($(KBUILD_CHECKSRC),2) |
| 190 | quiet_cmd_force_checksrc = CHECK $< |
| 191 | cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ; |
| 192 | else |
| 193 | quiet_cmd_checksrc = CHECK $< |
| 194 | cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ; |
| 195 | endif |
| 196 | endif |
| 197 | |
| 198 | # Do section mismatch analysis for each module/built-in.o |
| 199 | ifdef CONFIG_DEBUG_SECTION_MISMATCH |
| 200 | cmd_secanalysis = ; scripts/mod/modpost $@ |
| 201 | endif |
| 202 | |
| 203 | # Compile C sources (.c) |
| 204 | # --------------------------------------------------------------------------- |
| 205 | |
| 206 | # Default is built-in, unless we know otherwise |
| 207 | modkern_cflags = \ |
| 208 | $(if $(part-of-module), \ |
| 209 | $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ |
| 210 | $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL)) |
| 211 | quiet_modtag := $(empty) $(empty) |
| 212 | |
| 213 | $(real-objs-m) : part-of-module := y |
| 214 | $(real-objs-m:.o=.i) : part-of-module := y |
| 215 | $(real-objs-m:.o=.s) : part-of-module := y |
| 216 | $(real-objs-m:.o=.lst): part-of-module := y |
| 217 | |
| 218 | $(real-objs-m) : quiet_modtag := [M] |
| 219 | $(real-objs-m:.o=.i) : quiet_modtag := [M] |
| 220 | $(real-objs-m:.o=.s) : quiet_modtag := [M] |
| 221 | $(real-objs-m:.o=.lst): quiet_modtag := [M] |
| 222 | |
| 223 | $(obj-m) : quiet_modtag := [M] |
| 224 | |
| 225 | # Default for not multi-part modules |
| 226 | modname = $(basetarget) |
| 227 | |
| 228 | $(multi-objs-m) : modname = $(modname-multi) |
| 229 | $(multi-objs-m:.o=.i) : modname = $(modname-multi) |
| 230 | $(multi-objs-m:.o=.s) : modname = $(modname-multi) |
| 231 | $(multi-objs-m:.o=.lst) : modname = $(modname-multi) |
| 232 | $(multi-objs-y) : modname = $(modname-multi) |
| 233 | $(multi-objs-y:.o=.i) : modname = $(modname-multi) |
| 234 | $(multi-objs-y:.o=.s) : modname = $(modname-multi) |
| 235 | $(multi-objs-y:.o=.lst) : modname = $(modname-multi) |
| 236 | |
| 237 | quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ |
Masahiro Yamada | 598e2d3 | 2014-04-15 13:29:00 +0900 | [diff] [blame] | 238 | cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< |
Masahiro Yamada | 22433fc | 2014-02-04 17:24:27 +0900 | [diff] [blame] | 239 | |
| 240 | $(obj)/%.s: $(src)/%.c FORCE |
| 241 | $(call if_changed_dep,cc_s_c) |
| 242 | |
| 243 | quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@ |
| 244 | cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $< |
| 245 | |
| 246 | $(obj)/%.i: $(src)/%.c FORCE |
| 247 | $(call if_changed_dep,cc_i_c) |
| 248 | |
| 249 | cmd_gensymtypes = \ |
| 250 | $(CPP) -D__GENKSYMS__ $(c_flags) $< | \ |
| 251 | $(GENKSYMS) $(if $(1), -T $(2)) \ |
| 252 | $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) \ |
| 253 | $(if $(KBUILD_PRESERVE),-p) \ |
| 254 | -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null)) |
| 255 | |
| 256 | quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ |
| 257 | cmd_cc_symtypes_c = \ |
| 258 | set -e; \ |
| 259 | $(call cmd_gensymtypes,true,$@) >/dev/null; \ |
| 260 | test -s $@ || rm -f $@ |
| 261 | |
| 262 | $(obj)/%.symtypes : $(src)/%.c FORCE |
| 263 | $(call cmd,cc_symtypes_c) |
| 264 | |
| 265 | # C (.c) files |
| 266 | # The C file is compiled and updated dependency information is generated. |
| 267 | # (See cmd_cc_o_c + relevant part of rule_cc_o_c) |
| 268 | |
| 269 | quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ |
| 270 | |
| 271 | ifndef CONFIG_MODVERSIONS |
| 272 | cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< |
| 273 | |
| 274 | else |
| 275 | # When module versioning is enabled the following steps are executed: |
| 276 | # o compile a .tmp_<file>.o from <file>.c |
| 277 | # o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does |
| 278 | # not export symbols, we just rename .tmp_<file>.o to <file>.o and |
| 279 | # are done. |
| 280 | # o otherwise, we calculate symbol versions using the good old |
| 281 | # genksyms on the preprocessed source and postprocess them in a way |
| 282 | # that they are usable as a linker script |
| 283 | # o generate <file>.o from .tmp_<file>.o using the linker to |
| 284 | # replace the unresolved symbols __crc_exported_symbol with |
| 285 | # the actual value of the checksum generated by genksyms |
| 286 | |
| 287 | cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $< |
| 288 | cmd_modversions = \ |
| 289 | if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ |
| 290 | $(call cmd_gensymtypes,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ |
| 291 | > $(@D)/.tmp_$(@F:.o=.ver); \ |
| 292 | \ |
| 293 | $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ |
| 294 | -T $(@D)/.tmp_$(@F:.o=.ver); \ |
| 295 | rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ |
| 296 | else \ |
| 297 | mv -f $(@D)/.tmp_$(@F) $@; \ |
| 298 | fi; |
| 299 | endif |
| 300 | |
| 301 | ifdef CONFIG_FTRACE_MCOUNT_RECORD |
| 302 | ifdef BUILD_C_RECORDMCOUNT |
| 303 | ifeq ("$(origin RECORDMCOUNT_WARN)", "command line") |
| 304 | RECORDMCOUNT_FLAGS = -w |
| 305 | endif |
| 306 | # Due to recursion, we must skip empty.o. |
| 307 | # The empty.o file is created in the make process in order to determine |
| 308 | # the target endianness and word size. It is made before all other C |
| 309 | # files, including recordmcount. |
| 310 | sub_cmd_record_mcount = \ |
| 311 | if [ $(@) != "scripts/mod/empty.o" ]; then \ |
| 312 | $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \ |
| 313 | fi; |
| 314 | recordmcount_source := $(srctree)/scripts/recordmcount.c \ |
| 315 | $(srctree)/scripts/recordmcount.h |
| 316 | else |
| 317 | sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ |
| 318 | "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ |
| 319 | "$(if $(CONFIG_64BIT),64,32)" \ |
| 320 | "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \ |
| 321 | "$(LD)" "$(NM)" "$(RM)" "$(MV)" \ |
| 322 | "$(if $(part-of-module),1,0)" "$(@)"; |
| 323 | recordmcount_source := $(srctree)/scripts/recordmcount.pl |
| 324 | endif |
| 325 | cmd_record_mcount = \ |
| 326 | if [ "$(findstring -pg,$(_c_flags))" = "-pg" ]; then \ |
| 327 | $(sub_cmd_record_mcount) \ |
| 328 | fi; |
| 329 | endif |
| 330 | |
| 331 | define rule_cc_o_c |
| 332 | $(call echo-cmd,checksrc) $(cmd_checksrc) \ |
| 333 | $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ |
| 334 | $(cmd_modversions) \ |
| 335 | $(call echo-cmd,record_mcount) \ |
| 336 | $(cmd_record_mcount) \ |
| 337 | scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \ |
| 338 | $(dot-target).tmp; \ |
| 339 | rm -f $(depfile); \ |
| 340 | mv -f $(dot-target).tmp $(dot-target).cmd |
| 341 | endef |
| 342 | |
| 343 | # Built-in and composite module parts |
| 344 | $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE |
| 345 | $(call cmd,force_checksrc) |
| 346 | $(call if_changed_rule,cc_o_c) |
| 347 | |
| 348 | # Single-part modules are special since we need to mark them in $(MODVERDIR) |
| 349 | |
| 350 | $(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE |
| 351 | $(call cmd,force_checksrc) |
| 352 | $(call if_changed_rule,cc_o_c) |
| 353 | @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod) |
| 354 | |
| 355 | quiet_cmd_cc_lst_c = MKLST $@ |
| 356 | cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ |
| 357 | $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ |
| 358 | System.map $(OBJDUMP) > $@ |
| 359 | |
| 360 | $(obj)/%.lst: $(src)/%.c FORCE |
| 361 | $(call if_changed_dep,cc_lst_c) |
| 362 | |
| 363 | # Compile assembler sources (.S) |
| 364 | # --------------------------------------------------------------------------- |
| 365 | |
| 366 | modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) |
| 367 | |
| 368 | $(real-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) |
| 369 | $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) |
| 370 | |
| 371 | quiet_cmd_as_s_S = CPP $(quiet_modtag) $@ |
| 372 | cmd_as_s_S = $(CPP) $(a_flags) -o $@ $< |
| 373 | |
| 374 | $(obj)/%.s: $(src)/%.S FORCE |
| 375 | $(call if_changed_dep,as_s_S) |
| 376 | |
| 377 | quiet_cmd_as_o_S = AS $(quiet_modtag) $@ |
| 378 | cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< |
| 379 | |
| 380 | $(obj)/%.o: $(src)/%.S FORCE |
| 381 | $(call if_changed_dep,as_o_S) |
| 382 | |
| 383 | targets += $(real-objs-y) $(real-objs-m) $(lib-y) |
| 384 | targets += $(extra-y) $(MAKECMDGOALS) $(always) |
| 385 | |
| 386 | # Linker scripts preprocessor (.lds.S -> .lds) |
| 387 | # --------------------------------------------------------------------------- |
| 388 | quiet_cmd_cpp_lds_S = LDS $@ |
| 389 | cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \ |
| 390 | -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $< |
| 391 | |
| 392 | $(obj)/%.lds: $(src)/%.lds.S FORCE |
| 393 | $(call if_changed_dep,cpp_lds_S) |
| 394 | |
| 395 | # ASN.1 grammar |
| 396 | # --------------------------------------------------------------------------- |
| 397 | quiet_cmd_asn1_compiler = ASN.1 $@ |
| 398 | cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \ |
| 399 | $(subst .h,.c,$@) $(subst .c,.h,$@) |
| 400 | |
| 401 | .PRECIOUS: $(objtree)/$(obj)/%-asn1.c $(objtree)/$(obj)/%-asn1.h |
| 402 | |
| 403 | $(obj)/%-asn1.c $(obj)/%-asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler |
| 404 | $(call cmd,asn1_compiler) |
| 405 | |
| 406 | # Build the compiled-in targets |
| 407 | # --------------------------------------------------------------------------- |
| 408 | |
| 409 | # To build objects in subdirs, we need to descend into the directories |
| 410 | $(sort $(subdir-obj-y)): $(subdir-ym) ; |
| 411 | |
| 412 | # |
| 413 | # Rule to compile a set of .o files into one .o file |
| 414 | # |
| 415 | ifdef builtin-target |
| 416 | quiet_cmd_link_o_target = LD $@ |
| 417 | # If the list of objects to link is empty, just create an empty built-in.o |
| 418 | cmd_link_o_target = $(if $(strip $(obj-y)),\ |
| 419 | $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \ |
| 420 | $(cmd_secanalysis),\ |
| 421 | rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@) |
| 422 | |
| 423 | $(builtin-target): $(obj-y) FORCE |
| 424 | $(call if_changed,link_o_target) |
| 425 | |
| 426 | targets += $(builtin-target) |
| 427 | endif # builtin-target |
| 428 | |
| 429 | # |
| 430 | # Rule to create modules.order file |
| 431 | # |
| 432 | # Create commands to either record .ko file or cat modules.order from |
| 433 | # a subdirectory |
| 434 | modorder-cmds = \ |
| 435 | $(foreach m, $(modorder), \ |
| 436 | $(if $(filter %/modules.order, $m), \ |
| 437 | cat $m;, echo kernel/$m;)) |
| 438 | |
| 439 | $(modorder-target): $(subdir-ym) FORCE |
| 440 | $(Q)(cat /dev/null; $(modorder-cmds)) > $@ |
| 441 | |
| 442 | # |
| 443 | # Rule to compile a set of .o files into one .a file |
| 444 | # |
| 445 | ifdef lib-target |
| 446 | quiet_cmd_link_l_target = AR $@ |
| 447 | cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y) |
| 448 | |
| 449 | $(lib-target): $(lib-y) FORCE |
| 450 | $(call if_changed,link_l_target) |
| 451 | |
| 452 | targets += $(lib-target) |
| 453 | endif |
| 454 | |
| 455 | # |
| 456 | # Rule to link composite objects |
| 457 | # |
| 458 | # Composite objects are specified in kbuild makefile as follows: |
| 459 | # <composite-object>-objs := <list of .o files> |
| 460 | # or |
| 461 | # <composite-object>-y := <list of .o files> |
| 462 | link_multi_deps = \ |
| 463 | $(filter $(addprefix $(obj)/, \ |
| 464 | $($(subst $(obj)/,,$(@:.o=-objs))) \ |
| 465 | $($(subst $(obj)/,,$(@:.o=-y)))), $^) |
| 466 | |
| 467 | quiet_cmd_link_multi-y = LD $@ |
| 468 | cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis) |
| 469 | |
| 470 | quiet_cmd_link_multi-m = LD [M] $@ |
| 471 | cmd_link_multi-m = $(cmd_link_multi-y) |
| 472 | |
| 473 | # We would rather have a list of rules like |
| 474 | # foo.o: $(foo-objs) |
| 475 | # but that's not so easy, so we rather make all composite objects depend |
| 476 | # on the set of all their parts |
| 477 | $(multi-used-y) : %.o: $(multi-objs-y) FORCE |
| 478 | $(call if_changed,link_multi-y) |
| 479 | |
| 480 | $(multi-used-m) : %.o: $(multi-objs-m) FORCE |
| 481 | $(call if_changed,link_multi-m) |
| 482 | @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod) |
| 483 | |
| 484 | targets += $(multi-used-y) $(multi-used-m) |
| 485 | |
| 486 | |
| 487 | # Descending |
| 488 | # --------------------------------------------------------------------------- |
| 489 | |
| 490 | PHONY += $(subdir-ym) |
| 491 | $(subdir-ym): |
| 492 | $(Q)$(MAKE) $(build)=$@ |
| 493 | |
| 494 | # Add FORCE to the prequisites of a target to force it to be always rebuilt. |
| 495 | # --------------------------------------------------------------------------- |
| 496 | |
| 497 | PHONY += FORCE |
| 498 | |
| 499 | FORCE: |
| 500 | |
| 501 | # Read all saved command lines and dependencies for the $(targets) we |
| 502 | # may be building above, using $(if_changed{,_dep}). As an |
| 503 | # optimization, we don't need to read them if the target does not |
| 504 | # exist, we will rebuild anyway in that case. |
| 505 | |
| 506 | targets := $(wildcard $(sort $(targets))) |
| 507 | cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) |
| 508 | |
| 509 | ifneq ($(cmd_files),) |
| 510 | include $(cmd_files) |
| 511 | endif |
| 512 | |
| 513 | # Declare the contents of the .PHONY variable as phony. We keep that |
| 514 | # information in a variable se we can use it in if_changed and friends. |
| 515 | |
| 516 | .PHONY: $(PHONY) |