sgl

annotate configure @ 9:5efd62ff354a

- configure now also heeds mac-framework: options in modules - cleaned up the generated module.c a bit
author John Tsiombikas <nuclear@siggraph.org>
date Sat, 14 May 2011 08:58:49 +0300
parents edbfc96fe80d
children b925dabd4e96
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@9 6 extract()
nuclear@9 7 {
nuclear@9 8 grep "$2:" $1 | sed "s/^.*$2: \?\(.*\) \?\*\//\1/"
nuclear@9 9 }
nuclear@9 10
nuclear@7 11 get_depline()
nuclear@2 12 {
nuclear@9 13 extract $1 link-with
nuclear@9 14 }
nuclear@9 15
nuclear@9 16 get_framework()
nuclear@9 17 {
nuclear@9 18 extract $1 mac-framework
nuclear@2 19 }
nuclear@2 20
nuclear@7 21 get_usedef()
nuclear@7 22 {
nuclear@7 23 grep '#ifdef *USE_WSYS_MODULE' $1 | sed 's/^.*\(USE_WSYS_MODULE_.*\)/\1/'
nuclear@7 24 }
nuclear@2 25
nuclear@7 26 try_link()
nuclear@7 27 {
nuclear@7 28 srcfile=/tmp/sgl-trylink.c
nuclear@7 29 aout=/tmp/sgl-a.out
nuclear@7 30
nuclear@7 31 echo 'int main(void) { return 0; }' >$srcfile
nuclear@7 32 cc -o $aout $srcfile $1 >/dev/null 2>/dev/null
nuclear@7 33 }
nuclear@7 34
nuclear@7 35 # write beginning of config.h
nuclear@7 36 echo '#ifndef CONFIG_H_' >$cfgfile
nuclear@7 37 echo '#define CONFIG_H_' >>$cfgfile
nuclear@7 38 echo >>$cfgfile
nuclear@7 39
nuclear@7 40 # write beginning of modules.c
nuclear@7 41 echo "/* this file is generated by $0, do not edit */" >$modfile
nuclear@7 42 echo >>$modfile
nuclear@9 43 echo '#define REGISTER_MODULE(name) \' >>$modfile
nuclear@9 44 echo ' do { void sgl_register_##name(); sgl_register_##name(); } while(0)' >>$modfile
nuclear@9 45 echo >>$modfile
nuclear@7 46 echo 'void sgl_modules_init(void)' >>$modfile
nuclear@7 47 echo '{' >>$modfile
nuclear@7 48
nuclear@7 49
nuclear@7 50 # start scanning for modules
nuclear@7 51 echo 'Looking for usable window system modules ...'
nuclear@7 52
nuclear@7 53 # collect all src/wsys_whatever.c files
nuclear@7 54 all_files=`ls src/wsys_*.c 2>/dev/null`
nuclear@7 55
nuclear@7 56 for m in $all_files; do
nuclear@7 57 # extract USE_WSYS_MODULE_* define
nuclear@7 58 def=`get_usedef $m`
nuclear@7 59
nuclear@7 60 # extract link-with line
nuclear@9 61 if [ `uname -s` = Darwin ]; then
nuclear@9 62 dep=`get_framework $m`
nuclear@9 63 if [ -z "$dep" ]; then
nuclear@9 64 dep=`get_depline $m`
nuclear@9 65 fi
nuclear@9 66 else
nuclear@9 67 dep=`get_depline $m`
nuclear@9 68 fi
nuclear@9 69
nuclear@7 70 name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//'`
nuclear@7 71 echo -n "-> trying module $name (needs: $dep) ... "
nuclear@7 72
nuclear@7 73 if try_link $dep; then
nuclear@7 74 echo ok
nuclear@7 75
nuclear@7 76 libs="$libs $dep"
nuclear@7 77
nuclear@7 78 # emmit the USE_ define in config.h
nuclear@7 79 echo "#define $def" >>$cfgfile
nuclear@7 80 echo >>$cfgfile
nuclear@7 81
nuclear@7 82 # make the registration call in modules.c
nuclear@9 83 echo " REGISTER_MODULE($name);" >>$modfile
nuclear@7 84 else
nuclear@7 85 echo failed
nuclear@7 86 fi
nuclear@7 87 done
nuclear@7 88 echo "Will link with: $libs"
nuclear@7 89
nuclear@7 90 # wrap up the modules.c file
nuclear@7 91 echo '}' >>$modfile
nuclear@7 92
nuclear@7 93 # wrap up the config.h file
nuclear@7 94 echo '#endif /* CONFIG_H_ */' >>$cfgfile
nuclear@7 95
nuclear@7 96 # generate makefile
nuclear@7 97 echo Generating makefile ...
nuclear@7 98
nuclear@7 99 # hardcode prefix for now, too lazy to actually add an option...
nuclear@2 100 echo 'PREFIX = /usr/local' >Makefile
nuclear@7 101 echo "wsys_libs = $libs" >>Makefile
nuclear@2 102 cat Makefile.in >>Makefile
nuclear@7 103
nuclear@7 104 echo 'Configuration complete. Run make (or gmake) to compile.'