-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·150 lines (138 loc) · 3.91 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·150 lines (138 loc) · 3.91 KB
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
#!/bin/bash
set -eux
help() {
cat >&2 <<EOF
USAGE ./build.sh [--help] [--config-only] [--versions VERSIONS] [--targets TARGETS] [--cache-dir DIR]
--config-only
Only update the defconfigs instead of building the kernel
--versions VERSIONS
Build only the specified kernel versions. By default, all version directories under ./linux are built.
--targets TARGETS
Build only for the specified targets. By default, all targets are built.
--cache-dir DIR
Use DIR as the build cache directory (default: cache)
--clear-cache
Delete all contents of the cache directory and exit.
EXAMPLES
./build.sh --config-only --versions "4.10 6.7" --targets "armel mipseb mipsel mips64eb"
./build.sh --versions 4.10
./build.sh --targets armel
./build.sh
./build.sh --extra-docker-opts "--cpus=2"
./build.sh --cache-dir build_cache
EOF
}
# Default options
CONFIG_ONLY=false
#VERSIONS="4.10 6.7"
VERSIONS="" # Empty => auto-detect all version directories under ./linux
TARGETS="armel arm64 mipseb mipsel mips64eb mips64el powerpc powerpcle powerpc64 powerpc64le loongarch64 riscv64 x86_64"
NO_STRIP=false
MENU_CONFIG=false
INTERACTIVE=
DIFFDEFCONFIG=false
KERNEL_DEVEL=true
IMAGE="rehosting/linux_builder"
EXTRA_DOCKER_OPTS=""
CACHE_DIR="cache"
CLEAR_CACHE=false
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
help
exit
;;
--clear-cache)
CLEAR_CACHE=true
shift
;;
--config-only)
CONFIG_ONLY=true
shift
;;
--versions)
VERSIONS="$2"
shift # past flag
shift # past value
;;
--no-strip)
NO_STRIP=true
shift # past flag
;;
--menuconfig)
MENU_CONFIG=true
INTERACTIVE=-it
shift # past flag
;;
--targets)
TARGETS="$2"
shift # past flag
shift # past value
;;
--diffdefconfig)
DIFFDEFCONFIG=true
shift
;;
--kernel-devel)
KERNEL_DEVEL=true
shift
;;
--image)
IMAGE="$2"
shift # past flag
shift # past value
;;
--extra-docker-opts)
EXTRA_DOCKER_OPTS="$2"
shift # past flag
shift # past value
;;
--cache-dir)
CACHE_DIR="$2"
shift # past flag
shift # past value
;;
*)
help
exit 1
;;
esac
done
# Auto-detect versions if not provided
if [[ -z "${VERSIONS// }" ]]; then
if [[ ! -d linux ]]; then
echo "Error: linux directory not found; cannot auto-detect versions. Use --versions." >&2
exit 1
fi
mapfile -t _version_dirs < <(find linux -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | sort -V)
if [[ ${#_version_dirs[@]} -eq 0 ]]; then
echo "Error: No version subdirectories found under linux/. Use --versions." >&2
exit 1
fi
VERSIONS="${_version_dirs[*]}"
fi
# Resolve host cache directory path:
if [[ "$CACHE_DIR" == "cache" ]]; then
CACHE_HOST_DIR="$PWD/cache"
else
CACHE_HOST_DIR="$CACHE_DIR"
fi
if $CLEAR_CACHE; then
docker run --rm -v "$CACHE_HOST_DIR":/tmp/build -v "$PWD":/app pandare/kernel_builder /bin/bash -c "rm -rf /tmp/build/*"
exit
fi
# Check if the image exists locally, build if not
if ! docker image inspect "$IMAGE" >/dev/null 2>&1; then
echo "Docker image $IMAGE not found, building it..."
docker build -t "$IMAGE" .
fi
mkdir -p "$CACHE_HOST_DIR"
docker run $INTERACTIVE \
--rm -v "$CACHE_HOST_DIR":/tmp/build \
-v "$PWD":/app \
$EXTRA_DOCKER_OPTS \
"$IMAGE" \
bash /app/_in_container_build.sh \
"$CONFIG_ONLY" "$VERSIONS" "$TARGETS" \
"$NO_STRIP" "$MENU_CONFIG" "$DIFFDEFCONFIG" "$KERNEL_DEVEL"