#!/bin/env beesh

# note: CONFIG=/boot/config-WHATEVER BEE_MAKEFLAGS='-j 40' ./crashlinux-xxx.bee

KERNELVERSION=${PKGVERSION}
if [ -z "${PKGVERSION[3]}" ] ; then
    KERNELVERSION=${KERNELVERSION}.0
fi

# append extra version to get for example 4.8.0-rc4
KERNELVERSION=${KERNELVERSION}${PKGEXTRAVERSION_DASH}

echo $KERNELVERSION

SRCURL[0]="https://cdn.kernel.org/pub/linux/kernel/v${PKGVERSION[1]}.x/linux-${PKGVERSION}${PKGEXTRAVERSION_DASH}.tar.xz"

# EXCLUDE=""

#CONFIG=

KERNELLOCAL=".crash.${PKGREVISION}"
FULLKERNELVERSION="${KERNELVERSION}${KERNELLOCAL}"

B=${S}

mee_patch() {
    echo "PATCH $@"
    bee_patch $@
}

mee_configure() {
    echo "configure $@"

    if [ -z "$CONFIG" ]; then
        echo "please specifiy old config in environment"
        exit 1
    fi

    if [ ! -e ${CONFIG} ] ; then
        echo "can't find config '${CONFIG}'"
        exit 1
    fi

    cp -v ${CONFIG} .config

    LOCALVERSION="\"${KERNELLOCAL}\""
    sed -i -e "s@CONFIG_LOCALVERSION=.*@CONFIG_LOCALVERSION=${LOCALVERSION}@" .config

    echo "doing make -C ${S} olddefconfig in ${PWD} .."

    make olddefconfig

    echo "doing make -C ${S} menuconfig in ${PWD} .."

    make menuconfig
}

mee_build() {
    echo "build $@"
    make ${BEE_MAKEFLAGS}
}

mee_install() {
    echo "install $@"

    make install          INSTALL_PATH=${D}/boot

    ln -sv bzImage-${FULLKERNELVERSION} ${D}/boot/crashkernel.${PKGREVISION}
    ln -s ${D}/boot/crashkernel.${PKGREVISION} ${D}/boot/bzImage.crash
}