dnl configure.in for swbis


dnl Macro: AC_ARG_ENABLE (feature, help-string [, action-if-given [, action-if-not-given]]) 
dnl Macro: AC_ARG_WITH (package, help-string [, action-if-given [, action-if-not-given]]) 

AC_INIT([swbis], [0.499], [bug-swbis@gnu.org])
AM_INIT_AUTOMAKE
AC_CONFIG_HEADER(config.h)

# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.52)
min_automake_version="1.7.6"
AM_GNU_GETTEXT_VERSION(0.11.4)

dnl AC_ARG_WITH(tar,  --with-tar   compiled default pax utility, paxcommand=tar, paxcommand=false)
dnl AC_ARG_WITH(pax,  --with-pax   compiled default pax utility, paxcommand=pax, paxcommand=false)
dnl AC_ARG_WITH(star,  --with-star  compiled default pax utility, paxcommand=star, paxcommand=false)
dnl AC_ARG_WITH(gtar,  --with-gtar  compiled default pax utility, paxcommand=gtar, paxcommand=false)

usewithdbdump=no
usewithrpm=no
usewithselfrpm=yes
usewithoutrpm=no
compile_test_pgms=no

dnl export usewithdbdump
dnl export usewithrpm
dnl export usewithselfrpm
dnl export usewithoutrpm
dnl export compile_test_pgms
dnl export usewithoutflex
dnl export usewithoutbison


AC_ARG_WITH(debugdump,  --with-debugdump   compile object debugging code, usewithdbdump=yes, usewithdbdump=no)
AC_ARG_WITH(rpm,  --with-rpm   compile RPM decoding and translating program, usewithrpm=yes, usewithrpm=no)
AC_ARG_WITH(self-rpm,  --with-self-rpm   compile RPM decoding and translating program, usewithselfrpm=yes, usewithselfrpm=yes)
AC_ARG_WITH(no-rpm,  --with-no-rpm  dont compile rpm code, usewithselfrpm=no; usewithrpm=no; usewithoutrpm=yes, usewithoutrpm=no)
AC_ARG_WITH(tests,  --with-tests  compile test programs, compile_test_pgms=yes, compile_test_pgms=no)
AC_ARG_WITH(no-flex,  --with-no-flex  dont use flex, usewithoutflex=yes, usewithoutflex=no)
AC_ARG_WITH(no-bison,  --with-no-bison  dont use bison, usewithoutbison=yes, usewithoutbison=no)
dnl AC_ARG_WITH(flex,  --with-flex  use flex, usewithoutflex=no, usewithoutflex=yes)
dnl AC_ARG_WITH(bison,  --with-bison  use bison, usewithoutbison=no, usewithoutbison=yes)

if test $usewithoutrpm = yes; then
	usewithselfrpm=no
fi

LIBINTL=""
PO=""
GETTEXTSTUB="gettextstub.o"

AC_CANONICAL_HOST


AC_PROG_CC
AC_PROG_CXX

AC_PROG_INSTALL
AC_PROG_CPP                     dnl Later checks need this.
AC_PROG_CC_C_O
AC_PROG_LEX
AC_PROG_YACC
AC_PROG_AWK
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB

topincdir=`pwd`/include
topdir=`pwd`
topdirswsupplib=$topdir/swsupplib
export topdirswsupplib

export usewithdbdump

AC_MSG_CHECKING(docbook-to-man...)
AC_CHECK_PROG(DOCBOOKTOMAN, docbook-to-man, cat)

AC_AIX
AC_ISC_POSIX
AC_MINIX
AC_HEADER_STDC
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_TYPE_SIGNAL
AC_CHECK_HEADERS(error.h)
AC_CHECK_HEADERS(rpm/rpmio.h rpm/header.h rpm/rpmlib.h popt.h)
AC_CHECK_HEADERS(unistd.h termios.h termio.h sgtty.h stdarg.h getopt.h)
AC_CHECK_HEADERS(fcntl.h sys/fcntl.h sys/wait.h)

AC_DEFUN(jm_MACROS,
[ 
AC_REQUIRE([jm_FUNC_FPENDING])
])

dnl From Jim Meyering
dnl Using code from emacs, based on suggestions from Paul Eggert
dnl and Ulrich Drepper.

dnl Find out how to determine the number of pending output bytes on a stream.
dnl glibc (2.1.93 and newer) and Solaris provide __fpending.  On other systems,
dnl we have to grub around in the FILE struct.

AC_DEFUN(jm_FUNC_FPENDING,
[
  AC_CHECK_HEADERS(stdio_ext.h)
  AC_REPLACE_FUNCS([__fpending])
  fp_headers='
#     if HAVE_STDIO_EXT_H
#      include <stdio_ext.h>
#     endif
'
  AC_CHECK_DECLS([__fpending], , , $fp_headers)
  if test $ac_cv_func___fpending = no; then
    AC_CACHE_CHECK(
	      [how to determine the number of pending output bytes on a stream],
		   ac_cv_sys_pending_output_n_bytes,
      [
        fp_save_DEFS=$DEFS
	for ac_expr in						\
								\
	    '# glibc2'						\
	    'fp->_IO_write_ptr - fp->_IO_write_base'		\
								\
	    '# traditional Unix'				\
	    'fp->_ptr - fp->_base'				\
								\
	    '# BSD'						\
	    'fp->_p - fp->_bf._base'				\
								\
	    '# SCO, Unixware'					\
	    'fp->__ptr - fp->__base'				\
								\
	    '# old glibc?'					\
	    'fp->__bufp - fp->__buffer'				\
								\
	    '# old glibc iostream?'				\
	    'fp->_pptr - fp->_pbase'				\
								\
	    '# VMS'						\
	    '(*fp)->_ptr - (*fp)->_base'			\
								\
	    '# e.g., DGUX R4.11; the info is not available'	\
	    1							\
	    ; do

	  # Skip each embedded comment.
	  case "$ac_expr" in '#'*) continue;; esac

	  DEFS="$DEFS -DPENDING_OUTPUT_N_BYTES=$ac_expr"
	  AC_TRY_COMPILE(
	    [#include <stdio.h>
	    ],
	    [FILE *fp = stdin; (void) ($ac_expr);],
	    fp_done=yes
	  )
	  DEFS=$fp_save_DEFS
	  test "$fp_done" = yes && break
	done

	ac_cv_sys_pending_output_n_bytes=$ac_expr
      ]
    )
    AC_DEFINE_UNQUOTED(PENDING_OUTPUT_N_BYTES,
      $ac_cv_sys_pending_output_n_bytes,
      [the number of pending output bytes on stream `fp'])
  fi
])



echo "checking for --with-debugdump configure option"
if test $usewithdbdump = "yes"; then
AC_DEFINE(HAVE_WITH_DEBUGDUMP,,[include debugging routines])
DO_DEBUG=yes
else
DO_DEBUG=""
fi

echo "checking for <sstream>"
find /usr/include | egrep '/sstream$' 1>/dev/null
if test $? -eq 0; then
AC_DEFINE(HAVE_SSTREAM,,[sstream])
fi

echo "checking for <iostream>"
find /usr/include | egrep '/iostream$' 1>/dev/null
if test $? -eq 0; then
AC_DEFINE(HAVE_IOSTREAM,,[iostream])
fi

echo "checking for <istream>"
find /usr/include | egrep '/istream$' 1>/dev/null
if test $? -eq 0; then
AC_DEFINE(HAVE_ISTREAM,,[istream])
fi

echo "checking for <ostream>"
find /usr/include | egrep '/ostream$' 1>/dev/null
if test $? -eq 0; then
AC_DEFINE(HAVE_OSTREAM,,[ostream])
fi

dnl AC_CHECK_FUNCS(tcsetattr stty setsid geteuid seteuid  \
dnl   snprintf vprintf vsnprintf vsyslog getopt_long openpty)

dnl Check out the wait reality.  We have to assume sys/wait.h is present.
AC_CHECK_FUNCS(waitpid wait3)
AC_MSG_CHECKING(for union wait);
AC_TRY_LINK([#include <sys/types.h>
#include <sys/wait.h>],
                 [union wait status; int pid; pid = wait (&status);
#ifdef WEXITSTATUS
/* Some POSIXoid systems have both the new-style macros and the old
   union wait type, and they do not work together.  If union wait
   conflicts with WEXITSTATUS et al, we don't want to use it at all.  */
if (WEXITSTATUS (status) != 0) pid = -1;
#endif
#ifdef HAVE_WAITPID
/* Make sure union wait works with waitpid.  */
pid = waitpid (-1, &status, 0);
#endif
],
  [AC_DEFINE(HAVE_UNION_WAIT,,[have_union_wait]) AC_MSG_RESULT(yes)],
  AC_MSG_RESULT(no))

AC_C_CONST                      dnl getopt needs this.

AC_CHECK_LIB(rt, main)

if test "$GCC" = yes
then

GCC_W_NO_DEPRECATED=""
echo "checking for -Wno-deprecated compiler option"
man gcc | col -b | grep Wno.deprecated 1>/dev/null
if test $? -eq 0; then
dnl AC_DEFINE(HAVE_GCC_W_NO_DEPRECATED)
GCC_W_NO_DEPRECATED="-Wno-deprecated"
fi
   CFLAGS="-W -Wall -Wno-unused $CFLAGS"
else
   CFLAGS="$CFLAGS"
fi  

case "$GMAKE" in
	"")
		GMAKE=gmake
		;;
esac

MAKE=make
make -f /dev/null --version | grep -i 'GNU make' 1>/dev/null 2>&1
case $? in
	0)
		MAKE=make
		;;
	*)
		$GMAKE -f /dev/null --version | grep -i 'GNU make' 1>/dev/null 2>&1
		case $? in
		0)
			MAKE="$GMAKE"
			;;
		*)
			echo "GNU make required and not found" 1>&2
			exit 1
			;;
		esac
		;;
esac

dnl AC_CHECK_LIB(dl, dlopen)
dnl AC_CHECK_LIB(bz2, main)
dnl AC_CHECK_LIB(popt, poptParseArgvString)
dnl AC_CHECK_LIB(rpmio, fdOpen)
dnl AC_CHECK_LIB(db, main)
dnl AC_CHECK_LIB(db1, main)
dnl AC_CHECK_LIB(z, main)

dnl AC_CHECK_SIZEOF(int)
dnl AC_CHECK_SIZEOF(unsigned short)
dnl AC_CHECK_SIZEOF(unsigned int)
dnl AC_CHECK_SIZEOF(unsigned long)


LIBPATHLIST="/lib /usr/lib /usr/local/lib /opt/lib"
LIBS=""

for xLIBPATH in $LIBPATHLIST; do
if test -f $xLIBPATH/libutil.so -o -h $xLIBPATH/libutil.so; then
LIBS="$LIBS -lutil"
break;
fi
done

for xLIBPATH in $LIBPATHLIST; do
if test -f $xLIBPATH/librt.so -o -h $xLIBPATH/librt.so; then
LIBS="$LIBS -lrt"
break;
fi
done

for xLIBPATH in $LIBPATHLIST; do
if test -f $xLIBPATH/libnsl.so -o -h $xLIBPATH/libnsl.so; then
RPMLIBS="$RPMLIBS -lnsl"
break;
fi
done

for xLIBPATH in $LIBPATHLIST; do
if test -f $xLIBPATH/libsocket.so -o -h $xLIBPATH/libsocket.so; then
RPMLIBS="$RPMLIBS -lsocket"
break;
fi
done


RPMLIBS=""

if test "$compile_test_pgms" != "yes"; then 
DEVELTESTPROGS_="DEVELTESTPROGS="
AC_SUBST(DEVELTESTPROGS_)
fi

jm_MACROS

case "$usewithselfrpm" in
	"yes")
		DO_UM_RPM=um_rpm
		;;
	*)
		DO_UM_RPM=""
		;;
esac


case "$usewithoutrpm" in
	"yes")
		DO_UM_RPM=""
		usewithrpm=no
		usewithselfrpm=no
		;;
esac


AC_CHECK_FUNCS(tcsetattr stty setsid geteuid seteuid  \
  snprintf vprintf vsnprintf vsyslog getopt_long openpty)

AC_SUBST(DO_UM_RPM)
AC_SUBST(INCPATH)
AC_SUBST(LIBMISC)
AC_SUBST(LIBINTL)
AC_SUBST(varprefix)
AC_SUBST(tmpdir)
AC_SUBST(topincdir)
AC_SUBST(topdir)
AC_SUBST(DO_DEBUG)
AC_SUBST(INTLDEF)
AC_SUBST(XGETTEXT)
AC_SUBST(LIBINTL)
AC_SUBST(RPMLIBS)
AC_SUBST(LIBS)
AC_SUBST(PO)
AC_SUBST(GETTEXTSTUB)
AC_SUBST(FIXPERMS)
AC_SUBST(GCC_W_NO_DEPRECATED)
AC_SUBST(POSIXSHELL)
AC_SUBST(GTAR)
AC_SUBST(CPP)
AC_SUBST(CPPFLAGS)
AC_SUBST(MAKE)
AC_SUBST(CXX)
AC_SUBST(CC)

AC_CONFIG_SUBDIRS(swsupplib swstructlib)

SWBISDEFS="-DSWBISLIBEXECDIR=\\\"${libexecdir}\\\" -DSWBISLIBDIR=\\\"${libdir}\\\""
AC_SUBST(SWBISDEFS)

AC_OUTPUT(Makefile Makefile.inc doc/Makefile swprogs/Makefile tests/devel/Makefile tests/devel/Makefile.inc) 

# Print summary of options

# Someone please show me a better way :)
A=`eval echo ${prefix}` ; A=`eval echo ${A}`
B=`eval echo ${bindir}` ; B=`eval echo ${B}`
C=`eval echo ${sbindir}` ; C=`eval echo ${C}`
D=`eval echo ${sysconfdir}` ; D=`eval echo ${D}`
E=`eval echo ${libexecdir}` ; E=`eval echo ${E}`
F=`eval echo ${mandir}` ; F=`eval echo ${F}`
G=`eval echo ${piddir}` ; G=`eval echo ${G}`
H=`eval echo ${PRIVSEP_PATH}` ; H=`eval echo ${H}`
I=`eval echo ${user_path}` ; I=`eval echo ${I}`
J=`eval echo ${superuser_path}` ; J=`eval echo ${J}`
K=`eval echo ${datadir}` ; K=`eval echo ${K}`
L=`eval echo ${prefix}/lib` ; L=`eval echo ${L}`
N=`eval echo ${infodir}`; N=`eval echo ${N}`

echo ""
echo "swbis has been configured with the following options:"
echo "                     User binaries: $B"
echo "                  Library binaries: $E/swbis"
echo "                 Library data file: $L/swbis"
echo "                      Manual pages: $F"
echo "                    Info Documents: $N"
echo "                Misc Documentation: $K/swbis"
echo "         sw<utility> defaults file: $L/swbis/swdefaults"
echo "   sw<utility> swbis defaults file: $L/swbis/swbisdefaults"
echo ""
echo "             Host : ${host}"
echo "            shell : ${SHELL}"
echo "     Make program : ${MAKE}"
echo "      C++ Compiler: ${CXX}"
echo "          Compiler: ${CC}"
echo "     Preprocessor : ${CPP}"
echo "    Compiler flags: ${CFLAGS}"
echo "Preprocessor flags: ${CPPFLAGS}"
echo "      Linker flags: ${LDFLAGS}"
echo "         Libraries: ${LIBWRAP} ${LIBPAM} ${LIBS}"
echo "        as found in ${LIBPATHLIST}"

echo ""

if test "$usewithrpm" = "yes" -o "$usewithselfrpm" = "yes"; then 
echo "RPM translation support is enabled."
fi

if test "$usewithselfrpm" = "yes"; then 
echo "You are using the self contained rpmlib and header files."
fi

if test "$usewithrpm" = "yes"; then 
echo "You are using the system rpmlib and header files."
fi

if test "$usewithrpm" = "yes" -o "$usewithselfrpm" = "yes"; then 
echo "You are compiling rpm dependent utilities."
echo "The configured RPM version is" `grep RPM_VERSION  swsupplib/config.h | grep define`
else 
echo "You are NOT compiling rpm dependent utilities and tests."
fi
if test "$compile_test_pgms" = "yes"; then 
echo "You are compiling the test programs."
else 
echo "You are NOT compiling the test programs."
fi
echo "The configured version string is "$PACKAGE_VERSION

echo "To make: run make or gmake."
echo ""


