Move files in preparation for new build system.
[clinton/Smoothieware.git] / linux_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/linux_install.log
39 ERRORFILE=$ROOTDIR/linux_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 NEWBIN_URL=https://github.com/adamgreen/GCC-ARM-Embedded-20120316/tarball/master
50 NEWBIN_TAR=$ROOTDIR/GCC-ARM-Embedded-20120316.tar.gz
51 NEWBIN_MD5=ab3e32a3418a38121eceb267e4366848
52 NEWBIN_BASEDIR=$ROOTDIR/GCC-ARM-Embedded
53 NEWBIN_DIR=$NEWBIN_BASEDIR/lin32
54 OUR_MAKE=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 rm $GCC4ARM_FILENAME >/dev/null 2>/dev/null
64 echo `date` Executing wget $GCC4ARM_URL>>$LOGFILE
65 wget $GCC4ARM_URL
66
67 echo Validating md5 signature of GNU Tools for ARM Embedded Processors...
68 echo `date` Validating md5 signature of GNU Tools for ARM Embedded Processors>>$LOGFILE
69 archive_match=`md5sum $GCC4ARM_FILENAME | grep -c $GCC4ARM_MD5`
70 if [ "$archive_match" != "1" ] ; then
71 echo $GCC4ARM_FILENAME failed MD5 signature check.>>$LOGFILE
72 echo `date` Failure forced early exit>>$LOGFILE
73 cat $LOGFILE
74 rm -f $ERRORFILE
75 popd >/dev/null
76 read -n 1 -sp "Press any key to continue..." dummy ; echo
77 exit 1
78 fi
79
80 echo Downloading updated GCC binaries from github...
81 rm $NEWBIN_TAR >/dev/null 2>/dev/null
82 echo `date` Executing wget -O $NEWBIN_TAR $NEWBIN_URL>>$LOGFILE
83 wget -O $NEWBIN_TAR $NEWBIN_URL
84
85 echo Validating md5 signature of updated GCC binaries...
86 echo `date` Validating md5 signature of csgcc4mac project>>$LOGFILE
87 archive_match=`md5sum $NEWBIN_TAR | grep -c $NEWBIN_MD5`
88 if [ "$archive_match" != "1" ] ; then
89 echo $NEWBIN_TAR failed MD5 signature check.>>$LOGFILE
90 echo `date` Failure forced early exit>>$LOGFILE
91 cat $LOGFILE
92 rm -f $ERRORFILE
93 popd >/dev/null
94 read -n 1 -sp "Press any key to continue..." dummy ; echo
95 exit 1
96 fi
97
98 echo Extracting GNU Tools for ARM Embedded Processors...
99 rm -r $GCC4ARM_DIR >/dev/null 2>/dev/null
100 RunAndLog tar xf $GCC4ARM_TAR
101 RunAndLog mv $GCC4ARM_EXTRACT $GCC4ARM_DIR
102
103 echo Extracting updated GCC binaries...
104 RunAndLog tar -x --xform s/adamgreen-GCC-ARM-Embedded-[0-9]*-[a-f0-9]*/GCC-ARM-Embedded/ -f $NEWBIN_TAR
105
106 echo Installing updated GCC binaries...
107 RunAndLog cp $NEWBIN_DIR/arm-none-eabi-gdb $GCC4ARM_BINDIR/
108
109 echo Creating helper scripts...
110 echo "#! /usr/bin/env bash">$BUILDSHELL_CMD
111 echo "# Modify next line and set destination drive to match mbed device">>$BUILDSHELL_CMD
112 echo "export LPC_DEPLOY='cp PROJECT.bin /media/MBED/ ; sync'">>$BUILDSHELL_CMD
113 echo>>$BUILDSHELL_CMD
114 echo "SCRIPT_PATH=\$0">>$BUILDSHELL_CMD
115 echo "SCRIPT_PATH=\${SCRIPT_PATH%/*}">>$BUILDSHELL_CMD
116 echo "cd \$SCRIPT_PATH">>$BUILDSHELL_CMD
117 echo "SCRIPT_PATH=\$PWD">>$BUILDSHELL_CMD
118 echo "export PATH=\$SCRIPT_PATH/gcc-arm-none-eabi/bin:\$PATH">>$BUILDSHELL_CMD
119 echo "exec bash">>$BUILDSHELL_CMD
120 chmod +x $BUILDSHELL_CMD
121
122 echo "#! /usr/bin/env bash">$BUILDSHELL_DEBUG_CMD
123 echo "# Modify next line and set destination drive to match mbed device">>$BUILDSHELL_DEBUG_CMD
124 echo "export LPC_DEPLOY='cp PROJECT.bin /media/MBED/ ; sync'">>$BUILDSHELL_DEBUG_CMD
125 echo>>$BUILDSHELL_DEBUG_CMD
126 echo "SCRIPT_PATH=\$0">>$BUILDSHELL_DEBUG_CMD
127 echo "SCRIPT_PATH=\${SCRIPT_PATH%/*}">>$BUILDSHELL_DEBUG_CMD
128 echo "cd \$SCRIPT_PATH">>$BUILDSHELL_DEBUG_CMD
129 echo "SCRIPT_PATH=\$PWD">>$BUILDSHELL_DEBUG_CMD
130 echo "export PATH=\$SCRIPT_PATH/gcc-arm-none-eabi/bin:\$PATH">>$BUILDSHELL_DEBUG_CMD
131 echo "export GCC4MBED_TYPE=Debug">>$BUILDSHELL_DEBUG_CMD
132 echo "exec bash">>$BUILDSHELL_DEBUG_CMD
133 chmod +x $BUILDSHELL_DEBUG_CMD
134
135 # Place arm-none-eabi-* tools in the path before building gcc4mbed code.
136 PATH=$GCC4ARM_BINDIR:$PATH
137
138 echo Performing a clean build of the gcc4mbed samples...
139 RunAndLog $OUR_MAKE clean
140 RunAndLog $OUR_MAKE
141
142 echo Cleaning up intermediate files...
143 RunAndLog rm -r $NEWBIN_BASEDIR
144 RunAndLog rm $NEWBIN_TAR
145 RunAndLog rm $GCC4ARM_TAR
146
147 echo
148 echo To build gcc4mbed samples, you will first need to run the following script
149 echo so that your environment variables are set correctly:
150 echo $BUILDSHELL_CMD
151 echo You will want to run this each time you start a new Terminal. You
152 echo can simply double-click on this script file from Finder to launch a
153 echo bash Terminal that has been properly initialized for building gcc4mbed
154 echo based code. Feel free to customize it as you desire.
155 echo
156 echo You can also just edit your existing setup script such as \~/.profile
157 echo to update the PATH environment variable to include:
158 echo $GCC4ARM_BINDIR
159
160
161 # Restore current directory and exit script on success.
162 echo `date` Finished successfully>>$LOGFILE
163 echo Finished successfully
164 rm -f $ERRORFILE
165 popd >/dev/null
166 read -n 1 -sp "Press any key to continue..." dummy ; echo