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 24PROGRAM_PARAMETERS="<src-dir> <ndk-dir> <toolchain>" 25 26PROGRAM_DESCRIPTION=\ 27"Copy clang static code analyzer for the Android NDK. 28 29Where <src-dir> is the location of toolchain sources, <ndk-dir> is 30the top-level NDK installation path and <toolchain> is the name of 31the toolchain to use (e.g. llvm-3.1)." 32 33RELEASE=`date +%Y%m%d` 34 35PACKAGE_DIR= 36register_var_option "--package-dir=<path>" PACKAGE_DIR "Create archive tarball in specific directory" 37 38extract_parameters "$@" 39 40set_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 95set_parameters $PARAMETERS 96 97if [ "$PACKAGE_DIR" ]; then 98 mkdir -p "$PACKAGE_DIR" 99 fail_panic "Could not create package directory: $PACKAGE_DIR" 100fi 101 102# copy scan_build and scan_view 103SCAN_BUILD_SUBDIR="prebuilt/common/scan-build" 104run copy_directory "$SCAN_BUILD_SRC_DIR" "$NDK_DIR/$SCAN_BUILD_SUBDIR" 105cp -p "$LICENSE_FILE" "$NDK_DIR/$SCAN_BUILD_SUBDIR" 106rm -f $NDK_DIR/$SCAN_BUILD_SUBDIR/scan-build.1 107 108SCAN_VIEW_SUBDIR="prebuilt/common/scan-view" 109run copy_directory "$SCAN_VIEW_SRC_DIR" "$NDK_DIR/$SCAN_VIEW_SUBDIR" 110cp -p "$LICENSE_FILE" "$NDK_DIR/$SCAN_VIEW_SUBDIR" 111 112if [ "$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" 116fi 117 118dump "Done." 119