This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
compile_setup.sh
executable file
·169 lines (146 loc) · 4.44 KB
/
compile_setup.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/bash
############################### VERSION SELECTION ###############################
# User did not enter a major version selection, prompt for one
if [ "$1" = "" ]; then
echo "Which kernel version do you want to build?"
select major_version in "4.19" "5.3" "5.4" "5.5" "5.6" "5.7" "5.8"; do
break;
done
else
major_version=$1
fi
# Convert major version (e.g. 4.14) to full version (e.g. 4.14.40)
case $major_version in
"4.19")
version="4.19.91"
release_number=1
;;
"5.3")
version="5.3.18"
release_number=1
;;
"5.4")
version="5.4.63"
release_number=1
;;
"5.5")
version="5.5.19"
release_number=1
;;
"5.6")
version="5.6.19"
release_number=1
;;
"5.7")
version="5.7.19"
release_number=1
;;
"5.8")
version="5.8.14"
release_number=1
;;
*)
echo "Invalid selection!"
exit 1
;;
esac
############################### VARIABLES ###############################
cache_folder=.cache
build_folder=build-${version}-${release_number}
kernel_repository=git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
kernel_src_folder=linux-stable
patches_repository=git://github.com/qzed/linux-surface.git
patches_src_folder=linux-surface
kernel_suffix="-surface"
if [ "$major_version" = "4.19" ]; then
kernel_suffix="-surface-lts"
fi
############################### CACHE UPDATES ###############################
# Cache is used for holding frequently used repositories
echo "Updating cache ..."
mkdir -p $cache_folder
cd $cache_folder
# Update kernel source if repository is there, otherwise clone
if [ -d $kernel_src_folder ]; then
cd $kernel_src_folder && git pull && cd ..
else
git clone $kernel_repository $kernel_src_folder
fi
# Do the same with the patches repository
if [ -d $patches_src_folder ]; then
cd $patches_src_folder && git pull && cd ..
else
git clone $patches_repository $patches_src_folder
fi
# Exit the cache folder
cd ..
############################### BUILD UPDATES ###############################
# Ignore empty file pattern matches
shopt -s nullglob
# Copy templates
echo "Installing fresh set of template files ..."
rm -rf $build_folder
mkdir $build_folder
cp base/templates/* $build_folder
# Enter the newly created build directory
cd $build_folder
# Add kernel repository
echo "Creating symlink to kernel source code ..."
ln -s ../$cache_folder/$kernel_src_folder $kernel_src_folder
# Add Surface device patches
echo "Creating symlinks to Surface device patches ..."
for src in ../$cache_folder/$patches_src_folder/patches/$major_version/*.patch; do
filename=$(basename $src)
patch_entry=" ${filename}"
skip_entry=" 'SKIP'"
ln -s "$src" "$filename"
if [[ -z "$patch_names" ]]; then
patch_names="$patch_entry"
patch_skips="$skip_entry"
else
patch_names="${patch_names}\n${patch_entry}"
patch_skips="${patch_skips}\n${skip_entry}"
fi
done
# Add upstream patches
echo "Creating symlinks to upstream patches ..."
for src in ../base/patches/$major_version/*.patch; do
filename=$(basename $src)
patch_entry=" ${filename}"
skip_entry=" 'SKIP'"
ln -s "$src" "$filename"
if [[ -z "$patch_names" ]]; then
patch_names="$patch_entry"
patch_skips="$skip_entry"
else
patch_names="${patch_names}\n${patch_entry}"
patch_skips="${patch_skips}\n${skip_entry}"
fi
done
# Fill in blank variables in PKGBUILD
echo "Adjusting PKGBUILD version ..."
pkgbuild=`cat PKGBUILD`
pkgbuild="${pkgbuild/\{0\}/$kernel_suffix}"
pkgbuild="${pkgbuild/\{1\}/$major_version}"
pkgbuild="${pkgbuild/\{2\}/$version}"
pkgbuild="${pkgbuild/\{3\}/$release_number}"
pkgbuild="${pkgbuild/\{4\}/$patch_names}"
pkgbuild="${pkgbuild/\{5\}/$patch_skips}"
echo -e "$pkgbuild" > PKGBUILD
# Add version-specific configuration file
echo "Copying v$major_version .config file ..."
versioned_config="config.$major_version"
cp ../base/configs/$versioned_config .
mv $versioned_config config
# Exit the build directory
cd ..
############################### NEXT INSTRUCTIONS ###############################
nproc=`grep -c ^processor /proc/cpuinfo`
echo ""
echo "Build files for patched Linux kernel v$version are in $build_folder."
echo "The following commands can be used to build the kernel packages."
echo ""
echo "cd $build_folder"
echo "MAKEFLAGS=\"-j$nproc\" makepkg -sc"
echo ""
echo "You can optionally provide the -i flag to makepkg to install the kernel after build."