sgl

annotate configure @ 16:01a576351090

trying to fix the cocoa module
author John Tsiombikas <nuclear@siggraph.org>
date Fri, 20 May 2011 10:42:54 +0300
parents e989ab58ec5b
children 12ce0cef7ebf
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@12 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@13 33 res=$?
nuclear@13 34
nuclear@13 35 rm -f $srcfile $aout
nuclear@13 36 return $res
nuclear@7 37 }
nuclear@7 38
nuclear@7 39 # write beginning of config.h
nuclear@7 40 echo '#ifndef CONFIG_H_' >$cfgfile
nuclear@7 41 echo '#define CONFIG_H_' >>$cfgfile
nuclear@7 42 echo >>$cfgfile
nuclear@7 43
nuclear@7 44 # write beginning of modules.c
nuclear@7 45 echo "/* this file is generated by $0, do not edit */" >$modfile
nuclear@7 46 echo >>$modfile
nuclear@9 47 echo '#define REGISTER_MODULE(name) \' >>$modfile
nuclear@9 48 echo ' do { void sgl_register_##name(); sgl_register_##name(); } while(0)' >>$modfile
nuclear@9 49 echo >>$modfile
nuclear@7 50 echo 'void sgl_modules_init(void)' >>$modfile
nuclear@7 51 echo '{' >>$modfile
nuclear@7 52
nuclear@7 53
nuclear@7 54 # start scanning for modules
nuclear@7 55 echo 'Looking for usable window system modules ...'
nuclear@7 56
nuclear@7 57 # collect all src/wsys_whatever.c files
nuclear@13 58 all_files=`ls src/wsys_*.c src/wsys_*.m 2>/dev/null`
nuclear@7 59
nuclear@7 60 for m in $all_files; do
nuclear@7 61 # extract USE_WSYS_MODULE_* define
nuclear@7 62 def=`get_usedef $m`
nuclear@7 63
nuclear@7 64 # extract link-with line
nuclear@9 65 if [ `uname -s` = Darwin ]; then
nuclear@9 66 dep=`get_framework $m`
nuclear@9 67 if [ -z "$dep" ]; then
nuclear@9 68 dep=`get_depline $m`
nuclear@9 69 fi
nuclear@9 70 else
nuclear@9 71 dep=`get_depline $m`
nuclear@13 72 if [ -z "$dep" ]; then
nuclear@13 73 dep=`get_framework $m`
nuclear@13 74 fi
nuclear@9 75 fi
nuclear@9 76
nuclear@15 77 name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//' | sed 's/\.m//'`
nuclear@12 78 `which echo` -n "-> trying module $name (needs: $dep) ... "
nuclear@7 79
nuclear@12 80 if try_link "$dep"; then
nuclear@7 81 echo ok
nuclear@7 82
nuclear@7 83 libs="$libs $dep"
nuclear@7 84
nuclear@7 85 # emmit the USE_ define in config.h
nuclear@7 86 echo "#define $def" >>$cfgfile
nuclear@7 87 echo >>$cfgfile
nuclear@7 88
nuclear@7 89 # make the registration call in modules.c
nuclear@9 90 echo " REGISTER_MODULE($name);" >>$modfile
nuclear@7 91 else
nuclear@7 92 echo failed
nuclear@7 93 fi
nuclear@7 94 done
nuclear@7 95 echo "Will link with: $libs"
nuclear@7 96
nuclear@7 97 # wrap up the modules.c file
nuclear@7 98 echo '}' >>$modfile
nuclear@7 99
nuclear@7 100 # wrap up the config.h file
nuclear@7 101 echo '#endif /* CONFIG_H_ */' >>$cfgfile
nuclear@7 102
nuclear@7 103 # generate makefile
nuclear@7 104 echo Generating makefile ...
nuclear@7 105
nuclear@7 106 # hardcode prefix for now, too lazy to actually add an option...
nuclear@2 107 echo 'PREFIX = /usr/local' >Makefile
nuclear@7 108 echo "wsys_libs = $libs" >>Makefile
nuclear@2 109 cat Makefile.in >>Makefile
nuclear@7 110
nuclear@7 111 echo 'Configuration complete. Run make (or gmake) to compile.'