• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
31PROGRAM_PARAMETERS="<ndk-dir>"
32PROGRAM_DESCRIPTION="Rebuild the prebuilt ccache binary for the Android NDK toolchain."
33
34CCACHE_VERSION=ccache-2.4-android-20070905
35CCACHE_PACKAGE=$CCACHE_VERSION.tar.gz
36DOWNLOAD_ROOT=http://android.git.kernel.org/pub
37CCACHE_URL=$DOWNLOAD_ROOT/$CCACHE_PACKAGE
38
39OPTION_PACKAGE=no
40
41BUILD_OUT=$NDK_TMPDIR/build-ccache
42OPTION_BUILD_OUT=
43OPTION_FROM=
44
45register_option "--from=<url>" do_from "Specify source package" "$PACKAGE"
46register_option "--build-out=<path>" do_build_out "Set temporary build directory" "/tmp/ndk-$USER/<random>"
47
48do_from () { CCACHE_URL=$1; CCACHE_PACKAGE=`basename $1`; }
49do_build_out () { OPTION_BUILD_OUT=$1; }
50
51extract_parameters "$@"
52
53set_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
73set_parameters $PARAMETERS
74
75prepare_host_build
76
77fix_option BUILD_OUT "$OPTION_BUILD_OUT" "build directory"
78
79# Check for md5sum
80check_md5sum
81
82prepare_download
83
84run rm -rf $BUILD_OUT && run mkdir -p $BUILD_OUT
85if [ $? != 0 ] ; then
86    echo "ERROR: Could not create build directory: $BUILD_OUT"
87    exit 1
88fi
89
90dump "Getting sources from $CCACHE_URL"
91
92download_file $CCACHE_URL $BUILD_OUT/$CCACHE_PACKAGE
93if [ $? != 0 ] ; then
94    dump "Could not download $CCACHE_URL"
95    dump "Aborting."
96    exit 1
97fi
98
99cd $BUILD_OUT && tar xzf $BUILD_OUT/$CCACHE_PACKAGE
100if [ $? != 0 ] ; then
101    dump "Could not unpack $CCACHE_PACKAGE in $BUILD_OUT"
102    exit 1
103fi
104
105echo "Building ccache from sources..."
106cd $BUILD_OUT/$CCACHE_VERSION && run make clean && run make unpack && run make build
107if [ $? != 0 ] ; then
108    dump "Could not build ccache in $BUILD_OUT"
109fi
110
111PREBUILT_DIR=$NDK_DIR/build/prebuilt/$HOST_TAG/ccache
112mkdir -p $PREBUILT_DIR && cp -p $BUILD_OUT/$CCACHE_VERSION/ccache $PREBUILT_DIR
113if [ $? != 0 ] ; then
114    dump "Could not copy ccache binary!"
115    exit 1
116fi
117
118dump "Done"
119