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`/prebuilt-common.sh 24 PROGDIR=`dirname $0` 25 PROGDIR=`cd $PROGDIR && pwd` 26 27 # the default branch to use 28 BRANCH=master 29 register_option "--branch=<name>" BRANCH "Specify release branch" 30 31 # the default release name (use today's date) 32 if [ "$TOOLCHAIN_GIT_DATE" -a "$TOOLCHAIN_GIT_DATE" != "now" ] ; then 33 RELEASE=`echo $TOOLCHAIN_GIT_DATE | sed -e 's!-!!g'` 34 else 35 RELEASE=`date +%Y%m%d` 36 fi 37 register_var_option "--release=<name>" RELEASE "Specify release name" 38 39 GIT_DATE=$TOOLCHAIN_GIT_DATE 40 register_var_option "--git-date=<date>" GIT_DATE "Only sources that existed until specified <date>" 41 42 GITCMD=git 43 register_var_option "--git=<executable>" GITCMD "Use this version of the git tool" 44 45 OPTION_GIT_HTTP=no 46 register_var_option "--git-http" OPTION_GIT_HTTP "Use http to download sources from git" 47 48 OPTION_GIT_BASE= 49 register_var_option "--git-base=<git-uri>" OPTION_GIT_BASE "Use specific git repository base" 50 51 OPTION_PACKAGE=no 52 register_var_option "--package" OPTION_PACKAGE "Create source package in /tmp" 53 54 PROGRAM_PARAMETERS="<src-dir>" 55 PROGRAM_DESCRIPTION=\ 56 "Download the NDK toolchain sources from android.git.kernel.org into <src-dir>. 57 You will need to run this script before being able to rebuilt the NDK toolchain 58 binaries from scratch with build/tools/build-gcc.sh." 59 60 if [ -n "$TOOLCHAIN_GIT_DATE" ] ; then 61 PROGRAM_DESCRIPTION="$PROGRAM_DESCRIPTION\ 62 63 64 By default, this script will download sources from android.git.kernel.org that 65 correspond to the date of $TOOLCHAIN_GIT_DATE. If you want to use the tip of 66 tree, use '--git-date=now' instead. 67 68 If you don't want to use the official servers, use --git-base=<path> to 69 download the sources from another set of git repostories." 70 71 fi 72 73 extract_parameters "$@" 74 75 if [ -n "$OPTION_GIT_BASE" -a "$OPTION_GIT_HTTP" = "yes" ] ; then 76 echo "ERROR: You can't use --git-base and --git-http at the same time." 77 exit 1 78 fi 79 80 # Check that 'git' works 81 $GITCMD --version > /dev/null 2>&1 82 if [ $? != 0 ] ; then 83 echo "The git tool doesn't seem to work. Please check $GITCMD" 84 exit 1 85 fi 86 log "Git seems to work ok." 87 88 SRC_DIR="$PARAMETERS" 89 if [ -z "$SRC_DIR" -a "$OPTION_PACKAGE" = no ] ; then 90 echo "ERROR: You need to provide a <src-dir> parameter or use the --package option!" 91 exit 1 92 fi 93 94 if [ -n "$SRC_DIR" ] ; then 95 mkdir -p $SRC_DIR 96 SRC_DIR=`cd $SRC_DIR && pwd` 97 log "Using target source directory: $SRC_DIR" 98 fi 99 100 # Create temp directory where everything will be copied first 101 # 102 PKGNAME=android-ndk-toolchain-$RELEASE 103 TMPDIR=/tmp/$PKGNAME 104 log "Creating temporary directory $TMPDIR" 105 rm -rf $TMPDIR && mkdir $TMPDIR 106 fail_panic "Could not create temporary directory: $TMPDIR" 107 108 # prefix used for all clone operations 109 if [ -n "$OPTION_GIT_BASE" ] ; then 110 GITPREFIX="$OPTION_GIT_BASE" 111 else 112 GITPROTO=git 113 if [ "$OPTION_GIT_HTTP" = "yes" ] ; then 114 GITPROTO=http 115 fi 116 GITPREFIX=${GITPROTO}://android.git.kernel.org/toolchain 117 fi 118 dump "Using git clone prefix: $GITPREFIX" 119 120 toolchain_clone () 121 { 122 dump "downloading sources for toolchain/$1" 123 if [ -d "$GITPREFIX/$1" ]; then 124 log "cloning $GITPREFIX/$1" 125 run git clone $GITPREFIX/$1 $1 126 else 127 log "cloning $GITPREFIX/$1.git" 128 run git clone $GITPREFIX/$1.git $1 129 fi 130 fail_panic "Could not clone $GITPREFIX/$1.git ?" 131 log "checking out $BRANCH branch of $1.git" 132 cd $1 133 if [ "$BRANCH" != "master" ] ; then 134 run git checkout -b $BRANCH origin/$BRANCH 135 fail_panic "Could not checkout $1 ?" 136 # If --git-date is used, or we have a default 137 if [ -n "$GIT_DATE" ] ; then 138 REVISION=`git rev-list -n 1 --until="$GIT_DATE" HEAD` 139 dump "Using sources for date '$GIT_DATE': toolchain/$1 revision $REVISION" 140 run git checkout $REVISION 141 fail_panic "Could not checkout $1 ?" 142 fi 143 fi 144 # get rid of .git directory, we won't need it. 145 cd .. 146 log "getting rid of .git directory for $1." 147 run rm -rf $1/.git 148 } 149 150 cd $TMPDIR 151 toolchain_clone binutils 152 toolchain_clone build 153 toolchain_clone gcc 154 toolchain_clone gdb 155 toolchain_clone gmp 156 toolchain_clone gold # not sure about this one ! 157 toolchain_clone mpfr 158 159 # Patch the toolchain sources 160 PATCHES_DIR="$PROGDIR/toolchain-patches" 161 if [ -d "$PATCHES_DIR" ] ; then 162 dump "Patching toolchain sources" 163 run $PROGDIR/patch-sources.sh $FLAGS $TMPDIR $PATCHES_DIR 164 if [ $? != 0 ] ; then 165 dump "ERROR: Could not patch sources." 166 exit 1 167 fi 168 fi 169 170 171 # We only keep one version of gcc and binutils 172 173 # we clearly don't need this 174 log "getting rid of obsolete sources: gcc-4.2.1 gcc-4.3.1 gdb-6.8 binutils-2.17" 175 rm -rf $TMPDIR/gcc/gcc-4.2.1 176 rm -rf $TMPDIR/gcc/gcc-4.3.1 177 rm -rf $TMPDIR/gcc/gdb-6.8 178 rm -rf $TMPDIR/binutils/binutils-2.17 179 180 # remove all info files from the toolchain sources 181 # they create countless little problems during the build 182 # if you don't have exactly the configuration expected by 183 # the scripts. 184 # 185 find $TMPDIR -type f -a -name "*.info" -print0 | xargs -0 rm -f 186 187 if [ $OPTION_PACKAGE = "yes" ] ; then 188 # create the package 189 PACKAGE=/tmp/$PKGNAME.tar.bz2 190 dump "Creating package archive $PACKAGE" 191 pack_archive "$PACKAGE" "$TMPDIR" "." 192 fail_panic "Could not package toolchain source archive ?. See $TMPLOG" 193 dump "Toolchain sources downloaded and packaged succesfully at $PACKAGE" 194 else 195 # copy sources to <src-dir> 196 SRC_DIR=`cd $SRC_DIR && pwd` 197 rm -rf $SRC_DIR && mkdir -p $SRC_DIR 198 fail_panic "Could not create target source directory: $SRC_DIR" 199 copy_directory "$TMPDIR" "$SRC_DIR" 200 fail_panic "Could not copy downloaded sources to: $SRC_DIR" 201 dump "Toolchain sources downloaded and copied to $SRC_DIR" 202 fi 203 204 dump "Cleaning up..." 205 rm -rf $TMPDIR 206 rm -f $TMPLOG 207 dump "Done." 208