sgl
view configure @ 12:bf34fa677960
- fixed mac issues.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 May 2011 12:02:22 +0300 |
parents | b925dabd4e96 |
children | e989ab58ec5b |
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 }
35 # write beginning of config.h
36 echo '#ifndef CONFIG_H_' >$cfgfile
37 echo '#define CONFIG_H_' >>$cfgfile
38 echo >>$cfgfile
40 # write beginning of modules.c
41 echo "/* this file is generated by $0, do not edit */" >$modfile
42 echo >>$modfile
43 echo '#define REGISTER_MODULE(name) \' >>$modfile
44 echo ' do { void sgl_register_##name(); sgl_register_##name(); } while(0)' >>$modfile
45 echo >>$modfile
46 echo 'void sgl_modules_init(void)' >>$modfile
47 echo '{' >>$modfile
50 # start scanning for modules
51 echo 'Looking for usable window system modules ...'
53 # collect all src/wsys_whatever.c files
54 all_files=`ls src/wsys_*.c 2>/dev/null`
56 for m in $all_files; do
57 # extract USE_WSYS_MODULE_* define
58 def=`get_usedef $m`
60 # extract link-with line
61 if [ `uname -s` = Darwin ]; then
62 dep=`get_framework $m`
63 if [ -z "$dep" ]; then
64 dep=`get_depline $m`
65 fi
66 else
67 dep=`get_depline $m`
68 fi
70 name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//'`
71 `which echo` -n "-> trying module $name (needs: $dep) ... "
73 if try_link "$dep"; then
74 echo ok
76 libs="$libs $dep"
78 # emmit the USE_ define in config.h
79 echo "#define $def" >>$cfgfile
80 echo >>$cfgfile
82 # make the registration call in modules.c
83 echo " REGISTER_MODULE($name);" >>$modfile
84 else
85 echo failed
86 fi
87 done
88 echo "Will link with: $libs"
90 # wrap up the modules.c file
91 echo '}' >>$modfile
93 # wrap up the config.h file
94 echo '#endif /* CONFIG_H_ */' >>$cfgfile
96 # generate makefile
97 echo Generating makefile ...
99 # hardcode prefix for now, too lazy to actually add an option...
100 echo 'PREFIX = /usr/local' >Makefile
101 echo "wsys_libs = $libs" >>Makefile
102 cat Makefile.in >>Makefile
104 echo 'Configuration complete. Run make (or gmake) to compile.'