goat3dgfx
view configure @ 34:3eb6c8f89fe1
merge
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 02 Mar 2014 17:41:10 +0200 |
parents | 0ac499409edd |
children |
line source
1 #!/bin/sh
3 prefix=/usr/local
4 opt=false
5 dbg=true
6 vr=true
8 for arg in $#; do
9 case "$arg" in
10 --prefix=*)
11 value=`echo $arg | sed 's/--prefix=//'`
12 prefix=${value:-$prefix}
13 ;;
15 --enable-opt)
16 opt=true;;
17 --disable-opt)
18 opt=false;;
20 --enable-debug)
21 dbg=true;;
22 --disable-debug)
23 dbg=false;;
25 --enable-vr)
26 vr=true;;
27 --disable-vr)
28 vr=false;;
30 --help)
31 echo 'usage: ./configure [options]'
32 echo 'options:'
33 echo ' --prefix=<path>: installation path (default: /usr/local)'
34 echo ' --enable-<foo>/--disable-<foo>: enable/disable features where foo is:'
35 echo ' opt: speed optimizations'
36 echo ' dbg: debugging symbols'
37 echo ' vr: support for virtual reality'
38 echo 'all invalid options are silently ignored'
39 exit 0
40 ;;
41 esac
42 done
44 begin_emit()
45 {
46 emit_file=$1
47 cat /dev/null >$1
48 }
50 emit()
51 {
52 echo $* >>$emit_file
53 }
56 tmpfile_prefix=/tmp/goat3dgfx_configure-
57 build_log=/tmp/goat3dgfx_configure.log
59 check_ovr()
60 {
61 tmpfile_bin=${tmpfile_prefix}check_ovr
62 tmpfile_src=${tmpfile_bin}.cc
64 begin_emit $tmpfile_src
65 emit '#include <OVR.h>'
66 emit 'int main() {}'
68 echo -n 'checking for LibOVR ... '
70 if ! c++ $CFLAGS -o $tmpfile_bin $tmpfile_src -lovr >$build_log 2>&1; then
71 echo not found!
72 exit 1
73 else
74 echo ok
75 fi
77 LDFLAGS="$LDFLAGS -lovr -ludev -lXinerama"
78 rm -f $tmpfile_bin $tmpfile_src
79 }
81 check_glew()
82 {
83 tmpfile_bin=${tmpfile_prefix}check_glew
84 tmpfile_src=${tmpfile_bin}.c
86 begin_emit $tmpfile_src
87 emit '#include <GL/glew.h>'
88 emit 'int main() { return 0; }'
90 echo -n 'checking for GLEW ... '
92 if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src -lGLEW >$build_log 2>&1; then
93 echo not found!
94 exit 1
95 else
96 echo ok
97 fi
99 LDFLAGS="$LDFLAGS -lGLEW"
100 rm -f $tmpfile_bin $tmpfile_src
101 }
103 check_opengl()
104 {
105 tmpfile_bin=${tmpfile_prefix}check_gl
106 tmpfile_src=${tmpfile_bin}.c
108 echo -n 'checking for OpenGL ... '
110 begin_emit $tmpfile_src
111 if [ "`uname -s`" = Darwin ]; then
112 emit '#include <OpenGL/gl.h>'
114 libgl='-framework OpenGL'
115 else
116 if uname -s | grep MINGW; then
117 libgl='-lopengl32 -lglu32'
118 emit '#include <windows.h>'
119 else
120 libgl='-lGL -lGLU'
121 fi
123 emit '#include <GL/gl.h>'
124 fi
125 emit 'int main() { return 0; }'
127 if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src $libgl >$build_log 2>&1; then
128 echo not found!
129 exit 1
130 else
131 echo ok
132 fi
134 LDFLAGS="$LDFLAGS $libgl"
135 rm -f $tmpfile_bin $tmpfile_src
136 }
138 check_glut()
139 {
140 tmpfile_bin=${tmpfile_prefix}check_glut
141 tmpfile_src=${tmpfile_bin}.c
143 echo -n 'checking for GLUT ... '
145 begin_emit $tmpfile_src
146 if [ "`uname -s`" = Darwin ]; then
147 emit '#include <GLUT/glut.h>'
149 libglut='-framework GLUT'
150 else
151 emit '#include <GL/glut.h>'
153 if uname -s | grep MINGW; then
154 libglut='-lglut32'
155 else
156 libglut='-lglut'
157 fi
158 fi
159 emit 'int main() { return 0; }'
161 if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src $libglut >$build_log 2>&1; then
162 echo not found!
163 exit 1
164 else
165 echo ok
166 fi
168 LDFLAGS="$LDFLAGS $libglut"
169 rm -f $tmpfile_bin $tmpfile_src
170 }
172 check_lib()
173 {
174 libname=$1
175 hdr=$2
176 lib=-l$libname
177 tmpfile_bin=${tmpfile_prefix}check_$libname
178 tmpfile_src=${tmpfile_bin}.cc
180 echo -n "checking for $libname ... "
182 begin_emit $tmpfile_src
183 emit "#include <${hdr}>"
184 emit 'int main() {}'
186 if ! c++ -o $tmpfile_bin $tmpfile_src $lib -lpthread >$build_log 2>&1; then
187 echo not found!
188 exit 1
189 else
190 echo ok
191 fi
193 LDFLAGS="$LDFLAGS $lib"
194 rm -f $tmpfile_bin $tmpfile_src
195 }
197 gen_config()
198 {
199 echo "generating: src/config.h ..."
200 begin_emit src/config.h
202 emit '#ifndef GOAT3DGFX_CONFIG_H_'
203 emit '#define GOAT3DGFX_CONFIG_H_'
205 if $vr; then
206 emit '#define USE_VR'
207 emit '#define USE_LIBOVR'
208 else
209 emit '#undef USE_VR'
210 fi
212 emit '#endif // GOAT3DGFX_CONFIG_H_'
213 }
216 gen_makefile()
217 {
218 echo "generating: Makefile ..."
219 begin_emit Makefile
221 emit '# this makefile is automatically generated. do not edit!'
222 emit "PREFIX = $prefix"
223 if $opt; then emit 'opt = -O3'; fi
224 if $dbg; then emit 'dbg = -g'; fi
225 emit "cfg_cflags = $CFLAGS"
226 emit "cfg_ldflags = $LDFLAGS"
228 if $vr; then emit 'use_vr = true'; fi
230 cat Makefile.in >>Makefile
231 }
233 gen_pkgconfig()
234 {
235 pcfile=goat3dgfx.pc
236 echo "generating: $pcfile ..."
237 begin_emit $pcfile
239 emit "prefix=$prefix"
240 emit "ver=0.1"
242 if [ `uname -s` = Darwin ]; then
243 emit 'libgl=-framework OpenGL -framework GLUT -lGLEW'
244 else
245 emit 'libgl=-lGL -lGLU -lglut -lGLEW'
246 fi
247 emit 'libovr='
249 cat ${pcfile}.in >>$pcfile
250 }
252 check_opengl
253 check_glut
254 check_glew
255 if $vr; then check_ovr; fi
256 check_lib vmath vmath/vmath.h
257 check_lib imago imago2.h
258 check_lib anim anim/anim.h
259 check_lib psys psys/psys.h
260 check_lib resman resman.h
261 check_lib goat3d goat3d.h
263 gen_makefile
264 gen_config
265 gen_pkgconfig