go.m4 4.5 KB

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