sgl
annotate 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 |
rev | line source |
---|---|
nuclear@2 | 1 #!/bin/sh |
nuclear@2 | 2 |
nuclear@7 | 3 cfgfile=src/config.h |
nuclear@7 | 4 modfile=src/modules.c |
nuclear@7 | 5 |
nuclear@7 | 6 get_depline() |
nuclear@2 | 7 { |
nuclear@7 | 8 grep 'link-with:' $1 | sed 's/^.*link-with: \?\(.*\) \?\*\//\1/' |
nuclear@2 | 9 } |
nuclear@2 | 10 |
nuclear@7 | 11 get_usedef() |
nuclear@7 | 12 { |
nuclear@7 | 13 grep '#ifdef *USE_WSYS_MODULE' $1 | sed 's/^.*\(USE_WSYS_MODULE_.*\)/\1/' |
nuclear@7 | 14 } |
nuclear@2 | 15 |
nuclear@7 | 16 try_link() |
nuclear@7 | 17 { |
nuclear@7 | 18 srcfile=/tmp/sgl-trylink.c |
nuclear@7 | 19 aout=/tmp/sgl-a.out |
nuclear@7 | 20 |
nuclear@7 | 21 echo 'int main(void) { return 0; }' >$srcfile |
nuclear@7 | 22 cc -o $aout $srcfile $1 >/dev/null 2>/dev/null |
nuclear@7 | 23 } |
nuclear@7 | 24 |
nuclear@7 | 25 # write beginning of config.h |
nuclear@7 | 26 echo '#ifndef CONFIG_H_' >$cfgfile |
nuclear@7 | 27 echo '#define CONFIG_H_' >>$cfgfile |
nuclear@7 | 28 echo >>$cfgfile |
nuclear@7 | 29 |
nuclear@7 | 30 # write beginning of modules.c |
nuclear@7 | 31 echo "/* this file is generated by $0, do not edit */" >$modfile |
nuclear@7 | 32 echo >>$modfile |
nuclear@7 | 33 echo 'void sgl_modules_init(void)' >>$modfile |
nuclear@7 | 34 echo '{' >>$modfile |
nuclear@7 | 35 |
nuclear@7 | 36 |
nuclear@7 | 37 # start scanning for modules |
nuclear@7 | 38 echo 'Looking for usable window system modules ...' |
nuclear@7 | 39 |
nuclear@7 | 40 # collect all src/wsys_whatever.c files |
nuclear@7 | 41 all_files=`ls src/wsys_*.c 2>/dev/null` |
nuclear@7 | 42 |
nuclear@7 | 43 for m in $all_files; do |
nuclear@7 | 44 # extract USE_WSYS_MODULE_* define |
nuclear@7 | 45 def=`get_usedef $m` |
nuclear@7 | 46 |
nuclear@7 | 47 # extract link-with line |
nuclear@7 | 48 dep=`get_depline $m` |
nuclear@7 | 49 name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//'` |
nuclear@7 | 50 echo -n "-> trying module $name (needs: $dep) ... " |
nuclear@7 | 51 |
nuclear@7 | 52 if try_link $dep; then |
nuclear@7 | 53 echo ok |
nuclear@7 | 54 |
nuclear@7 | 55 libs="$libs $dep" |
nuclear@7 | 56 |
nuclear@7 | 57 # emmit the USE_ define in config.h |
nuclear@7 | 58 echo "#define $def" >>$cfgfile |
nuclear@7 | 59 echo >>$cfgfile |
nuclear@7 | 60 |
nuclear@7 | 61 # make the registration call in modules.c |
nuclear@7 | 62 echo " void sgl_register_$name();" >>$modfile |
nuclear@7 | 63 echo " sgl_register_$name();" >>$modfile |
nuclear@7 | 64 echo >>$modfile |
nuclear@7 | 65 else |
nuclear@7 | 66 echo failed |
nuclear@7 | 67 fi |
nuclear@7 | 68 done |
nuclear@7 | 69 echo "Will link with: $libs" |
nuclear@7 | 70 |
nuclear@7 | 71 # wrap up the modules.c file |
nuclear@7 | 72 echo '}' >>$modfile |
nuclear@7 | 73 |
nuclear@7 | 74 # wrap up the config.h file |
nuclear@7 | 75 echo '#endif /* CONFIG_H_ */' >>$cfgfile |
nuclear@7 | 76 |
nuclear@7 | 77 # generate makefile |
nuclear@7 | 78 echo Generating makefile ... |
nuclear@7 | 79 |
nuclear@7 | 80 # hardcode prefix for now, too lazy to actually add an option... |
nuclear@2 | 81 echo 'PREFIX = /usr/local' >Makefile |
nuclear@7 | 82 echo "wsys_libs = $libs" >>Makefile |
nuclear@2 | 83 cat Makefile.in >>Makefile |
nuclear@7 | 84 |
nuclear@7 | 85 echo 'Configuration complete. Run make (or gmake) to compile.' |