nuclear@10: #!/bin/sh nuclear@10: nuclear@10: prefix=/usr/local nuclear@10: opt=false nuclear@10: dbg=true nuclear@10: vr=true nuclear@10: nuclear@10: for arg; do nuclear@10: case "$arg" in nuclear@10: --prefix=*) nuclear@10: value=`echo $arg | sed 's/--prefix=//'` nuclear@10: prefix=${value:-$prefix} nuclear@10: ;; nuclear@10: nuclear@10: --enable-opt) nuclear@10: opt=true;; nuclear@10: --disable-opt) nuclear@10: opt=false;; nuclear@10: nuclear@10: --enable-debug) nuclear@10: dbg=true;; nuclear@10: --disable-debug) nuclear@10: dbg=false;; nuclear@10: nuclear@10: --enable-vr) nuclear@10: vr=true;; nuclear@10: --disable-vr) nuclear@10: vr=false;; nuclear@10: nuclear@10: --help) nuclear@10: echo 'usage: ./configure [options]' nuclear@10: echo 'options:' nuclear@10: echo ' --prefix=: installation path (default: /usr/local)' nuclear@10: echo ' --enable-/--disable-: enable/disable features where foo is:' nuclear@10: echo ' opt: speed optimizations' nuclear@10: echo ' dbg: debugging symbols' nuclear@10: echo ' vr: support for virtual reality' nuclear@10: echo 'all invalid options are silently ignored' nuclear@10: exit 0 nuclear@10: ;; nuclear@10: esac nuclear@10: done nuclear@10: nuclear@10: begin_emit() nuclear@10: { nuclear@10: emit_file=$1 nuclear@10: cat /dev/null >$1 nuclear@10: } nuclear@10: nuclear@10: emit() nuclear@10: { nuclear@10: echo $* >>$emit_file nuclear@10: } nuclear@10: nuclear@10: nuclear@10: tmpfile_prefix=/tmp/goat3dgfx_configure- nuclear@10: build_log=/tmp/goat3dgfx_configure.log nuclear@10: nuclear@10: check_ovr() nuclear@10: { nuclear@10: tmpfile_bin=${tmpfile_prefix}check_ovr nuclear@10: tmpfile_src=${tmpfile_bin}.cc nuclear@10: nuclear@10: begin_emit $tmpfile_src nuclear@10: emit '#include ' nuclear@10: emit 'int main() {}' nuclear@10: nuclear@10: echo -n 'checking for LibOVR ... ' nuclear@10: nuclear@10: if ! c++ $CFLAGS -o $tmpfile_bin $tmpfile_src -lovr >$build_log 2>&1; then nuclear@10: echo not found! nuclear@10: exit 1 nuclear@10: else nuclear@10: echo ok nuclear@10: fi nuclear@10: nuclear@15: LDFLAGS="$LDFLAGS -lovr -ludev -lXinerama" nuclear@10: rm -f $tmpfile_bin $tmpfile_src nuclear@10: } nuclear@10: nuclear@10: check_glew() nuclear@10: { nuclear@10: tmpfile_bin=${tmpfile_prefix}check_glew nuclear@10: tmpfile_src=${tmpfile_bin}.c nuclear@10: nuclear@10: begin_emit $tmpfile_src nuclear@10: emit '#include ' nuclear@10: emit 'int main() { return 0; }' nuclear@10: nuclear@10: echo -n 'checking for GLEW ... ' nuclear@10: nuclear@10: if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src -lGLEW >$build_log 2>&1; then nuclear@10: echo not found! nuclear@10: exit 1 nuclear@10: else nuclear@10: echo ok nuclear@10: fi nuclear@10: nuclear@10: LDFLAGS="$LDFLAGS -lGLEW" nuclear@10: rm -f $tmpfile_bin $tmpfile_src nuclear@10: } nuclear@10: nuclear@10: check_opengl() nuclear@10: { nuclear@10: tmpfile_bin=${tmpfile_prefix}check_gl nuclear@10: tmpfile_src=${tmpfile_bin}.c nuclear@10: nuclear@10: echo -n 'checking for OpenGL ... ' nuclear@10: nuclear@10: begin_emit $tmpfile_src nuclear@10: if [ "`uname -s`" = Darwin ]; then nuclear@10: emit '#include ' nuclear@10: nuclear@10: libgl='-framework OpenGL' nuclear@10: else nuclear@10: emit '#include ' nuclear@10: nuclear@10: if uname -s | grep MINGW; then nuclear@10: libgl='-lopengl32 -lglu32' nuclear@10: else nuclear@10: libgl='-lGL -lGLU' nuclear@10: fi nuclear@10: fi nuclear@10: emit 'int main() { return 0; }' nuclear@10: nuclear@10: if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src $libgl >$build_log 2>&1; then nuclear@10: echo not found! nuclear@10: exit 1 nuclear@10: else nuclear@10: echo ok nuclear@10: fi nuclear@10: nuclear@10: LDFLAGS="$LDFLAGS $libgl" nuclear@10: rm -f $tmpfile_bin $tmpfile_src nuclear@10: } nuclear@10: nuclear@10: check_glut() nuclear@10: { nuclear@10: tmpfile_bin=${tmpfile_prefix}check_glut nuclear@10: tmpfile_src=${tmpfile_bin}.c nuclear@10: nuclear@10: echo -n 'checking for GLUT ... ' nuclear@10: nuclear@10: begin_emit $tmpfile_src nuclear@10: if [ "`uname -s`" = Darwin ]; then nuclear@10: emit '#include ' nuclear@10: nuclear@10: libglut='-framework GLUT' nuclear@10: else nuclear@10: emit '#include ' nuclear@10: nuclear@10: if uname -s | grep MINGW; then nuclear@10: libglut='-lglut32' nuclear@10: else nuclear@10: libglut='-lglut' nuclear@10: fi nuclear@10: fi nuclear@10: emit 'int main() { return 0; }' nuclear@10: nuclear@10: if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src $libglut >$build_log 2>&1; then nuclear@10: echo not found! nuclear@10: exit 1 nuclear@10: else nuclear@10: echo ok nuclear@10: fi nuclear@10: nuclear@10: LDFLAGS="$LDFLAGS $libglut" nuclear@10: rm -f $tmpfile_bin $tmpfile_src nuclear@10: } nuclear@10: nuclear@10: gen_config() nuclear@10: { nuclear@10: echo "generating: src/config.h ..." nuclear@10: begin_emit src/config.h nuclear@10: nuclear@10: emit '#ifndef GOAT3DGFX_CONFIG_H_' nuclear@10: emit '#define GOAT3DGFX_CONFIG_H_' nuclear@10: nuclear@10: if $vr; then nuclear@10: emit '#define USE_VR' nuclear@10: emit '#define USE_LIBOVR' nuclear@10: else nuclear@10: emit '#undef USE_VR' nuclear@10: fi nuclear@10: nuclear@12: emit '#endif // GOAT3DGFX_CONFIG_H_' nuclear@10: } nuclear@10: nuclear@10: nuclear@10: gen_makefile() nuclear@10: { nuclear@10: echo "generating: Makefile ..." nuclear@10: begin_emit Makefile nuclear@10: nuclear@10: emit '# this makefile is automatically generated. do not edit!' nuclear@10: emit "PREFIX = $prefix" nuclear@10: if $opt; then emit 'opt = -O3'; fi nuclear@10: if $dbg; then emit 'dbg = -g'; fi nuclear@10: emit "cfg_cflags = $CFLAGS" nuclear@10: emit "cfg_ldflags = $LDFLAGS" nuclear@10: nuclear@11: if $vr; then emit 'use_vr = true'; fi nuclear@11: nuclear@10: cat Makefile.in >>Makefile nuclear@10: } nuclear@10: nuclear@10: check_opengl nuclear@10: check_glut nuclear@10: check_glew nuclear@10: if $vr; then check_ovr; fi nuclear@10: nuclear@10: gen_makefile nuclear@10: gen_config