Home | History | Annotate | Download | only in ppc-cross
      1 #!/bin/bash
      2 
      3 ############################################################################
      4 #
      5 # Script for generating a PowerPC cross compiler using crosstool.
      6 #
      7 # Copyright (C) 2009 Bart Van Assche <bvanassche (at] acm.org>.
      8 #
      9 # This program is free software; you can redistribute it and/or
     10 # modify it under the terms of the GNU General Public License
     11 # as published by the Free Software Foundation, version 2
     12 # of the License.
     13 #
     14 # This program is distributed in the hope that it will be useful,
     15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     17 # GNU General Public License for more details.
     18 #
     19 ############################################################################
     20 
     21 #########################
     22 # Function definitions  #
     23 #########################
     24 
     25 # Print an error message and exit.
     26 abort() {
     27   echo "build failed: $@"
     28   exit 1
     29 }
     30 
     31 # Print command-line help.
     32 usage() {
     33   cat <<EOF
     34 Usage: $0 [-h] [-t crosstools-directory] [gcc-version glibc-version]
     35 EOF
     36 }
     37 
     38 # Extract and run crosstool for the specified gcc and glibc versions.
     39 generate_cross_compiler() {
     40   export GCC_DIR=gcc-$1
     41   export GLIBC_DIR=glibc-$2
     42 
     43   export GLIBCTHREADS_FILENAME=glibc-linuxthreads-$2
     44   # glibc-crypt is only needed for glibc 2.1.x and earlier glibc versions.
     45   unset GLIBCCRYPT_FILENAME
     46   if [ "${2#2.1.}" != "${2}" ]; then
     47     GLIBCCRYPT_FILENAME=glibc-crypt-2.1
     48   fi
     49   export GLIBCCRYPT_FILENAME
     50   unset GCC_CORE_DIR
     51   if [ "${1#4.}" != "${1}" -a "${2#2.[12].}" != "$2" ]; then
     52     # Use gcc 2.95.3 for compiling glibc 2.1.* and glibc 2.2.*.
     53     GCC_CORE_DIR=gcc-2.95.3
     54   else
     55     GCC_CORE_DIR=gcc-3.3.6
     56   fi
     57   export GCC_CORE_DIR
     58 
     59   export GCC_EXTRA_CONFIG="--disable-linux-futex --disable-mudflap --disable-nls"
     60   #GLIBC_ADDON_OPTIONS=
     61 
     62   # gcc 4.x aborts with a syntax error on glibc's inline functions if you do
     63   # not specify -fgnu89-inline.
     64   #if [ "${1#4.}" != "${1}" ]; then
     65   #  export TARGET_FLAGS="$TARGET_FLAGS -fgnu89-inline"
     66   #fi
     67 
     68   if ! /bin/rm -rf $RESULT_TOP/${GCC_DIR}-${GLIBC_DIR}; then
     69     abort "Need write permission in $RESULT_TOP/${GCC_DIR}-${GLIBC_DIR}"
     70   fi
     71   if ! /bin/mkdir -p $RESULT_TOP/$GCC_DIR-$GLIBC_DIR/$TARGET; then
     72     abort "Need write permission in $RESULT_TOP/${GCC_DIR}-${GLIBC_DIR}/$TARGET"
     73   fi
     74 
     75   /bin/rm -rf $CROSSTOOL_FOLDER
     76   if [ ! -e $TARBALLS_DIR/crosstool-${CROSSTOOL_VERSION}.tar.gz ]; then
     77     (
     78       if cd $TARBALLS_DIR; then
     79         wget -q -nc "http://kegel.com/crosstool/crosstool-${CROSSTOOL_VERSION}.tar.gz"
     80       fi
     81     )
     82   fi
     83   /bin/tar -zxf $TARBALLS_DIR/crosstool-${CROSSTOOL_VERSION}.tar.gz
     84   /bin/tar -C patches -cf - . | /bin/tar -C $CROSSTOOL_FOLDER/patches -xf -
     85   (
     86     cd $CROSSTOOL_FOLDER
     87     for f in ../crosstool-patches/*
     88     do
     89       patch -p1 -f < "$f" || exit $?
     90     done
     91     ./all.sh --notest
     92   )
     93   # /bin/rm -rf $CROSSTOOL_FOLDER
     94 }
     95 
     96 
     97 #########################
     98 # Argument processing   #
     99 #########################
    100 
    101 if [ "$SHELL" = "/bin/tcsh" ]; then
    102   abort "tcsh is not supported."
    103 fi
    104 
    105 set -- $(/usr/bin/getopt ht: "$@")
    106 while [ "${1#-}" != "${1}" ]; do
    107   case "$1" in
    108     -h) usage; exit 1;;
    109     -t) result_top="$2"; shift; shift;;
    110     --) shift;;
    111   esac
    112 done
    113 
    114 #########################
    115 # Settings              #
    116 #########################
    117 
    118 set -e # Exit immediately if a simple command fails.
    119 set -x # Enable echo mode.
    120 
    121 # Variables that are ignored by crosstool.
    122 
    123 CROSSTOOL_VERSION=0.43
    124 CROSSTOOL_FOLDER=$PWD/crosstool-$CROSSTOOL_VERSION
    125 KERNEL_VERSION=2.6.22
    126 export LC_ALL=C
    127 
    128 
    129 # Variables that are used by the crosstool script as input.
    130 
    131 # Directory where cross-compilation tools will be installed.
    132 export RESULT_TOP=${result_top:-$HOME/x86_64-ppc}
    133 # Directory where the tool tar files can be found.
    134 export TARBALLS_DIR=$HOME/software/downloads
    135 # Target architecture: Pentium CPU, Linux OS.
    136 export TARGET=powerpc-linux
    137 # Compilation flags for target tools such as glibc.
    138 export TARGET_CFLAGS="-O"
    139 # Binutils version.
    140 export BINUTILS_DIR=binutils-2.16.1
    141 # Languages that must be supported by the gcc cross-compiler.
    142 export GCC_LANGUAGES="c,c++"
    143 # GDB version.
    144 export GDB_DIR=gdb-6.8
    145 # Linux kernel version.
    146 export LINUX_DIR=linux-$KERNEL_VERSION
    147 # Linux kernel config.
    148 export KERNELCONFIG=$PWD/kernel-config/$KERNEL_VERSION/.config
    149 # Make flags
    150 export PARALLELMFLAGS="-s -j3"
    151 
    152 ##############################
    153 # Cross-compiler generation. #
    154 ##############################
    155 
    156 if ! /bin/mkdir -p $RESULT_TOP; then
    157   abort "You need write permission in $RESULT_TOP"
    158 fi
    159 
    160 if [ "$#" = 0 ]; then
    161   generate_cross_compiler 4.1.1  2.3.6
    162 elif [ "$#" = 2 ]; then
    163   generate_cross_compiler "$1" "$2"
    164 else
    165   usage
    166   abort "Wrong number of arguments."
    167 fi
    168