]> git.zerfleddert.de Git - proxmark3-svn/blob - tools/install-gnuarm4.sh
Restore original inline help behavior as we've now separate fcts for -h/-m
[proxmark3-svn] / tools / install-gnuarm4.sh
1 #!/bin/bash
2
3 # Some things for you to configure
4 BINUTILS_VER="2.19.1a"
5 GCC_VER="4.3.3"
6 GDB_VER="6.8a"
7 NEWLIB_VER="1.17.0"
8 GMP_VER="4.2.4"
9 MPFR_VER="2.4.2"
10 INSIGHT_VER="6.8a"
11
12 # Where you want to install the tools
13 if [ "${1}" = "" ]; then
14 echo "Syntax: ${0} </installation/target/directory> [download & build directory (default ${PWD})]"
15 exit 1
16 else
17 DESTDIR="${1}"
18 fi
19
20 # Where do you want to build the tools. This is where the log files
21 # will be written (which you can monitor with 'tail' during compilation).
22 # You can delete this directory after everything is done.
23 if [ ! "${2}" = "" ]; then
24 SRCDIR="${2}"
25 else
26 SRCDIR="${PWD}"
27 fi
28 BUILDDIR=${SRCDIR}/build-gnuarm4
29
30 # Where to get each of the toolchain components
31 BINUTILS=http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.bz2
32 BINUTILS_TAR=binutils-${BINUTILS_VER}.tar.bz2
33 GCCCORE=http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-core-${GCC_VER}.tar.bz2
34 GCCCORE_TAR=gcc-core-${GCC_VER}.tar.bz2
35 GPP=http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-g++-${GCC_VER}.tar.bz2
36 GPP_TAR=gcc-g++-${GCC_VER}.tar.bz2
37 NEWLIB=ftp://sources.redhat.com/pub/newlib/newlib-${NEWLIB_VER}.tar.gz
38 NEWLIB_TAR=newlib-${NEWLIB_VER}.tar.gz
39 #INSIGHT=ftp://sourceware.org/pub/insight/releases/insight-${INSIGHT_VER}.tar.bz2
40 INSIGHT=http://mirrors.kernel.org/sources.redhat.com/insight/releases/insight-${INSIGHT_VER}.tar.bz2
41 INSIGHT_TAR=insight-${INSIGHT_VER}.tar.bz2
42 #INSIGHT=http://www.mirrorservice.org/sites/sources.redhat.com/pub/insight/releases/insight-${INSIGHT_VER}.tar.bz2
43 GDB=http://ftp.gnu.org/gnu/gdb/gdb-${GDB_VER}.tar.bz2
44 GDB_TAR=gdb-${GDB_VER}.tar.bz2
45 GMP=http://ftp.sunet.se/pub/gnu/gmp/gmp-${GMP_VER}.tar.bz2
46 GMP_TAR=gmp-${GMP_VER}.tar.bz2
47 MPFR=http://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VER}.tar.bz2
48 MPFR_TAR=mpfr-${MPFR_VER}.tar.bz2
49 GNU_KEYRING_GPG=gnu-keyring.gpg
50 GNU_KEYRING=ftp://ftp.gnu.org/gnu/${GNU_KEYRING_GPG}
51
52 # Common configuration options (i.e., things to pass to 'configure')
53 COMMON_CFG="--enable-interwork --target=arm-eabi --program-prefix=arm-none-eabi- --prefix=${DESTDIR} --disable-werror --enable-languages=c,c++ --enable-multilib --disable-shared"
54
55 # Extra configuration options for each toolchain component
56 BINUTILS_CFG=
57 GCCCORE_CFG="--disable-nls --disable-threads --with-gcc --with-gnu-ld --with-gnu-as --with-dwarf2 --with-newlib --with-headers=${BUILDDIR}/newlib-${NEWLIB_VER}/newlib/libc/include --disable-libssp --disable-libstdcxx-pch --disable-libmudflap --disable-libgomp -v"
58 NEWLIB_CFG=
59 INSIGHT_CFG=
60 GDB_CFG=
61
62 # Make flags
63 MAKEFLAGS="-j 4"
64
65 # wget options
66 # -nv: non-verbose but not too quiet (still print errors/warnings)
67 # -nc: no-clobber, do not download a file that already exists
68 # -t 0: retry indefinitely
69 # -a wget.log: append errors/warnings to wget.log file
70 # -c continue
71 #WGET_OPTS="-nv -nc -t 0 -a wget.log"
72 WGET_OPTS="-c -t 0"
73
74 # Compiler flags for compiling Newlib (-O2 is already hard-coded)
75 NEWLIB_FLAGS="-march=armv4t -mcpu=arm7tdmi -g"
76
77 # GPG options to avoid polluting the user's keyring
78 GPG_OPTS="--keyring ${GNU_KEYRING_GPG} --no-default-keyring --homedir ."
79
80 ############################################################################
81 # End of configuration section. You shouldn't have to modify anything below.
82 ############################################################################
83
84 if [[ "$USER" != "root" ]]; then
85 echo "*** Warning! Not running as root!"
86 echo "Installation may fail if you do not have appropriate permissions!"
87 fi
88
89 mkdir -p ${BUILDDIR}
90 cd ${SRCDIR}
91
92 if [[ -f all.downloaded ]]; then
93 echo Looks like all downloads are complete, skipping downloads
94 else
95 wget ${WGET_OPTS} ${GNU_KEYRING}
96
97 # TODO: guess it's better to have a function that "downloads, checks file-presence and signature, and returns true/false" whether the file is ok
98 # Function will check if file exists (otherwise try to download the file - if failed and file still doesn't exist, complain and exit the script)
99 # Check if signature file exists (otherwise download the signature file as well - if download fail, warn the user and return function)
100 # Check the signature. If failed, backup-by-renaming current files, redownload both file & signature, run the function body one more time - if still no success, warn and return from function
101
102 function download_lib {
103 echo Now downloading $1
104 wget ${WGET_OPTS} $2
105 }
106
107 function download_signed_lib {
108 download_lib $1 $2
109 wget -N ${WGET_OPTS} $2.sig
110 gpg $GPG_OPTS --verify $3.sig 2> /dev/null
111 if [[ $? != 0 ]]; then
112 echo "Failed signature check for:" $3.sig
113 exit 1
114 fi
115 }
116
117 # NOTE: If new downloads are added here, please see the IMPORTANT note below
118 download_signed_lib BINUTILS ${BINUTILS} ${BINUTILS_TAR} || exit 1
119 download_signed_lib GCC ${GCCCORE} ${GCCCORE_TAR} || exit 1
120 download_signed_lib G++ ${GPP} ${GPP_TAR} || exit 1
121 download_lib NEWLIB ${NEWLIB}
122 # TODO: signature/hash check
123 download_lib INSIGHT ${INSIGHT}
124 # TODO: signature/hash check
125 download_signed_lib GDB ${GDB} ${GDB_TAR} || exit 1
126 download_signed_lib GMP ${GMP} ${GMP_TAR} || exit 1
127 download_signed_lib MPFR ${MPFR} ${MPFR_TAR} || exit 1
128
129 # IMPORTANT: Here is the number of .tar. archives downloaded above. Please update if new .tar. are added to download list.
130 if [[ `ls -1 *.tar.bz2 *.tar.gz | wc -l` != 8 ]]; then
131 echo "Seems like not all prerequisite files downloaded... Exiting."
132 exit 1
133 else
134 touch all.downloaded
135 fi
136 fi
137
138 cd ${BUILDDIR}
139 if [[ -f binutils.built ]]; then
140 echo Looks like BINUTILS was already built.
141 else
142 echo Building BINUTILS...
143 tar -xjf ../`basename ${BINUTILS}`
144 echo ___________________ > make.log
145 echo Building binutils... >> make.log
146 cd `find . -maxdepth 1 -type d -name 'binutils*'`
147 mkdir gnuarm
148 cd gnuarm
149 ../configure ${COMMON_CFG} ${BINUTILS_CFG} >> ../../make.log 2>&1
150 make ${MAKEFLAGS} MAKEINFO=`which makeinfo` >> ../../make.log 2>&1
151 make install >> ../../make.log 2>&1
152 cd ../..
153 touch binutils.built
154 fi
155
156 echo ___________________ >> make.log
157 echo Adding ${DESTDIR}/bin to PATH >> make.log
158 export PATH; PATH=${DESTDIR}/bin:$PATH
159 echo ___________________ >> make.log
160
161 if [[ -f gcc.built ]]; then
162 echo Looks like GCC was already built.
163 else
164 echo Building GCC...
165 tar -xjf ../`basename ${GCCCORE}`
166 tar -xjf ../`basename ${GPP}`
167 tar -xjf ../`basename ${GMP}`
168 ln -s "${BUILDDIR}/gmp-${GMP_VER}" "${BUILDDIR}/gcc-${GCC_VER}/gmp"
169 tar -xjf ../`basename ${MPFR}`
170 ln -s "${BUILDDIR}/mpfr-${MPFR_VER}" "${BUILDDIR}/gcc-${GCC_VER}/mpfr"
171 tar -xzf ../`basename ${NEWLIB}`
172
173 echo ___________________ >> make.log
174
175 cat << EOF > gcc.patch
176 --- gcc-4.3.3.orig/gcc/config/arm/t-arm-elf
177 +++ gcc-4.3.3.mod/gcc/config/arm/t-arm-elf
178 @@ -33,8 +33,8 @@
179 # MULTILIB_DIRNAMES += fpu soft
180 # MULTILIB_EXCEPTIONS += *mthumb/*mhard-float*
181 #
182 -# MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork
183 -# MULTILIB_DIRNAMES += normal interwork
184 +MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork
185 +MULTILIB_DIRNAMES += normal interwork
186 #
187 # MULTILIB_OPTIONS += fno-leading-underscore/fleading-underscore
188 # MULTILIB_DIRNAMES += elf under
189 EOF
190
191 echo Patching GCC >> make.log
192 cd `find . -maxdepth 1 -type d -name 'gcc*'`
193 patch -p1 < ../gcc.patch
194 echo Building gcc... >> make.log
195 mkdir gnuarm
196 cd gnuarm
197 ../configure ${COMMON_CFG} ${GCCCORE_CFG} >> ../../make.log 2>&1
198 make ${MAKEFLAGS} all-gcc >> ../../make.log 2>&1
199 make install >> ../../make.log 2>&1
200 cd ../..
201 touch gcc.built
202 fi
203
204 if [[ -f newlib.built ]]; then
205 echo Looks like NEWLIB was already built.
206 else
207 echo Building NEWLIB...
208 echo ___________________ >> make.log
209 echo Building newlib... >> make.log
210 cd `find . -maxdepth 1 -type d -name 'newlib*'`
211 mkdir gnuarm
212 cd gnuarm
213 ../configure ${COMMON_CFG} ${NEWLIB_CFG} >> ../../make.log 2>&1
214
215 # This line adds our NEWLIB_CFLAGS to the configure.host file in the
216 # newlib subdirectory. This is the only way I could find to tell Newlib to
217 # compile itself with the -mmarch=armv4t and -mcpu=arm7tdmi flags.
218 # sed -i "/^newlib_cflags=/s/=.*\$/=\"${NEWLIB_FLAGS}\"/" ../newlib/configure.host
219 make ${MAKEFLAGS} >> ../../make.log 2>&1
220 make install >> ../../make.log 2>&1
221 cd ../..
222 touch newlib.built
223 fi
224
225 echo ___________________ >> make.log
226 echo "Now that newlib is built, second pass for GCC..." >> make.log
227 cd `find . -maxdepth 1 -type d -name 'gcc*'`
228 cd gnuarm
229 make ${MAKEFLAGS} >> ../../make.log 2>&1
230 make install >> ../../make.log 2>&1
231 cd ../..
232
233
234 if [[ -f insight.built ]]; then
235 echo Looks like INSIGHT was already built.
236 else
237 echo Building INSIGHT...
238 tar -xjf ../`basename ${INSIGHT}`
239 echo ___________________ >> make.log
240 echo Building insight... >> make.log
241 cd `find . -maxdepth 1 -type d -name 'insight*'`
242 mkdir gnuarm
243 cd gnuarm
244 ../configure ${COMMON_CFG} ${INSIGHT_CFG} >> ../../make.log 2>&1
245 make ${MAKEFLAGS} >> ../../make.log 2>&1
246 make install >> ../../make.log 2>&1
247 cd ../..
248 touch insight.built
249 fi
250
251 if [[ -f gdb.built ]]; then
252 echo Looks like GDB was already built.
253 else
254 echo Building GDB...
255 tar -xjf ../`basename ${GDB}`
256 echo ___________________ >> make.log
257 echo Building insight... >> make.log
258 cd `find . -maxdepth 1 -type d -name 'gdb*'`
259 mkdir gnuarm
260 cd gnuarm
261 ../configure ${COMMON_CFG} ${GDB_CFG} >> ../../make.log 2>&1
262 make ${MAKEFLAGS} >> ../../make.log 2>&1
263 make install >> ../../make.log 2>&1
264 cd ../..
265 touch gdb.built
266 fi
267
268 echo ___________________ >> make.log
269 echo Build complete. >> make.log
270
271 cd ${DESTDIR}
272 chmod -R a+rX .
273
274 echo Downloaded archives are in ${SRCDIR}
275 echo build driectory: ${BUILDDIR}
276 echo set environment variable ARMLIB to ${DESTDIR}/lib/gcc/arm-eabi/4.3.3/interwork for Makefile.linux
277 exit 0
Impressum, Datenschutz