open-cas-linux/configure.d/conf_framework
Michal Rakowski 0f2ea7ade7 configure: more deseralization & cleanup
Signed-off-by: Michal Rakowski <michal.rakowski@intel.com>
2019-09-09 16:10:31 +02:00

87 lines
1.6 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
i=3
while [ "$i" -le "$#" ]; do
INCLUDE+=$(echo -e "\n#include <${!i}>\\n")
i=$((i + 1))
done
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() {
local OLD_IFS=$IFS
IFS='?'
case "$1" in
"check") check $2 $3;;
"apply") apply $2 ;;
esac
IFS=$OLD_IFS
}