Merging with newer gcc4mbed for better compilability
[clinton/Smoothieware.git] / gcc4mbed / external / gcc / prep.sh
1 #! /usr/bin/env bash
2 # Copyright 2011 Adam Green (http://mbed.org/users/AdamGreen/)
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # Simple script to setup Code Sourcery files to build on Mac OS X
17
18 # TODO: Will most likely need to change this for each build of tools.
19 # Expected location of files based on Code Sourcery script
20 src_path=/scratch/janisjo/arm-eabi-lite/src
21
22 # TODO: Will need to be customized for newer builds.
23 # Name of the tarball archive to be used for building the toolchain.
24 archive_name=arm-2011.03-42-arm-none-eabi.src.tar.bz2
25 archive_url=https://sourcery.mentor.com/sgpp/lite/arm/portal/package7812/public/arm-none-eabi/$archive_name
26 archive_md5=7c302162ec813d039b8388bd7d2b4176
27
28 # This script expects to be sitting in the same directory as the main archive
29 # from Code Sourcery so change into the directory before attempting to
30 # perform the extraction of the source code
31 SCRIPT_PATH=$0
32 SCRIPT_PATH=${SCRIPT_PATH%/*}
33 cd $SCRIPT_PATH
34
35 # Pull the tarball down from the Mentor Graphics/Code Sourcery website.
36 echo Downloading $archive_url
37 curl -LO $archive_url
38
39 echo Validating the MD5 signature on $archive_name
40 archive_match=`md5 -q $archive_name | grep -c $archive_md5`
41 if [ "$archive_match" != "1" ] ; then
42 echo $archive_name failed MD5 signature check.
43 exit 1
44 fi
45
46 # Extract the various tool sources from the provided archive
47 echo Extracting $archive_name
48 tar xf $archive_name
49 archive_out=${archive_name%%.src.tar.bz2}
50
51 # Now extract the sources for each tool from their respective archive
52 echo Extracting sources from $archive_out
53 pushd $archive_out >/dev/null
54 mkdir -p $src_path
55 for archive in `ls *.tar.bz2` ; do
56 echo Extracting $archive
57 tar -xf $archive -C $src_path
58 done
59
60 # Find the build bash script
61 scripts=(`ls arm-*-arm-none-eabi.sh`)
62 if [ "${#scripts[*]}" != "1" ] ; then
63 echo This script only expects to find one build script in the package
64 echo Actually found ${scripts[*]}
65 exit 1
66 fi
67 script=${scripts[0]}
68
69 # Modify the script to skip portions not needed for Mac OS and
70 # replace the i686-pc-linux-gnu as appropriate for the Mac GCC toolchain
71 echo Creating modified bash build script appropriate for the Mac
72 sed -f ../build.sed $script >build.sh
73 chmod +x build.sh
74
75 # The build of GCC requires libgcc in /usr/lib without a version number so create a symbolic link.
76 if [[ ! (-a /usr/lib/libgcc_s.dylib) ]]; then
77 echo Creating symbolic link for /usr/lib/libgcc_s.dylib
78 sudo ln -s /usr/lib/libgcc_s.10.5.dylib /usr/lib/libgcc_s.dylib
79 fi
80
81 echo Apply patches to the source code.
82 cp ../src.patch $src_path
83 cd $src_path
84 patch -p5 -N <src.patch
85
86 echo You should now be able to run the $archive_out/build.sh script to kick off the build.
87
88 popd >/dev/null