tart: match new coding style.
[tart.git] / crosstools.sh
blob5b5df70b621ff2a3fe9bcd938fce930d1cb2a4f7
1 #!/bin/sh
3 # The download a file function.
4 download()
6 local url=$1
8 # Download the file.
9 wget --progress=dot -c -P tools $url 2>&1 | grep "%" | sed -u -e "s,\.,,g" -e "s,\,,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
11 # Delete everything and show done.
12 echo -ne "\b\b\b\b"
13 echo " [DONE]"
16 # Export some common stuff - the defaults, if they aren't in the arguments.
17 test ! -n "$PREFIX" && PREFIX=$(readlink -f ./tools)
19 # The TARGET.
20 # Currently allowed values: bcm2835 [RPi]
21 # TODO: probably spit out error message.
22 test ! -n "$TARGET" && TARGET=bcm2835
24 # Parse command line options for prefix & target.
25 while getopts "p:t:" optname
27 case "$optname" in
28 "p")
29 PREFIX=$OPTARG
31 "t")
32 TARGET=$OPTARG
34 esac
35 done
37 if test z"$TARGET" = z"bcm2835"
38 then
39 TARGET=arm-none-eabi
42 # Make the build directory.
43 mkdir -p tools
45 # Get the tools.
47 # Binutils.
48 echo -n " [WGET] tools/binutils-2.23.2.tar.bz2, "
49 download "http://ftp.gnu.org/gnu/binutils/binutils-2.23.2.tar.bz2"
51 # GCC.
52 echo -n " [WGET] tools/gcc-4.8.1.tar.bz2, "
53 download "http://ftp.gnu.org/gnu/gcc/gcc-4.8.1/gcc-4.8.1.tar.bz2"
55 # Untar them.
57 # Binutils.
58 echo " [UNTAR] tools/binutils-2.23.2.tar.bz2"
59 tar -xf tools/binutils-2.23.2.tar.bz2 -C tools >/dev/null
60 rm tools/binutils-2.23.2.tar.bz2
62 # GCC.
63 echo " [UNTAR] tools/gcc-4.8.1.tar.bz2"
64 tar -xf tools/gcc-4.8.1.tar.bz2 -C tools >/dev/null
65 rm tools/gcc-4.8.1.tar.bz2
67 # Build the tools.
69 # Binutils.
70 mkdir -p tools/build-binutils
72 # Configure.
73 echo " [BINUT] Configuring"
74 cd tools/build-binutils && ../binutils-2.23.2/configure --target=$TARGET --prefix=$PREFIX --disable-nls
75 cd ../../
77 # Compile.
78 echo " [BINUT] Compiling"
79 make -C tools/build-binutils all
81 # Install.
82 echo " [BINUT] Installing"
83 make -C tools/build-binutils install
85 # Clean.
86 echo " [BINUT] Cleaning"
87 rm -rf tools/build-binutils tools/binutils-2.23.2
89 # GCC.
90 mkdir -p tools/build-gcc
92 # Configure.
93 echo " [GCC] Configuring"
94 export PATH=$PATH:$PREFIX/bin
95 cd tools/build-gcc && ../gcc-4.8.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c --without-headers --with-gnu-as --with-gnu-ld
96 cd ../../
98 export LD_FOR_TARGET=$PREFIX/bin/$TARGET-elf-ld
99 export OBJDUMP_FOR_TARGET=$PREFIX/bin/$TARGET-elf-objdump
100 export NM_FOR_TARGET=$PREFIX/bin/$TARGET-elf-nm
101 export RANLIB_FOR_TARGET=$PREFIX/bin/$TARGET-elf-ranlib
102 export READELF_FOR_TARGET=$PREFIX/bin/$TARGET-elf-readelf
103 export STRIP_FOR_TARGET=$PREFIX/bin/$TARGET-elf-strip
104 export AS_FOR_TARGET=$PREFIX/bin/$TARGET-elf-as
106 # Compile.
107 echo " [GCC] Compiling"
108 make -C tools/build-gcc all-gcc
110 # Install.
111 echo " [GCC] Installing"
112 make -C tools/build-gcc install-gcc
114 # Compile libgcc.
115 echo " [LIBGCC] Compiling"
116 make -C tools/build-gcc all-target-libgcc CFLAGS_FOR_TARGET="-g -O2"
118 # Install
119 echo " [LIBGCC] Installing"
120 make -C tools/build-gcc install-target-libgcc
122 # Clean.
123 echo " [GCC] Cleaning"
124 rm -rf tools/build-gcc tools/gcc-4.8.1