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