-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
executable file
·137 lines (121 loc) · 3.99 KB
/
build.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
#!/bin/sh -eux
target=m68k-atari-mint
if [ -z "${INSTALL_DIR}" ] ; then
INSTALL_DIR="$HOME/gnu-tools"
fi
CPU_DIRS="m68000 m68020-60 m5475" # target directory
CPU_OPTS="m68000 m68020-60 mcpu=5475" # gcc command line
CPU_CPUS="m68000 m68020-60 5475" # --with-cpu=
CPU_COUNT=$(echo ${CPU_DIRS} | tr ' ' '\n' | wc -l)
indices=""
indices_all=""
i=1
while [ $i -le $CPU_COUNT ] ; do
indices_all="$indices_all $i"
i=$((i + 1))
done
skip_native=0
native_only=0
clean=0
# parse command line
for arg in $*
do
case $arg in
--skip-native)
skip_native=1
;;
--native-only)
native_only=1
;;
--all)
indices=$indices_all
;;
--clean)
clean=1
;;
*)
ok=0
i=1
while [ $i -le $CPU_COUNT ] ; do
cpu=$(echo $CPU_CPUS | cut -d ' ' -f $i)
if [ "$arg" = "$cpu" ] ; then
indices="$indices $i"
ok=1
fi
i=$((i + 1))
done
if [ $ok -eq 0 ] ; then
echo "Error : $arg is not a valid CPU."
echo "Valid CPU are : ${CPU_CPUS}"
exit 1
fi
;;
esac
done
if [ -z "$indices" ] ; then
echo "Do not invoke this script directly. Type 'make' or 'make help'."
exit 1
fi
if [ $clean -eq 0 -a $native_only -eq 0 ] ; then
# build & install temporary toolchain
DESTDIR="$PWD/preliminary"
${MAKE} PATH="$DESTDIR/bin:/usr/bin" TARGET=$target PREFIX="" DESTDIR="$DESTDIR" binutils-preliminary gcc-preliminary
# build & install mintlib/fdlibm (to make fdlibm's ./configure happy)
${MAKE} PATH="$DESTDIR/bin:/usr/bin" TARGET=$target DESTDIR="$DESTDIR/$target/sys-root" mintlib-preliminary fdlibm-preliminary
elif [ $clean -ne 0 -a $native_only -eq 0 ] ; then
# TODO: this is called even in 'make clean-cross'
${MAKE} TARGET=$target DESTDIR="$PWD/preliminary" clean-preliminary
# this must be followed by calling make clean-cross below
fi
for i in $indices
do
dir=$(echo $CPU_DIRS | cut -d ' ' -f $i)
cpu=$(echo $CPU_CPUS | cut -d ' ' -f $i)
opt=$(echo $CPU_OPTS | cut -d ' ' -f $i)
if [ $clean -eq 0 ]; then
if [ $native_only -eq 0 ] ; then
DESTDIR="$INSTALL_DIR/$dir/$target/sys-root"
# install pre-built mintlib/fdlibm (mintlib's make install requires a working compiler)
${MAKE} PATH="$PWD/preliminary/bin:/usr/bin" CPU="$cpu" TARGET=$target DESTDIR="$DESTDIR" mintlib fdlibm || exit 1
# remove mintlib m68000 leftovers
rm -r "$DESTDIR/sbin"
rm -r "$DESTDIR/usr/sbin"
# provide proper folders for m68020-60 and m5475 multilib
if [ "$dir" != "m68000" ]
then
target_dirs=""
for j in $indices_all
do
target_dir=$(echo $CPU_DIRS | cut -d ' ' -f $j)
if [ "$target_dir" != "m68000" ]
then
target_dirs="$target_dirs $target_dir"
fi
done
target_dir_1=$(echo $target_dirs | cut -d ' ' -f 1)
target_dir_2=$(echo $target_dirs | cut -d ' ' -f 2)
mkdir "$DESTDIR/usr/lib/m68000"
find "$DESTDIR/usr/lib" -mindepth 1 -maxdepth 1 -not -name "m68000" -not -name "$target_dir_1" -not -name "$target_dir_2" -exec mv "{}" "$DESTDIR/usr/lib/m68000" \;
find "$DESTDIR/usr/lib/$dir" -mindepth 1 -maxdepth 1 -exec mv "{}" "$DESTDIR/usr/lib" \;
rmdir "$DESTDIR/usr/lib/$dir"
fi
# install pre-built binutils
${MAKE} PATH="$INSTALL_DIR/$dir/bin:/usr/bin" CPU="$cpu" DESTDIR="$INSTALL_DIR/$dir" binutils || exit 1
# build & install gcc
${MAKE} PATH="$INSTALL_DIR/$dir/bin:/usr/bin" CPU="$cpu" TARGET=$target INSTALL_DIR="$INSTALL_DIR/$dir" gcc || exit 1
# build & install mintbin
${MAKE} PATH="$INSTALL_DIR/$dir/bin:/usr/bin" CPU="$cpu" TARGET=$target PREFIX="" DESTDIR="$INSTALL_DIR/$dir" mintbin || exit 1
fi
if [ $skip_native -eq 0 ] ; then
${MAKE} PATH="$INSTALL_DIR/$dir/bin:/usr/bin" CPU="$cpu" TARGET=$target INSTALL_DIR="$INSTALL_DIR/$dir" OPT="$opt" binutils-atari gcc-atari mintbin-atari || exit 1
${MAKE} PATH="$INSTALL_DIR/$dir/bin:/usr/bin" CPU="$cpu" TARGET=$target INSTALL_DIR="$INSTALL_DIR/$dir" strip-atari pack-atari || exit 1
fi
else
if [ $native_only -eq 0 ] ; then
${MAKE} CPU="$cpu" TARGET=$target clean-cross
fi
if [ $skip_native -eq 0 ] ; then
${MAKE} CPU="$cpu" TARGET=$target clean-atari
fi
fi
done