1# This file is part of Autoconf. -*- Autoconf -*- 2# Go language support. 3# Copyright (C) 2011-2012 Free Software Foundation, Inc. 4 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. 10# 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. 15# 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. 19# 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 <http://www.gnu.org/licenses/>. 24 25# Go support contributed by Ian Lance Taylor. 26 27# This currently only supports gccgo, not 6g/8g/5g. 28 29# ------------------- # 30# Language selection. 31# ------------------- # 32 33# AC_LANG(Go) 34# ----------- 35AC_LANG_DEFINE([Go], [go], [GO], [GOC], [], 36[ac_ext=go 37ac_compile='$GOC -c $GOFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD' 38ac_link='$GOC -o conftest$ac_exeext $GOFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD' 39ac_compiler_gnu=yes 40]) 41 42# AC_LANG_GO 43# ---------- 44AU_DEFUN([AC_LANG_GO], [AC_LANG(Go)]) 45 46# ------------------- # 47# Producing programs. 48# ------------------- # 49 50# AC_LANG_PROGRAM(Go)([PROLOGUE], [BODY]) 51# --------------------------------------- 52m4_define([AC_LANG_PROGRAM(Go)], 53[package main 54$1 55func main() { 56$2 57}]) 58 59# _AC_LANG_IO_PROGRAM(Go) 60# ----------------------- 61# Produce source that performs I/O. 62m4_define([_AC_LANG_IO_PROGRAM(Go)], 63[AC_LANG_PROGRAM([import ( "fmt"; "os" )], 64[f, err := os.Open("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])]) 75 76# AC_LANG_CALL(Go)(PROLOGUE, FUNCTION) 77# ------------------------------------ 78# Avoid conflicting decl of main. 79m4_define([AC_LANG_CALL(Go)], 80[AC_LANG_PROGRAM([$1 81m4_if([$2], [main], , 82[func $2()])],[$2()])]) 83 84# AC_LANG_FUNC_LINK_TRY(Go)(FUNCTION) 85# ----------------------------------- 86# Try to link a program which calls FUNCTION. 87m4_define([AC_LANG_FUNC_LINK_TRY(Go)], 88[AC_LANG_PROGRAM( 89[func $1() int 90var f = $1 91], [return f()])]) 92 93# AC_LANG_BOOL_COMPILE_TRY(Go)(PROLOGUE, EXPRESSION) 94# -------------------------------------------------- 95# Return a program which is valid if EXPRESSION is nonzero. 96m4_define([AC_LANG_BOOL_COMPILE_TRY(Go)], 97[AC_LANG_PROGRAM([$1], [var test_array @<:@1 - 2 * !($2)@:>@int 98test_array @<:@0@:>@ = 0 99])]) 100 101# AC_LANG_INT_SAVE(Go)(PROLOGUE, EXPRESSION) 102# ------------------------------------------ 103m4_define([AC_LANG_INT_SAVE(Go)], 104[AC_LANG_PROGRAM([$1 105import ( 106 "fmt" 107 "os" 108) 109], 110[f, err := os.Open("conftest.val", os.O_CREATE|os.O_WRONLY, 0777) 111 if err != nil { 112 os.Exit(1) 113 } 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 } 130 } 131 if err = f.Close(); err != nil { 132 os.Exit(1) 133 } 134 os.Exit(0); 135])]) 136 137# ---------------------- # 138# Looking for compilers. # 139# ---------------------- # 140 141# AC_LANG_COMPILER(Go) 142# -------------------- 143AC_DEFUN([AC_LANG_COMPILER(Go)], 144[AC_REQUIRE([AC_PROG_GO])]) 145 146# AC_PROG_GO 147# ---------- 148AN_MAKEVAR([GOC], [AC_PROG_GO]) 149AN_PROGRAM([gccgo], [AC_PROG_GO]) 150AC_DEFUN([AC_PROG_GO], 151[AC_LANG_PUSH(Go)dnl 152AC_ARG_VAR([GOC], [Go compiler command])dnl 153AC_ARG_VAR([GOFLAGS], [Go compiler flags])dnl 154_AC_ARG_VAR_LDFLAGS()dnl 155m4_ifval([$1], 156 [AC_CHECK_TOOLS(GOC, [$1])], 157[AC_CHECK_TOOL(GOC, gccgo) 158if 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 162fi 163if test -z "$GOC"; then 164 AC_CHECK_PROG(GOC, gccgo, gccgo, , , false) 165fi 166]) 167 168# Provide some information about the compiler. 169_AS_ECHO_LOG([checking for _AC_LANG compiler version]) 170set X $ac_compile 171ac_compiler=$[2] 172_AC_DO_LIMIT([$ac_compiler --version >&AS_MESSAGE_LOG_FD]) 173m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl 174m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl 175GOFLAGS="-g -O2" 176AC_LANG_POP(Go)dnl 177])# AC_PROG_GO 178