#!/usr/bin/env beesh


# eg ixgbe_linux-4.4.2-80-4.3.13-0.bee
# ARCH=x86_64
# BEE_BUILDARCHIVEDIR=/src/mariux/beeroot/build-archives
# BEE_TMP_TMPDIR=/scratch/local
# PKGEXTRANAME=linux-4.4.2-80
# PKGEXTRANAME_DASH=-linux-4.4.2-80
# PKGEXTRANAME_UNDERSCORE=_linux-4.4.2-80
# PKGEXTRAVERSION=
# PKGEXTRAVERSION_DASH=
# PKGEXTRAVERSION_UNDERSCORE=
# PKGFULLNAME=ixgbe_linux-4.4.2-80
# PKGFULLPKG=ixgbe_linux-4.4.2-80-4.3.13-0
# PKGFULLVERSION=4.3.13
# PKGNAME=ixgbe
# PKGREVISION=0
# PKGSUFFIX=.bee
# PKGVERSION=([0]="4.3.13" [1]="4" [2]="4.3" [3]="4.3.13")


LINUXPKG=${PKGEXTRANAME}.${ARCH}		                              # linux-4.4.2-80.x86_64
LINUXKLOCALVER=$(beeversion --format "%v.mx64.%r" "${LINUXPKG}")      # 4.4.2.mx64.80 







## this file was created by bee init and should be executed to build a
## bee-package. (Additional hints are located at the end of this file.)

###############################################################################
## The source URL(s) define the location of the sources that will be
## downloaded. Version variables may be used to simplify reuse of this bee-file.

SRCURL[0]="https://downloadmirror.intel.com/14687/eng/ixgbe-${PKGVERSION}.tar.gz"

###############################################################################
## Add URLs/pathes to patch files to the PATCHURL array.
## The sources will be patched in the order of the array.

# PATCHURL+=()

###############################################################################
## Add filename patterns to the EXCLUDE array of files that should not
## be added to you package but may be present in the image directory.

# EXCLUDE+=()

###############################################################################
## Uncomment the next statement, if the software may not be able to be build
## outside the source directory and need to be build inside the source
## directory.

build_in_sourcedir

###############################################################################
## bee cannot detect buildtypes specified in subdirectories.
## Sometimes packages "hide" the real sources in a subdirectory named
## 'src' or 'cmake' or ..
## use 'sourcesubdir_append' to specify this directory if known.

# sourcesubdir_append src


###############################################################################
## Change the default (auto-detected) steps to
## extract, patch, configure/setup, build and install the software.
## Make sure the mee_install function does install everything to the
## image directory "${D}"

mee_extract() {
    bee_extract "${@}"

    LINUXBUILDARCHIVE="${BEE_BUILDARCHIVEDIR}/${LINUXPKG}.beebuild.tar.bz2"   # /src/mariux/beeroot/build-archives/linux-4.4.2-80.x86_64.beebuild.tar.bz2
	LINUXSRCDIR="${BEE_TMP_TMPDIR}/${LINUXPKG}/source"	                      # /scratch/local/linux-4.4.2-80.x86_64/source

    print_info "using kernel sources from ${LINUXSRCDIR} .."

    if [ ! -d "$LINUXSRCDIR" ] ; then
        print_info "extracting linux build ${LINUXPKG} .."
        start_cmd gtar -xf "${LINUXBUILDARCHIVE}" -C ${BEE_TMP_TMPDIR}
    fi
}

#mee_patch() {
#    bee_patch "${@}"
#}

mee_configure() {
    # bee_configure 
    :
}

mee_build() {
    #bee_build
    cd src
    make -j 20 KSP="$LINUXSRCDIR"
}

mee_install() {
    # bee_install
    #make install KSP="$LINUXSRCDIR" INSTALL_MOD_PATH="${D}/lib/modules/${LINUXKLOCALVER}" cmd_depmod=true
    make install KSP="$LINUXSRCDIR" INSTALL_MOD_PATH="${D}" cmd_depmod=true
}

## by default this may be 'make install DESTDIR="${D}"'

###############################################################################
##
## Additional hints:
##
## The name of this bee-file should follow the following naming convention:
##     pkgname-pkgversion-pkgrevision.bee
##
## You may remove all comments as long as SRCURL[0] is set.
##
## Everything in this file will be executed in a bash environment.
##
## Build the package by executing
##     './pkg-version-N.bee' or
##     'beesh ./pkg-version-N.bee'
##
## see http://beezinga.org/
##