• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright (C) 2009 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17#  This shell script is used to download the sources of the Android NDK toolchain
18#  from the git server at android.git.kernel.org and package them in a nice tarball
19#  that can later be used with the 'built-toolchain.sh' script.
20#
21
22# include common function and variable definitions
23. `dirname $0`/../core/ndk-common.sh
24
25OPTION_HELP=no
26OPTION_RELEASE=
27OPTION_GIT=
28OPTION_BRANCH=
29
30# the default release name (use today's date)
31RELEASE=`date +%Y%m%d`
32
33# the default branch to use
34BRANCH=eclair
35
36GITCMD=git
37
38VERBOSE=no
39VERBOSE2=no
40
41for opt do
42    optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
43    case "$opt" in
44    --help|-h|-\?) OPTION_HELP=yes
45    ;;
46    --branch=*)
47        OPTION_BRANCH="$optarg"
48        ;;
49    --git=*)
50        OPTION_GIT="$optarg"
51        ;;
52    --verbose)
53        if [ "$VERBOSE" = "yes" ] ; then
54            VERBOSE2=yes
55        else
56            VERBOSE=yes
57        fi
58        ;;
59    --release=*)
60        OPTION_RELEASE=$optarg
61        ;;
62    *)
63        echo "unknown option '$opt', use --help"
64        exit 1
65    esac
66done
67
68if [ $OPTION_HELP = "yes" ] ; then
69    echo "Download the NDK toolchain sources from android.git.kernel.org and package them."
70    echo "You will need to run this script before being able to rebuild the NDK toolchain"
71    echo "binaries from scratch with build/tools/build-toolchain.sh"
72    echo ""
73    echo "options (defaults in brackets):"
74    echo ""
75    echo "  --help               print this message"
76    echo "  --branch=<name>      specify release branch [$BRANCH]"
77    echo "  --release=<name>     specify release name [$RELEASE]"
78    echo "  --git=<executable>   use this version of the git tool [$GITCMD]"
79    echo "  --verbose            increase verbosity"
80    echo ""
81    exit 0
82fi
83
84TMPLOG=/tmp/android-ndk-download-toolchain-$$.log
85rm -rf $TMPLOG
86
87if [ $VERBOSE = yes ] ; then
88    run ()
89    {
90        echo "##### NEW COMMAND"
91        echo $@
92        $@ 2>&1 | tee $TMPLOG
93    }
94    log ()
95    {
96        echo "LOG: $@"
97    }
98else
99    echo "To follow download, please use in another terminal: tail -F $TMPLOG"
100    run ()
101    {
102        echo "##### NEW COMMAND" >> $TMPLOG
103        echo "$@" >> $TMPLOG
104        $@ 1>$TMPLOG 2>&1
105    }
106    log ()
107    {
108        echo "$@" > /dev/null
109    }
110fi
111
112if [ -n "$OPTION_RELEASE" ] ; then
113    RELEASE="$OPTION_RELEASE"
114    log "Using release name $RELEASE"
115else
116    log "Using default release name $RELEASE"
117fi
118
119# Check that 'git' works
120if [ -n "$OPTION_GIT" ] ; then
121    GITCMD="$OPTION_GIT"
122    log "Using git tool command: '$GITCMD'"
123else
124    log "Using default git tool command."
125fi
126$GITCMD --version > /dev/null 2>&1
127if [ $? != 0 ] ; then
128    echo "The git tool doesn't seem to work. Please check $GITCMD"
129    exit 1
130fi
131log "Git seems to work ok."
132
133if [ -n "$OPTION_BRANCH" ] ; then
134    BRANCH="$OPTION_BRANCH"
135    log "Using branch named $BRANCH"
136else
137    log "Using default branch name $BRANCH"
138fi
139
140# Create temp directory where everything will be copied
141#
142PKGNAME=android-ndk-toolchain-$RELEASE
143TMPDIR=/tmp/$PKGNAME
144log "Creating temporary directory $TMPDIR"
145rm -rf $TMPDIR && mkdir $TMPDIR
146if [ $? != 0 ] ; then
147    echo "Could not create temporary directory: $TMPDIR"
148fi
149
150# prefix used for all clone operations
151GITPREFIX=git://android.git.kernel.org/toolchain
152
153toolchain_clone ()
154{
155    echo "downloading sources for toolchain/$1"
156    log "cloning $GITPREFIX/$1.git"
157    run git clone $GITPREFIX/$1.git $1
158    if [ $? != 0 ] ; then
159        echo "Could not clone $GITPREFIX/$1.git ?"
160        exit 1
161    fi
162    log "checking out $BRANCH branch of $1.git"
163    cd $1
164    run git checkout -b $BRANCH origin/$BRANCH
165    if [ $? != 0 ] ; then
166        echo "Could not checkout $1 ?"
167        exit 1
168    fi
169    # get rid of .git directory, we won't need it.
170    cd ..
171    log "getting rid of .git directory for $1."
172    run rm -rf $1/.git
173}
174
175
176cd $TMPDIR
177toolchain_clone binutils
178toolchain_clone build
179toolchain_clone gcc
180toolchain_clone gdb
181toolchain_clone gmp
182#toolchain_clone gold  # not sure about this one !
183toolchain_clone mpfr
184
185# We only keep one version of gcc and binutils
186
187# we clearly don't need this
188log "getting rid of obsolete gcc 4.3.1 sources"
189rm -rf $TMPDIR/gcc/gcc-4.3.1
190
191# create the package
192PACKAGE=/tmp/$PKGNAME.tar.bz2
193echo "Creating package archive $PACKAGE"
194cd `dirname $TMPDIR`
195run tar cjvf $PACKAGE -C /tmp/$PKGNAME .
196if [ $? != 0 ] ; then
197    echo "Could not package toolchain source archive ?. See $TMPLOG"
198    exit 1
199fi
200
201echo "Toolchain sources downloaded and packaged succesfully at $PACKAGE"
202rm -f $TMPLOG
203