From 0e929a9c41033775dfe2bd08452644e4d96fb39a Mon Sep 17 00:00:00 2001
From: Massimiliano Gubinelli <m.gubinelli@gmail.com>
Date: Mon, 23 Mar 2020 02:08:49 +0000
Subject: fixes


diff --git a/Makefile.in b/Makefile.in
index ae4bce4..a829f98 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -175,7 +175,7 @@ INSTALL:
 	$(CP) $(tmdir)/styles $(DESTDIR)$(tmdata)
 	$(CP) $(tmdir)/texts $(DESTDIR)$(tmdata)
 	$(CHMOD) -R go=rX $(DESTDIR)$(tmdata)
-	@echo installed TeXmacs data in $(DESTDIR)$(tmdata)
+	@echo installed Guile data in $(DESTDIR)$(tmdata)
 	$(CP) plugins $(DESTDIR)$(tmdata)
 	$(RM) $(DESTDIR)$(tmdata)/plugins/*/Makefile
 	$(RM) -r $(DESTDIR)$(tmdata)/plugins/*/src
@@ -184,8 +184,8 @@ INSTALL:
 	@echo installed TeXmacs plugins data in $(DESTDIR)$(tmdata)/plugins
 	$(MKDIR) $(DESTDIR)$(datadir)/pixmaps
 	$(CP) $(tmdir)/misc/pixmaps/TeXmacs.xpm $(DESTDIR)$(datadir)/pixmaps
-	packages/linux/icons.sh install $(tmdir)/misc/images texmacs text-x-texmacs
-	packages/linux/mime.sh install $(tmdir)/misc/mime
+#	packages/linux/icons.sh install $(tmdir)/misc/images texmacs text-x-texmacs
+#	packages/linux/mime.sh install $(tmdir)/misc/mime
 	$(MKDIR) $(DESTDIR)$(bindir)
 	$(CHMOD) 755 $(tmdir)/bin/*
 	$(CP) $(tmdir)/bin/fig2ps $(DESTDIR)$(bindir)
diff --git a/configure b/configure
index 80a4ea6..c1ed01f 100755
--- a/configure
+++ b/configure
@@ -7153,6 +7153,16 @@ $as_echo "#define OS_DARWIN 1" >>confdefs.h
       CONFIG_SO="dylib"
       CONFIG_LIB_PATH="DYLD_LIBRARY_PATH"
     ;;
+    *haiku*)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: a generic Haiku host" >&5
+$as_echo "a generic Haiku host" >&6; }
+
+$as_echo "#define OS_HAIKU 1" >>confdefs.h
+
+      CONFIG_OS="HAIKU"
+      CONFIG_QTPIPES="yes"
+      CONFIG_CXXOPTIMIZE="-O3 -fexpensive-optimizations"
+    ;;
     powerpc-*-linux*)
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: a PowerPC/GNU-linux host" >&5
 $as_echo "a PowerPC/GNU-linux host" >&6; }
diff --git a/misc/m4/tm_platform.m4 b/misc/m4/tm_platform.m4
index 3fadab5..fedd350 100644
--- a/misc/m4/tm_platform.m4
+++ b/misc/m4/tm_platform.m4
@@ -140,6 +140,13 @@ AC_DEFUN([TM_PLATFORM],[
       CONFIG_SO="dylib"
       CONFIG_LIB_PATH="DYLD_LIBRARY_PATH"
     ;;
+    *haiku*)
+      AC_MSG_RESULT(a generic Haiku host)
+      AC_DEFINE([OS_HAIKU],[1],[OS type])
+      CONFIG_OS="HAIKU"
+      CONFIG_QTPIPES="yes"
+      CONFIG_CXXOPTIMIZE="-O3 -fexpensive-optimizations"
+    ;;    
     powerpc-*-linux*)
       AC_MSG_RESULT(a PowerPC/GNU-linux host)
       AC_DEFINE([OS_POWERPC_GNU_LINUX],[1],[OS type])
diff --git a/plugins/r/Makefile b/plugins/r/Makefile
index f9fd47c..887403c 100644
--- a/plugins/r/Makefile
+++ b/plugins/r/Makefile
@@ -14,7 +14,7 @@ RM = rm -f
 all: bin/tm_r
 
 bin/tm_r: src/tm_r.c
-	$(CC) $(CPPFLAGS) $(CFLAGS) -I../../src/System src/tm_r.c -o bin/tm_r -lutil
+	$(CC) $(CPPFLAGS) $(CFLAGS) -lbsd -I../../src/System src/tm_r.c -o bin/tm_r
 
 clean:
 	$(RM) bin/tm_r
diff --git a/plugins/r/src/tm_r.c b/plugins/r/src/tm_r.c
index 3ecd81b..a0b2878 100644
--- a/plugins/r/src/tm_r.c
+++ b/plugins/r/src/tm_r.c
@@ -21,8 +21,10 @@
 #include <util.h>
 #endif
 
+#if !defined(__HAIKU__)
 #include <utmp.h>
 #endif
+#endif
 #include <unistd.h>
 #include <termios.h>
 #include <stdlib.h>
diff --git a/plugins/shell/Makefile b/plugins/shell/Makefile
index 3ca4da5..42614c3 100644
--- a/plugins/shell/Makefile
+++ b/plugins/shell/Makefile
@@ -14,7 +14,7 @@ RM = rm -f
 all: bin/tm_shell
 
 bin/tm_shell: src/tm_shell.cpp
-	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -I../../src/System src/tm_shell.cpp -o bin/tm_shell -lutil
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lbsd -I../../src/System src/tm_shell.cpp -o bin/tm_shell
 
 clean:
 	$(RM) bin/tm_shell
diff --git a/src/Plugins/Pdf/LibAesgm/brg_endian.h b/src/Plugins/Pdf/LibAesgm/brg_endian.h
index 4c34f2b..3d5ddb6 100644
--- a/src/Plugins/Pdf/LibAesgm/brg_endian.h
+++ b/src/Plugins/Pdf/LibAesgm/brg_endian.h
@@ -35,7 +35,7 @@ Issue Date: 20/12/2007
 #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
 #  if !defined( __MINGW32__ ) && !defined( _AIX )
 #    include <endian.h>
-#    if !defined( __BEOS__ )
+#    if !defined( __BEOS__ ) && !defined( __HAIKU__ )
 #      include <byteswap.h>
 #    endif
 #  endif
diff --git a/src/System/Language/locale.cpp b/src/System/Language/locale.cpp
index 2565488..a7da4c0 100644
--- a/src/System/Language/locale.cpp
+++ b/src/System/Language/locale.cpp
@@ -211,6 +211,8 @@ get_locale_charset () {
   return "UTF-8";
 #elif X11TEXMACS
   return "UTF-8";
+#elif OS_HAIKU
+  return "UTF-8";
 #else
   std::locale previous= std::locale::global (std::locale(""));
   string charset= string (nl_langinfo (CODESET));
diff --git a/src/System/config.in b/src/System/config.in
index 9c5a531..826982c 100644
--- a/src/System/config.in
+++ b/src/System/config.in
@@ -141,6 +141,9 @@
 /* OS type */
 #undef OS_GNU_LINUX
 
+/* OS type */
+#undef OS_HAIKU
+
 /* OS type */
 #undef OS_IRIX
 
diff --git a/src/Texmacs/Texmacs/texmacs.cpp b/src/Texmacs/Texmacs/texmacs.cpp
index 8aa39bc..f55f5d4 100644
--- a/src/Texmacs/Texmacs/texmacs.cpp
+++ b/src/Texmacs/Texmacs/texmacs.cpp
@@ -173,6 +173,15 @@ TeXmacs_init_paths (int& argc, char** argv) {
   // system("set");
 #endif
 
+#ifdef OS_HAIKU
+  // Initialization inside the Haiku package management environment
+  // TEXMACS_PATH is set relative to the executable which is in $prefix/app
+  // to $prefix/data/TeXmacs
+
+  if (is_empty (current_texmacs_path))
+    set_env ("TEXMACS_PATH", as_string (exedir * "../data/TeXmacs"));
+#endif
+
   // check on the latest $TEXMACS_PATH
   current_texmacs_path = get_env ("TEXMACS_PATH");
   if (is_empty (current_texmacs_path) ||
@@ -555,6 +564,8 @@ immediate_options (int argc, char** argv) {
         set_env ("HOME", get_env("USERPROFILE"));
     set_env ("TEXMACS_HOME_PATH", get_env ("APPDATA") * "\\TeXmacs");
 	}
+#elif defined(OS_HAIKU)
+    set_env ("TEXMACS_HOME_PATH", get_env ("HOME") * "/config/settings/TeXmacs");
 #else
     set_env ("TEXMACS_HOME_PATH", get_env ("HOME") * "/.TeXmacs");
 #endif
-- 
2.24.1


From 256426a9555cbfac724806f39b218e4df7395a64 Mon Sep 17 00:00:00 2001
From: Massimiliano Gubinelli <m.gubinelli@gmail.com>
Date: Mon, 23 Mar 2020 14:48:42 +0000
Subject: fix PATH


diff --git a/src/Texmacs/Texmacs/texmacs.cpp b/src/Texmacs/Texmacs/texmacs.cpp
index f55f5d4..fa9372c 100644
--- a/src/Texmacs/Texmacs/texmacs.cpp
+++ b/src/Texmacs/Texmacs/texmacs.cpp
@@ -180,6 +180,9 @@ TeXmacs_init_paths (int& argc, char** argv) {
 
   if (is_empty (current_texmacs_path))
     set_env ("TEXMACS_PATH", as_string (exedir * "../data/TeXmacs"));
+
+  set_env ("PATH", get_env("PATH") * ":" *
+             as_string ("/system/lib/TeXmacs/bin"));
 #endif
 
   // check on the latest $TEXMACS_PATH
-- 
2.24.1

