• 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#  A shell script used to configure the host-specific parts of the NDK
18#  build system. This will create out/host/config-host.make based on
19#  your host system and additionnal command-line options.
20#
21
22# check that this script is run from the top-level NDK directory
23if [ ! -f build/core/ndk-common.sh ] ; then
24    echo "Please run this script from the top-level NDK directory as in:"
25    echo "   cd \$NDKROOT"
26    echo "   build/host-setup.sh"
27    exit 1
28fi
29
30# include common function and variable definitions
31. `dirname $0`/core/ndk-common.sh
32
33OUT_DIR=out
34HOST_CONFIG=$OUT_DIR/host/config.mk
35
36## Build configuration file support
37## you must define $config_mk before calling this function
38##
39create_config_mk ()
40{
41    # create the directory if needed
42    local  config_dir
43    config_mk=${config_mk:-$HOST_CONFIG}
44    config_dir=`dirname $config_mk`
45    mkdir -p $config_dir 2> $TMPL
46    if [ $? != 0 ] ; then
47        echo "Can't create directory for host config file: $config_dir"
48        exit 1
49    fi
50
51    # re-create the start of the configuration file
52    log "Generate   : $config_mk"
53
54    echo "# This file was autogenerated by $PROGNAME. Do not edit !" > $config_mk
55}
56
57add_config ()
58{
59    echo "$1" >> $config_mk
60}
61
62# assume $1 points to a GNU Make executable, and extract version number
63# to verify its a least what we need
64check_gnu_make_version ()
65{
66    if [ -n "$GNU_MAKE" ] ; then
67        return
68    fi
69
70    log2 "  looking for GNU Make as '$1'"
71    local executable=`which $1`
72    if [ -z "$executable" ] ; then
73        log2 "    Not available."
74        return
75    fi
76
77    # I'd love to do the version extraction with awk, but I'm unsure it is
78    # part of the default Cygwin install, so don't bring the dependency
79    # and rely on dumb tools instead.
80    #
81    local version major minor
82    version=`$executable --version | grep "GNU Make"`
83    if [ -z "$version" ] ; then
84        log2 "    Not a GNU Make executable."
85        return
86    fi
87    version=`echo $version | sed -e 's/^GNU Make \([0-9\.]*\).*$/\1/g'`
88    log2 "    Found version $version"
89    major=`echo $version | sed -e 's/\([0-9]*\)\..*/\1/g'`
90    minor=`echo $version | sed -e 's/[0-9]*\.\(.*\)/\1/g'`
91    if [ "$major" -lt "3" ] ; then
92        log2 "    Major version too small ($major.$minor < 3.81)."
93        return
94    fi
95    if [ "$major" -eq "3" -a $minor -lt 80 ] ; then
96        log2 "    Minor version too small ($major.$minor < 3.81)."
97        return
98    fi
99    GNU_MAKE=$1
100    GNU_MAKE_VERSION=$version
101}
102
103# check that $1 points to an awk executable that has a working
104# match() function. This really means Nawk or GNU Awk, which should
105# be installed on all modern distributions, but hey, you never know...
106check_awk ()
107{
108    if [ -n "$AWK" ] ; then
109        return
110    fi
111    log2 "  looking for nawk/gawk as '$1'"
112    local executable=`which $1`
113    if [ -z "$executable" ] ; then
114        log2 "    Not available."
115        return
116    fi
117    local result
118    result=`echo "" | $executable -f build/check-awk.awk`
119    if [ "$result" = "Pass" ] ; then
120        AWK="$1"
121    fi
122    log2 "    Check $result"
123}
124
125OPTION_HELP=no
126OPTION_NO_MAKE_CHECK=no
127OPTION_NO_AWK_CHECK=no
128
129for opt do
130  optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
131  case "$opt" in
132  --help|-h|-\?) OPTION_HELP=yes
133  ;;
134  --no-make-check) OPTION_NO_MAKE_CHECK=yes
135  ;;
136  --no-awk-check) OPTION_NO_AWK_CHECK=yes
137  ;;
138  --verbose)
139    if [ "$VERBOSE" = "yes" ] ; then
140        VERBOSE2=yes
141    else
142        VERBOSE=yes
143    fi
144  ;;
145  *)
146    echo "unknown option '$opt', use --help"
147    exit 1
148  esac
149done
150
151if [ $OPTION_HELP = yes ] ; then
152    echo "Usage: build/host-setup.sh [options]"
153    echo ""
154    echo "This script is used to check your host development environment"
155    echo "to ensure that the Android NDK will work correctly with it."
156    echo ""
157    echo "Options: [defaults in brackets after descriptions]"
158    echo ""
159    echo "  --help            Print this help message"
160    echo "  --verbose         Enable verbose mode"
161    echo "  --no-make-check   Ignore GNU Make version check"
162    echo "  --no-awk-check    Ignore Nawk/Gawk check"
163    echo ""
164    exit 1
165fi
166
167
168echo "Checking host development environment."
169echo "NDK Root   : $ANDROID_NDK_ROOT"
170
171## Check for GNU Make with a proper version number
172##
173if [ "$OPTION_NO_MAKE_CHECK" = "no" ] ; then
174    GNU_MAKE=
175    check_gnu_make_version make
176    check_gnu_make_version gmake
177    if [ -z "$GNU_MAKE" ] ; then
178        echo "ERROR: Could not find a valid GNU Make executable."
179        echo "       Please ensure GNU Make 3.81 or later is installed."
180        echo "       Use the --no-make-check option to ignore this message."
181        exit 1
182    fi
183    echo "GNU Make   : $GNU_MAKE (version $GNU_MAKE_VERSION)"
184else
185    echo "GNU Make   : Check ignored through user option."
186fi
187
188## Check for nawk or gawk, straight awk doesn't have the 'match'
189## function we need in the build system.
190##
191if [ "$OPTION_NO_AWK_CHECK" = "no" ] ; then
192    AWK=
193    check_awk awk
194    check_awk gawk
195    check_awk nawk
196    if [ -z "$AWK" ] ; then
197        echo "ERROR: Could not find a valid Nawk or Gawk executable."
198        echo "       Please ensure that either one of them is installed."
199        echo "       Use the --no-awk-check option to ignore this message."
200        exit 1
201    fi
202    echo "Awk        : $AWK"
203else
204    echo "Awk        : Check ignored through user option."
205fi
206
207## Check the host platform tag that will be used to locate prebuilt
208## toolchain binaries. And create configuration file.
209##
210force_32bit_binaries
211echo "Platform   : $HOST_TAG"
212
213create_config_mk
214add_config "HOST_OS       := $HOST_OS"
215add_config "HOST_ARCH     := $HOST_ARCH"
216add_config "HOST_TAG      := $HOST_TAG"
217add_config "HOST_AWK      := $AWK"
218
219## Check that the toolchains we need are installed
220## Otherwise, instruct the user to download them from the web site
221
222TOOLCHAINS=arm-eabi-4.2.1
223
224for tc in $TOOLCHAINS; do
225    echo "Toolchain  : Checking for $tc prebuilt binaries"
226    PREBUILT_BIN=build/prebuilt/$HOST_TAG/$tc/bin
227    log2 "Toolchain  : Cross-compiler in <NDK>/$PREBUILT_BIN ?"
228    COMPILER_PATTERN=$ANDROID_NDK_ROOT/$PREBUILT_BIN/*-gcc$HOST_EXE
229    COMPILERS=`ls $COMPILER_PATTERN 2> /dev/null`
230    if [ -z $COMPILERS ] ; then
231        echo ""
232        echo "ERROR: Toolchain compiler not found"
233        echo "It seems you do not have the correct $tc toolchain binaries."
234        echo "This may be the result of incorrect unzipping of the NDK archive."
235        echo "Please go to the official Android NDK web site and download the"
236        echo "appropriate NDK package for your platform ($HOST_TAG)."
237        echo "See http://developer.android.com/sdk/index.html"
238        echo ""
239        echo "ABORTING."
240        echo ""
241        exit 1
242    fi
243done
244
245echo ""
246echo "Host setup complete. Please read docs/OVERVIEW.TXT if you don't know what to do."
247echo ""
248