1dnl @synopsis AX_DMD
2dnl
3dnl Test for the presence of a DMD-compatible D2 compiler, and (optionally)
4dnl specified modules on the import path.
5dnl
6dnl If "DMD" is defined in the environment, that will be the only
7dnl dmd command tested. Otherwise, a hard-coded list will be used.
8dnl
9dnl After AX_DMD runs, the shell variables "success" and "ax_dmd" are set to
10dnl "yes" or "no", and "DMD" is set to the appropriate command. Furthermore,
11dnl "dmd_optlink" will be set to "yes" or "no" depending on whether OPTLINK is
12dnl used as the linker (DMD/Windows), and "dmd_of_dirsep" will be set to the
13dnl directory separator to use when passing -of to DMD (OPTLINK requires a
14dnl backslash).
15dnl
16dnl AX_CHECK_D_MODULE must be run after AX_DMD. It tests for the presence of a
17dnl module in the import path of the chosen compiler, and sets the shell
18dnl variable "success" to "yes" or "no".
19dnl
20dnl @category D
21dnl @version 2011-05-31
22dnl @license AllPermissive
23dnl
24dnl Copyright (C) 2009 David Reiss
25dnl Copyright (C) 2011 David Nadlinger
26dnl Copying and distribution of this file, with or without modification,
27dnl are permitted in any medium without royalty provided the copyright
28dnl notice and this notice are preserved.
29
30
31AC_DEFUN([AX_DMD],
32         [
33          dnl Hard-coded default commands to test.
34          DMD_PROGS="dmd,gdmd,ldmd"
35
36          dnl Allow the user to specify an alternative.
37          if test -n "$DMD" ; then
38            DMD_PROGS="$DMD"
39          fi
40
41          AC_MSG_CHECKING(for DMD)
42
43          # std.algorithm as a quick way to check for D2/Phobos.
44          echo "import std.algorithm; void main() {}" > configtest_ax_dmd.d
45          success=no
46          oIFS="$IFS"
47
48          IFS=","
49          for DMD in $DMD_PROGS ; do
50            IFS="$oIFS"
51
52            echo "Running \"$DMD configtest_ax_dmd.d\"" >&AS_MESSAGE_LOG_FD
53            if $DMD configtest_ax_dmd.d >&AS_MESSAGE_LOG_FD 2>&1 ; then
54              success=yes
55              break
56            fi
57          done
58
59          if test "$success" != "yes" ; then
60            AC_MSG_RESULT(no)
61            DMD=""
62          else
63            AC_MSG_RESULT(yes)
64          fi
65
66          ax_dmd="$success"
67
68          # Test whether OPTLINK is used by trying if DMD accepts -L/? without
69          # erroring out.
70          if test "$success" == "yes" ; then
71            AC_MSG_CHECKING(whether DMD uses OPTLINK)
72            echo "Running \”$DMD -L/? configtest_ax_dmd.d\"" >&AS_MESSAGE_LOG_FD
73            if $DMD -L/? configtest_ax_dmd.d >&AS_MESSAGE_LOG_FD 2>&1 ; then
74              AC_MSG_RESULT(yes)
75              dmd_optlink="yes"
76
77              # This actually produces double slashes in the final configure
78              # output, but at least it works.
79              dmd_of_dirsep="\\\\"
80            else
81              AC_MSG_RESULT(no)
82              dmd_optlink="no"
83              dmd_of_dirsep="/"
84            fi
85          fi
86
87          rm -f configtest_ax_dmd*
88         ])
89
90
91AC_DEFUN([AX_CHECK_D_MODULE],
92         [
93          AC_MSG_CHECKING(for D module [$1])
94
95          echo "import $1; void main() {}" > configtest_ax_dmd.d
96
97          echo "Running \"$DMD configtest_ax_dmd.d\"" >&AS_MESSAGE_LOG_FD
98          if $DMD -c configtest_ax_dmd.d >&AS_MESSAGE_LOG_FD 2>&1 ; then
99            AC_MSG_RESULT(yes)
100            success=yes
101          else
102            AC_MSG_RESULT(no)
103            success=no
104          fi
105
106          rm -f configtest_ax_dmd*
107         ])
108