Find git executable at run time
[git-darcs-import.git] / aclocal.m4
blobe677beb53d9bb01179dd8531076a7e431712a8ec
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])
9 # -----------
10 # Compile and link using ghc.
11 AC_DEFUN([TRY_COMPILE_GHC],[
12 cat << \EOF > conftest.hs
13 [$1]
14 -- this file generated by TRY-COMPILE-GHC
15 EOF
16 rm -f Main.hi Main.o
17 # Convert LDFLAGS and LIBS to the format GHC wants them in
18 GHCLDFLAGS=""
19 for f in $LDFLAGS ; do
20   GHCLDFLAGS="$GHCLDFLAGS -optl$f"
21 done
22 GHCLIBS=""
23 for l in $LIBS ; do
24   GHCLIBS="$GHCLIBS -optl$l"
25 done
26 if AC_TRY_COMMAND($GHC $GHCFLAGS $GHCLDFLAGS -o conftest conftest.hs $GHCLIBS) && test -s conftest
27 then
28 dnl Don't remove the temporary files here, so they can be examined.
29   ifelse([$2], , :, [$2])
30 else
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
35   $3
36 ])dnl
37 fi])
39 # TRY_RUN_GHC(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
40 # -----------
41 # Compile, link and run using ghc.
42 AC_DEFUN([TRY_RUN_GHC],[
43   TRY_COMPILE_GHC([$1],
44     AS_IF([AC_TRY_COMMAND(./conftest)],[$2],[$3]),
45     [$3])
48 # GHC_CHECK_ONE_MODULE(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
49 # -----------
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")
54                 ],[$3],[$4])
58 # GHC_CHECK_MODULE(MODULE, PACKAGE, CODE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
59 # -----------
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])
64 $4], [
65   check_module_save_GHCFLAGS=$GHCFLAGS
66   GHCFLAGS="$GHCFLAGS -package $2"
67   GHC_CHECK_ONE_MODULE([$1], [$3], [AC_MSG_RESULT([in package $2])
68 $4],[
69     GHCFLAGS=$check_module_save_GHCFLAGS
70     AC_MSG_RESULT(no; and neither in package $2)
71     $5])
72   ])
75 # GHC_COMPILE_FFI(IMPORT, TYPE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
76 # -----------
77 # Compile and link ffi code using ghc.
78 AC_DEFUN([GHC_COMPILE_FFI],[
79 TRY_COMPILE_GHC([{-# OPTIONS -fffi -Werror #-}
80 module Main where
82 foreign import ccall unsafe "$1" fun :: $2
84 main = fun `seq` putStrLn "hello world"
85 ],[$3],[$4])])
87 # GHC_CHECK_LIBRARY(LIBRARY, IMPORT, TYPE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
88 # -----------
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])
93 $4], [
94   check_library_save_LIBS=$LIBS
95   LIBS="$LIBS -l$1"
96   GHC_COMPILE_FFI([$2], [$3], [AC_MSG_RESULT([in -l$1])
97   $4],[
98     LIBS=$check_library_save_LIBS
99     AC_MSG_RESULT(no; and not with -l$1 either)
100     $5])
101   ])