-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-kernel.sh
executable file
·96 lines (81 loc) · 3.01 KB
/
build-kernel.sh
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
#!/bin/bash
# Determine Threads based on logical CPUs
#########################################
#THREADS=1
LOGICALCPUS=$(cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l)
THREADS=$(($LOGICALCPUS+1))
echo "Found $LOGICALCPUS logical CPUs. "
# Determine compiler settings
#############################
# Optimizations:
# -O1 performs only optimizations that don't effect the compile time much.
# -O2 performs optimizations without trading space for speed
# -O3 performs maximal speed optimization
# -Os tries to make the executable as small as possible
#if [ -n $3 ]; then
# # Set max. Threads
# echo "Threadcount $3 specified."
# THREADS=$3
#fi
echo "Compiling with $THREADS Threads."
case "$2" in
O2)
echo "$2: Compiler-optimization-flag is set to $2."
OPTIMIZATION="-O2"
;;
O3)
echo "$2: Compiler-optimization-flag is set to $2."
OPTIMIZATION="-O3"
;;
*)
echo "No Compiler-optimization-flag is set. Using default..."
OPTIMIZATION="-O2"
;;
esac
echo "$Yellow Compiling with optimization: $OPTIMIZATION..."
# Optimize for CPU (set CFLAGS):
case "$1" in
aw17r4)
echo "$1: Compiling for Dell Alienware 17R4"
#export CFLAGS="-march=native $OPTIMIZATION -pipe" #https://wiki.gentoo.org/wiki/Safe_CFLAGS#Intel #AW17R4 has a Skylake CPU
export CFLAGS="-march=skylake $OPTIMIZATION -pipe" #https://wiki.gentoo.org/wiki/Safe_CFLAGS#Intel #AW17R4 has a Skylake CPU
APPENDTEXT="-czm0d-skylake-$1"
;;
eeepc)
echo "$1: Compiling for Asus EEEPC"
export CFLAGS="-march=atom -mtune=atom $OPTIMIZATION -pipe" #https://wiki.gentoo.org/wiki/Safe_CFLAGS
APPENDTEXT="-czm0d-atom-$1"
;;
winpad12)
echo "$1: Compiling for Odys Winpad 12"
export CFLAGS="-march=atom -mtune=atom -fexcess-precision=fast $OPTIMIZATION -pipe" #https://wiki.gentoo.org/wiki/Safe_CFLAGS
APPENDTEXT="-czm0d-atom-$1"
;;
probook650g3)
echo "$1: Compiling for HP ProBook 650 G3"
export CFLAGS="-march=skylake $OPTIMIZATION -pipe" #https://wiki.gentoo.org/wiki/Safe_CFLAGS#Probook 650 G3 has a Kaby Lake CPU
APPENDTEXT="-czm0d-kabylake-$1"
;;
*)
echo "$1: Unknown Target. Aborting!"
echo "Usage: build-kernel.sh <target> [optimization]"
echo "Possible targets: \"aw17r4\", \"eeepc\", \"winpad12\", \"probook650g3\""
echo "Possible optimizations: \"-O2 \(optimize for space, default is -03 [speed]\)\""
exit -1
;;
esac
echo "CFLAGS are: $CFLAGS"
# Configuring Compiler
######################
export CXXFLAGS="$CFLAGS"
BUILD_START=$(date +"%s")
echo "$Yellow Start Kernel build..."
echo "$Yellow #####################"
echo ""
echo "$Yellow Build started at $(date)"
echo ""
#fakeroot make-kpkg -j $THREADS --verbose --initrd --arch-in-name --append-to-version=-czm0d kernel_image kernel_headers
make-kpkg -j $THREADS --verbose --initrd --arch-in-name --append-to-version=$APPENDTEXT kernel_image kernel_headers
BUILD_END=$(date +"%s")
DIFF=$(($BUILD_END - $BUILD_START))
echo -e "$Yellow Build ended after $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) seconds.$nocol"