sgl
view 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 |
line source
1 #!/bin/sh
3 cfgfile=src/config.h
4 modfile=src/modules.c
6 extract()
7 {
8 grep "$2:" $1 | sed "s/^.*$2: *\(.*\)\*\//\1/"
9 }
11 get_depline()
12 {
13 extract $1 link-with
14 }
16 get_framework()
17 {
18 extract $1 mac-framework
19 }
21 get_usedef()
22 {
23 grep '#ifdef *USE_WSYS_MODULE' $1 | sed 's/^.*\(USE_WSYS_MODULE_.*\)/\1/'
24 }
26 try_link()
27 {
28 srcfile=/tmp/sgl-trylink.c
29 aout=/tmp/sgl-a.out
31 echo 'int main(void) { return 0; }' >$srcfile
32 cc -o $aout $srcfile $1 >/dev/null 2>/dev/null
33 res=$?
35 rm -f $srcfile $aout
36 return $res
37 }
39 # write beginning of config.h
40 echo '#ifndef CONFIG_H_' >$cfgfile
41 echo '#define CONFIG_H_' >>$cfgfile
42 echo >>$cfgfile
44 # write beginning of modules.c
45 echo "/* this file is generated by $0, do not edit */" >$modfile
46 echo >>$modfile
47 echo '#define REGISTER_MODULE(name) \' >>$modfile
48 echo ' do { void sgl_register_##name(); sgl_register_##name(); } while(0)' >>$modfile
49 echo >>$modfile
50 echo 'void sgl_modules_init(void)' >>$modfile
51 echo '{' >>$modfile
54 # start scanning for modules
55 echo 'Looking for usable window system modules ...'
57 # collect all src/wsys_whatever.c files
58 all_files=`ls src/wsys_*.c src/wsys_*.m 2>/dev/null`
60 for m in $all_files; do
61 # extract USE_WSYS_MODULE_* define
62 def=`get_usedef $m`
64 # extract link-with line
65 if [ `uname -s` = Darwin ]; then
66 dep=`get_framework $m`
67 if [ -z "$dep" ]; then
68 dep=`get_depline $m`
69 fi
70 else
71 dep=`get_depline $m`
72 if [ -z "$dep" ]; then
73 dep=`get_framework $m`
74 fi
75 fi
77 name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//' | sed 's/\.m//'`
78 `which echo` -n "-> trying module $name (needs: $dep) ... "
80 if try_link "$dep"; then
81 echo ok
83 libs="$libs $dep"
85 # emmit the USE_ define in config.h
86 echo "#define $def" >>$cfgfile
87 echo >>$cfgfile
89 # make the registration call in modules.c
90 echo " REGISTER_MODULE($name);" >>$modfile
91 else
92 echo failed
93 fi
94 done
95 echo "Will link with: $libs"
97 # wrap up the modules.c file
98 echo '}' >>$modfile
100 # wrap up the config.h file
101 echo '#endif /* CONFIG_H_ */' >>$cfgfile
103 # generate makefile
104 echo Generating makefile ...
106 # hardcode prefix for now, too lazy to actually add an option...
107 echo 'PREFIX = /usr/local' >Makefile
108 echo "wsys_libs = $libs" >>Makefile
109 cat Makefile.in >>Makefile
111 echo 'Configuration complete. Run make (or gmake) to compile.'