1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-only
3
4set -e
5
6destdir=${1}
7
8test -n "${srctree}"
9test -n "${SRCARCH}"
10
11is_enabled() {
12	grep -q "^$1=y" include/config/auto.conf
13}
14
15mkdir -p "${destdir}"
16
17(
18	cd "${srctree}"
19	echo Makefile
20	find "arch/${SRCARCH}" -maxdepth 1 -name 'Makefile*'
21	find include scripts -type f -o -type l
22	find "arch/${SRCARCH}" -name Kbuild.platforms -o -name Platform
23	find "$(find "arch/${SRCARCH}" -name include -o -name scripts -type d)" -type f
24) | tar -c -f - -C "${srctree}" -T - | tar -xf - -C "${destdir}"
25
26{
27	if is_enabled CONFIG_OBJTOOL; then
28		echo tools/objtool/objtool
29	fi
30
31	find "arch/${SRCARCH}/include" Module.symvers include scripts -type f
32
33	if is_enabled CONFIG_GCC_PLUGINS; then
34		find scripts/gcc-plugins -name '*.so'
35	fi
36} | tar -c -f - -T - | tar -xf - -C "${destdir}"
37
38# copy .config manually to be where it's expected to be
39cp "${KCONFIG_CONFIG}" "${destdir}/.config"
40