
Functions and macros dependent on different kernel versions are now generated before compilation basing on current kernel capabilities instead of hardcoding them for specific kernels. Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
63 lines
1.0 KiB
Bash
63 lines
1.0 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Copyright(c) 2012-2019 Intel Corporation
|
|
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
|
#
|
|
|
|
SCRIPTPATH=`dirname $0`
|
|
SCRIPTPATH=`realpath $SCRIPTPATH`
|
|
MODULE_FILE=$SCRIPTPATH/test_mod.c
|
|
OBJ_MOD=$SCRIPTPATH/test_mod.o
|
|
KERN_VER=`uname -r`
|
|
NPROC=`nproc`
|
|
DEFINE_FILE=$SCRIPTPATH/../modules/generated_defines.h
|
|
|
|
|
|
add_define() {
|
|
printf "#define %s\n" $1 >> $DEFINE_FILE
|
|
}
|
|
|
|
add_function() {
|
|
printf "%s\n" $1 >> $DEFINE_FILE
|
|
}
|
|
|
|
compile_module(){
|
|
if [ $# -gt 1 ]
|
|
then
|
|
INCLUDE="#include <$2>"
|
|
else
|
|
INCLUDE=""
|
|
fi
|
|
|
|
############# TEST MODULE #############
|
|
cat > $MODULE_FILE <<- EOF
|
|
#include <linux/module.h>
|
|
#include <linux/kernel.h>
|
|
$INCLUDE
|
|
|
|
int init_module(void) {
|
|
$1;
|
|
return 0;
|
|
}
|
|
void cleanup_module(void) {};
|
|
EOF
|
|
#######################################
|
|
|
|
make -C $SCRIPTPATH &> /dev/null
|
|
|
|
local ret=$?
|
|
if [ $ret -eq 0 ]; then
|
|
make -C $SCRIPTPATH clean &> /dev/null
|
|
fi
|
|
|
|
return $ret
|
|
}
|
|
|
|
kernel_not_supp_fail() {
|
|
echo "Current kernel is not supported!"
|
|
rm $DEFINE_FILE
|
|
exit 1
|
|
}
|
|
|
|
IFS='?'
|