sgl

view configure @ 28:f5e83de47903

added --prefix and --without-whatever args in configure script
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 27 Jun 2011 01:59:26 +0300
parents 12ce0cef7ebf
children 3d6ee9fb9ac1
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_usedef()
32 {
33 grep '#ifdef *USE_WSYS_MODULE' $1 | sed 's/^.*\(USE_WSYS_MODULE_.*\)/\1/'
34 }
36 try_link()
37 {
38 srcfile=/tmp/sgl-trylink.c
39 aout=/tmp/sgl-a.out
41 echo >>$logfile
42 echo "trying command line: cc -o $aout $srcfile $*" >>$logfile
44 echo 'int main(void) { return 0; }' >$srcfile
45 eval cc -o $aout $srcfile $1 >>$logfile 2>>$logfile
46 res=$?
48 rm -f $srcfile $aout
49 return $res
50 }
52 message "configuring SimplyGL ..."
54 for arg; do
55 case "$arg" in
56 --prefix=*)
57 value=`echo $arg | awk -F= '{print $2}'`
58 prefix=${value:-$prefix}
59 ;;
61 --without-*)
62 value=`echo $arg | awk -F- '{print $4}'`
63 ignore="$ignore $value"
64 message "without: $value"
65 ;;
66 esac
67 done
69 # write beginning of config.h
70 echo '#ifndef CONFIG_H_' >$cfgfile
71 echo '#define CONFIG_H_' >>$cfgfile
72 echo >>$cfgfile
74 # write beginning of modules.c
75 echo "/* this file is generated by $0, do not edit */" >$modfile
76 echo >>$modfile
77 echo '#define REGISTER_MODULE(name) \' >>$modfile
78 echo ' do { void sgl_register_##name(); sgl_register_##name(); } while(0)' >>$modfile
79 echo >>$modfile
80 echo 'void sgl_modules_init(void)' >>$modfile
81 echo '{' >>$modfile
84 # start scanning for modules
85 message 'Looking for usable window system modules ...'
87 # collect all src/wsys_whatever.c files
88 all_files=`ls src/wsys_*.c src/wsys_*.m 2>/dev/null`
90 for m in $all_files; do
91 # extract USE_WSYS_MODULE_* define
92 def=`get_usedef $m`
94 # extract link-with line
95 if [ `uname -s` = Darwin ]; then
96 dep=`get_framework $m`
97 if [ -z "$dep" ]; then
98 dep=`get_depline $m`
99 fi
100 else
101 dep=`get_depline $m`
102 if [ -z "$dep" ]; then
103 dep=`get_framework $m`
104 fi
105 fi
107 name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//' | sed 's/\.m//'`
108 message -n "-> trying module $name (needs: $dep) ... "
110 if echo $ignore | grep $name >/dev/null; then
111 message ignored
113 elif try_link "$dep"; then
114 message ok
116 libs="$libs $dep"
118 # emmit the USE_ define in config.h
119 echo "#define $def" >>$cfgfile
120 echo >>$cfgfile
122 # make the registration call in modules.c
123 echo " REGISTER_MODULE($name);" >>$modfile
124 else
125 message failed
126 fi
127 done
129 message "Will link with: $libs"
131 # wrap up the modules.c file
132 echo '}' >>$modfile
134 # wrap up the config.h file
135 echo '#endif /* CONFIG_H_ */' >>$cfgfile
137 # generate makefile
138 message Generating makefile ...
140 message "install prefix: $prefix"
141 echo "PREFIX = $prefix" >Makefile
142 echo "wsys_libs = $libs" >>Makefile
143 cat Makefile.in >>Makefile
145 message 'Configuration complete. Run make (or gmake) to compile.'