build-scripts/naclbuild.sh
changeset 8833 ae720d61d14d
child 8877 0d691f3734ac
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build-scripts/naclbuild.sh	Fri Jun 06 15:45:59 2014 -0300
     1.3 @@ -0,0 +1,105 @@
     1.4 +#!/bin/bash
     1.5 +if [ -z "$1" ] && [ -z "$NACL_SDK_ROOT" ]; then
     1.6 +    echo "Usage: ./naclbuild ~/nacl/pepper_33"
     1.7 +    echo "This will build SDL for Native Client, and testgles2.c as a demo"
     1.8 +    echo "You can set env vars CC, AR, LD and RANLIB to override the default PNaCl toolchain used"
     1.9 +    echo "You can set env var SOURCES to select a different source file than testgles2.c"
    1.10 +    exit 1
    1.11 +fi
    1.12 +
    1.13 +if [ -n "$1" ]; then
    1.14 +    NACL_SDK_ROOT="$1"
    1.15 +fi
    1.16 +
    1.17 +CC=""
    1.18 +
    1.19 +if [ -n "$2" ]; then
    1.20 +    CC="$2"
    1.21 +fi
    1.22 +
    1.23 +echo "Using SDK at $NACL_SDK_ROOT"
    1.24 +
    1.25 +export NACL_SDK_ROOT="$NACL_SDK_ROOT"
    1.26 +export CFLAGS="$CFLAGS -I$NACL_SDK_ROOT/include"
    1.27 +
    1.28 +NCPUS="1"
    1.29 +case "$OSTYPE" in
    1.30 +    darwin*)
    1.31 +        NCPU=`sysctl -n hw.ncpu`
    1.32 +        ;; 
    1.33 +    linux*)
    1.34 +        if [ -n `which nproc` ]; then
    1.35 +            NCPUS=`nproc`
    1.36 +        fi  
    1.37 +        ;;
    1.38 +  *);;
    1.39 +esac
    1.40 +
    1.41 +CURDIR=`pwd -P`
    1.42 +SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
    1.43 +BUILDPATH="$SDLPATH/build/nacl"
    1.44 +TESTBUILDPATH="$BUILDPATH/test"
    1.45 +SDL2_STATIC="$BUILDPATH/build/.libs/libSDL2.a"
    1.46 +mkdir -p $BUILDPATH
    1.47 +mkdir -p $TESTBUILDPATH
    1.48 +
    1.49 +if [ -z "$CC" ]; then
    1.50 +    export CC="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-clang"
    1.51 +fi
    1.52 +if [ -z "$AR" ]; then
    1.53 +    export AR="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ar"
    1.54 +fi
    1.55 +if [ -z "$LD" ]; then
    1.56 +    export LD="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ar"
    1.57 +fi
    1.58 +if [ -z "$RANLIB" ]; then
    1.59 +    export RANLIB="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ranlib"
    1.60 +fi
    1.61 +
    1.62 +if [ -z "$SOURCES" ]; then
    1.63 +    export SOURCES="$SDLPATH/test/testgles2.c"
    1.64 +fi
    1.65 +
    1.66 +if [ ! -f "$CC" ]; then
    1.67 +    echo "Could not find compiler at $CC"
    1.68 +    exit 1
    1.69 +fi
    1.70 +
    1.71 +
    1.72 +
    1.73 +
    1.74 +cd $BUILDPATH
    1.75 +$SDLPATH/configure --host=pnacl --prefix $TESTBUILDPATH
    1.76 +make -j$NCPUS CFLAGS="$CFLAGS -I./include"
    1.77 +make install
    1.78 +
    1.79 +if [ ! -f "$SDL2_STATIC" ]; then
    1.80 +    echo "Build failed! $SDL2_STATIC"
    1.81 +    exit 1
    1.82 +fi
    1.83 +
    1.84 +echo "Building test"
    1.85 +cp -f $SDLPATH/test/nacl/* $TESTBUILDPATH
    1.86 +# Some tests need these resource files
    1.87 +cp -f $SDLPATH/test/*.bmp $TESTBUILDPATH
    1.88 +cp -f $SDLPATH/test/*.wav $TESTBUILDPATH
    1.89 +cp -f $SDL2_STATIC $TESTBUILDPATH
    1.90 +
    1.91 +# Copy user sources
    1.92 +_SOURCES=($SOURCES)
    1.93 +for src in "${_SOURCES[@]}"
    1.94 +do
    1.95 +    cp $src $TESTBUILDPATH
    1.96 +done
    1.97 +export SOURCES="$SOURCES"
    1.98 +
    1.99 +cd $TESTBUILDPATH
   1.100 +make -j$NCPUS CONFIG="Release" CFLAGS="$CFLAGS -I$TESTBUILDPATH/include/SDL2 -I$SDLPATH/include"
   1.101 +make -j$NCPUS CONFIG="Debug" CFLAGS="$CFLAGS -I$TESTBUILDPATH/include/SDL2 -I$SDLPATH/include"
   1.102 +
   1.103 +echo
   1.104 +echo "Run the test with: "
   1.105 +echo "cd $TESTBUILDPATH;python -m SimpleHTTPServer"
   1.106 +echo "Then visit http://localhost:8000 with Chrome"
   1.107 +
   1.108 +cd $CURDIR