| 1 | # SPDX-License-Identifier: GPL-2.0
|
| 2 | # ==========================================================================
|
| 3 | # Building
|
| 4 | # ==========================================================================
|
| 5 |
|
| 6 | src := $(srcroot)/$(obj)
|
| 7 |
|
| 8 | PHONY := $(obj)/
|
| 9 | $(obj)/:
|
| 10 |
|
| 11 | # Init all relevant variables used in kbuild files so
|
| 12 | # 1) they have correct type
|
| 13 | # 2) they do not inherit any value from the environment
|
| 14 | obj-y :=
|
| 15 | obj-m :=
|
| 16 | lib-y :=
|
| 17 | lib-m :=
|
| 18 | always-y :=
|
| 19 | always-m :=
|
| 20 | targets :=
|
| 21 | subdir-y :=
|
| 22 | subdir-m :=
|
| 23 | asflags-y :=
|
| 24 | ccflags-y :=
|
| 25 | rustflags-y :=
|
| 26 | cppflags-y :=
|
| 27 | ldflags-y :=
|
| 28 |
|
| 29 | subdir-asflags-y :=
|
| 30 | subdir-ccflags-y :=
|
| 31 | subdir-rustflags-y :=
|
| 32 |
|
| 33 | # Read auto.conf if it exists, otherwise ignore
|
| 34 | -include $(objtree)/include/config/auto.conf
|
| 35 |
|
| 36 | include $(srctree)/scripts/Kbuild.include
|
| 37 | include $(srctree)/scripts/Makefile.compiler
|
| 38 | include $(kbuild-file)
|
| 39 | include $(srctree)/scripts/Makefile.lib
|
| 40 |
|
| 41 | # flags that take effect in current and sub directories
|
| 42 | KBUILD_AFLAGS += $(subdir-asflags-y)
|
| 43 | KBUILD_CFLAGS += $(subdir-ccflags-y)
|
| 44 | KBUILD_RUSTFLAGS += $(subdir-rustflags-y)
|
| 45 |
|
| 46 | # Figure out what we need to build from the various variables
|
| 47 | # ===========================================================================
|
| 48 |
|
| 49 | # When an object is listed to be built compiled-in and modular,
|
| 50 | # only build the compiled-in version
|
| 51 | obj-m := $(filter-out $(obj-y),$(obj-m))
|
| 52 |
|
| 53 | # Libraries are always collected in one lib file.
|
| 54 | # Filter out objects already built-in
|
| 55 | lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
|
| 56 |
|
| 57 | # Subdirectories we need to descend into
|
| 58 | subdir-ym := $(sort $(subdir-y) $(subdir-m) \
|
| 59 | $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
|
| 60 |
|
| 61 | # Handle objects in subdirs:
|
| 62 | # - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
|
| 63 | # foo/modules.order
|
| 64 | # - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
|
| 65 | #
|
| 66 | # Generate modules.order to determine modorder. Unfortunately, we don't have
|
| 67 | # information about ordering between -y and -m subdirs. Just put -y's first.
|
| 68 |
|
| 69 | ifdef need-modorder
|
| 70 | obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
|
| 71 | else
|
| 72 | obj-m := $(filter-out %/, $(obj-m))
|
| 73 | endif
|
| 74 |
|
| 75 | ifdef need-builtin
|
| 76 | obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
|
| 77 | else
|
| 78 | obj-y := $(filter-out %/, $(obj-y))
|
| 79 | endif
|
| 80 |
|
| 81 | # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
|
| 82 | suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
|
| 83 | # List composite targets that are constructed by combining other targets
|
| 84 | multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
|
| 85 | # List primitive targets that are compiled from source files
|
| 86 | real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
|
| 87 |
|
| 88 | # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
|
| 89 | multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
|
| 90 | multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
|
| 91 | multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
|
| 92 |
|
| 93 | # Replace multi-part objects by their individual parts,
|
| 94 | # including built-in.a from subdirectories
|
| 95 | real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
|
| 96 | real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
|
| 97 |
|
| 98 | always-y += $(always-m)
|
| 99 |
|
| 100 | # hostprogs-always-y += foo
|
| 101 | # ... is a shorthand for
|
| 102 | # hostprogs += foo
|
| 103 | # always-y += foo
|
| 104 | hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
|
| 105 | always-y += $(hostprogs-always-y) $(hostprogs-always-m)
|
| 106 |
|
| 107 | # userprogs-always-y is likewise.
|
| 108 | userprogs += $(userprogs-always-y) $(userprogs-always-m)
|
| 109 | always-y += $(userprogs-always-y) $(userprogs-always-m)
|
| 110 |
|
| 111 | # Add subdir path
|
| 112 |
|
| 113 | ifneq ($(obj),.)
|
| 114 | extra-y := $(addprefix $(obj)/, $(extra-y))
|
| 115 | always-y := $(addprefix $(obj)/, $(always-y))
|
| 116 | targets := $(addprefix $(obj)/, $(targets))
|
| 117 | obj-m := $(addprefix $(obj)/, $(obj-m))
|
| 118 | lib-y := $(addprefix $(obj)/, $(lib-y))
|
| 119 | real-obj-y := $(addprefix $(obj)/, $(real-obj-y))
|
| 120 | real-obj-m := $(addprefix $(obj)/, $(real-obj-m))
|
| 121 | multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
|
| 122 | subdir-ym := $(addprefix $(obj)/, $(subdir-ym))
|
| 123 | endif
|
| 124 |
|
| 125 | ifndef obj
|
| 126 | $(warning kbuild: Makefile.build is included improperly)
|
| 127 | endif
|
| 128 |
|
| 129 | ifeq ($(need-modorder),)
|
| 130 | ifneq ($(obj-m),)
|
| 131 | $(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.)
|
| 132 | $(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.)
|
| 133 | endif
|
| 134 | endif
|
| 135 |
|
| 136 | # ===========================================================================
|
| 137 |
|
| 138 | # subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...)
|
| 139 | subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y)))
|
| 140 | subdir-modorder := $(sort $(filter %/modules.order, $(obj-m)))
|
| 141 |
|
| 142 | targets-for-builtin := $(extra-y)
|
| 143 |
|
| 144 | ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
|
| 145 | targets-for-builtin += $(obj)/lib.a
|
| 146 | endif
|
| 147 |
|
| 148 | ifdef need-builtin
|
| 149 | targets-for-builtin += $(obj)/built-in.a
|
| 150 | endif
|
| 151 |
|
| 152 | targets-for-modules := $(foreach x, o mod, \
|
| 153 | $(patsubst %.o, %.$x, $(filter %.o, $(obj-m))))
|
| 154 |
|
| 155 | ifdef need-modorder
|
| 156 | targets-for-modules += $(obj)/modules.order
|
| 157 | endif
|
| 158 |
|
| 159 | targets += $(targets-for-builtin) $(targets-for-modules)
|
| 160 |
|
| 161 | # Linus' kernel sanity checking tool
|
| 162 | ifeq ($(KBUILD_CHECKSRC),1)
|
| 163 | quiet_cmd_checksrc = CHECK $(patsubst $(srctree)/%,%,$<)
|
| 164 | cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
|
| 165 | else ifeq ($(KBUILD_CHECKSRC),2)
|
| 166 | quiet_cmd_force_checksrc = CHECK $(patsubst $(srctree)/%,%,$<)
|
| 167 | cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
|
| 168 | endif
|
| 169 |
|
| 170 | ifeq ($(KBUILD_EXTMOD),)
|
| 171 | ifneq ($(KBUILD_EXTRA_WARN),)
|
| 172 | cmd_checkdoc = PYTHONDONTWRITEBYTECODE=1 $(PYTHON3) $(KERNELDOC) -none $(KDOCFLAGS) \
|
| 173 | $(if $(findstring 2, $(KBUILD_EXTRA_WARN)), -Wall) \
|
| 174 | $<
|
| 175 | endif
|
| 176 | endif
|
| 177 |
|
| 178 | # Compile C sources (.c)
|
| 179 | # ---------------------------------------------------------------------------
|
| 180 |
|
| 181 | quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
|
| 182 | cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS) $(CC_FLAGS_LTO), $(c_flags)) -fverbose-asm -S -o $@ $<
|
| 183 |
|
| 184 | $(obj)/%.s: $(obj)/%.c FORCE
|
| 185 | $(call if_changed_dep,cc_s_c)
|
| 186 |
|
| 187 | quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
|
| 188 | cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
|
| 189 |
|
| 190 | $(obj)/%.i: $(obj)/%.c FORCE
|
| 191 | $(call if_changed_dep,cpp_i_c)
|
| 192 |
|
| 193 | getexportsymbols = $(NM) $@ | sed -n 's/.* __export_symbol_\(.*\)/$(1)/p'
|
| 194 |
|
| 195 | gendwarfksyms = $(objtree)/scripts/gendwarfksyms/gendwarfksyms \
|
| 196 | $(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes)) \
|
| 197 | $(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable)
|
| 198 |
|
| 199 | genksyms = $(objtree)/scripts/genksyms/genksyms \
|
| 200 | $(if $(KBUILD_SYMTYPES), -T $(@:.o=.symtypes)) \
|
| 201 | $(if $(KBUILD_PRESERVE), -p) \
|
| 202 | $(addprefix -r , $(wildcard $(@:.o=.symref)))
|
| 203 |
|
| 204 | # These mirror gensymtypes_S and co below, keep them in synch.
|
| 205 | ifdef CONFIG_GENDWARFKSYMS
|
| 206 | cmd_gensymtypes_c = $(if $(skip_gendwarfksyms),, \
|
| 207 | $(call getexportsymbols,\1) | $(gendwarfksyms) $@)
|
| 208 | else
|
| 209 | cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
|
| 210 | endif # CONFIG_GENDWARFKSYMS
|
| 211 |
|
| 212 | # LLVM assembly
|
| 213 | # Generate .ll files from .c
|
| 214 | quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
|
| 215 | cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -fno-discard-value-names -o $@ $<
|
| 216 |
|
| 217 | $(obj)/%.ll: $(obj)/%.c FORCE
|
| 218 | $(call if_changed_dep,cc_ll_c)
|
| 219 |
|
| 220 | # C (.c) files
|
| 221 | # The C file is compiled and updated dependency information is generated.
|
| 222 | # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
|
| 223 |
|
| 224 | is-single-obj-m = $(and $(part-of-module),$(filter $@, $(obj-m)),y)
|
| 225 |
|
| 226 | ifdef CONFIG_MODVERSIONS
|
| 227 | # When module versioning is enabled the following steps are executed:
|
| 228 | # o compile a <file>.o from <file>.c
|
| 229 | # o if <file>.o doesn't contain a __export_symbol_*, i.e. does
|
| 230 | # not export symbols, it's done.
|
| 231 | # o otherwise, we calculate symbol versions using the good old
|
| 232 | # genksyms on the preprocessed source and dump them into the .cmd file.
|
| 233 | # o modpost will extract versions from that file and create *.c files that will
|
| 234 | # be compiled and linked to the kernel and/or modules.
|
| 235 |
|
| 236 | gen_symversions = \
|
| 237 | if $(NM) $@ 2>/dev/null | grep -q ' __export_symbol_'; then \
|
| 238 | $(cmd_gensymtypes_$1) >> $(dot-target).cmd; \
|
| 239 | fi
|
| 240 |
|
| 241 | cmd_gen_symversions_c = $(call gen_symversions,c)
|
| 242 |
|
| 243 | endif
|
| 244 |
|
| 245 | ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
|
| 246 | # compiler will not generate __mcount_loc use recordmcount or recordmcount.pl
|
| 247 | ifdef BUILD_C_RECORDMCOUNT
|
| 248 | ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
|
| 249 | RECORDMCOUNT_FLAGS = -w
|
| 250 | endif
|
| 251 | # Due to recursion, we must skip empty.o.
|
| 252 | # The empty.o file is created in the make process in order to determine
|
| 253 | # the target endianness and word size. It is made before all other C
|
| 254 | # files, including recordmcount.
|
| 255 | sub_cmd_record_mcount = \
|
| 256 | if [ $(@) != "scripts/mod/empty.o" ]; then \
|
| 257 | $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \
|
| 258 | fi;
|
| 259 | recordmcount_source := $(srctree)/scripts/recordmcount.c \
|
| 260 | $(srctree)/scripts/recordmcount.h
|
| 261 | else
|
| 262 | sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
|
| 263 | "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
|
| 264 | "$(if $(CONFIG_64BIT),64,32)" \
|
| 265 | "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
|
| 266 | "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \
|
| 267 | "$(if $(part-of-module),1,0)" "$(@)";
|
| 268 | recordmcount_source := $(srctree)/scripts/recordmcount.pl
|
| 269 | endif # BUILD_C_RECORDMCOUNT
|
| 270 | cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), \
|
| 271 | $(sub_cmd_record_mcount))
|
| 272 | endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
|
| 273 |
|
| 274 | # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
|
| 275 | # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
|
| 276 | # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
|
| 277 |
|
| 278 | is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(target-stem).o)$(OBJECT_FILES_NON_STANDARD)n),$(is-kernel-object))
|
| 279 |
|
| 280 | ifdef CONFIG_OBJTOOL
|
| 281 | $(obj)/%.o: private objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y))
|
| 282 | endif
|
| 283 |
|
| 284 | ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
|
| 285 | cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi)))
|
| 286 | endif
|
| 287 |
|
| 288 | # Built-in and composite module parts
|
| 289 | $(obj)/%.o: $(obj)/%.c $(recordmcount_source) FORCE
|
| 290 | $(call if_changed_rule,cc_o_c)
|
| 291 | $(call cmd,force_checksrc)
|
| 292 |
|
| 293 | # To make this rule robust against "Argument list too long" error,
|
| 294 | # ensure to add $(obj)/ prefix by a shell command.
|
| 295 | cmd_mod = printf '%s\n' $(call real-search, $*.o, .o, -objs -y -m) | \
|
| 296 | $(AWK) '!x[$$0]++ { print("$(obj)/"$$0) }' > $@
|
| 297 |
|
| 298 | $(obj)/%.mod: FORCE
|
| 299 | $(call if_changed,mod)
|
| 300 |
|
| 301 | quiet_cmd_cc_lst_c = MKLST $@
|
| 302 | cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
|
| 303 | $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
|
| 304 | System.map $(OBJDUMP) > $@
|
| 305 |
|
| 306 | $(obj)/%.lst: $(obj)/%.c FORCE
|
| 307 | $(call if_changed_dep,cc_lst_c)
|
| 308 |
|
| 309 | # Compile Rust sources (.rs)
|
| 310 | # ---------------------------------------------------------------------------
|
| 311 |
|
| 312 | # The features in this list are the ones allowed for non-`rust/` code.
|
| 313 | #
|
| 314 | # - Stable since Rust 1.87.0: `feature(asm_goto)`.
|
| 315 | # - Stable since Rust 1.89.0: `feature(generic_arg_infer)`.
|
| 316 | # - Expected to become stable: `feature(arbitrary_self_types)`.
|
| 317 | # - To be determined: `feature(used_with_arg)`.
|
| 318 | #
|
| 319 | # Please see https://github.com/Rust-for-Linux/linux/issues/2 for details on
|
| 320 | # the unstable features in use.
|
| 321 | rust_allowed_features := arbitrary_self_types,asm_goto,generic_arg_infer,used_with_arg
|
| 322 |
|
| 323 | # `--out-dir` is required to avoid temporaries being created by `rustc` in the
|
| 324 | # current working directory, which may be not accessible in the out-of-tree
|
| 325 | # modules case.
|
| 326 | rust_common_cmd = \
|
| 327 | OBJTREE=$(abspath $(objtree)) \
|
| 328 | RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) $(rust_flags) \
|
| 329 | -Zallow-features=$(rust_allowed_features) \
|
| 330 | -Zcrate-attr=no_std \
|
| 331 | -Zcrate-attr='feature($(rust_allowed_features))' \
|
| 332 | -Zunstable-options --extern pin_init --extern kernel \
|
| 333 | --extern zerocopy --extern zerocopy_derive \
|
| 334 | --crate-type rlib -L $(objtree)/rust/ \
|
| 335 | --sysroot=/dev/null \
|
| 336 | --out-dir $(dir $@) --emit=dep-info=$(depfile)
|
| 337 |
|
| 338 | # `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit
|
| 339 | # will be used. We explicitly request `-Ccodegen-units=1` in any case, and
|
| 340 | # the compiler shows a warning if it is not 1. However, if we ever stop
|
| 341 | # requesting it explicitly and we start using some other `--emit` that does not
|
| 342 | # imply it (and for which codegen is performed), then we would be out of sync,
|
| 343 | # i.e. the outputs we would get for the different single targets (e.g. `.ll`)
|
| 344 | # would not match each other.
|
| 345 |
|
| 346 | quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
|
| 347 | cmd_rustc_o_rs = $(rust_common_cmd) --emit=$(if $(CONFIG_RUST_INLINE_HELPERS),llvm-bc=$(patsubst %.o,%.bc,$@),obj=$@) $< \
|
| 348 | $(if $(CONFIG_RUST_INLINE_HELPERS),;$(LLVM_LINK) --internalize --suppress-warnings $(patsubst %.o,%.bc,$@) \
|
| 349 | $(objtree)/rust/helpers/helpers$(if $(part-of-module),_module).bc -o $(patsubst %.o,%.m.bc,$@); \
|
| 350 | $(CC) $(CLANG_FLAGS) $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS)) \
|
| 351 | $(CC_FLAGS_RUST_INLINE_HELPERS) -Wno-override-module -c $(patsubst %.o,%.m.bc,$@) -o $@ \
|
| 352 | $(cmd_ld_single)) \
|
| 353 | $(cmd_objtool)
|
| 354 |
|
| 355 | define rule_rustc_o_rs
|
| 356 | $(call cmd_and_fixdep,rustc_o_rs)
|
| 357 | $(call cmd,gen_objtooldep)
|
| 358 | endef
|
| 359 |
|
| 360 | $(obj)/%.o: $(obj)/%.rs FORCE
|
| 361 | +$(call if_changed_rule,rustc_o_rs)
|
| 362 |
|
| 363 | quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
|
| 364 | cmd_rustc_rsi_rs = \
|
| 365 | $(rust_common_cmd) -Zunpretty=expanded $< >$@; \
|
| 366 | command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) --config-path $(srctree)/.rustfmt.toml $@
|
| 367 |
|
| 368 | $(obj)/%.rsi: $(obj)/%.rs FORCE
|
| 369 | +$(call if_changed_dep,rustc_rsi_rs)
|
| 370 |
|
| 371 | quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
|
| 372 | cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $<
|
| 373 |
|
| 374 | $(obj)/%.s: $(obj)/%.rs FORCE
|
| 375 | +$(call if_changed_dep,rustc_s_rs)
|
| 376 |
|
| 377 | quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
|
| 378 | cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $<
|
| 379 |
|
| 380 | $(obj)/%.ll: $(obj)/%.rs FORCE
|
| 381 | +$(call if_changed_dep,rustc_ll_rs)
|
| 382 |
|
| 383 | quiet_cmd_rustc_rs_rs_S = RSCPP $(quiet_modtag) $@
|
| 384 | cmd_rustc_rs_rs_S = $(CPP) $(c_flags) -xc -C -P $< | sed '1,/^\/\/ Cut here.$$/d' >$@
|
| 385 |
|
| 386 | $(obj)/%.rs: $(obj)/%.rs.S FORCE
|
| 387 | +$(call if_changed_dep,rustc_rs_rs_S)
|
| 388 |
|
| 389 | # Compile assembler sources (.S)
|
| 390 | # ---------------------------------------------------------------------------
|
| 391 |
|
| 392 | # .S file exports must have their C prototypes defined in asm/asm-prototypes.h
|
| 393 | # or a file that it includes, in order to get versioned symbols. We build a
|
| 394 | # dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from
|
| 395 | # the .S file (with trailing ';'), and run genksyms on that, to extract vers.
|
| 396 | #
|
| 397 | # This is convoluted. The .S file must first be preprocessed to run guards and
|
| 398 | # expand names, then the resulting exports must be constructed into plain
|
| 399 | # EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
|
| 400 | # to make the genksyms input or compiled into an object for gendwarfksyms.
|
| 401 | #
|
| 402 | # These mirror gensymtypes_c and co above, keep them in synch.
|
| 403 | getasmexports = \
|
| 404 | { echo "\#include <linux/kernel.h>" ; \
|
| 405 | echo "\#include <linux/string.h>" ; \
|
| 406 | echo "\#include <asm/asm-prototypes.h>" ; \
|
| 407 | $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }
|
| 408 |
|
| 409 | ifdef CONFIG_GENDWARFKSYMS
|
| 410 | cmd_gensymtypes_S = \
|
| 411 | $(getasmexports) | \
|
| 412 | $(CC) $(c_flags) -c -o $(@:.o=.gendwarfksyms.o) -xc -; \
|
| 413 | $(call getexportsymbols,\1) | \
|
| 414 | $(gendwarfksyms) $(@:.o=.gendwarfksyms.o)
|
| 415 | else
|
| 416 | cmd_gensymtypes_S = \
|
| 417 | $(getasmexports) | \
|
| 418 | $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
|
| 419 | endif # CONFIG_GENDWARFKSYMS
|
| 420 |
|
| 421 | quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
|
| 422 | cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
|
| 423 |
|
| 424 | $(obj)/%.s: $(obj)/%.S FORCE
|
| 425 | $(call if_changed_dep,cpp_s_S)
|
| 426 |
|
| 427 | ifdef CONFIG_ASM_MODVERSIONS
|
| 428 |
|
| 429 | # versioning matches the C process described above, with difference that
|
| 430 | # we parse asm-prototypes.h C header to get function definitions.
|
| 431 |
|
| 432 | cmd_gen_symversions_S = $(call gen_symversions,S)
|
| 433 |
|
| 434 | endif
|
| 435 |
|
| 436 | $(obj)/%.o: $(obj)/%.S FORCE
|
| 437 | $(call if_changed_rule,as_o_S)
|
| 438 |
|
| 439 | targets += $(filter-out $(subdir-builtin), $(real-obj-y))
|
| 440 | targets += $(filter-out $(subdir-modorder), $(real-obj-m))
|
| 441 | targets += $(lib-y) $(always-y)
|
| 442 |
|
| 443 | # Linker scripts preprocessor (.lds.S -> .lds)
|
| 444 | # ---------------------------------------------------------------------------
|
| 445 | quiet_cmd_cpp_lds_S = LDS $@
|
| 446 | cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \
|
| 447 | -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
|
| 448 |
|
| 449 | $(obj)/%.lds: $(src)/%.lds.S FORCE
|
| 450 | $(call if_changed_dep,cpp_lds_S)
|
| 451 |
|
| 452 | # ASN.1 grammar
|
| 453 | # ---------------------------------------------------------------------------
|
| 454 | quiet_cmd_asn1_compiler = ASN.1 $(basename $@).[ch]
|
| 455 | cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
|
| 456 | $(basename $@).c $(basename $@).h
|
| 457 |
|
| 458 | $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
|
| 459 | $(call cmd,asn1_compiler)
|
| 460 |
|
| 461 | # Build the compiled-in targets
|
| 462 | # ---------------------------------------------------------------------------
|
| 463 |
|
| 464 | # To build objects in subdirs, we need to descend into the directories
|
| 465 | $(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ;
|
| 466 | $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
|
| 467 |
|
| 468 | #
|
| 469 | # Rule to compile a set of .o files into one .a file (without symbol table)
|
| 470 | #
|
| 471 | # To make this rule robust against "Argument list too long" error,
|
| 472 | # remove $(obj)/ prefix, and restore it by a shell command.
|
| 473 |
|
| 474 | quiet_cmd_ar_builtin = AR $@
|
| 475 | cmd_ar_builtin = rm -f $@; \
|
| 476 | $(if $(real-prereqs), printf "$(obj)/%s " $(patsubst $(obj)/%,%,$(real-prereqs)) | xargs) \
|
| 477 | $(AR) cDPrST $@
|
| 478 |
|
| 479 | $(obj)/built-in.a: $(real-obj-y) FORCE
|
| 480 | $(call if_changed,ar_builtin)
|
| 481 |
|
| 482 | # This is a list of build artifacts from the current Makefile and its
|
| 483 | # sub-directories. The timestamp should be updated when any of the member files.
|
| 484 |
|
| 485 | cmd_gen_order = { $(foreach m, $(real-prereqs), \
|
| 486 | $(if $(filter %/$(notdir $@), $m), cat $m, echo $m);) :; } \
|
| 487 | > $@
|
| 488 |
|
| 489 | $(obj)/modules.order: $(obj-m) FORCE
|
| 490 | $(call if_changed,gen_order)
|
| 491 |
|
| 492 | #
|
| 493 | # Rule to compile a set of .o files into one .a file (with symbol table)
|
| 494 | #
|
| 495 |
|
| 496 | $(obj)/lib.a: $(lib-y) FORCE
|
| 497 | $(call if_changed,ar)
|
| 498 |
|
| 499 | quiet_cmd_ld_multi_m = LD [M] $@
|
| 500 | cmd_ld_multi_m = $(LD) $(ld_flags) -r -o $@ @$< $(cmd_objtool)
|
| 501 |
|
| 502 | define rule_ld_multi_m
|
| 503 | $(call cmd_and_savecmd,ld_multi_m)
|
| 504 | $(call cmd,gen_objtooldep)
|
| 505 | endef
|
| 506 |
|
| 507 | $(multi-obj-m): private objtool-enabled := $(delay-objtool)
|
| 508 | $(multi-obj-m): private part-of-module := y
|
| 509 | $(multi-obj-m): %.o: %.mod FORCE
|
| 510 | $(call if_changed_rule,ld_multi_m)
|
| 511 | $(call multi_depend, $(multi-obj-m), .o, -objs -y -m)
|
| 512 |
|
| 513 | # Add intermediate targets:
|
| 514 | # When building objects with specific suffix patterns, add intermediate
|
| 515 | # targets that the final targets are derived from.
|
| 516 | intermediate_targets = $(foreach sfx, $(2), \
|
| 517 | $(patsubst %$(strip $(1)),%$(sfx), \
|
| 518 | $(filter %$(strip $(1)), $(targets))))
|
| 519 | # %.asn1.o <- %.asn1.[ch] <- %.asn1
|
| 520 | targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h)
|
| 521 |
|
| 522 | # Include additional build rules when necessary
|
| 523 | # ---------------------------------------------------------------------------
|
| 524 |
|
| 525 | # $(sort ...) is used here to remove duplicated words and excessive spaces.
|
| 526 | hostprogs := $(sort $(hostprogs))
|
| 527 | ifneq ($(hostprogs),)
|
| 528 | include $(srctree)/scripts/Makefile.host
|
| 529 | endif
|
| 530 |
|
| 531 | # $(sort ...) is used here to remove duplicated words and excessive spaces.
|
| 532 | userprogs := $(sort $(userprogs))
|
| 533 | ifneq ($(userprogs),)
|
| 534 | include $(srctree)/scripts/Makefile.userprogs
|
| 535 | endif
|
| 536 |
|
| 537 | # Single targets
|
| 538 | # ---------------------------------------------------------------------------
|
| 539 |
|
| 540 | single-subdirs := $(foreach d, $(subdir-ym), $(if $(filter $d/%, $(MAKECMDGOALS)), $d))
|
| 541 | single-subdir-goals := $(filter $(addsuffix /%, $(single-subdirs)), $(MAKECMDGOALS))
|
| 542 |
|
| 543 | $(single-subdir-goals): $(single-subdirs)
|
| 544 | @:
|
| 545 |
|
| 546 | # Descending
|
| 547 | # ---------------------------------------------------------------------------
|
| 548 |
|
| 549 | PHONY += $(subdir-ym)
|
| 550 | $(subdir-ym):
|
| 551 | $(Q)$(MAKE) $(build)=$@ \
|
| 552 | need-builtin=$(if $(filter $@/built-in.a, $(subdir-builtin)),1) \
|
| 553 | need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1) \
|
| 554 | $(filter $@/%, $(single-subdir-goals))
|
| 555 |
|
| 556 | # Add FORCE to the prerequisites of a target to force it to be always rebuilt.
|
| 557 | # ---------------------------------------------------------------------------
|
| 558 |
|
| 559 | PHONY += FORCE
|
| 560 |
|
| 561 | FORCE:
|
| 562 |
|
| 563 | targets += $(filter-out $(single-subdir-goals), $(MAKECMDGOALS))
|
| 564 | targets := $(filter-out $(PHONY), $(targets))
|
| 565 |
|
| 566 | # Now that targets is fully known, include dtb rules if needed
|
| 567 | ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
|
| 568 | include $(srctree)/scripts/Makefile.dtbs
|
| 569 | endif
|
| 570 |
|
| 571 | # Build
|
| 572 | # Needs to be after the include of Makefile.dtbs, which updates always-y
|
| 573 | # ---------------------------------------------------------------------------
|
| 574 |
|
| 575 | $(obj)/: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \
|
| 576 | $(if $(KBUILD_MODULES), $(targets-for-modules)) \
|
| 577 | $(subdir-ym) $(always-y)
|
| 578 | @:
|
| 579 |
|
| 580 | # Read all saved command lines and dependencies for the $(targets) we
|
| 581 | # may be building above, using $(if_changed{,_dep}). As an
|
| 582 | # optimization, we don't need to read them if the target does not
|
| 583 | # exist, we will rebuild anyway in that case.
|
| 584 |
|
| 585 | existing-targets := $(wildcard $(sort $(targets)))
|
| 586 |
|
| 587 | -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
|
| 588 |
|
| 589 | # Create directories for object files if they do not exist
|
| 590 | obj-dirs := $(sort $(patsubst %/,%, $(dir $(targets))))
|
| 591 | # If targets exist, their directories apparently exist. Skip mkdir.
|
| 592 | existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
|
| 593 | obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
|
| 594 | ifneq ($(obj-dirs),)
|
| 595 | $(shell mkdir -p $(obj-dirs))
|
| 596 | endif
|
| 597 |
|
| 598 | .PHONY: $(PHONY)
|