@@ -129,6 +129,11 @@ endif
129129$(if $(word 2, $(KBUILD_EXTMOD)), \
130130 $(error building multiple external modules is not supported))
131131
132+ # Remove trailing slashes
133+ ifneq ($(filter % /, $(KBUILD_EXTMOD ) ) ,)
134+ KBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD ) .)
135+ endif
136+
132137export KBUILD_EXTMOD
133138
134139# Kbuild will save output files in the current working directory.
@@ -544,14 +549,21 @@ scripts_basic:
544549 $(Q ) rm -f .tmp_quiet_recordmcount
545550
546551PHONY += outputmakefile
552+ ifdef building_out_of_srctree
547553# Before starting out-of-tree build, make sure the source tree is clean.
548554# outputmakefile generates a Makefile in the output directory, if using a
549555# separate output directory. This allows convenient use of make in the
550556# output directory.
551557# At the same time when output Makefile generated, generate .gitignore to
552558# ignore whole output directory
559+
560+ quiet_cmd_makefile = GEN Makefile
561+ cmd_makefile = { \
562+ echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \
563+ echo "include $(srctree)/Makefile"; \
564+ } > Makefile
565+
553566outputmakefile :
554- ifdef building_out_of_srctree
555567 $(Q ) if [ -f $( srctree) /.config -o \
556568 -d $(srctree ) /include/config -o \
557569 -d $(srctree ) /arch/$(SRCARCH ) /include/generated ]; then \
@@ -562,7 +574,7 @@ ifdef building_out_of_srctree
562574 false ; \
563575 fi
564576 $(Q ) ln -fsn $(srctree ) source
565- $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree )
577+ $(call cmd,makefile )
566578 $(Q ) test -e .gitignore || \
567579 { echo " # this is build directory, ignore it" ; echo " *" ; } > .gitignore
568580endif
@@ -658,7 +670,7 @@ endif
658670
659671ifeq ($(KBUILD_EXTMOD ) ,)
660672# Objects we will link into vmlinux / subdirs we need to visit
661- core-y := init/ usr/
673+ core-y := init/ usr/ arch/ $( SRCARCH ) /
662674drivers-y := drivers/ sound/
663675drivers-$(CONFIG_SAMPLES) += samples/
664676drivers-$(CONFIG_NET) += net/
@@ -961,8 +973,8 @@ KBUILD_CFLAGS += $(CC_FLAGS_CFI)
961973export CC_FLAGS_CFI
962974endif
963975
964- ifdef CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_32B
965- KBUILD_CFLAGS += -falign-functions=32
976+ ifdef CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_64B
977+ KBUILD_CFLAGS += -falign-functions=64
966978endif
967979
968980# arch Makefile may override CC so keep this after arch Makefile is included
@@ -1089,41 +1101,6 @@ export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
10891101MODLIB = $(INSTALL_MOD_PATH ) /lib/modules/$(KERNELRELEASE )
10901102export MODLIB
10911103
1092- HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
1093-
1094- has_libelf = $(call try-run,\
1095- echo "int main() {}" | $(HOSTCC ) $(KBUILD_HOSTLDFLAGS ) -xc -o /dev/null $(HOST_LIBELF_LIBS ) -,1,0)
1096-
1097- ifdef CONFIG_STACK_VALIDATION
1098- ifeq ($(has_libelf),1)
1099- objtool_target := tools/objtool FORCE
1100- else
1101- SKIP_STACK_VALIDATION := 1
1102- export SKIP_STACK_VALIDATION
1103- endif
1104- endif
1105-
1106- PHONY += resolve_btfids_clean
1107-
1108- resolve_btfids_O = $(abspath $(objtree ) ) /tools/bpf/resolve_btfids
1109-
1110- # tools/bpf/resolve_btfids directory might not exist
1111- # in output directory, skip its clean in that case
1112- resolve_btfids_clean :
1113- ifneq ($(wildcard $(resolve_btfids_O ) ) ,)
1114- $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
1115- endif
1116-
1117- ifdef CONFIG_BPF
1118- ifdef CONFIG_DEBUG_INFO_BTF
1119- ifeq ($(has_libelf),1)
1120- resolve_btfids_target := tools/bpf/resolve_btfids FORCE
1121- else
1122- ERROR_RESOLVE_BTFIDS := 1
1123- endif
1124- endif # CONFIG_DEBUG_INFO_BTF
1125- endif # CONFIG_BPF
1126-
11271104PHONY += prepare0
11281105
11291106export extmod_prefix = $(if $(KBUILD_EXTMOD ) ,$(KBUILD_EXTMOD ) /)
@@ -1235,7 +1212,7 @@ prepare0: archprepare
12351212 $(Q )$(MAKE ) $(build ) =.
12361213
12371214# All the preparing..
1238- prepare : prepare0 prepare-objtool prepare-resolve_btfids
1215+ prepare : prepare0
12391216
12401217PHONY += remove-stale-files
12411218remove-stale-files :
@@ -1252,26 +1229,6 @@ uapi-asm-generic:
12521229 $(Q )$(MAKE ) $(asm-generic ) =arch/$(SRCARCH ) /include/generated/uapi/asm \
12531230 generic=include/uapi/asm-generic
12541231
1255- PHONY += prepare-objtool prepare-resolve_btfids
1256- prepare-objtool : $(objtool_target )
1257- ifeq ($(SKIP_STACK_VALIDATION ) ,1)
1258- ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
1259- @echo "error: Cannot generate __mcount_loc for CONFIG_DYNAMIC_FTRACE=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1260- @false
1261- endif
1262- ifdef CONFIG_UNWINDER_ORC
1263- @echo "error: Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1264- @false
1265- else
1266- @echo "warning: Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1267- endif
1268- endif
1269-
1270- prepare-resolve_btfids : $(resolve_btfids_target )
1271- ifeq ($(ERROR_RESOLVE_BTFIDS ) ,1)
1272- @echo "error: Cannot resolve BTF IDs for CONFIG_DEBUG_INFO_BTF, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1273- @false
1274- endif
12751232# Generate some files
12761233# ---------------------------------------------------------------------------
12771234
@@ -1359,6 +1316,43 @@ PHONY += scripts_unifdef
13591316scripts_unifdef : scripts_basic
13601317 $(Q )$(MAKE ) $(build ) =scripts scripts/unifdef
13611318
1319+ # ---------------------------------------------------------------------------
1320+ # Tools
1321+
1322+ ifdef CONFIG_STACK_VALIDATION
1323+ prepare : tools/objtool
1324+ endif
1325+
1326+ ifdef CONFIG_BPF
1327+ ifdef CONFIG_DEBUG_INFO_BTF
1328+ prepare : tools/bpf/resolve_btfids
1329+ endif
1330+ endif
1331+
1332+ PHONY += resolve_btfids_clean
1333+
1334+ resolve_btfids_O = $(abspath $(objtree ) ) /tools/bpf/resolve_btfids
1335+
1336+ # tools/bpf/resolve_btfids directory might not exist
1337+ # in output directory, skip its clean in that case
1338+ resolve_btfids_clean :
1339+ ifneq ($(wildcard $(resolve_btfids_O ) ) ,)
1340+ $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
1341+ endif
1342+
1343+ # Clear a bunch of variables before executing the submake
1344+ ifeq ($(quiet ) ,silent_)
1345+ tools_silent =s
1346+ endif
1347+
1348+ tools/ : FORCE
1349+ $(Q ) mkdir -p $(objtree ) /tools
1350+ $(Q )$(MAKE ) LDFLAGS= MAKEFLAGS=" $( tools_silent) $( filter --j% -j,$( MAKEFLAGS) ) " O=$(abspath $(objtree ) ) subdir=tools -C $(srctree ) /tools/
1351+
1352+ tools/% : FORCE
1353+ $(Q ) mkdir -p $(objtree ) /tools
1354+ $(Q )$(MAKE ) LDFLAGS= MAKEFLAGS=" $( tools_silent) $( filter --j% -j,$( MAKEFLAGS) ) " O=$(abspath $(objtree ) ) subdir=tools -C $(srctree ) /tools/ $*
1355+
13621356# ---------------------------------------------------------------------------
13631357# Kernel selftest
13641358
@@ -1959,20 +1953,6 @@ kernelversion:
19591953image_name :
19601954 @echo $(KBUILD_IMAGE )
19611955
1962- # Clear a bunch of variables before executing the submake
1963-
1964- ifeq ($(quiet ) ,silent_)
1965- tools_silent =s
1966- endif
1967-
1968- tools/ : FORCE
1969- $(Q ) mkdir -p $(objtree ) /tools
1970- $(Q )$(MAKE ) LDFLAGS= MAKEFLAGS=" $( tools_silent) $( filter --j% -j,$( MAKEFLAGS) ) " O=$(abspath $(objtree ) ) subdir=tools -C $(srctree ) /tools/
1971-
1972- tools/% : FORCE
1973- $(Q ) mkdir -p $(objtree ) /tools
1974- $(Q )$(MAKE ) LDFLAGS= MAKEFLAGS=" $( tools_silent) $( filter --j% -j,$( MAKEFLAGS) ) " O=$(abspath $(objtree ) ) subdir=tools -C $(srctree ) /tools/ $*
1975-
19761956quiet_cmd_rmfiles = $(if $(wildcard $(rm-files ) ) ,CLEAN $(wildcard $(rm-files ) ) )
19771957 cmd_rmfiles = rm -rf $(rm-files )
19781958
0 commit comments