3 # Convert a /usr/local toolchain to a /usr/local/uclinux-dist toolchain
4 # installer that is date stamped appropriately.
6 # David McCullough <ucdevel@gmail.com>
9 if [ $# -lt 3 -o $# -gt 4 -o ! -f "$1" ]
11 echo "usage: `basename $0` <tar-gz from / of usr local chain> <build-date> <cross> [prefix]"
13 echo " `basename $0` arm-linux-tools-20070808.tar.gz 20070808 arm-linux"
14 echo " `basename $0` mips-linux-tools-20130305.tar.gz 20130305 mips-linux mips-unknown-linux-gnu"
16 echo "cross - new tools will be called cross-date-gcc"
17 echo "prefix - if existing prefix is different to cross, otherwise"
18 echo " it defaults to cross"
26 EXTRACT_DIR=/usr/local/uclinux-dist
27 LINK_DIR=/usr/local/bin
31 # helper to extract tar.gz from archive
40 SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' "$1"`
50 # lets check the archive is pure ;-)
54 cat_archive "$ARCHIVE" | tar tvzf - > $CHECK
57 if egrep -v '(usr/local|usr/$)' $CHECK
59 echo "Found files outside usr/local !"
66 # Now we generate a script to install this appropriately
69 INSTALL_FILE="$CROSS-tools-$DATE.sh"
71 cat <<!EOF > $INSTALL_FILE
74 EXTRACT_DIR=$EXTRACT_DIR
84 if [ -f "\${SCRIPT}" ]
86 SCRIPT="\`pwd\`/\${SCRIPT}"
88 SCRIPT="\`which \${SCRIPT}\`"
95 if [ ! -f "\${SCRIPT}" ]
97 echo "Cannot find the location of the install script (\$SCRIPT) ?"
101 SKIP=\`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' \${SCRIPT}\`
104 # find out where to put the buld of the archive
107 echo -n "Where would you like these tools installed? [\$EXTRACT_DIR]: "
112 if [ -w \`basename \$t\` -o -w \$t ]; then
116 echo "Neither \`basename \$t\` or \$t are writable"
122 # and where we need to install the "compiler" executables for running
125 echo -n "Install executable links into ? [\$LINK_DIR]: "
130 if [ -w \`basename \$t\` -o -w \$t ]; then
134 echo "Neither \`basename \$t\` or \$t are writable"
140 # clean out old or possibly conflicting tools chains ?
143 echo "***** Warning - removal may break other non SG packaged tool chains"
144 echo -n "Remove old or possible conflicting toolchains/files ? [\$CLEAN_OLD]: "
148 y|Y|[yY][eE][sS]) CLEAN_OLD=y; break ;;
149 n|N|[nN][oO]) CLEAN_OLD=n; break ;;
150 *) echo "Either Y or N will do :-)" ;;
155 # if they have ccache install, let them use it by default :-)
157 if [ -x "\`which ccache\`" ]; then
158 echo -n "You have ccache installed, always use it? [\$CCACHE_OPTION]: "
162 y|Y|[yY][eE][sS]) CCACHE_OPTION=y; break ;;
163 n|N|[nN][oO]) CCACHE_OPTION=n; break ;;
164 *) echo "Either Y or N will do :-)" ;;
168 if [ "\$CCACHE_OPTION" = y ]; then
169 CCACHE="\`which ccache\`"
175 # Now clean up old conflicting tool chains and directories
177 if [ "\$CLEAN_OLD" = "y" ]; then
178 rm -rf "/usr/local/${CROSS}"
179 rm -rf "/usr/local/lib/gcc-lib/${CROSS}"
180 rm -rf "/usr/local/lib/gcc/${CROSS}"
181 rm -rf "/usr/local/libexec/gcc/${CROSS}"
182 rm -rf /usr/local/include/g++-v3
183 rm -rf /usr/local/include/c++
184 for i in /usr/local/bin/${CROSS}-*
187 /usr/local/bin/${CROSS}-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-*)
188 echo "\$i is ok, leaving..."
191 echo "\$i is a conflict, removing..."
199 # extract the toolchain and install the executables appropriately
202 [ -d \$EXTRACT_DIR ] || mkdir -p \$EXTRACT_DIR
203 if [ ! -d \$EXTRACT_DIR ]; then
204 echo "Cannot make directory \$EXTRACT_DIR"
207 rm -rf \$EXTRACT_DIR/${CROSS}-tools-${DATE}
208 if [ -d \$EXTRACT_DIR/${CROSS}-tools-${DATE} ]; then
209 echo "Cannot remove \$EXTRACT_DIR/${CROSS}-tools-${DATE}"
212 mkdir -p \$EXTRACT_DIR/${CROSS}-tools-${DATE}
213 if [ ! -d \$EXTRACT_DIR/${CROSS}-tools-${DATE} ]; then
214 echo "Cannot make directory \$EXTRACT_DIR/${CROSS}-tools-${DATE}"
219 cd \$EXTRACT_DIR/${CROSS}-tools-${DATE} || exit 1
220 tail -n +\${SKIP} \${SCRIPT} | gunzip | tar xf -
223 if [ ! -d \$EXTRACT_DIR/${CROSS}-tools-${DATE}/usr ]; then
224 "Extraction failed, no usr directory created in target"
229 # move the binaries to a nicer location
231 for i in \$EXTRACT_DIR/${CROSS}-tools-${DATE}/usr/local/*
233 mv "\$i" \$EXTRACT_DIR/${CROSS}-tools-${DATE}/.
235 rm -rf \$EXTRACT_DIR/${CROSS}-tools-${DATE}/usr
238 # create the executables
240 for i in \$EXTRACT_DIR/${CROSS}-tools-${DATE}/bin/*
242 BASE="\`basename \$i\`"
243 BASE="\`echo \$BASE | sed 's/^${PREFIX}-//'\`"
244 rm -f \$LINK_DIR/${CROSS}-${DATE}-\$BASE
245 echo "#!/bin/sh" >> \$LINK_DIR/${CROSS}-${DATE}-\$BASE
246 if [ "\$CCACHE" ]; then
249 echo "exec \$CCACHE \$i \\"\\\$@\\"" >> \
250 \$LINK_DIR/${CROSS}-${DATE}-\$BASE
254 # fallback to non cache in case ccache is removed
255 printf "exec \$i \\"\\\$@\\"" >> \$LINK_DIR/${CROSS}-${DATE}-\$BASE
256 chmod 755 \$LINK_DIR/${CROSS}-${DATE}-\$BASE
263 cat_archive "$ARCHIVE" >> $INSTALL_FILE
264 chmod +x $INSTALL_FILE