#!/bin/bash
# Copyright (c) Mentor Graphics, a Siemens business, 2019
# SPDX-License-Identifier: MIT

# Load common stuff
. ${S}/debian/isar/common || exit ${?}

do_build() {

    # Print a few things that are of particular interest
    print_settings

    # Process existing kernel configuration to make sure it is complete
    # (use defaults for options that were not specified)
    ${MAKE} O=${KERNEL_BUILD_DIR} olddefconfig prepare || exit ${?}

    # Transfer effective kernel version into control file and scripts
    KR=$(${MAKE} O=${KERNEL_BUILD_DIR} -s --no-print-directory kernelrelease)
    sed -i "s/@KR@/${KR}/g" ${S}/debian/control ${S}/debian/linux-image-${KERNEL_NAME_PROVIDED}.*

    # Trace what we do here
    set -x

    # Build the Linux kernel
    ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} || exit ${?}

    # Stop tracing
    set +x
}

print_settings() {
    cat <<EOF
# Build settings:
# ---------------
# ARCH=${ARCH}
# CROSS_COMPILE=${CROSS_COMPILE}
EOF
}

main build ${*}
