goat3dgfx

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/configure	Sun Nov 24 13:30:44 2013 +0200
     1.3 @@ -0,0 +1,211 @@
     1.4 +#!/bin/sh
     1.5 +
     1.6 +prefix=/usr/local
     1.7 +opt=false
     1.8 +dbg=true
     1.9 +vr=true
    1.10 +
    1.11 +for arg; do
    1.12 +	case "$arg" in
    1.13 +	--prefix=*)
    1.14 +		value=`echo $arg | sed 's/--prefix=//'`
    1.15 +		prefix=${value:-$prefix}
    1.16 +		;;
    1.17 +
    1.18 +	--enable-opt)
    1.19 +		opt=true;;
    1.20 +	--disable-opt)
    1.21 +		opt=false;;
    1.22 +
    1.23 +	--enable-debug)
    1.24 +		dbg=true;;
    1.25 +	--disable-debug)
    1.26 +		dbg=false;;
    1.27 +
    1.28 +	--enable-vr)
    1.29 +		vr=true;;
    1.30 +	--disable-vr)
    1.31 +		vr=false;;
    1.32 +
    1.33 +	--help)
    1.34 +		echo 'usage: ./configure [options]'
    1.35 +		echo 'options:'
    1.36 +		echo '  --prefix=<path>: installation path (default: /usr/local)'
    1.37 +		echo '  --enable-<foo>/--disable-<foo>: enable/disable features where foo is:'
    1.38 +		echo '    opt: speed optimizations'
    1.39 +		echo '    dbg: debugging symbols'
    1.40 +		echo '    vr: support for virtual reality'
    1.41 +		echo 'all invalid options are silently ignored'
    1.42 +		exit 0
    1.43 +		;;
    1.44 +	esac
    1.45 +done
    1.46 +
    1.47 +begin_emit()
    1.48 +{
    1.49 +	emit_file=$1
    1.50 +	cat /dev/null >$1
    1.51 +}
    1.52 +
    1.53 +emit()
    1.54 +{
    1.55 +	echo $* >>$emit_file
    1.56 +}
    1.57 +
    1.58 +
    1.59 +tmpfile_prefix=/tmp/goat3dgfx_configure-
    1.60 +build_log=/tmp/goat3dgfx_configure.log
    1.61 +
    1.62 +check_ovr()
    1.63 +{
    1.64 +	tmpfile_bin=${tmpfile_prefix}check_ovr
    1.65 +	tmpfile_src=${tmpfile_bin}.cc
    1.66 +
    1.67 +	begin_emit $tmpfile_src
    1.68 +	emit '#include <OVR.h>'
    1.69 +	emit 'int main() {}'
    1.70 +
    1.71 +	echo -n 'checking for LibOVR ... '
    1.72 +
    1.73 +	if ! c++ $CFLAGS -o $tmpfile_bin $tmpfile_src -lovr >$build_log 2>&1; then
    1.74 +		echo not found!
    1.75 +		exit 1
    1.76 +	else
    1.77 +		echo ok
    1.78 +	fi
    1.79 +
    1.80 +	LDFLAGS="$LDFLAGS -lovr"
    1.81 +	rm -f $tmpfile_bin $tmpfile_src
    1.82 +}
    1.83 +
    1.84 +check_glew()
    1.85 +{
    1.86 +	tmpfile_bin=${tmpfile_prefix}check_glew
    1.87 +	tmpfile_src=${tmpfile_bin}.c
    1.88 +
    1.89 +	begin_emit $tmpfile_src
    1.90 +	emit '#include <GL/glew.h>'
    1.91 +	emit 'int main() { return 0; }'
    1.92 +
    1.93 +	echo -n 'checking for GLEW ... '
    1.94 +
    1.95 +	if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src -lGLEW >$build_log 2>&1; then
    1.96 +		echo not found!
    1.97 +		exit 1
    1.98 +	else
    1.99 +		echo ok
   1.100 +	fi
   1.101 +
   1.102 +	LDFLAGS="$LDFLAGS -lGLEW"
   1.103 +	rm -f $tmpfile_bin $tmpfile_src
   1.104 +}
   1.105 +
   1.106 +check_opengl()
   1.107 +{
   1.108 +	tmpfile_bin=${tmpfile_prefix}check_gl
   1.109 +	tmpfile_src=${tmpfile_bin}.c
   1.110 +
   1.111 +	echo -n 'checking for OpenGL ... '
   1.112 +
   1.113 +	begin_emit $tmpfile_src
   1.114 +	if [ "`uname -s`" = Darwin ]; then
   1.115 +		emit '#include <OpenGL/gl.h>'
   1.116 +
   1.117 +		libgl='-framework OpenGL'
   1.118 +	else
   1.119 +		emit '#include <GL/gl.h>'
   1.120 +
   1.121 +		if uname -s | grep MINGW; then
   1.122 +			libgl='-lopengl32 -lglu32'
   1.123 +		else
   1.124 +			libgl='-lGL -lGLU'
   1.125 +		fi
   1.126 +	fi
   1.127 +	emit 'int main() { return 0; }'
   1.128 +
   1.129 +	if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src $libgl >$build_log 2>&1; then
   1.130 +		echo not found!
   1.131 +		exit 1
   1.132 +	else
   1.133 +		echo ok
   1.134 +	fi
   1.135 +
   1.136 +	LDFLAGS="$LDFLAGS $libgl"
   1.137 +	rm -f $tmpfile_bin $tmpfile_src
   1.138 +}
   1.139 +
   1.140 +check_glut()
   1.141 +{
   1.142 +	tmpfile_bin=${tmpfile_prefix}check_glut
   1.143 +	tmpfile_src=${tmpfile_bin}.c
   1.144 +
   1.145 +	echo -n 'checking for GLUT ... '
   1.146 +
   1.147 +	begin_emit $tmpfile_src
   1.148 +	if [ "`uname -s`" = Darwin ]; then
   1.149 +		emit '#include <GLUT/glut.h>'
   1.150 +
   1.151 +		libglut='-framework GLUT'
   1.152 +	else
   1.153 +		emit '#include <GL/glut.h>'
   1.154 +
   1.155 +		if uname -s | grep MINGW; then
   1.156 +			libglut='-lglut32'
   1.157 +		else
   1.158 +			libglut='-lglut'
   1.159 +		fi
   1.160 +	fi
   1.161 +	emit 'int main() { return 0; }'
   1.162 +
   1.163 +	if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src $libglut >$build_log 2>&1; then
   1.164 +		echo not found!
   1.165 +		exit 1
   1.166 +	else
   1.167 +		echo ok
   1.168 +	fi
   1.169 +
   1.170 +	LDFLAGS="$LDFLAGS $libglut"
   1.171 +	rm -f $tmpfile_bin $tmpfile_src
   1.172 +}
   1.173 +
   1.174 +gen_config()
   1.175 +{
   1.176 +	echo "generating: src/config.h ..."
   1.177 +	begin_emit src/config.h
   1.178 +
   1.179 +	emit '#ifndef GOAT3DGFX_CONFIG_H_'
   1.180 +	emit '#define GOAT3DGFX_CONFIG_H_'
   1.181 +
   1.182 +	if $vr; then
   1.183 +		emit '#define USE_VR'
   1.184 +		emit '#define USE_LIBOVR'
   1.185 +	else
   1.186 +		emit '#undef USE_VR'
   1.187 +	fi
   1.188 +
   1.189 +	emit '#endif /* GOAT3DGFX_CONFIG_H_ */'
   1.190 +}
   1.191 +
   1.192 +
   1.193 +gen_makefile()
   1.194 +{
   1.195 +	echo "generating: Makefile ..."
   1.196 +	begin_emit Makefile
   1.197 +
   1.198 +	emit '# this makefile is automatically generated. do not edit!'
   1.199 +	emit "PREFIX = $prefix"
   1.200 +	if $opt; then emit 'opt = -O3'; fi
   1.201 +	if $dbg; then emit 'dbg = -g'; fi
   1.202 +	emit "cfg_cflags = $CFLAGS"
   1.203 +	emit "cfg_ldflags = $LDFLAGS"
   1.204 +
   1.205 +	cat Makefile.in >>Makefile
   1.206 +}
   1.207 +
   1.208 +check_opengl
   1.209 +check_glut
   1.210 +check_glew
   1.211 +if $vr; then check_ovr; fi
   1.212 +
   1.213 +gen_makefile
   1.214 +gen_config