From ec2e6d6d8cd0aec0a90ab3a6488b8f8d90316084 Mon Sep 17 00:00:00 2001
From: Luigi Scarso <luigi.scarso@gmail.com>
Date: Sat, 7 May 2016 18:46:20 +0000
Subject: [PATCH] sinc with TeXLive revision 40931 (trunk).

---
 source/doc/README.solaris       | 132 +++++++++++++++++++++++++++++++-
 source/texk/web2c/lib/ChangeLog |   7 +-
 source/texk/web2c/lib/texmfmp.c |   4 +
 3 files changed, 139 insertions(+), 4 deletions(-)

diff --git a/source/doc/README.solaris b/source/doc/README.solaris
index 713be511c..9a96a2064 100644
--- a/source/doc/README.solaris
+++ b/source/doc/README.solaris
@@ -2,9 +2,6 @@
 
 Compiling TeX binaries on Solaris
 
-(The document describes the procedures used on Sparc Solaris binaries,
-but the same rules should apply to i386 and x86_64 as well.)
-
 Solaris 9 has been out of official support for a while and making
 software compile on that platform is challenging, so it hardly makes any
 sense to try to support it.
@@ -41,6 +38,14 @@ You can check the libc version with
         SUNW_0.8;
         SUNW_0.7;
 
+Building for 64-bit
+===================
+
+All binaries have been compiled with gcc-5.2.
+The only thing that is needed to build for 64-bit is to define
+    export CC="/path/to/gcc-5.2 -m64"
+    export CXX="/path/to/g++-5.2 -m64"
+
 Building wget
 =============
 
@@ -71,6 +76,9 @@ The binary was built with gcc 5.2.
 The definition '#define _XOPEN_SOURCE 500' has been removed from 'src/sysdep.h'
 to avoid compile error due to the fact that GCC 5 switched to -std=99. 
 
+On i386 and x86_64 one has to manually add "-lsocket -lnsl" to the last linker command.
+This should be reported upstream.
+
 > pvs Master/tlpkg/installer/wget/wget.sparc-solaris
     libsocket.so.1 (SUNW_1.4);
     libnsl.so.1 (SUNW_1.7);
@@ -108,6 +116,67 @@ libc.so - SUNW_1.22 SUNWprivate_1.1 $ADDVERS=SUNW_1.22;
 If users need binaries to run on even older systems, we can target what
 is desired by changing the map file.
 
+Building asymptote
+==================
+
+Asymptote has been built with the following flags:
+
+export CC=/opt/csw/bin/gcc-5.2
+export CXX=/opt/csw/bin/g++-5.2
+./configure --prefix=/tmp/asyinst --enable-texlive-build \
+    --disable-fftw --disable-offscreen \
+    --disable-gl --disable-gsl --disable-readline
+
+Even though GL, GSL and readline should generally not be disabled,
+the resulting binaries would not be portable enough otherwise.
+
+Because a newer gcc compiler was used we had to link statically against stdlib.
+In the last command that builds the asy binary the following part:
+    -lnsl -lrt -lz -lm gc-7.4.2/.libs/libgc.a
+was replaced by:
+    gc-7.4.2/.libs/libgc.a -nodefaultlibs -Wl,-Bstatic -lstdc++ \
+    -Wl,-Bdynamic -lnsl -lrt -lz -lm -lgcc_eh -lgcc -lc
+
+The resulting binary depends on:
+
+> pvs asy
+    libnsl.so.1 (SUNW_0.7);
+    librt.so.1 (SUNW_1.2);
+    libm.so.2 (SUNW_1.2);
+    libc.so.1 (SUNW_1.22, SUNWprivate_1.1);
+> ldd asy
+    libnsl.so.1 =>   /lib/libnsl.so.1
+    librt.so.1 =>    /lib/librt.so.1
+    libz.so.1 =>     /usr/lib/libz.so.1
+    libm.so.2 =>     /lib/libm.so.2
+    libc.so.1 =>     /lib/libc.so.1
+    libmp.so.2 =>    /lib/libmp.so.2
+    libmd.so.1 =>    /lib/libmd.so.1
+    libscf.so.1 =>   /lib/libscf.so.1
+    libaio.so.1 =>   /lib/libaio.so.1
+    libdoor.so.1 =>  /lib/libdoor.so.1
+    libuutil.so.1 => /lib/libuutil.so.1
+    libgen.so.1 =>   /lib/libgen.so.1
+
+Additional notes:
+
+* gc-7.4.2 doesn't support sparc properly, so the sources for sparc were fetched from
+  https://github.com/ivmai/bdwgc/tree/release-7_4
+  and put into gc-7.4.2
+  Running ./autogen.sh was needed before proceeding
+
+* Workarounds were needed for:
+  * https://github.com/vectorgraphics/asymptote/issues/19
+    CC and CXX env variables are not respected when building GC
+  * https://github.com/vectorgraphics/asymptote/issues/20
+    Provide a configure-time option to disable sigsegv
+  * https://github.com/vectorgraphics/asymptote/pull/21
+    Makefile.in: replace 'test ! -e' => 'test ! -s'
+  * https://github.com/vectorgraphics/asymptote/issues/22
+    Wrong expansion of revision in Bourne Shell
+
+* Patches used are listed below.
+
 Building texlive
 ================
 
@@ -117,3 +186,60 @@ Additional settings were needed to compile TeX Live with gcc 5.2:
 The '--without-iconv' makes sure to avoid linking against libiconv
 which is not available on SunOS by default.
 
+
+
+Patches for Asymptote
+=====================
+
+--- Makefile.in (revision 40918)
++++ Makefile.in (working copy)
+@@ -114,7 +114,7 @@
+        fi
+ 
+ version: $(GCLIB) $(FILES:=.o)
+-       if test ! -e revision.cc -o "$(revision)" != "$(last)"; then     \
++       if test ! -s revision.cc -o "$(revision)" != "$(last)"; then     \
+          echo $(REVISION)\"$(revision)\"\; > revision.cc; \
+        fi
+        $(CXX) $(OPTS) $(INCL) -o revision.o -c revision.cc;
+@@ -160,7 +160,7 @@
+          mv gc-7.2 gc-7.2d; \
+        fi
+        cd $(GC) && \
+-       ./configure $(GCOPTIONS); \
++       ./configure CC="$(CC)" CXX="$(CXX)" $(GCOPTIONS); \
+        $(MAKE) check
+
+ $(GCPPLIB): $(GCLIB)
+--- configure.ac        (revision 40918)
++++ configure.ac        (working copy)
+@@ -223,15 +223,15 @@
+ AC_SUBST(OPTIONS)
+ 
+ # Checks for libraries.
+-AC_CHECK_LIB([ncurses], [setupterm], [AC_DEFINE(HAVE_LIBCURSES)
+-                        LIBS=$LIBS"-lncurses "],
+-                        AC_CHECK_LIB([curses], [setupterm]))
++#AC_CHECK_LIB([ncurses], [setupterm], [AC_DEFINE(HAVE_LIBCURSES)
++#                       LIBS=$LIBS"-lncurses "],
++#                       AC_CHECK_LIB([curses], [setupterm]))
+ AC_CHECK_LIB([m], [sqrt],,
+ AC_MSG_ERROR([*** Please install libm on your system ***]))
+ AC_CHECK_LIB([z], [deflate],,
+ AC_MSG_ERROR([*** Please install libz or zlib-devel on your system ***]))
+ AX_PTHREAD
+-AC_CHECK_LIB([sigsegv], [stackoverflow_install_handler])
++#AC_CHECK_LIB([sigsegv], [stackoverflow_install_handler])
+ AC_CHECK_LIB([rt], [sched_yield])
+ 
+ AC_ARG_ENABLE(readline,
+@@ -254,7 +254,7 @@
+ # Checks for header files.
+ AC_HEADER_SYS_WAIT
+ AC_CHECK_HEADERS([fenv.h stddef.h libintl.h])
+-AC_CHECK_HEADERS([ncurses/curses.h ncurses.h curses.h], [break])
++#AC_CHECK_HEADERS([ncurses/curses.h ncurses.h curses.h], [break])
+ AC_CHECK_HEADERS(fpu_control.h)
+ 
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include "xstream.h"])],
+
diff --git a/source/texk/web2c/lib/ChangeLog b/source/texk/web2c/lib/ChangeLog
index 94b1d492f..5994ef7ac 100644
--- a/source/texk/web2c/lib/ChangeLog
+++ b/source/texk/web2c/lib/ChangeLog
@@ -1,3 +1,8 @@
+2016-05-06  Akira Kakuto  <kakuto@fuk.kinidai.ac.jp>
+
+	* texmfmp.c: Avoid to crash for too large a value of SOURCE_DATE_EPOCH.
+	(w32 only).
+
 2016-05-06  Karl Berry  <karl@tug.org>
 
 	* texmfmp.c (init_start_time, get_date_and_time) [onlyTeX]:
@@ -5,7 +10,7 @@
 
 2016-05-05  Akira Kakuto  <kakuto@fuk.kinidai.ac.jp>
 
-	* texmfmp.c (strtoull) [_MSC_VER]: #define as _strtoi64.
+	* texmfmp.c (strtoull) [_MSC_VER]: #define as _strtoui64.
 
 2016-05-04  Karl Berry  <karl@freefriends.org>
 
diff --git a/source/texk/web2c/lib/texmfmp.c b/source/texk/web2c/lib/texmfmp.c
index c56cd026a..cd7953a93 100644
--- a/source/texk/web2c/lib/texmfmp.c
+++ b/source/texk/web2c/lib/texmfmp.c
@@ -2222,6 +2222,10 @@ void init_start_time() {
 FATAL1 ("invalid epoch-seconds-timezone value for environment variable $SOURCE_DATE_EPOCH: %s",
                       source_date_epoch);
             }
+#if defined(_MSC_VER)
+            if (epoch > 32535291599ULL)
+                epoch = 32535291599ULL;
+#endif
             start_time = epoch;
         } else
 #endif /* not onlyTeX */
-- 
GitLab