66b75c06f327108da7fc714a1dc50d913d5ca8f4
[clinton/Smoothieware.git] / gcc4mbed / mac_install
1 #! /usr/bin/env bash
2 # Copyright 2012 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
17 # Logs the command to be run and then executes the command while logging the results.
18 RunAndLog () {
19 echo `date` Executing $@>>$LOGFILE
20 $@ 1>>$LOGFILE 2>$ERRORFILE
21 if [ "$?" != "0" ] ; then
22 cat $ERRORFILE >>$LOGFILE
23 echo `date` Failure forced early exit>>$LOGFILE
24 cat $LOGFILE
25 rm -f $ERRORFILE
26 popd >/dev/null
27 read -n 1 -sp "Press any key to continue..." dummy ; echo
28 exit 1
29 fi
30 }
31
32
33 # Setup script variables.
34 ROOTDIR=$0
35 ROOTDIR=${ROOTDIR%/*}
36 pushd $ROOTDIR
37 ROOTDIR=$PWD
38 LOGFILE=$ROOTDIR/mac_install.log
39 ERRORFILE=$ROOTDIR/mac_install.err
40 GCC4ARM_VERSION=gcc-arm-none-eabi-4_6-2012q1
41 GCC4ARM_FILENAME=gcc-arm-none-eabi-4_6-2012q1-20120316.tar.bz2
42 GCC4ARM_URL=https://launchpad.net/gcc-arm-embedded/4.6/4.6-2012-q1-update/+download/$GCC4ARM_FILENAME
43 GCC4ARM_TAR=$ROOTDIR/$GCC4ARM_FILENAME
44 GCC4ARM_MD5=3999e0ce25ecd97b3138f3b0dc13c76f
45 GCC4ARM_EXTRACT=$ROOTDIR/$GCC4ARM_VERSION
46 GCC4ARM_DIR=$ROOTDIR/gcc-arm-none-eabi
47 GCC4ARM_BINDIR=$GCC4ARM_DIR/bin
48 GCC4ARM_LIBEXEC=$GCC4ARM_DIR/libexec/gcc/arm-none-eabi/4.6.2
49 MACBIN_URL=https://github.com/adamgreen/GCC-ARM-Embedded-20120316/tarball/master
50 MACBIN_TAR=$ROOTDIR/GCC-ARM-Embedded-20120316.tar.gz
51 MACBIN_MD5=ab3e32a3418a38121eceb267e4366848
52 MACBIN_BASEDIR=$ROOTDIR/GCC-ARM-Embedded
53 MACBIN_DIR=$MACBIN_BASEDIR/osx64
54 OUR_MAKE=$ROOTDIR/external/osx64/make
55 BUILDSHELL_CMD=$ROOTDIR/BuildShell
56 BUILDSHELL_DEBUG_CMD=$ROOTDIR/BuildShellDebug
57
58
59 echo Logging install results to $LOGFILE
60 echo `date` Starting $0 $*>$LOGFILE
61
62 echo Downloading GNU Tools for ARM Embedded Processors...
63 echo `date` Executing curl -L0 $GCC4ARM_URL>>$LOGFILE
64 curl -L0 $GCC4ARM_URL >$GCC4ARM_FILENAME
65
66 echo Validating md5 signature of GNU Tools for ARM Embedded Processors...
67 echo `date` Validating md5 signature of GNU Tools for ARM Embedded Processors>>$LOGFILE
68 archive_match=`md5 -q $GCC4ARM_FILENAME | grep -c $GCC4ARM_MD5`
69 if [ "$archive_match" != "1" ] ; then
70 echo $GCC4ARM_FILENAME failed MD5 signature check.>>$LOGFILE
71 echo `date` Failure forced early exit>>$LOGFILE
72 cat $LOGFILE
73 rm -f $ERRORFILE
74 popd >/dev/null
75 read -n 1 -sp "Press any key to continue..." dummy ; echo
76 exit 1
77 fi
78
79 echo Downloading Mac OS X GCC binaries from github...
80 echo `date` Executing curl -L0 $MACBIN_URL>>$LOGFILE
81 curl -L0 $MACBIN_URL >$MACBIN_TAR
82
83 echo Validating md5 signature of Mac OS X GCC binaries...
84 echo `date` Validating md5 signature of csgcc4mac project>>$LOGFILE
85 archive_match=`md5 -q $MACBIN_TAR | grep -c $MACBIN_MD5`
86 if [ "$archive_match" != "1" ] ; then
87 echo $MACBIN_TAR failed MD5 signature check.>>$LOGFILE
88 echo `date` Failure forced early exit>>$LOGFILE
89 cat $LOGFILE
90 rm -f $ERRORFILE
91 popd >/dev/null
92 read -n 1 -sp "Press any key to continue..." dummy ; echo
93 exit 1
94 fi
95
96 echo Extracting GNU Tools for ARM Embedded Processors...
97 rm -r $GCC4ARM_DIR >/dev/null 2>/dev/null
98 RunAndLog tar xf $GCC4ARM_TAR
99 RunAndLog mv $GCC4ARM_EXTRACT $GCC4ARM_DIR
100
101 echo Extracting Mac OS X GCC binaries...
102 RunAndLog tar -x -s /adamgreen-GCC-ARM-Embedded-[0-9]*-[a-f0-9]*/GCC-ARM-Embedded/ -f $MACBIN_TAR
103
104 echo Installing 64-bit Intel Mac OS X binaries...
105 RunAndLog rm -f $GCC4ARM_BINDIR/*
106 RunAndLog cp $MACBIN_DIR/arm-none-eabi-* $GCC4ARM_BINDIR/
107 files_to_link=(as g++ ld objcopy ranlib ar c++ gcc nm objdump strip)
108 for file_item in ${files_to_link[*]} ; do
109 RunAndLog rm -f $GCC4ARM_DIR/arm-none-eabi/bin/$file_item
110 RunAndLog cp $GCC4ARM_BINDIR/arm-none-eabi-$file_item $GCC4ARM_DIR/arm-none-eabi/bin/$file_item
111 done
112 RunAndLog rm -rf $GCC4ARM_LIBEXEC/
113 RunAndLog mkdir $GCC4ARM_LIBEXEC/
114 RunAndLog cp -R $MACBIN_DIR/libexec/ $GCC4ARM_LIBEXEC/
115
116 echo Creating helper scripts...
117 echo "#! /usr/bin/env bash">$BUILDSHELL_CMD
118 echo "# Modify next line and set destination drive to match mbed device">>$BUILDSHELL_CMD
119 echo "export LPC_DEPLOY='cp PROJECT.bin /Volumes/MBED/'">>$BUILDSHELL_CMD
120 echo>>$BUILDSHELL_CMD
121 echo "SCRIPT_PATH=\$0">>$BUILDSHELL_CMD
122 echo "SCRIPT_PATH=\${SCRIPT_PATH%/*}">>$BUILDSHELL_CMD
123 echo "cd \$SCRIPT_PATH">>$BUILDSHELL_CMD
124 echo "SCRIPT_PATH=\$PWD">>$BUILDSHELL_CMD
125 echo "export PATH=\$SCRIPT_PATH/gcc-arm-none-eabi/bin:\$SCRIPT_PATH/external/osx64:\$PATH">>$BUILDSHELL_CMD
126 echo "exec bash">>$BUILDSHELL_CMD
127 chmod +x $BUILDSHELL_CMD
128
129 echo "#! /usr/bin/env bash">$BUILDSHELL_DEBUG_CMD
130 echo "# Modify next line and set destination drive to match mbed device">>$BUILDSHELL_DEBUG_CMD
131 echo "export LPC_DEPLOY='cp PROJECT.bin /Volumes/MBED/'">>$BUILDSHELL_DEBUG_CMD
132 echo>>$BUILDSHELL_DEBUG_CMD
133 echo "SCRIPT_PATH=\$0">>$BUILDSHELL_DEBUG_CMD
134 echo "SCRIPT_PATH=\${SCRIPT_PATH%/*}">>$BUILDSHELL_DEBUG_CMD
135 echo "cd \$SCRIPT_PATH">>$BUILDSHELL_DEBUG_CMD
136 echo "SCRIPT_PATH=\$PWD">>$BUILDSHELL_DEBUG_CMD
137 echo "export PATH=\$SCRIPT_PATH/gcc-arm-none-eabi/bin:\$PATH">>$BUILDSHELL_DEBUG_CMD
138 echo "export GCC4MBED_TYPE=Debug">>$BUILDSHELL_DEBUG_CMD
139 echo "exec bash">>$BUILDSHELL_DEBUG_CMD
140 chmod +x $BUILDSHELL_DEBUG_CMD
141
142 # Place arm-none-eabi-* tools in the path before building gcc4mbed code.
143 PATH=$GCC4ARM_BINDIR:$PATH
144
145 echo Performing a clean build of the gcc4mbed samples...
146 RunAndLog $OUR_MAKE clean
147 RunAndLog $OUR_MAKE
148
149 echo Cleaning up intermediate files...
150 RunAndLog rm -r $MACBIN_BASEDIR
151 RunAndLog rm $MACBIN_TAR
152 RunAndLog rm $GCC4ARM_TAR
153
154 echo
155 echo To build gcc4mbed samples, you will first need to run the following script
156 echo so that your environment variables are set correctly:
157 echo $BUILDSHELL_CMD
158 echo You will want to run this each time you start a new Terminal. You
159 echo can simply double-click on this script file from Finder to launch a
160 echo bash Terminal that has been properly initialized for building gcc4mbed
161 echo based code. Feel free to customize it as you desire.
162 echo
163 echo You can also just edit your existing setup script such as \~/.profile
164 echo to update the PATH environment variable to include:
165 echo $GCC4ARM_BINDIR
166
167
168 # Restore current directory and exit script on success.
169 echo `date` Finished successfully>>$LOGFILE
170 echo Finished successfully
171 rm -f $ERRORFILE
172 popd >/dev/null
173 read -n 1 -sp "Press any key to continue..." dummy ; echo