1#
2# Minimal autoconf support for the D language.
3# Adapted from the Go language support files.
4#
5
6# ------------------- #
7# Language selection.
8# ------------------- #
9
10# AC_LANG(D)
11# -----------
12AC_LANG_DEFINE([D], [d], [GDC], [GDC], [],
13[ac_ext=d
14ac_compile='$GDC -c $GDCFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
15ac_link='$GDC -o conftest$ac_exeext $GDCFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
16ac_compiler_gnu=yes
17])
18
19# AC_LANG_D
20# ----------
21AU_DEFUN([AC_LANG_D], [AC_LANG(D)])
22
23# ------------------- #
24# Producing programs.
25# ------------------- #
26
27# AC_LANG_PROGRAM(D)([PROLOGUE], [BODY])
28# ---------------------------------------
29m4_define([AC_LANG_PROGRAM(D)],
30[module mod;
31$1
32
33extern(C) int main() {
34  $2
35}])
36
37# _AC_LANG_IO_PROGRAM(D)
38# -----------------------
39# Produce source that performs I/O.
40m4_define([_AC_LANG_IO_PROGRAM(D)],
41[AC_LANG_PROGRAM([import core.stdc.stdio;],
42[FILE *f = fopen ("conftest.out", "w");
43 return ferror (f) || fclose (f) != 0;
44])])
45
46# AC_LANG_CALL(D)(PROLOGUE, FUNCTION)
47# ------------------------------------
48# TODO: Avoid conflicting decl of main?
49# Used by AC_SEARCH_LIBS.
50m4_define([AC_LANG_CALL(D)],
51[AC_LANG_PROGRAM([$1 extern(C) int $2();], [$2(); return 0;])])
52
53# AC_LANG_FUNC_LINK_TRY(D)(FUNCTION)
54# -----------------------------------
55# Try to link a program which calls FUNCTION.
56# This only works for extern(C) functions.
57m4_define([AC_LANG_FUNC_LINK_TRY(D)],
58[AC_LANG_PROGRAM([extern(C) int $1();], [return $1();])])
59
60# AC_LANG_BOOL_COMPILE_TRY(D)(PROLOGUE, EXPRESSION)
61# --------------------------------------------------
62# Return a program which is valid if EXPRESSION is nonzero.
63# Probably not that useful for D, we can extract any information
64# we need using CTFE.
65m4_define([AC_LANG_BOOL_COMPILE_TRY(D)],
66[AC_LANG_PROGRAM([$1],
67[static assert($2); return 0;])])
68
69# AC_LANG_INT_SAVE(D)(PROLOGUE, EXPRESSION)
70# ------------------------------------------
71m4_define([AC_LANG_INT_SAVE(D)],
72[AC_LANG_PROGRAM([$1
73import core.stdc.stdio, core.stdc.stdlib;
74],
75[
76  FILE *f = fopen ("conftest.val", "w");
77  if (! f)
78    return 1;
79  if (($2) < 0)
80    {
81      fprintf (f, "%ld", $2);
82    }
83  else
84    {
85      fprintf (f, "%lu", $2);
86    }
87  /* Do not output a trailing newline, as this causes \r\n confusion
88     on some platforms.  */
89  return ferror (f) || fclose (f) != 0;
90])])
91
92# ---------------------- #
93# Looking for compilers. #
94# ---------------------- #
95
96# AC_LANG_COMPILER(D)
97# --------------------
98AC_DEFUN([AC_LANG_COMPILER(D)],
99[AC_REQUIRE([AC_PROG_GDC])])
100
101# AC_PROG_GDC
102# ----------
103AN_MAKEVAR([GDC], [AC_PROG_GDC])
104AN_PROGRAM([gdc], [AC_PROG_GDC])
105AC_DEFUN([AC_PROG_GDC],
106[AC_LANG_PUSH(D)dnl
107AC_ARG_VAR([GDC],     [D compiler command])dnl
108AC_ARG_VAR([GDCFLAGS],  [D compiler flags])dnl
109_AC_ARG_VAR_LDFLAGS()dnl
110m4_ifval([$1],
111      [AC_CHECK_TOOLS(GDC, [$1])],
112[AC_CHECK_TOOL(GDC, gdc)
113if test -z "$GDC"; then
114  if test -n "$ac_tool_prefix"; then
115    AC_CHECK_PROG(GDC, [${ac_tool_prefix}gdc], [$ac_tool_prefix}gdc])
116  fi
117fi
118if test -z "$GDC"; then
119  AC_CHECK_PROG(GDC, gdc, gdc, , , false)
120fi
121])
122
123# Provide some information about the compiler.
124_AS_ECHO_LOG([checking for _AC_LANG compiler version])
125set X $ac_compile
126ac_compiler=$[2]
127_AC_DO_LIMIT([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
128m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
129m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
130AC_LANG_POP(D)dnl
131])# AC_PROG_D
132
133