Home | History | Annotate | Download | only in conscrypt
      1 #!/usr/bin/env bash
      2 
      3 if (( BASH_VERSINFO[0] < 3 )); then
      4   echo "Must be running BASH version 3 or newer!"
      5   exit 1
      6 fi
      7 
      8 if [[ -z $TOP ]]; then \
      9   echo "You must do envsetup beforehand."
     10   exit 1
     11 fi
     12 
     13 # We are currently in frameworks/rs, so compute our top-level directory.
     14 MY_ANDROID_DIR="$TOP"
     15 cd "$MY_ANDROID_DIR"
     16 
     17 if [[ $OSTYPE != *linux* ]]; then \
     18   echo "Only works on Linux."
     19   exit 1
     20 fi
     21 
     22 SHORT_OSNAME=linux
     23 SONAME=so
     24 # Target architectures and their system library names.
     25 declare -a TARGETS=(generic_armv5 aosp_arm aosp_mips aosp_x86)
     26 declare -a ABI_NAMES=(armeabi armeabi-v7a mips x86)
     27 declare -a SYS_NAMES=(generic_armv5 generic generic_mips generic_x86)
     28 declare -i NUM_CORES="$(awk '/^processor/ { i++ } END { print i }' /proc/cpuinfo)"
     29 
     30 echo "Using $NUM_CORES cores"
     31 
     32 # Turn off the build cache and make sure we build all of LLVM from scratch.
     33 #export ANDROID_USE_BUILDCACHE=false
     34 
     35 # PREBUILTS_DIR is where we want to copy our new files to.
     36 PREBUILTS_DIR="$MY_ANDROID_DIR/prebuilts/conscrypt/"
     37 
     38 print_usage() {
     39   echo "USAGE: $0 [-h|--help] [-n|--no-build] [-x]"
     40   echo "OPTIONS:"
     41   echo "    -h, --help     : Display this help message."
     42   echo "    -n, --no-build : Skip the build step and just copy files."
     43   echo "    -x             : Display commands before they are executed."
     44 }
     45 
     46 build_libs() {
     47   local t="$1"
     48   echo Building for target $t
     49   cd $MY_ANDROID_DIR
     50   WITH_HOST_DALVIK=false make -j32 PRODUCT-$t-userdebug APP-conscrypt_unbundled-libconscrypt_jni || exit 1
     51 }
     52 
     53 # Build everything by default
     54 build_me=1
     55 
     56 while [[ $# -gt 0 ]]; do
     57   case "$1" in
     58     -h|--help)
     59       print_usage
     60       exit 0
     61       ;;
     62     -n|--no-build)
     63       build_me=0
     64       ;;
     65     -x)
     66       # set lets us enable bash -x mode.
     67       set -x
     68       ;;
     69     *)
     70       echo Unknown argument: "$1"
     71       print_usage
     72       exit 99
     73       break
     74       ;;
     75   esac
     76   shift
     77 done
     78 
     79 declare -i i
     80 
     81 if [ $build_me -eq 1 ]; then
     82 
     83   echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     84   echo !!! BUILDING CONSCRYPT PREBUILTS !!!
     85   echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     86 
     87   source build/envsetup.sh
     88 
     89   for (( i=0; i < ${#TARGETS[@]}; i++ )); do
     90     build_libs "${TARGETS[$i]}"
     91   done
     92 
     93   echo DONE BUILDING CONSCRYPT PREBUILTS
     94 
     95 else
     96 
     97   echo SKIPPING BUILD OF CONSCRYPT PREBUILTS
     98 
     99 fi
    100 
    101 DATE="$(date +"%Y%m%d")"
    102 
    103 cd "$PREBUILTS_DIR" || exit 3
    104 repo start "pb_$DATE" .
    105 
    106 # Don't copy device prebuilts on Darwin. We don't need/use them.
    107 for (( i=0; i < ${#TARGETS[@]}; i++ )); do
    108   sys="${SYS_NAMES[$i]}"
    109   abi="${ABI_NAMES[$i]}"
    110   sys_lib_dir="$MY_ANDROID_DIR/out/target/product/$sys/system/lib"
    111   if [[ ! -d "jni/$abi" ]]; then
    112     mkdir -p "jni/$abi"
    113   fi
    114   cp "$sys_lib_dir/libconscrypt_jni.so" "jni/$abi/" || exit 4
    115 done
    116 
    117 # javalib.jar
    118 cp "$MY_ANDROID_DIR/out/target/common/obj/JAVA_LIBRARIES/conscrypt_unbundled_intermediates/classes.jar" .
    119