1 # Copyright 2005,2008 David Roundy
4 # Redistribution and use in source and binary forms of this file, with or
5 # without modification, are permitted provided that redistributions of
6 # source code must retain the above copyright notice.
8 # TRY_COMPILE_GHC(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
10 # Compile and link using ghc.
11 AC_DEFUN([TRY_COMPILE_GHC],[
12 cat << \EOF > conftest.hs
14 -- this file generated by TRY-COMPILE-GHC
17 # Convert LDFLAGS and LIBS to the format GHC wants them in
19 for f in $LDFLAGS ; do
20 GHCLDFLAGS="$GHCLDFLAGS -optl$f"
24 GHCLIBS="$GHCLIBS -optl$l"
26 if AC_TRY_COMMAND($GHC $GHCFLAGS $GHCLDFLAGS -o conftest conftest.hs $GHCLIBS) && test -s conftest
28 dnl Don't remove the temporary files here, so they can be examined.
29 ifelse([$2], , :, [$2])
31 echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD
32 cat conftest.hs >&AS_MESSAGE_LOG_FD
33 echo "end of failed program." >&AS_MESSAGE_LOG_FD
34 ifelse([$3], , , [ rm -f Main.hi Main.o
39 # TRY_RUN_GHC(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
41 # Compile, link and run using ghc.
42 AC_DEFUN([TRY_RUN_GHC],[
44 AS_IF([AC_TRY_COMMAND(./conftest)],[$2],[$3]),
48 # GHC_CHECK_ONE_MODULE(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
50 # Compile and link using ghc.
51 AC_DEFUN([GHC_CHECK_ONE_MODULE],[
52 TRY_COMPILE_GHC([import $1
53 main = seq ($2) (putStr "Hello world.\n")
58 # GHC_CHECK_MODULE(MODULE, PACKAGE, CODE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
60 # Compile and link using ghc.
61 AC_DEFUN([GHC_CHECK_MODULE],[
62 AC_MSG_CHECKING([for module $1])
63 GHC_CHECK_ONE_MODULE([$1], [$3], [AC_MSG_RESULT([yes])
65 check_module_save_GHCFLAGS=$GHCFLAGS
66 GHCFLAGS="$GHCFLAGS -package $2"
67 GHC_CHECK_ONE_MODULE([$1], [$3], [AC_MSG_RESULT([in package $2])
69 GHCFLAGS=$check_module_save_GHCFLAGS
70 AC_MSG_RESULT(no; and neither in package $2)
75 # GHC_COMPILE_FFI(IMPORT, TYPE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
77 # Compile and link ffi code using ghc.
78 AC_DEFUN([GHC_COMPILE_FFI],[
79 TRY_COMPILE_GHC([{-# OPTIONS -fffi -Werror #-}
82 foreign import ccall unsafe "$1" fun :: $2
84 main = fun `seq` putStrLn "hello world"
87 # GHC_CHECK_LIBRARY(LIBRARY, IMPORT, TYPE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
89 # Compile and link with C library using ghc.
90 AC_DEFUN([GHC_CHECK_LIBRARY],[
91 AC_MSG_CHECKING([for library $1])
92 GHC_COMPILE_FFI([$2], [$3], [AC_MSG_RESULT([yes])
94 check_library_save_LIBS=$LIBS
96 GHC_COMPILE_FFI([$2], [$3], [AC_MSG_RESULT([in -l$1])
98 LIBS=$check_library_save_LIBS
99 AC_MSG_RESULT(no; and not with -l$1 either)