Made more of unpack() common. Use wildcards to pick up different compression types.
[fw/cortex-toolchain] / summon-arm-toolchain
1 #!/bin/bash
2 # Written by Uwe Hermann <uwe@hermann-uwe.de>, released as public domain.
3 # Modified by Piotr Esden-Tempski <piotr@esden.net>, released as public domain.
4
5 #
6 # Requirements (example is for Debian, replace package names as needed):
7 #
8 # apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev \
9 # libmpc-dev autoconf texinfo build-essential
10 #
11
12 # Stop if any command fails
13 set -e
14
15 TARGET=arm-none-eabi            # Or: TARGET=arm-elf
16 PREFIX=${HOME}/arm-none-eabi    # Install location of your final toolchain
17 PARALLEL=                       # Or: PARALLEL="-j 5" for 4 CPUs
18 DARWIN_OPT_PATH=/opt/local      # Path in which MacPorts or Fink is installed
19
20 BINUTILS=binutils-2.20
21 GCC=gcc-4.5.1
22 NEWLIB=newlib-1.18.0
23 GDB=gdb-7.2
24 LIBCMSIS=v1.10-2
25 LIBSTM32=v3.0.0-1
26 LIBSTM32USB=v3.0.1-1
27 LIBOPENSTM32=master
28 LIBSTM32_EN=0
29 LIBOPENSTM32_EN=0
30
31 SUDO=
32 SUMMON_DIR=$(pwd)
33 SOURCES=${SUMMON_DIR}/sources
34 STAMPS=${SUMMON_DIR}/stamps
35
36 export PATH="${PREFIX}/bin:${PATH}"
37
38 GCCFLAGS=
39 GDBFLAGS=
40 BINUTILFLAGS=
41
42 # Fetch a versioned file from a URL
43 function fetch {
44     if [ ! -e ${STAMPS}/$1.fetch ]; then
45         echo "Downloading $1 sources..."
46         wget -c --no-passive-ftp $2
47         touch ${STAMPS}/$1.fetch
48     fi
49 }
50
51 # Log a message out to the console
52 function log {
53     echo "******************************************************************"
54     echo "* $*"
55     echo "******************************************************************"
56 }
57
58 # Unpack an archive
59 function unpack {
60     log Unpacking $*
61     # Use 'auto' mode decompression.  Replace with a switch if tar doesn't support -a
62     tar xvaf ${SOURCES}/$1.tar.*
63 }
64
65 # Install a build
66 function install {
67     log $1
68     ${SUDO} make ${PARALLEL} $2 $3 $4 $5 $6 $7 $8
69 }
70
71 case "$(uname)" in
72         Linux)
73         echo "Found Linux OS."
74         ;;
75         Darwin)
76         echo "Found Darwin OS."
77         GCCFLAGS="${GCCFLAGS} \
78                   --with-gmp=${DARWIN_OPT_PATH} \
79                   --with-mpfr=${DARWIN_OPT_PATH} \
80                   --with-mpc=${DARWIN_OPT_PATH} \
81                   -with-libiconv-prefix=${DARWIN_OPT_PATH}"
82         ;;
83         *)
84         echo "Found unknown OS. Aborting!"
85         exit 1
86         ;;
87 esac
88
89 mkdir -p ${STAMPS} ${SOURCES}
90
91 cd ${SOURCES}
92
93 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
94 fetch ${GCC} http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
95 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
96 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
97
98 if [ ${LIBSTM32_EN} != 0 ]; then
99 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
100         echo "Cloning libcmsis sources..."
101         git clone git://git.open-bldc.org/libcmsis.git
102         cd libcmsis
103         git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
104             bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
105         cd ..
106         rm -rf libcmsis
107 fi
108
109 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
110         echo "Cloning libstm32 sources..."
111         git clone git://git.open-bldc.org/libstm32.git
112         cd libstm32
113         git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
114             bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
115         cd ..
116         rm -rf libstm32
117 fi
118
119 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
120         echo "Cloning libstm32usb sources..."
121         git clone git://git.open-bldc.org/libstm32usb.git
122         cd libstm32usb
123         git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
124             bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
125         cd ..
126         rm -rf libstm32usb
127 fi
128 fi
129
130 if [ ${LIBOPENSTM32_EN} != 0 ]; then
131 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
132         echo "Cloning libopenstm32 sources..."
133         git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
134         cd libopenstm32
135         git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
136             bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
137         cd ..
138         rm -rf libopenstm32
139 fi
140 fi
141
142 cd ${SUMMON_DIR}
143
144 if [ ! -e build ]; then
145     mkdir build
146 fi
147
148 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
149     unpack ${BINUTILS}
150     cd build
151     log "Configuring ${BINUTILS}"
152     ../${BINUTILS}/configure --target=${TARGET} \
153                            --prefix=${PREFIX} \
154                            --enable-interwork \
155                            --enable-multilib \
156                            --with-gnu-as \
157                            --with-gnu-ld \
158                            --disable-nls \
159                            --disable-werror \
160                            ${BINUTILFLAGS}
161     log "Building ${BINUTILS}"
162     make ${PARALLEL}
163     install ${BINUTILS} install
164     cd ..
165     log "Cleaning up ${BINUTILS}"
166     touch ${STAMPS}/${BINUTILS}.build
167     rm -rf build/* ${BINUTILS}
168 fi
169
170 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
171     unpack ${GCC} boot
172     cd build
173     log "Configuring ${GCC}-boot"
174     ../${GCC}/configure --target=${TARGET} \
175                       --prefix=${PREFIX} \
176                       --enable-interwork \
177                       --enable-multilib \
178                       --enable-languages="c" \
179                       --with-newlib \
180                       --without-headers \
181                       --disable-shared \
182                       --with-gnu-as \
183                       --with-gnu-ld \
184                       --disable-nls \
185                       --disable-werror \
186                       ${GCCFLAGS}
187     log "Building ${GCC}-boot"
188     make ${PARALLEL} all-gcc
189     install ${GCC}-boot install-gcc
190     cd ..
191     log "Cleaning up ${GCC}-boot"
192     touch ${STAMPS}/${GCC}-boot.build
193     rm -rf build/* ${GCC}
194 fi
195
196 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
197     unpack ${NEWLIB}
198     cd build
199     log "Configuring ${NEWLIB}"
200     ../${NEWLIB}/configure --target=${TARGET} \
201                          --prefix=${PREFIX} \
202                          --enable-interwork \
203                          --enable-multilib \
204                          --with-gnu-as \
205                          --with-gnu-ld \
206                          --disable-nls \
207                          --disable-werror \
208                          --disable-newlib-supplied-syscalls
209     log "Building ${NEWLIB}"
210     make ${PARALLEL}
211     install ${NEWLIB} install
212     cd ..
213     log "Cleaning up ${NEWLIB}"
214     touch ${STAMPS}/${NEWLIB}.build
215     rm -rf build/* ${NEWLIB}
216 fi
217
218 # Yes, you need to build gcc again!
219 if [ ! -e ${STAMPS}/${GCC}.build ]; then
220     unpack ${GCC}
221     cd build
222     log "Configuring ${GCC}"
223     ../${GCC}/configure --target=${TARGET} \
224                       --prefix=${PREFIX} \
225                       --enable-interwork \
226                       --enable-multilib \
227                       --enable-languages="c,c++" \
228                       --with-newlib \
229                       --disable-shared \
230                       --with-gnu-as \
231                       --with-gnu-ld \
232                       --disable-nls \
233                       --disable-werror \
234                      ${GCCFLAGS}
235     log "Building ${GCC}"
236     make ${PARALLEL}
237     install ${GCC} install
238     cd ..
239     log "Cleaning up ${GCC}"
240     touch ${STAMPS}/${GCC}.build
241     rm -rf build/* ${GCC}
242 fi
243
244 if [ ! -e ${STAMPS}/${GDB}.build ]; then
245     unpack ${GDB}
246     cd build
247     log "Configuring ${GDB}"
248     ../${GDB}/configure --target=${TARGET} \
249                       --prefix=${PREFIX} \
250                       --enable-interwork \
251                       --enable-multilib \
252                       --disable-werror \
253                       ${GDBFLAGS}
254     log "Building ${GDB}"
255     make ${PARALLEL}
256     install ${GDB} install
257     cd ..
258     log "Cleaning up ${GDB}"
259     touch ${STAMPS}/${GDB}.build
260     rm -rf build/* ${GDB}
261 fi
262
263 if [ ${LIBSTM32_EN} != 0 ]; then
264 if [ ! -e .libcmsis-${LIBCMSIS}.build ]; then
265     unpack libcmsis-${LIBCMSIS}
266     cd libcmsis-${LIBCMSIS}
267     log "Building libcmsis-${LIBCMSIS}"
268     make arch_prefix=${TARGET} prefix=${PREFIX}
269     install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
270     cd ..
271     log "Cleaning up libcmsis-${LIBCMSIS}"
272     touch .libcmsis-${LIBCMSIS}.build
273     rm -rf libcmsis-${LIBCMSIS}
274 fi
275
276 if [ ! -e .libstm32-${LIBSTM32}.build ]; then
277     unpack libstm32-${LIBSTM32}
278     cd libstm32-${LIBSTM32}
279     log "Building libstm32-${LIBSTM32}"
280     make arch_prefix=${TARGET} prefix=${PREFIX}
281     install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
282     cd ..
283     log "Cleaning up libstm32-${LIBSTM32}"
284     touch .libstm32-${LIBSTM32}.build
285     rm -rf libstm32-${LIBSTM32}
286 fi
287
288 if [ ! -e .libstm32usb-${LIBSTM32USB}.build ]; then
289     unpack libstm32usb-${LIBSTM32USB}
290     cd libstm32usb-${LIBSTM32USB}
291     log "Building libstm32usb-${LIBSTM32USB}"
292     make arch_prefix=${TARGET} prefix=${PREFIX}
293     install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
294     cd ..
295     log "Cleaning up libstm32usb-${LIBSTM32USB}"
296     touch .libstm32usb-${LIBSTM32USB}.build
297     rm -rf libstm32usb-${LIBSTM32USB}
298 fi
299 fi
300
301 if [ $LIBOPENSTM32_EN != 0 ]; then
302     unpack libopenstm32-${LIBOPENSTM32}
303     cd libopenstm32-${LIBOPENSTM32}
304     log "Building libopenstm32-${LIBOPENSTM32}"
305     make PREFIX=${TARGET} DESTDIR=${PREFIX}
306     install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
307     cd ..
308     log "Cleaning up libopenstm32-${LIBOPENSTM32}"
309     touch .libopenstm32-${LIBOPENSTM32}.build
310     rm -rf libopenstm32-${LIBOPENSTM32}
311 fi