On Thu, Jan 15, 2015 at 8:30 AM, Rainer Orth
<r...@cebitec.uni-bielefeld.de> wrote:
>
> Apart from that, bootstrap fails in gotools: due to the use of
> -static-libgo, all commands there fail to link since the socket
> functions are missing.  It seems like $LIBS from libgo needs to be added
> somewhere, but I'm unsure how best to handle this.  To make any progress
> at all, I've just manually added -lsocket -lnsl to gotools/Makefile
> (AM_LDFLAGS).

I also don't know what the best way is to handle this.  For now I've
just added a configure test to check whether the libraries are needed.
Based on the libgo build, as far as I can tell, no other libraries
should be needed.

Ian


2015-01-15  Ian Lance Taylor  <i...@google.com>

        * configure.ac: Check for networking libraries; see NET_LIBS.
        * Makefile.am (go$(EXEEXT)): Link against NET_LIBS.
        (gofmt$(EXEEXT), cgo$(EXEEXT)): Likewise.
        * configure, Makefile.in: Rebuild.
Index: Makefile.am
===================================================================
--- Makefile.am (revision 219627)
+++ Makefile.am (working copy)
@@ -108,11 +108,11 @@ bin_PROGRAMS = go$(EXEEXT) gofmt$(EXEEXT
 libexecsub_PROGRAMS = cgo$(EXEEXT)
 
 go$(EXEEXT): $(go_cmd_go_files) zdefaultcc.go $(LIBGODEP)
-       $(GOLINK) $(go_cmd_go_files) zdefaultcc.go
+       $(GOLINK) $(go_cmd_go_files) zdefaultcc.go $(NET_LIBS)
 gofmt$(EXEEXT): $(go_cmd_gofmt_files) $(LIBGODEP)
-       $(GOLINK) $(go_cmd_gofmt_files)
+       $(GOLINK) $(go_cmd_gofmt_files) $(NET_LIBS)
 cgo$(EXEEXT): $(go_cmd_cgo_files) zdefaultcc.go $(LIBGODEP)
-       $(GOLINK) $(go_cmd_cgo_files) zdefaultcc.go
+       $(GOLINK) $(go_cmd_cgo_files) zdefaultcc.go $(NET_LIBS)
 
 else
 
Index: configure.ac
===================================================================
--- configure.ac        (revision 219408)
+++ configure.ac        (working copy)
@@ -48,6 +48,37 @@ AC_PROG_GO
 
 AM_CONDITIONAL(NATIVE, test "$cross_compiling" = no)
 
+dnl Test for -lsocket and -lnsl.  Copied from libjava/configure.ac.
+AC_CACHE_CHECK([for socket libraries], gotools_cv_lib_sockets,
+  [gotools_cv_lib_sockets=
+   gotools_check_both=no
+   AC_CHECK_FUNC(connect, gotools_check_socket=no, gotools_check_socket=yes)
+   if test "$gotools_check_socket" = "yes"; then
+     unset ac_cv_func_connect
+     AC_CHECK_LIB(socket, main, gotools_cv_lib_sockets="-lsocket",
+                 gotools_check_both=yes)
+   fi
+   if test "$gotools_check_both" = "yes"; then
+     gotools_old_libs=$LIBS
+     LIBS="$LIBS -lsocket -lnsl"
+     unset ac_cv_func_accept
+     AC_CHECK_FUNC(accept,
+                  [gotools_check_nsl=no
+                   gotools_cv_lib_sockets="-lsocket -lnsl"])
+     unset ac_cv_func_accept
+     LIBS=$gotools_old_libs
+   fi
+   unset ac_cv_func_gethostbyname
+   gotools_old_libs="$LIBS"
+   AC_CHECK_FUNC(gethostbyname, ,
+                [AC_CHECK_LIB(nsl, main,
+                       [gotools_cv_lib_sockets="$gotools_cv_lib_sockets 
-lnsl"])])
+   unset ac_cv_func_gethostbyname
+   LIBS=$gotools_old_libs
+])
+NET_LIBS="$gotools_cv_lib_sockets"
+AC_SUBST(NET_LIBS)
+
 AC_CONFIG_FILES(Makefile)
 
 AC_OUTPUT

Reply via email to