#!/bin/bash

###################################################################################
# Script: slackwareaarch64-current/source/k/scripts/alternatek-src
# Purpose: Provide an example of building Slackware ARM Linux Kernel packages
#          using the Raspberry Pi Linux Kernel fork as an alternate Kernel source.
# Author : Stuart Winter <mozes@slackware.com>
# Date...: 26-Jun-2022
###################################################################################

echo "** This is an example. You need to edit this."
exit

mkdir -p /tmp/altkernel
cd /tmp/altkernel
# git clone --depth=100 --branch rpi-5.18.y https://github.com/raspberrypi/linux.git linux-rpi-5.18.y
wget https://github.com/raspberrypi/linux/archive/refs/heads/rpi-5.18.y.zip
unzip rpi-*zip || exit 1
mv -fv rpi*.zip /tmp
# Obtain the Kernel version of this src:
pushd linux-*
kver=$( echo "$(sed -ne's/^VERSION *= *//p' Makefile).$(sed -ne's/^PATCHLEVEL *= *//p' Makefile).$(sed -ne's/^SUBLEVEL *= *//p' Makefile)" )

# Note: don't use the default config.  Use the configs/experimental/ one prepared for you
# and work with that.

# This creates a default config for the RPi4, but you
# may want to use your own config here.
# See notes below.
#make ARCH=arm64 bcm2711_defconfig
# Switch this to the standard Slackware ARM uses:
#sed -i 's?^CONFIG_LOCALVERSION=.*?CONFIG_LOCALVERSION="-armv8"?g' .config
popd
# Use the Slackware standard naming convention:
mv -fv linux-* linux-$kver

echo "Linux Kernel version: $kver"

# Next:
#
# This assumes you've already configured 'slackkit' (the Slackware ARM development kit/build
# system library).

# 1. Within your Slackware ARM build system tree:
#    e.g. slackwareaarch64-current/source/k
#    Ensure that the 'arm/build' script has the matching Kernel version
#    number set.
#
# 2. Apply any source patches to the source in /tmp/altkernel/linux-$kver
#
# 3. Create a Kernel configuration file:
#    To begin it's recommended to copy the Slackware ARM Kernel configuration and
#    make required changes.  This is because the Slackware ARM OS expects certain
#    modules to be available.
#    If you use a custom or default configuration, your mileage may vary.
#
#    e.g.
#    cp slackwareaarch64-current/source/k/configs/config-armv7 /tmp/altkernel/linux-$kver/.config
#    cd /tmp/altkernel/linux-$kver/
#    make ARCH=arm64 oldconfig
#    ## Or use the experimental config: slackwareaarch64-current/source/k/configs/experimental
#
# 4. Build the Slackware ARM Kernel packages:
#    cd slackwareaarch64-current/source/k
#    ./arm/build --srcdir /tmp/altkernel --noconfig --nopatches
#
#    Or if you're using distcc and have the 'dbuild' tool:
#    dbuild --srcdir /tmp/altkernel --noconfig --nopatches
