#!/bin/sh
#----------------------------------------------------------------------------
# /tmp/preinstall.sh - preinstall for eiskernel-dev
#
# Copyright (c) 2001-2025 the eisfair team, team(at)eisfar(dot)org
#
# Creation:     2021-01-13 dv
# Last Update:  2025-12-19 02:29:26 dv
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#----------------------------------------------------------------------------
. /var/install/include/eislib

# check for installed gcc
if [ ! -f /usr/bin/gcc ]
then
    echo
    echo
    mecho --error "gcc-base is not properly configured."
    mecho --error "Please configure gcc-base first."
    echo
    echo
    exit 1
else
    gccmajor='14'

    # check what is the best version
    value=$(/usr/sbin/update-alternatives --query gcc | /usr/bin/awk '/Value/ {print $2}')

    # if the best version not this version, use this version manual
    if ! echo "${value}" | /usr/bin/grep -q "/gcc-${gccmajor}"
    then
        echo
        echo
        mecho --warn "gcc-${gccmajor} is not active."
        mecho --warn "Since the kernel has been compiled with gcc-${gccmajor}, all additional"
        mecho --warn "kernel modules must be compiled with the very same compiler version"
        mecho --warn "as well. So make sure to activate gcc-${gccmajor} before compiling any"
        mecho --warn "third party kernel modules."
        echo
        echo
    fi
fi

exit 0
