Home | History | Annotate | Download | only in tools
      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 
     20 PROGDIR=$(dirname $0)
     21 . $PROGDIR/prebuilt-common.sh
     22 
     23 PROGRAM_PARAMETERS="<src-dir>"
     24 
     25 PROGRAM_DESCRIPTION=\
     26 "Rebuild the host perl used by the Android NDK.
     27 
     28 Where <src-dir> is the location of toolchain sources."
     29 
     30 register_try64_option
     31 register_canadian_option
     32 register_jobs_option
     33 
     34 BUILD_OUT=/tmp/ndk-$USER/build/perl
     35 OPTION_BUILD_OUT=
     36 register_var_option "--build-out=<path>" OPTION_BUILD_OUT "Set temporary build directory"
     37 
     38 NDK_DIR=$ANDROID_NDK_ROOT
     39 register_var_option "--ndk-dir=<path>" NDK_DIR "Specify NDK install directory"
     40 
     41 PACKAGE_DIR=
     42 register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive to package directory"
     43 
     44 CHECK=no
     45 do_check_option () { CHECK=yes; }
     46 register_option "--check" do_check_option "Check Perl"
     47 
     48 extract_parameters "$@"
     49 
     50 SUBDIR=$(get_prebuilt_install_prefix)
     51 BIN_OUT="$SUBDIR/bin/perl${HOST_EXE}"
     52 LIB_OUT="$SUBDIR/lib/perl5"
     53 
     54 fix_option BUILD_OUT "$OPTION_BUILD_OUT" "build directory"
     55 
     56 PERL_VERSION=$DEFAULT_PERL_VERSION
     57 
     58 set_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 
     78 set_parameters $PARAMETERS
     79 
     80 prepare_host_build
     81 
     82 if [ "$MINGW" != "yes" -a "$DARWIN" != "yes" ] ; then
     83     dump "Using C compiler: $CC"
     84     dump "Using C++ compiler: $CXX"
     85 fi
     86 
     87 log "Configuring the build"
     88 mkdir -p $BUILD_OUT && rm -rf $BUILD_OUT/*
     89 prepare_canadian_toolchain $BUILD_OUT
     90 
     91 run copy_directory "$SRC_DIR/perl/perl-$PERL_VERSION" "$BUILD_OUT"
     92 fail_panic "Could not copy perl source $SRC_DIR/perl/perl-$PERL_VERSION to build directory $BUILD_OUT"
     93 
     94 LIBS_SEARCH=`$CC -print-search-dirs | grep libraries | sed ' s/^.*=// ' | sed ' s/:/ /g '`
     95 
     96 cd $BUILD_OUT &&
     97 CFLAGS=$HOST_CFLAGS" -O2 -s" &&
     98 run ./Configure \
     99     -des \
    100     -Dprefix=$BUILD_OUT/prefix \
    101     -Dcc="$CC" \
    102     -Dcc_as_ld \
    103     -Dccflags="$CFLAGS" \
    104     -A prepend:libpth="$LIBS_SEARCH"
    105 fail_panic "Failed to configure the perl-$PERL_VERSION build!"
    106 
    107 log "Building perl"
    108 run make -j $NUM_JOBS
    109 fail_panic "Failed to build perl-$PERL_VERSION!"
    110 
    111 if [ "$CHECK" = "yes" ]; then
    112     log "Checking perl"
    113     run make check
    114     fail_warning "Failed to check perl-$PERL_VERSION!"
    115 fi
    116 
    117 log "Installing perl"
    118 run make install
    119 fail_panic "Failed to install perl-$PERL_VERSION!"
    120 
    121 log "Copying executable to prebuilt location"
    122 run copy_file_list "$BUILD_OUT/prefix/bin" $(dirname "$NDK_DIR/$BIN_OUT") perl
    123 fail_panic "Could not copy executable to: $NDK_DIR/$BIN_OUT"
    124 
    125 log "Copying library to prebuilt location"
    126 run copy_directory "$BUILD_OUT/prefix/lib" "$NDK_DIR/$LIB_OUT"
    127 fail_panic "Could not copy library to: $NDK_DIR/$LIB_OUT"
    128 
    129 if [ "$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"
    135 fi
    136 
    137 log "Cleaning up"
    138 if [ -z "$OPTION_BUILD_OUT" ] ; then
    139    rm -rf $BUILD_OUT
    140 fi
    141 
    142 log "Done."
    143 
    144