+ # Copy arch scripts
+ (find arch -name scripts -type d -print0 | \
+ xargs -0 -n1 -i: find : -type f) | \
+ cpio -pd --preserve-modification-time "${LINUX_HDROBJ_DIR}"
+
+ # Cleanup scripts
+ rm -f "${LINUX_HDROBJ_DIR}/scripts/*.o"
+ rm -f "${LINUX_HDROBJ_DIR}/scripts/*/*.o"
+
+ # On powerpc 32bits this object is required to link modules
+ if [ "${karch}" = "powerpc" ]; then
+ if [ "x$(scripts/config -s CONFIG_PPC64)" = "xy" ] && vergte "${kversion}" "5.4"; then
+ :
+ else
+ cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LINUX_HDROBJ_DIR}/"
+ fi
+ fi
+
+ # On arm64 between 4.13 and 1.15 this object is required to build with ftrace support
+ if [ "${karch}" = "arm64" ]; then
+ if [ -f "arch/arm64/kernel/ftrace-mod.S" ]; then
+ cp -a --parents arch/arm64/kernel/ftrace-mod.[So] "${LINUX_HDROBJ_DIR}/"
+ fi
+ fi
+
+ # Newer kernels need objtool to build modules when CONFIG_STACK_VALIDATION=y
+ if [ -f tools/objtool/objtool ]; then
+ cp -a --parents tools/objtool/objtool "${LINUX_HDROBJ_DIR}/"
+ fi
+
+ if [ -f "arch/x86/kernel/macros.s" ]; then
+ cp -a --parents arch/x86/kernel/macros.s "${LINUX_HDROBJ_DIR}/"
+ fi
+
+ # Copy modules related stuff, if available
+ if [ -s Module.symvers ]; then
+ cp Module.symvers "${LINUX_HDROBJ_DIR}"
+ fi
+
+ if [ -s System.map ]; then
+ cp System.map "${LINUX_HDROBJ_DIR}"
+ fi
+
+ if [ -s Module.markers ]; then
+ cp Module.markers "${LINUX_HDROBJ_DIR}"
+ fi
+
+ # Copy config file
+ cp .config "${LINUX_HDROBJ_DIR}"
+
+ # Make sure the Makefile and version.h have a matching timestamp so that
+ # external modules can be built
+ if [ -s "${LINUX_HDROBJ_DIR}/include/generated/uapi/linux/version.h" ]; then
+ touch -r "${LINUX_HDROBJ_DIR}/Makefile" "${LINUX_HDROBJ_DIR}/include/generated/uapi/linux/version.h"
+ elif [ -s "${LINUX_HDROBJ_DIR}/include/linux/version.h" ]; then
+ touch -r "${LINUX_HDROBJ_DIR}/Makefile" "${LINUX_HDROBJ_DIR}/include/linux/version.h"
+ else
+ echo "Missing version.h"
+ exit 1
+ fi
+ touch -r "${LINUX_HDROBJ_DIR}/.config" "${LINUX_HDROBJ_DIR}/include/generated/autoconf.h"
+
+ # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
+ cp "${LINUX_HDROBJ_DIR}/.config" "${LINUX_HDROBJ_DIR}/include/config/auto.conf"
+
+ # Finally clean the object files from the full source tree
+ make clean
+
+ # And regen the modules support files
+ make modules_prepare CC="$CC"
+
+ # On powerpc 32bits this object is required to link modules
+ if [ "${karch}" = "powerpc" ]; then
+ if [ "x$(scripts/config -s CONFIG_PPC64)" = "xy" ] && vergte "${kversion}" "5.4"; then
+ :
+ else
+ make arch/powerpc/lib/crtsavres.o CC="$CC"
+ fi
+ fi
+
+ # On arm64 between 4.13 and 4.15 this object is required to build with ftrace support
+ if [ "${karch}" = "arm64" ]; then
+ if [ -f "arch/arm64/kernel/ftrace-mod.S" ]; then
+ make arch/arm64/kernel/ftrace-mod.o CC="$CC"
+ fi
+ fi