goat3dgfx

changeset 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 25b911c7c35c
children d061fe1a31ec
files Makefile Makefile.in configure src/goat3dgfx.cc src/goat3dgfx.h
diffstat 5 files changed, 306 insertions(+), 84 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Mon Nov 18 04:10:19 2013 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,84 +0,0 @@
     1.4 -PREFIX = /usr/local
     1.5 -
     1.6 -csrc = $(wildcard src/*.c)
     1.7 -ccsrc = $(wildcard src/*.cc)
     1.8 -obj = $(csrc:.c=.o) $(ccsrc:.cc=.o)
     1.9 -dep = $(obj:.o=.d)
    1.10 -name = goat3dgfx
    1.11 -lib_a = lib$(name).a
    1.12 -
    1.13 -so_major = 0
    1.14 -so_minor = 1
    1.15 -
    1.16 -ifeq ($(shell uname -r), Darwin)
    1.17 -	libgl = -framework OpenGL -framework GLUT -lGLEW
    1.18 -
    1.19 -	lib_so = lib$(name).dylib
    1.20 -	shared = -dynamiclib
    1.21 -else
    1.22 -	libgl = -lGL -lGLU -lglut -lGLEW
    1.23 -
    1.24 -	lib_so = lib$(name).so.$(so_major).$(so_minor)
    1.25 -	soname = lib$(name).so.$(so_major)
    1.26 -	devlink = lib$(name).so
    1.27 -	shared = -shared -Wl,-soname=$(soname)
    1.28 -	pic = -fPIC
    1.29 -endif
    1.30 -
    1.31 -dbg = -g
    1.32 -warn = -Wall
    1.33 -
    1.34 -libs_ldflags = -limago -lanim -lpsys -lvmath
    1.35 -
    1.36 -CFLAGS = -pedantic $(warn) $(dbg) $(pic) $(opt) $(inc) $(libs_cflags)
    1.37 -CXXFLAGS =  $(CFLAGS)
    1.38 -LDFLAGS = $(libgl) $(libs_ldflags)
    1.39 -
    1.40 -.PHONY: all
    1.41 -all: $(lib_so) $(lib_a)
    1.42 -
    1.43 -$(lib_a): $(obj)
    1.44 -	$(AR) rcs $@ $(obj)
    1.45 -
    1.46 -$(lib_so): $(obj)
    1.47 -	$(CXX) $(shared) -o $@ $(obj) $(LDFLAGS)
    1.48 -
    1.49 --include $(dep)
    1.50 -
    1.51 -%.d: %.c
    1.52 -	@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
    1.53 -
    1.54 -%.d: %.cc
    1.55 -	@$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@
    1.56 -
    1.57 -.PHONY: clean
    1.58 -clean:
    1.59 -	rm -f $(obj) $(lib_a) $(lib_so)
    1.60 -
    1.61 -.PHONY: cleandep
    1.62 -cleandep:
    1.63 -	rm -f $(dep)
    1.64 -
    1.65 -.PHONY: install
    1.66 -install: $(lib_so) $(lib_a)
    1.67 -	mkdir -p $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include/goat3dgfx
    1.68 -	cp src/*.h src/*.inl $(DESTDIR)$(PREFIX)/include/goat3dgfx/
    1.69 -	cp $(lib_a) $(DESTDIR)$(PREFIX)/lib/$(lib_a)
    1.70 -	cp $(lib_so) $(DESTDIR)$(PREFIX)/lib/$(lib_so)
    1.71 -	[ -n "$(devlink)" ] && \
    1.72 -		cd $(DESTDIR)$(PREFIX)/lib && \
    1.73 -		rm -f $(soname) $(devlink) && \
    1.74 -		ln -s $(lib_so) $(soname) && \
    1.75 -		ln -s $(soname) $(devlink) || \
    1.76 -		true
    1.77 -
    1.78 -.PHONY: uninstall
    1.79 -uninstall:
    1.80 -	rm -f $(DESTDIR)$(PREFIX)/include/goat3dgfx/*
    1.81 -	rmdir $(DESTDIR)$(PREFIX)/include/goat3dgfx
    1.82 -	rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so)
    1.83 -	rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_a)
    1.84 -	[ -n "$(devlink)" ] && \
    1.85 -		rm -f $(DESTDIR)$(PREFIX)/lib/$(soname) && \
    1.86 -		rm -f $(DESTDIR)$(PREFIX)/lib/$(devlink) || \
    1.87 -		true
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile.in	Sun Nov 24 13:30:44 2013 +0200
     2.3 @@ -0,0 +1,78 @@
     2.4 +
     2.5 +csrc = $(wildcard src/*.c)
     2.6 +ccsrc = $(wildcard src/*.cc)
     2.7 +obj = $(csrc:.c=.o) $(ccsrc:.cc=.o)
     2.8 +dep = $(obj:.o=.d)
     2.9 +name = goat3dgfx
    2.10 +lib_a = lib$(name).a
    2.11 +
    2.12 +so_major = 0
    2.13 +so_minor = 1
    2.14 +
    2.15 +ifeq ($(shell uname -r), Darwin)
    2.16 +	lib_so = lib$(name).dylib
    2.17 +	shared = -dynamiclib
    2.18 +else
    2.19 +	lib_so = lib$(name).so.$(so_major).$(so_minor)
    2.20 +	soname = lib$(name).so.$(so_major)
    2.21 +	devlink = lib$(name).so
    2.22 +	shared = -shared -Wl,-soname=$(soname)
    2.23 +	pic = -fPIC
    2.24 +endif
    2.25 +
    2.26 +warn = -Wall
    2.27 +
    2.28 +libs_ldflags = -limago -lanim -lpsys -lvmath
    2.29 +
    2.30 +CFLAGS = -pedantic $(warn) $(dbg) $(pic) $(opt) $(inc) $(cfg_cflags) $(libs_cflags)
    2.31 +CXXFLAGS =  $(CFLAGS)
    2.32 +LDFLAGS = $(cfg_ldflags) $(libs_ldflags)
    2.33 +
    2.34 +.PHONY: all
    2.35 +all: $(lib_so) $(lib_a)
    2.36 +
    2.37 +$(lib_a): $(obj)
    2.38 +	$(AR) rcs $@ $(obj)
    2.39 +
    2.40 +$(lib_so): $(obj)
    2.41 +	$(CXX) $(shared) -o $@ $(obj) $(LDFLAGS)
    2.42 +
    2.43 +-include $(dep)
    2.44 +
    2.45 +%.d: %.c
    2.46 +	@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
    2.47 +
    2.48 +%.d: %.cc
    2.49 +	@$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@
    2.50 +
    2.51 +.PHONY: clean
    2.52 +clean:
    2.53 +	rm -f $(obj) $(lib_a) $(lib_so)
    2.54 +
    2.55 +.PHONY: cleandep
    2.56 +cleandep:
    2.57 +	rm -f $(dep)
    2.58 +
    2.59 +.PHONY: install
    2.60 +install: $(lib_so) $(lib_a)
    2.61 +	mkdir -p $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include/goat3dgfx
    2.62 +	cp src/*.h src/*.inl $(DESTDIR)$(PREFIX)/include/goat3dgfx/
    2.63 +	cp $(lib_a) $(DESTDIR)$(PREFIX)/lib/$(lib_a)
    2.64 +	cp $(lib_so) $(DESTDIR)$(PREFIX)/lib/$(lib_so)
    2.65 +	[ -n "$(devlink)" ] && \
    2.66 +		cd $(DESTDIR)$(PREFIX)/lib && \
    2.67 +		rm -f $(soname) $(devlink) && \
    2.68 +		ln -s $(lib_so) $(soname) && \
    2.69 +		ln -s $(soname) $(devlink) || \
    2.70 +		true
    2.71 +
    2.72 +.PHONY: uninstall
    2.73 +uninstall:
    2.74 +	rm -f $(DESTDIR)$(PREFIX)/include/goat3dgfx/*
    2.75 +	rmdir $(DESTDIR)$(PREFIX)/include/goat3dgfx
    2.76 +	rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so)
    2.77 +	rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_a)
    2.78 +	[ -n "$(devlink)" ] && \
    2.79 +		rm -f $(DESTDIR)$(PREFIX)/lib/$(soname) && \
    2.80 +		rm -f $(DESTDIR)$(PREFIX)/lib/$(devlink) || \
    2.81 +		true
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/configure	Sun Nov 24 13:30:44 2013 +0200
     3.3 @@ -0,0 +1,211 @@
     3.4 +#!/bin/sh
     3.5 +
     3.6 +prefix=/usr/local
     3.7 +opt=false
     3.8 +dbg=true
     3.9 +vr=true
    3.10 +
    3.11 +for arg; do
    3.12 +	case "$arg" in
    3.13 +	--prefix=*)
    3.14 +		value=`echo $arg | sed 's/--prefix=//'`
    3.15 +		prefix=${value:-$prefix}
    3.16 +		;;
    3.17 +
    3.18 +	--enable-opt)
    3.19 +		opt=true;;
    3.20 +	--disable-opt)
    3.21 +		opt=false;;
    3.22 +
    3.23 +	--enable-debug)
    3.24 +		dbg=true;;
    3.25 +	--disable-debug)
    3.26 +		dbg=false;;
    3.27 +
    3.28 +	--enable-vr)
    3.29 +		vr=true;;
    3.30 +	--disable-vr)
    3.31 +		vr=false;;
    3.32 +
    3.33 +	--help)
    3.34 +		echo 'usage: ./configure [options]'
    3.35 +		echo 'options:'
    3.36 +		echo '  --prefix=<path>: installation path (default: /usr/local)'
    3.37 +		echo '  --enable-<foo>/--disable-<foo>: enable/disable features where foo is:'
    3.38 +		echo '    opt: speed optimizations'
    3.39 +		echo '    dbg: debugging symbols'
    3.40 +		echo '    vr: support for virtual reality'
    3.41 +		echo 'all invalid options are silently ignored'
    3.42 +		exit 0
    3.43 +		;;
    3.44 +	esac
    3.45 +done
    3.46 +
    3.47 +begin_emit()
    3.48 +{
    3.49 +	emit_file=$1
    3.50 +	cat /dev/null >$1
    3.51 +}
    3.52 +
    3.53 +emit()
    3.54 +{
    3.55 +	echo $* >>$emit_file
    3.56 +}
    3.57 +
    3.58 +
    3.59 +tmpfile_prefix=/tmp/goat3dgfx_configure-
    3.60 +build_log=/tmp/goat3dgfx_configure.log
    3.61 +
    3.62 +check_ovr()
    3.63 +{
    3.64 +	tmpfile_bin=${tmpfile_prefix}check_ovr
    3.65 +	tmpfile_src=${tmpfile_bin}.cc
    3.66 +
    3.67 +	begin_emit $tmpfile_src
    3.68 +	emit '#include <OVR.h>'
    3.69 +	emit 'int main() {}'
    3.70 +
    3.71 +	echo -n 'checking for LibOVR ... '
    3.72 +
    3.73 +	if ! c++ $CFLAGS -o $tmpfile_bin $tmpfile_src -lovr >$build_log 2>&1; then
    3.74 +		echo not found!
    3.75 +		exit 1
    3.76 +	else
    3.77 +		echo ok
    3.78 +	fi
    3.79 +
    3.80 +	LDFLAGS="$LDFLAGS -lovr"
    3.81 +	rm -f $tmpfile_bin $tmpfile_src
    3.82 +}
    3.83 +
    3.84 +check_glew()
    3.85 +{
    3.86 +	tmpfile_bin=${tmpfile_prefix}check_glew
    3.87 +	tmpfile_src=${tmpfile_bin}.c
    3.88 +
    3.89 +	begin_emit $tmpfile_src
    3.90 +	emit '#include <GL/glew.h>'
    3.91 +	emit 'int main() { return 0; }'
    3.92 +
    3.93 +	echo -n 'checking for GLEW ... '
    3.94 +
    3.95 +	if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src -lGLEW >$build_log 2>&1; then
    3.96 +		echo not found!
    3.97 +		exit 1
    3.98 +	else
    3.99 +		echo ok
   3.100 +	fi
   3.101 +
   3.102 +	LDFLAGS="$LDFLAGS -lGLEW"
   3.103 +	rm -f $tmpfile_bin $tmpfile_src
   3.104 +}
   3.105 +
   3.106 +check_opengl()
   3.107 +{
   3.108 +	tmpfile_bin=${tmpfile_prefix}check_gl
   3.109 +	tmpfile_src=${tmpfile_bin}.c
   3.110 +
   3.111 +	echo -n 'checking for OpenGL ... '
   3.112 +
   3.113 +	begin_emit $tmpfile_src
   3.114 +	if [ "`uname -s`" = Darwin ]; then
   3.115 +		emit '#include <OpenGL/gl.h>'
   3.116 +
   3.117 +		libgl='-framework OpenGL'
   3.118 +	else
   3.119 +		emit '#include <GL/gl.h>'
   3.120 +
   3.121 +		if uname -s | grep MINGW; then
   3.122 +			libgl='-lopengl32 -lglu32'
   3.123 +		else
   3.124 +			libgl='-lGL -lGLU'
   3.125 +		fi
   3.126 +	fi
   3.127 +	emit 'int main() { return 0; }'
   3.128 +
   3.129 +	if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src $libgl >$build_log 2>&1; then
   3.130 +		echo not found!
   3.131 +		exit 1
   3.132 +	else
   3.133 +		echo ok
   3.134 +	fi
   3.135 +
   3.136 +	LDFLAGS="$LDFLAGS $libgl"
   3.137 +	rm -f $tmpfile_bin $tmpfile_src
   3.138 +}
   3.139 +
   3.140 +check_glut()
   3.141 +{
   3.142 +	tmpfile_bin=${tmpfile_prefix}check_glut
   3.143 +	tmpfile_src=${tmpfile_bin}.c
   3.144 +
   3.145 +	echo -n 'checking for GLUT ... '
   3.146 +
   3.147 +	begin_emit $tmpfile_src
   3.148 +	if [ "`uname -s`" = Darwin ]; then
   3.149 +		emit '#include <GLUT/glut.h>'
   3.150 +
   3.151 +		libglut='-framework GLUT'
   3.152 +	else
   3.153 +		emit '#include <GL/glut.h>'
   3.154 +
   3.155 +		if uname -s | grep MINGW; then
   3.156 +			libglut='-lglut32'
   3.157 +		else
   3.158 +			libglut='-lglut'
   3.159 +		fi
   3.160 +	fi
   3.161 +	emit 'int main() { return 0; }'
   3.162 +
   3.163 +	if ! cc $CFLAGS -o $tmpfile_bin $tmpfile_src $libglut >$build_log 2>&1; then
   3.164 +		echo not found!
   3.165 +		exit 1
   3.166 +	else
   3.167 +		echo ok
   3.168 +	fi
   3.169 +
   3.170 +	LDFLAGS="$LDFLAGS $libglut"
   3.171 +	rm -f $tmpfile_bin $tmpfile_src
   3.172 +}
   3.173 +
   3.174 +gen_config()
   3.175 +{
   3.176 +	echo "generating: src/config.h ..."
   3.177 +	begin_emit src/config.h
   3.178 +
   3.179 +	emit '#ifndef GOAT3DGFX_CONFIG_H_'
   3.180 +	emit '#define GOAT3DGFX_CONFIG_H_'
   3.181 +
   3.182 +	if $vr; then
   3.183 +		emit '#define USE_VR'
   3.184 +		emit '#define USE_LIBOVR'
   3.185 +	else
   3.186 +		emit '#undef USE_VR'
   3.187 +	fi
   3.188 +
   3.189 +	emit '#endif /* GOAT3DGFX_CONFIG_H_ */'
   3.190 +}
   3.191 +
   3.192 +
   3.193 +gen_makefile()
   3.194 +{
   3.195 +	echo "generating: Makefile ..."
   3.196 +	begin_emit Makefile
   3.197 +
   3.198 +	emit '# this makefile is automatically generated. do not edit!'
   3.199 +	emit "PREFIX = $prefix"
   3.200 +	if $opt; then emit 'opt = -O3'; fi
   3.201 +	if $dbg; then emit 'dbg = -g'; fi
   3.202 +	emit "cfg_cflags = $CFLAGS"
   3.203 +	emit "cfg_ldflags = $LDFLAGS"
   3.204 +
   3.205 +	cat Makefile.in >>Makefile
   3.206 +}
   3.207 +
   3.208 +check_opengl
   3.209 +check_glut
   3.210 +check_glew
   3.211 +if $vr; then check_ovr; fi
   3.212 +
   3.213 +gen_makefile
   3.214 +gen_config
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/goat3dgfx.cc	Sun Nov 24 13:30:44 2013 +0200
     4.3 @@ -0,0 +1,14 @@
     4.4 +#include "goat3dgfx.h"
     4.5 +
     4.6 +bool init_goat_graphics()
     4.7 +{
     4.8 +	log_info("initializing goat3d graphics\n");
     4.9 +
    4.10 +	glewInit();
    4.11 +
    4.12 +	return true;
    4.13 +}
    4.14 +
    4.15 +void shutdown_goat_graphics()
    4.16 +{
    4.17 +}
     5.1 --- a/src/goat3dgfx.h	Mon Nov 18 04:10:19 2013 +0200
     5.2 +++ b/src/goat3dgfx.h	Sun Nov 24 13:30:44 2013 +0200
     5.3 @@ -27,4 +27,7 @@
     5.4  #include <goat3dgfx/unistate.h>
     5.5  #include <goat3dgfx/xform_node.h>
     5.6  
     5.7 +bool init_goat_graphics();
     5.8 +void shutdown_goat_graphics();
     5.9 +
    5.10  #endif	// GOAT3DGFX_H_