2009-10-20 00:31:17 +00:00
|
|
|
#!/bin/sh
|
2010-09-12 18:28:35 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) 2009-2010 Mark Heily <mark@heily.com>
|
|
|
|
#
|
|
|
|
# Permission to use, copy, modify, and distribute this software for any
|
|
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
|
|
# copyright notice and this permission notice appear in all copies.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
#
|
|
|
|
|
2009-10-20 00:31:17 +00:00
|
|
|
|
2009-11-08 02:04:16 +00:00
|
|
|
c_exports="program version target cflags"
|
|
|
|
|
|
|
|
make_exports="program version target \
|
|
|
|
prefix libdir includedir mandir \
|
2009-11-08 05:53:38 +00:00
|
|
|
cflags ldflags ldadd libdepends \
|
2009-11-25 01:37:14 +00:00
|
|
|
sources objs deps mans headers extra_dist subdirs \
|
2010-04-03 16:18:42 +00:00
|
|
|
abi_major abi_minor abi_version \
|
|
|
|
cc cpp ld ln ar install diff"
|
2009-11-08 02:04:16 +00:00
|
|
|
|
|
|
|
required_headers=
|
|
|
|
optional_headers=
|
|
|
|
|
|
|
|
pre_configure_hook() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
post_configure_hook() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
export_to_make() {
|
|
|
|
for id in $*
|
|
|
|
do
|
2009-11-26 06:09:44 +00:00
|
|
|
|
|
|
|
# Prepend $DESTDIR to installation directories
|
|
|
|
case "$id" in
|
|
|
|
prefix|libdir|includedir|mandir)
|
|
|
|
eval "$id=\"\\\$\\\$DESTDIR\$$id\""
|
|
|
|
esac
|
|
|
|
|
2009-11-24 03:32:59 +00:00
|
|
|
uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
|
2009-11-08 02:04:16 +00:00
|
|
|
eval "echo \"$uc_id=\"\$$id\"\" >> config.mk"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
export_to_c() {
|
|
|
|
for id in $*
|
|
|
|
do
|
2009-11-24 03:32:59 +00:00
|
|
|
uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
|
2009-11-08 02:04:16 +00:00
|
|
|
eval "echo \"#define $uc_id \\\"\$$id\\\"\" >> config.h"
|
|
|
|
done
|
|
|
|
}
|
2009-11-01 19:06:43 +00:00
|
|
|
|
|
|
|
finalize() {
|
2009-11-24 03:32:59 +00:00
|
|
|
uc_id=`echo \"$1\" | $tr '[:lower:]' '[:upper:]'`;
|
2009-11-06 03:12:23 +00:00
|
|
|
eval "if [ \"\$$1\" = \"\" ] ; then $1=\"$2\" ; fi"
|
2009-11-01 19:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
process_argv() {
|
|
|
|
for arg in $*
|
|
|
|
do
|
|
|
|
id=`echo "$arg" | sed 's/=.*//; s/^--//;'`
|
|
|
|
val=`echo "$arg" | sed 's/^.*=//'`
|
|
|
|
if [ "$val" = "" ] ; then val=1 ; fi
|
2009-11-08 02:04:16 +00:00
|
|
|
eval "$id=\"$val\""
|
2009-11-01 19:06:43 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2009-11-24 03:32:59 +00:00
|
|
|
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"
|
2010-04-03 16:18:42 +00:00
|
|
|
test -n "$LN" && ld="$LN"
|
2009-11-24 03:32:59 +00:00
|
|
|
test -n "$LDFLAGS" && ldflags="$LDFLAGS"
|
|
|
|
test -n "$AR" && ar="$AR"
|
|
|
|
}
|
2009-11-08 05:53:38 +00:00
|
|
|
|
2009-10-20 00:31:17 +00:00
|
|
|
check_header() {
|
2009-11-08 02:04:16 +00:00
|
|
|
sym=`echo "have_$1" | sed 's,[./],_,g'`
|
2009-11-24 03:32:59 +00:00
|
|
|
uc_sym=`echo "$sym" | $tr '[:lower:]' '[:upper:]'`;
|
2009-11-01 19:06:43 +00:00
|
|
|
path=$1
|
|
|
|
|
|
|
|
printf "checking for $path.. "
|
|
|
|
if [ -f "/usr/include/$path" ] ; then
|
|
|
|
echo "yes"
|
2010-02-06 00:50:04 +00:00
|
|
|
echo "#define $uc_sym 1" >> config.h
|
2009-11-08 02:04:16 +00:00
|
|
|
eval "$sym=yes"
|
2009-10-20 00:31:17 +00:00
|
|
|
return 0
|
|
|
|
else
|
2009-11-01 19:06:43 +00:00
|
|
|
echo "no"
|
2009-11-08 02:04:16 +00:00
|
|
|
echo "#undef $uc_sym" >> config.h
|
|
|
|
eval "$sym=no"
|
2009-10-20 00:31:17 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-09-12 18:28:35 +00:00
|
|
|
# Determine the path to an executable binary
|
|
|
|
check_binary() {
|
|
|
|
id=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
for path in $*
|
|
|
|
do
|
|
|
|
test -f $path
|
|
|
|
if [ $? = 0 ] ; then
|
|
|
|
eval "$id=\"$path\""
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "not found"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2009-11-08 02:04:16 +00:00
|
|
|
check_headers() {
|
|
|
|
for header in $*
|
|
|
|
do
|
|
|
|
check_header "$header"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2009-11-08 05:09:30 +00:00
|
|
|
check_symbol() {
|
|
|
|
header=$1
|
|
|
|
symbol=$2
|
|
|
|
|
2009-11-24 03:32:59 +00:00
|
|
|
uc_symbol=`echo "HAVE_$symbol" | $tr '[:lower:]' '[:upper:]' | sed 's,[./],_,g'`
|
|
|
|
lc_symbol=`echo "have_$symbol" | $tr '[:upper:]' '[:lower:]' | sed 's,[./],_,g'`
|
2009-11-08 05:53:38 +00:00
|
|
|
|
|
|
|
if [ -f "$header" ] ; then
|
|
|
|
path="$header"
|
|
|
|
elif [ -f "/usr/include/$header" ] ; then
|
2009-11-08 05:56:34 +00:00
|
|
|
path="/usr/include/$header"
|
2009-11-08 05:53:38 +00:00
|
|
|
else
|
|
|
|
echo "*** ERROR: Cannot find <$header>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-11-08 05:56:34 +00:00
|
|
|
printf "checking $header for $symbol.. "
|
2009-11-08 05:53:38 +00:00
|
|
|
if [ "`grep $symbol $path`" != "" ] ; then
|
2009-11-08 05:09:30 +00:00
|
|
|
eval "$lc_symbol=yes"
|
2009-11-08 05:24:21 +00:00
|
|
|
echo "#define $uc_symbol 1" >> config.h
|
|
|
|
echo "yes"
|
2009-11-08 05:09:30 +00:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
eval "$lc_symbol=no"
|
2009-11-08 05:24:21 +00:00
|
|
|
echo "no"
|
2009-11-08 05:09:30 +00:00
|
|
|
echo "#undef $uc_symbol" >> config.h
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-11-08 02:04:16 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2009-11-24 03:32:59 +00:00
|
|
|
check_target() {
|
|
|
|
printf "checking operating system type.. "
|
|
|
|
default_target=`uname -s | $tr '[:upper:]' '[:lower:]'`
|
|
|
|
if [ "$default_target" = "sunos" ] ; then
|
|
|
|
default_target="solaris"
|
|
|
|
fi
|
2010-08-07 23:18:03 +00:00
|
|
|
if [ "$default_target" = "gnu/kfreebsd" ] ; then
|
|
|
|
default_target="freebsd"
|
|
|
|
fi
|
2009-11-24 03:32:59 +00:00
|
|
|
finalize target "$default_target"
|
|
|
|
echo "$target"
|
|
|
|
}
|
|
|
|
|
|
|
|
check_compiler() {
|
|
|
|
printf "checking for a C compiler.. "
|
2010-09-12 18:28:35 +00:00
|
|
|
check_binary default_cc "/usr/bin/cc" "/usr/bin/gcc" "/usr/sfw/bin/gcc"
|
2009-11-24 03:32:59 +00:00
|
|
|
finalize cc "$default_cc"
|
|
|
|
echo "$cc"
|
|
|
|
}
|
|
|
|
|
|
|
|
check_linker() {
|
|
|
|
printf "checking for a suitable linker.. "
|
2009-11-26 06:09:44 +00:00
|
|
|
|
|
|
|
# Workaround for "hidden symbol <foo> is referenced by DSO" linker error
|
|
|
|
# seen when compiling libdispatch.
|
|
|
|
# Appears to be a problem with GCC 4.0 and binutils
|
|
|
|
#
|
|
|
|
default_ld="$cc"
|
2010-08-03 02:46:27 +00:00
|
|
|
ldflags="-shared -o $program.so.$abi_major.$abi_minor $ldflags"
|
2010-07-27 01:24:06 +00:00
|
|
|
|
2010-08-03 02:46:27 +00:00
|
|
|
# FIXME: port to solaris
|
2010-07-27 01:24:06 +00:00
|
|
|
if [ "$target" = "linux" ] ; then
|
2010-08-03 02:46:27 +00:00
|
|
|
ldflags="$ldflags -Wl,-export-dynamic -Wl,-soname,$program.so.$abi_major"
|
2010-07-27 01:24:06 +00:00
|
|
|
fi
|
2009-11-26 06:09:44 +00:00
|
|
|
|
2010-07-28 00:15:09 +00:00
|
|
|
if [ "$target" = "solaris" ] ; then
|
2010-08-03 02:46:27 +00:00
|
|
|
ldflags="$ldflags"
|
2010-07-28 00:15:09 +00:00
|
|
|
fi
|
|
|
|
|
2009-11-24 03:32:59 +00:00
|
|
|
finalize ld "$default_ld"
|
|
|
|
echo "$ld"
|
|
|
|
}
|
|
|
|
|
|
|
|
check_archiver() {
|
|
|
|
printf "checking for a suitable archiver.. "
|
2010-09-12 18:28:35 +00:00
|
|
|
if [ "`uname -s`" = "SunOS" -a "`uname -v | grep Nexenta`" = "" ] ; then
|
2009-11-24 03:32:59 +00:00
|
|
|
default_ar="/usr/sfw/bin/gar"
|
|
|
|
else
|
|
|
|
default_ar="/usr/bin/ar"
|
|
|
|
fi
|
|
|
|
finalize ar "$default_ar"
|
|
|
|
echo "$ar"
|
|
|
|
}
|
2010-02-10 03:22:39 +00:00
|
|
|
|
2009-11-08 02:04:16 +00:00
|
|
|
err() {
|
|
|
|
echo "*** ERROR *** $*"
|
2010-02-10 03:22:39 +00:00
|
|
|
rm -f config.mk $program.pc config.h
|
2009-11-08 02:04:16 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2010-01-30 05:11:40 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2009-11-16 03:54:47 +00:00
|
|
|
subst_vars() {
|
|
|
|
outfile=$1
|
|
|
|
|
|
|
|
if [ ! -f "${outfile}.in" ] ; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Creating $outfile"
|
|
|
|
rm -f $outfile
|
|
|
|
sed -e "
|
2010-09-15 02:24:34 +00:00
|
|
|
s,@@CWD@@,`pwd`,g;
|
2009-11-16 03:54:47 +00:00
|
|
|
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;
|
2010-12-24 17:34:51 +00:00
|
|
|
s,@@RPM_DATE@@,`date +'%a %b %d %Y'`,g;
|
2009-11-16 03:54:47 +00:00
|
|
|
s,@@PKG_DESCRIPTION@@,$pkg_description,g;
|
|
|
|
s,@@LICENSE@@,$license,g;
|
|
|
|
s,@@AUTHOR@@,$author,g;
|
|
|
|
" < ${outfile}.in > $outfile
|
|
|
|
chmod 400 $outfile
|
|
|
|
}
|
|
|
|
|
2009-11-01 19:06:43 +00:00
|
|
|
#######################################################################
|
|
|
|
#
|
|
|
|
# MAIN()
|
|
|
|
#
|
|
|
|
#######################################################################
|
2009-10-20 00:31:17 +00:00
|
|
|
|
2009-11-24 03:32:59 +00:00
|
|
|
# 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
|
|
|
|
|
2009-11-01 19:06:43 +00:00
|
|
|
# Initialize the output files
|
|
|
|
#
|
2009-11-06 03:12:23 +00:00
|
|
|
for output_file in config.mk $program.pc
|
2009-11-01 19:06:43 +00:00
|
|
|
do
|
|
|
|
rm -f $output_file
|
|
|
|
echo "# AUTOMATICALLY GENERATED -- DO NOT EDIT" > $output_file
|
|
|
|
done
|
2009-11-06 03:12:23 +00:00
|
|
|
rm -f config.h
|
|
|
|
echo "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */" > config.h
|
2009-11-01 19:06:43 +00:00
|
|
|
|
2009-11-08 02:04:16 +00:00
|
|
|
process_argv "$*"
|
2009-11-24 03:32:59 +00:00
|
|
|
process_env
|
|
|
|
|
|
|
|
check_target
|
|
|
|
check_compiler
|
|
|
|
check_linker
|
|
|
|
check_archiver
|
|
|
|
check_install
|
2010-01-30 05:11:40 +00:00
|
|
|
check_diff
|
2009-11-01 19:06:43 +00:00
|
|
|
|
2009-11-08 02:04:16 +00:00
|
|
|
finalize program "$program"
|
|
|
|
finalize version "$version"
|
2010-04-03 16:18:42 +00:00
|
|
|
finalize abi_major "$abi_major"
|
|
|
|
finalize abi_minor "$abi_minor"
|
|
|
|
finalize abi_version "$abi_major.$abi_minor"
|
2009-11-08 02:04:16 +00:00
|
|
|
finalize prefix "/usr/local"
|
2009-11-01 19:06:43 +00:00
|
|
|
finalize libdir "${prefix}/lib"
|
|
|
|
finalize includedir "${prefix}/include"
|
|
|
|
finalize mandir "${prefix}/share/man"
|
2009-11-08 02:04:16 +00:00
|
|
|
finalize cflags "$cflags"
|
|
|
|
finalize libdepends "$libdepends"
|
2009-11-08 05:53:38 +00:00
|
|
|
finalize ldadd ""
|
|
|
|
finalize ldflags ""
|
2009-11-25 01:37:14 +00:00
|
|
|
finalize deps ""
|
2010-04-03 16:18:42 +00:00
|
|
|
finalize ln "`which ln`"
|
2009-11-08 02:04:16 +00:00
|
|
|
|
|
|
|
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
|
2009-10-20 00:31:17 +00:00
|
|
|
|
2009-11-25 00:28:12 +00:00
|
|
|
objs="`echo \"$sources\" | sed 's/\.c/\.o/g'`"
|
|
|
|
|
2009-11-16 03:54:47 +00:00
|
|
|
subst_vars "$program.pc"
|
2009-11-18 01:22:29 +00:00
|
|
|
subst_vars "$program.la"
|
2009-11-16 03:54:47 +00:00
|
|
|
subst_vars "rpm.spec"
|
2009-11-01 23:49:32 +00:00
|
|
|
|
2009-11-08 02:04:16 +00:00
|
|
|
echo "Creating config.h"
|
|
|
|
export_to_c $c_exports
|
|
|
|
|
2009-11-01 23:49:32 +00:00
|
|
|
echo "Creating config.mk"
|
2009-11-08 02:04:16 +00:00
|
|
|
export_to_make "$make_exports"
|