Qball's Weblog
Compile a cross-compiler for microblaze xilinx
The following script builds a cross-compiler for microblaze-xilinx. Took some time to get it ‘right’. Subtle things like gcc refusing (with very strange errors) to build inside it own source directory, made it take a while.
Hope somebody can use it.
https://github.com/DaveDavenport/CrossCompilerGCCScript/blob/master/gcc_cross_compiler.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 |
#!/bin/bash ## # Script to build GCC for microblaze. # Written by Martijn Koedam (m.l.p.j.koedam@tue.nl) # # Current version is testing on ubuntu 11.04, 11.10 and 12.04 ## TARGET=microblaze-xilinx-elf PROGRAM_PREFIX=mb- BUILD_DIR=build INSTALL_DIR=$PWD/install CORES=8 GCC_URL=ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.7.0/gcc-4.7.0.tar.bz2 NEWLIB_URL=ftp://sources.redhat.com/pub/newlib/newlib-1.20.0.tar.gz BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.bz2 GCC_FILE=$(basename $GCC_URL) NEWLIB_FILE=$(basename $NEWLIB_URL) BINUTILS_FILE=$(basename $BINUTILS_URL) GCC=${GCC_FILE%.tar.*} BINUTILS=${BINUTILS_FILE%.tar.*} NEWLIB=${NEWLIB_FILE%.tar.*} # target # needed for newlib, because of non-standard PROGRAM_PREFIX. export CC_FOR_TARGET="$PROGRAM_PREFIX"gcc export CXX_FOR_TARGET="$PROGRAM_PREFIX"g++ export GCC_FOR_TARGET="$PROGRAM_PREFIX"gcc export AR_FOR_TARGET="$PROGRAM_PREFIX"ar export AS_FOR_TARGET="$PROGRAM_PREFIX"as export LD_FOR_TARGET="$PROGRAM_PREFIX"ld export NM_FOR_TARGET="$PROGRAM_PREFIX"nm export RANLIB_FOR_TARGET="$PROGRAM_PREFIX"ranlib export STRIP_FOR_TARGET="$PROGRAM_PREFIX"strip function download() { if [ ! -f $1 ] then wget -O $1 $2 else echo "$1 exists" fi } function extract() { if [ ! -d "$BUILD_DIR/$2" ] then tar xf $1 -C $BUILD_DIR fi if [ ! -d "$BUILD_DIR/$2" ] then echo "Failed to extract $2 to $1" exit 1 fi } function build() { pushd $BUILD_DIR pushd $1 if [ ! -d "build" ] then mkdir "build" pushd "build" else pushd "build" make distclean fi ../configure --target=$TARGET --prefix=/opt/mb-gcc/ --program-prefix=$PROGRAM_PREFIX --prefix=$INSTALL_DIR $2 if [ $? != ] then echo "Failed to configure" exit 1; fi env make -j"$CORES" all$3 if [ $? != ] then echo "Failed to build" exit 1; fi make install$3 if [ $? != ] then echo "Failed to install" exit 1; fi popd popd popd } function gcc_dependencies() { pushd $BUILD_DIR pushd $1 ./contrib/download_prerequisites popd popd } if [ ! -d $BUILD_DIR ] then mkdir $BUILD_DIR fi if [ ! -d $INSTALL_DIR ] then mkdir $INSTALL_DIR fi #download files. echo "Downloading" download "$GCC_FILE" "$GCC_URL" download "$NEWLIB_FILE" "$NEWLIB_URL" download "$BINUTILS_FILE" "$BINUTILS_URL" echo "Building binutils" extract "$BINUTILS_FILE" "$BINUTILS" build $BINUTILS "" "" # put results into PATH. export PATH=$PATH:$INSTALL_DIR/bin/ echo "Building gcc-stage1" extract "$GCC_FILE" "$GCC" gcc_dependencies "$GCC" build $GCC "--enable-languages=c --disable-nls --without-headers --disable-multilib --disable-libssp --with-newlib" "-host" echo "Building newlib" extract "$NEWLIB_FILE" "$NEWLIB" build $NEWLIB "" "" echo "Building gcc,g++ stage2" extract "$GCC_FILE" "$GCC" build $GCC "--enable-languages=c,c++ --disable-nls --without-headers --disable-multilib --disable-libssp --with-newlib" "" |