Home | History | Annotate | Download | only in tools
      1 #!/bin/sh
      2 #
      3 # Copyright (C) 2012 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 copy clang tool "scan-build" and "scan-view"
     18 #  for the Android NDK.
     19 #
     20 
     21 # include common function and variable definitions
     22 . `dirname $0`/prebuilt-common.sh
     23 
     24 PROGRAM_PARAMETERS="<src-dir> <ndk-dir> <toolchain>"
     25 
     26 PROGRAM_DESCRIPTION=\
     27 "Copy clang static code analyzer for the Android NDK.
     28 
     29 Where <src-dir> is the location of toolchain sources, <ndk-dir> is
     30 the top-level NDK installation path and <toolchain> is the name of
     31 the toolchain to use (e.g. llvm-3.1)."
     32 
     33 RELEASE=`date +%Y%m%d`
     34 
     35 PACKAGE_DIR=
     36 register_var_option "--package-dir=<path>" PACKAGE_DIR "Create archive tarball in specific directory"
     37 
     38 extract_parameters "$@"
     39 
     40 set_parameters ()
     41 {
     42     SRC_DIR="$1"
     43     NDK_DIR="$2"
     44     TOOLCHAIN="$3"
     45 
     46     # Check source directory
     47     #
     48     if [ -z "$SRC_DIR" ] ; then
     49         echo "ERROR: Missing source directory parameter. See --help for details."
     50         exit 1
     51     fi
     52 
     53     SCAN_BUILD_SRC_DIR=$SRC_DIR/$TOOLCHAIN/clang/tools/scan-build
     54     if [ ! -d "$SCAN_BUILD_SRC_DIR" ] ; then
     55         echo "ERROR: Source directory does not contain scan-build: $SCAN_BUILD_SRC_DIR"
     56         exit 1
     57     fi
     58 
     59     SCAN_VIEW_SRC_DIR=$SRC_DIR/$TOOLCHAIN/clang/tools/scan-view
     60     if [ ! -d "$SCAN_VIEW_SRC_DIR" ] ; then
     61         echo "ERROR: Source directory does not contain scan-view: $SCAN_VIEW_SRC_DIR"
     62         exit 1
     63     fi
     64 
     65     LICENSE_FILE=$SRC_DIR/$TOOLCHAIN/clang/LICENSE.TXT
     66     if [ ! -f "$LICENSE_FILE" ] ; then
     67         echo "ERROR: Source directory does not contain clang license file: $LICENSE_FILE"
     68         exit 1
     69     fi
     70 
     71     log "Using source directory: $SRC_DIR"
     72 
     73     # Check NDK installation directory
     74     #
     75     if [ -z "$NDK_DIR" ] ; then
     76         echo "ERROR: Missing NDK directory parameter. See --help for details."
     77         exit 1
     78     fi
     79 
     80     if [ ! -d "$NDK_DIR" ] ; then
     81         mkdir -p $NDK_DIR
     82         fail_panic "Could not create target NDK installation path: $NDK_DIR"
     83     fi
     84 
     85     log "Using NDK directory: $NDK_DIR"
     86 
     87     # Check toolchain name
     88     #
     89     if [ -z "$TOOLCHAIN" ] ; then
     90         echo "ERROR: Missing toolchain name parameter. See --help for details."
     91         exit 1
     92     fi
     93 }
     94 
     95 set_parameters $PARAMETERS
     96 
     97 if [ "$PACKAGE_DIR" ]; then
     98     mkdir -p "$PACKAGE_DIR"
     99     fail_panic "Could not create package directory: $PACKAGE_DIR"
    100 fi
    101 
    102 # copy scan_build and scan_view
    103 SCAN_BUILD_SUBDIR="prebuilt/common/scan-build"
    104 run copy_directory "$SCAN_BUILD_SRC_DIR" "$NDK_DIR/$SCAN_BUILD_SUBDIR"
    105 cp -p "$LICENSE_FILE" "$NDK_DIR/$SCAN_BUILD_SUBDIR"
    106 rm -f $NDK_DIR/$SCAN_BUILD_SUBDIR/scan-build.1
    107 
    108 SCAN_VIEW_SUBDIR="prebuilt/common/scan-view"
    109 run copy_directory "$SCAN_VIEW_SRC_DIR" "$NDK_DIR/$SCAN_VIEW_SUBDIR"
    110 cp -p "$LICENSE_FILE" "$NDK_DIR/$SCAN_VIEW_SUBDIR"
    111 
    112 if [ "$PACKAGE_DIR" ]; then
    113     ARCHIVE="scan-build-view.tar.bz2"
    114     dump "Packaging $ARCHIVE"
    115     pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SCAN_BUILD_SUBDIR" "$SCAN_VIEW_SUBDIR"
    116 fi
    117 
    118 dump "Done."
    119