-
Notifications
You must be signed in to change notification settings - Fork 0
/
avr-gcc-100.sh
executable file
·248 lines (189 loc) · 8.1 KB
/
avr-gcc-100.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
#!/usr/bin/env bash
#
# Copyright Christopher Kormanyos 2023 - 2024.
# Distributed under The Unlicense.
#
# Example call(s):
# ./avr-gcc-100.sh 13.2.0 x86_64-linux-gnu x86_64-linux-gnu
# ./avr-gcc-100.sh 13.2.0 x86_64-w64-mingw32 x86_64-w64-mingw32 /c/mingw
#
SCRIPT_PATH=$(readlink -f "$BASH_SOURCE")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
MY_VERSION=$1
BUILD_NAME=$2
HOST_NAME=$3
if [[ "$BUILD_NAME" == "x86_64-w64-mingw32" ]]; then
# echo 'install necessary packages and build tools'
# pacman -S --needed --noconfirm autoconf automake bzip2 cmake git make ninja patch python texinfo wget
# Get standalone msys2 from nuwen (contains standalone gcc-x86_64-w64-mingw32).
# The page describing this is: https://nuwen.net/mingw.html
# The exact download link is: https://nuwen.net/files/mingw/mingw-19.0.exe
# For detailed background information, see also the detailed instructions
# at GitHub from Stephan T. Lavavej's repositiony.
# These can be found here: https://github.com/StephanTLavavej/mingw-distro
OLD_MINGW_PATH=$4
echo 'append standalone gcc-x86_64-w64-mingw32 path'
export X_DISTRO_ROOT="$OLD_MINGW_PATH"
export X_DISTRO_BIN=$X_DISTRO_ROOT/bin
export X_DISTRO_INC=$X_DISTRO_ROOT/include
export X_DISTRO_LIB=$X_DISTRO_ROOT/lib
export PATH=$PATH:$X_DISTRO_BIN
export C_INCLUDE_PATH=$X_DISTRO_INC
export CPLUS_INCLUDE_PATH=$X_DISTRO_INC
echo
fi
echo 'clean gcc_build directory'
rm -rf gcc_build | true
echo 'make and enter gcc_build directory'
mkdir -p $SCRIPT_DIR/gcc_build
echo
if [[ "$MY_VERSION" == "12.3.0" ]]; then
echo 'copy gcc patch file'
cd $SCRIPT_DIR/gcc_build
cp ../avr-gcc-100-"$MY_VERSION"_"$BUILD_NAME".patch .
echo
fi
echo 'query system gcc'
g++ -v
result_system_gcc=$?
echo "result_system_gcc: " "$result_system_gcc"
echo
cd $SCRIPT_DIR/gcc_build
echo 'get tar-balls'
wget --no-check-certificate https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz
wget --no-check-certificate https://ftp.gnu.org/gnu/libiconv/libiconv-1.17.tar.gz
wget --no-check-certificate https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz
wget --no-check-certificate https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz
wget --no-check-certificate https://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz
wget --no-check-certificate https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.24.tar.bz2
wget --no-check-certificate https://gcc.gnu.org/pub/gcc/infrastructure/cloog-0.18.1.tar.gz
wget --no-check-certificate https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.xz
wget --no-check-certificate https://ftp.gnu.org/gnu/gcc/gcc-"$MY_VERSION"/gcc-"$MY_VERSION".tar.xz
echo
cd $SCRIPT_DIR/gcc_build
echo 'build zstd'
tar -xf zstd-1.5.5.tar.gz
mkdir objdir-zstd-1.5.5
cd objdir-zstd-1.5.5
cmake "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_C_FLAGS=-s -O2" "-DCMAKE_INSTALL_PREFIX=$SCRIPT_DIR/local/zstd-1.5.5" "-DZSTD_BUILD_SHARED=OFF" -G Ninja $SCRIPT_DIR/gcc_build/zstd-1.5.5/build/cmake
ninja
ninja install
echo
cd $SCRIPT_DIR/gcc_build
echo 'build libiconv'
tar -xf libiconv-1.17.tar.gz
mkdir objdir-libiconv-1.17
cd objdir-libiconv-1.17
../libiconv-1.17/configure --prefix=$SCRIPT_DIR/local/libiconv-1.17 --build="$BUILD_NAME" --target="$HOST_NAME" --host="$HOST_NAME" --enable-static --disable-shared
make --jobs=6
make install
echo
cd $SCRIPT_DIR/gcc_build
echo 'build gmp'
tar -xf gmp-6.3.0.tar.xz
mkdir objdir-gmp-6.3.0
cd objdir-gmp-6.3.0
../gmp-6.3.0/configure --prefix=$SCRIPT_DIR/local/gmp-6.3.0 --build="$BUILD_NAME" --target="$HOST_NAME" --host="$HOST_NAME" --enable-static --disable-shared
make --jobs=6
make install
echo
cd $SCRIPT_DIR/gcc_build
echo 'build mpfr'
tar -xf mpfr-4.2.1.tar.xz
mkdir objdir-mpfr-4.2.1
cd objdir-mpfr-4.2.1
../mpfr-4.2.1/configure --prefix=$SCRIPT_DIR/local/mpfr-4.2.1 --build="$BUILD_NAME" --target="$HOST_NAME" --host="$HOST_NAME" --enable-static --disable-shared --with-gmp=$SCRIPT_DIR/local/gmp-6.3.0
make --jobs=6
make install
echo
cd $SCRIPT_DIR/gcc_build
echo 'build mpc'
tar -xf mpc-1.3.1.tar.gz
mkdir objdir-mpc-1.3.1
cd objdir-mpc-1.3.1
../mpc-1.3.1/configure --prefix=$SCRIPT_DIR/local/mpc-1.3.1 --build="$BUILD_NAME" --target="$HOST_NAME" --host="$HOST_NAME" --enable-static --disable-shared --with-gmp=$SCRIPT_DIR/local/gmp-6.3.0 --with-mpfr=$SCRIPT_DIR/local/mpfr-4.2.1
make --jobs=6
make install
echo
cd $SCRIPT_DIR/gcc_build
echo 'build isl'
tar -xjf isl-0.24.tar.bz2
mkdir objdir-isl-0.24
cd objdir-isl-0.24
../isl-0.24/configure --prefix=$SCRIPT_DIR/local/isl-0.24 --build="$BUILD_NAME" --target="$HOST_NAME" --host="$HOST_NAME" --enable-static --disable-shared --with-gmp-prefix=$SCRIPT_DIR/local/gmp-6.3.0
make --jobs=6
make install
echo
cd $SCRIPT_DIR/gcc_build
echo 'build cloog'
tar -xf cloog-0.18.1.tar.gz
mkdir objdir-cloog-0.18.1
cd objdir-cloog-0.18.1
../cloog-0.18.1/configure --prefix=$SCRIPT_DIR/local/cloog-0.18.1 --build="$BUILD_NAME" --target="$HOST_NAME" --host="$HOST_NAME" --enable-static --disable-shared --with-isl=$SCRIPT_DIR/local/isl-0.24 --with-gmp-prefix=$SCRIPT_DIR/local/gmp-6.3.0
make --jobs=6
make install
echo
cd $SCRIPT_DIR/gcc_build
echo 'build binutils'
tar -xf binutils-2.41.tar.xz
mkdir objdir-binutils-2.41-avr-gcc-"$MY_VERSION"
cd objdir-binutils-2.41-avr-gcc-"$MY_VERSION"
../binutils-2.41/configure --prefix=$SCRIPT_DIR/local/gcc-"$MY_VERSION"-avr --target=avr --enable-languages=c,c++ --build="$BUILD_NAME" --host="$HOST_NAME" --with-pkgversion='Built by ckormanyos/real-time-cpp' --disable-plugins --enable-static --disable-shared --disable-tls --disable-libada --disable-libssp --disable-nls --enable-mingw-wildcard --with-gnu-as --with-dwarf2 --with-isl=$SCRIPT_DIR/local/isl-0.24 --with-cloog=$SCRIPT_DIR/local/cloog-0.18.1 --with-gmp=$SCRIPT_DIR/local/gmp-6.3.0 --with-mpfr=$SCRIPT_DIR/local/mpfr-4.2.1 --with-mpc=$SCRIPT_DIR/local/mpc-1.3.1 --with-libiconv-prefix=$SCRIPT_DIR/local/libiconv-1.17 --with-zstd=$SCRIPT_DIR/local/zstd-1.5.5/lib --disable-werror
make --jobs=6
make install
echo
ls -la $SCRIPT_DIR/local/gcc-"$MY_VERSION"-avr/bin
ls -la $SCRIPT_DIR/local/gcc-"$MY_VERSION"-avr/bin/avr-ld*
result_binutils=$?
echo "result_binutils: " "$result_binutils"
echo
#
# Notes on patch of GCC-12.3.0
#
# How do you make the patch? (Example for gcc-12.3.0)
# diff -ru gcc-12.3.0/ gcc-12.3.0_new/ > avr-gcc-100-12.3.0_x86_64-w64-mingw32.patch
# How do you apply the patch? (Example for gcc-12.3.0)
# patch -p0 < avr-gcc-100-12.3.0_x86_64-w64-mingw32.patch
cd $SCRIPT_DIR/gcc_build
echo 'build gcc'
tar -xf gcc-"$MY_VERSION".tar.xz
if [[ "$MY_VERSION" == "12.3.0" ]]; then
patch -p0 < avr-gcc-100-"$MY_VERSION"_"$BUILD_NAME".patch
fi
mkdir objdir-gcc-"$MY_VERSION"-avr
cd objdir-gcc-"$MY_VERSION"-avr
../gcc-"$MY_VERSION"/configure --prefix=$SCRIPT_DIR/local/gcc-"$MY_VERSION"-avr --target=avr --enable-languages=c,c++ --build="$BUILD_NAME" --host="$HOST_NAME" --with-pkgversion='Built by ckormanyos/real-time-cpp' --disable-gcov --enable-static --disable-shared --disable-tls --disable-libada --disable-libssp --disable-nls --enable-mingw-wildcard --with-gnu-as --with-dwarf2 --with-isl=$SCRIPT_DIR/local/isl-0.24 --with-cloog=$SCRIPT_DIR/local/cloog-0.18.1 --with-gmp=$SCRIPT_DIR/local/gmp-6.3.0 --with-mpfr=$SCRIPT_DIR/local/mpfr-4.2.1 --with-mpc=$SCRIPT_DIR/local/mpc-1.3.1 --with-libiconv-prefix=$SCRIPT_DIR/local/libiconv-1.17 --with-zstd=$SCRIPT_DIR/local/zstd-1.5.5/lib
make --jobs=6
make install
echo
ls -la $SCRIPT_DIR/local/gcc-"$MY_VERSION"-avr/bin
ls -la $SCRIPT_DIR/local/gcc-"$MY_VERSION"-avr/bin/avr-gcc*
result_gcc=$?
echo "result_gcc: " "$result_gcc"
echo
cd $SCRIPT_DIR/gcc_build
echo 'clone and bootstrap avr-libc'
git clone -b main --depth 1 https://github.com/avrdudes/avr-libc.git avr-libc
cd avr-libc
./bootstrap
result_bootstrap=$?
echo "result_bootstrap: " "$result_bootstrap"
echo
cd $SCRIPT_DIR/gcc_build
echo 'add avr-gcc path'
PATH=$SCRIPT_DIR/local/gcc-"$MY_VERSION"-avr/bin:"$PATH"
export PATH
CC=""
export CC
echo
cd $SCRIPT_DIR/gcc_build
echo 'build avr-libc'
cd objdir-gcc-"$MY_VERSION"-avr
../avr-libc/configure --prefix=$SCRIPT_DIR/local/gcc-"$MY_VERSION"-avr --build="$BUILD_NAME" --host=avr --enable-static --disable-shared
make --jobs=8
make install
echo
result_total=$((result_system_gcc+result_binutils+result_gcc+result_bootstrap))
echo "result_total: " "$result_total"
echo
exit $result_total