Prefer HTTPS to FTP and HTTP
[autoconf.git] / lib / autoconf / go.m4
blob36c4ef35f38770ab9c59b1f269153f8bdbf712cc
1 # This file is part of Autoconf.                       -*- Autoconf -*-
2 # Go language support.
3 # Copyright (C) 2011-2017 Free Software Foundation, Inc.
5 # This file is part of Autoconf.  This program is free
6 # software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the
8 # Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # Under Section 7 of GPL version 3, you are granted additional
17 # permissions described in the Autoconf Configure Script Exception,
18 # version 3.0, as published by the Free Software Foundation.
20 # You should have received a copy of the GNU General Public License
21 # and a copy of the Autoconf Configure Script Exception along with
22 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
23 # respectively.  If not, see <https://www.gnu.org/licenses/>.
25 # Go support contributed by Ian Lance Taylor.
27 # This currently only supports gccgo, not 6g/8g/5g.
29 # ------------------- #
30 # Language selection.
31 # ------------------- #
33 # AC_LANG(Go)
34 # -----------
35 AC_LANG_DEFINE([Go], [go], [GO], [GOC], [],
36 [ac_ext=go
37 ac_compile='$GOC -c $GOFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
38 ac_link='$GOC -o conftest$ac_exeext $GOFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
39 ac_compiler_gnu=yes
42 # AC_LANG_GO
43 # ----------
44 AU_DEFUN([AC_LANG_GO], [AC_LANG(Go)])
46 # ------------------- #
47 # Producing programs.
48 # ------------------- #
50 # AC_LANG_PROGRAM(Go)([PROLOGUE], [BODY])
51 # ---------------------------------------
52 m4_define([AC_LANG_PROGRAM(Go)],
53 [package main
55 func main() {
57 }])
59 # _AC_LANG_IO_PROGRAM(Go)
60 # -----------------------
61 # Produce source that performs I/O.
62 m4_define([_AC_LANG_IO_PROGRAM(Go)],
63 [AC_LANG_PROGRAM([import ( "fmt"; "os" )],
64 [f, err := os.OpenFile("conftest.out", os.O_CREATE|os.O_WRONLY, 0777)
65  if err != nil {
66         fmt.Println(err)
67         os.Exit(1)
68  }
69  if err = f.Close(); err != nil {
70         fmt.Println(err)
71         os.Exit(1)
72  }
73  os.Exit(0)
74 ])])
76 # AC_LANG_CALL(Go)(PROLOGUE, FUNCTION)
77 # ------------------------------------
78 # Avoid conflicting decl of main.
79 m4_define([AC_LANG_CALL(Go)],
80 [AC_LANG_PROGRAM([$1
81 m4_if([$2], [main], ,
82 [func $2()])],[$2()])])
84 # AC_LANG_FUNC_LINK_TRY(Go)(FUNCTION)
85 # -----------------------------------
86 # Try to link a program which calls FUNCTION.
87 m4_define([AC_LANG_FUNC_LINK_TRY(Go)],
88 [AC_LANG_PROGRAM(
89 [func $1() int
90 var f = $1
91 ], [return f()])])
93 # AC_LANG_BOOL_COMPILE_TRY(Go)(PROLOGUE, EXPRESSION)
94 # --------------------------------------------------
95 # Return a program which is valid if EXPRESSION is nonzero.
96 m4_define([AC_LANG_BOOL_COMPILE_TRY(Go)],
97 [AC_LANG_PROGRAM([$1], [var test_array @<:@1 - 2 * !($2)@:>@int
98 test_array @<:@0@:>@ = 0
99 ])])
101 # AC_LANG_INT_SAVE(Go)(PROLOGUE, EXPRESSION)
102 # ------------------------------------------
103 m4_define([AC_LANG_INT_SAVE(Go)],
104 [AC_LANG_PROGRAM([$1
105 import (
106         "fmt"
107         "os"
110 [f, err := os.OpenFile("conftest.val", os.O_CREATE|os.O_WRONLY, 0777)
111  if err != nil {
112         os.Exit(1)
114  if $2 < 0 {
115         int64 i = int64($2)
116         if i != $2 {
117                 os.Exit(1)
118         }
119         if _, err := fmt.Print(f, i); err != nil {
120                 os.Exit(1)
121         }
122  } else {
123         uint64 i = uint64($2)
124         if i != $2 {
125                 os.Exit(1)
126         }
127         if _, err := fmt.Print(f, i); err != nil {
128                 os.Exit(1)
129         }
131  if err = f.Close(); err != nil {
132         os.Exit(1)
134  os.Exit(0);
135 ])])
137 # ---------------------- #
138 # Looking for compilers. #
139 # ---------------------- #
141 # AC_LANG_COMPILER(Go)
142 # --------------------
143 AC_DEFUN([AC_LANG_COMPILER(Go)],
144 [AC_REQUIRE([AC_PROG_GO])])
146 # AC_PROG_GO
147 # ----------
148 AN_MAKEVAR([GOC], [AC_PROG_GO])
149 AN_PROGRAM([gccgo], [AC_PROG_GO])
150 AC_DEFUN([AC_PROG_GO],
151 [AC_LANG_PUSH(Go)dnl
152 AC_ARG_VAR([GOC],   [Go compiler command])dnl
153 AC_ARG_VAR([GOFLAGS], [Go compiler flags])dnl
154 _AC_ARG_VAR_LDFLAGS()dnl
155 m4_ifval([$1],
156       [AC_CHECK_TOOLS(GOC, [$1])],
157 [AC_CHECK_TOOL(GOC, gccgo)
158 if test -z "$GOC"; then
159   if test -n "$ac_tool_prefix"; then
160     AC_CHECK_PROG(GOC, [${ac_tool_prefix}gccgo], [$ac_tool_prefix}gccgo])
161   fi
163 if test -z "$GOC"; then
164   AC_CHECK_PROG(GOC, gccgo, gccgo, , , false)
168 # Provide some information about the compiler.
169 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
170 set X $ac_compile
171 ac_compiler=$[2]
172 _AC_DO_LIMIT([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
173 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
174 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
175 GOFLAGS="-g -O2"
176 AC_LANG_POP(Go)dnl
177 ])# AC_PROG_GO