1 #!/bin/sh 2 # 3 # Copyright (C) 2010 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 ccache 18 # tool that can be used to speed-up rebuilds of NDK binaries. 19 # 20 # We use a special patched version of ccache 2.4 that works 21 # well on Win32 and handles the dependency generation compiler 22 # flags (-MMD -MP -MF) properly. 23 # 24 # Beta versions of ccache 3.0 are supposed to do that as well but 25 # have not been checked yet. 26 # 27 28 # include common function and variable definitions 29 . `dirname $0`/prebuilt-common.sh 30 31 PROGRAM_PARAMETERS="<ndk-dir>" 32 PROGRAM_DESCRIPTION="Rebuild the prebuilt ccache binary for the Android NDK toolchain." 33 34 CCACHE_VERSION=ccache-2.4-android-20070905 35 CCACHE_PACKAGE=$CCACHE_VERSION.tar.gz 36 DOWNLOAD_ROOT=http://android.git.kernel.org/pub 37 CCACHE_URL=$DOWNLOAD_ROOT/$CCACHE_PACKAGE 38 39 OPTION_PACKAGE=no 40 41 BUILD_OUT=`random_temp_directory` 42 OPTION_BUILD_OUT= 43 OPTION_FROM= 44 45 register_option "--from=<url>" do_from "Specify source package" "$PACKAGE" 46 register_option "--build-out=<path>" do_build_out "Set temporary build directory" "/tmp/<random>" 47 48 do_from () { CCACHE_URL=$1; CCACHE_PACKAGE=`basename $1`; } 49 do_build_out () { OPTION_BUILD_OUT=$1; } 50 51 extract_parameters $@ 52 53 set_parameters () 54 { 55 if [ -n "$2" ] ; then 56 echo "ERROR: Too many parameters. See --help for usage." 57 exit 1 58 fi 59 60 NDK_DIR=$1 61 if [ -z "$NDK_DIR" ] ; then 62 echo "ERROR: Missing required ndk directory. See --help for usage." 63 exit 1 64 fi 65 66 mkdir -p $NDK_DIR 67 if [ $? != 0 ] ; then 68 echo "ERROR: Could not create NDK target directory: $NDK_DIR" 69 exit 1 70 fi 71 } 72 73 set_parameters $PARAMETERS 74 75 prepare_host_flags 76 77 fix_option BUILD_OUT "$OPTION_BUILD_OUT" "build directory" 78 79 # Check for md5sum 80 check_md5sum 81 82 prepare_download 83 84 run rm -rf $BUILD_OUT && run mkdir -p $BUILD_OUT 85 if [ $? != 0 ] ; then 86 echo "ERROR: Could not create build directory: $BUILD_OUT" 87 exit 1 88 fi 89 90 dump "Getting sources from $CCACHE_URL" 91 92 download_file $CCACHE_URL $BUILD_OUT/$CCACHE_PACKAGE 93 if [ $? != 0 ] ; then 94 dump "Could not download $CCACHE_URL" 95 dump "Aborting." 96 exit 1 97 fi 98 99 cd $BUILD_OUT && tar xzf $BUILD_OUT/$CCACHE_PACKAGE 100 if [ $? != 0 ] ; then 101 dump "Could not unpack $CCACHE_PACKAGE in $BUILD_OUT" 102 exit 1 103 fi 104 105 echo "Building ccache from sources..." 106 cd $BUILD_OUT/$CCACHE_VERSION && run make clean && run make unpack && run make build 107 if [ $? != 0 ] ; then 108 dump "Could not build ccache in $BUILD_OUT" 109 fi 110 111 PREBUILT_DIR=$NDK_DIR/build/prebuilt/$HOST_TAG/ccache 112 mkdir -p $PREBUILT_DIR && cp -p $BUILD_OUT/$CCACHE_VERSION/ccache $PREBUILT_DIR 113 if [ $? != 0 ] ; then 114 dump "Could not copy ccache binary!" 115 exit 1 116 fi 117 118 dump "Done" 119