3 # Copyright (c) 2009-2010 Mark Heily <mark@heily.com>
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.
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.
19 c_exports="program version target cflags"
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"
31 pre_configure_hook() {
35 post_configure_hook() {
43 # Prepend $DESTDIR to installation directories
45 prefix|libdir|includedir|mandir)
46 eval "$id=\"\\\$\\\$DESTDIR\$$id\""
49 uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
50 eval "echo \"$uc_id=\"\$$id\"\" >> config.mk"
57 uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
58 eval "echo \"#define $uc_id \\\"\$$id\\\"\" >> config.h"
63 uc_id=`echo \"$1\" | $tr '[:lower:]' '[:upper:]'`;
64 eval "if [ \"\$$1\" = \"\" ] ; then $1=\"$2\" ; fi"
70 id=`echo "$arg" | sed 's/=.*//; s/^--//;'`
71 val=`echo "$arg" | sed 's/^.*=//'`
72 if [ "$val" = "" ] ; then val=1 ; fi
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"
89 sym=`echo "have_$1" | sed 's,[./],_,g'`
90 uc_sym=`echo "$sym" | $tr '[:lower:]' '[:upper:]'`;
93 printf "checking for $path.. "
94 if [ -f "/usr/include/$path" ] ; then
96 echo "#define $uc_sym 1" >> config.h
101 echo "#undef $uc_sym" >> config.h
107 # Determine the path to an executable binary
128 check_header "$header"
136 uc_symbol=`echo "HAVE_$symbol" | $tr '[:lower:]' '[:upper:]' | sed 's,[./],_,g'`
137 lc_symbol=`echo "have_$symbol" | $tr '[:upper:]' '[:lower:]' | sed 's,[./],_,g'`
139 if [ -f "$header" ] ; then
141 elif [ -f "/usr/include/$header" ] ; then
142 path="/usr/include/$header"
144 echo "*** ERROR: Cannot find <$header>"
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
157 echo "#undef $uc_symbol" >> config.h
163 printf "checking for a BSD-compatible install.. "
164 if [ "`uname -s`" = "SunOS" ] ; then
165 default_install=/usr/ucb/install
167 default_install=/usr/bin/install
169 finalize install "$default_install"
174 printf "checking operating system type.. "
175 default_target=`uname -s | $tr '[:upper:]' '[:lower:]'`
176 if [ "$default_target" = "sunos" ] ; then
177 default_target="solaris"
179 if [ "$default_target" = "gnu/kfreebsf libkqueue.so.0.0 libkqueue.sosd" ] ; then
180 default_target="freebsd"
182 finalize target "$default_target"
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"
194 printf "checking for a suitable linker.. "
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
201 ldflags="-shared -o $program.so.$abi_major.$abi_minor $ldflags"
203 # FIXME: port to solaris
204 if [ "$target" = "linux" ] ; then
205 ldflags="$ldflags -Wl,-export-dynamic -Wl,-soname,$program.so.$abi_major"
208 if [ "$target" = "solaris" ] ; then
212 finalize ld "$default_ld"
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"
221 default_ar="/usr/bin/ar"
223 finalize ar "$default_ar"
228 echo "*** ERROR *** $*"
229 rm -f config.mk $program.pc config.h
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"
244 if [ ! -f "${outfile}.in" ] ; then
248 echo "Creating $outfile"
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
267 #######################################################################
271 #######################################################################
273 # Workaround for Solaris "Bad string" issue when LOCALE is undefined
275 test -f /usr/xpg4/bin/tr && tr="/usr/xpg4/bin/tr"
279 # Initialize the output files
281 for output_file in config.mk $program.pc
284 echo "# AUTOMATICALLY GENERATED -- DO NOT EDIT" > $output_file
287 echo "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */" > config.h
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"
314 finalize ln "/bin/ln"
318 for header in $required_headers
320 check_header "$header" || err "$header is required, but cannot be found."
322 check_headers $optional_headers
326 objs="`echo \"$sources\" | sed 's/\.c/\.o/g'`"
328 subst_vars "$program.pc"
329 subst_vars "$program.la"
330 subst_vars "rpm.spec"
332 echo "Creating config.h"
333 export_to_c $c_exports
335 echo "Creating config.mk"
336 export_to_make "$make_exports"