dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.2)
AC_INIT(rpmfind.c)
AC_REVISION

dnl
dnl Checks for platform information
dnl

AC_CANONICAL_SYSTEM
AC_CONFIG_HEADER(config.h)

dnl
dnl Initializing Automake
dnl

AC_PROG_MAKE_SET
AC_ARG_PROGRAM

dnl Checks for programs.
AC_PROG_CC
AC_PROG_LN_S
AC_PROG_INSTALL
AC_PATH_PROG(RM, rm, /bin/rm)
AC_PATH_PROG(MV, mv, /bin/mv)
AC_PATH_PROG(TAR, tar, /bin/tar)
AC_PATH_PROG(GZIP, gzip, /bin/gzip)

dnl
dnl Checking for libxml
dnl
AC_CHECK_PROG(XML_CONFIG, xml-config, xml-config)
if test "$XML_CONFIG" != ""
then
    XML_LIBS="`xml-config --libs`"
    XML_CFLAGS="`xml-config --cflags`"
fi
AC_SUBST(XML_LIBS)
AC_SUBST(XML_CFLAGS)


dnl Checks for libraries.
dnl Replace `main' with a function in -lrpm:
for z in z gz ; do
   AC_CHECK_LIB(${z}, deflate,
     [LIBS="-l${z} $LIBS"; break])
done

AC_CHECK_LIB(bz2, bzread,
  [LIBS="$LIBS -lbz2"; break],
   AC_CHECK_LIB(bz2, BZ2_bzread, [
     LIBS="$LIBS -lbz2"
     AC_DEFINE(HAVE_BZ2_1_0) ],
     AC_MSG_WARN([rpm needs libbz2.a (from the bzip2 package)])))

AC_CHECK_LIB(intl, gettext)

AC_CHECK_FUNC(dbopen, [], [
  AC_CHECK_LIB(db-3.1, db_create, [LIBS="-ldb-3.1 $LIBS"],
    AC_CHECK_LIB(db-3.0, db_create, [LIBS="-ldb-3.0 $LIBS"],
      AC_CHECK_LIB(db1, dbopen, [LIBS="-ldb1 $LIBS"],
        AC_CHECK_LIB(db, dbopen, [LIBS="-ldb $LIBS"],
           AC_MSG_ERROR([*** db lib not found])))))
])

AC_CHECK_LIB(popt, poptParseArgvString,,AC_MSG_ERROR(*** popt lib not found))

AC_CHECK_LIB(rpmio, Fopen,
  [LIBS="-lrpmio $LIBS";
	AC_DEFINE_UNQUOTED(USE_RPMIO, 1)
	AC_SUBST(USE_RPMIO)
  ])

AC_CHECK_LIB(rpm, rpmReadConfigFiles,
  [LIBS="-lrpm $LIBS"],
  AC_MSG_ERROR(*** librpm not found))

for z in z gz ; do
   AC_CHECK_LIB(${z}, deflate,
     [LIBS="-l${z} $LIBS"; break])
done


dnl
dnl Checking for libWWW
dnl
dnl AC_CHECK_PROG(WWW_CONFIG, libwww-config, libwww-config)
dnl if test "$WWW_CONFIG" != ""
dnl then
dnl     WWW_LIBS="`libwww-config --libs`"
dnl     WWW_CFLAGS="`libwww-config --cflags`"
dnl fi
AC_SUBST(WWW_LIBS)
AC_SUBST(WWW_CFLAGS)

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h unistd.h)

dnl Checks for header files:
AC_CHECK_HEADERS(appkit/appkit.h appkit.h)
AC_CHECK_HEADERS(arpa/inet.h inet.h)
AC_CHECK_HEADERS(net/errno.h sys/errno.h errno.h)
AC_CHECK_HEADERS(netinet/in.h in.h)
AC_CHECK_HEADERS(netinet/tcp.h tcp.h)
AC_CHECK_HEADERS(sys/fcntl.h fcntl.h)
AC_CHECK_HEADERS(sys/file.h)
AC_CHECK_HEADERS(sys/ioctl.h)
AC_CHECK_HEADERS(sys/ipc.h)
AC_CHECK_HEADERS(sys/limits.h limits.h)
AC_CHECK_HEADERS(sys/machine.h)
AC_CHECK_HEADERS(sys/resource.h resource.h)
AC_CHECK_HEADERS(sys/select.h select.h)
AC_CHECK_HEADERS(sys/socket.h socket.h)
AC_CHECK_HEADERS(sys/stat.h stat.h)
AC_CHECK_HEADERS(sys/systeminfo.h)
AC_CHECK_HEADERS(sys/time.h time.h)
AC_CHECK_HEADERS(sys/types.h types.h)
AC_CHECK_HEADERS(sys/unistd.h unistd.h)
AC_CHECK_HEADERS(sys/utsname.h utsname.h)
AC_CHECK_HEADERS(wais/wais.h wais.h)
AC_CHECK_HEADERS(bsdtime.h)
AC_CHECK_HEADERS(bsdtypes.h)
AC_CHECK_HEADERS(ctype.h)
AC_CHECK_HEADERS(cursesX.h curses.h)
AC_CHECK_HEADERS(db_185.h db1/db.h)
AC_CHECK_HEADERS(dn.h)
AC_CHECK_HEADERS(dnetdb.h)
AC_CHECK_HEADERS(grp.h)
AC_CHECK_HEADERS(libc.h)
AC_CHECK_HEADERS(malloc.h)
AC_CHECK_HEADERS(manifest.h)
AC_CHECK_HEADERS(memory.h)
AC_CHECK_HEADERS(netdb.h)
AC_CHECK_HEADERS(pwd.h)
AC_CHECK_HEADERS(rpm/rpmio.h)
AC_CHECK_HEADERS(rxposix.h regex.h)
AC_CHECK_HEADERS(signal.h)
AC_CHECK_HEADERS(stdefs.h)
AC_CHECK_HEADERS(stdio.h)
AC_CHECK_HEADERS(stdlib.h)
AC_CHECK_HEADERS(string.h strings.h)
AC_CHECK_HEADERS(syslog.h)
AC_CHECK_HEADERS(termios.h)
AC_CHECK_HEADERS(unixlib.h)
AC_CHECK_HEADERS(zlib.h)

AC_CHECK_HEADERS(dlfcn.h dl.h)

AC_HEADER_DIRENT
AC_CHECK_HEADERS(dir.h direct.h) dnl AC_HEADER_DIRENT only checks for some..
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
AC_HEADER_STAT

dnl Checks for typedefs, structures, and compiler characteristics:
AC_TYPE_UID_T
AC_TYPE_PID_T
AC_TYPE_GETGROUPS
AC_TYPE_MODE_T
AC_TYPE_SIZE_T
AC_TYPE_SIGNAL

dnl AC_CHECK_TYPE(BOOLEAN, char)
dnl AC_CHECK_TYPE(u_char, unsigned char)
dnl AC_CHECK_TYPE(u_short, unsigned short)
dnl AC_CHECK_TYPE(u_long, unsigned long)

AC_CHECK_SIZEOF(char, 1)
AC_CHECK_SIZEOF(char *, 4)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(long, 4)

dnl Checks for library functions:
AC_FUNC_VPRINTF
AC_FUNC_STRFTIME
AC_CHECK_FUNCS(getcwd gethostname getdomainname getwd  \
		select socket strerror strtol opendir getpid strchr memcpy \
		getlogin getpass fcntl readdir sysinfo ioctl chdir tempnam \
		getsockopt setsockopt strstr \
		gettimeofday mktime timegm unsetenv)
AC_CHECK_FUNC(unlink)
AC_CHECK_FUNC(uname)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_STRUCT_TM

dnl Checks for library functions.
AC_FUNC_STRFTIME
AC_CHECK_FUNCS(gethostname strdup strndup strerror snprintf)

AC_OUTPUT(Makefile)
