sgl

annotate configure @ 25:0eb6abc43ac6

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