Tizen 2.1 base
[platform/upstream/gcd.git] / BlocksRuntime-0.1 / configure
1 #!/bin/sh
2 #
3 # TODO: backport 'distfile' to ./configure trunk
4
5 c_exports="program version target cflags"
6
7 make_exports="program version target distfile \
8               prefix libdir includedir mandir \
9               cflags ldflags ldadd libdepends \
10               sources objs deps mans headers extra_dist subdirs \
11               abi_major abi_minor abi_version \
12               cc cpp ld ln ar install diff"
13
14 required_headers=
15 optional_headers=
16
17 pre_configure_hook() {
18     return
19 }
20
21 post_configure_hook() {
22     return
23 }
24
25 export_to_make() {
26   for id in $*
27   do
28
29     # Prepend $DESTDIR to installation directories
30     case "$id" in
31         prefix|libdir|includedir|mandir)  
32         eval "$id=\"\\\$\\\$DESTDIR\$$id\""
33     esac
34
35     uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
36     eval "echo \"$uc_id=\"\$$id\"\" >> config.mk"
37   done
38 }
39
40 export_to_c() {
41   for id in $*
42   do
43     uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
44     eval "echo \"#define $uc_id \\\"\$$id\\\"\" >> config.h"
45   done
46 }
47
48 finalize() {
49   uc_id=`echo \"$1\" | $tr '[:lower:]' '[:upper:]'`;
50   eval "if [ \"\$$1\" = \"\" ] ; then $1=\"$2\" ; fi"
51 }
52
53 process_argv() {
54     for arg in $*
55     do
56         id=`echo "$arg" | sed 's/=.*//; s/^--//;'`
57         val=`echo "$arg" | sed 's/^.*=//'`
58         if [ "$val" = "" ] ; then val=1 ; fi
59         eval "$id=\"$val\"" 
60     done
61 }
62
63 process_env() {
64     test -n "$CC" && cc="$CC"
65     test -n "$CPP" && cpp="$CPP"
66     test -n "$CPPFLAGS" && cppflags="$CPPFLAGS"
67     test -n "$CFLAGS" && cflags="$CFLAGS"
68     test -n "$LD" && ld="$LD"
69     test -n "$LN" && ld="$LN"
70     test -n "$LDFLAGS" && ldflags="$LDFLAGS"
71     test -n "$AR" && ar="$AR"
72 }
73  
74 check_header() {         
75    sym=`echo "have_$1" | sed 's,[./],_,g'`       
76    uc_sym=`echo "$sym" | $tr '[:lower:]' '[:upper:]'`;
77    path=$1
78
79    printf "checking for $path.. "
80    if [ -f "/usr/include/$path" ] ; then
81      echo "yes"
82      echo "#define $uc_sym 1" >> config.h
83      eval "$sym=yes"
84      return 0
85    else  
86      echo "no"
87      echo "#undef $uc_sym" >> config.h
88      eval "$sym=no"
89      return 1
90    fi
91 }
92
93 check_headers() {        
94    for header in $*
95    do
96        check_header "$header"
97    done
98 }
99
100 check_symbol() {
101     header=$1
102     symbol=$2
103
104     uc_symbol=`echo "HAVE_$symbol" | $tr '[:lower:]' '[:upper:]' | sed 's,[./],_,g'`
105     lc_symbol=`echo "have_$symbol" | $tr '[:upper:]' '[:lower:]' | sed 's,[./],_,g'`
106
107     if [ -f "$header" ] ; then
108         path="$header"
109     elif [ -f "/usr/include/$header" ] ; then
110         path="/usr/include/$header"
111     else
112         echo "*** ERROR: Cannot find <$header>"
113         exit 1
114     fi
115      
116     printf "checking $header for $symbol.. "    
117     if [ "`grep $symbol $path`" != "" ] ; then
118      eval "$lc_symbol=yes"
119      echo "#define $uc_symbol 1" >> config.h
120      echo "yes"
121      return 0
122     else
123      eval "$lc_symbol=no"
124      echo "no"
125      echo "#undef $uc_symbol" >> config.h
126      return 1
127     fi
128 }
129
130 check_install() {
131     printf "checking for a BSD-compatible install.. "
132     if [ "`uname -s`" = "SunOS" ] ; then
133         default_install=/usr/ucb/install
134     else
135         default_install=/usr/bin/install
136     fi
137     finalize install "$default_install"
138     echo "$install"
139 }
140
141 check_target() {
142     printf "checking operating system type.. "
143     default_target=`uname -s | $tr '[:upper:]' '[:lower:]'`
144     if [ "$default_target" = "sunos" ] ; then
145        default_target="solaris"
146     fi
147     finalize target "$default_target"
148     echo "$target"
149 }
150
151 check_compiler() {
152     printf "checking for a C compiler.. "
153     if [ "`uname -s`" = "SunOS" ] ; then
154        default_cc="/usr/sfw/bin/gcc"
155     else
156        default_cc="/usr/bin/cc"
157     fi
158     finalize cc "$default_cc"
159     echo "$cc"
160 }
161
162 check_linker() {
163     printf "checking for a suitable linker.. "
164
165     # Disabled due to problems with ld(1) under Linux
166     #if [ "`uname -s`" = "SunOS" ] ; then
167     #   default_ld="/usr/sfw/bin/gld"
168     #else
169     #   default_ld="/usr/bin/ld"
170     #fi
171     #ldflags="-shared -export-dynamic -soname $program.so $ldflags"
172
173     # Workaround for "hidden symbol <foo> is referenced by DSO" linker error
174     # seen when compiling libdispatch.
175     # Appears to be a problem with GCC 4.0 and binutils
176     #
177     default_ld="$cc"
178     ldflags="-shared -Wl,-export-dynamic -Wl,-soname,$program.so.$abi_major -o $program.so.$abi_major.$abi_minor $ldflags"
179
180     finalize ld "$default_ld"
181     echo "$ld"
182 }
183
184 check_archiver() {
185     printf "checking for a suitable archiver.. "
186     if [ "`uname -s`" = "SunOS" ] ; then
187        default_ar="/usr/sfw/bin/gar"
188     else
189        default_ar="/usr/bin/ar"
190     fi
191     finalize ar "$default_ar"
192     echo "$ar"
193 }
194
195 err() {
196     echo "*** ERROR *** $*"
197     rm -f config.mk $program.pc config.h
198     exit 1
199 }
200
201 check_diff() {
202     # TODO: Support non-GNU diff syntax
203     # TODO: Search for the command
204     printf "checking for a suitable diff(1) command.. "
205     finalize diff "diff -ruN -dEbwBp -x .svn -x .o -x config.h -x config.mk"
206     echo "found"
207 }
208
209 subst_vars() {
210   outfile=$1
211
212   if [ ! -f "${outfile}.in" ] ; then
213       return
214   fi
215
216   echo "Creating $outfile"
217   rm -f $outfile
218   sed -e "
219        s,@@PROGRAM@@,$program,g;
220        s,@@VERSION@@,$version,g;
221        s,@@PREFIX@@,$prefix,g;
222        s,@@LIBDIR@@,$libdir,g;
223        s,@@INCLUDEDIR@@,$includedir,g;
224        s,@@MANDIR@@,$mandir,g;
225        s,@@LIBDEPENDS@@,$libdepends,g;
226        s,@@PKG_SUMMARY@@,$pkg_summary,g;
227        s,@@PKG_DESCRIPTION@@,$pkg_description,g;
228        s,@@LICENSE@@,$license,g;
229        s,@@AUTHOR@@,$author,g;
230        " < ${outfile}.in > $outfile
231   chmod 400 $outfile
232 }
233
234 #######################################################################
235 #
236 #                           MAIN()
237 #
238 #######################################################################
239
240 # Workaround for Solaris "Bad string" issue when LOCALE is undefined
241 tr="/usr/bin/tr"
242 test -f /usr/xpg4/bin/tr && tr="/usr/xpg4/bin/tr"
243
244 . ./config.inc
245
246 # Initialize the output files
247 #
248 for output_file in config.mk $program.pc
249 do
250    rm -f $output_file
251    echo "# AUTOMATICALLY GENERATED -- DO NOT EDIT" > $output_file
252 done
253 rm -f config.h
254 echo "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */" > config.h
255
256 process_argv "$*"
257 process_env
258
259 check_target
260 check_compiler
261 check_linker
262 check_archiver
263 check_install
264 check_diff
265
266 finalize program    "$program"
267 finalize version    "$version"
268 finalize abi_major  "$abi_major"
269 finalize abi_minor  "$abi_minor"
270 finalize abi_version "$abi_major.$abi_minor"
271 finalize prefix     "/usr/local"
272 finalize libdir     "${prefix}/lib"
273 finalize includedir "${prefix}/include"
274 finalize mandir     "${prefix}/share/man"
275 finalize cflags     "$cflags"
276 finalize libdepends "$libdepends"
277 finalize ldadd      ""
278 finalize ldflags    ""
279 finalize deps       ""
280 finalize ln         "/bin/ln"
281 finalize distfile   "$program-$version.tar.gz"
282
283 pre_configure_hook
284
285 for header in $required_headers
286 do
287   check_header "$header" || err "$header is required, but cannot be found."
288 done
289 check_headers $optional_headers
290
291 post_configure_hook
292
293 objs="`echo \"$sources\" | sed 's/\.c/\.o/g'`"
294
295 subst_vars "$program.pc"
296 subst_vars "$program.la"
297 subst_vars "rpm.spec"
298
299 echo "Creating config.h"
300 export_to_c $c_exports
301
302 echo "Creating config.mk"
303 export_to_make "$make_exports"
304
305 make clean >/dev/null 2>&1