dnl $Id: configure.in,v 1.70 2007/06/07 02:33:53 vkurland Exp $

AC_INIT
AC_CONFIG_SRCDIR([src/gui/main.cpp])
AC_CANONICAL_TARGET
AC_CONFIG_HEADER(config.h)
AC_CONFIG_HEADER(src/libfwbuilder/src/fwbuilder/libfwbuilder-config.h)

PACKAGE=fwbuilder
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [package])
AC_SUBST(PACKAGE)

LT_INIT
AC_CONFIG_MACRO_DIR([m4])

dnl
dnl all version numbers are defined in the file VERSION
dnl
. ./VERSION

RELEASE_NUM=$BUILD_NUM

AC_DEFINE_UNQUOTED(BUILD_NUM, "$BUILD_NUM")
AC_SUBST(BUILD_NUM)
AC_SUBST(RELEASE_NUM)

AC_SUBST(FWB_MAJOR_VERSION)
AC_SUBST(FWB_MINOR_VERSION)
AC_SUBST(FWB_MICRO_VERSION)
AC_SUBST(FWB_VERSION)

# libfwbuilder versions
dnl AC_SUBST(LIBFWBUILDER_VERSION)
AC_SUBST(FWBUILDER_XML_VERSION)

AC_DEFINE_UNQUOTED(FWBUILDER_XML_VERSION, "$FWBUILDER_XML_VERSION")

echo "Creating VERSION.h file..."

cat <<EOF > VERSION.h
#define VERSION      "$VERSION"
#define GENERATION   "$GENERATION"
EOF

dnl try to find QT
dnl
AC_ARG_WITH(qtdir,[  --with-qtdir=DIR        Specify directory path for QT ])

if test -n "$with_qtdir"; then
   AC_MSG_CHECKING(Using QT in )
   QTDIR="$with_qtdir";
   export QTDIR
   AC_MSG_RESULT($QTDIR)
fi

# TODO: do we need to add $QTDIR/bin to PATH to find qmake?
EXTENDED_PATH="/usr/local/bin:$PATH"

AC_ARG_WITH(qmake, [  --with-qmake=qmake     Specify the qmake to be used (debian qmake-qt4) ])
if test -n "$with_qmake"; then
    AC_PATH_PROG(QMAKE,  $with_qmake,      ,[$EXTENDED_PATH])
    if test -z "$QMAKE"; then
        AC_MSG_ERROR("Could not find qmake")
    fi
else
    AC_PATH_PROG(QMAKE,  qmake,      ,[$EXTENDED_PATH])
    if test -z "$QMAKE"; then
        AC_PATH_PROG(QMAKE,  qmake-qt4,      ,[$EXTENDED_PATH])
        if test -z "$QMAKE"; then
            AC_MSG_ERROR("Could not find qmake")
        fi
    fi
fi

AC_MSG_CHECKING(checking version of QT this qmake is part of)
qmake_version=`$QMAKE -v 2>&1 | awk '/Using Qt version/ { print $4;}'`
case $qmake_version in
    4.*) AC_MSG_RESULT( $qmake_version ) ;;
      *) AC_MSG_ERROR( "$qmake_version -- v4.x is required") ;;
esac



AC_ARG_WITH(templatedir, [  --with-templatedir=DIR  Specify directory path for fwbuilder template files ])
AC_ARG_WITH(docdir,      [  --with-docdir=DIR       Specify directory path for fwbuilder 
                          documentation files  ])
AC_ARG_WITH(datadir,     [  --with-datadir=DIR      Specify directory path for fwbuilder 
                          data files  ])

AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),
               AC_DEFINE(WORDS_LITTLEENDIAN),
               AC_MSG_ERROR(Failed to determine endianness!!))

LIBFWBUILDER_LIBDIR='-L${libdir}'



dnl
dnl   Determine init dir and add definition to config.h. Program
dnl   determines prefix name of the directory it was started from
dnl   and prepends it to the RES_DIR
dnl

PREFIX=$ac_default_prefix

if test "x$prefix" != "xNONE"; then
  PREFIX=$prefix
fi
AC_DEFINE_UNQUOTED(PREFIX, "${PREFIX}", [prefix])
AC_SUBST(PREFIX)

AC_DEFINE_UNQUOTED(VERSION,              "$VERSION", [version])
AC_SUBST(VERSION)


AC_PROG_INSTALL

AC_ISC_POSIX
AC_PROG_CC
dnl  AM_PROG_CC_STDC
AC_HEADER_STDC
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_CXXCPP

dnl need this for intl to compile on FreeBSD and may be other platforms
AC_CHECK_FUNCS(strchr memcpy)


dnl AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
dnl AC_CANONICAL_HOST

AC_PROG_MAKE_SET


dnl Check for GNU make 
dnl 
AC_MSG_CHECKING(whether make is GNU Make)
if ${MAKE-make} -q --version 2>/dev/null | grep '^GNU Make ' >/dev/null ; then
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
  if test "$host_vendor" = "sun" ; then
    AC_MSG_ERROR("SUN make does not work for building Firewall Builder. Please install GNU make")
  fi
fi

dnl some platform-dependent flags
dnl 
dnl e.g. we need to set -I/sw/include before check for GETTEXT
dnl
GUILINKFLAGS=
case "$build_os" in
  *solaris*)
    GUILINKFLAGS="-export-dynamic"
    ;;
 esac
AC_SUBST(GUILINKFLAGS)

dnl
dnl forkpty is in libutil on Linux and BSD, while on Mac it is in libc
dnl
AC_CHECK_HEADERS( [pty.h libutil.h util.h],[],[],[#include <sys/types.h>])
AC_CHECK_LIB(c,forkpty,[
  AC_DEFINE_UNQUOTED(HAVE_FORKPTY, 1, [forkpty])
  ],[
  AC_CHECK_LIB(util,forkpty,[
    AC_DEFINE_UNQUOTED(HAVE_FORKPTY, 1, [forkpty])
    LIBS="-lutil $LIBS"
    ],[
    AC_MSG_RESULT(["forkpty not found, will use emulation"])
  ],[])
],[])

AC_CHECK_LIB(c,cfmakeraw,[
  AC_DEFINE_UNQUOTED(HAVE_CFMAKERAW, 1, [cfmakeraw])
])


dnl standard LIBTOOL fragment
dnl
dnl     commented out 12/20 - we now use qmake and do not need libtool 
dnl
dnl AC_LIBTOOL_DLOPEN
dnl AC_PROG_LIBTOOL
dnl AC_SUBST(LIBTOOL_DEPS)
dnl AM_PROG_LIBTOOL
dnl AC_PROG_RANLIB

AC_CHECK_HEADERS([getopt.h])
AC_CHECK_HEADERS([signal.h])
AC_CHECK_HEADERS([endian.h])

AC_CHECK_FUNCS(strtok_r)

AC_CHECK_FUNCS(stat _stat signal)

AC_STRUCT_TM
AC_STRUCT_TIMEZONE

dnl do not insert spaces in these macros, even outside of []
AC_PATH_PROG(RCS_FILE_NAME,[rcs],[rcs],[$EXTENDED_PATH])
AC_PATH_PROG(RCSDIFF_FILE_NAME,[rcsdiff],[rcsdiff],[$EXTENDED_PATH])
AC_PATH_PROG(RLOG_FILE_NAME,[rlog],[rlog],[$EXTENDED_PATH])
AC_PATH_PROG(CI_FILE_NAME,[ci],[ci],[$EXTENDED_PATH])
AC_PATH_PROG(CO_FILE_NAME,[co],[co],[$EXTENDED_PATH])

AC_DEFINE_UNQUOTED(RCS_FILE_NAME,      ["$RCS_FILE_NAME"], [rcs_file_name])
AC_DEFINE_UNQUOTED(RCSDIFF_FILE_NAME,  ["$RCSDIFF_FILE_NAME"], [rcsdiff_file_name])
AC_DEFINE_UNQUOTED(RLOG_FILE_NAME,     ["$RLOG_FILE_NAME"], [rlog_file_name])
AC_DEFINE_UNQUOTED(CI_FILE_NAME,       ["$CI_FILE_NAME"], [ci_file_name])
AC_DEFINE_UNQUOTED(CO_FILE_NAME,       ["$CO_FILE_NAME"], [co_file_name])


AC_SUBST(LIBS) 

AC_LANG([C++])

AM_PATH_CPPUNIT(1.12.0, [HAVE_CPPUNIT="1"])
AC_DEFINE_UNQUOTED(HAVE_CPPUNIT, $HAVE_CPPUNIT)
AC_SUBST(HAVE_CPPUNIT)
AC_SUBST(CPPUNIT_CFLAGS)
AC_SUBST(CPPUNIT_LIBS)

dnl A check for antlr-runtime library used to be here but has been
dnl removed. We should always use antlr runtime code incuded with
dnl fwbuilder code tree because of the fixes I've done in
dnl CurcularQueue.hpp module for 64 bit systems. This problem seems to
dnl have been fixed in antlr v3 but until we convert all grammars to
dnl the new antlr, we have to use provided antlr 2.7.7 with these
dnl fixes. This means we can't use antlr runtime that comes with the
dnl OS even if it is installed.

ANTLR_INCLUDEPATH="`pwd`/src/"
ANTLR_LIBS="`pwd`/src/antlr/libantlr.a"
AC_SUBST(ANTLR_LIBS)
AC_SUBST(ANTLR_INCLUDEPATH)

dnl check for pthreads
dnl
dnl Somehow, standard macro tries -lpthreads, while pthread library really
dnl is "libpthread" on Linux. Thus only test using -pthread suceeds, but
dnl PTHREAD_LIBS macro ends up empty.

ACX_PTHREAD([
   test -z "$PTHREAD_LIBS" && test "$PTHREAD_CFLAGS" = "-pthread" && PTHREAD_LIBS="-pthread"

   echo "Found pthread library:"
   echo "PTHREAD_CFLAGS="$PTHREAD_CFLAGS
   echo "PTHREAD_LIBS="$PTHREAD_LIBS

] , [
   AC_MSG_ERROR([POSIX threads library not present or not configured])
])

dnl check for XML library

AC_PATH_PROG(XML2_CONFIG, xml2-config,  ,[$EXTENDED_PATH])

if test x$XML2_CONFIG = x ; then
   AC_MSG_ERROR([libxml2 not present or not configured])
else
  XML_CFLAGS="`$XML2_CONFIG --cflags`"
  XML_LIBS="`$XML2_CONFIG --libs`"
fi
XML_CFLAGS=`echo $XML_CFLAGS | sed 's/-I\/usr\/include //'`
AC_SUBST(XML_CFLAGS)
AC_SUBST(XML_LIBS) 

SAVE_LIBS=${LIBS}
LIBS="$XML_LIBS $LIBS"
AC_CHECK_FUNCS(xmlSaveFormatFileEnc)
LIBS=${SAVE_LIBS}

dnl check for XSLT library

AC_PATH_PROG(XSLT_CONFIG, xslt-config,  ,[$EXTENDED_PATH])

if test x$XSLT_CONFIG = x ; then
   AC_MSG_ERROR([libxslt not present or not configured])
else
  XSLT_CFLAGS="`$XSLT_CONFIG --cflags`"
  XSLT_LIBS="`$XSLT_CONFIG --libs`"
fi
XSLT_CFLAGS=`echo $XSLT_CFLAGS | sed 's/-I\/usr\/include //'`

dnl
dnl purely aestetical: xslt-config often reports the same flags as 
dnl xml2-config
dnl
ac_xslt_var=""
for w in ${XSLT_CFLAGS}; do
  case " ${XML_CFLAGS} " in
    *\ $w\ *) ;;
    *) ac_xslt_var="$ac_xslt_var $w" ;;
  esac
done
XSLT_CFLAGS=$ac_xslt_var

ac_xslt_var=""
for w in ${XSLT_LIBS}; do
  case " ${XML_LIBS} " in
    *\ $w\ *) ;;
    *) ac_xslt_var="$ac_xslt_var $w" ;;
  esac
done
XSLT_LIBS=$ac_xslt_var

AC_SUBST(XSLT_CFLAGS)
AC_SUBST(XSLT_LIBS) 
 
dnl libXslt header libxslt/xsltconfig.h only present in newew version of libxslt
dnl for instance it is not part of 1.0.1 but present in 1.0.7.
AC_CHECK_HEADERS(libxslt/xsltconfig.h)

dnl Check for bind specific headers and libraries
dnl if they are present, use them, rather than ones
dnl coming with libc.

AC_CHECK_HEADER(bind/resolv.h, [
  CPPFLAGS="$CPPFLAGS -I/usr/include/bind"
  HAVE_RESOLV_H=yes
] , [ AC_CHECK_HEADER(/usr/local/bind/include/resolv.h, [
    CPPFLAGS="$CPPFLAGS -I/usr/local/bind/include/"
    HAVE_RESOLV_H=yes
  ], [ 
    AC_CHECK_HEADERS([resolv.h], [ HAVE_RESOLV_H=yes ], [], [
#include <sys/types.h>
#include <netinet/in.h> 
    ] )
  ] )
], [
#include <netinet/in.h>
] )

LIB_RESOLV=""
HAVE_RES_NQUERY=""
AC_SUBST(LIB_RESOLV) 


dnl
dnl prepare equivalents of *_CFLAGS variables for qmake
dnl qmake requires these to be without "-I"
dnl
XML_CFLAGS_Q=`echo ${XML_CFLAGS} | sed 's/-I//g'`
XSLT_CFLAGS_Q=`echo ${XSLT_CFLAGS} | sed 's/-I//g'`
PTHREAD_CFLAGS_Q=`echo ${PTHREAD_CFLAGS} | sed 's/-I//g'`
LIBS_Q=`echo ${LIBS} | sed 's/-I//g'`

AC_SUBST(XML_CFLAGS_Q)
AC_SUBST(XSLT_CFLAGS_Q)
AC_SUBST(PTHREAD_CFLAGS_Q)
AC_SUBST(LIBS_Q)



dnl
dnl  We also support "--with-ucdsnmp=no" and "--without-ucdsnmp"
dnl  By default we assume user wants snmp support, provided script
dnl  can find the library
dnl
dnl  Just in case we support both --with-ucdsnmp and --with-ucd-snmp
dnl                                    --vk
dnl

check_for_ucdsnmp=yes
if test x$with_ucdsnmp = xno ; then
  check_for_ucdsnmp=no
fi

if test x$with_ucd_snmp = xno ; then
  check_for_ucdsnmp=no
fi

if test $check_for_ucdsnmp = yes ; then

dnl
dnl net-snmp library includes script net-snmp-config which I use to determine cflags
dnl and libs. Unfortunately even if this script is there and is used  flags, 
dnl the program may still not link with the library. Currently having this problem on 
dnl FreeBSD 4.7 - after upgrade of openssl, code using net-snmp stopped linking. That 
dnl is why I still try to do linking test even if script is present.
dnl
dnl Testing for presence of includes and doing linking test assures that -devel 
dnl package is indeed installed (primitive test program could link with libsnmp.so 
dnl even if -devel package is not installed and headers are not there).
dnl
  AC_PATH_PROG(NET_SNMP_CONFIG, net-snmp-config,  ,[$EXTENDED_PATH])
  if test x$NET_SNMP_CONFIG != x ; then
    ac_LIBSNMP_LIBS="`$NET_SNMP_CONFIG --libs`"
    ac_LIBSNMP_CFLAGS="`$NET_SNMP_CONFIG --cflags`"
    AC_CHECK_LIB(netsnmp, init_snmp,
    [
      HAVE_LIBSNMP="1"
      AC_DEFINE(HAVE_LIBSNMP)
      NET_SNMP="1"
      AC_DEFINE(NET_SNMP)
      LIBSNMP_LIBS=$ac_LIBSNMP_LIBS
      LIBSNMP_CFLAGS=$ac_LIBSNMP_CFLAGS
      AC_CHECK_LIB(netsnmp, snprint_objid, [
        AC_DEFINE(HAVE_SNPRINT_OBJID)
      ], ,$ac_LIBSNMP_LIBS)
    ], ,$ac_LIBSNMP_LIBS)
  else
    AC_CHECK_HEADERS([ucd-snmp/asn1.h], [
      AC_CHECK_HEADER(ucd-snmp/snmp.h, [
        AC_CHECK_LIBSNMP( snmp )
        if test "Z$HAVE_LIBSNMP" != "Z"; then
          UCD_SNMP="1"
          AC_DEFINE(UCD_SNMP)
          save_LIBS=$LIBS
          LIBS="$LIBSNMP_LIBS $LIBS"
          AC_CHECK_LIB(snmp, snprint_objid, [
            AC_DEFINE(HAVE_SNPRINT_OBJID)
          ])
          LIBS=$save_LIBS
        fi
      ], ,[
#include <sys/types.h>
#include <ucd-snmp/asn1.h>
      ])
    ])
  fi

  LIBS="${LIBSNMP_LIBS} ${LIBS}"

fi
AC_SUBST(LIBSNMP_LIBS) 

AC_CHECK_LIB(c, inet_net_ntop, [
  AC_DEFINE_UNQUOTED(HAVE_INET_NET_NTOP, 1, [inet_net_ntop])
  ],[
    AC_CHECK_LIB(bind, inet_net_ntop, [
      AC_DEFINE_UNQUOTED(HAVE_INET_NET_NTOP, 1, [inet_net_ntop])
      LIBS="-lbind $LIBS"
      ])
],[])


AC_CHECK_LIB(z, gzopen, [ LIBS="-lz ${LIBS}"], [
   AC_MSG_ERROR([libz library not found])
])

dnl
dnl   Determine init dir and add definition to config.h
dnl

PREFIX=$ac_default_prefix

if test "x$prefix" != "xNONE"; then
  PREFIX=$prefix
fi

dnl ********************************************************************


if test "x$with_docdir" != "x"; then
  DOCDIR="${with_docdir}"
else
  DOCDIR="${PREFIX}/share/doc/fwbuilder-${VERSION}"
fi
DOCDIRPATH=`dirname ${DOCDIR}`

if test "x$with_datadir" != "x"; then
  DATADIR="${with_datadir}"
else
  DATADIR="${PREFIX}/share/"
fi

ICONSDIR=""

AC_MSG_CHECKING(what OS this is)

case ${host} in
  *-*-cygwin*)
    OS=cygwin
    OS_CYGWIN=1
    AC_MSG_RESULT(Win32 cygwin)
    DEFAULT_RES_DIR="resources"
    ;;

  *-*-mingw32*)
    OS=mingw32
    OS_MINGW=1
    AC_MSG_RESULT(Win32 mingw)
    DEFAULT_RES_DIR="resources"
    ;;

  *-*-darwin*)
    OS=MacOSX
    OS_MACOSX=1
    MANDIR="${PREFIX}/share/man/"
    AC_MSG_RESULT(MacOSX)
    DEFAULT_RES_DIR="../Resources"
    ;;

  *-*-solaris*)
    OS=Solaris
    OS_SOLARIS=1
    MANDIR="${PREFIX}/share/man/"
    AC_MSG_RESULT(Solaris)
    DEFAULT_RES_DIR="${PREFIX}/share/fwbuilder-${VERSION}"
    ;;

  *-*-freebsd*)
    OS=FreeBSD
    OS_FREEBSD=1
    MANDIR="${PREFIX}/man/"
    AC_MSG_RESULT(FreeBSD)
    DEFAULT_RES_DIR="${PREFIX}/share/fwbuilder-${VERSION}"
    ;;

  *-*-openbsd*)
    OS=OpenBSD
    OS_OPENBSD=1
    MANDIR="${PREFIX}/man/"
    AC_MSG_RESULT(OpenBSD)
    DEFAULT_RES_DIR="${PREFIX}/share/fwbuilder-${VERSION}"
    ;;

  *-*-kfreebsd*)
    OS=FreeBSD
    OS_FREEBSD=1
    if test -f /etc/debian_version ; then
       DISTRO=Debian
    else
       DISTRO="Unknown"
    fi
    MANDIR="${PREFIX}/share/man/"
    AC_MSG_RESULT($DISTRO GNU/kFreeBSD)
    DEFAULT_RES_DIR="${PREFIX}/share/fwbuilder-${VERSION}"
    ;;

  *-*-linux*)
    DEFAULT_RES_DIR="${PREFIX}/share/fwbuilder-${VERSION}"
    OS=Linux
    OS_LINUX=1
    if test -f /etc/debian_version ; then
	DISTRO=Debian
    elif test -f /etc/mandrake-release ; then
	DISTRO=Mandrake
    elif test -f /etc/slackware-version ; then
	DISTRO=Slackware
    elif test -f /etc/SuSE-release ; then
        DISTRO=SuSE
    elif test -f /etc/redhat-release ; then
#
# Mandrake has symlink /etc/redhat-release -> /etc/manrake-release ,
# so this check must be the last
#
	DISTRO=RedHat
    else
	DISTRO="Unknown"
    fi
    MANDIR="${PREFIX}/share/man/"
    ICONSDIR="${DATADIR}/icons/hicolor/"
    AC_MSG_RESULT($DISTRO Linux)
    ;;

  *)
    OS=Unknown
    OS_UNKNOWN=1
    DISTRO=Unknown
    MANDIR="${PREFIX}/share/man/"
    AC_MSG_RESULT(Unknown)
    DEFAULT_RES_DIR="${PREFIX}/share/fwbuilder-${VERSION}"
    ;;
esac

if test "x$with_templatedir" != "x"; then
  RES_DIR="${with_templatedir}"
else
  RES_DIR="$DEFAULT_RES_DIR"
fi

AC_DEFINE_UNQUOTED(RES_DIR, "$RES_DIR", [res_dir])
AC_SUBST(RES_DIR)

dnl   prefix has bogus value while building RPM. Since program
dnl   should incrorporate full path to the templates directory into
dnl   the code via config.h file, we need to keep track of
dnl   this directory twice: TEMPLATE_DIR is what goes to config.h, while
dnl   "install" Makefile targets will use $(prefix) to build install
dnl   path

TEMPLATE_DIR=$RES_DIR
AC_DEFINE_UNQUOTED(LIBFWBUILDER_TEMPLATE_DIR, "${TEMPLATE_DIR}")
AC_SUBST(TEMPLATE_DIR)


AC_SUBST(OS)
AC_DEFINE_UNQUOTED(OS, "${OS}", [os])
test -n "$OS_CYGWIN" && AC_DEFINE_UNQUOTED(OS_CYGWIN, "${OS_CYGWIN}", [cygwin])
test -n "$OS_MINGW" && AC_DEFINE_UNQUOTED(OS_MINGW, "${OS_MINGW}", [mingw])
test -n "$OS_MACOSX" && AC_DEFINE_UNQUOTED(OS_MACOSX, "${OS_MACOSX}", [macosx])
test -n "$OS_SOLARIS" && AC_DEFINE_UNQUOTED(OS_SOLARIS,"${OS_SOLARIS}",[solaris])
test -n "$OS_FREEBSD" && AC_DEFINE_UNQUOTED(OS_FREEBSD,"${OS_FREEBSD}",[freebsd])
test -n "$OS_OPENBSD" && AC_DEFINE_UNQUOTED(OS_OPENBSD,"${OS_OPENBSD}",[openbsd])
test -n "$OS_LINUX" && AC_DEFINE_UNQUOTED(OS_LINUX, "${OS_LINUX}", [linux])
test -n "$OS_SECUWALL" && AC_DEFINE_UNQUOTED(OS_SECUWALL, "${OS_SECUWALL}", [secuwall])
test -n "$OS_UNKNOWN" && AC_DEFINE_UNQUOTED(OS_UNKNOWN,"${OS_UNKNOWN}",[unknown])

AC_SUBST(DISTRO)
AC_DEFINE_UNQUOTED(DISTRO, "${DISTRO}", [distro])

AC_SUBST(DOCDIRPATH)
AC_DEFINE_UNQUOTED(DOCDIRPATH, "${DOCDIRPATH}", [docdirpath])

AC_SUBST(DOCDIR)
AC_DEFINE_UNQUOTED(DOCDIR, "${DOCDIR}", [docdir])

AC_SUBST(DATADIR)
AC_SUBST(MANDIR)
AC_SUBST(ICONSDIR)

AC_ARG_WITH(ccache,[  --with-ccache=yes      Use ccache to speed up repeated compilation])

if test -n "$with_ccache"; then
  if test "x$with_ccache" != "xno"; then
    AC_PATH_PROG(CCACHE, ccache, , )
    AC_SUBST(CCACHE)
    if test -n "$CCACHE"
    then
      ccache -s
    fi
  else
    CCACHE=""
    AC_SUBST(CCACHE)
  fi
else
  AC_PATH_PROG(CCACHE, ccache, , )
  AC_SUBST(CCACHE)
  if test -n "$CCACHE"
  then
        ccache -s
  fi
fi

AC_ARG_WITH(distcc,[  --with-distcc=N        Use distcc with N parallel make count])

if test -n "$with_distcc"; then
  if test "x$with_distcc" != "xno"; then
    AC_PATH_PROG(HAVE_DISTCC, distcc, , )
    if test -n "$HAVE_DISTCC"; then
       DISTCC=$HAVE_DISTCC
       AC_SUBST(DISTCC)
       PARALLEL_MAKE_COUNT=$with_distcc
       AC_SUBST(PARALLEL_MAKE_COUNT)
    fi
  fi
else

  AC_PATH_PROG(HAVE_DISTCC, distcc, , )
  if test -n "$HAVE_DISTCC"; then
     M_J=$(distcc -j 2>/dev/null)
     if test -n "$M_J"; then
        DISTCC=$HAVE_DISTCC
        AC_SUBST(DISTCC)
        PARALLEL_MAKE_COUNT=$M_J
        AC_SUBST(PARALLEL_MAKE_COUNT)
     fi
  fi
fi

AC_CONFIG_FILES([ qmake.inc
                  src/res/objects_init.xml
                  src/res/templates.xml
                  src/libfwbuilder/qmake.inc
                  src/libfwbuilder/etc/fwbuilder.dtd
                  packaging/fwbuilder.control
                  packaging/fwbuilder.spec
                  packaging/fwbuilder-static-qt.spec])


AC_OUTPUT

# QMAKE=$QMAKE CCACHE=$CCACHE QTDIR=$QTDIR ./runqmake.sh
QMAKE=$QMAKE QTDIR=$QTDIR ./runqmake.sh

