forked from adtools/amigaos-cross-toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·667 lines (550 loc) · 14.1 KB
/
bootstrap.sh
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
#!/bin/bash -Eeux
readonly TOP_DIR="$(pwd)"
readonly ARCHIVES="${TOP_DIR}/archives"
readonly PATCHES="${TOP_DIR}/patches"
readonly SOURCES="${TOP_DIR}/sources"
readonly BUILD_DIR="${TOP_DIR}/build"
readonly HOST_DIR="${TOP_DIR}/host"
readonly STAMP="${TOP_DIR}/stamps"
readonly MAKE="make -j$(getconf _NPROCESSORS_CONF)"
function prepare_target {
mkdir -p "${STAMP}" "${BUILD_DIR}" "${PREFIX}"
[ -f "${STAMP}/prepare-target" ] && return 0
pushd "${PREFIX}"
mkdir -p "bin" "doc" "etc" "lib" "m68k-amigaos"
mkdir -p "os-include/lvo" "os-lib" "vbcc-include" "vbcc-lib"
ln -sf "../os-include" "m68k-amigaos/include"
ln -sf "../lib" "m68k-amigaos/lib"
popd
touch "${STAMP}/prepare-target"
}
function copy_non_diff {
find "${PATCHES}/$1" -type f \! -name '*.diff' | while read IN ; do
OUT=$(echo "$IN" | sed -e "s,$PATCHES/,$SOURCES/,g")
cp "$IN" "$OUT"
done
}
function apply_patches {
for file in $(find "${PATCHES}/$1" -type f -iname '*.diff' | sort); do
patch -i $file -t -p1
done
}
function mkdir_empty {
rm -rf "$1"
mkdir -p "$1"
}
function unpack_clean {
local cmd
rm -rf "$1"
while (( "$#" > 1 )); do
shift
case "$1" in
*.tar.gz)
cmd="tar -xzf";;
*.tar.bz2)
cmd="tar -xjf";;
*.lha)
cmd="lha -xq";;
*.zip)
cmd="unzip";;
*)
cmd="false";;
esac
${cmd} "${ARCHIVES}/$1"
done
}
function compare_version {
python2.7 - "$1" "$2" "$3" <<EOF
from distutils.version import StrictVersion
import sys
cmp = lambda x, y: StrictVersion(x).__cmp__(y)
op = {"lt": [-1], "gt": [1],
"le": [-1, 0], "ge": [1, 0],
"eq": [0], "ne": [-1, 1]}
res = cmp(sys.argv[1], sys.argv[3]) in op[sys.argv[2]]
sys.exit(int(not res))
EOF
}
function unpack_sources {
[ -f "${STAMP}/unpack-sources" ] && return 0
rm -rf "${SOURCES}"
mkdir -p "${SOURCES}"
pushd "${SOURCES}"
unpack_clean "${BINUTILS}" "${BINUTILS_SRC}"
pushd "${BINUTILS}"
copy_non_diff "${BINUTILS}"
apply_patches "${BINUTILS}"
popd
unpack_clean "${GCC}" "${GCC_CORE_SRC}" "${GCC_CPP_SRC}"
pushd "${GCC}"
copy_non_diff "${GCC}"
apply_patches "${GCC}"
popd
if compare_version "${GCC_VER}" "ge" "4.0.0"; then
unpack_clean "${GMP}" "${GMP_SRC}"
unpack_clean "${MPC}" "${MPC_SRC}"
unpack_clean "${MPFR}" "${MPFR_SRC}"
fi
unpack_clean "${FD2SFD}" "${FD2SFD_SRC}"
pushd "${FD2SFD}"
apply_patches "${FD2SFD}"
popd
unpack_clean "${SFDC}" "${SFDC_SRC}"
pushd "${SFDC}"
apply_patches "${SFDC}"
popd
unpack_clean "${NDK}" "${NDK_SRC}"
rm -f *.info
pushd "${NDK}"
mkdir Include/include_h/inline
copy_non_diff "${NDK}"
apply_patches "${NDK}"
popd
unpack_clean "${IXEMUL}" "${IXEMUL_SRC}"
mv "ixemul" "${IXEMUL}"
pushd "${IXEMUL}"
chmod a+x "configure" "mkinstalldirs"
apply_patches "${IXEMUL}"
popd
unpack_clean "${LIBNIX}" "${LIBNIX_SRC}"
mv "libnix-master" "${LIBNIX}"
chmod a+x "${LIBNIX}/mkinstalldirs"
unpack_clean "${LIBM}" "${LIBM_SRC}"
mv "contrib/libm" "${LIBM}"
rmdir "contrib"
mkdir_empty "${LIBAMIGA}"
pushd "${LIBAMIGA}"
tar -xzf "${ARCHIVES}/${LIBAMIGA_SRC}"
popd
unpack_clean "${TEXINFO}" "${TEXINFO_SRC}"
unpack_clean "${BISON}" "${BISON_SRC}"
unpack_clean "${GAWK}" "${GAWK_SRC}"
unpack_clean "${M4}" "${M4_SRC}"
unpack_clean "${VASM}" "${VASM_SRC}"
mv "vasm" "${VASM}"
unpack_clean "${VLINK}" "${VLINK_SRC}"
mv "vlink" "${VLINK}"
unpack_clean "${VBCC}" "${VBCC_SRC}"
mv "vbcc" "${VBCC}"
pushd "${VBCC}"
apply_patches "${VBCC}"
popd
unpack_clean "${VCLIB}" "${VCLIB_SRC}"
mv "vbcc_target_m68k-amigaos" "${VCLIB}"
rm "vbcc_target_m68k-amigaos.info"
popd
touch "${STAMP}/unpack-sources"
}
function build_tools {
[ -f "${STAMP}/build-tools" ] && return 0
mkdir_empty "${HOST_DIR}"
pushd "${BUILD_DIR}"
mkdir_empty "${M4}"
pushd "${M4}"
"${SOURCES}/${M4}/configure" \
--prefix="${HOST_DIR}"
${MAKE}
make install
ln -s m4 "${HOST_DIR}/bin/gm4"
popd
mkdir_empty "${GAWK}"
pushd "${GAWK}"
"${SOURCES}/${GAWK}/configure" \
--prefix="${HOST_DIR}"
${MAKE}
make install
popd
if compare_version "${GCC_VER}" "le" "3.4.6"; then
mkdir_empty "${BISON}"
pushd "${BISON}"
"${SOURCES}/${BISON}/configure" \
--prefix="${HOST_DIR}"
${MAKE}
make install
popd
fi
mkdir_empty "${TEXINFO}"
pushd "${TEXINFO}"
"${SOURCES}/${TEXINFO}/configure" \
--prefix="${HOST_DIR}"
${MAKE}
make install
popd
if compare_version "${GCC_VER}" "ge" "4.0.0"; then
mkdir_empty "${GMP}"
pushd "${GMP}"
"${SOURCES}/${GMP}/configure" \
--prefix="${HOST_DIR}" \
--disable-shared
${MAKE}
make install
popd
mkdir_empty "${MPFR}"
pushd "${MPFR}"
"${SOURCES}/${MPFR}/configure" \
--prefix="${HOST_DIR}" \
--disable-shared \
--with-gmp="${HOST_DIR}"
${MAKE}
make install
popd
mkdir_empty "${MPC}"
pushd "${MPC}"
"${SOURCES}/${MPC}/configure" \
--prefix="${HOST_DIR}" \
--disable-shared \
--with-gmp="${HOST_DIR}" \
--with-mpfr="${HOST_DIR}"
${MAKE}
make install
popd
fi
popd
touch "${STAMP}/build-tools"
}
function build_vasm {
[ -f "${STAMP}/build-vasm" ] && return 0
pushd "${BUILD_DIR}"
rm -rf "${VASM}"
cp -a "${SOURCES}/${VASM}" .
cd "${VASM}"
make CPU="m68k" SYNTAX="mot"
cp "vasmm68k_mot" "vobjdump" "${PREFIX}/bin/"
cat >"${PREFIX}/bin/vasm" <<EOF
#!/bin/sh
vasmm68k_mot -I${PREFIX}/os-include "\$@"
EOF
popd
chmod a+x "${PREFIX}/bin/vasm"
touch "${STAMP}/build-vasm"
}
function build_vlink {
[ -f "${STAMP}/build-vlink" ] && return 0
pushd "${BUILD_DIR}"
rm -rf "${VLINK}"
cp -a "${SOURCES}/${VLINK}" .
cd "${VLINK}"
make
cp "vlink" "${PREFIX}/bin/"
popd
touch "${STAMP}/build-vlink"
}
function build_vbcc {
[ -f "${STAMP}/build-vbcc" ] && return 0
pushd "${BUILD_DIR}"
rm -rf "${VBCC}"
cp -a "${SOURCES}/${VBCC}" .
cd "${VBCC}"
mkdir "bin"
make TARGET="m68k" CC+="-DETCDIR=\\\"${PREFIX}/etc/\\\"" <<EOF
y
y
signed char
y
unsigned char
n
y
signed short
n
y
unsigned short
n
y
signed int
n
y
unsigned int
n
y
signed long
n
y
unsigned long
n
y
float
n
y
double
EOF
cp "bin/vbccm68k" "bin/vc" "bin/vprof" "${PREFIX}/bin/"
popd
touch "${STAMP}/build-vbcc"
}
function install_vclib {
[ -f "${STAMP}/install-vclib" ] && return 0
pushd "${PREFIX}/vbcc-include"
cp -av "${SOURCES}/${VCLIB}/targets/m68k-amigaos/include/"* .
popd
pushd "${PREFIX}/vbcc-lib"
cp -av "${SOURCES}/${VCLIB}/targets/m68k-amigaos/lib/"* .
popd
sed -e "s,-Ivincludeos3:,-I${PREFIX}/vbcc-include -I${PREFIX}/os-include,g" \
-e "s,-Lvlibos3:,-L${PREFIX}/vbcc-lib -L${PREFIX}/vbcc-include,g" \
-e "s,vlibos3:,${PREFIX}/vbcc-lib/,g" \
-e "s,-lvc,-lvc -lamiga,g" \
-e "/^-as/s,\$, -I${PREFIX}/os-include,g" \
-e "s,delete quiet,rm,g" \
-e "s,delete,rm -v,g" \
"${SOURCES}/${VCLIB}/config/aos68k" > "${PREFIX}/etc/vc.config"
touch "${STAMP}/install-vclib"
}
function build_binutils {
[ -f "${STAMP}/build-binutils" ] && return 0
pushd "${BUILD_DIR}"
mkdir_empty "${BINUTILS}"
cd "${BINUTILS}"
CC="${CC} ${ARCH:-}" "${SOURCES}/${BINUTILS}/configure" \
--prefix="${PREFIX}" \
--host="i686-linux-gnu" \
--target="m68k-amigaos"
make all
make install install-info
popd
touch "${STAMP}/build-binutils"
}
function build_gcc {
[ -f "${STAMP}/build-gcc" ] && return 0
pushd "${BUILD_DIR}"
mkdir_empty "${GCC}"
cd "${GCC}"
"${SOURCES}/${GCC}/configure" \
--prefix="${PREFIX}" \
--target="m68k-amigaos" \
--enable-languages=c \
--with-headers="${SOURCES}/${IXEMUL}/include" \
${GCC_CONFIGURE_OPTS[*]}
make all ${FLAGS_FOR_TARGET[*]}
make install ${FLAGS_FOR_TARGET[*]}
popd
touch "${STAMP}/build-gcc"
}
function build_gpp {
[ -f "${STAMP}/build-gpp" ] && return 0
local GPP="${GCC/gcc/g++}"
pushd "${BUILD_DIR}"
mkdir_empty "${GPP}"
cd "${GPP}"
"${SOURCES}/${GCC}/configure" \
--prefix="${PREFIX}" \
--target="m68k-amigaos" \
--enable-languages=c++ \
--with-headers="${SOURCES}/${IXEMUL}/include" \
${GCC_CONFIGURE_OPTS[*]}
make all ${FLAGS_FOR_TARGET[*]}
make install ${FLAGS_FOR_TARGET[*]}
popd
touch "${STAMP}/build-gpp"
}
function process_ndk {
[ -f "${STAMP}/process-ndk" ] && return 0
pushd "${BUILD_DIR}"
rm -rf "${FD2SFD}"
cp -a "${SOURCES}/${FD2SFD}" "${FD2SFD}"
cd "${FD2SFD}"
./configure \
--prefix="${PREFIX}"
make
make install
popd
pushd "${BUILD_DIR}"
rm -rf "${SFDC}"
cp -a "${SOURCES}/${SFDC}" "${SFDC}"
cd "${SFDC}"
./configure \
--prefix="${PREFIX}"
make
make install
popd
pushd "${PREFIX}/os-include"
cp -av "${SOURCES}/${NDK}/Include/include_h/"* .
cp -av "${SOURCES}/${NDK}/Include/include_i/"* .
for file in ${SOURCES}/${NDK}/Include/sfd/*.sfd; do
base=$(basename ${file%_lib.sfd})
sfdc --target=m68k-amigaos --mode=proto \
--output="proto/${base}.h" $file
sfdc --target=m68k-amigaos --mode=macros \
--output="inline/${base}.h" $file
sfdc --target=m68k-amigaos --mode=lvo \
--output="lvo/${base}_lib.i" $file
done
popd
pushd "${PREFIX}/os-lib"
cp -av "${SOURCES}/${NDK}/Include/fd" .
cp -av "${SOURCES}/${NDK}/Include/sfd" .
cp -av "${SOURCES}/${NDK}/Include/linker_libs/"* .
popd
pushd "${PREFIX}/doc"
cp -av "${SOURCES}/${NDK}/Documentation/Autodocs/"* .
popd
touch "${STAMP}/process-ndk"
}
function install_libamiga {
[ -f "${STAMP}/install-libamiga" ] && return 0
pushd "${PREFIX}"
cp -av "${SOURCES}/${LIBAMIGA}/lib" .
popd
touch "${STAMP}/install-libamiga"
}
function build_libnix {
[ -f "${STAMP}/build-libnix" ] && return 0
pushd "${BUILD_DIR}"
mkdir_empty "${LIBNIX}"
cd "${LIBNIX}"
"${SOURCES}/${LIBNIX}/configure" \
--prefix="${PREFIX}" \
--host="i686-linux-gnu" \
--target="m68k-amigaos"
make all \
CC=m68k-amigaos-gcc \
CPP="m68k-amigaos-gcc -E" \
AR=m68k-amigaos-ar \
AS=m68k-amigaos-as \
RANLIB=m68k-amigaos-ranlib \
LD=m68k-amigaos-ld \
MAKEINFO=:
[ -f "${PREFIX}/guide" ] && rm -f "${PREFIX}/guide"
make install MAKEINFO=:
install -v -m 644 "${SOURCES}/${LIBNIX}/sources/headers/stabs.h" "${PREFIX}/m68k-amigaos/sys-include"
popd
touch "${STAMP}/build-libnix"
}
function build_libm {
[ -f "${STAMP}/build-libm" ] && return 0
pushd "${BUILD_DIR}"
mkdir_empty "${LIBM}"
cd "${LIBM}"
CC=m68k-amigaos-gcc \
AR=m68k-amigaos-ar \
CFLAGS="-noixemul" \
RANLIB=m68k-amigaos-ranlib \
"${SOURCES}/${LIBM}/configure" \
--prefix="${PREFIX}" \
--host="i686-linux-gnu" \
--build="m68k-amigaos"
make
make install
popd
touch "${STAMP}/build-libm"
}
function build_ixemul {
[ -f "${STAMP}/build-ixemul" ] && return 0
pushd "${BUILD_DIR}"
mkdir_empty "${IXEMUL}"
cd "${IXEMUL}"
CC=m68k-amigaos-gcc \
CFLAGS="-noixemul -I${PREFIX}/os-include" \
AR=m68k-amigaos-ar \
RANLIB=m68k-amigaos-ranlib \
"${SOURCES}/${IXEMUL}/configure" \
--prefix="${PREFIX}" \
--host="i686-linux-gnu" \
--target="m68k-amigaos"
make MAKEINFO=: all
make MAKEINFO=: install
popd
touch "${STAMP}/build-ixemul"
}
function build {
source "${TOP_DIR}/bootstrap.conf"
# On 64-bit architecture GNU Assembler crashes writing out an object, due to
# (probably) miscalculated structure sizes. There could be some other bugs
# lurking there in 64-bit mode, but I have little incentive chasing them.
# Just compile everything in 32-bit mode and forget about the issues.
if [ "$(uname -m)" == "x86_64" ]; then
ARCH="-m32"
fi
# Take over the path -- to preserve hermetic build.
export PATH="/usr/bin:/bin:/usr/local/bin:/opt/local/bin"
# Make sure we always choose known compiler (from the distro) and not one
# in user's path that could shadow the original one.
CC="$(which gcc) -std=gnu89"
CXX="$(which g++) -std=gnu++98"
# Define extra options for gcc's configure script.
if [ "${VERSION}" != "4" ]; then
# Older gcc compilers (i.e. 2.95.3 and 3.4.6) have to be tricked into
# thinking that they're being compiled on IA-32 architecture.
CC="${CC} ${ARCH:-}"
CXX="${CXX} ${ARCH:-}"
GCC_CONFIGURE_OPTS+=("--host=i686-linux-gnu" \
"--build=i686-linux-gnu")
else
# GCC 4.x requires some extra dependencies to be supplied.
GCC_CONFIGURE_OPTS+=("--with-gmp=${HOST_DIR}" \
"--with-mpfr=${HOST_DIR}" \
"--with-mpc=${HOST_DIR}" \
"--disable-shared")
fi
export CC CXX
readonly FLAGS_FOR_TARGET=( \
"MAKEINFO=makeinfo" \
"CFLAGS_FOR_TARGET=-noixemul" \
"AR_FOR_TARGET=${PREFIX}/bin/m68k-amigaos-ar" \
"AS_FOR_TARGET=${PREFIX}/bin/m68k-amigaos-as" \
"LD_FOR_TARGET=${PREFIX}/bin/m68k-amigaos-ld" \
"NM_FOR_TARGET=${PREFIX}/bin/m68k-amigaos-nm" \
"OBJCOPY_FOR_TARGET=${PREFIX}/bin/m68k-amigaos-objcopy" \
"OBJDUMP_FOR_TARGET=${PREFIX}/bin/m68k-amigaos-objdump" \
"RANLIB_FOR_TARGET=${PREFIX}/bin/m68k-amigaos-ranlib")
prepare_target
unpack_sources
export PATH="${HOST_DIR}/bin:${PATH}"
build_tools
build_vasm
build_vlink
build_vbcc
install_vclib
build_binutils
build_gcc
export PATH="${PREFIX}/bin:${PATH}"
process_ndk
install_libamiga
build_libnix
build_libm
build_gpp
# TODO: Ixemul is not suited for cross compilation very well. The build
# process compiles some tools with cross compiler and tries to run them
# locally.
#build_ixemul
}
function main {
PREFIX="${TOP_DIR}/target"
VERSION="2"
local action="build"
while [ -n "${1:-}" ]; do
case "$1" in
--prefix=*)
PREFIX=${1#*=}
;;
--version=*)
VERSION=${1#*=}
;;
--*)
echo "Unknown option: $1"
exit 1
;;
*)
break
;;
esac
shift
done
if [ -n "${1:-}" ]; then
action="$1"
fi
case "${action}" in
"build")
build
;;
"clean")
for dir in ${SOURCES} ${BUILD_DIR} ${HOST_DIR} ${STAMP}; do
rm -rf "${dir}"
done
;;
*)
echo "Unknown action '${action}'!"
exit 1
;;
esac
}
main "$@"