1 #!/bin/sh 2 3 $NDK/ndk-build "$@" 4 if [ $? != 0 ]; then 5 echo "ERROR: Could not build test program!" 6 exit 1 7 fi 8 9 # Return the type of a given file as returned by /usr/bin/file 10 # $1: file path 11 get_file_type () { 12 /usr/bin/file -b "$1" 2>/dev/null 13 } 14 15 # Returns success iff a given file is a thin archive. 16 # $1: file type as returned by get_file_type() 17 is_file_type_thin_archive () { 18 # The output of /usr/bin/file will depend on the OS: 19 # regular Linux -> 'current ar archive' 20 # regular Darwin -> 'current ar archive random library' 21 # thin Linux -> 'data' 22 # thin Darwin -> 'data' 23 case "$1" in 24 *"ar archive"*) 25 return 1 26 ;; 27 *"thin archive"*) 28 return 0 29 ;; 30 "data") 31 return 0 32 ;; 33 *) 34 echo "ERROR: Unknown '$FILE_TYPE' file type" >&2 35 return 2 36 ;; 37 esac 38 } 39 40 # Check that libfoo.a is a thin archive 41 LIBFOO_LIST=$(find obj/local -name "libfoo.a") 42 EXIT_CODE=0 43 for LIB in $LIBFOO_LIST; do 44 LIB_TYPE=$(get_file_type "$LIB") 45 if is_file_type_thin_archive "$LIB_TYPE"; then 46 echo "OK: $LIB is a thin archive ('$LIB_TYPE')." 47 else 48 echo "ERROR: $LIB is not a thin archive: '$LIB_TYPE'" 49 EXIT_CODE=1 50 fi 51 done 52 53 # Check that libbar.a is not a thin archive 54 LIBBAR_LIST=$(find obj/local -name "libbar.a") 55 for LIB in $LIBBAR_LIST; do 56 LIB_TYPE=$(get_file_type "$LIB") 57 if is_file_type_thin_archive "$LIB_TYPE"; then 58 echo "ERROR: $LIB is not a regular archive: '$LIB_TYPE'" 59 EXIT_CODE=1 60 else 61 echo "OK: $LIB is a regular archive: '$LIB_TYPE'" 62 fi 63 done 64 65 exit $EXIT_CODE 66