-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdk.sh
More file actions
executable file
·170 lines (142 loc) · 2.91 KB
/
Copy pathsdk.sh
File metadata and controls
executable file
·170 lines (142 loc) · 2.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/sh
set -ex
ARCH="${ARCH:-i686-elf}"
# Usage: usage EXIT_CODE
# Example: usage 0
usage() {
if [ "$1" -eq 0 ]; then
FILE=/dev/stdout
else
FILE=/dev/stderr
fi
cat << EOF
Usage: $0 [options] [subcmd]
Options:
-c pass --no-cache to docker build
-t set the tag parameter for the docker image
-h Print this help and exit
-v Print verbosely
Subcommands:
docker: Build the docker image
setup: Setup/clean the Meson build system
build: Build the operating system
shell: Run the docker image interactively
sysroot: Generate a sysroot in the build directory
iso: Generate an ISO image from the generated sysroot
qemu: Run the generated ISO with qemu-system-i386
help: Print this help and exit
EOF
> $FILE
exit $1
}
check_docker() {
if [ -z "$(docker images -q "${TAG}" 2> /dev/null)" ]; then
echo "ERROR: docker image "${TAG}" not build!" 2>&1
echo "ERROR: needs '$0 docker' to be run from the build machine" 2>&1
usage 1
fi
}
# Usage: if in_docker ; then echo "IM IN"; fi
in_docker() {
test -n "${__OSDEV_ENV__}"
}
# Usage: sdk_exec COMMAND [ARGS...]
# Run COMMAND, ensuring it is run with
# in the Docker cross-compilation environment.
sdk_exec() {
if in_docker ; then
$@
else
check_docker
echo "loading sdk"
docker run \
-v .:/src \
--user="$(id -u):$(id -g)" \
-t "${TAG}" \
$@
fi
}
TAG=docker-osdev-${ARCH}
CACHE=
VERBOSE=0
while getopts ":hc:t:v" o; do
case "${o}" in
v)
VERBOSE=$((VERBOSE+1))
;;
c)
CACHE="--no-cache"
;;
t)
TAG="${OPTARG}"
;;
h)
usage 0
;;
esac
done
shift $((OPTIND - 1))
if [ "$#" -eq 0 ]; then
echo "Missing subcommand" 2>&1
usage 1
fi
subcmd="$1"
shift 1
if [ "$VERBOSE" -gt 0 ]; then
set -x
fi
case "${subcmd}" in
docker)
docker build -t "$TAG" . ${CACHE} --progress=plain $@
;;
setup)
sdk_exec meson setup --cross-file="${ARCH}" build --wipe $@
;;
build)
sdk_exec meson compile -C build $@ \
$([ "${VERBOSE}" -gt 0 ] && echo "-v")
;;
shell)
if in_docker ; then
echo "Cannot exec shell from within Docker environment" 2>&1
usage 1
fi
sdk_exec sh $@
;;
sysroot)
sdk_exec meson install -C build --destdir sysroot $@
;;
iso)
if in_docker ; then
echo "TODO: ISO build is unsupported in the docker environment" 2>&1
usage 1
fi
if [ ! -d "build/sysroot" ]; then
echo "sysroot has not been setup" 2>&1
usage 1
fi
scripts/iso.sh build/sysroot build/denton.iso
;;
qemu)
if [ ! -f "build/denton.iso" ]; then
echo "ISO has not been generated" 2>&1
usage 1
fi
qemu-system-i386 \
-no-reboot \
-no-shutdown \
-cdrom build/denton.iso \
-s \
-d int \
-nographic \
-S \
$@
;;
help)
usage 0
;;
*)
echo "Unknown subcommand: $1" 2>&1
usage 1
;;
esac