[darcs-users] [darcs-devel] darcs patch: Use GHC instead of GCC to check for zlib availability ...

David Roundy droundy at darcs.net
Wed Apr 30 23:05:52 UTC 2008


On Thu, May 01, 2008 at 12:02:08AM +0200, Reinier Lamers wrote:
> Thu May  1 00:01:05 CEST 2008  tux_rocker at reinier.de
>   * Use GHC instead of GCC to check for zlib availability (issue 813)

This looks like a nice attempt, but I'd like to see an even nicer
version that defines an autoconf macro to do this sort of test...

Content-Description: A darcs patch for your repository!
> 
> New patches:
> 
> [Use GHC instead of GCC to check for zlib availability (issue 813)
> tux_rocker at reinier.de**20080430220105] hunk ./configure.ac 410
> +dnl look for zlib library and header.
> +dnl Use TRY_COMPILE_GHC 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)
> +
> +OLDGHCFLAGS="$GHCFLAGS"
> +dnl Force compilation via C to detect missing headers
> +GHCFLAGS="$GHCFLAGS -lz -fvia-C"
> +AC_MSG_CHECKING([for zlib])
> +TRY_COMPILE_GHC([{-# INCLUDE <zlib.h> #-}
> +{-# OPTIONS_GHC -fglasgow-exts #-}
> +module Main where 
> +import Foreign
> +import Foreign.C
> +import Foreign.Ptr
> +
> +foreign import ccall unsafe "zlib.h deflate" zlib_deflate :: Ptr () -> CInt -> CInt

We should be able to simplify the function, since ghc never checks the
correctness of the type of foreign code.  So we ought to be able to get by
with something like

foreign import ccall unsafe "zlib.h deflate" foo :: Ptr ()

which would mean we could omit some of the imports, and we could write a
macro that could be called like

TRY_LIBRARY_GHC([z],[zlib.h],[deflate])

If we had a macro like this, we could use it to test for all the C
libraries we link with!

> +main = zlib_deflate nullPtr 0 `seq` putStrLn "hello world"
> +], LIBS="$LIBS -lz", [AC_MSG_ERROR(Cannot find system's zlib library; please set the LDFLAGS environment variable!)])
> +GHCFLAGS="$OLDGHCFLAGS"
> +AC_MSG_RESULT([yes])
> +
> hunk ./configure.ac 532
> -dnl look for zlib library and header.
> -
> -AC_CHECK_HEADER(zlib.h, :,
> -    AC_MSG_ERROR([Cannot find zlib.h; please set the CPPFLAGS environment variable!]))
> -AC_CHECK_LIB(z, gzopen, LIBS="$LIBS -lz",
> -    [
> -    AC_MSG_ERROR(Cannot find system's zlib library; please set the LDFLAGS environment variable!)
> -    ])
> -

I guess really it's not so much that there's a problem with this patch, but
that I can't help but think this could be done more nicely.

David


More information about the darcs-users mailing list