-
Notifications
You must be signed in to change notification settings - Fork 3
/
compile
executable file
·200 lines (182 loc) · 5.59 KB
/
compile
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#! /bin/bash
# syntax:
# ./compile [ PLATFORM [ debug ] [ DOCKERFILE_STAGE ] ]
# usage examples:
# build combined package for x86_64
# ./compile x86_64
# build BasiliskII package only, for x86_64
# ./compile x86_64 basilisk2
# locally hosted macemu source
# MACEMU_SOURCE=local ./compile x86_64
# enter debug shell for the SheepShaver build environment in i386
# ./compile i386 debug buildenv-sheepshaver
# quick debug shell for non-crashing build
# DOCKER_BUILDKIT=1 ./compile i386 debug buildenv-sheepshaver
{
set -eu
set -o pipefail
# must be root to control docker
if [ "$USER" != "root" ]
then
sudo -E "$0" $@
exit
fi
SELF=$(readlink -f "$0")
HERE=${SELF%/*}
cd "$HERE"
PLATFORM=${1:-}
LXDEPLOY_ARCH=""
PACKAGING="none"
SKIP_VHD="y"
SKIP_BINCUE="n"
MACEMU_SOURCE="${MACEMU_SOURCE:-git}"
MACEMU_GIT_ARGS="--depth 1 https://github.com/kanjitalk755/macemu"
case "${PLATFORM}" in
""|"x86_64")
echo "Building x86_64"
DOCKER_SUFFIX="x86_64"
DOCKER_PLATFORM="linux/x86-64"
DISTRO="ubuntu:bionic"
SKIP_VHD="n"
PACKAGING="linuxdeploy"
LXDEPLOY_ARCH="x86_64"
;;
"i386")
echo "Building ${PLATFORM}"
DOCKER_SUFFIX="i386"
DOCKER_PLATFORM="linux/386"
DISTRO="ubuntu:bionic"
SKIP_VHD="y"
PACKAGING="linuxdeploy"
LXDEPLOY_ARCH="i386"
;;
"pi1"|"pi0")
echo "Building Rasperry ${PLATFORM} (pi1, pi0) [EXPERIMENTAL]"
echo "WARNING: SheepShaver is known not to build on this platform"
echo "WARNING: No packager available for this platform"
DOCKER_SUFFIX="pi1"
DOCKER_PLATFORM="linux/arm/v5"
DISTRO="balenalib/raspberry-pi-ubuntu:bionic-build"
;;
"pi2")
echo "Building Raspberry ${PLATFORM} [EXPERIMENTAL]"
echo "WARNING: SheepShaver is known not to build on this platform"
echo "WARNING: No packager available for this platform"
DOCKER_SUFFIX="pi2"
DOCKER_PLATFORM="linux/arm/v7"
DISTRO="balenalib/raspberry-pi2-ubuntu:bionic-build"
#DISTRO="balenalib/raspberry-pi2-ubuntu:focal-build"
;;
"pi3"|"pi4"|"pi0v2")
echo "Building Rasperry ${PLATFORM} (pi3, pi4, pi0v2) [EXPERIMENTAL]"
echo "WARNING: SheepShaver is known not to build on this platform"
echo "WARNING: No packager available for this platform"
DOCKER_SUFFIX="pi3"
DOCKER_PLATFORM="linux/arm/v7"
DISTRO="balenalib/raspberrypi3-ubuntu:bionic-build"
;;
"pi4-64")
echo "Building Rasperry ${PLATFORM} (raspberrypi4 64-bit) [EXPERIMENTAL]"
echo "WARNING: SheepShaver is known not to build on this platform"
echo "WARNING: No packager available for this platform"
DOCKER_SUFFIX="pi4-64"
DOCKER_PLATFORM="linux/arm64"
DISTRO="balenalib/raspberrypi4-64-ubuntu:bionic-build"
#DISTRO="debian:bullseye"
#MACEMU_GIT_ARGS="--depth 1 https://github.com/cebix/macemu"
;;
*)
echo "Invalid build platform specified: ${1}"
exit 1
;;
esac
echo "$(git config --get remote.origin.url) @ $(git log -1 --format="%ad") ($(git rev-parse --short HEAD))" > docker/build/version-macemu-appimage-builder
# prepare empty output directory
mkdir -p ./output
rm -rf ./output/*
touch ./compile.log
# convenience: chown logs to the sudo caller
if [ "${SUDO_USER:-}" != "" ]
then
chown "$SUDO_USER" -R ./compile.log
fi
if [ "${2:-}" = "debug" ]
then
TARGET="${3}"
echo "Debugging stage $TARGET"
sleep 2
build_status=0
# DOCKER_BUILDKIT=1 not applied so we can enter last intermediate image
# NOTE: you can still prepend DOCKER_BUILDKIT=1 if you know the build succeeds to use your cache
docker build \
--platform $DOCKER_PLATFORM \
--build-arg DISTRO=$DISTRO \
--build-arg SKIP_VHD=$SKIP_VHD \
--build-arg SKIP_BINCUE=$SKIP_BINCUE \
--build-arg PACKAGING=$PACKAGING \
--build-arg LXDEPLOY_ARCH=$LXDEPLOY_ARCH \
--build-arg "MACEMU_SOURCE=$MACEMU_SOURCE" \
--build-arg "MACEMU_GIT_ARGS=$MACEMU_GIT_ARGS" \
--tag macemu-build:$TARGET-$DOCKER_SUFFIX \
--target $TARGET \
docker \
2>&1 | tee compile.log \
|| build_status=$?
if [ "$build_status" = "0" ]
then
# image successfully created, start shell based on tag
docker run --rm -it \
--platform $DOCKER_PLATFORM \
-v "$(realpath ./):/compiledir" \
macemu-build:$TARGET-$DOCKER_SUFFIX \
/bin/bash \
;
else
# build failed, start shell based on last intermediate image
last_intermediate=$(tac compile.log | grep -E " ---> [0-9a-f]{12}" | head -n1 | sed "s/ ---> //")
if [ "$last_intermediate" != "" ]
then
docker run --rm -it \
--platform $DOCKER_PLATFORM \
-v "$(realpath ./):/compiledir" \
sha256:$last_intermediate \
/bin/bash \
;
fi
fi
exit
else
TARGET="${2:-combined}"
echo "Building stage $TARGET (packaging: $PACKAGING)"
sleep 2
# DOCKER_BUILDKIT=1 currently required for custom --output
DOCKER_BUILDKIT=1 docker build \
--platform $DOCKER_PLATFORM \
--build-arg DISTRO=$DISTRO \
--build-arg SKIP_VHD=$SKIP_VHD \
--build-arg SKIP_BINCUE=$SKIP_BINCUE \
--build-arg PACKAGING=$PACKAGING \
--build-arg LXDEPLOY_ARCH=$LXDEPLOY_ARCH \
--build-arg "MACEMU_SOURCE=$MACEMU_SOURCE" \
--build-arg "MACEMU_GIT_ARGS=$MACEMU_GIT_ARGS" \
--tag macemu-build:$TARGET-$DOCKER_SUFFIX \
--target $TARGET \
--output=type=local,dest=./output \
docker \
2>&1 | tee compile.log \
;
#docker run --platform=$DOCKER_PLATFORM --rm \
# -v "$(realpath ./output):/externalOutput" \
# macemu-build:$TARGET-$DOCKER_SUFFIX \
# /bin/bash -c "cp -ax /output/* /externalOutput/" \
#;
fi
# convenience: chown the output directory to the sudo caller
if [ "${SUDO_USER:-}" != "" ]
then
chown "$SUDO_USER" -R ./output
fi
echo "BUILD COMPLETE"
find ./output
exit
}