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