Build linux-source package for the kernel

Small refactoring
This commit is contained in:
zador-blood-stained
2017-08-01 22:07:58 +03:00
parent a39390da23
commit 04f5972b9c
2 changed files with 53 additions and 27 deletions

View File

@@ -11,6 +11,7 @@
# compile_uboot
# compile_kernel
# compile_sunxi_tools
# grab_version
# find_toolchain
# advanced_patch
# process_patch_file
@@ -183,12 +184,26 @@ compile_kernel()
[[ $FORCE_CHECKOUT == yes ]] && advanced_patch "kernel" "$KERNELPATCHDIR" "$BOARD" "" "$BRANCH" "$LINUXFAMILY-$BRANCH"
# create patch for manual source changes in debug mode
[[ $CREATE_PATCHES == yes ]] && userpatch_create "kernel"
if ! grep -qoE '^-rc[[:digit:]]+' <(grep "^EXTRAVERSION" Makefile | head -1 | awk '{print $(NF)}'); then
sed -i 's/EXTRAVERSION = .*/EXTRAVERSION = /' Makefile
fi
rm -f localversion
# read kernel version
local version=$(grab_version "$kerneldir")
# create linux-source package - with already patched sources
local sources_pkg_dir=$SRC/.tmp/linux-source-${BRANCH}-${LINUXFAMILY}_${REVISION}_all
rm -rf ${sources_pkg_dir}
mkdir -p $sources_pkg_dir/usr/src/ $sources_pkg_dir/usr/share/doc/linux-source-${version}-${LINUXFAMILY} $sources_pkg_dir/DEBIAN
display_alert "Compressing sources for the linux-source package"
tar cp --directory="$kerneldir" --exclude='./.git/' . | pixz -4 > $sources_pkg_dir/usr/src/linux-source-${version}-${LINUXFAMILY}.tar.xz
cp COPYING $sources_pkg_dir/usr/share/doc/linux-source-${version}-${LINUXFAMILY}/LICENSE
# create patch for manual source changes in debug mode
[[ $CREATE_PATCHES == yes ]] && userpatch_create "kernel"
display_alert "Compiling $BRANCH kernel" "$version" "info"
local toolchain=""
@@ -216,11 +231,6 @@ compile_kernel()
# hack for deb builder. To pack what's missing in headers pack.
cp $SRC/patch/misc/headers-debian-byteshift.patch /tmp
export LOCALVERSION="-$LINUXFAMILY"
sed -i 's/EXTRAVERSION = .*/EXTRAVERSION =/' Makefile
rm -f localversion
if [[ $KERNEL_CONFIGURE != yes ]]; then
if [[ $BRANCH == default ]]; then
make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" silentoldconfig
@@ -241,8 +251,11 @@ compile_kernel()
fi
fi
xz < .config > $sources_pkg_dir/usr/src/${LINUXCONFIG}_${version}_${REVISION}_config.xz
eval CCACHE_BASEDIR="$(pwd)" ${toolchain:+env PATH=$toolchain:$PATH} \
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" $KERNEL_IMAGE_TYPE modules dtbs 2>&1' \
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" LOCALVERSION="-$LINUXFAMILY" \
$KERNEL_IMAGE_TYPE modules dtbs 2>&1' \
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling kernel..." $TTY_Y $TTY_X'} \
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
@@ -258,14 +271,33 @@ compile_kernel()
local kernel_packing="deb-pkg"
fi
display_alert "Creating packages"
# produce deb packages: image, headers, firmware, dtb
eval CCACHE_BASEDIR="$(pwd)" ${toolchain:+env PATH=$toolchain:$PATH} \
'make -j1 $kernel_packing KDEB_PKGVERSION=$REVISION LOCALVERSION="-"$LINUXFAMILY \
'make -j1 $kernel_packing KDEB_PKGVERSION=$REVISION LOCALVERSION="-${LINUXFAMILY}" \
KBUILD_DEBARCH=$ARCH ARCH=$ARCHITECTURE DEBFULLNAME="$MAINTAINER" DEBEMAIL="$MAINTAINERMAIL" CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" 2>&1' \
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Creating kernel packages..." $TTY_Y $TTY_X'} \
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
cat <<-EOF > $sources_pkg_dir/DEBIAN/control
Package: linux-source-${version}-${LINUXFAMILY}
Version: ${version}-${LINUXFAMILY}+${REVISION}
Architecture: all
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
Section: kernel
Priority: optional
Depends: binutils, coreutils
Provides: linux-source
Recommends: gcc, make
Description: This package provides the source code for the Linux kernel $version
EOF
dpkg-deb -z0 -b $sources_pkg_dir ${sources_pkg_dir}.deb
mv ${sources_pkg_dir}.deb $DEST/debs/
rm -rf $sources_pkg_dir
cd ..
mv *.deb $DEST/debs/ || exit_with_error "Failed moving kernel DEBs"
}
@@ -285,6 +317,16 @@ compile_sunxi_tools()
fi
}
grab_version()
{
local ver=()
ver[0]=$(grep "^VERSION" $1/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
ver[1]=$(grep "^PATCHLEVEL" $1/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
ver[2]=$(grep "^SUBLEVEL" $1/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
ver[3]=$(grep "^EXTRAVERSION" $1/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^-rc[[:digit:]]+')
echo "${ver[0]:-0}${ver[1]:+.${ver[1]}}${ver[2]:+.${ver[2]}}${ver[3]}"
}
# find_toolchain <compiler_prefix> <expression>
#
# returns path to toolchain that satisfies <expression>

View File

@@ -14,7 +14,6 @@
# create_sources_list
# fetch_from_repo
# display_alert
# grab_version
# fingerprint_image
# addtorepo
# prepare_host
@@ -40,6 +39,7 @@ cleaning()
find $DEST/debs \( -name "${CHOSEN_KERNEL}_*.deb" -o \
-name "${CHOSEN_KERNEL/image/dtb}_*.deb" -o \
-name "${CHOSEN_KERNEL/image/headers}_*.deb" -o \
-name "${CHOSEN_KERNEL/image/source}_*.deb" -o \
-name "${CHOSEN_KERNEL/image/firmware-image}_*.deb" \) -delete
[[ -n $RELEASE ]] && rm -f $DEST/debs/$RELEASE/${CHOSEN_ROOTFS}_*.deb
fi
@@ -315,22 +315,6 @@ display_alert()
esac
}
#---------------------------------------------------------------------------------------------------------------------------------
# grab_version <path>
#
# <path>: Extract kernel or uboot version from $path/Makefile
#---------------------------------------------------------------------------------------------------------------------------------
grab_version()
{
local ver=""
for component in VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION; do
tmp=$(cat $1/Makefile | grep $component | head -1 | awk '{print $(NF)}' | cut -d '=' -f 2)"#"
[[ $tmp != "#" ]] && ver="$ver$tmp"
done
ver=${ver//#/.}; ver=${ver%.}; ver=${ver//.-/-}
echo $ver
}
fingerprint_image()
{
#--------------------------------------------------------------------------------------------------------------------------------
@@ -481,7 +465,7 @@ prepare_host()
parted pkg-config libncurses5-dev whiptail debian-keyring debian-archive-keyring f2fs-tools libfile-fcntllock-perl rsync libssl-dev \
nfs-kernel-server btrfs-tools gcc-aarch64-linux-gnu ncurses-term p7zip-full dos2unix dosfstools libc6-dev-armhf-cross libc6-dev-armel-cross \
libc6-dev-arm64-cross curl gcc-arm-none-eabi libnewlib-arm-none-eabi patchutils python liblz4-tool libpython2.7-dev linux-base swig libpython-dev \
locales ncurses-base"
locales ncurses-base pixz"
local codename=$(lsb_release -sc)
display_alert "Build host OS release" "${codename:-(unknown)}" "info"