sgl

view configure @ 37:b3374e30361c

xcode project for uikit version, untested
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 27 Jun 2012 05:15:50 +0300
parents f5e83de47903
children
line source
1 #!/bin/sh
3 prefix=/usr/local
4 ignore=
5 cfgfile=src/config.h
6 modfile=src/modules.c
7 logfile=config.log
8 echobin=`which echo`
10 rm -f $logfile
11 message()
12 {
13 $echobin $* | tee -a $logfile
14 }
16 extract()
17 {
18 grep "$2:" $1 | sed "s/^.*$2: *\(.*\)\*\//\1/"
19 }
21 get_depline()
22 {
23 extract $1 link-with
24 }
26 get_framework()
27 {
28 extract $1 mac-framework
29 }
31 get_cflags()
32 {
33 extract $1 cflags
34 }
36 get_usedef()
37 {
38 grep '#ifdef *USE_WSYS_MODULE' $1 | sed 's/^.*\(USE_WSYS_MODULE_.*\)/\1/'
39 }
41 try_link()
42 {
43 srcfile=/tmp/sgl-trylink.c
44 aout=/tmp/sgl-a.out
46 echo >>$logfile
47 echo "trying command line: cc -o $aout $srcfile $*" >>$logfile
49 echo 'int main(void) { return 0; }' >$srcfile
50 eval cc -o $aout $srcfile $1 >>$logfile 2>>$logfile
51 res=$?
53 rm -f $srcfile $aout
54 return $res
55 }
57 message "configuring SimplyGL ..."
59 for arg; do
60 case "$arg" in
61 --prefix=*)
62 value=`echo $arg | awk -F= '{print $2}'`
63 prefix=${value:-$prefix}
64 ;;
66 --without-*)
67 value=`echo $arg | awk -F- '{print $4}'`
68 ignore="$ignore $value"
69 message "without: $value"
70 ;;
71 esac
72 done
74 # write beginning of config.h
75 echo '#ifndef CONFIG_H_' >$cfgfile
76 echo '#define CONFIG_H_' >>$cfgfile
77 echo >>$cfgfile
79 # write beginning of modules.c
80 echo "/* this file is generated by $0, do not edit */" >$modfile
81 echo >>$modfile
82 echo '#define REGISTER_MODULE(name) \' >>$modfile
83 echo ' do { void sgl_register_##name(); sgl_register_##name(); } while(0)' >>$modfile
84 echo >>$modfile
85 echo 'void sgl_modules_init(void)' >>$modfile
86 echo '{' >>$modfile
89 # start scanning for modules
90 message 'Looking for usable window system modules ...'
92 # collect all src/wsys_whatever.c files
93 all_files=`ls src/wsys_*.c src/wsys_*.m 2>/dev/null`
95 for m in $all_files; do
96 # extract USE_WSYS_MODULE_* define
97 def=`get_usedef $m`
99 # extract link-with line
100 if [ `uname -s` = Darwin ]; then
101 dep=`get_framework $m`
102 if [ -z "$dep" ]; then
103 dep=`get_depline $m`
104 fi
105 else
106 dep=`get_depline $m`
107 if [ -z "$dep" ]; then
108 dep=`get_framework $m`
109 fi
110 fi
112 cfl=`get_cflags $m`
114 name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//' | sed 's/\.m//'`
115 message -n "-> trying module $name (needs: $dep) ... "
117 if echo $ignore | grep $name >/dev/null; then
118 message ignored
120 elif try_link "$dep"; then
121 message ok
123 cflags="$cflags $cfl"
124 libs="$libs $dep"
126 # emmit the USE_ define in config.h
127 echo "#define $def" >>$cfgfile
128 echo >>$cfgfile
130 # make the registration call in modules.c
131 echo " REGISTER_MODULE($name);" >>$modfile
132 else
133 message failed
134 fi
135 done
137 if [ -n "$cflags" ]; then
138 message "will compile with: $cflags"
139 fi
140 message "Will link with: $libs"
142 # wrap up the modules.c file
143 echo '}' >>$modfile
145 # wrap up the config.h file
146 echo '#endif /* CONFIG_H_ */' >>$cfgfile
148 # generate makefile
149 message Generating makefile ...
151 message "install prefix: $prefix"
152 echo "PREFIX = $prefix" >Makefile
153 echo "wsys_cflags = $cflags" >>Makefile
154 echo "wsys_libs = $libs" >>Makefile
155 cat Makefile.in >>Makefile
157 message 'Configuration complete. Run make (or gmake) to compile.'