sgl
view configure @ 8:0b07dd867b2f
added empty-file warning silencers in wsys_* files
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Sat, 14 May 2011 08:33:41 +0300 |
parents | 1b6c5dadb460 |
children | 5efd62ff354a |
line source
1 #!/bin/sh
3 cfgfile=src/config.h
4 modfile=src/modules.c
6 get_depline()
7 {
8 grep 'link-with:' $1 | sed 's/^.*link-with: \?\(.*\) \?\*\//\1/'
9 }
11 get_usedef()
12 {
13 grep '#ifdef *USE_WSYS_MODULE' $1 | sed 's/^.*\(USE_WSYS_MODULE_.*\)/\1/'
14 }
16 try_link()
17 {
18 srcfile=/tmp/sgl-trylink.c
19 aout=/tmp/sgl-a.out
21 echo 'int main(void) { return 0; }' >$srcfile
22 cc -o $aout $srcfile $1 >/dev/null 2>/dev/null
23 }
25 # write beginning of config.h
26 echo '#ifndef CONFIG_H_' >$cfgfile
27 echo '#define CONFIG_H_' >>$cfgfile
28 echo >>$cfgfile
30 # write beginning of modules.c
31 echo "/* this file is generated by $0, do not edit */" >$modfile
32 echo >>$modfile
33 echo 'void sgl_modules_init(void)' >>$modfile
34 echo '{' >>$modfile
37 # start scanning for modules
38 echo 'Looking for usable window system modules ...'
40 # collect all src/wsys_whatever.c files
41 all_files=`ls src/wsys_*.c 2>/dev/null`
43 for m in $all_files; do
44 # extract USE_WSYS_MODULE_* define
45 def=`get_usedef $m`
47 # extract link-with line
48 dep=`get_depline $m`
49 name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//'`
50 echo -n "-> trying module $name (needs: $dep) ... "
52 if try_link $dep; then
53 echo ok
55 libs="$libs $dep"
57 # emmit the USE_ define in config.h
58 echo "#define $def" >>$cfgfile
59 echo >>$cfgfile
61 # make the registration call in modules.c
62 echo " void sgl_register_$name();" >>$modfile
63 echo " sgl_register_$name();" >>$modfile
64 echo >>$modfile
65 else
66 echo failed
67 fi
68 done
69 echo "Will link with: $libs"
71 # wrap up the modules.c file
72 echo '}' >>$modfile
74 # wrap up the config.h file
75 echo '#endif /* CONFIG_H_ */' >>$cfgfile
77 # generate makefile
78 echo Generating makefile ...
80 # hardcode prefix for now, too lazy to actually add an option...
81 echo 'PREFIX = /usr/local' >Makefile
82 echo "wsys_libs = $libs" >>Makefile
83 cat Makefile.in >>Makefile
85 echo 'Configuration complete. Run make (or gmake) to compile.'