lal#
dnl#
dnl# Process this file with autoconf to produce a configure script.
dnl#
AC_INIT(src/version.h)
BUILD_DIR=`pwd`
cd ..
TOP_DIR=`pwd`
cd ${BUILD_DIR}
AC_SUBST(BUILD_DIR)
AC_CONFIG_AUX_DIR(${BUILD_DIR}/autoconf)
AC_CONFIG_HEADER(src/config.h:autoconf/config.h.in)

dnl require a recent autoconf
AC_PREREQ(2.13)


dnl search for true and false programs.
AC_PATH_PROGS(TRUEPRG, true, :)
AC_PATH_PROGS(FALSEPRG, false, :)

#AC_CANONICAL_HOST

dnl bacula version
VERSION=`sed -n -e 's/^.*VERSION.*"\(.*\)"$/\1/p' ${srcdir}/src/version.h`
DATE=`sed -n -e 's/^.*[ \t]*BDATE.*"\(.*\)"$/\1/p' ${srcdir}/src/version.h`
LSMDATE=`sed -n -e 's/^.*LSMDATE.*"\(.*\)"$/\1/p' ${srcdir}/src/version.h`
AC_SUBST(VERSION)dnl 
AC_SUBST(DATE)dnl 
AC_SUBST(LSMDATE)dnl 
echo "configuring for bacula $VERSION ($DATE)"


dnl -------------------------------------------------------
dnl# Check for compiler.
dnl ------------------------------------------------------

AC_PROG_CC
AC_PROG_CXX
AC_PROG_CC_C_O			dnl Determine if C compiler support -c -o.
AC_PROG_GCC_TRADITIONAL 	dnl Determine if ioctl() need -traditional.

if test x$CC = xgcc
then
   AC_DEFINE(HAVE_GCC)
fi

dnl -------------------------------------------------------
dnl# Check for programs.
dnl ------------------------------------------------------
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PATH_PROG(MV, mv, mv)
AC_PATH_PROG(RM, rm, rm)
AC_PATH_PROG(CP, cp, cp)
AC_PATH_PROG(SED, sed, sed)
AC_PATH_PROG(AWK, awk, awk)
AC_PATH_PROG(ECHO, echo, echo)
AC_PATH_PROG(CMP, cmp, cmp)
AC_PATH_PROG(TBL, tbl, tbl)
AC_PATH_PROG(AR, ar, ar)
dnl AC_PATH_PROG(RANLIB, ranlib, ranlib)
AC_PATH_PROG(OPENSSL, openssl, none)
AC_PATH_PROG(MTX, mtx, mtx)
AC_PATH_PROG(PKGCONFIG, pkg-config, pkg-config)
AC_PATH_PROG(WXCONFIG, wx-config, wx-config)

test -n "$ARFLAG" || ARFLAGS="cr"
AC_SUBST(ARFLAGS)

MAKE_SHELL=/bin/sh
AC_SUBST(MAKE_SHELL)

AC_SUBST(LOCAL_LIBS)
AC_SUBST(LOCAL_CFLAGS)
AC_SUBST(LOCAL_LDFLAGS)
AC_SUBST(LOCAL_DEFS)



dnl --------------------------------------------------
dnl Bacula OP Sys determination (see aclocal.m4)
dnl --------------------------------------------------
BA_CHECK_OPSYS

# -----------------------------------------------------------
dnl Bacula OPSys Distribution determination (see aclocal.m4)
# ----------------------------------------------------------
BA_CHECK_OPSYS_DISTNAME

# -----------------------------------------------------------
dnl Check for gnome stuff for gnome-console
# ----------------------------------------------------------
AM_ACLOCAL_INCLUDE(gnome-macros)

# ------------------------------------------------------------------
#  If the user has not set --prefix, we set our default to nothing.
#  In this case, if the user has not set --sysconfdir, we set it
#  to the package default of /etc/bacula.  If either --prefix or
#  --sysconfdir is set, we leave sysconfdir alone except to eval it.
# ------------------------------------------------------------------
if test x${prefix} = xNONE ; then
    if test `eval echo ${sysconfdir}` = NONE/etc ; then
	sysconfdir=/etc/bacula
    fi
    prefix=
fi
sysconfdir=`eval echo ${sysconfdir}`

# -------------------------------------------------------------------------
#  If the user has not set --exec-prefix, we default to ${prefix}
# -------------------------------------------------------------------------
if test x${exec_prefix} = xNONE ; then
    exec_prefix=${prefix}
fi

# ------------------------------------------------------------------
# If the user has not set --sbindir, we set our default as /sbin
# ------------------------------------------------------------------
if test x$sbindir = x'${exec_prefix}/sbin' ; then
    sbindir=${exec_prefix}/sbin
fi
sbindir=`eval echo ${sbindir}`
		      
# ------------------------------------------------------------------
# All list of languages for which a translation exist. Each
#  language is separated by a space.
# ------------------------------------------------------------------
ALL_LINGUAS=""

AC_PATH_PROGS(MSGFMT, msgfmt, no)
if test "$MSGFMT" = "no"
then
   echo 'msgfmt program not found, disabling NLS !'
   USE_NLS=no
   USE_INCLUDED_LIBINTL=no
#else
#   AM_GNU_GETTEXT
fi


support_mysql=no
support_sqlite=no
support_postgresql=no
support_smartalloc=yes
support_readline=yes
support_conio=yes
support_gnome=no
support_wx_console=no
gnome_version=
support_static_tools=no
support_static_fd=no
support_static_sd=no
support_static_dir=no
support_static_cons=no
build_client_only=no
cats=
db_name=Internal
DB_NAME=bdb

dnl# --------------------------------------------------------------------------
dnl# CHECKING COMMAND LINE OPTIONS
dnl# --------------------------------------------------------------------------

# -------------------------------------------
# gnome (default off)
# -------------------------------------------
AC_ARG_ENABLE(gnome,
  [  --enable-gnome	  enable build of gnome-console GUI [disabled]],
  [if test x$enableval = xyes; then
    support_gnome=yes
  fi])

GNOME_DIR=
if test x$support_gnome = xyes; then
  abc=`$PKGCONFIG --exists libgnomeui-2.0`
  pkg=$?
  if test $pkg = 0; then
     GNOME_INCLUDEDIR=`$PKGCONFIG --cflags-only-I libgnomeui-2.0`
     GNOMEUI_LIBS=`$PKGCONFIG --libs-only-l libgnomeui-2.0`
     GNOME_LIBDIR=`$PKGCONFIG --libs libgnomeui-2.0`
     GNOME_LIBS=`$PKGCONFIG --libs-only-l libgnomeui-2.0`
     AC_SUBST(GNOME_INCLUDEDIR)
     AC_SUBST(GNOMEUI_LIBS)
     AC_SUBST(GNOME_LIBDIR)
     AC_SUBST(GNOME_LIBS)
     GNOME_DIR=src/gnome2-console
     gnome_version="Version 2.x"
  else
dnl do 1.4 stuff
     GNOME_INIT
     GNOME_DIR=src/gnome-console
     gnome_version="Version 1.4"
  fi
fi
AC_SUBST(GNOME_DIR)


# -------------------------------------------
# wx-console (default off)
# -------------------------------------------
AC_ARG_ENABLE(wx-console,
  [  --enable-wx-console      enable build of wxWidgets console [disabled]],
  [if test x$enableval = xyes; then
    support_wx_console=yes
  fi])

WX_DIR=
if test x$support_wx_console = xyes; then
  abc=`$WXCONFIG --cppflags`
  pkg=$?
  if test $pkg = 0; then
     WXCONS_CPPFLAGS=`$WXCONFIG --cppflags`
     WXCONS_LDFLAGS=`$WXCONFIG --libs`
     AC_SUBST(WXCONS_CPPFLAGS)
     AC_SUBST(WXCONS_LDFLAGS)
     WX_DIR=src/wx-console
  else
     echo " "
     echo "wx-config program not found. wx-console disabled."
     echo " "
     support_wx_console=no
  fi
fi
AC_SUBST(WX_DIR)



# -------------------------------------------
# smartalloc (default off)
# -------------------------------------------
AC_ARG_ENABLE(smartalloc,
  [  --enable-smartalloc     enable smartalloc debugging support [disabled]],
  [if test x$enableval = xno; then
    support_smartalloc=no
  fi])

if test x$support_smartalloc = xyes; then
   AC_DEFINE(SMARTALLOC)
fi

# -------------------------------------------
# static-tools (default off)
# -------------------------------------------
AC_ARG_ENABLE(static-tools,
   [  --enable-static-tools   enable static tape tools [disabled]],
   [if test x$enableval = xyes; then
     support_static_tools=yes
   fi])

TTOOL_LDFLAGS=
if test x$support_static_tools = xyes; then
   TTOOL_LDFLAGS="-static"
fi
AC_SUBST(TTOOL_LDFLAGS)

# -------------------------------------------
# static-fd    (default off)
# -------------------------------------------
AC_ARG_ENABLE(static-fd,
   [  --enable-static-fd      enable static File daemon [disabled]],
   [if test x$enableval = xyes; then
     support_static_fd=yes
   fi])

STATIC_FD=
if test x$support_static_fd = xyes; then
   STATIC_FD="static-bacula-fd"
fi
AC_SUBST(STATIC_FD)

# -------------------------------------------
# static-sd    (default off)
# -------------------------------------------
AC_ARG_ENABLE(static-sd,
   [  --enable-static-sd      enable static Storage daemon [disabled]],
   [if test x$enableval = xyes; then
     support_static_sd=yes
   fi])

STATIC_SD=
if test x$support_static_sd = xyes; then
   STATIC_SD="static-bacula-sd"
fi
AC_SUBST(STATIC_SD)

# -------------------------------------------
# static-dir   (default off)
# -------------------------------------------
AC_ARG_ENABLE(static-dir,
   [  --enable-static-dir     enable static Director [disabled]],
   [if test x$enableval = xyes; then
     support_static_dir=yes
   fi])

STATIC_DIR=
if test x$support_static_dir = xyes; then
   STATIC_DIR="static-bacula-dir"
fi
AC_SUBST(STATIC_DIR)

# -------------------------------------------
# static-cons  (default off)
# -------------------------------------------
AC_ARG_ENABLE(static-cons,
   [  --enable-static-cons    enable static Console [disabled]],
   [if test x$enableval = xyes; then
     support_static_cons=yes
   fi])

STATIC_CONS=
STATIC_GNOME_CONS=
STATIC_WX_CONS=
if test x$support_static_cons = xyes; then
   STATIC_CONS="static-bconsole"
   STATIC_GNOME_CONS="static-gnome-console"
   STATIC_WX_CONS="static-wx-console"
fi
AC_SUBST(STATIC_CONS)
AC_SUBST(STATIC_GNOME_CONS)
AC_SUBST(STATIC_WX_CONS)

# -------------------------------------------
# client_only  (default off)
# -------------------------------------------
AC_ARG_ENABLE(client-only,
   [  --enable-client-only    build client (File daemon) only [disabled]],
   [if test x$enableval = xyes; then
     build_client_only=yes
    db_name=None
    DB_NAME=none
   fi])
if test x$build_client_only = xno; then
   ALL_DIRS="subdirs"
else
   ALL_DIRS=""
fi
AC_SUBST(ALL_DIRS)

# ---------------------------------------------------
# Check for conio (Bacula readline substitute)(
# ---------------------------------------------------
# this allows you to turn it completely off
AC_ARG_ENABLE(conio,   
  [  --disable-conio	     disable conio support [enabled]
						      ],
  [if test x$enableval = xno; then
    support_conio=no
  fi])

got_conio="no"
if test x$support_conio = xyes; then
   AC_CHECK_HEADER(termcap.h, 
     [ AC_CHECK_LIB(termcap, tgetent, 
       [ CONS_LIBS="-ltermcap"
	 CONS_OBJ="conio.o"
	 CONS_SRC="conio.c"
	 got_conio="yes"
	 support_readline=no
	 AC_DEFINE(HAVE_CONIO, 1, [Set if Bacula conio support enabled]) 
       ],   
       [ AC_CHECK_LIB(ncurses, tgetent,
	 [ CONS_LIBS="-lncurses"
	   CONS_OBJ="conio.o"
	   CONS_SRC="conio.c"
	   got_conio="yes"
	   support_readline=no
	   AC_DEFINE(HAVE_CONIO, 1, [Set if Bacula conio support enabled]) 
	 ],   
	 [ echo " "; echo "Neither termcap nor ncurses library found. CONIO turned off ..."; echo " "])
       ])
    ],[echo " "; echo "termcap.h not found. CONIO turned off ..."; echo " "])
fi


# ---------------------------------------------------
# Check for readline support/directory (default off)
# ---------------------------------------------------
# this allows you to turn it completely off
AC_ARG_ENABLE(readline,
  [  --disable-readline      disable readline support [disable]
						      ],
  [if test x$enableval = xno; then
    support_readline=no
  fi])

got_readline="no"
READLINE_SRC=
if test x$support_readline = xyes; then
   AC_ARG_WITH(readline,
     [ --with-readline=DIR		 specify readline library directory],
     [
	case "$with_readline" in
	no) : ;;
	yes|*)
	  if test "$with_readline" != "yes"; then
	    CONS_INC="-I${with_readline}"
	    CONS_LDFLAGS="-L$with_readline"
	  else
	     with_readline="/usr/include/readline" 
	  fi
	  AC_CHECK_HEADER(${with_readline}/readline.h, 
	     [ AC_DEFINE(HAVE_READLINE) 
	       CONS_LIBS="-lreadline -ltermcap"
	       got_readline="yes"   
	     ],
	     [ echo " "
	       echo "readline.h not found. readline turned off ..."
	       echo " "
	     ]
	  )
	  ;;
	esac
     ],[
       # check for standard readline library
       AC_CHECK_HEADER(/usr/include/readline/readline.h, 
	 [ AC_DEFINE(HAVE_READLINE)
	   got_readline="yes"
	   CONS_INC="-I/usr/include/readline"
	   CONS_LIBS="-lreadline -ltermcap"
	 ], [
	   # Did not find standard library, so try Bacula's default
	    AC_CHECK_HEADER(${TOP_DIR}/depkgs/readline/readline.h, 
	      [ AC_DEFINE(HAVE_READLINE) 
		 got_readline="yes"   
		 CONS_INC="-I${TOP_DIR}/depkgs/readline"
		 CONS_LIBS="-lreadline -lhistory -ltermcap"
		 CONS_LDFLAGS="-L${TOP_DIR}/depkgs/readline"
		 PRTREADLINE_SRC="${TOP_DIR}/depkgs/readline"
	      ],
	      [ echo " "
		echo "readline.h not found. readline turned off ..."
		echo " "
	      ]
	    )
	 ]
       )
     ]	 
   )
fi



AC_SUBST(CONS_INC)
AC_SUBST(CONS_OBJ)
AC_SUBST(CONS_SRC)
AC_SUBST(CONS_LIBS)
AC_SUBST(CONS_LDFLAGS)
AC_SUBST(READLINE_SRC)

# Minimal stuff for readline Makefile configuration
MAKE_SHELL=/bin/sh
AC_SUBST(MAKE_SHELL)

AC_HEADER_STAT
AC_HEADER_DIRENT

AC_CHECK_FUNCS(strcasecmp select setenv putenv tcgetattr setlocale lstat lchown)
AC_CHECK_FUNCS(nanosleep nl_langinfo)

AC_CHECK_HEADERS(varargs.h)

# End of readline/conio stuff
# -----------------------------------------------------------------------


# ---------------------------------------------------
# Check for GMP support/directory
# ---------------------------------------------------
#GMP_SRC=
#local_gmp="no"
#AC_ARG_WITH(gmp,
#  [  --with-gmp[=DIR]	 Specify gmp library directory],
#  [
#     case "$with_gmp" in
#     no) : ;;
#     yes|*)
#	if test "$with_gmp" != "yes"; then
#	  GMP_INC="-I$with_gmp"
#	  GMP_LIBS="-lgmp"
#	  GMP_LDFLAGS="-L$with_gmp"
#	else
#	   with_gmp="/usr/include" 
#	fi
#	AC_CHECK_HEADER($with_gmp/gmp.h, 
#	   [ AC_MSG_RESULT(yes)
#	     AC_DEFINE(HAVE_GMP) 
#	     GMP_LIBS="-lgmp"
#	     got_gmp="yes"   
#	   ],
#	   [ AC_MSG_ERROR([*** gmp library missing]) 
#	   ]
#	)
#	;;
#     esac
#  ],[
#    # check for standard gmp library
#    AC_CHECK_HEADER(/usr/include/gmp.h,
#    [ AC_MSG_RESULT(yes)
#      AC_DEFINE(HAVE_GMP)
#      got_gmp="yes"
#      GMP_INC=
#      GMP_LIBS="-lgmp"
#    ], [
#      # Did not find standard library, so use our own
#      AC_MSG_RESULT(yes)
#      AC_DEFINE(HAVE_GMP)
#      got_gmp="yes"
#      local_gmp="yes"
#      GMP_INC="-I${TOP_DIR}/depkgs/gmp"
#      GMP_LIBS="-lgmp"
#      GMP_LDFLAGS="-L${TOP_DIR}/depkgs/gmp"
#      GMP_SRC="${TOP_DIR}/depkgs/gmp"
#    ])
#  ]   
#)
#AC_SUBST(GMP_INC)
#AC_SUBST(GMP_LIBS)
#AC_SUBST(GMP_LDFLAGS)
#AC_SUBST(GMP_SRC)

# End of GMP stuff
# -----------------------------------------------------------------------


# ---------------------------------------------------
# Check for CWEB support/directory
# ---------------------------------------------------
#CWEB_SRC=
#CWEB=/bin
#local_cweb="no"
#AC_ARG_WITH(cweb,
#  [  --with-cweb[=DIR]   Specify cweb library directory],
#  [
#     case "$with_cweb" in
#     no) : ;;
#     yes|*)
#	if test "$with_cweb" != "yes"; then
#	  CWEB_INC="-I$with_cweb"
#	  CWEB_LIBS="-lcweb"
#	  CWEB_LDFLAGS="-L$with_cweb"
#	else
#	   with_cweb="/usr/include" 
#	fi
#	AC_CHECK_HEADER($with_cweb/cweb.h, 
#	   [ AC_MSG_RESULT(yes)
#	     AC_DEFINE(HAVE_CWEB) 
#	     CWEB_LIBS="-lcweb"
#	     got_cweb="yes"   
#	   ],
#	   [ AC_MSG_ERROR([*** cweb library missing]) 
#	   ]
#	)
#	;;
#     esac
#  ],[
#    # check for standard cweb library
#    AC_CHECK_HEADER(/usr/include/cweb.h,
#    [ AC_MSG_RESULT(yes)
#      AC_DEFINE(HAVE_CWEB)
#      got_cweb="yes"
#      CWEB_INC=
#      CWEB_LIBS="-lcweb"
#    ], [
#      # Did not find starndard library, so use our own
#      AC_MSG_RESULT(yes)
#      AC_DEFINE(HAVE_CWEB)
#      got_cweb="yes"
#      local_cweb="yes"
#      CWEB=${TOP_DIR}/depkgs/cweb
#      CWEB_INC="-I${TOP_DIR}/depkgs/cweb"
#      CWEB_LIBS="-lcweb"
#      CWEB_LDFLAGS="-L${TOP_DIR}/depkgs/cweb"
#      CWEB_SRC="${TOP_DIR}/depkgs/cweb"
#    ])
#  ]   
#)
#AC_SUBST(CWEB)
#AC_SUBST(CWEB_INC)
#AC_SUBST(CWEB_LIBS)
#AC_SUBST(CWEB_LDFLAGS)
#AC_SUBST(CWEB_SRC)

# End of CWEB stuff
# -----------------------------------------------------------------------



# -----------------------------------------------------------
# Check whether user wants TCP wrappers support (default off)
# -----------------------------------------------------------
TCPW_MSG="no" 
AC_ARG_WITH(tcp-wrappers,
  [  --with-tcp-wrappers=DIR	 enable tcpwrappers support],
  [
    if test "x$withval" != "xno" ; then
       saved_LIBS="$LIBS"
       LIBS="$saved_LIBS -lwrap"
       AC_MSG_CHECKING(for libwrap)
       AC_TRY_LINK(
	  [ #include <tcpd.h>
	     int deny_severity = 0;
	     int allow_severity = 0;
	     struct request_info *req; ],
	  [ hosts_access(req); ],
	  [
	    AC_MSG_RESULT(yes)
	    AC_DEFINE(HAVE_LIBWRAP)
	    TCPW_MSG="yes" 
	  ], [
	    LIBS="$saved_LIBS -lwrap -lnsl"
	    AC_TRY_LINK(
	      [ #include <tcpd.h>
		 int deny_severity = 0;
		 int allow_severity = 0;
		 struct request_info *req; ],
	      [ hosts_access(req); ],
	      [
		 AC_MSG_RESULT(yes)
		 AC_DEFINE(HAVE_LIBWRAP)
		 TCPW_MSG="yes" 
	      ],
	      [AC_MSG_ERROR([*** libwrap missing]) ] ]
	    )
       )
    fi
  ]
)

# ------------------------------------------
# Where to place working dir
# ------------------------------------------
working_dir=`eval echo ${prefix}/var/bacula/working`
AC_ARG_WITH(working-dir,
   [  --with-working-dir=PATH	 specify path of Bacula working directory],
   [
       if test "x$withval" != "xno" ; then     
	      working_dir=$withval
       fi
   ]
)

AC_SUBST(working_dir)


# ------------------------------------------
# Where to place scriptdir (script files)
# ------------------------------------------
scriptdir=`eval echo ${sysconfdir}`
AC_ARG_WITH(scriptdir,
   [  --with-scriptdir=PATH    specify path of Bacula scripts directory],
   [
       if test "x$withval" != "xno" ; then     
	      scriptdir=$withval
       fi
   ]
)

AC_SUBST(scriptdir)


# ------------------------------------------
# Where to send dump email
# ------------------------------------------
dump_email=root@localhost
AC_ARG_WITH(dump-email,
   [  --with-dump-email=EMAIL	 dump email address],
   [
       if test "x$withval" != "xno" ; then     
	      dump_email=$withval
       fi
   ]
)

AC_SUBST(dump_email)

# ------------------------------------------
# Where to send job email
# ------------------------------------------
job_email=root@localhost
AC_ARG_WITH(job-email,
   [  --with-job-email=EMAIL	 job output email address],
   [
       if test "x$withval" != "xno" ; then     
	      job_email=$withval
       fi
   ]
)

AC_SUBST(job_email)

# ------------------------------------------
# Where to find smtp host
# ------------------------------------------
smtp_host=localhost
AC_ARG_WITH(smtp_host,
   [  --with-smtp-host=HOST		 SMTP mail host address],
   [
       if test "x$withval" != "xno" ; then     
	      smtp_host=$withval
       fi
   ]
)

AC_SUBST(smtp_host)


# ------------------------------------
# Where to place pid files
# ------------------------------------
piddir=/var/run
AC_ARG_WITH(pid-dir,
    [  --with-pid-dir=PATH		 specify location of Bacula pid files],
    [
	if test "x$withval" != "xno" ; then	
	    piddir=$withval
	fi
    ]
)

AC_DEFINE_UNQUOTED(_PATH_BACULA_PIDDIR, "$piddir")
AC_SUBST(piddir)


# ------------------------------------
# Where to place subsys "lock file"
# ------------------------------------
subsysdir=/var/run/subsys
AC_ARG_WITH(subsys-dir,
    [  --with-subsys-dir=PATH	 specify location of Bacula subsys file],
    [
	if test "x$withval" != "xno" ; then	
	    subsysdir=$withval
	fi
    ]
)

AC_SUBST(subsysdir)



# ------------------------------------
# Where to start assigning ports
# ------------------------------------
baseport=9101
AC_ARG_WITH(baseport,
    [  --with-baseport=PORT		 specify base port address for daemons],
    [
	if test "x$withval" != "xno" ; then	
	     baseport=$withval
	fi
    ]
)

AC_SUBST(baseport)
dir_port=`expr $baseport`
fd_port=`expr $baseport + 1`
sd_port=`expr $fd_port + 1`

AC_SUBST(dir_port)
AC_SUBST(fd_port)
AC_SUBST(sd_port)


# ------------------------------------------
# Generate passwords
# ------------------------------------------
dir_password=
AC_ARG_WITH(dir-password,
   [  --with-dir-password=PASSWORD   specify Director's password],
   [
       if test "x$withval" != "xno" ; then     
	   dir_password=$withval
       fi
   ]
)

if test "x$dir_password" = "x" ; then
   if test "x$OPENSSL" = "xnone" ; then
#     key=`date | uuencode /dev/stdout | tr "\"@\\\`\\ \\=\\,\\(\\)\\#\\.\\!\\-$'" abcdefghijklmnopqrst | awk '{getline} {print} {exit}'`
      key=`autoconf/randpass 33`
   else
      key=`openssl rand -base64 33`
   fi
   dir_password=$key
fi

fd_password=
AC_ARG_WITH(fd-password,
   [  --with-fd-password=PASSWORD    specify Client's password],
   [
       if test "x$withval" != "xno" ; then     
	   fd_password=$withval
       fi
   ]
)

if test "x$fd_password" = "x" ; then
   if test "x$OPENSSL" = "xnone" ; then
#     key=`date | uuencode /dev/stdout | tr "\"@\\\`\\ \\=\\,\\(\\)\\#\\.\\!\\-$'" tsrqponmlkjihgfedcba | awk '{getline} {print} {exit}'`
      key=`autoconf/randpass 37`
   else
      key=`openssl rand -base64 33`
   fi
   fd_password=$key
fi

sd_password=
AC_ARG_WITH(sd-password,
   [  --with-sd-password=PASSWORD    specify Storage daemon's password],
   [
       if test "x$withval" != "xno" ; then     
	   sd_password=$withval
       fi
   ]
)

if test "x$sd_password" = "x" ; then
   if test "x$OPENSSL" = "xnone" ; then
#     key=`date | uuencode /dev/stdout | tr "\"@\\\`\\ \\=\\,\\(\\)\\#\\.\\!\\-$'" 123456789uvwxyzabcdef | awk '{getline} {print} {exit}'`
      key=`autoconf/randpass 41`
   else
      key=`openssl rand -base64 33`
   fi
   sd_password=$key
fi


AC_SUBST(dir_password)
AC_SUBST(fd_password)
AC_SUBST(sd_password)


#
# Handle users and groups for each daemon
#
dir_user=
AC_ARG_WITH(dir_user,
    [  --with-dir-user=USER		 specify user for Director daemon],
    [
	if test "x$withval" != "x" ; then	
	     dir_user=$withval
	fi
    ]
)

dir_group=
AC_ARG_WITH(dir_group,
    [  --with-dir-group=GROUP		 specify group for Director daemon],
    [
	if test "x$withval" != "x" ; then	
	     dir_group=$withval
	fi
    ]
)

sd_user=
AC_ARG_WITH(sd_user,
    [  --with-sd-user=USER		 specify user for Storage daemon],
    [
	if test "x$withval" != "x" ; then	
	     sd_user=$withval
	fi
    ]
)

sd_group=
AC_ARG_WITH(sd_group,
    [  --with-sd-group=GROUP		 specify group for Storage daemon],
    [
	if test "x$withval" != "x" ; then	
	     sd_group=$withval
	fi
    ]
)

fd_user=
AC_ARG_WITH(fd_user,
    [  --with-fd-user=USER		 specify user for File daemon],
    [
	if test "x$withval" != "x" ; then	
	     fd_user=$withval
	fi
    ]
)

fd_group=
AC_ARG_WITH(fd_group,
    [  --with-fd-group=GROUP		 specify group for File daemon],
    [
	if test "x$withval" != "x" ; then	
	     fd_group=$withval
	fi
    ]
)




AC_SUBST(dir_user)
AC_SUBST(dir_group)
AC_SUBST(sd_user)
AC_SUBST(sd_group)
AC_SUBST(fd_user)
AC_SUBST(fd_group)

#
# allow setting default executable permissions
#
SBINPERM=0754
AC_ARG_WITH(sbin-perm,
    [  --with-sbin-perm=MODE		 specify permissions for sbin binaries (0754)],
    [
	if test "x$withval" != "x" ; then	
	    SBINPERM=$withval
	fi
    ]
)

AC_SUBST(SBINPERM)

# ------------------------------------------------
# Bacula check for various SQL database engines
# ------------------------------------------------
BA_CHECK_POSTGRESQL_DB

BA_CHECK_MYSQL_DB

BA_CHECK_SQLITE_DB

AC_SUBST(cats)
AC_SUBST(DB_NAME)

AC_DEFINE(PROTOTYPES)

dnl# --------------------------------------------------------------------------
dnl# Supply default CFLAGS, if not specified by `CFLAGS=flags ./configure'
dnl#
if test -z "$CFLAGS"; then
    if test -z "$CCOPTS"; then
	CCOPTS='-g -O2'
dnl>	if test "x$GCC" = xyes; then
dnl>	    if test x$system = xLinux; then
dnl>		CCOPTS="$CCOPTS "'-O2 -fno-strength-reduce'
dnl>	    fi
dnl>	fi
    fi
    CFLAGS="$CCOPTS"
fi


dnl A few others 
AC_EXEEXT

dnl See if we can use 64 bit file addresses
largefile_support="no"
AC_BAC_LARGEFILE


AC_PATH_XTRA

dnl# --------------------------------------------------------------------------
dnl# CHECKING FOR HEADER FILES
dnl# --------------------------------------------------------------------------
AC_CHECK_HEADERS( \
	assert.h \
	fcntl.h \
	grp.h \
	pwd.h \
	libc.h \
	limits.h \
	stdarg.h \
	stdlib.h \
	stdint.h \
	string.h \
	termios.h \
	unistd.h \
	sys/byteorder.h \
	sys/ioctl.h \
	sys/select.h \
	sys/sockio.h \
	sys/time.h \
	sys/socket.h \
	arpa/nameser.h \
	resolv.h \
	mtio.h \
	sys/mtio.h \
)
AC_HEADER_STDC
AC_HEADER_MAJOR
AC_HEADER_DIRENT
AC_HEADER_STAT
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
AC_STRUCT_ST_BLKSIZE
AC_STRUCT_ST_BLOCKS
AC_STRUCT_TIMEZONE

dnl# --------------------------------------------------------------------------
dnl# Check for utime.h structure 
dnl# --------------------------------------------------------------------------
AC_CACHE_CHECK(for utime.h, ba_cv_header_utime_h,
  [AC_TRY_COMPILE([
#include <sys/types.h>
#include <utime.h>], [struct utimbuf foo],
  ba_cv_header_utime_h=yes, ba_cv_header_utime_h=no)])
test $ba_cv_header_utime_h = yes && AC_DEFINE(HAVE_UTIME_H)

dnl# --------------------------------------------------------------------------
dnl# Check for socklen_t
dnl# --------------------------------------------------------------------------
AC_CACHE_CHECK(for socklen_t, ba_cv_header_socklen_t,
  [AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>],
  [socklen_t x],
  ba_cv_header_socklen_t=yes, ba_cv_header_socklen_t=no)])
test $ba_cv_header_socklen_t = yes && AC_DEFINE(HAVE_SOCKLEN_T)

dnl# --------------------------------------------------------------------------
dnl# Check for bigendian
dnl# --------------------------------------------------------------------------
AC_CACHE_CHECK([for bigendian], ba_cv_bigendian,
  [AC_TRY_RUN(
    [main(){long a=1L; char *p=(char *)&a; exit(*p);}],
    [ba_cv_bigendian=yes], 
    [ba_cv_bigendian=no], 
    [ba_cv_bigendian=no])])
test $ba_cv_bigendian = yes && AC_DEFINE(HAVE_BIGENDIAN)


AC_C_CONST


dnl# --------------------------------------------------------------------------
dnl# CHECKING FOR FILESYSTEM TYPE
dnl# --------------------------------------------------------------------------
AC_MSG_CHECKING(how to get filesystem type)
fstype=no
# The order of these tests is important.
AC_TRY_CPP([#include <sys/statvfs.h>
#include <sys/fstyp.h>], AC_DEFINE(FSTYPE_STATVFS) fstype=SVR4)
if test $fstype = no; then
AC_TRY_CPP([#include <sys/statfs.h>
#include <sys/fstyp.h>], AC_DEFINE(FSTYPE_USG_STATFS) fstype=SVR3)
fi
if test $fstype = no; then
AC_TRY_CPP([#include <sys/statfs.h>
#include <sys/vmount.h>], AC_DEFINE(FSTYPE_AIX_STATFS) fstype=AIX)
fi
if test $fstype = no; then  
AC_TRY_CPP([#include <mntent.h>], AC_DEFINE(FSTYPE_MNTENT) fstype=4.3BSD)
fi
if test $fstype = no; then  
AC_EGREP_HEADER(f_type;, sys/mount.h, AC_DEFINE(FSTYPE_STATFS) fstype=4.4BSD/OSF1)
fi
if test $fstype = no; then  
AC_TRY_CPP([#include <sys/mount.h>
#include <sys/fs_types.h>], AC_DEFINE(FSTYPE_GETMNT) fstype=Ultrix)
fi
AC_MSG_RESULT($fstype)

dnl# --------------------------------------------------------------------------
dnl# CHECKING FOR TYPEDEFS, STRUCTURES, AND COMPILER CHARACTERISTICS.
dnl# --------------------------------------------------------------------------
AC_TYPE_SIGNAL
SIGNAL_CHECK
AC_TYPE_MODE_T
AC_TYPE_UID_T
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_TYPE_OFF_T
AC_CHECK_TYPE(ino_t, unsigned long)
AC_CHECK_TYPE(dev_t, unsigned long)
AC_CHECK_TYPE(daddr_t, long)
AC_CHECK_TYPE(major_t, int)
AC_CHECK_TYPE(minor_t, int)
AC_CHECK_TYPE(ssize_t, int)
AC_STRUCT_ST_BLOCKS
AC_STRUCT_ST_RDEV
AC_STRUCT_TM
AC_C_CONST


AC_CHECK_SIZEOF(char, 1)
AC_CHECK_SIZEOF(short int, 2)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(long int, 4)
AC_CHECK_SIZEOF(long long int, 8)
AC_CHECK_SIZEOF(int *, 4)

# Check for sys/types.h types
AC_CACHE_CHECK([for u_int type], ac_cv_have_u_int, [
    AC_TRY_COMPILE(
	[ #include <sys/types.h> ], 
	[ u_int a; a = 1;], 
	[ ac_cv_have_u_int="yes" ],
	[ ac_cv_have_u_int="no" ]
    )
])
if test "x$ac_cv_have_u_int" = "xyes" ; then
   AC_DEFINE(HAVE_U_INT)
   have_u_int=1
fi

AC_CACHE_CHECK([for intmax_t type], ac_cv_have_intmax_t, [
   AC_TRY_COMPILE(
      [ #include <sys/types.h> ], 
      [ intmax_t a; a = 1;], 
      [ ac_cv_have_intmax_t="yes" ],
      [ 
	 AC_TRY_COMPILE(
	    [ #include <stdint.h> ], 
	    [ intmax_t a; a = 1;], 
	    [ ac_cv_have_intmax_t="yes" ],
	    [ ac_cv_have_intmax_t="no" ]
	 )
      ]
   )	    

])
if test "x$ac_cv_have_intmax_t" = "xyes" ; then
   AC_DEFINE(HAVE_INTMAX_T)
   have_intmax_t=1
fi


AC_CACHE_CHECK([for u_intmax_t type], ac_cv_have_u_intmax_t, [
   AC_TRY_COMPILE(
      [ #include <sys/types.h> ], 
      [ u_intmax_t a; a = 1;], 
      [ ac_cv_have_u_intmax_t="yes" ],
      [ 
	 AC_TRY_COMPILE(
	    [ #include <stdint.h> ], 
	    [ u_intmax_t a; a = 1;], 
	    [ ac_cv_have_u_intmax_t="yes" ],
	    [ ac_cv_have_u_intmax_t="no" ]
	 )
      ]
   )
])
if test "x$ac_cv_have_u_intmax_t" = "xyes" ; then
   AC_DEFINE(HAVE_U_INTMAX_T)
   have_u_intmax_t=1
fi


AC_CACHE_CHECK([for intXX_t types], ac_cv_have_intxx_t, [
   AC_TRY_COMPILE(
      [ #include <sys/types.h> ], 
      [ int8_t a; int16_t b; int32_t c; a = b = c = 1;], 
      [ ac_cv_have_intxx_t="yes" ],
      [ ac_cv_have_intxx_t="no" ]
   )
])
if test "x$ac_cv_have_intxx_t" = "xyes" ; then
   AC_DEFINE(HAVE_INTXX_T)
   have_intxx_t=1
fi
	
AC_CACHE_CHECK([for int64_t type], ac_cv_have_int64_t, [
   AC_TRY_COMPILE(
      [ #include <sys/types.h> ], 
      [ int64_t a; a = 1;], 
      [ ac_cv_have_int64_t="yes" ],
      [ ac_cv_have_int64_t="no" ]
   )
])
if test "x$ac_cv_have_int64_t" = "xyes" ; then
   AC_DEFINE(HAVE_INT64_T)
   have_int64_t=1
fi
	
AC_CACHE_CHECK([for u_intXX_t types], ac_cv_have_u_intxx_t, [
   AC_TRY_COMPILE(
      [ #include <sys/types.h> ], 
      [ u_int8_t a; u_int16_t b; u_int32_t c; a = b = c = 1;], 
      [ ac_cv_have_u_intxx_t="yes" ],
      [ ac_cv_have_u_intxx_t="no" ]
   )
])
if test "x$ac_cv_have_u_intxx_t" = "xyes" ; then
   AC_DEFINE(HAVE_U_INTXX_T)
   have_u_intxx_t=1
fi

AC_CACHE_CHECK([for u_int64_t types], ac_cv_have_u_int64_t, [
   AC_TRY_COMPILE(
      [ #include <sys/types.h> ], 
      [ u_int64_t a; a = 1;], 
      [ ac_cv_have_u_int64_t="yes" ],
      [ ac_cv_have_u_int64_t="no" ]
   )
])
if test "x$ac_cv_have_u_int64_t" = "xyes" ; then
   AC_DEFINE(HAVE_U_INT64_T)
   have_u_int64_t=1
fi

if (test -z "$have_u_intxx_t" || test -z "$have_intxx_t" && \
	   test "x$ac_cv_header_sys_bitypes_h" = "xyes")
then
   AC_MSG_CHECKING([for intXX_t and u_intXX_t types in sys/bitypes.h])
   AC_TRY_COMPILE(
      [ #include <sys/bitypes.h>  ], 
      [ int8_t a; int16_t b; int32_t c;
	u_int8_t e; u_int16_t f; u_int32_t g;
	a = b = c = e = f = g = 1;  ], 
      [ AC_DEFINE(HAVE_U_INTXX_T)
	AC_DEFINE(HAVE_INTXX_T)
	AC_DEFINE(HAVE_SYS_BITYPES_H)
	AC_MSG_RESULT(yes) ],
      [ AC_MSG_RESULT(no)]
   ) 
fi

if test -z "$have_u_intxx_t" ; then
   AC_CACHE_CHECK([for uintXX_t types], ac_cv_have_uintxx_t, [
      AC_TRY_COMPILE(
	 [ #include <sys/types.h> ], 
	 [ uint8_t a; uint16_t b; 
	   uint32_t c; a = b = c = 1; ], 
	 [ ac_cv_have_uintxx_t="yes" ],
	 [ ac_cv_have_uintxx_t="no" ]
      )
   ])
   if test "x$ac_cv_have_uintxx_t" = "xyes" ; then
      AC_DEFINE(HAVE_UINTXX_T)
   fi
fi


dnl# --------------------------------------------------------------------------
dnl# CHECKING FOR LIBRARY FUNCTIONS
dnl# --------------------------------------------------------------------------
AC_CHECK_FUNCS( \
	fork \
	getcwd \
	gethostname \
	getpid \
	gettimeofday \
	setpgid \
	setpgrp \
	setsid \
	signal \
	strerror \
	strncmp \
	strncpy \
	vfprintf \
	,,
	[echo 'configure: cannot find needed function.'; exit 1]
)

AC_CHECK_FUNCS(fchdir, [AC_DEFINE(HAVE_FCHDIR)])
AC_CHECK_FUNCS(strtoll, [AC_DEFINE(HAVE_STRTOLL)])

AC_CHECK_FUNCS(chflags) 

AC_CHECK_FUNCS(snprintf vsnprintf gethostid getdomainname)

dnl# --------------------------------------------------------------------------
dnl# CHECKING FOR THREAD SAFE FUNCTIONS
dnl# --------------------------------------------------------------------------
AC_CHECK_FUNCS(localtime_r readdir_r strerror_r gethostbyname_r)

# If resolver functions are not in libc check for -lnsl or -lresolv.
AC_CHECK_FUNC(gethostbyname_r,
    AC_MSG_RESULT(using libc's resolver),
    AC_CHECK_LIB(nsl,gethostbyname_r)
    AC_CHECK_LIB(resolv,gethostbyname_r))


# Find where sockets are (especially for Solaris)
AC_CHECK_FUNC(socket,
    AC_MSG_RESULT(using libc's socket),
    AC_CHECK_LIB(xnet,socket)
    AC_CHECK_LIB(socket,socket)
    AC_CHECK_LIB(inet,socket))

AC_CHECK_FUNCS(inet_pton, [AC_DEFINE(HAVE_INET_PTON)])

AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_FUNC_ALLOCA
AC_FUNC_GETMNTENT
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_SETPGRP 		      dnl check for BSD setpgrp.
AC_FUNC_FNMATCH


dnl# FreeBSD needs to link libxpg4
AC_CHECK_LIB(xpg4, setlocale, [LIBS="$LIBS -lxpg4"])


AC_CHECK_LIB(sun, getpwnam)

AC_CHECK_HEADERS(zlib.h)
AC_CHECK_LIB(z, deflate, [FDLIBS="-lz"])
have_zlib=no
if test x$FDLIBS = x-lz; then
  AC_DEFINE(HAVE_LIBZ)
  have_zlib=yes
fi

AC_CHECK_HEADER(sys/acl.h)
AC_CHECK_LIB(acl, acl_get_file, [FDLIBS="-lacl $FDLIBS"])
have_acl=no
if test $ac_cv_lib_acl_acl_get_file = yes; then
   AC_DEFINE(HAVE_ACL)
   have_acl=yes
fi

dnl Check for pthread libraries
PTHREAD_LIB=""
AC_CHECK_LIB(pthread, pthread_create, PTHREAD_LIB="-lpthread",
	[AC_CHECK_LIB(pthreads, pthread_create, PTHREAD_LIB="-lpthreads",
	    [AC_CHECK_LIB(c_r, pthread_create, PTHREAD_LIB="-lc_r",
		[AC_CHECK_FUNC(pthread_create)]
	    )]
	)]
)

AC_SUBST(FDLIBS)
AC_DEFINE(FDLIBS)


CFLAGS=${CFLAGS--O}
LDFLAGS=${LDFLAGS--O}
DB_LIBS="${SQL_LFLAGS}"

CPPFLAGS="$CPPFLAGS"
AC_SUBST(DEBUG)
AC_SUBST(DINCLUDE)
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(X_CFLAGS)
AC_SUBST(LIBS)
AC_SUBST(DLIB)
AC_SUBST(DB_LIBS)
AC_SUBST(X_LIBS)
AC_SUBST(X_EXTRA_LIBS)
AC_SUBST(WCFLAGS)
AC_SUBST(WLDFLAGS)

dnl# extra configurable objects
OBJLIST=
AC_SUBST(OBJLIST)

lld="lld"
llu="llu"

WCFLAGS=
WLDFLAGS=

#
# Finally we set appropriate distribution specific
#  variables and defaults
#
# PFILES are platform specific files
PFILES="platforms/Makefile"
PSCMD="ps -e"
WIN32=
MACOSX=
hostname=`uname -n | cut -d '.' -f 1`
case "$DISTNAME" in
aix)
	DISTVER=`uname -r`
	PSCMD="ps -e -o pid,comm"
	PFILES="${PFILES} \
	   platforms/aix/Makefile"
	TAPEDRIVE="/dev/rmt0.1" 
  ;;	  
alpha)
	DISTVER=`uname -r`
	PTHREAD_LIB="-lpthread -lexc"
	if test "${CC}" = "gcc" ; then
	   lld="lld"
	   llu="llu"
	else
	   lld="ld"
	   llu="lu"
	fi
	TAPEDRIVE="/dev/nrmt0"
  ;;
bsdi)
	DISTVER=`uname -a |awk '{print $3}'`
	TAPEDRIVE="/dev/nrmt0"
	PTHREAD_LIB="-pthread"
	CFLAGS="${CFLAGS} -pthread"
	PSCMD="ps -x -o pid,command"
	lld="qd"
	llu="qu"
	PFILES="${PFILES} \
	    platforms/bsdi/Makefile \
	    platforms/bsdi/bacula-fd \
	    platforms/bsdi/bacula-sd \
	    platforms/bsdi/bacula-dir"
	largefile_support="yes"
  ;;
cygwin)
	DISTVER=`uname -a |awk '{print $3}'`
	TAPEDRIVE="/dev/nrst0"
	WIN32=win32
	WCFLAGS="-mwindows"
	WLDFLAGS="-mwindows"
  ;;
darwin)
	DISTVER=`uname -r`
	TAPEDRIVE="/dev/nst0"
	PSCMD="ps -e -o pid,command"
	MACOSX=macosx
	PFILES="${PFILES} \
	   platforms/darwin/Makefile"
  ;;
debian)
	DISTVER=`cat /etc/debian_version`
	TAPEDRIVE="/dev/nrst0"
	PSCMD="ps -e -o pid,command"
  ;;
freebsd)
	DISTVER=`uname -a |awk '{print $3}'`
	VER=`echo $DISTVER | cut -c 1`
	if test x$VER = x4 ; then
	   PTHREAD_LIB="-pthread"
	   CFLAGS="${CFLAGS} -pthread"
	fi
	lld="qd"
	llu="qu"
	TAPEDRIVE="/dev/nrsa0"
	PSCMD="ps -x -o pid,command"
	PFILES="${PFILES} \
	    platforms/freebsd/Makefile \
	    platforms/freebsd/bacula-fd \
	    platforms/freebsd/bacula-sd \
	    platforms/freebsd/bacula-dir"
	largefile_support="yes"
  ;;
hpux)
	PSCMD="UNIX95=1 ps -e -o pid,comm"
	CFLAGS="$(CFLAGS) -D_XOPEN_SOURCE_EXTENDED=1"
	DISTVER=`uname -r`
	TAPEDRIVE="/dev/rmt/0hnb"
  ;;
irix)
	DISTVER=`uname -r`
	TAPEDRIVE="/dev/rmt/0cbn"
	PSCMD="ps -e -o pid,comm"
	PFILES="${PFILES} \
	    platforms/irix/Makefile \
	    platforms/irix/bacula-fd \
	    platforms/irix/bacula-sd \
	    platforms/irix/bacula-dir"
  ;;
netbsd)
	DISTVER=`uname -a |awk '{print $3}'`
	lld="qd"
	llu="qu"
	TAPEDRIVE="/dev/nrst0"
	PSCMD="ps -a -o pid,command"
	PTHREAD_LIB="-pthread"
	CFLAGS="${CFLAGS} -pthread"
  ;;
openbsd)
	DISTVER=`uname -a |awk '{print $3}'`
	lld="qd"
	llu="qu"
	TAPEDRIVE="/dev/nrst0"
	PSCMD="ps -a -o pid,command"
	PTHREAD_LIB="-pthread"
	CFLAGS="${CFLAGS} -pthread"
	PFILES="${PFILES} \
	    platforms/openbsd/Makefile \
	    platforms/openbsd/bacula-fd \
	    platforms/openbsd/bacula-sd \
	    platforms/openbsd/bacula-dir"
  ;;
redhat)
	if test `cat /etc/redhat-release | grep release |\
		   cut -f 3 -d ' '`x = "Enterprise"x ; then
	   DISTVER="Enterprise "`cat /etc/redhat-release | grep release |\
		    cut -f 6 -d ' '`
	else
	    DISTVER=`cat /etc/redhat-release | grep release |\
		     cut -f 5 -d ' '`
	fi
	TAPEDRIVE="/dev/nst0"
	PSCMD="ps -e -o pid,command"
	PFILES="${PFILES} \
	    platforms/redhat/Makefile \
	    platforms/redhat/bacula-fd \
	    platforms/redhat/bacula-sd \
	    platforms/redhat/bacula-dir \
	    platforms/redhat/bacula.spec \
	    "
	hostname=`hostname -s`
  ;;
mandrake)
	DISTVER=`cat /etc/mandrake-release | grep release |\
	   cut -f 5 -d ' '`
	TAPEDRIVE="/dev/nst0"
	PSCMD="ps -e -o pid,command"
	PFILES="${PFILES} \
	    platforms/mandrake/Makefile \
	    platforms/mandrake/bacula-fd \
	    platforms/mandrake/bacula-sd \
	    platforms/mandrake/bacula-dir \
	    platforms/mandrake/bacula.spec \
	    "
  ;;
gentoo)
	DISTVER=`awk '/version / {print $5}' < /etc/gentoo-release`
	TAPEDRIVE="/dev/nst0"
	PSCMD="ps -e -o pid,command"
	PFILES="${PFILES} \
	    platforms/gentoo/Makefile \
	    platforms/gentoo/bacula-fd \
	    platforms/gentoo/bacula-sd \
	    platforms/gentoo/bacula-dir"
  ;;
slackware)
	DISTVER=`cat /etc/slackware-version`
	TAPEDRIVE="/dev/nst0"
	PSCMD="ps -e -o pid,command"
	PFILES="${PFILES} \
	    platforms/slackware/Makefile \
	    platforms/slackware/rc.bacula-fd \
	    platforms/slackware/rc.bacula-sd \
	    platforms/slackware/rc.bacula-dir\
	    platforms/slackware/functions.bacula"
  ;;
solaris)
	DISTVER=`uname -r`
	TAPEDRIVE="/dev/rmt/0cbn"
	PSCMD="ps -e -o pid,comm"
	PFILES="${PFILES} \
	    platforms/solaris/Makefile \
	    platforms/solaris/bacula-fd \
	    platforms/solaris/bacula-sd \
	    platforms/solaris/bacula-dir"
	if test x$DISTVER = x5.6 ; then
	    AC_DEFINE(HAVE_OLD_SOCKOPT)
	fi
  ;;
suse)
	DISTVER=`cat /etc/SuSE-release |grep VERSION|\
	    cut -f 3 -d ' '`
	TAPEDRIVE="/dev/nst0"
	PSCMD="ps -e -o pid,command"
	PFILES="${PFILES} \
	    platforms/suse/Makefile \
	    platforms/suse/bacula-fd \
	    platforms/suse/bacula-sd \
	    platforms/suse/bacula-dir \
	    platforms/suse/bacula \
	    platforms/suse/bacula.spec"
  ;;
suse5)
	DISTNAME=suse
	DISTVER=5.x
	TAPEDRIVE="/dev/nst0"
	PSCMD="ps -e -o pid,command"
	PFILES="${PFILES} \
	    platforms/suse/Makefile \
	    platforms/suse/bacula-fd \
	    platforms/suse/bacula-sd \
	    platforms/suse/bacula-dir"
  ;;
unknown)
	DISTVER=unknown
	TAPEDRIVE="/dev/nst0"
  ;;
*)
  echo " === Something went wrong. Unknown DISTNAME $DISTNAME ==="
  ;;
esac  

AC_SUBST(hostname)

LIBS="$PTHREAD_LIB $LIBS"

AC_DEFINE_UNQUOTED(lld, "$lld")
AC_DEFINE_UNQUOTED(llu, "$llu")
AC_SUBST(TAPEDRIVE)
AC_SUBST(PSCMD)
AC_SUBST(WIN32)
AC_SUBST(MACOSX)
AC_SUBST(DISTNAME)
AC_SUBST(DISTVER)

dnl# common parts of the Makefile
MCOMMON=./autoconf/Make.common
AC_SUBST_FILE(MCOMMON)

dnl# Insanity check
if test "x${subsysdir}" = "x${sbindir}" ; then
   echo " "
   echo " "
   echo "You have set both --sbindir and --with-subsys-dir"
   echo "  equal to: ${subsysdir} "
   echo "This is not permitted. Please reconfigure."
   echo " "
   echo "Aborting configuration ..."
   echo " "
   echo " "
   exit 1
fi 

AC_OUTPUT([autoconf/Make.common \
	   Makefile \
	   rescue/Makefile \
	   rescue/linux/Makefile \
	   rescue/freebsd/Makefile \
	   rescue/solaris/Makefile \
	   scripts/startmysql \
	   scripts/stopmysql \
	   scripts/btraceback \
	   scripts/startit \
	   scripts/stopit \
	   scripts/bconsole \
	   scripts/gconsole \
	   scripts/bacula \
	   scripts/devel_bacula \
	   scripts/fd \
	   scripts/Makefile \
	   scripts/logrotate \
	   scripts/bacula.desktop.gnome1 \
	   scripts/bacula.desktop.gnome2 \
	   scripts/bacula.desktop.gnome1.consolehelper \
	   scripts/bacula.desktop.gnome2.consolehelper \
	   scripts/bacula.desktop.gnome1.xsu \
	   scripts/bacula.desktop.gnome2.xsu \
	   scripts/gnome-console.console_apps \
	   scripts/mtx-changer \
	   doc/Makefile \
	   src/Makefile \
	   src/host.h \
	   src/console/Makefile \
	   src/console/bconsole.conf \
	   src/gnome-console/Makefile \
	   src/gnome-console/gnome-console.conf \
	   src/gnome2-console/Makefile \
	   src/gnome2-console/gnome-console.conf \
	   src/wx-console/Makefile \
	   src/wx-console/wx-console.conf \
	   src/dird/Makefile \
	   src/dird/bacula-dir.conf \
	   src/lib/Makefile \
	   src/stored/Makefile \
	   src/stored/bacula-sd.conf \
	   src/filed/Makefile \
	   src/filed/bacula-fd.conf \
	   src/filed/win32/Makefile \
	   src/cats/Makefile \
	   src/cats/make_catalog_backup \
	   src/cats/delete_catalog_backup \
	   src/cats/create_postgresql_database \
	   src/cats/update_postgresql_tables \
	   src/cats/make_postgresql_tables \
	   src/cats/grant_postgresql_privileges \
	   src/cats/drop_postgresql_tables \
	   src/cats/drop_postgresql_database \
	   src/cats/create_mysql_database \
	   src/cats/update_mysql_tables \
	   src/cats/make_mysql_tables \
	   src/cats/grant_mysql_privileges \
	   src/cats/drop_mysql_tables \
	   src/cats/drop_mysql_database \
	   src/cats/create_sqlite_database \
	   src/cats/update_sqlite_tables \
	   src/cats/make_sqlite_tables \
	   src/cats/grant_sqlite_privileges \
	   src/cats/drop_sqlite_tables \
	   src/cats/drop_sqlite_database \
	   src/cats/sqlite \
	   src/cats/mysql \
	   src/cats/create_bdb_database \
	   src/cats/update_bdb_tables \
	   src/cats/make_bdb_tables \
	   src/cats/grant_bdb_privileges \
	   src/cats/drop_bdb_tables \
	   src/cats/drop_bdb_database \
	   src/cats/create_bacula_database \
	   src/cats/update_bacula_tables \
	   src/cats/grant_bacula_privileges \
	   src/cats/make_bacula_tables \
	   src/cats/drop_bacula_tables \
	   src/cats/drop_bacula_database \
	   src/findlib/Makefile \
	   src/tools/Makefile \
	   src/win32/winbacula.nsi \
	   src/win32/baculafd/bacula-fd.conf \
	   src/win32/Makefile \
	   src/win32/console/bconsole.conf \
	   src/win32/wx-console/wx-console.conf \
	   $PFILES ],  
	  [(echo "Doing make of dependencies"; make depend;) ]
)

cd scripts
chmod 755 startmysql stopmysql bacula startit stopit btraceback mtx-changer
chmod 755 bconsole gconsole mtx-changer devel_bacula logrotate
cd ..

c=src/cats

chmod 755 $c/create_bacula_database   $c/update_bacula_tables  $c/make_bacula_tables
chmod 755 $c/grant_bacula_privileges  $c/drop_bacula_tables    $c/drop_bacula_database

chmod 755 $c/create_bdb_database      $c/update_bdb_tables     $c/make_bdb_tables
chmod 755 $c/grant_bdb_privileges     $c/drop_bdb_tables       $c/drop_bdb_database

chmod 755 $c/create_mysql_database    $c/update_mysql_tables   $c/make_mysql_tables
chmod 755 $c/grant_mysql_privileges   $c/drop_mysql_tables     $c/drop_mysql_database

chmod 755 $c/create_sqlite_database   $c/update_sqlite_tables  $c/make_sqlite_tables
chmod 755 $c/grant_sqlite_privileges  $c/drop_sqlite_tables    $c/drop_sqlite_database

chmod 755 $c/create_postgresql_database  $c/update_postgresql_tables $c/make_postgresql_tables
chmod 755 $c/grant_postgresql_privileges $c/drop_postgresql_tables   $c/drop_postgresql_database

chmod 755 $c/make_catalog_backup $c/delete_catalog_backup
chmod 755 $c/sqlite
chmod 755 $c/mysql

if test "x$ac_cv_sys_largefile_CFLAGS" != "xno" ; then
   largefile_support="yes"
fi

#
# A whole lot of hand springs to get the compiler version.
#  This is because gcc changed the output in version 3.0
#
CCVERSION=`${CC} --version | tr '\n' ' ' | cut -f 3 -d ' '`
if test "x${CCVERSION}" = "x" ; then
  CCVERSION=`${CC} --version | tr '\n' ' ' | cut -f 1 -d ' '`
fi
CXXVERSION=`${CXX} --version | tr '\n' ' ' | cut -f 3 -d ' '`
if test x"${CXXVERSION}" = x ; then
  CXXVERSION=`${CXX} --version | tr '\n' ' ' | cut -f 1 -d ' '`
fi

if test "x${subsysdir}" = "x${sbindir}" ; then
   echo " "
   echo " "
   echo "You have set --sbindir and --with-subsys-dir"
   echo "  both equal to: ${subsysdir} "
   echo "  This is not permitted. Please reconfigure."
   echo " "
   echo "Aborting configuration ..."
   echo " "
   echo " "
   exit 1
fi 

if test "x${db_name}" = "xInternal" ; then
   echo " "
   echo " "
   echo "You have not specified either --enable-client-only or one of the"
   echo "  supported databases: MySQL, PostgreSQL, or SQLite".
   echo "  This is not permitted. Please reconfigure."
   echo " "
   echo "Aborting the configuration ..."
   echo " "
   echo " "
   exit 1
fi

echo "
Configuration on `date`:

  Host: 		      $host -- ${DISTNAME} ${DISTVER}
  Bacula version:	      ${VERSION} (${DATE})
  Source code location:       ${srcdir}
  Install binaries:	      ${sbindir}
  Install config files:       ${sysconfdir}
  Scripts directory:	      ${scriptdir}
  Working directory:	      ${working_dir}
  PID directory:	      ${piddir}
  Subsys directory:	      ${subsysdir}
  C Compiler:		      ${CC} ${CCVERSION}
  C++ Compiler: 	      ${CXX} ${CXXVERSION}
  Compiler flags:	      ${WCFLAGS} ${CFLAGS} 
  Linker flags: 	      ${WLDFLAGS} ${LDFLAGS}
  Libraries:		      ${LIBS}
  Statically Linked Tools:    ${support_static_tools}
  Statically Linked FD:       ${support_static_fd}
  Statically Linked SD:       ${support_static_sd}
  Statically Linked DIR:      ${support_static_dir}
  Statically Linked CONS:     ${support_static_cons}
  Database type:	      ${db_name}
  Database lib: 	      ${DB_LIBS}

  Job Output Email:	      ${job_email}
  Traceback Email:	      ${dump_email}
  SMTP Host Address:	      ${smtp_host}

  Director Port:	      ${dir_port}
  File daemon Port:	      ${fd_port}
  Storage daemon Port:	      ${sd_port}

  Director User:	      ${dir_user}
  Director Group:	      ${dir_group}
  Storage Daemon User:	      ${sd_user}
  Storage DaemonGroup:	      ${sd_group}
  File Daemon User:	      ${fd_user}
  File Daemon Group:	      ${fd_group}

  SQL binaries Directory      ${SQL_BINDIR}

  Large file support:	      $largefile_support
  Bacula conio support:       ${got_conio} ${CONS_LIBS}
  readline support:	      ${got_readline} ${PRTREADLINE_SRC}
  TCP Wrappers support:       ${TCPW_MSG}
  ZLIB support: 	      ${have_zlib}
  enable-smartalloc:	      ${support_smartalloc} 
  enable-gnome: 	      ${support_gnome} ${gnome_version}
  enable-wx-console:	      ${support_wx_console}
  client-only:		      ${build_client_only}
  ACL support:		      ${have_acl}

  " > config.out

cat config.out

# old stuff
# cweb support: 	      ${got_cweb} ${CWEB_SRC}
# gmp support:		      ${got_gmp} ${GMP_SRC}
