naclbuild.sh (2516B)
1#!/bin/bash 2if [ -z "$1" ] && [ -z "$NACL_SDK_ROOT" ]; then 3 echo "Usage: ./naclbuild ~/nacl/pepper_35" 4 echo "This will build SDL for Native Client, and testgles2.c as a demo" 5 echo "You can set env vars CC, AR, LD and RANLIB to override the default PNaCl toolchain used" 6 echo "You can set env var SOURCES to select a different source file than testgles2.c" 7 exit 1 8fi 9 10if [ -n "$1" ]; then 11 NACL_SDK_ROOT="$1" 12fi 13 14CC="" 15 16if [ -n "$2" ]; then 17 CC="$2" 18fi 19 20echo "Using SDK at $NACL_SDK_ROOT" 21 22export NACL_SDK_ROOT="$NACL_SDK_ROOT" 23export CFLAGS="$CFLAGS -I$NACL_SDK_ROOT/include -I$NACL_SDK_ROOT/include/pnacl" 24 25NCPUS="1" 26case "$OSTYPE" in 27 darwin*) 28 NCPU=`sysctl -n hw.ncpu` 29 ;; 30 linux*) 31 if [ -n `which nproc` ]; then 32 NCPUS=`nproc` 33 fi 34 ;; 35 *);; 36esac 37 38CURDIR=`pwd -P` 39SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )" 40BUILDPATH="$SDLPATH/build/nacl" 41TESTBUILDPATH="$BUILDPATH/test" 42SDL2_STATIC="$BUILDPATH/build/.libs/libSDL2.a" 43mkdir -p $BUILDPATH 44mkdir -p $TESTBUILDPATH 45 46if [ -z "$CC" ]; then 47 export CC="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-clang" 48fi 49if [ -z "$AR" ]; then 50 export AR="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ar" 51fi 52if [ -z "$LD" ]; then 53 export LD="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ar" 54fi 55if [ -z "$RANLIB" ]; then 56 export RANLIB="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ranlib" 57fi 58 59if [ -z "$SOURCES" ]; then 60 export SOURCES="$SDLPATH/test/testgles2.c" 61fi 62 63if [ ! -f "$CC" ]; then 64 echo "Could not find compiler at $CC" 65 exit 1 66fi 67 68 69 70 71cd $BUILDPATH 72$SDLPATH/configure --host=pnacl --prefix $TESTBUILDPATH 73make -j$NCPUS CFLAGS="$CFLAGS -I./include" 74make install 75 76if [ ! -f "$SDL2_STATIC" ]; then 77 echo "Build failed! $SDL2_STATIC" 78 exit 1 79fi 80 81echo "Building test" 82cp -f $SDLPATH/test/nacl/* $TESTBUILDPATH 83# Some tests need these resource files 84cp -f $SDLPATH/test/*.bmp $TESTBUILDPATH 85cp -f $SDLPATH/test/*.wav $TESTBUILDPATH 86cp -f $SDL2_STATIC $TESTBUILDPATH 87 88# Copy user sources 89_SOURCES=($SOURCES) 90for src in "${_SOURCES[@]}" 91do 92 cp $src $TESTBUILDPATH 93done 94export SOURCES="$SOURCES" 95 96cd $TESTBUILDPATH 97make -j$NCPUS CONFIG="Release" CFLAGS="$CFLAGS -I$TESTBUILDPATH/include/SDL2 -I$SDLPATH/include" 98make -j$NCPUS CONFIG="Debug" CFLAGS="$CFLAGS -I$TESTBUILDPATH/include/SDL2 -I$SDLPATH/include" 99 100echo 101echo "Run the test with: " 102echo "cd $TESTBUILDPATH;python -m SimpleHTTPServer" 103echo "Then visit http://localhost:8000 with Chrome" 104 105cd $CURDIR