packages feed

darcs-cabalized-2.0.2: configure.ac

dnl This file is in the public domain.

dnl Process this file with Autoconf to produce a configure script.

dnl Remove the datarootdir/docdir tests below if this is increased:
AC_PREREQ([2.59])
AC_INIT([darcs], [2.0.2], [bugs@darcs.net])
AC_CONFIG_SRCDIR([src/darcs.lhs])

dnl Write our invocation date/time and flags into a file so that
dnl Darcs knows how it was built.

ac_cmdline_args="$*"
AC_CONFIG_COMMANDS([config.command],
                   [ echo > config.command "# configured $date"
                     echo >>config.command "./configure $args"
		     chmod +x config.command
                   ],
                   [date="`date`"; args="$ac_cmdline_args"])

dnl The following is now the authoritative location of the version
dnl number. All references to the darcs version number should
dnl originate here. From Haskell this is easily done by importing
dnl the module "Autoconf ( darcs_version )".
dnl
dnl The version string must not contain any spaces. The version
dnl state will automatically be set to any of:
dnl
dnl    "prerelease #n"
dnl    "release candidate #n"
dnl    "release"
dnl    "unstable branch"
dnl    "stable branch"
dnl    "unknown branch"
dnl
dnl The new darcs custom is to increase the version number
dnl directly after a release, since the checking for a tag
dnl indicates whether the number is really correct.

DARCS_VERSION=$PACKAGE_VERSION
AC_SUBST(DARCS_VERSION)

dnl See if we are in a darcs repo and also have darcs available,
dnl and whether we're in a repository...

AC_CHECK_PROG(DARCS, darcs, darcs)
AC_MSG_CHECKING([if we're in a darcs repository])
if test ! -z "$DARCS" && test -e "_darcs/hashed_inventory"; then
  I_AM_IN_REPO=yes
else
  I_AM_IN_REPO=no
fi
AC_MSG_RESULT($I_AM_IN_REPO)
AC_SUBST(I_AM_IN_REPO)

dnl Get rid of the lousy '-g -O2' defaults

CFLAGS=$CFLAGS

dnl Find gcc

dnl AC_PROG_CC
dnl AC_PROG_CPP

dnl Make sure a decent "install" is installed.

AC_PROG_INSTALL

dnl Check to see if we are compiling under Windows

AC_CHECK_HEADER(windows.h, [SYS=windows], [SYS=other])
AC_SUBST(SYS)

dnl Find ghc

AC_CHECK_PROG(GHC, ghc, ghc)
if test -z "$GHC"; then
    AC_MSG_ERROR([Cannot find ghc in your path; please set the GHC environment variable!!])
fi
AC_SUBST(GHCFLAGS)
echo found `$GHC --version`

dnl Make sure compiler actually works:

TRY_COMPILE_GHC([main = putStr "Hello world!\n"],,
                AC_MSG_ERROR(Compile failed.))

dnl Before anything else, we need to decide what core compiler features to
dnl use, becaues this affects all the tests below (e.g. some packages may
dnl not be available with profiling)

dnl Make default to not profile...

AC_MSG_CHECKING([whether to profile])
AC_ARG_ENABLE(profile,
              AS_HELP_STRING([--enable-profile],[enable profiling]),
              profile=$enableval,profile=no)
AC_MSG_RESULT($profile)

if test "$profile" = yes; then
   GHCFLAGS="$GHCFLAGS -prof -auto-all"
fi

dnl See if we want to use -threaded to get more responsive progress reporting.
AC_MSG_CHECKING([whether to use the threaded runtime])
AC_ARG_ENABLE(threaded,AS_HELP_STRING([--disable-threaded],
              [don't compile with threaded runtime]),[AC_MSG_RESULT([no])],
              [MYOLDGHCFLAGS=$GHCFLAGS
               GHCFLAGS="$GHCFLAGS -threaded"
               TRY_COMPILE_GHC([main = putStr "Hello world!\n"],
                [AC_MSG_RESULT([yes])],
                [AC_MSG_RESULT([failed, threaded runtime disabled])
                 AC_MSG_WARN([Unable to compile with threaded runtime!])
                 GHCFLAGS=$MYOLDGHCFLAGS])])

INIT_WORKAROUND

dnl Figure out how to convert a file descriptor to a Handle

WORKAROUND_openFd

dnl Handle posix signals nicely:

WORKAROUND_POSIXSIGNALS([installHandler, raiseSignal, Handler(..), Signal,
                         sigINT, sigHUP, sigABRT, sigALRM, sigTERM, sigPIPE,])

AC_CHECK_HEADERS([siginfo.h])

dnl Look for Text.Regex

GHC_CHECK_MODULE(Text.Regex( mkRegex, matchRegex, Regex ), text, mkRegex undefined,,
  GHC_CHECK_MODULE(Text.Regex( mkRegex, matchRegex, Regex ), regex-compat, mkRegex undefined,,
    AC_MSG_ERROR(Cannot find Test.Regex; try installing the package text or regex-compat?)
  )
)

dnl Look for native http library

GHC_CHECK_MODULE(Network.HTTP( urlEncode ), HTTP, urlEncode undefined,
                 [HAVE_HTTP=True
                  AC_DEFINE([HAVE_HTTP])],[HAVE_HTTP=False])

AC_SUBST(HAVE_HTTP)

dnl See if we need a package for QuickCheck

GHC_CHECK_MODULE(Test.QuickCheck( quickCheck ), QuickCheck, quickCheck True,,
                 AC_MSG_ERROR(Cannot find Test.QuickCheck; try installing package quickcheck?))

dnl See if we have an adequate version of bytestring
GHC_CHECK_MODULE(Data.ByteString.Internal( fromForeignPtr ),
                 bytestring,
                 fromForeignPtr,
                 [bytestringfound=yes],
                 [bytestringfound=no])
if test $bytestringfound = "yes"; then
  AC_MSG_CHECKING([whether to use ByteString])
  AC_ARG_ENABLE(bytestring,
                AS_HELP_STRING([--disable-bytestring], [do not use bytestring, even if it is present]),
                bytestring=$enableval,
                bytestring=yes)
  AC_MSG_RESULT($bytestring)
  # If we aren't instructed to avoid bytestring, and we did successfully find bytestring...
  if test $bytestring = "yes"; then
     CPPFLAGS="$CPPFLAGS -DHAVE_BYTESTRING"
  fi
fi

dnl See if we need the util or mtl packages for Control.Monad

GHC_CHECK_MODULE(Control.Monad.Error, mtl, strMsg "foo" :: String,,
                 AC_MSG_ERROR(Cannot find Control.Monad.Error; try installing package mtl?))

dnl See if we need a package for parsec...

GHC_CHECK_MODULE(Text.ParserCombinators.Parsec, parsec, errorPos undefined,,
                 AC_MSG_ERROR(Cannot find Text.ParserCombinators.Parsec; try installing package parsec?))

dnl Check if we need package html

GHC_CHECK_MODULE(Text.Html, html, text "foo",,
                 AC_MSG_ERROR(Cannot find Text.Html; try installing package html?))

dnl Check if we need package containers

GHC_CHECK_MODULE(Data.Map, containers, empty,,
                 AC_MSG_ERROR(Cannot find Data.Map; try installing package containers?))

dnl Deal with systems on which getCurrentDirectory uses '\\' rather than '/':

WORKAROUND_getCurrentDirectory
AC_SUBST(GHC_SEPARATOR)

dnl Deal with systems without createLink

WORKAROUND_createLink

dnl Deal with GHCs without createDirectoryIfMissing

WORKAROUND_createDirectoryIfMissing

dnl Handle systems with a buggy renameFile

WORKAROUND_renameFile

dnl Deal with systems without bracketWithError

WORKAROUND_bracketOnError

dnl Handle systems that don't do POSIX file modes

WORKAROUND_fileModes

WORKAROUND_executable

dnl Make default to have optimizations on...

AC_MSG_CHECKING([whether to optimize])
AC_ARG_ENABLE(optimize,
              AS_HELP_STRING([--disable-optimize],[disable optimization]),
              optimize=$enableval, optimize=yes)
AC_MSG_RESULT($optimize)

if test "$optimize" = yes; then
   GHCFLAGS="$GHCFLAGS -O2 -funbox-strict-fields"
   if test "$CFLAGS" = ""; then
      CFLAGS="$CFLAGS -O2"
   fi
fi

dnl Make default to not use hpc

AC_MSG_CHECKING([whether to use Haskell Program Coverage])
AC_ARG_ENABLE(hpc,
              AS_HELP_STRING([--enable-hpc],[enable Haskell Program Coverage]),
              hpc=$enableval,hpc=no)
AC_MSG_RESULT($hpc)

if test "$hpc" = yes; then
   GHCFLAGS="$GHCFLAGS -fhpc"
fi

dnl See if we want to use mmap... defaults to yes, except under
dnl Windows, where this is always disabled.

AC_MSG_CHECKING([whether to use mmap])
AC_ARG_ENABLE(mmap, AS_HELP_STRING([--disable-mmap],
              [do not use mmap (use this flag if you get bus errors)]),
              enable_mmap=$enableval,enable_mmap=yes)
if test "$SYS" = "windows"; then
  AC_MSG_RESULT(no (Windows))
else
  AC_MSG_RESULT($enable_mmap)
fi
USE_MMAP="True"
if test "$enable_mmap" = "no" || test "$SYS" = "windows" ; then
    USE_MMAP="False"
fi
AC_SUBST(USE_MMAP)

TARGETS="darcs doc/darcs.1"
INSTALLWHAT="installbin"
BUILDDOC="no"

dnl Check whether to generate the AUTHORS and ChangeLog files...
if test -d "_darcs"; then
  TARGETS="$TARGETS AUTHORS ChangeLog"
fi

dnl Check whether to use crazy PackedString debugging...

AC_MSG_CHECKING([whether to do PackedString debugging])
AC_ARG_ENABLE(debug-ps,
              [  --enable-debug-ps       enable PackedString debug mode],
               debugps=$enableval, debugps=no)
AC_MSG_RESULT($debugps)


if test "$debugps" = yes; then
   GHCFLAGS="$GHCFLAGS -DDEBUG_PS"
fi

dnl Find latex and friends

AC_MSG_CHECKING([whether to build docs])
AC_ARG_WITH(docs,
	AS_HELP_STRING([--without-docs],
                           [do not try to build docs]),
           ,with_docs=yes)
AC_MSG_RESULT($with_docs)

if test "$with_docs" = "yes"; then
	AC_CHECK_PROG(LATEX, latex, latex)
	if test -z "$LATEX"; then
	AC_MSG_WARN([Cannot find latex in your path!])
	fi
	AC_CHECK_PROG(PDFLATEX, pdflatex, pdflatex)
	if test -z "$PDFLATEX"; then
	AC_MSG_WARN([Cannot find pdflatex in your path!])
	fi
	AC_CHECK_PROG(DVIPS, dvips, dvips)
	if test -z "$DVIPS"; then
	AC_MSG_WARN([Cannot find dvips in your path!])
	fi
	if test ! '(' '(' -z "$LATEX" ')' -o '(' -z "$DVIPS" ')' ')'; then
	TARGETS="$TARGETS doc/manual/darcs.ps"
	INSTALLWHAT="$INSTALLWHAT installdocs"
	BUILDDOC="yes"
	fi
	if test ! '(' -z "$PDFLATEX" ')'; then
	TARGETS="$TARGETS doc/manual/darcs.pdf doc/manual/patch-theory.pdf"
	fi
	AC_CHECK_PROG(LATEX2HTML, latex2html, latex2html)
	if test -z "$LATEX2HTML"; then
	AC_MSG_WARN([Cannot find latex2html in your path!])
	PREPROCHTML=""
	AC_CHECK_PROG(HTLATEX, htlatex, htlatex)
	if test -z "$HTLATEX"; then
		AC_MSG_WARN([Cannot find htlatex in your path either!])
		AC_CHECK_PROG(HEVEA, hevea, hevea)
		if test -z "$HEVEA"; then
		AC_MSG_WARN([Cannot find hevea in your path either!])
		MAKEMANUAL="touch doc/manual/index.html; echo Cannot make manual!"
		else
		TARGETS="$TARGETS doc/manual/index.html"
		MAKEMANUAL="$HEVEA -o doc/manual/index.html src/darcs.tex"
		fi
	else
		TARGETS="$TARGETS doc/manual/index.html"
		MAKEMANUAL="cd doc/manual && $HTLATEX ../../src/darcs.tex && ln -sf darcs.html index.html"
	fi
	else
	TARGETS="$TARGETS doc/manual/index.html"
	MAKEMANUAL="$LATEX2HTML -split +1 -dir doc/manual src/darcs.tex"
	dnl the following tells "preproc" to generate "rawhtml" sections for latex2html.
	PREPROCHTML="--html"
	fi
else
	BUILDDOC="no"
fi

AC_SUBST(TARGETS)
AC_SUBST(MAKEMANUAL)
AC_SUBST(INSTALLWHAT)
AC_SUBST(PREPROCHTML)

dnl Look for sendmail...

AC_ARG_WITH(sendmail, [  --with-sendmail=PATHTOSENDMAIL],
[
SENDMAIL=$with_sendmail
HAVE_SENDMAIL="True"
],[
STUPID_PATH=/usr/sbin:/usr/lib
AC_PATH_PROG(SENDMAIL, sendmail, "", $PATH:$STUPID_PATH)
if test -z "$SENDMAIL"; then
    SENDMAIL=""
    HAVE_SENDMAIL="False"
else
    HAVE_SENDMAIL="True"
fi
])
AC_SUBST(SENDMAIL)
AC_SUBST(HAVE_SENDMAIL)

dnl Look for MAPISendMail

AC_CHECK_LIB(mapi32, MAPISendMail, HAVE_MAPI="True", HAVE_MAPI="False")
AC_SUBST(HAVE_MAPI)

if test "$HAVE_SENDMAIL" = "False" -a "$HAVE_MAPI" = "False"; then
    AC_MSG_WARN([Can't find sendmail or mapi so you won't be able to push by email!])
fi

dnl Allow use of color in output to be disabled

AC_ARG_ENABLE(color, AS_HELP_STRING([--disable-color],[do not use ansi color escapes]))

dnl export color flag
USE_COLOR="True"
if test "$enable_color" = "no"; then
    USE_COLOR="False"
fi
AC_SUBST(USE_COLOR)

dnl Try to link with static versions of libraries.

AC_ARG_WITH(static-libs, [  --with-static-libs      link with static versions of libraries])
if test "x$with_static_libs" = "xyes"; then
    LDFLAGS="-static $LDFLAGS"
fi

dnl Check whether to use existential type witnesses

AC_MSG_CHECKING([for gadt type witnesses])
AC_ARG_WITH(type-witnesses,
            AS_HELP_STRING([--with-type-witnesses],
                           [use GADT type witnesses (EXPERIMENTAL!)])
            ,with_typew=yes
            ,with_typew=no)

if test "$with_typew" = "yes"; then
 GHCFLAGS="$GHCFLAGS -fglasgow-exts"
 AC_DEFINE([GADT_WITNESSES])
 AC_MSG_RESULT([yes])
else
 AC_MSG_RESULT([no])
fi

dnl look for zlib library and header.
dnl Use GHC_CHECK_LIBRARY and not AC_CHECK_HEADER / AC_CHECK_LIB because GHC may
dnl use a different library and header than the system GCC (on Windows, issue 813)

GHC_CHECK_LIBRARY([z],[zlib.h deflate],[Int -> Int -> Int],[],
   [AC_MSG_ERROR(Cannot find system's zlib library; please set the LDFLAGS environment variable!)])

dnl Find libcurl and other libraries needed by hscurl.c

AC_ARG_WITH(libcurl,
            AS_HELP_STRING([--without-libcurl],[do not use libcurl]))

AC_ARG_WITH(curl, AS_HELP_STRING([--with-curl=<DIR>],[use curl installed in directory <DIR>]))

CURLLIBS=
CURL_CONFIG="curl-config"

if test "$with_libcurl" != "no"; then
 if test "$with_curl" != ""; then
   CURL_CONFIG="$with_curl/bin/curl-config"
 fi

 AC_MSG_CHECKING([for libcurl])
 if eval $CURL_CONFIG --version 2>/dev/null >/dev/null; then
   ver=`$CURL_CONFIG --version | sed -e "s/libcurl //g"`
   opt="--libs"
   CURLCFLAGS=`$CURL_CONFIG --cflags`
   if test "x$with_static_libs" = "xyes"; then
       CURLCFLAGS="$CURLFLAGS -DCURL_STATICLIB"
       opt="--static-libs"
   fi
   CURLLIBS=`$CURL_CONFIG $opt | sed "s_-arch @<:@^ @:>@@<:@^ @:>@*__"`
   AC_MSG_RESULT($ver)
 else
   AC_MSG_RESULT(FAILED)
   AC_MSG_WARN([curl-config was not found])
 fi
fi

if test "$CURLLIBS" != ""; then
    # we enable curl
    CPPFLAGS="$CPPFLAGS -DHAVE_CURL"

    CFLAGS="$CFLAGS $CURLCFLAGS"
    LIBS="$LIBS $CURLLIBS"
    old_LIBS="$LIBS"
    AC_CHECK_LIB(curl, curl_global_init,
                 [],
                 AC_MSG_ERROR(Cannot actually use libcurl; try specifying --without-libcurl.))
    AC_CHECK_LIB(curl, curl_multi_timeout,
                 CPPFLAGS="$CPPFLAGS -DCURL_MULTI_TIMEOUT")
    LIBS="$old_LIBS"

    # Check if we want pipelining enabled...
    AC_ARG_WITH(curl_pipelining,
            AS_HELP_STRING([--with-curl-pipelining],[use curl pipelining (requires libcurl >= 7.18.0)]))

    if test "$with_curl_pipelining" == "yes"; then
      AC_MSG_CHECKING([for libcurl pipelining])
      let vernum=0x0`$CURL_CONFIG --vernum`
      let minver=0x071200
      if test $vernum -ge $minver; then
        CPPFLAGS="$CPPFLAGS -DCURL_PIPELINING"
        CURL_PIPELINING=True
        AC_MSG_RESULT([yes])
      else
        AC_MSG_RESULT([no])
        AC_MSG_WARN([Requires libcurl version >= 7.18.0])
      fi
    fi

    # Check if we want curl debug enabled...
    AC_MSG_CHECKING([whether to do libcurl debugging])
    AC_ARG_ENABLE(curl-debug,
                  AS_HELP_STRING([--enable-curl-debug],[enable libcurl debug mode]),
                  curl_debug=$enableval, curl_debug=no)
    AC_MSG_RESULT($curl_debug)
    if test "$curl_debug" = "yes"; then
      CPPFLAGS="$CPPFLAGS -DCURL_DEBUG"
    fi
fi

dnl Find libwww and other libraries needed by hswww.c

AC_ARG_WITH(libwww,
            AS_HELP_STRING([--with-libwww],[use libwww]))

if test "$with_libwww" == "yes"; then
 AC_MSG_CHECKING([for libwww])
 if eval libwww-config --version 2>/dev/null >/dev/null; then
   CPPFLAGS="$CPPFLAGS -DHAVE_LIBWWW"
   WWWVERSION=`libwww-config --version`
   LIBS="$LIBS `libwww-config --libs`"
   CFLAGS="$CFLAGS `libwww-config --cflags`"
   AC_MSG_RESULT($WWWVERSION)

   # Check if we want libwww debug enabled...
   AC_MSG_CHECKING([whether to do libwww debugging])
   AC_ARG_ENABLE(libwww-debug,
                 AS_HELP_STRING([--enable-libwww-debug],[enable libwww debug mode]),
                 libwww_debug=$enableval, libwww_debug=no)
   AC_MSG_RESULT($libwww_debug)
   if test "$libwww_debug" = "yes"; then
     CPPFLAGS="$CPPFLAGS -DLIBWWW_DEBUG"
   fi
 else
   AC_MSG_RESULT(FAILED)
   AC_MSG_WARN([libwww-config was not found])
 fi
fi

dnl Check for libcurses...

AC_ARG_ENABLE(libcurses, [  --without-curses        do not use libcurses])

HAVE_CURSES=False
if test "$with_libcurses" != "no"; then
  # term.h is documented to require curses.h and actually needs it on
  # Solaris, for instance, though not on GNU/Linux.
  AC_CHECK_HEADER(term.h,
      [AC_SEARCH_LIBS(tgetent, [curses ncurses], [HAVE_CURSES=True])], ,
      [#include <curses.h>
      ])
  if test "$HAVE_CURSES" != "True"; then
    AC_MSG_WARN([Cannot find term.h, disabling color.])
  else
    # The precondition for this is: we both have curses available and not disabled
    CPPFLAGS="$CPPFLAGS -DHAVE_CURSES"
  fi
fi
AC_SUBST(HAVE_CURSES)

dnl Look for a suitable diff command

AC_CHECK_PROGS(DIFF, [gdiff gnudiff diff])

dnl Look for NullSoft Installer System

AC_PATH_PROGS(MAKENSIS, [makensis.exe])

dnl Check endianness

AC_C_BIGENDIAN([BIGENDIAN="True"],[BIGENDIAN="False"])
AC_SUBST(BIGENDIAN)

dnl Check for a haddock 2.0.0 or more recent

AC_CHECK_PROG(HADDOCK, haddock, haddock)
AC_MSG_CHECKING([haddock version])
if test "$HADDOCK" = ""; then
   HADDOCK_VERSION=0
else
   HADDOCK_VERSION=`haddock --version | head -n 1 | sed 's/^.* \(@<:@0-9@:>@@<:@0-9@:>@*\)\..*/\1/g'`
fi
AC_SUBST(HADDOCK_VERSION)
AC_MSG_RESULT(version $HADDOCK_VERSION)
if test "$HADDOCK_VERSION" -lt 2; then
   AC_MSG_WARN([You need haddock 2.0.0 or later to build API docs])
fi

dnl Write results

dnl Remove these two tests when autoconf >2.59 can be required.
if test -z "${datarootdir}"; then
   datarootdir=${datarootdir:-'${prefix}/share'}
   AC_SUBST(datarootdir)
fi
if test -z "${docdir}"; then
   docdir=${docdir:-'${datarootdir}/doc/${PACKAGE_TARNAME}'}
   AC_SUBST(docdir)
fi

AC_DEFUN([AC_DATAROOTDIR_CHECKED])
OUTPUT_WORKAROUND
AC_CONFIG_FILES([autoconf.mk src/Autoconf.lhs
           tools/cgi/darcs.cgi tools/cgi/README tools/cgi/cgi.conf
           darcs.buildinfo])
AC_OUTPUT

cat <<[EOF]

The build is configured as follows:

    bindir          = $bindir
    sbindir         = $sbindir
    mandir          = $mandir
    datadir         = $datadir
    sysconfdir      = $sysconfdir
    libexecdir      = $libexecdir

    Build Manual    = $BUILDDOC

If you want to adjust any of these values, edit autoconf.mk and
src/Autoconf.lhs -- or run configure with appropriate settings.

[EOF]

dnl Responsibility shifts to the user after this point.