goat3dgfx

annotate configure @ 10:b4c9a24c946e

wrote an awesome configure script added "main" 3d engine source file with global init/cleanup
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 24 Nov 2013 13:30:44 +0200
parents
children d061fe1a31ec
rev   line source
nuclear@10 1 #!/bin/sh
nuclear@10 2
nuclear@10 3 prefix=/usr/local
nuclear@10 4 opt=false
nuclear@10 5 dbg=true
nuclear@10 6 vr=true
nuclear@10 7
nuclear@10 8 for arg; do
nuclear@10 9 case "$arg" in
nuclear@10 10 --prefix=*)
nuclear@10 11 value=`echo $arg | sed 's/--prefix=//'`
nuclear@10 12 prefix=${value:-$prefix}
nuclear@10 13 ;;
nuclear@10 14
nuclear@10 15 --enable-opt)
nuclear@10 16 opt=true;;
nuclear@10 17 --disable-opt)
nuclear@10 18 opt=false;;
nuclear@10 19
nuclear@10 20 --enable-debug)
nuclear@10 21 dbg=true;;
nuclear@10 22 --disable-debug)
nuclear@10 23 dbg=false;;
nuclear@10 24
nuclear@10 25 --enable-vr)
nuclear@10 26 vr=true;;
nuclear@10 27 --disable-vr)
nuclear@10 28 vr=false;;
nuclear@10 29
nuclear@10 30 --help)
nuclear@10 31 echo 'usage: ./configure [options]'
nuclear@10 32 echo 'options:'
nuclear@10 33 echo ' --prefix=<path>: installation path (default: /usr/local)'
nuclear@10 34 echo ' --enable-<foo>/--disable-<foo>: enable/disable features where foo is:'
nuclear@10 35 echo ' opt: speed optimizations'
nuclear@10 36 echo ' dbg: debugging symbols'
nuclear@10 37 echo ' vr: support for virtual reality'
nuclear@10 38 echo 'all invalid options are silently ignored'
nuclear@10 39 exit 0
nuclear@10 40 ;;
nuclear@10 41 esac
nuclear@10 42 done
nuclear@10 43
nuclear@10 44 begin_emit()
nuclear@10 45 {
nuclear@10 46 emit_file=$1
nuclear@10 47 cat /dev/null >$1
nuclear@10 48 }
nuclear@10 49
nuclear@10 50 emit()
nuclear@10 51 {
nuclear@10 52 echo $* >>$emit_file
nuclear@10 53 }
nuclear@10 54
nuclear@10 55
nuclear@10 56 tmpfile_prefix=/tmp/goat3dgfx_configure-
nuclear@10 57 build_log=/tmp/goat3dgfx_configure.log
nuclear@10 58
nuclear@10 59 check_ovr()
nuclear@10 60 {
nuclear@10 61 tmpfile_bin=${tmpfile_prefix}check_ovr
nuclear@10 62 tmpfile_src=${tmpfile_bin}.cc
nuclear@10 63
nuclear@10 64 begin_emit $tmpfile_src
nuclear@10 65 emit '#include <OVR.h>'
nuclear@10 66 emit 'int main() {}'
nuclear@10 67
nuclear@10 68 echo -n 'checking for LibOVR ... '
nuclear@10 69
nuclear@10 70 if ! c++ $CFLAGS -o $tmpfile_bin $tmpfile_src -lovr >$build_log 2>&1; then
nuclear@10 71 echo not found!
nuclear@10 72 exit 1
nuclear@10 73 else
nuclear@10 74 echo ok
nuclear@10 75 fi
nuclear@10 76
nuclear@10 77 LDFLAGS="$LDFLAGS -lovr"
nuclear@10 78 rm -f $tmpfile_bin $tmpfile_src
nuclear@10 79 }
nuclear@10 80
nuclear@10 81 check_glew()
nuclear@10 82 {
nuclear@10 83 tmpfile_bin=${tmpfile_prefix}check_glew
nuclear@10 84 tmpfile_src=${tmpfile_bin}.c
nuclear@10 85
nuclear@10 86 begin_emit $tmpfile_src
nuclear@10 87 emit '#include <GL/glew.h>'
nuclear@10 88 emit 'int main() { return 0; }'
nuclear@10 89
nuclear@10 90 echo -n 'checking for GLEW ... '
nuclear@10 91
nuclear@10 92 if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src -lGLEW >$build_log 2>&1; then
nuclear@10 93 echo not found!
nuclear@10 94 exit 1
nuclear@10 95 else
nuclear@10 96 echo ok
nuclear@10 97 fi
nuclear@10 98
nuclear@10 99 LDFLAGS="$LDFLAGS -lGLEW"
nuclear@10 100 rm -f $tmpfile_bin $tmpfile_src
nuclear@10 101 }
nuclear@10 102
nuclear@10 103 check_opengl()
nuclear@10 104 {
nuclear@10 105 tmpfile_bin=${tmpfile_prefix}check_gl
nuclear@10 106 tmpfile_src=${tmpfile_bin}.c
nuclear@10 107
nuclear@10 108 echo -n 'checking for OpenGL ... '
nuclear@10 109
nuclear@10 110 begin_emit $tmpfile_src
nuclear@10 111 if [ "`uname -s`" = Darwin ]; then
nuclear@10 112 emit '#include <OpenGL/gl.h>'
nuclear@10 113
nuclear@10 114 libgl='-framework OpenGL'
nuclear@10 115 else
nuclear@10 116 emit '#include <GL/gl.h>'
nuclear@10 117
nuclear@10 118 if uname -s | grep MINGW; then
nuclear@10 119 libgl='-lopengl32 -lglu32'
nuclear@10 120 else
nuclear@10 121 libgl='-lGL -lGLU'
nuclear@10 122 fi
nuclear@10 123 fi
nuclear@10 124 emit 'int main() { return 0; }'
nuclear@10 125
nuclear@10 126 if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src $libgl >$build_log 2>&1; then
nuclear@10 127 echo not found!
nuclear@10 128 exit 1
nuclear@10 129 else
nuclear@10 130 echo ok
nuclear@10 131 fi
nuclear@10 132
nuclear@10 133 LDFLAGS="$LDFLAGS $libgl"
nuclear@10 134 rm -f $tmpfile_bin $tmpfile_src
nuclear@10 135 }
nuclear@10 136
nuclear@10 137 check_glut()
nuclear@10 138 {
nuclear@10 139 tmpfile_bin=${tmpfile_prefix}check_glut
nuclear@10 140 tmpfile_src=${tmpfile_bin}.c
nuclear@10 141
nuclear@10 142 echo -n 'checking for GLUT ... '
nuclear@10 143
nuclear@10 144 begin_emit $tmpfile_src
nuclear@10 145 if [ "`uname -s`" = Darwin ]; then
nuclear@10 146 emit '#include <GLUT/glut.h>'
nuclear@10 147
nuclear@10 148 libglut='-framework GLUT'
nuclear@10 149 else
nuclear@10 150 emit '#include <GL/glut.h>'
nuclear@10 151
nuclear@10 152 if uname -s | grep MINGW; then
nuclear@10 153 libglut='-lglut32'
nuclear@10 154 else
nuclear@10 155 libglut='-lglut'
nuclear@10 156 fi
nuclear@10 157 fi
nuclear@10 158 emit 'int main() { return 0; }'
nuclear@10 159
nuclear@10 160 if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src $libglut >$build_log 2>&1; then
nuclear@10 161 echo not found!
nuclear@10 162 exit 1
nuclear@10 163 else
nuclear@10 164 echo ok
nuclear@10 165 fi
nuclear@10 166
nuclear@10 167 LDFLAGS="$LDFLAGS $libglut"
nuclear@10 168 rm -f $tmpfile_bin $tmpfile_src
nuclear@10 169 }
nuclear@10 170
nuclear@10 171 gen_config()
nuclear@10 172 {
nuclear@10 173 echo "generating: src/config.h ..."
nuclear@10 174 begin_emit src/config.h
nuclear@10 175
nuclear@10 176 emit '#ifndef GOAT3DGFX_CONFIG_H_'
nuclear@10 177 emit '#define GOAT3DGFX_CONFIG_H_'
nuclear@10 178
nuclear@10 179 if $vr; then
nuclear@10 180 emit '#define USE_VR'
nuclear@10 181 emit '#define USE_LIBOVR'
nuclear@10 182 else
nuclear@10 183 emit '#undef USE_VR'
nuclear@10 184 fi
nuclear@10 185
nuclear@10 186 emit '#endif /* GOAT3DGFX_CONFIG_H_ */'
nuclear@10 187 }
nuclear@10 188
nuclear@10 189
nuclear@10 190 gen_makefile()
nuclear@10 191 {
nuclear@10 192 echo "generating: Makefile ..."
nuclear@10 193 begin_emit Makefile
nuclear@10 194
nuclear@10 195 emit '# this makefile is automatically generated. do not edit!'
nuclear@10 196 emit "PREFIX = $prefix"
nuclear@10 197 if $opt; then emit 'opt = -O3'; fi
nuclear@10 198 if $dbg; then emit 'dbg = -g'; fi
nuclear@10 199 emit "cfg_cflags = $CFLAGS"
nuclear@10 200 emit "cfg_ldflags = $LDFLAGS"
nuclear@10 201
nuclear@10 202 cat Makefile.in >>Makefile
nuclear@10 203 }
nuclear@10 204
nuclear@10 205 check_opengl
nuclear@10 206 check_glut
nuclear@10 207 check_glew
nuclear@10 208 if $vr; then check_ovr; fi
nuclear@10 209
nuclear@10 210 gen_makefile
nuclear@10 211 gen_config