
lx_config ()
{
	echo "Generic linux source patching and configuration ..."

	mainver="`echo $ver | sed s/_.*//`"
	patchver="`echo $ver | sed s/.*_//`"

	echo "  ... For version [$mainver], patchlevel [$patchver]."

	echo -n "Extracting the Linux Kernel Sources [$mainver] ..."
	tar --use-compress-program=bzip2 -xf \
		$base/pkg-archive/linux-$mainver.tar.bz2
	echo 'done'

	cd linux-$mainver

	if [ "$patchver" ] ; then
	  echo "Patching to version $patchver ..."
	  bunzip2 -c $base/pkg-archive/patch-$patchver.bz2 | patch -p1
	fi

	if [ "$1" = "patch" ] ; then
	  echo "Patching ..."
          for x in $base/misc/linux/*.patch ; do
                echo "Applying '$x' ..."
                patch -p1 -s < $x
          done
	fi

        echo "lx_cpu is $lx_cpu."
        echo "Create symlinks and a few headers for arch <$lx_cpu> ... "
        make ARCH=$lx_cpu include/linux/version.h symlinks
        cp $base/misc/linux/autoconf.h include/linux/
        touch include/linux/modversions.h

	echo "Creating default configuration ...."
	echo "  using: '$base/arch-conf/$arch/kernel.conf'"
	cp $base/arch-conf/$arch/kernel.conf .config
	echo "  merging: 'arch/$lx_cpu/defconfig'"
	cat arch/$lx_cpu/defconfig | \
	while read line ; do
		label=`echo $line | sed 's,=.*,,; s,# \([^ ]*\).*,\1,;'`
		if expr "$label" : "CONFIG_.*" > /dev/null &&
		! grep -q "$label[ =]" $base/arch-conf/$arch/kernel.conf
		then
			echo $line >> .config
		fi
	done
	
	
	echo "Selecting modules ...."
	cp .config config.new
	#cp .config debug1
	ARCH=$lx_cpu bash ./scripts/Configure -M arch/$lx_cpu/config.in > /dev/null

	#echo "  merging: arch/$lx_cpu/config.in"
	#bash ./scripts/Configure -M arch/$lx_cpu/config.in > /dev/null
	#echo "  tricky all scsi / all net selection ..."
	#find . drivers/scsi drivers/net -name 'Config.in' | xargs cat | \
	#tr ' "' '\n\n' | grep '^CONFIG_' | sort -u | \
	#{ sed 's,.*,grep -x "&=m" .config >> config.new,' ; \
	#echo exit 0 ; } | bash
	#mv config.new .config
	#echo "  merging: arch/$lx_cpu/config.in"
	bash ./scripts/Configure -D arch/$lx_cpu/config.in > /dev/null
	#cp .config debug2

	echo "disable broken handling ..."
	sh $base/misc/linux/disable-broken.sh \
	$base/arch-conf/$arch/kernel-disable.lst \
	$base/misc/linux/disable-broken.lst < .config > config.new
	mv -f config.new .config
	ARCH=$lx_cpu bash ./scripts/Configure -D \
	arch/$lx_cpu/config.in > /dev/null
	cp .config $root/usr/src/kernel/.config-kernel

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

	echo "Generic linux source configuration finished."
}

