79 lines
1.5 KiB
Bash
79 lines
1.5 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Copyright(c) 2012-2019 Intel Corporation
|
|
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
|
#
|
|
|
|
SCRIPTPATH=`dirname $0`
|
|
SCRIPTPATH=`realpath $SCRIPTPATH`
|
|
KERNEL_DIR="${KERNEL_DIR:-/lib/modules/$(uname -r)/build/}"
|
|
KERNEL_VER="$(cd $KERNEL_DIR; make kernelversion)"
|
|
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 2 ]
|
|
then
|
|
INCLUDE="#include <$3>"
|
|
else
|
|
INCLUDE=""
|
|
fi
|
|
|
|
config_file=$1
|
|
test_module_dir=$SCRIPTPATH/configure.d/${config_file}_dir
|
|
test_module_file=$test_module_dir/test_mod.c
|
|
test_module_obj=$test_module_dir/test_mod.o
|
|
|
|
mkdir -p $test_module_dir
|
|
cp -f $SCRIPTPATH/configure.d/Makefile $test_module_dir
|
|
|
|
############# TEST MODULE #############
|
|
cat > $test_module_file <<- EOF
|
|
#include <linux/module.h>
|
|
#include <linux/kernel.h>
|
|
$INCLUDE
|
|
|
|
int init_module(void) {
|
|
$2;
|
|
return 0;
|
|
}
|
|
void cleanup_module(void) {};
|
|
EOF
|
|
#######################################
|
|
|
|
make -C $test_module_dir KERNEL_DIR=${KERNEL_DIR} &> /dev/null
|
|
|
|
local ret=$?
|
|
|
|
rm -Rf $test_module_dir
|
|
|
|
return $ret
|
|
}
|
|
|
|
kernel_not_supp_fail() {
|
|
echo "Current kernel is not supported!"
|
|
rm $DEFINE_FILE
|
|
exit 1
|
|
}
|
|
|
|
# $1 - name of function to be called
|
|
# $2 - path to file with valid configs
|
|
# $3 - name of processed template file
|
|
conf_run() {
|
|
case "$1" in
|
|
"check") check $2 $3;;
|
|
"apply") apply $2 ;;
|
|
esac
|
|
}
|
|
|
|
IFS='?'
|