sgl

diff configure @ 7:edbfc96fe80d

glut wsys thingy and stuff...
author John Tsiombikas <nuclear@siggraph.org>
date Sat, 14 May 2011 08:26:10 +0300
parents 1b6c5dadb460
children 5efd62ff354a
line diff
     1.1 --- a/configure	Fri May 13 09:44:21 2011 +0300
     1.2 +++ b/configure	Sat May 14 08:26:10 2011 +0300
     1.3 @@ -1,27 +1,85 @@
     1.4  #!/bin/sh
     1.5  
     1.6 -gen_module_init()
     1.7 +cfgfile=src/config.h
     1.8 +modfile=src/modules.c
     1.9 +
    1.10 +get_depline()
    1.11  {
    1.12 -	# collect all src/wsys_whatever.c files
    1.13 -	modules=`ls src/wsys_*.c 2>/dev/null | sort | sed 's/src\/wsys_//' | sed 's/\.c//'`
    1.14 -
    1.15 -	echo "/* this file is generated by $0, do not edit */"
    1.16 -	for m in $modules; do
    1.17 -		echo "void sgl_register_$m();"
    1.18 -	done
    1.19 -
    1.20 -	echo
    1.21 -	echo 'void sgl_modules_init(void)'
    1.22 -	echo '{'
    1.23 -
    1.24 -	for m in $modules; do
    1.25 -		echo "	sgl_register_$m();"
    1.26 -	done
    1.27 -
    1.28 -	echo '}'
    1.29 +	grep 'link-with:' $1 | sed 's/^.*link-with: \?\(.*\) \?\*\//\1/'
    1.30  }
    1.31  
    1.32 -gen_module_init >src/modules.c
    1.33 +get_usedef()
    1.34 +{
    1.35 +	grep '#ifdef *USE_WSYS_MODULE' $1 | sed 's/^.*\(USE_WSYS_MODULE_.*\)/\1/'
    1.36 +}
    1.37  
    1.38 +try_link()
    1.39 +{
    1.40 +	srcfile=/tmp/sgl-trylink.c
    1.41 +	aout=/tmp/sgl-a.out
    1.42 +
    1.43 +	echo 'int main(void) { return 0; }' >$srcfile
    1.44 +	cc -o $aout $srcfile $1 >/dev/null 2>/dev/null
    1.45 +}
    1.46 +
    1.47 +# write beginning of config.h
    1.48 +echo '#ifndef CONFIG_H_' >$cfgfile
    1.49 +echo '#define CONFIG_H_' >>$cfgfile
    1.50 +echo >>$cfgfile
    1.51 +
    1.52 +# write beginning of modules.c
    1.53 +echo "/* this file is generated by $0, do not edit */" >$modfile
    1.54 +echo >>$modfile
    1.55 +echo 'void sgl_modules_init(void)' >>$modfile
    1.56 +echo '{' >>$modfile
    1.57 +
    1.58 +
    1.59 +# start scanning for modules
    1.60 +echo 'Looking for usable window system modules ...'
    1.61 +
    1.62 +# collect all src/wsys_whatever.c files
    1.63 +all_files=`ls src/wsys_*.c 2>/dev/null`
    1.64 +
    1.65 +for m in $all_files; do
    1.66 +	# extract USE_WSYS_MODULE_* define
    1.67 +	def=`get_usedef $m`
    1.68 +
    1.69 +	# extract link-with line
    1.70 +	dep=`get_depline $m`
    1.71 +	name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//'`
    1.72 +	echo -n "-> trying module $name (needs: $dep) ... "
    1.73 +
    1.74 +	if try_link $dep; then
    1.75 +		echo ok
    1.76 +
    1.77 +		libs="$libs $dep"
    1.78 +
    1.79 +		# emmit the USE_ define in config.h
    1.80 +		echo "#define $def" >>$cfgfile
    1.81 +		echo >>$cfgfile
    1.82 +
    1.83 +		# make the registration call in modules.c
    1.84 +		echo "	void sgl_register_$name();" >>$modfile
    1.85 +		echo "	sgl_register_$name();" >>$modfile
    1.86 +		echo >>$modfile
    1.87 +	else
    1.88 +		echo failed
    1.89 +	fi
    1.90 +done
    1.91 +echo "Will link with: $libs"
    1.92 +
    1.93 +# wrap up the modules.c file
    1.94 +echo '}' >>$modfile
    1.95 +
    1.96 +# wrap up the config.h file
    1.97 +echo '#endif	/* CONFIG_H_ */' >>$cfgfile
    1.98 +
    1.99 +# generate makefile
   1.100 +echo Generating makefile ...
   1.101 +
   1.102 +# hardcode prefix for now, too lazy to actually add an option...
   1.103  echo 'PREFIX = /usr/local' >Makefile
   1.104 +echo "wsys_libs = $libs" >>Makefile
   1.105  cat Makefile.in >>Makefile
   1.106 +
   1.107 +echo 'Configuration complete. Run make (or gmake) to compile.'