mid-kid
7 years ago
2 changed files with 124 additions and 21 deletions
@ -1,129 +1,232 @@ |
|||||
#!/bin/sh |
#!/bin/sh |
||||
set -e |
set -e |
||||
|
|
||||
|
# This is a SlackBuild script for building as-original-as-possible kernel packages. |
||||
|
# It combines existing SlackBuilds and other files in the slackware source tree with vanilla SlackBuild conventions in a way that is clean and functional. |
||||
|
# Unlike the "official" method of building a Slackware kernel, it builds and installs everything in $TMP, so it doesn't taint the host system, and you can build it as a regular user under fakeroot, if you wanted to. |
||||
|
# This often means that the $PKG directory is used as an intermediate directory to run a SlackBuild in, and that said SlackBuilds may need to be modified to run properly in $PKG. |
||||
|
|
||||
|
# This script is tailored for x86_64. i?86 support is untested, and would need more modifications (such as building the -smp kernels and fixing $TMP in the packaging SlackBuilds). |
||||
|
# Other architectures can be added, provided the source tree for them is anywhere close to the original slackware tree. |
||||
|
|
||||
|
# This SlackBuild should be placed in the "source/k" directory of the source DVD. |
||||
|
# However, this directory doesn't contain all the files we need, as they're scattered all throughout the slackware tree. |
||||
|
|
||||
|
# This code may help prepare the source directory: |
||||
|
if [ "$1" = prepare ]; then |
||||
|
shift |
||||
|
|
||||
|
if [ $# -lt 3 ]; then |
||||
|
echo Usage: $0 prepare \<source\> \<install\> \<output\> 1>&2 |
||||
|
echo e.g. $0 prepare /mnt/tmp/slackware-14.2-source-dvd/source /mnt/tmp/slackware64-14.2-install-dvd/slackware64 ./kernel 1>&2 |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
SOURCE=$1 |
||||
|
INSTALL=$2 |
||||
|
OUT=$3 |
||||
|
|
||||
|
# Copy the "source/k" directory |
||||
|
cp -aT $SOURCE/k $OUT |
||||
|
|
||||
|
# Copy the "source/d/kernel-headers" and "source/a/kernel-firmware" directories into it |
||||
|
cp -at $OUT $SOURCE/d/kernel-headers $SOURCE/a/kernel-firmware |
||||
|
|
||||
|
# Copy "slackware*/k/kernel-source-*-noarch-*.txt" to use as slack-desc for kernel-source into it |
||||
|
mkdir -p $OUT/kernel-source |
||||
|
cp -aT $INSTALL/k/kernel-source-*-noarch-*.txt $OUT/kernel-source/slack-desc |
||||
|
|
||||
|
# Copy the SlackBuild |
||||
|
cp -at $OUT $0 |
||||
|
|
||||
|
exit |
||||
|
fi |
||||
|
|
||||
PKGNAM=${PKGNAM:-linux} |
PKGNAM=${PKGNAM:-linux} |
||||
BASEVER=${BASEVER:-4.4.29} |
BASEVER=${BASEVER:-4.4.14} |
||||
VERSION=${VERSION:-4.4.29} |
VERSION=${VERSION:-$BASEVER} |
||||
ARCH=${ARCH:-x86_64} |
ARCH=${ARCH:-x86_64} |
||||
KARCH=${KARCH:-x86} |
KARCH=${KARCH:-x86} |
||||
BUILD=${BUILD:-1_slack14.2} |
BUILD=${BUILD:-1} |
||||
|
|
||||
CWD=$(pwd) |
CWD=$(pwd) |
||||
TMP=${TMP:-/tmp/kernel} |
TMP=${TMP:-/tmp/kernel} |
||||
PKG=$TMP/package |
|
||||
|
|
||||
NUMJOBS=${NUMJOBS:-" -j7 "} |
NUMJOBS=${NUMJOBS:-" -j7 "} |
||||
|
|
||||
export VERSION ARCH BUILD TMP |
export VERSION ARCH BUILD TMP |
||||
|
|
||||
|
# Extract the kernel source |
||||
mkdir -p $TMP |
mkdir -p $TMP |
||||
|
|
||||
cd $TMP |
cd $TMP |
||||
rm -rf $PKGNAM-$BASEVER $PKGNAM-$VERSION |
rm -rf $PKGNAM-$BASEVER $PKGNAM-$VERSION |
||||
tar xvf $CWD/$PKGNAM-$BASEVER.tar.xz |
tar xvf $CWD/$PKGNAM-$BASEVER.tar.xz |
||||
|
|
||||
# Apply incremental patches |
# Rename the kernel source directory to the proper VERSION |
||||
#mv $PKGNAM-$BASEVER $PKGNAM-$VERSION |
# This is useful if you're applying stable patches and the actual VERSION is different from the one the tarball is named after |
||||
#cd $PKGNAM-$VERSION |
if [ "$BASEVER" != "$VERSION" ]; then |
||||
#xz -cd $CWD/patch-4.4.29-30.xz | patch -p1 --verbose |
mv $PKGNAM-$BASEVER $PKGNAM-$VERSION |
||||
|
fi |
||||
|
|
||||
|
# Apply patches |
||||
|
cd $PKGNAM-$VERSION |
||||
|
#xzcat $CWD/patch-x.x.xx.xz | patch -p1 --verbose |
||||
|
|
||||
|
|
||||
|
# |
||||
# Build kernel-headers |
# Build kernel-headers |
||||
|
# |
||||
cd $TMP/$PKGNAM-$VERSION |
cd $TMP/$PKGNAM-$VERSION |
||||
|
|
||||
|
# Install the kernel headers |
||||
|
PKG=$TMP/package-kernel-headers |
||||
rm -rf $PKG |
rm -rf $PKG |
||||
mkdir -p $PKG/usr |
mkdir -p $PKG/usr |
||||
make $NUMJOBS INSTALL_HDR_PATH=$PKG/usr headers_install |
make $NUMJOBS INSTALL_HDR_PATH=$PKG/usr headers_install |
||||
|
|
||||
|
# Apply some modifications that are present in the original kernel-headers package |
||||
find $PKG/usr -type f -a ! -name '*.h' -delete |
find $PKG/usr -type f -a ! -name '*.h' -delete |
||||
rm -rf $PKG/usr/include/drm |
rm -rf $PKG/usr/include/drm |
||||
mv $PKG/usr/include/asm{,-x86} |
mv $PKG/usr/include/asm $PKG/usr/include/asm-$KARCH |
||||
ln -sf asm-x86 $PKG/usr/include/asm |
ln -sf asm-$KARCH $PKG/usr/include/asm |
||||
|
|
||||
|
# Install the slack-desc |
||||
mkdir -p $PKG/install |
mkdir -p $PKG/install |
||||
cat $CWD/kernel-headers/slack-desc > $PKG/install/slack-desc |
cat $CWD/kernel-headers/slack-desc > $PKG/install/slack-desc |
||||
|
|
||||
|
# Create the package |
||||
cd $PKG |
cd $PKG |
||||
/sbin/makepkg -l y -c n $TMP/kernel-headers-$VERSION-$KARCH-$BUILD.txz |
/sbin/makepkg -l y -c n $TMP/kernel-headers-$(echo $VERSION | tr - _)-$KARCH-$BUILD.txz |
||||
|
|
||||
|
|
||||
|
# |
||||
# Build kernel-huge |
# Build kernel-huge |
||||
|
# |
||||
cd $TMP/$PKGNAM-$VERSION |
cd $TMP/$PKGNAM-$VERSION |
||||
|
|
||||
|
# Build the kernel image |
||||
make $NUMJOBS mrproper |
make $NUMJOBS mrproper |
||||
cat $CWD/config-$ARCH/config-huge-* > .config |
cat $CWD/config-$ARCH/config-huge-* > .config |
||||
make $NUMJOBS oldconfig |
make $NUMJOBS oldconfig |
||||
make $NUMJOBS bzImage |
make $NUMJOBS bzImage |
||||
|
|
||||
|
# Prepare the directory to run the packaging SlackBuild in |
||||
|
PKG=$TMP/kernel-huge |
||||
rm -rf $PKG |
rm -rf $PKG |
||||
mkdir -p $PKG |
mkdir -p $PKG |
||||
cp arch/$KARCH/boot/bzImage $PKG |
cp arch/$KARCH/boot/bzImage $PKG |
||||
cp System.map $PKG |
cp System.map $PKG |
||||
cp .config $PKG/config |
cp .config $PKG/config |
||||
|
|
||||
|
# Copy the packaging SlackBuild |
||||
cp $CWD/packaging-$ARCH/kernel-huge/kernel-huge.SlackBuild $PKG |
cp $CWD/packaging-$ARCH/kernel-huge/kernel-huge.SlackBuild $PKG |
||||
cp $CWD/packaging-$ARCH/kernel-huge/slack-desc $PKG |
cp $CWD/packaging-$ARCH/kernel-huge/slack-desc $PKG |
||||
|
|
||||
|
# Run the packaging SlackBuild |
||||
cd $PKG |
cd $PKG |
||||
./kernel-huge.SlackBuild |
./kernel-huge.SlackBuild |
||||
|
|
||||
|
|
||||
|
# |
||||
# Build kernel-generic |
# Build kernel-generic |
||||
|
# |
||||
cd $TMP/$PKGNAM-$VERSION |
cd $TMP/$PKGNAM-$VERSION |
||||
|
|
||||
|
# Build the kernel image |
||||
make $NUMJOBS mrproper |
make $NUMJOBS mrproper |
||||
cat $CWD/config-$ARCH/config-generic-* > .config |
cat $CWD/config-$ARCH/config-generic-* > .config |
||||
make $NUMJOBS oldconfig |
make $NUMJOBS oldconfig |
||||
make $NUMJOBS bzImage |
make $NUMJOBS bzImage |
||||
|
|
||||
|
# Prepare the directory to run the packaging SlackBuild in |
||||
|
PKG=$TMP/kernel-generic |
||||
rm -rf $PKG |
rm -rf $PKG |
||||
mkdir -p $PKG |
mkdir -p $PKG |
||||
cp arch/$KARCH/boot/bzImage $PKG |
cp arch/$KARCH/boot/bzImage $PKG |
||||
cp System.map $PKG |
cp System.map $PKG |
||||
cp .config $PKG/config |
cp .config $PKG/config |
||||
|
|
||||
|
# Copy the packaging SlackBuild |
||||
cp $CWD/packaging-$ARCH/kernel-generic/kernel-generic.SlackBuild $PKG |
cp $CWD/packaging-$ARCH/kernel-generic/kernel-generic.SlackBuild $PKG |
||||
cp $CWD/packaging-$ARCH/kernel-generic/slack-desc $PKG |
cp $CWD/packaging-$ARCH/kernel-generic/slack-desc $PKG |
||||
|
|
||||
|
# Run the packaging SlackBuild |
||||
cd $PKG |
cd $PKG |
||||
./kernel-generic.SlackBuild |
./kernel-generic.SlackBuild |
||||
|
|
||||
|
|
||||
|
# |
||||
# Build kernel-modules |
# Build kernel-modules |
||||
|
# |
||||
cd $TMP/$PKGNAM-$VERSION |
cd $TMP/$PKGNAM-$VERSION |
||||
|
|
||||
|
# Build the kernel modules with the already-present kernel-generic config |
||||
make $NUMJOBS modules |
make $NUMJOBS modules |
||||
|
|
||||
|
# Prepare the directory to run the packaging SlackBuild in |
||||
|
PKG=$TMP/kernel-modules |
||||
rm -rf $PKG |
rm -rf $PKG |
||||
mkdir -p $PKG |
mkdir -p $PKG |
||||
make $NUMJOBS INSTALL_MOD_PATH=$PKG modules_install |
make $NUMJOBS INSTALL_MOD_PATH=$PKG modules_install |
||||
|
|
||||
rm -f $PKG/lib/modules/$VERSION/{build,source} |
# Point the build and source links to the proper source directory in /usr/src, as packaged in kernel-source |
||||
|
rm -f $PKG/lib/modules/$VERSION/build $PKG/lib/modules/$VERSION/source |
||||
ln -s /usr/src/$PKGNAM-$VERSION $PKG/lib/modules/$VERSION/build |
ln -s /usr/src/$PKGNAM-$VERSION $PKG/lib/modules/$VERSION/build |
||||
ln -s /usr/src/$PKGNAM-$VERSION $PKG/lib/modules/$VERSION/source |
ln -s /usr/src/$PKGNAM-$VERSION $PKG/lib/modules/$VERSION/source |
||||
|
|
||||
|
# Copy the packaging SlackBuild |
||||
cp $CWD/packaging-$ARCH/kernel-modules/kernel-modules.SlackBuild $PKG |
cp $CWD/packaging-$ARCH/kernel-modules/kernel-modules.SlackBuild $PKG |
||||
cp $CWD/packaging-$ARCH/kernel-modules/slack-desc $PKG |
cp $CWD/packaging-$ARCH/kernel-modules/slack-desc $PKG |
||||
|
|
||||
|
# Prefix absolute module paths in the SlackBuild with $CWD, since we installed the modules there |
||||
sed -i -e 's@/lib/modules/${KERNELRELEASE}@$CWD&@' $PKG/kernel-modules.SlackBuild |
sed -i -e 's@/lib/modules/${KERNELRELEASE}@$CWD&@' $PKG/kernel-modules.SlackBuild |
||||
|
|
||||
|
# Run the packaging SlackBuild |
||||
cd $PKG |
cd $PKG |
||||
KERNELRELEASE=$VERSION ./kernel-modules.SlackBuild |
KERNELRELEASE=$VERSION ./kernel-modules.SlackBuild |
||||
|
|
||||
|
|
||||
|
# |
||||
# Build kernel-source |
# Build kernel-source |
||||
|
# |
||||
cd $TMP/$PKGNAM-$VERSION |
cd $TMP/$PKGNAM-$VERSION |
||||
|
|
||||
|
# Cleanup the source directory that was prepared and built with the kernel-generic config |
||||
make $NUMJOBS clean |
make $NUMJOBS clean |
||||
make $NUMJOBS prepare |
make $NUMJOBS prepare |
||||
rm .version .config.old |
rm .version .config.old |
||||
|
|
||||
|
# Install the kernel source |
||||
|
PKG=$TMP/package-kernel-source |
||||
rm -rf $PKG |
rm -rf $PKG |
||||
mkdir -p $PKG/usr/src |
mkdir -p $PKG/usr/src |
||||
ln -s $PKGNAM-$VERSION $PKG/usr/src/$PKGNAM |
ln -s $PKGNAM-$VERSION $PKG/usr/src/$PKGNAM |
||||
|
|
||||
|
# Install the slack-desc |
||||
mkdir -p $PKG/install |
mkdir -p $PKG/install |
||||
cat $CWD/kernel-source/slack-desc > $PKG/install/slack-desc |
cat $CWD/kernel-source/slack-desc > $PKG/install/slack-desc |
||||
|
|
||||
|
# Create the package |
||||
cd $PKG |
cd $PKG |
||||
mv $TMP/$PKGNAM-$VERSION usr/src |
mv $TMP/$PKGNAM-$VERSION usr/src |
||||
/sbin/makepkg -l y -c n $TMP/kernel-source-$VERSION-noarch-$BUILD.txz |
/sbin/makepkg -l y -c n $TMP/kernel-source-$(echo $VERSION | tr - _)-noarch-$BUILD.txz |
||||
|
|
||||
# Build kernel-firmware |
|
||||
exit |
|
||||
|
|
||||
|
# |
||||
|
# Build kernel-firmware |
||||
|
# |
||||
cd $TMP |
cd $TMP |
||||
|
|
||||
|
# Prepare the directory to run the packaging SlackBuild in |
||||
|
PKG=$TMP/kernel-firmware |
||||
rm -rf $PKG |
rm -rf $PKG |
||||
mkdir -p $PKG |
mkdir -p $PKG |
||||
cp -a $CWD/kernel-firmware $PKG |
cp -aT $CWD/kernel-firmware $PKG |
||||
sed -i -e 's/git clone/& --depth=1/' $PKG/kernel-firmware/kernel-firmware.SlackBuild |
|
||||
|
|
||||
cd $PKG/kernel-firmware |
# Use --depth=1 to cause git to not to download the entire history |
||||
unset VERSION |
sed -i -e 's/git clone/& --depth=1/' $PKG/kernel-firmware.SlackBuild |
||||
|
|
||||
|
# Run the packaging SlackBuild |
||||
|
cd $PKG |
||||
|
unset VERSION # The script uses `date` to make a $VERSION |
||||
./kernel-firmware.SlackBuild |
./kernel-firmware.SlackBuild |
||||
|
Loading…
Reference in new issue