Tizen 2.1 base
[platform/upstream/gcd.git] / kqueue-1.0.4 / configure
1 #!/bin/sh
2 #
3 # Copyright (c) 2009-2010 Mark Heily <mark@heily.com>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #
17
18
19 c_exports="program version target cflags"
20
21 make_exports="program version target \
22               prefix libdir includedir mandir \
23               cflags ldflags ldadd libdepends \
24               sources objs deps mans headers extra_dist subdirs \
25               abi_major abi_minor abi_version \
26               cc cpp ld ln ar install diff"
27
28 required_headers=
29 optional_headers=
30
31 pre_configure_hook() {
32     return
33 }
34
35 post_configure_hook() {
36     return
37 }
38
39 export_to_make() {
40   for id in $*
41   do
42
43     # Prepend $DESTDIR to installation directories
44     case "$id" in
45         prefix|libdir|includedir|mandir)  
46         eval "$id=\"\\\$\\\$DESTDIR\$$id\""
47     esac
48
49     uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
50     eval "echo \"$uc_id=\"\$$id\"\" >> config.mk"
51   done
52 }
53
54 export_to_c() {
55   for id in $*
56   do
57     uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
58     eval "echo \"#define $uc_id \\\"\$$id\\\"\" >> config.h"
59   done
60 }
61
62 finalize() {
63   uc_id=`echo \"$1\" | $tr '[:lower:]' '[:upper:]'`;
64   eval "if [ \"\$$1\" = \"\" ] ; then $1=\"$2\" ; fi"
65 }
66
67 process_argv() {
68     for arg in $*
69     do
70         id=`echo "$arg" | sed 's/=.*//; s/^--//;'`
71         val=`echo "$arg" | sed 's/^.*=//'`
72         if [ "$val" = "" ] ; then val=1 ; fi
73         eval "$id=\"$val\"" 
74     done
75 }
76
77 process_env() {
78     test -n "$CC" && cc="$CC"
79     test -n "$CPP" && cpp="$CPP"
80     test -n "$CPPFLAGS" && cppflags="$CPPFLAGS"
81     test -n "$CFLAGS" && cflags="$CFLAGS"
82     test -n "$LD" && ld="$LD"
83     test -n "$LN" && ld="$LN"
84     test -n "$LDFLAGS" && ldflags="$LDFLAGS"
85     test -n "$AR" && ar="$AR"
86 }
87  
88 check_header() {         
89    sym=`echo "have_$1" | sed 's,[./],_,g'`       
90    uc_sym=`echo "$sym" | $tr '[:lower:]' '[:upper:]'`;
91    path=$1
92
93    printf "checking for $path.. "
94    if [ -f "/usr/include/$path" ] ; then
95      echo "yes"
96      echo "#define $uc_sym 1" >> config.h
97      eval "$sym=yes"
98      return 0
99    else  
100      echo "no"
101      echo "#undef $uc_sym" >> config.h
102      eval "$sym=no"
103      return 1
104    fi
105 }
106
107 # Determine the path to an executable binary
108 check_binary() {
109    id=$1
110    shift
111
112    for path in $*
113    do
114        test -f $path
115        if [ $? = 0 ] ; then
116            eval "$id=\"$path\""
117            return
118        fi
119    done
120
121    echo "not found"
122    return
123 }
124
125 check_headers() {        
126    for header in $*
127    do
128        check_header "$header"
129    done
130 }
131
132 check_symbol() {
133     header=$1
134     symbol=$2
135
136     uc_symbol=`echo "HAVE_$symbol" | $tr '[:lower:]' '[:upper:]' | sed 's,[./],_,g'`
137     lc_symbol=`echo "have_$symbol" | $tr '[:upper:]' '[:lower:]' | sed 's,[./],_,g'`
138
139     if [ -f "$header" ] ; then
140         path="$header"
141     elif [ -f "/usr/include/$header" ] ; then
142         path="/usr/include/$header"
143     else
144         echo "*** ERROR: Cannot find <$header>"
145         exit 1
146     fi
147      
148     printf "checking $header for $symbol.. "    
149     if [ "`grep $symbol $path`" != "" ] ; then
150      eval "$lc_symbol=yes"
151      echo "#define $uc_symbol 1" >> config.h
152      echo "yes"
153      return 0
154     else
155      eval "$lc_symbol=no"
156      echo "no"
157      echo "#undef $uc_symbol" >> config.h
158      return 1
159     fi
160 }
161
162 check_install() {
163     printf "checking for a BSD-compatible install.. "
164     if [ "`uname -s`" = "SunOS" ] ; then
165         default_install=/usr/ucb/install
166     else
167         default_install=/usr/bin/install
168     fi
169     finalize install "$default_install"
170     echo "$install"
171 }
172
173 check_target() {
174     printf "checking operating system type.. "
175     default_target=`uname -s | $tr '[:upper:]' '[:lower:]'`
176     if [ "$default_target" = "sunos" ] ; then
177        default_target="solaris"
178     fi
179     if [ "$default_target" = "gnu/kfreebsf libkqueue.so.0.0 libkqueue.sosd" ] ; then
180        default_target="freebsd"
181     fi
182     finalize target "$default_target"
183     echo "$target"
184 }
185
186 check_compiler() {
187     printf "checking for a C compiler.. "
188     check_binary default_cc "/usr/bin/cc" "/usr/bin/gcc" "/usr/sfw/bin/gcc"
189     finalize cc "$default_cc"
190     echo "$cc"
191 }
192
193 check_linker() {
194     printf "checking for a suitable linker.. "
195
196     # Workaround for "hidden symbol <foo> is referenced by DSO" linker error
197     # seen when compiling libdispatch.
198     # Appears to be a problem with GCC 4.0 and binutils
199     #
200     default_ld="$cc"
201     ldflags="-shared -o $program.so.$abi_major.$abi_minor $ldflags"
202
203     # FIXME: port to solaris
204     if [ "$target" = "linux" ] ; then
205     ldflags="$ldflags -Wl,-export-dynamic -Wl,-soname,$program.so.$abi_major"
206     fi 
207
208     if [ "$target" = "solaris" ] ; then
209     ldflags="$ldflags"
210     fi
211
212     finalize ld "$default_ld"
213     echo "$ld"
214 }
215
216 check_archiver() {
217     printf "checking for a suitable archiver.. "
218     if [ "`uname -s`" = "SunOS" -a "`uname -v | grep Nexenta`" = "" ] ; then
219        default_ar="/usr/sfw/bin/gar"
220     else
221        default_ar="/usr/bin/ar"
222     fi
223     finalize ar "$default_ar"
224     echo "$ar"
225 }
226
227 err() {
228     echo "*** ERROR *** $*"
229     rm -f config.mk $program.pc config.h
230     exit 1
231 }
232
233 check_diff() {
234     # TODO: Support non-GNU diff syntax
235     # TODO: Search for the command
236     printf "checking for a suitable diff(1) command.. "
237     finalize diff "diff -ruN -dEbwBp -x .svn -x .o -x config.h -x config.mk"
238     echo "found"
239 }
240
241 subst_vars() {
242   outfile=$1
243
244   if [ ! -f "${outfile}.in" ] ; then
245       return
246   fi
247
248   echo "Creating $outfile"
249   rm -f $outfile
250   sed -e "
251        s,@@CWD@@,`pwd`,g;
252        s,@@PROGRAM@@,$program,g;
253        s,@@VERSION@@,$version,g;
254        s,@@PREFIX@@,$prefix,g;
255        s,@@LIBDIR@@,$libdir,g;
256        s,@@INCLUDEDIR@@,$includedir,g;
257        s,@@MANDIR@@,$mandir,g;
258        s,@@LIBDEPENDS@@,$libdepends,g;
259        s,@@PKG_SUMMARY@@,$pkg_summary,g;
260        s,@@PKG_DESCRIPTION@@,$pkg_description,g;
261        s,@@LICENSE@@,$license,g;
262        s,@@AUTHOR@@,$author,g;
263        " < ${outfile}.in > $outfile
264   chmod 400 $outfile
265 }
266
267 #######################################################################
268 #
269 #                           MAIN()
270 #
271 #######################################################################
272
273 # Workaround for Solaris "Bad string" issue when LOCALE is undefined
274 tr="/usr/bin/tr"
275 test -f /usr/xpg4/bin/tr && tr="/usr/xpg4/bin/tr"
276
277 . ./config.inc
278
279 # Initialize the output files
280 #
281 for output_file in config.mk $program.pc
282 do
283    rm -f $output_file
284    echo "# AUTOMATICALLY GENERATED -- DO NOT EDIT" > $output_file
285 done
286 rm -f config.h
287 echo "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */" > config.h
288
289 process_argv "$*"
290 process_env
291
292 check_target
293 check_compiler
294 check_linker
295 check_archiver
296 check_install
297 check_diff
298
299
300 finalize program    "$program"
301 finalize version    "$version"
302 finalize abi_major  "$abi_major"
303 finalize abi_minor  "$abi_minor"
304 finalize abi_version "$abi_major.$abi_minor"
305 finalize prefix     "/usr/local"
306 finalize includedir "${prefix}/include"
307 finalize libdir     "${prefix}/lib"
308 finalize mandir     "${prefix}/share/man"
309 finalize cflags     "$cflags"
310 finalize libdepends "$libdepends"
311 finalize ldadd      ""
312 finalize ldflags    ""
313 finalize deps       ""
314 finalize ln         "/bin/ln"
315
316 pre_configure_hook
317
318 for header in $required_headers
319 do
320   check_header "$header" || err "$header is required, but cannot be found."
321 done
322 check_headers $optional_headers
323
324 post_configure_hook
325
326 objs="`echo \"$sources\" | sed 's/\.c/\.o/g'`"
327
328 subst_vars "$program.pc"
329 subst_vars "$program.la"
330 subst_vars "rpm.spec"
331
332 echo "Creating config.h"
333 export_to_c $c_exports
334
335 echo "Creating config.mk"
336 export_to_make "$make_exports"