#!/bin/sh # # TODO: backport 'distfile' to ./configure trunk c_exports="program version target cflags" make_exports="program version target distfile \ prefix libdir includedir mandir \ cflags ldflags ldadd libdepends \ sources objs deps mans headers extra_dist subdirs \ abi_major abi_minor abi_version \ cc cpp ld ln ar install diff" required_headers= optional_headers= pre_configure_hook() { return } post_configure_hook() { return } export_to_make() { for id in $* do # Prepend $DESTDIR to installation directories case "$id" in prefix|libdir|includedir|mandir) eval "$id=\"\\\$\\\$DESTDIR\$$id\"" esac uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`; eval "echo \"$uc_id=\"\$$id\"\" >> config.mk" done } export_to_c() { for id in $* do uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`; eval "echo \"#define $uc_id \\\"\$$id\\\"\" >> config.h" done } finalize() { uc_id=`echo \"$1\" | $tr '[:lower:]' '[:upper:]'`; eval "if [ \"\$$1\" = \"\" ] ; then $1=\"$2\" ; fi" } process_argv() { for arg in $* do id=`echo "$arg" | sed 's/=.*//; s/^--//;'` val=`echo "$arg" | sed 's/^.*=//'` if [ "$val" = "" ] ; then val=1 ; fi eval "$id=\"$val\"" done } process_env() { test -n "$CC" && cc="$CC" test -n "$CPP" && cpp="$CPP" test -n "$CPPFLAGS" && cppflags="$CPPFLAGS" test -n "$CFLAGS" && cflags="$CFLAGS" test -n "$LD" && ld="$LD" test -n "$LN" && ld="$LN" test -n "$LDFLAGS" && ldflags="$LDFLAGS" test -n "$AR" && ar="$AR" } check_header() { sym=`echo "have_$1" | sed 's,[./],_,g'` uc_sym=`echo "$sym" | $tr '[:lower:]' '[:upper:]'`; path=$1 printf "checking for $path.. " if [ -f "/usr/include/$path" ] ; then echo "yes" echo "#define $uc_sym 1" >> config.h eval "$sym=yes" return 0 else echo "no" echo "#undef $uc_sym" >> config.h eval "$sym=no" return 1 fi } check_headers() { for header in $* do check_header "$header" done } check_symbol() { header=$1 symbol=$2 uc_symbol=`echo "HAVE_$symbol" | $tr '[:lower:]' '[:upper:]' | sed 's,[./],_,g'` lc_symbol=`echo "have_$symbol" | $tr '[:upper:]' '[:lower:]' | sed 's,[./],_,g'` if [ -f "$header" ] ; then path="$header" elif [ -f "/usr/include/$header" ] ; then path="/usr/include/$header" else echo "*** ERROR: Cannot find <$header>" exit 1 fi printf "checking $header for $symbol.. " if [ "`grep $symbol $path`" != "" ] ; then eval "$lc_symbol=yes" echo "#define $uc_symbol 1" >> config.h echo "yes" return 0 else eval "$lc_symbol=no" echo "no" echo "#undef $uc_symbol" >> config.h return 1 fi } check_install() { printf "checking for a BSD-compatible install.. " if [ "`uname -s`" = "SunOS" ] ; then default_install=/usr/ucb/install else default_install=/usr/bin/install fi finalize install "$default_install" echo "$install" } check_target() { printf "checking operating system type.. " default_target=`uname -s | $tr '[:upper:]' '[:lower:]'` if [ "$default_target" = "sunos" ] ; then default_target="solaris" fi finalize target "$default_target" echo "$target" } check_compiler() { printf "checking for a C compiler.. " if [ "`uname -s`" = "SunOS" ] ; then default_cc="/usr/sfw/bin/gcc" else default_cc="/usr/bin/cc" fi finalize cc "$default_cc" echo "$cc" } check_linker() { printf "checking for a suitable linker.. " # Disabled due to problems with ld(1) under Linux #if [ "`uname -s`" = "SunOS" ] ; then # default_ld="/usr/sfw/bin/gld" #else # default_ld="/usr/bin/ld" #fi #ldflags="-shared -export-dynamic -soname $program.so $ldflags" # Workaround for "hidden symbol is referenced by DSO" linker error # seen when compiling libdispatch. # Appears to be a problem with GCC 4.0 and binutils # default_ld="$cc" ldflags="-shared -Wl,-export-dynamic -Wl,-soname,$program.so.$abi_major -o $program.so.$abi_major.$abi_minor $ldflags" finalize ld "$default_ld" echo "$ld" } check_archiver() { printf "checking for a suitable archiver.. " if [ "`uname -s`" = "SunOS" ] ; then default_ar="/usr/sfw/bin/gar" else default_ar="/usr/bin/ar" fi finalize ar "$default_ar" echo "$ar" } err() { echo "*** ERROR *** $*" rm -f config.mk $program.pc config.h exit 1 } check_diff() { # TODO: Support non-GNU diff syntax # TODO: Search for the command printf "checking for a suitable diff(1) command.. " finalize diff "diff -ruN -dEbwBp -x .svn -x .o -x config.h -x config.mk" echo "found" } subst_vars() { outfile=$1 if [ ! -f "${outfile}.in" ] ; then return fi echo "Creating $outfile" rm -f $outfile sed -e " s,@@PROGRAM@@,$program,g; s,@@VERSION@@,$version,g; s,@@PREFIX@@,$prefix,g; s,@@LIBDIR@@,$libdir,g; s,@@INCLUDEDIR@@,$includedir,g; s,@@MANDIR@@,$mandir,g; s,@@LIBDEPENDS@@,$libdepends,g; s,@@PKG_SUMMARY@@,$pkg_summary,g; s,@@PKG_DESCRIPTION@@,$pkg_description,g; s,@@LICENSE@@,$license,g; s,@@AUTHOR@@,$author,g; " < ${outfile}.in > $outfile chmod 400 $outfile } ####################################################################### # # MAIN() # ####################################################################### # Workaround for Solaris "Bad string" issue when LOCALE is undefined tr="/usr/bin/tr" test -f /usr/xpg4/bin/tr && tr="/usr/xpg4/bin/tr" . ./config.inc # Initialize the output files # for output_file in config.mk $program.pc do rm -f $output_file echo "# AUTOMATICALLY GENERATED -- DO NOT EDIT" > $output_file done rm -f config.h echo "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */" > config.h process_argv "$*" process_env check_target check_compiler check_linker check_archiver check_install check_diff finalize program "$program" finalize version "$version" finalize abi_major "$abi_major" finalize abi_minor "$abi_minor" finalize abi_version "$abi_major.$abi_minor" finalize prefix "/usr/local" finalize libdir "${prefix}/lib" finalize includedir "${prefix}/include" finalize mandir "${prefix}/share/man" finalize cflags "$cflags" finalize libdepends "$libdepends" finalize ldadd "" finalize ldflags "" finalize deps "" finalize ln "/bin/ln" finalize distfile "$program-$version.tar.gz" pre_configure_hook for header in $required_headers do check_header "$header" || err "$header is required, but cannot be found." done check_headers $optional_headers post_configure_hook objs="`echo \"$sources\" | sed 's/\.c/\.o/g'`" subst_vars "$program.pc" subst_vars "$program.la" subst_vars "rpm.spec" echo "Creating config.h" export_to_c $c_exports echo "Creating config.mk" export_to_make "$make_exports" make clean >/dev/null 2>&1