From bd95a285e81b9fd3ff852810bacfb4c751ae7aec Mon Sep 17 00:00:00 2001
From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Date: Sun, 24 May 2015 20:20:28 +1200
Subject: Haiku support


diff --git a/libs/lua52/lua-5.2.3/src/luaconf.h b/libs/lua52/lua-5.2.3/src/luaconf.h
index 18be9a9..cf06f9a 100644
--- a/libs/lua52/lua-5.2.3/src/luaconf.h
+++ b/libs/lua52/lua-5.2.3/src/luaconf.h
@@ -69,7 +69,9 @@
 #define LUA_USE_MKSTEMP
 #define LUA_USE_ISATTY
 #define LUA_USE_POPEN
+#ifndef __HAIKU__
 #define LUA_USE_ULONGJMP
+#endif
 #define LUA_USE_GMTIME_R
 #endif
 
diff --git a/m4/kpse-socket-libs.m4 b/m4/kpse-socket-libs.m4
index c768b95..c291884 100644
--- a/m4/kpse-socket-libs.m4
+++ b/m4/kpse-socket-libs.m4
@@ -20,7 +20,7 @@ AC_DEFUN([KPSE_CHECK_SOCKET_LIBS],
 [AC_REQUIRE([KPSE_CHECK_WIN32])
 AS_IF([test "x$kpse_cv_have_win32" = xno],
       [kpse_save_LIBS=$LIBS
-       AC_SEARCH_LIBS([connect], [socket nsl])
+       AC_SEARCH_LIBS([connect], [socket nsl network])
        LIBS=$kpse_save_LIBS],
       [AC_CHECK_LIB([wsock32], [main],
                     [ac_cv_search_connect=-lwsock32],
diff --git a/texk/dviljk/config.h b/texk/dviljk/config.h
index a92d247..3d9bd99 100644
--- a/texk/dviljk/config.h
+++ b/texk/dviljk/config.h
@@ -10,6 +10,8 @@
 #define unix
 #elif defined (__NetBSD__)
 #define unix
+#elif defined (__HAIKU__)
+#define unix
 #endif
 #endif
 
diff --git a/texk/dvipdfm-x/configure.ac b/texk/dvipdfm-x/configure.ac
index 60d9987..4a8b00e 100644
--- a/texk/dvipdfm-x/configure.ac
+++ b/texk/dvipdfm-x/configure.ac
@@ -49,6 +49,7 @@ AC_CHECK_SIZEOF([int])
 AC_CHECK_SIZEOF([long])
 
 AC_SEARCH_LIBS([pow], [m])
+AC_SEARCH_LIBS([getpass], [bsd])
 
 KPSE_KPATHSEA_FLAGS
 KPSE_ZLIB_FLAGS
diff --git a/texk/dvipdfm-x/pdfencrypt.c b/texk/dvipdfm-x/pdfencrypt.c
index 480823c..c0a206f 100644
--- a/texk/dvipdfm-x/pdfencrypt.c
+++ b/texk/dvipdfm-x/pdfencrypt.c
@@ -31,6 +31,9 @@
 #include <conio.h>
 #define getch _getch
 #else  /* !WIN32 */
+#ifdef __HAIKU__
+#define _BSD_SOURCE
+#endif
 #include <unistd.h>
 #endif /* WIN32 */
 
diff --git a/texk/web2c/configure.ac b/texk/web2c/configure.ac
index 87e2ad5..61e79ef 100644
--- a/texk/web2c/configure.ac
+++ b/texk/web2c/configure.ac
@@ -22,7 +22,7 @@ dnl
 m4_include([../../version.ac])[] dnl define tex_live_version
 AC_INIT([Web2C], tex_live_version(), [tex-k@tug.org])
 AC_PREREQ([2.65])
-dnl 
+dnl
 dnl We don't use (for example) tex/tex.web because people who only want
 dnl to build part of the distribution may not have any given program.
 dnl Even cpascal.h isn't guaranteed, but then nothing is, really ...
@@ -107,9 +107,9 @@ KPSE_LUA52_DEFINES
 KPSE_LUAJIT_DEFINES
 LIBS=$kpse_save_LIBS
 if test "x$kpse_cv_have_win32" = xno; then
-  AC_SEARCH_LIBS([gethostbyname], [nsl])
-  AC_SEARCH_LIBS([hstrerror], [resolv])
-  AC_SEARCH_LIBS([inet_aton], [resolv])
+  AC_SEARCH_LIBS([gethostbyname], [nsl network])
+  AC_SEARCH_LIBS([hstrerror], [resolv bind])
+  AC_SEARCH_LIBS([inet_aton], [resolv bind])
   LIBS=$kpse_save_LIBS
   AC_SEARCH_LIBS([nanosleep], [rt])
   LIBS=$kpse_save_LIBS
-- 
2.2.2


From 080a1c28447c5abae634ef1848ddc60a504b050a Mon Sep 17 00:00:00 2001
From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Date: Tue, 2 Jun 2015 09:30:45 +1200
Subject: Don't use the /nonesuch idiom on Haiku.


diff --git a/texk/kpathsea/cnf-to-paths.awk b/texk/kpathsea/cnf-to-paths.awk
index 939f54d..431062f 100644
--- a/texk/kpathsea/cnf-to-paths.awk
+++ b/texk/kpathsea/cnf-to-paths.awk
@@ -43,12 +43,9 @@
     # Replace all semicolons with colons in the SELFAUTO paths we're keeping.
     # (The path-splitting code should be changed to understand both.)
     gsub(/;/, ":", val);
-  } else if (val ~ /^\//) {
-    # If the value starts with /, presume we're compiling with changes
-    # made for a distro, and keep it.  Likewise switch to :.
-    gsub(/;/, ":", val);
   } else {
-    val = "/nonesuch";
+    # Just hard-code it on Haiku; it never does the right thing otherwise
+    gsub(/;/, ":", val);
   }
   
   print "#ifndef DEFAULT_" ident;
-- 
2.2.2


From ee7a3fb96fb2be78a1b7b7721adde56a5514fc9e Mon Sep 17 00:00:00 2001
From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Date: Tue, 2 Jun 2015 10:16:26 +1200
Subject: Don't allow SELFAUTO* magic on Haiku.


diff --git a/texk/kpathsea/progname.c b/texk/kpathsea/progname.c
index c4fe781..0d032b4 100644
--- a/texk/kpathsea/progname.c
+++ b/texk/kpathsea/progname.c
@@ -667,6 +667,15 @@ kpathsea_set_program_name (kpathsea kpse,  const_string argv0,
 #endif
   /* SELFAUTODIR is actually the parent of the invocation directory,
      and SELFAUTOPARENT the grandparent.  This is how teTeX did it.  */
+#ifdef __HAIKU__
+  /* The SELFAUTO* variables don't work under a packaged TeX Live installation
+     on Haiku; normally SELFAUTOLOC would be a path like texlive/texmf-dist/bin/platform.
+     Have no idea how this is going to play out... */
+  kpathsea_xputenv (kpse, "SELFAUTOLOC", "/boot/system/bin");
+  kpathsea_xputenv (kpse, "SELFAUTODIR", "/boot/system/data/texlive/texmf-dist");
+  kpathsea_xputenv (kpse, "SELFAUTOPARENT", "/boot/system/data/texlive");
+  kpathsea_xputenv (kpse, "SELFAUTOGRANDPARENT", "/boot/system/data");
+#else
   kpathsea_xputenv (kpse, "SELFAUTOLOC", fix_selfdir (sdir));
   sdir_parent = xdirname (sdir);
   kpathsea_xputenv (kpse, "SELFAUTODIR", fix_selfdir (sdir_parent));
@@ -674,6 +683,7 @@ kpathsea_set_program_name (kpathsea kpse,  const_string argv0,
   kpathsea_xputenv (kpse, "SELFAUTOPARENT", fix_selfdir (sdir_grandparent));
   sdir_greatgrandparent = xdirname (sdir_grandparent);
   kpathsea_xputenv (kpse, "SELFAUTOGRANDPARENT", fix_selfdir (sdir_greatgrandparent));
+#endif
 
 #if defined(WIN32) || defined(__CYGWIN__)
   mk_suffixlist(kpse);
-- 
2.2.2


From 1b8868ceaac76a98ae55619475734ecc794940f7 Mon Sep 17 00:00:00 2001
From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Date: Wed, 3 Jun 2015 15:07:56 +1200
Subject: Try and fix up more weirdness with install-tl


diff --git a/texk/texlive/tl_scripts/texlinks.sh b/texk/texlive/tl_scripts/texlinks.sh
index 028b50b..0e848c8 100755
--- a/texk/texlive/tl_scripts/texlinks.sh
+++ b/texk/texlive/tl_scripts/texlinks.sh
@@ -162,26 +162,36 @@ install_link()
       # context includes wrapper scripts that create/run these.
       verbose_echo "skipped ConTeXtish symlink $src -> $dest (special case)"
       ;;
+    /boot/system/bin/*)
+      # Trying to symlink to ourself
+      verbose_echo "skipped symlinking to self: $src -> $dest (haiku case)"
+      ;;
     *)
-      test "x$src" != "x`(ls -ld $src | awk '{print $NF}') 2>/dev/null`" &&
-        rm -f "$src"
-  
-      if test -f "$src"; then
-        if $silent; then :; else
-          # i.e., the rm failed.
-          errmsg "install_link $src -> $dest failed: file already exists."
-        fi
-      else
-        if echo "$src" | grep '/pdfcsplain$' >/dev/null; then
-          # at p.olsak insistence: we have three pdfcsplain entries in
-          # fmtutil.cnf with different engines, but the executable link
-          # must point to pdftex.
-          verbose_echo "forcing pdfcsplain destination to be pdftex"
-          dest=pdftex
+      case $dest in
+    /boot/system/bin/*)
+        verbose_echo "skipped symlink to bin dir: $src -> $dest (haiku case)"
+        ;;
+    *)
+        test "x$src" != "x`(ls -ld $src | awk '{print $NF}') 2>/dev/null`" &&
+          rm -f "$src"
+    
+        if test -f "$src"; then
+          if $silent; then :; else
+            # i.e., the rm failed.
+            errmsg "install_link $src -> $dest failed: file already exists."
+          fi
+        else
+          if echo "$src" | grep '/pdfcsplain$' >/dev/null; then
+            # at p.olsak insistence: we have three pdfcsplain entries in
+            # fmtutil.cnf with different engines, but the executable link
+            # must point to pdftex.
+            verbose_echo "forcing pdfcsplain destination to be pdftex"
+            dest=pdftex
+          fi
+          verbose_do ln -s "$dest" "$src"
         fi
-        verbose_do ln -s "$dest" "$src"
-      fi
-      ;;
+        ;;
+     esac
    esac
 }
 
-- 
2.2.2

