1 #!/bin/sh 2 # 3 # Copyright (C) 2011 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 # dev-platform-expand.sh 18 # 19 # This tool is used to expand the content of development/ndk/platforms 20 # into a _single_ directory containing all headers / libraries corresponding 21 # to a given API level and architecture. 22 # 23 # The idea is that the content of $SRC/android-N/ only contains stuff 24 # that is relevant to API level N, and not contain anything that is already 25 # provided by API level N-1, N-2, etc.. 26 # 27 # More precisely, for each architecture A: 28 # $SRC/android-N/include --> $DST/android-N/arch-A/usr/include 29 # $SRC/android-N/arch-A/include --> $DST/android-N/arch-A/usr/include 30 # $SRC/android-N/arch-A/lib --> $DST/android-N/arch-A/usr/lib 31 # 32 # If we target level $API, we're going to copy the contents of android-3 to 33 # android-$API to the destination directory. 34 # 35 36 . `dirname $0`/prebuilt-common.sh 37 38 # Return the list of platform supported from $1/platforms 39 # as a single space-separated list of levels. (e.g. "3 4 5 8 9") 40 # $1: source directory 41 extract_platforms_from () 42 { 43 local RET 44 if [ -d "$1" ] ; then 45 RET=$((cd "$1/platforms" && ls -d android-*) | sed -e "s!android-!!" | sort -g) 46 else 47 RET="" 48 fi 49 RET=$(echo $RET) # converts newlines to spaces 50 echo $RET 51 } 52 53 # The default platform is the last entry in the API_LEVELS default variable 54 PLATFORM=android-$(echo $API_LEVELS | tr ' ' '\n' | tail -1) 55 register_var_option "--platform=<level>" PLATFORM "Target API level" 56 57 # We take by default stuff from $NDK/../development/ndk 58 SRCDIR="$(cd $ANDROID_NDK_ROOT/../development/ndk/platforms && pwd)" 59 register_var_option "--src-dir=<path>" SRCDIR "Source for compressed platforms" 60 61 # The default destination directory is a temporary one 62 DSTDIR=/tmp/ndk-$USER/platforms 63 register_var_option "--dst-dir=<path>" DSTDIR "Destination directory" 64 65 # Default architecture, note we can have several ones here 66 ARCHS=$(find_ndk_unknown_archs) 67 ARCHS="$DEFAULT_ARCHS $ARCHS" 68 register_var_option "--arch=<name>" ARCHS "List of target architectures" 69 70 PROGRAM_PARAMETERS="" 71 72 PROGRAM_DESCRIPTION=\ 73 "Uncompress the platform files (headers/libraries) correspond to a given 74 platform into a single directory. The main idea is that the files are stored 75 in a platform-specific way under SRC=$$NDK/../development/ndk, i.e.: 76 77 \$SRC/platforms/android-3/ -> all files corresponding to API level 3 78 \$SRC/platforms/android-4/ -> only new/modified files corresponding to API level 4 79 \$SRC/platforms/android-5/ -> only new/modified files corresponding to API level 5 80 ... 81 82 As an example, expanding android-5 would mean: 83 84 1 - copy all files from android-3 to \$DST directory 85 86 2 - copy all files from android-4 to \$DST, eventually overwriting stuff 87 from android-3 that was modified in API level 4 88 89 3 - copy all files from android-5 to \$DST, eventually overwriting stuff 90 from android-4 that was modified in API level 5 91 92 The script 'dev-platform-compress.sh' can be used to perform the opposite 93 operation, and knows which files are part of which API level. 94 " 95 96 extract_parameters "$@" 97 98 # Check source directory 99 if [ ! -d "$SRCDIR" ] ; then 100 echo "ERROR: Source directory doesn't exist: $SRCDIR" 101 exit 1 102 fi 103 if [ ! -d "$SRCDIR/android-3" ]; then 104 echo "ERROR: Source directory doesn't seem to be valid: $SRCDIR" 105 exit 1 106 fi 107 log "Using source directory: $SRCDIR" 108 109 # Check platform (normalize it, i.e. android-9 -> 9} 110 PLATFORM=${PLATFORM##android-} 111 if [ ! -d "$SRCDIR/android-$PLATFORM" ]; then 112 echo "ERROR: Platform directory doesn't exist: $SRCDIR/android-$PLATFORM" 113 exit 1 114 fi 115 log "Using platform: $PLATFORM" 116 117 if [ ! -d "$DSTDIR" ]; then 118 mkdir -p "$DSTDIR" 119 if [ $? != 0 ]; then 120 echo "ERROR: Could not create destination directory: $DSTDIR" 121 exit 1 122 fi 123 fi 124 log "Using destination directory: $DSTDIR" 125 126 # Handle architecture list 127 # 128 # We support both --arch and --abi for backwards compatibility reasons 129 # --arch is the new hotness, --abi is deprecated. 130 # 131 if [ -n "$OPTION_ARCH" ]; then 132 OPTION_ARCH=$(commas_to_spaces $OPTION_ARCH) 133 fi 134 135 if [ -n "$OPTION_ABI" ] ; then 136 echo "WARNING: --abi=<names> is deprecated. Use --arch=<names> instead!" 137 OPTION_ABI=$(commas_to_spaces $OPTION_ABI) 138 if [ -n "$OPTION_ARCH" -a "$OPTION_ARCH" != "$OPTION_ABI" ]; then 139 echo "ERROR: You can't use both --abi and --arch with different values!" 140 exit 1 141 fi 142 OPTION_ARCH=$OPTION_ABI 143 fi 144 145 ARCHS=$(commas_to_spaces $ARCHS) 146 log "Using architectures: $(commas_to_spaces $ARCHS)" 147 148 # log "Checking source platform architectures." 149 # BAD_ARCHS= 150 # for ARCH in $ARCHS; do 151 # eval CHECK_$ARCH=no 152 # done 153 # for ARCH in $ARCHS; do 154 # DIR="$SRCDIR/android-$PLATFORM/arch-$ARCH" 155 # if [ -d $DIR ] ; then 156 # log " $DIR" 157 # eval CHECK_$ARCH=yes 158 # fi 159 # done 160 # 161 # BAD_ARCHS= 162 # for ARCH in $ARCHS; do 163 # CHECK=`var_value CHECK_$ARCH` 164 # log " $ARCH check: $CHECK" 165 # if [ "$CHECK" = no ] ; then 166 # if [ -z "$BAD_ARCHS" ] ; then 167 # BAD_ARCHS=$ARCH 168 # else 169 # BAD_ARCHS="$BAD_ARCHS $ARCH" 170 # fi 171 # fi 172 # done 173 # 174 # if [ -n "$BAD_ARCHS" ] ; then 175 # echo "ERROR: Source directory doesn't support these ARCHs: $BAD_ARCHS" 176 # exit 3 177 # fi 178 179 copy_optional_directory () 180 { 181 if [ -d "$1" ]; then 182 copy_directory "$1" "$2" 183 fi 184 } 185 186 # Copy platform sysroot and samples into your destination 187 # 188 189 # $SRC/android-$PLATFORM/include --> $DST/platforms/android-$PLATFORM/arch-$ARCH/usr/include 190 # $SRC/android-$PLATFORM/arch-$ARCH/include --> $DST/platforms/android-$PLATFORM/arch-$ARCH/usr/include 191 # for compatibility: 192 # $SRC/android-$PLATFORM/arch-$ARCH/usr/include --> $DST/platforms/android-$PLATFORM/arch-$ARCH/usr/include 193 194 195 196 # $SRC/android-$PLATFORM/arch-$ARCH/usr --> $DST/platforms/android-$PLATFORM/arch-$ARCH/usr 197 # $SRC/android-$PLATFORM/samples --> $DST/samples 198 # 199 for LEVEL in $API_LEVELS; do 200 if [ "$LEVEL" -gt "$PLATFORM" ]; then 201 break 202 fi 203 log "Copying android-$LEVEL platform files" 204 for ARCH in $ARCHS; do 205 SDIR="$SRCDIR/android-$LEVEL" 206 DDIR="$DSTDIR/android-$PLATFORM" 207 if [ -d "$SDIR" ]; then 208 copy_directory "$SDIR/include" "$DDIR/include" 209 fi 210 ARCH_SDIR="$SDIR/arch-$ARCH" 211 ARCH_DDIR="$DDIR/arch-$ARCH" 212 if [ -d "$ARCH_SDIR" ]; then 213 copy_optional_directory "$ARCH_SDIR/include" "$ARCH_DDIR/include" 214 copy_optional_directory "$ARCH_SDIR/lib" "$ARCH_DDIR/lib" 215 rm -f "$ARCH_DDIR"/lib/*.so 216 copy_optional_directory "$ARCH_SDIR/symbols" "$ARCH_DDIR/symbols" 217 rm -f "$ARCH_DDIR"/symbols/*.so.txt 218 fi 219 done 220 done 221 222 log "Done !" 223 exit 0 224