-
Notifications
You must be signed in to change notification settings - Fork 12
/
kerndev-build
executable file
·58 lines (44 loc) · 1.24 KB
/
kerndev-build
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
#!/bin/bash
set -e; set -o pipefail; source kerndev-shared.sh
# NOTE: $cross_compile_prefix will vary depending on your cross-compiler setup.
# If an argument is provided, it specifies a cross-compile target architecture.
target_arch=${1:-"x86_64"}
# Sanity checks.
check_linux_dev_path
[[ $EUID = 0 ]] && fatal "Don't run as root, causes file ownership pain"
case $target_arch in
arm)
# Use aarch64 + backwards compatibility.
;&
aarch64)
linux_arch="arm64"
cross_compile_prefix="aarch64-linux-gnu-"
;;
"x86_64")
;;
*)
fatal "unknown architecture: $target_arch"
;;
esac
if [[ "$target_arch" != "x86_64" ]]; then
# Make sure we have cross-compilers. `gcc` check should suffice.
check_exists ${cross_compile_prefix}gcc
# For now, always force a rebuild.
REBUILD=y
make_opts="ARCH=${linux_arch} CROSS_COMPILE=$cross_compile_prefix"
fi
# Ref: http://stackoverflow.com/a/6481016
cores=$(grep -c ^processor /proc/cpuinfo)
push_linux
echo Configuring kernel...
source kerndev-config
# Set any new options implied by kerndev-config to default.
mak olddefconfig
echo Compiling kernel...
# 1 extra thread to account for I/O waiting.
mak -j$((cores + 1))
if [[ -z "$DONT_INSTALL" ]]; then
NO_DONE=y sudo -E kerndev-install $target_arch
fi
pop
say_done