bin bash DIR dirname readlink -f SUCCESS_COLOR 033 32m ERROR_COLOR 033

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
#!/bin/bash
DIR="$(dirname "$(readlink -f "$0")")"
SUCCESS_COLOR='\033[1;32m'
ERROR_COLOR='\033[1;31m'
MODULE_COLOR='\033[1;36m'
YELLOW_COLOR='\033[1;33m'
BLUE_COLOR='\033[1;34m'
WHITE_COLOR='\033[1;37m'
NC='\033[0m' # No Color
source $DIR/config.sh
num_of_succeed_built_modules=0
total_num_of_modules=0
DIR="$(dirname "$(readlink -f "$0")")"
cd "${DIR}"
if [ ! -n ${GCC} ]; then
echo -e "gcc was not found. You can set full path to it in config.sh";
exit -1
fi
if [ ! -n ${GCC4} ]; then
echo -e "gcc-4 was not found. You can set full path to it in config.sh";
exit -1
fi
declare -A errors
function build_kernel() {
mkdir -p "${BUILD}"/"${1#$DIR}"
exec 3>&1
filename=$(basename "${1#$DIR}")
local_module_name=$(basename $MODULE_NAME ".ko")
printf -v error_it "$local_module_name-$filename.ko\n\"$1\"\n\"$2\""
errors[$error_it]=$(script -q /dev/null --command "make CC=$2 BUILD=${BUILD}/${1#$DIR} KDIR=$1 -C $LKM_SRC 2>&1 1>&3" < /dev/null)
if [ $? == 0 ]; then
cp "${BUILD}"/"${1#$DIR}"/$MODULE_NAME "${OUTPUT}"/$local_module_name-$filename.ko
if [ $? == 0 ]; then
echo -e "${SUCCESS_COLOR}Build done for ${BLUE_COLOR}KDIR=${WHITE_COLOR}\"$1\"${SUCCESS_COLOR}: \nFile ${MODULE_COLOR}${OUTPUT}/$local_module_name-$filename.ko${SUCCESS_COLOR} was created${NC}";
num_of_succeed_built_modules=$((num_of_succeed_built_modules + 1))
else
echo -e "${ERROR_COLOR}Can't create ${MODULE_COLOR}$local_module_name-$filename.ko${ERROR_COLOR} in output directory ${YELLOW_COLOR}${OUTPUT}${NC}";
fi
else
echo -e "${ERROR_COLOR}Build failure for headers ${BLUE_COLOR}KDIR=${WHITE_COLOR}\"$1\"{NC}";
fi
exec 3>&-
}
mkdir -p "${TMP}"
mkdir -p "${BUILD}"
mkdir -p "${OUTPUT}"
rm -rf "${TMP}"/*
rm -rf "${OUTPUT}"/*
for c in "${!headerMap[@]}"; do
echo -e "${SUCCESS_COLOR}Build start for: ${BLUE_COLOR}KDIR=${WHITE_COLOR}\"$c\"${SUCCESS_COLOR} with ${BLUE_COLOR}CC=${WHITE_COLOR}\"${headerMap[$c]}\"${NC}"
build_kernel "$c" "${headerMap[$c]}"
total_num_of_modules=$((total_num_of_modules + 1))
done
function untar() {
tar -C "$TMP/" -zxf "$1" "${2}"
return $?
}
for c in "${!headerInTarGZMap[@]}"; do
pair=(${c//:/ })
path_to_archive=${pair[0]}
headers=${pair[1]}
arr=(${headerInTarGZMap[$c]//:/ })
COMPILER=${arr[$((${#arr[@]} - 1))]}
untar ${path_to_archive} ${headers}
if [ $? == 0 ]; then
for dir in "${!arr[@]}"; do
if [ $dir == $((${#arr[@]} - 1)) ]; then
continue
fi
echo ${arr[$dir]}
untar ${path_to_archive} ${arr[$dir]}
done
build_kernel "${TMP}/${headers}" "${COMPILER}"
else
echo -e "${ERROR_COLOR}Can't untar \"${headers}\" from \"${path_to_archive}\"${NC}";
fi
total_num_of_modules=$((total_num_of_modules + 1))
done
echo -e "\n${SUCCESS_COLOR}Possible errors:${NC}"
for c in "${!errors[@]}"; do
IFS=$'\n' variables=(${c//\\n/ })
IFS=$'\n' errors_by_lines=(${errors[$c]//\\n/ })
PREFIX="${ERROR_COLOR}${variables[0]} ( ${BLUE_COLOR}KDIR=${WHITE_COLOR}${relative} : ${BLUE_COLOR}CC=${WHITE_COLOR}${variables[2]}${ERROR_COLOR} ): ${NC}"
echo -e "\n${PREFIX}"
for err in "${!errors_by_lines[@]}"; do
echo -e "${errors_by_lines[$err]}"
done
done
echo -e "\n${SUCCESS_COLOR}Totally number of built modules $num_of_succeed_built_modules out of ${total_num_of_modules}${NC}"