• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright (C) 2013 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# Build the host version of the perl executable and place it
18# at the right location
19
20PROGDIR=$(dirname $0)
21. $PROGDIR/prebuilt-common.sh
22
23PROGRAM_PARAMETERS="<src-dir>"
24
25PROGRAM_DESCRIPTION=\
26"Rebuild the host perl used by the Android NDK.
27
28Where <src-dir> is the location of toolchain sources."
29
30register_try64_option
31register_canadian_option
32register_jobs_option
33
34BUILD_OUT=/tmp/ndk-$USER/build/perl
35OPTION_BUILD_OUT=
36register_var_option "--build-out=<path>" OPTION_BUILD_OUT "Set temporary build directory"
37
38NDK_DIR=$ANDROID_NDK_ROOT
39register_var_option "--ndk-dir=<path>" NDK_DIR "Specify NDK install directory"
40
41PACKAGE_DIR=
42register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive to package directory"
43
44CHECK=no
45do_check_option () { CHECK=yes; }
46register_option "--check" do_check_option "Check Perl"
47
48extract_parameters "$@"
49
50SUBDIR=$(get_prebuilt_install_prefix)
51BIN_OUT="$SUBDIR/bin/perl${HOST_EXE}"
52LIB_OUT="$SUBDIR/lib/perl5"
53
54fix_option BUILD_OUT "$OPTION_BUILD_OUT" "build directory"
55
56PERL_VERSION=$DEFAULT_PERL_VERSION
57
58set_parameters ()
59{
60    SRC_DIR="$1"
61
62    # Check source directory
63    #
64    if [ -z "$SRC_DIR" ] ; then
65        echo "ERROR: Missing source directory parameter. See --help for details."
66        exit 1
67    fi
68
69    if [ ! -d "$SRC_DIR/perl/perl-$PERL_VERSION" ] ; then
70        echo "ERROR: Source directory does not contain perl sources: $SRC_DIR/perl/perl-$PERL_VERSION"
71        exit 1
72    fi
73
74    log "Using source directory: $SRC_DIR"
75
76}
77
78set_parameters $PARAMETERS
79
80prepare_host_build
81
82if [ "$MINGW" != "yes" -a "$DARWIN" != "yes" ] ; then
83    dump "Using C compiler: $CC"
84    dump "Using C++ compiler: $CXX"
85fi
86
87log "Configuring the build"
88mkdir -p $BUILD_OUT && rm -rf $BUILD_OUT/*
89prepare_canadian_toolchain $BUILD_OUT
90
91run copy_directory "$SRC_DIR/perl/perl-$PERL_VERSION" "$BUILD_OUT"
92fail_panic "Could not copy perl source $SRC_DIR/perl/perl-$PERL_VERSION to build directory $BUILD_OUT"
93
94LIBS_SEARCH=`$CC -print-search-dirs | grep libraries | sed ' s/^.*=// ' | sed ' s/:/ /g '`
95
96cd $BUILD_OUT &&
97CFLAGS=$HOST_CFLAGS" -O2 -s" &&
98run ./Configure \
99    -des \
100    -Dprefix=$BUILD_OUT/prefix \
101    -Dcc="$CC" \
102    -Dcc_as_ld \
103    -Dccflags="$CFLAGS" \
104    -A prepend:libpth="$LIBS_SEARCH"
105fail_panic "Failed to configure the perl-$PERL_VERSION build!"
106
107log "Building perl"
108run make -j $NUM_JOBS
109fail_panic "Failed to build perl-$PERL_VERSION!"
110
111if [ "$CHECK" = "yes" ]; then
112    log "Checking perl"
113    run make check
114    fail_warning "Failed to check perl-$PERL_VERSION!"
115fi
116
117log "Installing perl"
118run make install
119fail_panic "Failed to install perl-$PERL_VERSION!"
120
121log "Copying executable to prebuilt location"
122run copy_file_list "$BUILD_OUT/prefix/bin" $(dirname "$NDK_DIR/$BIN_OUT") perl
123fail_panic "Could not copy executable to: $NDK_DIR/$BIN_OUT"
124
125log "Copying library to prebuilt location"
126run copy_directory "$BUILD_OUT/prefix/lib" "$NDK_DIR/$LIB_OUT"
127fail_panic "Could not copy library to: $NDK_DIR/$LIB_OUT"
128
129if [ "$PACKAGE_DIR" ]; then
130    ARCHIVE=ndk-perl-$HOST_TAG.tar.bz2
131    dump "Packaging: $ARCHIVE"
132    mkdir -p "$PACKAGE_DIR" &&
133    pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$BIN_OUT" "$LIB_OUT"
134    fail_panic "Could not package archive: $PACKAGE_DIR/$ARCHIVE"
135fi
136
137log "Cleaning up"
138if [ -z "$OPTION_BUILD_OUT" ] ; then
139   rm -rf $BUILD_OUT
140fi
141
142log "Done."
143
144