134 lines
3.8 KiB
Bash
Executable file
134 lines
3.8 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -e
|
|
#set -x
|
|
|
|
CWD=$(pwd)
|
|
PRGNAM=$(basename "$CWD")
|
|
BUILD=${BUILD:-20}
|
|
BRANCH=${BRANCH:-stable} # stable ; mainline
|
|
ARCH=$(uname -m)
|
|
|
|
TAG=gwh
|
|
TMP=/tmp/$TAG
|
|
PKG=$TMP/pkg-$PRGNAM
|
|
OUTPUT=/tmp
|
|
|
|
NUMJOBS=${NUMJOBS:-$(nproc)}
|
|
|
|
CONFIG=${CONFIG:-""}
|
|
|
|
REPOSITORY=${REPOSITORY:-/home/installs/SlackBuilds/_repositories/$PRGNAM}
|
|
|
|
VERSION=${VERSION:-$(curl https://www.kernel.org/feeds/kdist.xml | grep -o "[0-9.rc-]*: $BRANCH" | head -n1 | cut -d: -f1)}
|
|
|
|
mkdir -p "$REPOSITORY"
|
|
|
|
rm -fr "$PKG"
|
|
|
|
mkdir -p "$PKG/usr/src/"
|
|
if [ "$BRANCH" == "stable" ]; then
|
|
SRC_URL="https://cdn.kernel.org/pub/linux/kernel/v$(echo "$VERSION" | cut -d. -f1).x"
|
|
else
|
|
SRC_URL="https://git.kernel.org/torvalds/t"
|
|
fi
|
|
|
|
[ ! -e "$REPOSITORY"/linux-"$VERSION".tar.gz ] && wget -c "$SRC_URL/linux-$VERSION.tar.gz" -O "$REPOSITORY/linux-$VERSION.tar.gz"
|
|
tar xf "$REPOSITORY/linux-$VERSION.tar.gz" -C "$PKG/usr/src/"
|
|
|
|
cd "$PKG/usr/src/" || exit 1
|
|
mv "linux-$VERSION" "linux-gwh"
|
|
cd "linux-gwh" || exit 1
|
|
|
|
if [ -n "$CONFIG" ] && [ -e "$CONFIG" ]; then
|
|
cat "$CONFIG" > .config
|
|
fi
|
|
if [ ! -f .config ]; then
|
|
zcat /proc/config.gz > .config
|
|
fi
|
|
|
|
make oldconfig "$@"
|
|
|
|
make -j"$NUMJOBS"
|
|
make modules -j"$NUMJOBS"
|
|
make modules_install INSTALL_MOD_PATH="$PKG"
|
|
|
|
if [ -z "${HEADERS_ARCH}" ]; then
|
|
case "$(uname -m)" in
|
|
i?86) HEADERS_ARCH=x86 ;;
|
|
x86_64) HEADERS_ARCH=x86 ;;
|
|
aarch64) HEADERS_ARCH=arm64 ;;
|
|
# Use uname -m for all other archs:
|
|
*) HEADERS_ARCH=$(uname -m) ;;
|
|
esac
|
|
fi
|
|
|
|
# Generate the kernel headers and clean them up:
|
|
( echo "Generating headers from the Linux kernel source tree in ${KERNEL_SOURCE}:"
|
|
make headers_install ARCH="${HEADERS_ARCH}" INSTALL_HDR_PATH="$PKG/usr"
|
|
cd "$PKG/usr/include" || exit 1
|
|
# You won't want these files. The ones in libdrm work better.
|
|
rm -rf drm
|
|
# This next part seems pretty much cosmetic, but since we've been doing this
|
|
# for a long time (and others also do), we'll stick with it:
|
|
mv asm "asm-${HEADERS_ARCH}"
|
|
ln -sf "asm-${HEADERS_ARCH}" asm
|
|
# Remove unneeded dotfiles:
|
|
find . -name ".??*" -exec rm -f {} \+
|
|
)
|
|
|
|
VERSION=$(basename "$(find "$PKG/lib/modules/" -type d -maxdepth 1 -mindepth 1 | head -n1)")
|
|
|
|
cd ..
|
|
mv "$PKG/usr/src/linux-gwh" "$PKG/usr/src/linux-${VERSION}"
|
|
cd "$PKG/usr/src/linux-${VERSION}" || exit 1
|
|
|
|
# Fix build and source symlinks if they are pointing into $TMP:
|
|
( cd "$PKG"/lib/modules/"${VERSION}"
|
|
target=$(readlink build)
|
|
if echo "$target" | grep -q "^$PKG/" ; then
|
|
rm -f build
|
|
ln -sf "/usr/src/linux-${VERSION}" build
|
|
fi
|
|
)
|
|
|
|
mkdir -p "$PKG/boot/"
|
|
cp System.map "$PKG/boot/System.map-$VERSION"
|
|
cp .config "$PKG/boot/config-$VERSION"
|
|
cp "arch/${ARCH}/boot/bzImage" "$PKG/boot/vmlinuz-$VERSION"
|
|
|
|
make clean
|
|
|
|
mkdir -p "$PKG/install"
|
|
cat <<EOF > "$PKG/install/doinst.sh"
|
|
echo -n "updating grub... "
|
|
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub
|
|
echo OK
|
|
|
|
echo -n "building initrd… "
|
|
cd /
|
|
UCODE=""
|
|
[ -e /boot/intel-ucode.cpio ] && UCODE="-P /boot/intel-ucode.cpio"
|
|
eval "\$(/usr/share/mkinitrd/mkinitrd_command_generator.sh -k $VERSION -r | sed "s|/boot/initrd.gz|/boot/initrd-${VERSION}.gz|") \${UCODE}"
|
|
echo "OK"
|
|
|
|
grub-mkconfig -o /boot/grub/grub.cfg
|
|
EOF
|
|
|
|
cat <<EOF > "$PKG/install/slack-desc"
|
|
$PRGNAM: $PRGNAM (kernel)
|
|
$PRGNAM:
|
|
$PRGNAM: Linux is a clone of the operating system Unix, written from scratch by
|
|
$PRGNAM: Linus Torvalds with assistance from a loosely-knit team of hackers
|
|
$PRGNAM: across the Net. It aims towards POSIX and Single UNIX Specification
|
|
$PRGNAM: compliance.
|
|
$PRGNAM:
|
|
$PRGNAM: It has all the features you would expect in a modern fully-fledged Unix
|
|
$PRGNAM:
|
|
$PRGNAM: http://www.kernel.org
|
|
$PRGNAM:
|
|
EOF
|
|
|
|
cd "$PKG" || exit 1
|
|
rm -f "$PKG/{,usr/}lib$(uname -m | grep -o 64)/*.la"
|
|
/sbin/makepkg --linkadd y --prepend --chown n "$OUTPUT/$PRGNAM-$(echo "$VERSION" | tr - _)-$ARCH-$BUILD$TAG.txz"
|