-
Notifications
You must be signed in to change notification settings - Fork 2
/
toolchain-morphos
executable file
·348 lines (302 loc) · 9.97 KB
/
toolchain-morphos
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/bash
#
# setup-cross-env.sh version 1.6 Copyright 2013-2016 Mark Olsen, 2017-2019 Marlon Beijer
#
# Script to automatically set up a MorphOS cross compiler environment on Linux (and other Unix-oids).
#
# History:
# 1.8 - 20191015
# - Update to latest MorphOS SDK
# - Set default gcc version to gcc9
# Marlon Beijer
#
# 1.7 - 20190627
# - Fix gcc6 toolchain install
# Marlon Beijer
#
# 1.6 - 20180815
# - Update to latest MorphOS SDK
# Marlon Beijer
#
# 1.5 - 20171212
# - Made it so you can choose which gcc-version to use, and which prefix to install in.
# Marlon Beijer
#
# 1.4 - 20160129
# - The GNU people just can't stop breaking Makeinfo, so documentation generation for GCC is now disabled to avoid Makeinfo problems.
# - The GNU people also just can't stop breaking GCC, so a patch to let GCC build with (a newer) GCC has also been included.
# Mark Olsen
#
# 1.3 - 20150812
# - Now works on Mac OS X
# Mark Olsen
#
VER='1.8'
SDKVERSION='20191006'
WOSSDK='gcc-mos2wos-lite'
GCCVER='gcc9'
TYPE='morphos'
PREFIX="/opt/ppc-$TYPE"
CURDIR=$PWD
gccarray=("gcc4\tgcc5\tgcc6\tgcc7\tgcc8\tgcc9")
usage () {
printf "MorphOS/WarpOS Cross Toolchain v$VER\n"
printf "Usage: $0 [OPTION]...\n\n"
printf "Options:\n"
printf " -p, --prefix\t\t\tchoose the path for your prefix. Default: $PREFIX\n"
printf " -g, --gcc\t\t\tpick the version of gcc you want to install. Available versions: gcc4, gcc5, gcc6, gcc7, gcc8, gcc9 (default)\n"
printf " -w, --warpup\t\t\tinstall WarpOS toolchain\n"
printf " -v, --version\t\tdisplay the SDK-version of MorphOS and exit\n"
printf " -h, --help\t\t\tprint this help\n"
printf "\n"
exit 1;
}
# Picking GCC version
gcchelp () { printf "Available GCC versions:\n * gcc4\n * gcc5\n * gcc6\n * gcc7\n * gcc8\n * gcc9 (default)\n"; }
pickgcc () {
if [ -z "$1" ]; then
gcchelp;
exit 1;
else
if [[ "\t${gccarray[@]}\t" =~ "\t${1}\t" ]]; then
GCCVER=$1;
else
gcchelp;
exit 1;
fi
fi
}
prefixhelp () { printf "Usage: $0 --prefix /path/to/prefix\n"; }
pickprefix () {
if [ -z "$1" ]; then
prefixhelp;
exit 1;
else
PREFIX=$1;
fi
}
ARGV0=$0 # First argument is shell command (as in C)
ARGC=$# # Number of args, not counting $0
i=1 # Used as argument index
while [ $i -le $ARGC ]; do
case ${!i} in
"--version")
printf "Using SDK version: $SDKVERSION.\n"
exit 1;
;;
"-v")
printf "Using SDK version: $SDKVERSION.\n"
exit 1;
;;
"--prefix")
i=$((i+1))
pickprefix ${!i}
;;
"-p")
i=$((i+1))
pickprefix ${!i}
;;
"--gcc")
i=$((i+1))
pickgcc ${!i}
;;
"-g")
i=$((i+1))
pickgcc ${!i}
;;
"-h")
usage
exit 1
;;
"--force")
FORCE=y
;;
"-f")
FORCE=y
;;
"--warpup")
WARPUP=y
;;
"-w")
WARPUP=y
;;
"--help")
usage
exit 1
;;
esac
i=$((i+1))
done
for i in bison bzip2 flex gcc ld lha m4 make makeinfo patch xz wget
do
if [ -z "`which $i`" ]
then
echo "$i is missing."
ERROR=1
fi
done
if [ ! -z "$WARPUP" ]
then
echo "Installing WarpOS toolchain."
TYPE='warpos'
wget -c http://aminet.net/dev/gcc/$WOSSDK.lha -O $WOSSDK.lha
fi
if [ ! -f "sdk-$SDKVERSION.lha" ]
then
wget -c http://www.morphos-team.net/files/sdk-$SDKVERSION.lha -O sdk-$SDKVERSION.lha
fi
if [ ! -f "sdk-source-$SDKVERSION.tar.xz" ]
then
wget -c http://www.morphos-team.net/files/src/sdk/sdk-source-$SDKVERSION.tar.xz -O sdk-source-$SDKVERSION.tar.xz
fi
if [ -d $PREFIX ]
then
echo "$PREFIX already exist. Please remove or pick another prefix path."
ERROR=1
else
mkdir -p ${PREFIX}
fi
if [ ! -O $PREFIX ]
then
echo "$PREFIX isn't owned by you. Please chown it to your user."
ERROR=1
fi
if [ ! -w $PREFIX ]
then
#echo "$PREFIX isn't writable by you. Please chmod u+w $PREFIX";
#ERROR=1;
chmod u+w $PREFIX
fi
if [ -z "$FORCE" ]
then
if [ -d $PREFIX/include ] || [ -d $PREFIX/os-include ] || [ -d $PREFIX/includestd ] || [ -d $PREFIX/ppc-morphos ]
then
echo "You already have an SDK installed in $PREFIX. Either remove the old SDK manually or use -f/--force to automatically overwrite it."
ERROR=1
fi
fi
if [ ! -z "$ERROR" ]
then
exit 1
fi
SDKSOURCE="`ls sdk-source-????????.tar.xz | head -n 1`"
SDKVERSION=`echo "$SDKSOURCE" | sed "s/sdk-source-\(........\)\.tar\.xz/\1/"`
SDK="sdk-$SDKVERSION.lha"
if [ ! -f "$SDK" ] || [ ! -f "$SDKSOURCE" ]
then
echo "Unable to find the SDK files."
echo "Please download the SDK and the corresponding SDK source code files from"
echo "http://www.morphos-team.net/ and place them in the current directory."
exit 1
fi
if [ -z "$SDKVERSION" ]
then
echo "Unable to detect SDK version."
exit 1
fi
echo "Using SDK version: $SDKVERSION"
echo "Installing in prefix: $PREFIX"
echo "Chosen GCC version: $GCCVER"
if [ "`uname`" = "Darwin" ]
then
TMPDIR="`mktemp -d -t setupcrosssdk`"
else
TMPDIR="`mktemp -d`"
fi
if [ -z "$TMPDIR" ]
then
echo "Unable to create temporary directory."
exit 1
fi
trap "rm -rf \"$TMPDIR\"" exit
if [ -d $PREFIX/include ] || [ -d $PREFIX/os-include ] || [ -d $PREFIX/includestd ] || [ -d $PREFIX/ppc-morphos ]
then
echo "Removing old SDK installation."
rm -rf $PREFIX/include $PREFIX/os-include $PREFIX/includestd $PREFIX/ppc-morphos
fi
echo "Extracting SDK files."
if [ ! -z "$WARPUP" ]
then
(cd "$TMPDIR" && lha -x "$CURDIR/$WOSSDK.lha" && tar xvf $WOSSDK.tar) || exit 1
cp -fr $TMPDIR/GG/ppc-warpos $PREFIX/
mkdir -p $PREFIX/bin $PREFIX/lib $PREFIX/include $PREFIX/usr/include $PREFIX/usr/lib
sed -i "s|/gg|$PREFIX|g" $TMPDIR/GG/bin/sdl-config
sed -i "s|/gg|$PREFIX|g" $TMPDIR/GG/bin/libpng-config
sed -i "s|/gg|$PREFIX|g" $TMPDIR/GG/bin/freetype-config
sed -i "s|/gg|$PREFIX|g" $TMPDIR/GG/bin/libmikmod-config
cp -fr $TMPDIR/GG/bin/* $PREFIX/bin
ln -sf $PREFIX/ppc-warpos $PREFIX/ppc-morphos
else
# Extract files for $PREFIX
(cd "$TMPDIR" && lha -x "$CURDIR/$SDK" "morphossdk/sdk.pack" >/dev/null && xz -dcf morphossdk/sdk.pack | (cd $PREFIX && tar --transform "s,^Development/gg/,," -x "Development/gg/ppc-morphos" "Development/gg/include" "Development/gg/includestd" "Development/gg/os-include")) || exit 1
ln -sf $PREFIX/os-include $PREFIX/ppc-morphos/sys-include
ln -sf $PREFIX/include $PREFIX/ppc-morphos/include
fi
if [ $GCCVER == "gcc6" ]
then
(cd "$CURDIR" && wget -c ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-6.5.0/gcc-6.5.0.tar.gz -O gcc6.tgz)
(cd "$TMPDIR" && tar -xf "$CURDIR/$SDKSOURCE" sdk-source/binutils)
(cd "$TMPDIR" && mv -f sdk-source/binutils binutils)
(cd "$TMPDIR" && tar -xf "$CURDIR/gcc6.tgz")
else
# Extract the Binutils/GCC source code.
(cd "$TMPDIR" && rm -rf binutils $GCCVER && tar -xf "$CURDIR/$SDKSOURCE" sdk-source/binutils sdk-source/$GCCVER)
(cd "$TMPDIR" && mv -f sdk-source/binutils binutils && mv -f sdk-source/$GCCVER $GCCVER)
fi
# Build Binutils
echo "Building binutils."
cd "$TMPDIR" && chmod -R 777 binutils
(cd "$TMPDIR/binutils" && sed -i 's|s/@prefix@/\\/gg/|s\|@prefix@\|'$PREFIX'\||g' Makefile && sed -i 's|/gg|'$PREFIX'|g' Makefile 2>&1) || ERROR=1
(cd "$TMPDIR/binutils" && sed -i 's|include|\#include|g' Makefile 2>&1) || ERROR=1
(cd "$TMPDIR/binutils" && sed -i 's|\.\/mkdist|mkdir dist|g' Makefile 2>&1) || ERROR=1
(cd "$TMPDIR/binutils" && sed -i 's|cd dist\; ixrun Install|cd build\; \$\(MAKE\) install|g' Makefile 2>&1) || ERROR=1
(cd "$TMPDIR/binutils" && sed -i 's|--target=ppc-morphos|--target=ppc-morphos --program-prefix=ppc-'$TYPE'-|g' Makefile 2>&1) || ERROR=1
test -z "$ERROR" && (cd "$TMPDIR/binutils" && make >>"$CURDIR/setup-cross-sdk.log" 2>&1) || ERROR=1
test -z "$ERROR" && (cd "$TMPDIR/binutils" && make install >>"$CURDIR/setup-cross-sdk.log" 2>&1) || ERROR=1
if [ ! -z "$ERROR" ]
then
echo "Failed to build Binutils for whatever reason. You're unfortunately on"
echo "your own now. Check \"$CURDIR/setup-cross-sdk.log\" for details."
exit 1
fi
# Set up required Binutils symlinks
#mkdir -p $PREFIX/ppc-$TYPE/bin
#for i in ar as ld nm objdump ranlib
#do
# ln -s $PREFIX/bin/ppc-$TYPE-$i $PREFIX/ppc-$TYPE/bin/$i
# ln -sf $PREFIX/bin/ppc-$TYPE-$i $PREFIX/ppc-morphos/bin/$i
#done
echo "Building $GCCVER."
if [ $GCCVER == "gcc6" ]
then
cp $CURDIR/gcc-6-morphos.diff $TMPDIR/
sed -i "s|/gg|$PREFIX|g" $TMPDIR/gcc-6-morphos.diff
#sed -i "s|ppc-morphos|ppc-$TYPE|g" $TMPDIR/gcc-6-morphos.diff
(cd "$TMPDIR/gcc-6.5.0" && patch -p1 < $TMPDIR/gcc-6-morphos.diff)
mkdir $TMPDIR/build
test -z "$ERROR" && (cd $TMPDIR/build && ../gcc-6.5.0/configure --target=ppc-morphos --with-plugin-ld=no --enable-languages=c,c++,objc,obj-c++ --prefix=$PREFIX --with-sysroot=$PREFIX --libexecdir=$PREFIX/lib --oldincludedir=$PREFIX/include --program-prefix=ppc-$TYPE- --enable-threads=morphos --disable-bootstrap --with-pkgversion=GCC/MorphOS --with-bugurl=http://www.morphos-team.net/ >>"$CURDIR/setup-cross-sdk.log" 2>&1) || ERROR=1
test -z "$ERROR" && (cd $TMPDIR/build && make -j8 >>"$CURDIR/setup-cross-sdk.log" 2>&1) || ERROR=1
test -z "$ERROR" && (cd $TMPDIR/build && make install -j8 >>"$CURDIR/setup-cross-sdk.log" 2>&1) || ERROR=1
else
cd "$TMPDIR/$GCCVER"
sed -i "s|/gg|$PREFIX|g" Makefile
sed -i "s|--target=ppc-morphos|--target=ppc-morphos --program-prefix=ppc-"$TYPE"-|g" Makefile
sed -i "s|--program-suffix=-2|--program-suffix=\"\"|g" Makefile
sed -i "s|--program-suffix=-3|--program-suffix=\"\"|g" Makefile
sed -i "s|--program-suffix=-4|--program-suffix=\"\"|g" Makefile
sed -i "s|--program-suffix=-5|--program-suffix=\"\"|g" Makefile
sed -i "s|--program-suffix=-6|--program-suffix=\"\"|g" Makefile
sed -i "s|--program-suffix=-7|--program-suffix=\"\"|g" Makefile
sed -i "s|--program-suffix=-8|--program-suffix=\"\"|g" Makefile
test -z "$ERROR" && (cd "$TMPDIR/$GCCVER" && make >>"$CURDIR/setup-cross-sdk.log" 2>&1) || ERROR=1
test -z "$ERROR" && (cd "$TMPDIR/$GCCVER" && make install >>"$CURDIR/setup-cross-sdk.log" 2>&1) || ERROR=1
fi
rm -rf $PREFIX/bin/ar $PREFIX/as $PREFIX/ld $PREFIX/nm $PREFIX/objdump $PREFIX/ranlib $PREFIX/strip
if [ ! -z "$ERROR" ]
then
echo "Failed to build $GCCVER for whatever reason. You're unfortunately on"
echo "your own now. Check \"$CURDIR/setup-cross-sdk.log\" for details."
exit 1
fi
echo 'All done!'
exit 0