# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../linux26-src/linux26-src.conf
# Copyright (C) 2007 The OpenSDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

# include the function to patch and configure the kernel
. $base/package/*/*/linux-conf.in

main_lx_src() {
	local vanilla_ver=$( echo $ver | cut -d. -f1-3 )
	local patches_dir=

	echo "Extracting the Linux Kernel Sources [$vanilla_ver] ... "

	# hack to extract the files into our usr/src dir ...
	# this part is continued inside lx_injectextraversion
	tar $taropt $( match_source_file -p linux linux$treever | head -n 1 )

	chown -R 0:0 linux-$vanilla_ver; chmod go=u,go-w linux-$vanilla_ver
	cd linux-$vanilla_ver

	lx_patch
	lx_config

	patches_dir="$root/usr/src/linux-$lx_kernelrelease-patches"

	# remove debug configs
	rm -f .config.[1-9]

	if [ "$SDECFG_PKG_LINUX_CONFIG_STYLE" = none ] ; then
		# create a valid .config (new settings may be available etc.)
		yes '' | eval $MAKE oldconfig > /dev/null
	fi

	if grep -q "CONFIG_MODULES=y" .config ; then
		eval $MAKE $makeopt modules_prepare
	fi

	echo "Clean up the *.orig and *~ files ... "
	find -name '*.orig' -o -name '*~' | xargs rm -f
	rm -f .config.old

	echo "Copying kernel patches ... "
	rm -rf "$patches_dir"; mkdir -p "$patches_dir"

	cat <<-EOT > $patches_dir/README
	This directory contains all the applied patches, used
	to build the kernel (in addition to the official kernel sources).
	EOT

	for x in $patchfiles ; do
		# if the patch does not exist it was downloaded or so
		# and we just do not copy it ...
		[ ! -f "$x" ] || cp -v "$x" "$patches_dir"
	done

	if [ "$SDECFG_PKG_LINUX_CONFIG_STYLE" != none ] ; then
		cp -v .config_nomods	"$patches_dir/config_nomods.txt"
		cp -v .config_modules	"$patches_dir/config_modules.txt"
	fi
	cp -v .config "$patches_dir/config.txt"

	echo "Installing kernel sources [$lx_kernelrelease] "
	rm -rf $root/usr/src/{linux-$lx_kernelrelease,linux}
	mkdir -vp "$root/usr/src/linux-$lx_kernelrelease"
	ln -svnf "linux-$lx_kernelrelease" $root/usr/src/linux

	tar -cf - * | tar -C "$root/usr/src/linux-$lx_kernelrelease" -xf -
	cp -v .config "$root/usr/src/linux-$lx_kernelrelease/"
}

createdocs=0
srctar=none

custmain="main_lx_src"

for x in $( match_source_file -p patch-.* linux$treever | grep -v '\.tar\.' ); do
	var_insert patchfiles " " "$x"
done
for x in $( ls -1d $base/package/$repository/linux$treever/*.patch ); do
	var_append patchfiles " " "$x"
done