When I tried to build libgo on Solaris 9/x86 with native tools, I ran
into a couple of issues:

* To correctly build sysinfo.go, one needs a different set of flags to
  compile sysinfo.c that conflict with the onces needed on Solaris 10+.
  Since there seems to be no easy way to autoconf this knowledge, I'm
  hardcoding it in configure.ac (OSCFLAGS) and pass it to mksysinfo.sh.

* As documented in the Autoconf manual, the native grep cannot handle
  \|.  One needs to use egrep for that instead.  I've only updated the
  affected invocations, but one may want (or need) to either do this
  wholesale and/or replace the hardcoded egrep by autoconfed $EGREP.

* Similarly, native sed cannot handle \?, so I'm substituting both
  alternatives in sequence.

* For native TLS to work, libgo needs to be linked with -pthread, so
  libthread.so is included in the link.  On Solaris 8, -pthread takes
  care of even more contortions necessary to get the proper thread
  library.  In order for that to happen, I've introduced
  libgo_la_LDFLAGS.

With those changes (and the strerror_r replacement since Solaris 8 and 9
also lack that function), I could successfully build and test libgo,
with relatively decent results:

FAIL: fmt
Can't open -n
grep: can't open -n
grep: can't open -n
mallocs per Sprintf(""): 1
mallocs per Sprintf("xxx"): 1
mallocs per Sprintf("%x"): 3
mallocs per Sprintf("%x %x"): 4
/vol/gcc/src/hg/trunk/local/libgo/testsuite/gotest[325]: 22734 Segmentation 
Fault
make: *** [fmt/check] Error 1

FAIL: archive/zip
Can't open -n
grep: can't open -n
grep: can't open -n
--- FAIL: zip.TestReader (0.0 seconds)
        error=open testdata/dd.zip: No such file or directory, want <nil>
FAIL
make: *** [archive/zip/check] Error 1

FAIL: crypto/rand
Can't open -n
grep: can't open -n
grep: can't open -n
--- FAIL: rand.TestRead (0.0 seconds)
        Read(buf) = 1040, %!s(<nil>)
FAIL
make: *** [crypto/rand/check] Error 1

FAIL: image/png
Can't open -n
grep: can't open -n
grep: can't open -n
--- FAIL: png.TestReader (1.0 seconds)
        basn0g01-30 open testdata/pngsuite/basn0g01-30.png: No such file or 
directory
        basn0g02-29 open testdata/pngsuite/basn0g02-29.png: No such file or 
directory
        basn0g04-31 open testdata/pngsuite/basn0g04-31.png: No such file or 
directory
--- FAIL: png.TestWriter (0.2 seconds)
        basn0g01-30 open testdata/pngsuite/basn0g01-30.png: No such file or 
directory
        basn0g02-29 open testdata/pngsuite/basn0g02-29.png: No such file or 
directory
        basn0g04-31 open testdata/pngsuite/basn0g04-31.png: No such file or 
directory
FAIL
make: *** [image/png/check] Error 1

I'll be running make check-go shortly.

        Rainer


2011-03-24  Rainer Orth  <r...@cebitec.uni-bielefeld.de>

        * configure.ac (OSCFLAGS): Define.
        * Makefile.am (s-sysinfo): Use it.
        (libgo_la_LDFLAGS): Define.
        * mksysinfo.sh (sysinfo.c) [__sun__ && __svr4__]: Remove.
        Replace \| in grep REs with egrep and |.
        Replace \? in sed REs with two variants.
        * Makefile.in: Regenerate.
        * configure: Regenerate.

diff -r 75d0e839ffe1 libgo/Makefile.am
--- a/libgo/Makefile.am Thu Mar 24 13:22:54 2011 +0100
+++ b/libgo/Makefile.am Thu Mar 24 16:45:53 2011 +0100
@@ -1459,6 +1459,8 @@
 
 libgo_la_SOURCES = $(runtime_files)
 
+libgo_la_LDFLAGS = $(PTHREAD_CFLAGS)
+
 libgo_la_LIBADD = \
        $(libgo_go_objs) $(LIBFFI) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS)
 
@@ -2512,7 +2514,7 @@
 
 sysinfo.go: s-sysinfo; @true
 s-sysinfo: $(srcdir)/mksysinfo.sh config.h
-       CC="$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) 
$(CPPFLAGS)" $(SHELL) $(srcdir)/mksysinfo.sh
+       CC="$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) 
$(CPPFLAGS) $(OSCFLAGS)" $(SHELL) $(srcdir)/mksysinfo.sh
        $(SHELL) $(srcdir)/../move-if-change tmp-sysinfo.go sysinfo.go
        $(STAMP) $@
 
diff -r 75d0e839ffe1 libgo/configure.ac
--- a/libgo/configure.ac        Thu Mar 24 13:22:54 2011 +0100
+++ b/libgo/configure.ac        Thu Mar 24 16:45:53 2011 +0100
@@ -229,6 +229,22 @@
 fi
 AC_SUBST(GO_DEBUG_PROC_REGS_OS_ARCH_FILE)
 
+dnl Some targets need special flags to build sysinfo.go.
+case "$target" in
+    *-*-solaris2.[[89]])
+       # Solaris 8/9 need this so struct msghdr gets the msg_control
+       # etc. fields in <sys/socket.h> (_XPG4_2).
+       OSCFLAGS='-D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D__EXTENSIONS__'
+       ;;
+    *-*-solaris2.1[[01]])
+       # Solaris 10+ needs this so struct msghdr gets the msg_control
+       # etc. fields in <sys/socket.h> (_XPG4_2).  _XOPEN_SOURCE=500 as
+       # above doesn't work with C99.
+       OSCFLAGS='-D_XOPEN_SOURCE=600 -D__EXTENSIONS__'
+       ;;
+esac
+AC_SUBST(OSCFLAGS)
+
 dnl Use -fsplit-stack when compiling C code if available.
 AC_CACHE_CHECK([whether -fsplit-stack is supported],
 [libgo_cv_c_split_stack_supported],
diff -r 75d0e839ffe1 libgo/mksysinfo.sh
--- a/libgo/mksysinfo.sh        Thu Mar 24 13:22:54 2011 +0100
+++ b/libgo/mksysinfo.sh        Thu Mar 24 16:45:53 2011 +0100
@@ -29,12 +29,6 @@
 #define _LARGEFILE_SOURCE
 #define _FILE_OFFSET_BITS 64
 
-#if defined(__sun__) && defined(__svr4__)
-/* Needed by Solaris header files.  */
-#define _XOPEN_SOURCE 600
-#define __EXTENSIONS__
-#endif
-
 #include <sys/types.h>
 #include <dirent.h>
 #include <errno.h>
@@ -96,7 +90,7 @@
   sed -e 's/^\(const \)_\(E[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
 
 # The O_xxx flags.
-grep '^const _\(O\|F\|FD\)_' gen-sysinfo.go | \
+egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
   sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
   echo "const O_ASYNC = 0" >> ${OUT}
@@ -139,7 +133,7 @@
 fi
 
 # Networking constants.
-grep '^const _\(AF\|SOCK\|SOL\|SO\|IPPROTO\|TCP\|IP\|IPV6\)_' gen-sysinfo.go |
+egrep '^const _(AF|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
   sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
 grep '^const _SOMAXCONN' gen-sysinfo.go |
   sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
@@ -318,7 +312,8 @@
   grep '^type _stat64 ' gen-sysinfo.go
 else
   grep '^type _stat ' gen-sysinfo.go
-fi | sed -e 's/type _stat\(64\)\?/type Stat_t/' \
+fi | sed -e 's/type _stat64/type Stat_t/' \
+         -e 's/type _stat/type Stat_t/' \
          -e 's/st_dev/Dev/' \
          -e 's/st_ino/Ino/g' \
          -e 's/st_nlink/Nlink/' \
@@ -344,7 +339,8 @@
   grep '^type _dirent64 ' gen-sysinfo.go
 else
   grep '^type _dirent ' gen-sysinfo.go
-fi | sed -e 's/type _dirent\(64\)\?/type Dirent/' \
+fi | sed -e 's/type _dirent64/type Dirent/' \
+         -e 's/type _dirent/type Dirent/' \
          -e 's/d_name \[0+1\]/d_name [0+256]/' \
          -e 's/d_name/Name/' \
          -e 's/]int8/]byte/' \

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

Reply via email to