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