-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_gcc.sh
239 lines (203 loc) · 6.95 KB
/
build_gcc.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
#! bash
# build_gcc.sh - A script for building gnu gcc compiler tools
#
# Copyright (c) 2016 Elisha Kendagor [email protected]
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
gcc_src=/usr/local/src/gcc
gcc_build=~/build/gcc
ret_dir=$PWD
install=false
sync=false
ld_conf_src=/etc/ld.so.conf.d/x86_64-linux-gnu.conf
prefix_override=false
while [ $# -gt 0 ]; do
case $1 in
-i | --install)
install=true
sync=true
;;
-s | --sync)
sync=true
;;
-p | --prefix)
prefix_override=true
;;
esac
shift
done
checkfail() {
if [ $1 -gt 0 ]; then
echo $2
exit 1
fi
return
}
if [ "$install" = "true" ]; then
bison --version
if [ $? -gt 0 ]; then
sudo apt install bison -y
checkfail $? "Install svn failed"
fi
perl --version
if [ $? -gt 0 ]; then
sudo apt install perl -y
checkfail $? "Install perl failed"
fi
make --version
if [ $? -gt 0 ]; then
sudo apt install make -y
checkfail $? "Install make failed"
fi
sudo apt install binutils -y
checkfail $? "Install binutils failed"
bzip2 --version
if [ $? -gt 0 ]; then
sudo apt install bzip2 -y
checkfail $? "Install bzip2 failed"
fi
gzip --version
if [ $? -gt 0 ]; then
sudo apt install gzip -y
checkfail $? "Install gzip failed"
fi
tar --version
if [ $? -gt 0 ]; then
sudo apt install tar -y
checkfail $? "Install tar failed"
fi
gawk --version
if [ $? -gt 0 ]; then
sudo apt install gawk -y
checkfail $? "Install gawk failed"
fi
gettext --version
if [ $? -gt 0 ]; then
sudo apt install gettext -y
checkfail $? "Install gettext failed"
fi
sudo apt install libc6-dev -y
checkfail $? "Install libc6-dev failed"
sudo apt install libgmp-dev -y
checkfail $? "Install libgmp-dev failed"
sudo apt install libmpfr-dev -y
checkfail $? "Install libmpfr-dev failed"
sudo apt install libmpc-dev -y
checkfail $? "Install libmpc-dev failed"
sudo apt install libisl-dev -y
checkfail $? "Install libisl-dev failed"
flex --version
if [ $? -gt 0 ]; then
sudo apt install flex -y
checkfail $? "Install flex failed"
fi
fi
if [ "$sync" = "true" ]; then
ls -d $gcc_src
if [ $? -gt 0 ]; then
sudo git clone https://gcc.gnu.org/git/gcc.git $gcc_src
checkfail $? "git clone failed"
else
cd $gcc_src
sudo git pull
checkfail $? "git pull failed"
fi
fi
ls -d $gcc_src
checkfail $? "gcc source not found: $gcc_src"
if [ -f $gcc_build ]; then
sudo rm -r $gcc_build
checkfail $? "Failed to delete $gcc_build"
fi
mkdir -p $gcc_build
checkfail $? "Could not create $gcc_build"
cd $gcc_build
checkfail $? "Could not cd $gcc_build"
if [ "$prefix_override" = "true" ]; then
new_prefix="--prefix=/usr/bin"
fi
# $gcc_src/configure $new_prefix \
# --enable-languages=c,c++ \
# --enable-shared \
# --enable-host-shared \
# --with-gmp \
# --with-mpfr \
# --with-mpc \
# --with-isl \
# --enable-multilib \
# --disable-werror \
# --disable-bootstrap
$gcc_src/configure $new_prefix \
--enable-languages=c,c++ \
--enable-shared \
--enable-host-shared \
--with-gmp \
--with-mpfr \
--with-mpc \
--with-isl \
--disable-werror \
--disable-bootstrap \
--disable-multilib \
CFLAGS="-fPIE" \
CXXFLAGS="-fPIE" \
LDFLAGS="-pie"
checkfail $? "\'configure\' failed"
# make -j $(nproc) bootstrap-lean
make -j $(nproc)
checkfail $? "\'make\' failed"
sudo make install
checkfail $? "\'make install\' failed"
# grep --regexp="^# Multiarch support$" $ld_conf_src
# checkfail $? "ldconfig cfg file doesn\'t have the expected first line"
# grep --regexp="^/usr/local/lib64$" $ld_conf_src
# if [ $? -gt 0 ]; then
# sudo sed -i "/^# Multiarch support$/a/usr/local/lib64" $ld_conf_src
# fi
sudo ldconfig
checkfail $? "\'ldconfig\' failed"
sudo mv /usr/local/bin/gcc /usr/local/bin/gcc-dev
sudo mv /usr/local/bin/g++ /usr/local/bin/g++-dev
sudo mv /usr/local/bin/c++ /usr/local/bin/c++-dev
sudo mv /usr/local/bin/cpp /usr/local/bin/cpp-dev
echo -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
echo --- build complete. Optional step:
echo sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 40 --slave /usr/bin/c++ c++ /usr/bin/g++ --slave /usr/bin/cpp cpp /usr/bin/gcc-cpp
echo sudo update-alternatives --install /usr/bin/cc cc /usr/local/bin/gcc-dev 60 --slave /usr/bin/c++ c++ /usr/local/bin/g++-dev --slave /usr/bin/cpp cpp /usr/local/bin/cpp-dev
echo -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
echo Typical output after build in case you missed it:
echo ----------------------------------------------------------------------
echo Libraries have been installed in:
echo /usr/local/lib/../lib64
echo
echo If you ever happen to want to link against installed libraries
echo in a given directory, LIBDIR, you must either use libtool, and
echo specify the full pathname of the library, or use the '-LLIBDIR'
echo flag during linking and do at least one of the following:
echo - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
echo during execution
echo - add LIBDIR to the 'LD_RUN_PATH' environment variable
echo during linking
echo - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
echo - have your system administrator add LIBDIR to '/etc/ld.so.conf'
echo
echo See any operating system documentation about shared libraries for
echo more information, such as the 'ld(1)' and 'ld.so(8)' manual pages.
echo ----------------------------------------------------------------------
cd $ret_dir