Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-only
3
4set -eu
5
6destdir=${1}
7
8is_enabled() {
9 grep -q "^$1=y" include/config/auto.conf
10}
11
12find_in_scripts() {
13 find scripts \
14 \( -name atomic -o -name dtc -o -name kconfig -o -name package \) -prune -o \
15 ! -name unifdef -a ! -name mk_elfconfig -a \( -type f -o -type l \) -print
16}
17
18mkdir -p "${destdir}"
19
20(
21 cd "${srctree}"
22 echo Makefile
23 find "arch/${SRCARCH}" -maxdepth 1 -name 'Makefile*'
24 find "arch/${SRCARCH}" -name generated -prune -o -name include -type d -print
25 find "arch/${SRCARCH}" -name Kbuild.platforms -o -name Platform
26 find include \( -name config -o -name generated \) -prune -o \( -type f -o -type l \) -print
27 find_in_scripts
28) | tar -c -f - -C "${srctree}" -T - | tar -xf - -C "${destdir}"
29
30{
31 if is_enabled CONFIG_OBJTOOL; then
32 echo tools/objtool/objtool
33 fi
34
35 if is_enabled CONFIG_DEBUG_INFO_BTF_MODULES; then
36 echo tools/bpf/resolve_btfids/resolve_btfids
37 fi
38
39 echo Module.symvers
40 echo "arch/${SRCARCH}/include/generated"
41 echo include/config/auto.conf
42 echo include/config/kernel.release
43 echo include/generated
44 find_in_scripts
45
46 if is_enabled CONFIG_GCC_PLUGINS; then
47 find scripts/gcc-plugins -name '*.so'
48 fi
49} | tar -c -f - -T - | tar -xf - -C "${destdir}"
50
51# When ${CC} and ${HOSTCC} differ, rebuild host programs using ${CC}.
52#
53# This caters to host programs that participate in Kbuild. objtool and
54# resolve_btfids are out of scope.
55if [ "${CC}" != "${HOSTCC}" ]; then
56 cat "${destdir}/scripts/Makefile" - <<-'EOF' > "${destdir}/scripts/Kbuild"
57 subdir-y += basic
58 hostprogs-always-y += mod/modpost
59 mod/modpost-objs := $(addprefix mod/, modpost.o file2alias.o sumversion.o symsearch.o)
60 EOF
61
62 # HOSTCXX is not overridden. The C++ compiler is used to build:
63 # - scripts/kconfig/qconf, which is unneeded for external module builds
64 # - GCC plugins, which will not work on the installed system even after
65 # being rebuilt.
66 #
67 # Clear VPATH and srcroot because the source files reside in the output
68 # directory.
69 # shellcheck disable=SC2016 # $(MAKE) and $(build) will be expanded by Make
70 "${MAKE}" run-command KBUILD_RUN_COMMAND='+$(MAKE) HOSTCC="'"${CC}"'" VPATH= srcroot=. $(build)='"$(realpath --relative-to=. "${destdir}")"/scripts
71
72 rm -f "${destdir}/scripts/Kbuild"
73fi
74
75find "${destdir}" \( -name '.*.cmd' -o -name '*.o' \) -delete