imcplugin demo: Extend to support stat() call
[nativeclient.git] / tests / xaos / xaos_tool.sh
blob3f65fe26b16defe1c230c2b67a73a0bdec7f9016
1 #!/bin/bash
2 # Copyright 2008, Google Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #@ xaos_tool.sh
34 #@ usage: xaos_tool.sh <mode>
36 #@ this script bootstraps a nacl module for the xaos fractal rendering
37 #@ engine off the web including the gsl package it depends on.
39 #@ This works on linux only, assumes you have web access
40 #@ and that you have the typical linux tools installed
42 set -o nounset
43 set -o errexit
45 readonly SAVE_PWD=$(pwd)
47 readonly DIR_TMP=${DIR_TMP:-/tmp/nacl}
48 readonly DIR_INSTALL=${DIR_INSTALL:-/tmp/nacl}
49 readonly OS_NAME=$(uname -s)
50 if [ $OS_NAME = "Darwin" ]; then
51 readonly OS_SUBDIR="mac"
52 elif [ $OS_NAME = "Linux" ]; then
53 readonly OS_SUBDIR="linux"
54 else
55 readonly OS_SUBDIR="windows"
57 readonly NACL_SDK_BASE=${SAVE_PWD}/../../../third_party/nacl_sdk/$OS_SUBDIR/sdk/nacl-sdk/
60 readonly URL_XAOS=http://downloads.sourceforge.net/xaos/XaoS-3.4.tar.gz
61 readonly URL_GSL=http://ftp.gnu.org/pub/gnu/gsl/gsl-1.9.tar.gz
63 readonly PATCH_GSL=${SAVE_PWD}/gsl-1.9.patch
64 readonly PATCH_XAOS=${SAVE_PWD}/XaoS-3.4.patch
67 # TODO: the dimensions need a little bit of more work in the xaos patch
68 readonly NACL_DIM_W=800
69 readonly NACL_DIM_H=600
70 readonly NACLCC=${NACL_SDK_BASE}/bin/nacl-gcc
71 readonly NACLAR=${NACL_SDK_BASE}/bin/nacl-ar
72 readonly NACLRANLIB=${NACL_SDK_BASE}/bin/nacl-ranlib
73 readonly DIR_AV_LIB=${NACL_SDK_BASE}/nacl/lib
74 readonly DIR_AV_INCLUDE=${NACL_SDK_BASE}/nacl/include
77 ######################################################################
78 # Helper functions
79 ######################################################################
81 Banner() {
82 echo "######################################################################"
83 echo $*
84 echo "######################################################################"
88 Usage() {
89 egrep "^#@" $0 | cut --bytes=3-
93 ReadKey() {
94 read
98 Download() {
99 if which wget ; then
100 wget $1 -O $2
101 elif which curl ; then
102 curl --location --url $1 -o $2
103 else
104 Banner "Problem encountered"
105 echo "Please install curl or wget and rerun this script"
106 echo "or manually download $1 to $2"
107 echo
108 echo "press any key when done"
109 ReadKey
112 if [ ! -s $2 ] ; then
113 echo "ERROR: could not find $2"
114 exit -1
119 DownloadGsl() {
120 Banner "downloading gsl"
121 cd $1
122 Download $2 gsl.tgz
123 Banner "untaring and patching gsl"
124 rm -rf gsl-1.9
125 tar zxf gsl.tgz
126 patch -p0 < $3
130 # params (tmp, install)
131 BuildGsl() {
132 Banner "configuring gsl"
133 cd $1
134 export CC=${NACLCC}
135 export AR=${NACLAR}
136 export RANLIB=${NACLRANLIB}
137 export LIBS="-lm -lsrpc"
138 rm -rf gsl-build
139 mkdir gsl-build
140 cd gsl-build
141 ../gsl-1.9/configure\
142 --host=nacl\
143 --disable-shared\
144 --prefix=$2
145 Banner "building and installing gsl"
146 make
147 make install
150 # params (tmp, url, patch)
151 DownloadXaos() {
152 Banner "downloading xaos"
153 cd $1
154 Download $2 xaos.tgz
155 rm -rf XaoS-3.4
156 tar zxf xaos.tgz
157 Banner "untaring, patching and autoconfing xaos"
158 patch -p0 < $3
159 cd XaoS-3.4
160 autoconf
163 # params (tmp, install)
164 BuildXaos() {
165 Banner "configuring xaos"
166 cd $1
167 export PATH="$2/bin:${PATH}"
168 export CC=${NACLCC}
169 export AR=${NACLAR}
170 export RANLIB=${NACLRANLIB}
171 export LDFLAGS="-static"
172 export CFLAGS="-DNACL_DIM_H=${NACL_DIM_H} -DNACL_DIM_W=${NACL_DIM_W} -I${DIR_AV_INCLUDE}"
173 export LIBS="-L${DIR_AV_LIB} -lav -lsrpc -lpthread"
174 rm -rf xaos-build
175 # sadly xaos seem wants to be built in-place
176 cp -r XaoS-3.4 xaos-build
177 cd xaos-build
178 ../XaoS-3.4/configure\
179 --with-png=no\
180 --host=nacl\
181 --with-x11-driver=no
183 Banner "building and installing xaos"
184 make
187 ######################################################################
188 # Parse the mode and extract the needed arguments
189 ######################################################################
190 if [ $# -eq 0 ] ; then
191 echo "no mode specified"
192 Usage
193 exit -1
196 readonly MODE=$1
197 shift
200 #@ help
202 #@ Prints help for all modes.
203 if [ ${MODE} = 'help' ] ; then
204 Usage
205 exit 0
209 #@ download_gsl
212 if [ ${MODE} = 'download_gsl' ] ; then
213 mkdir -p ${DIR_TMP}
214 DownloadGsl ${DIR_TMP} ${URL_GSL} ${PATCH_GSL}
215 exit 0
219 #@ build_gsl
222 if [ ${MODE} = 'build_gsl' ] ; then
223 BuildGsl ${DIR_TMP} ${DIR_INSTALL}
224 exit 0
228 #@ download_xoas
231 if [ ${MODE} = 'download_xaos' ] ; then
232 mkdir -p ${DIR_TMP}
233 DownloadXaos ${DIR_TMP} ${URL_XAOS} ${PATCH_XAOS}
234 exit 0
238 #@ build_xaos
241 if [ ${MODE} = 'build_xaos' ] ; then
242 BuildXaos ${DIR_TMP} ${DIR_INSTALL}
243 exit 0
247 #@ all
250 if [ ${MODE} = 'all' ] ; then
251 mkdir -p ${DIR_TMP}
252 DownloadGsl ${DIR_TMP} ${URL_GSL} ${PATCH_GSL}
253 BuildGsl ${DIR_TMP} ${DIR_INSTALL}
254 DownloadXaos ${DIR_TMP} ${URL_XAOS} ${PATCH_XAOS}
255 BuildXaos ${DIR_TMP} ${DIR_INSTALL}
257 Banner "Copying relevant files into this directory"
258 cp ${DIR_TMP}/xaos-build/bin/xaos ${SAVE_PWD}/xaos.nexe
259 cp ${DIR_TMP}/xaos-build/help/xaos.hlp ${SAVE_PWD}/
261 Banner "To view the demo"
263 echo "either point your browser at"
264 echo
265 echo "http://localhost:5103/tests/xaos/xaos.html"
266 echo
267 echo "after running tools/httpd.py while in the native_client directory"
268 echo "or run"
269 echo
270 echo "../../scons-out/opt-linux/staging/sel_ldr ./xaos.nexe"
271 exit 0
275 ######################################################################
276 # Mode is not handled
277 ######################################################################
279 echo "unknown mode: ${MODE}"
280 exit -1