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 "data") 28 return 0 29 ;; 30 *) 31 echo "ERROR: Unknown '$FILE_TYPE' file type" >&2 32 return 2 33 ;; 34 esac 35 } 36 37 # Check that libfoo.a is a thin archive 38 LIBFOO_LIST=$(find obj/local -name "libfoo.a") 39 EXIT_CODE=0 40 for LIB in $LIBFOO_LIST; do 41 LIB_TYPE=$(get_file_type "$LIB") 42 if is_file_type_thin_archive "$LIB_TYPE"; then 43 echo "OK: $LIB is a thin archive ('$LIB_TYPE')." 44 else 45 echo "ERROR: $LIB is not a thin archive: '$LIB_TYPE'" 46 EXIT_CODE=1 47 fi 48 done 49 50 # Check that libbar.a is not a thin archive 51 LIBBAR_LIST=$(find obj/local -name "libbar.a") 52 for LIB in $LIBBAR_LIST; do 53 LIB_TYPE=$(get_file_type "$LIB") 54 if is_file_type_thin_archive "$LIB_TYPE"; then 55 echo "ERROR: $LIB is not a regular archive: '$LIB_TYPE'" 56 EXIT_CODE=1 57 else 58 echo "OK: $LIB is a regular archive: '$LIB_TYPE'" 59 fi 60 done 61 62 exit $EXIT_CODE 63