3 # Copyright (c) 2009-2011 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.
18 makeconf_version="$Revision: 10 $"
20 c_exports="program version target api cflags"
22 make_exports="program version target api distfile basedir \
23 prefix bindir sbindir libdir includedir mandir \
24 cflags ldflags ldadd libdepends \
25 sources objs deps mans headers extra_dist subdirs \
26 abi_major abi_minor abi_version \
27 cc cpp ld ln ar install diff"
32 pre_configure_hook() {
36 post_configure_hook() {
43 uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
44 eval "echo \"$uc_id=\"\$$id\"\" >> config.mk"
51 uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
52 eval "echo \"#define $uc_id \\\"\$$id\\\"\" >> config.h"
57 uc_id=`echo \"$1\" | $tr '[:lower:]' '[:upper:]'`;
58 eval "if [ \"\$$1\" = \"\" ] ; then $1=\"$2\" ; fi"
64 if [ "$arg" = "--makeconf-version" ] ; then
65 echo $makeconf_version | sed 's/[^0-9.]//g'
68 id=`echo "$arg" | sed 's/=.*//; s/^--//;'`
69 val=`echo "$arg" | sed 's/^.*=//'`
70 if [ "$val" = "" ] ; then val=1 ; fi
76 test -n "$CC" && cc="$CC"
77 test -n "$CPP" && cpp="$CPP"
78 test -n "$CPPFLAGS" && cppflags="$CPPFLAGS"
79 test -n "$CFLAGS" && cflags="$CFLAGS"
80 test -n "$LD" && ld="$LD"
81 test -n "$LN" && ld="$LN"
82 test -n "$LDFLAGS" && ldflags="$LDFLAGS"
83 test -n "$AR" && ar="$AR"
88 sym=`echo "have_$1" | sed 's,[./],_,g'`
89 uc_sym=`echo "$sym" | $tr '[:lower:]' '[:upper:]'`;
92 printf "checking for $path.. "
93 if [ -f "/usr/include/$path" ] ; then
95 echo "#define $uc_sym 1" >> config.h
100 echo "#undef $uc_sym" >> config.h
106 # Determine the path to an executable binary
127 check_header "$header"
135 uc_symbol=`echo "HAVE_$symbol" | $tr '[:lower:]' '[:upper:]' | sed 's,[./],_,g'`
136 lc_symbol=`echo "have_$symbol" | $tr '[:upper:]' '[:lower:]' | sed 's,[./],_,g'`
138 if [ -f "$header" ] ; then
140 elif [ -f "/usr/include/$header" ] ; then
141 path="/usr/include/$header"
143 echo "*** ERROR: Cannot find <$header>"
147 printf "checking $header for $symbol.. "
148 if [ "`grep $symbol $path`" != "" ] ; then
149 eval "$lc_symbol=yes"
150 echo "#define $uc_symbol 1" >> config.h
156 echo "#undef $uc_symbol" >> config.h
162 printf "checking for a BSD-compatible install.. "
163 if [ "`uname -s`" = "SunOS" ] ; then
164 default_install=/usr/ucb/install
166 default_install=/usr/bin/install
168 finalize install "$default_install"
173 printf "checking operating system type.. "
174 default_target=`uname -s | $tr '[:upper:]' '[:lower:]'`
176 case "$default_target" in
178 default_target="solaris"
181 default_target="freebsd"
184 default_target="windows"
185 default_api="windows"
188 finalize target "$default_target"
189 finalize api "$default_api"
194 printf "checking for a C compiler.. "
195 check_binary default_cc "$cc" "`which $cc 2>/dev/null`" "/usr/bin/cc" "/usr/bin/gcc" "/usr/sfw/bin/gcc" "`which gcc 2>/dev/null`"
196 finalize cc "$default_cc"
197 # test -x "$cc" || err "Unable to locate a C compiler"
202 printf "checking for a suitable linker.. "
204 # Workaround for "hidden symbol <foo> is referenced by DSO" linker error
205 # seen when compiling libdispatch.
206 # Appears to be a problem with GCC 4.0 and binutils
209 ldflags="-o $program.so.$abi_major.$abi_minor $ldflags"
211 # FIXME: port to solaris
212 if [ "$target" = "linux" ] ; then
213 ldflags="$ldflags -Wl,-export-dynamic -Wl,-soname,$program.so.$abi_major"
216 if [ "$target" = "solaris" ] ; then
220 finalize ld "$default_ld"
225 printf "checking for a suitable archiver.. "
226 if [ "`uname -s`" = "SunOS" -a "`uname -v | grep Nexenta`" = "" ] ; then
227 default_ar="/usr/sfw/bin/gar"
229 default_ar="/usr/bin/ar"
231 finalize ar "$default_ar"
236 echo "*** ERROR *** $*"
237 rm -f config.mk $program.pc config.h
242 # TODO: Support non-GNU diff syntax
243 # TODO: Search for the command
244 printf "checking for a suitable diff(1) command.. "
245 finalize diff "diff -ruN -dEbwBp -x .svn -x .o -x config.h -x config.mk"
252 if [ ! -f "${outfile}.in" ] ; then
256 echo "Creating $outfile"
260 s,@@PROGRAM@@,$program,g;
261 s,@@VERSION@@,$version,g;
262 s,@@PREFIX@@,$prefix,g;
263 s,@@LIBDIR@@,$libdir,g;
264 s,@@INCLUDEDIR@@,$includedir,g;
265 s,@@MANDIR@@,$mandir,g;
266 s,@@LIBDEPENDS@@,$libdepends,g;
267 s,@@PKG_SUMMARY@@,$pkg_summary,g;
268 s,@@RPM_DATE@@,`date +'%a %b %d %Y'`,g;
269 s,@@PKG_DESCRIPTION@@,$pkg_description,g;
270 s,@@LICENSE@@,$license,g;
271 s,@@AUTHOR@@,$author,g;
272 " < ${outfile}.in > $outfile
276 #######################################################################
280 #######################################################################
282 # Workaround for Solaris "Bad string" issue when LOCALE is undefined
284 test -f /usr/xpg4/bin/tr && tr="/usr/xpg4/bin/tr"
288 # Initialize the output files
290 for output_file in config.mk
293 echo "# AUTOMATICALLY GENERATED -- DO NOT EDIT" > $output_file
295 if [ "$sources" != "" ] ; then
297 echo "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */" > config.h
310 finalize program "$program"
311 finalize version "$version"
312 finalize abi_major "$abi_major"
313 finalize abi_minor "$abi_minor"
314 finalize abi_version "$abi_major.$abi_minor"
315 finalize prefix "/usr/local"
316 finalize bindir "\\\$(PREFIX)/bin"
317 finalize sbindir "\\\$(PREFIX)/sbin"
318 finalize libdir "\\\$(PREFIX)/lib"
319 finalize includedir "\\\$(PREFIX)/include"
320 finalize mandir "\\\$(PREFIX)/share/man"
321 finalize cflags "$cflags"
322 finalize libdepends "$libdepends"
326 finalize ln "/bin/ln"
327 finalize distfile "$program-$version.tar.gz"
331 for header in $required_headers
333 check_header "$header" || err "$header is required, but cannot be found."
335 check_headers $optional_headers
339 objs="`echo \"$sources\" | sed 's/\.c/\.o/g'`"
341 subst_vars "$program.pc"
342 subst_vars "$program.la"
343 subst_vars "rpm.spec"
345 if [ "$sources" != "" ] ; then
346 echo "Creating config.h"
347 export_to_c $c_exports
350 echo "Creating config.mk"
351 export_to_make "$make_exports"