1 #!/bin/bash 2 3 function exportVar { 4 NAME=$1 5 VALUE=$2 6 echo export $NAME=\"$VALUE\" 7 export $NAME="$VALUE" 8 } 9 10 function setenv { 11 if [ -z "$1" ]; then 12 echo "ERROR: setenv() requires one argument." 13 exit 1 14 fi 15 if [ -z "${NACL_SDK_ROOT}" ]; then 16 echo "ERROR: This script requires NACL_SDK_ROOT to be set." 17 exit 1 18 fi 19 20 ARCH_WIDTH=$1 21 if [ ${ARCH_WIDTH} = "32" ]; then 22 CROSS_ID=i686 23 elif [ ${ARCH_WIDTH} = "64" ]; then 24 CROSS_ID=x86_64 25 else 26 echo "ERROR: Unknown arch width: ${ARCH_WIDTH}" 27 exit 1 28 fi 29 30 OS_NAME=$(uname -s) 31 if [ $OS_NAME = "Darwin" ]; then 32 OS_SUBDIR="mac" 33 OS_SUBDIR_SHORT="mac" 34 OS_JOBS=4 35 elif [ $OS_NAME = "Linux" ]; then 36 OS_SUBDIR="linux" 37 OS_SUBDIR_SHORT="linux" 38 OS_JOBS=4 39 else 40 OS_SUBDIR="windows" 41 OS_SUBDIR_SHORT="win" 42 OS_JOBS=1 43 fi 44 45 NACL_TOOLCHAIN_ROOT=${NACL_SDK_ROOT}/toolchain/${OS_SUBDIR_SHORT}_x86_newlib 46 NACL_BIN_PATH=${NACL_TOOLCHAIN_ROOT}/bin 47 export NACL_CROSS_PREFIX=${CROSS_ID}-nacl 48 49 if [[ -z "$NACL_MAKE_CCACHE" ]]; then 50 exportVar NACLCC ${NACL_BIN_PATH}/${NACL_CROSS_PREFIX}-gcc 51 exportVar NACLCXX ${NACL_BIN_PATH}/${NACL_CROSS_PREFIX}-g++ 52 else 53 exportVar NACLCC "${NACL_MAKE_CCACHE} ${NACL_BIN_PATH}/${NACL_CROSS_PREFIX}-gcc" 54 exportVar NACLCXX "${NACL_MAKE_CCACHE} ${NACL_BIN_PATH}/${NACL_CROSS_PREFIX}-g++" 55 fi 56 exportVar NACLAR ${NACL_BIN_PATH}/${NACL_CROSS_PREFIX}-ar 57 exportVar NACLRANLIB ${NACL_BIN_PATH}/${NACL_CROSS_PREFIX}-ranlib 58 exportVar NACLLD ${NACL_BIN_PATH}/${NACL_CROSS_PREFIX}-ld 59 exportVar NACLSTRINGS ${NACL_BIN_PATH}/${NACL_CROSS_PREFIX}-strings 60 exportVar NACLSTRIP ${NACL_BIN_PATH}/${NACL_CROSS_PREFIX}-strip 61 62 exportVar CC "${NACLCC}" 63 exportVar CXX "${NACLCXX}" 64 exportVar AR "${NACLAR}" 65 exportVar RANLIB "${NACLRANLIB}" 66 exportVar PATH ${NACL_BIN_PATH}:${PATH}; 67 exportVar C_INCLUDE_PATH "${NACL_SDK_ROOT}/include:${NACL_SDK_ROOT}/ports/include:${C_INCLUDE_PATH}" 68 exportVar CPLUS_INCLUDE_PATH "${NACL_SDK_ROOT}/include:${NACL_SDK_ROOT}/ports/include:${CPLUS_INCLUDE_PATH}" 69 exportVar GYP_DEFINES "skia_os=nacl skia_gpu=0 skia_arch_width=${ARCH_WIDTH}" 70 } 71 72 function build { 73 if [ -z "$1" ]; then 74 echo "ERROR: build() requires one argument." 75 exit 1 76 fi 77 setenv $1 78 79 export SKIA_OUT=out/nacl$1 80 make ${MAKE_ARGS} 81 } 82 83 MAKE_ARGS="" 84 85 while (( "$#" )); do 86 if [[ "$1" == "--use-ccache" ]]; 87 then 88 if [[ -z "$NACL_MAKE_CCACHE" ]]; 89 then 90 NACL_MAKE_CCACHE=$(which ccache) 91 fi 92 elif [ -z "${MAKE_ARGS}" ]; then 93 MAKE_ARGS="$1" 94 else 95 MAKE_ARGS="${MAKE_ARGS} $1" 96 fi 97 shift 98 done 99 100 if [[ -n "$NACL_MAKE_CCACHE" ]]; then 101 $NACL_MAKE_CCACHE --version &> /dev/null 102 if [[ "$?" != "0" ]]; then 103 echo "Unable to find ccache!" 104 exit 1 105 fi 106 fi 107 108 build 32 && \ 109 build 64 && \ 110 if ! [ -L platform_tools/nacl/out ]; then 111 ln -s ../../out platform_tools/nacl 112 fi