From e33be2b34f8664e213b0b350b24a7169f6316e3d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Wed, 11 Dec 2013 10:16:33 +0100
Subject: [PATCH 1/6] Add Haiku resource definition file

Icon designed by me, extracted from:
data/artwork/icons/App_OpenCubicPlayer from Haiku sources
---
 ocp.rdef | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 ocp.rdef

diff --git a/ocp.rdef b/ocp.rdef
new file mode 100644
index 0000000..c710155
--- /dev/null
+++ b/ocp.rdef
@@ -0,0 +1,39 @@
+/* Haiku resources definitions for OCP */
+
+resource app_signature "application/x-vnd.OpenCubicPlayer";
+
+resource app_version {
+	major  = 0,
+	middle = 1,
+	minor  = 21,
+
+	variety = B_APPV_BETA,
+
+	internal = 0,
+
+	short_info = "Open Cubic Player",
+	long_info = "Open Cubic Player ©1994-2012 Niklas Beisert, Stian Skjelstad and others."
+};
+
+resource app_flags B_MULTIPLE_LAUNCH | B_ARGV_ONLY;
+
+resource file_types message {
+	"types" = "application/ogg",
+	"types" = "application/x-ogg",
+	"types" = "audio"
+};
+
+resource("BEOS:ICON") #'VICN' array {
+	$"6E636966060500020006023B55F13C5CD2BE755C3D78974A454E48FFCB006464"
+	$"CEFF1C184C020016023CD471BA2F923B0FF33DF6F048DA184417BB00FFFFBB02"
+	$"0016023C318B3A487CBD09B43EEB2D4B485C48176F0099FF4A04016D04FF6D07"
+	$"0A0627312C483D58594A582F43220A0427312C483D5838400A0427313840582F"
+	$"43220A043D58594A582F38400A042C5039605F59483D0204422840284428452A"
+	$"4528452C422C442C402C3F2A3F2C3F280A032351235C2B57160A040104000A00"
+	$"01001001178400040A010101000A020102000A030103000A05010528211E10FF"
+	$"0A04010528211F10FF0A05010528292510FF0A04010528292610FF0A05010528"
+	$"112610FF0A04010528112710FF0A050105281A2D10FF0A040105281A2E10FF0A"
+	$"050105281F3A10FF0A040105281E3A10FF0A050105282E3210FF0A040105282D"
+	$"3210FF0A05010528224310FF0A04010528214310FF0A05010528303C10FF0A04"
+	$"0105282F3C10FF0A0001060810FF"
+};
-- 
1.8.3.4


From 4f1cba4ec366f082afb4f9a2df7dffc46aa2dcd5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Wed, 11 Dec 2013 10:17:36 +0100
Subject: [PATCH 2/6] Export HAIKU variable to indicate building on Haiku

---
 Rules.make.in | 1 +
 configure.ac  | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/Rules.make.in b/Rules.make.in
index 636f0ba..f1f7e98 100644
--- a/Rules.make.in
+++ b/Rules.make.in
@@ -6,6 +6,7 @@ INFODIR=@INFODIR@
 BINDIR=@BINDIR@
 SYSCONFDIR=@SYSCONFDIR@
 DESKTOP_FILE_INSTALL=@DESKTOP_FILE_INSTALL@
+HAIKU=@HAIKU@
 
 DIR_SUFFIX=@DIR_SUFFIX@
 
diff --git a/configure.ac b/configure.ac
index e6ecfb1..1efdc26 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,6 +31,7 @@ AC_C_BIGENDIAN
 AC_SUBST(SHARED_FLAGS)
 AC_SUBST(LIB_SUFFIX)
 AC_SUBST(PTHREAD_LIBS)
+AC_SUBST(HAIKU)
 target=`gcc -dumpmachine`
 case "$target" in
 	*-darwin*)
@@ -45,6 +46,7 @@ case "$target" in
 		LIB_SUFFIX=.so
 		PTHREAD_LIBS=
 		with_desktop_file_install=no
+		HAIKU=1
 		;;
 	*)
 		SHARED_FLAGS=-shared
-- 
1.8.3.4


From dd77379d0431d48e94f08494f68aa61fe59edbc7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Wed, 11 Dec 2013 10:18:30 +0100
Subject: [PATCH 3/6] Apply resources file when building on Haiku

---
 Makefile.in | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Makefile.in b/Makefile.in
index f3a1c13..aa21c6d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -166,6 +166,11 @@ endif
 
 ocp: boot/kickload.o
 	$(CC) $(LDFLAGS) -o $@ $^ @DL_LIBS@ @EFENCE_LIBS@ @DUMA_LIBS@
+ifeq ($(HAIKU),1)
+	rc -o ocp.rsrc ocp.rdef
+	xres -o $@ ocp.rsrc
+	mimeset $@
+endif
 
 ocp.hlp: doc/opencp.dox goodies/helpc/ocphhc
 	goodies/helpc/ocphhc doc/opencp.dox $@
@@ -202,6 +207,7 @@ endif
 	find . -name '*~' -exec rm {} ';'
 	rm -f ocp.hlp ocp *$(LIB_SUFFIX)
 	rm -f CPARCH.DAT
+	rm -f ocp.rsrc
 
 distclean: clean
 	rm -Rf config.h autom4te.cache Rules.make config.log config.status Makefile ocp.ini desktop/opencubicplayer.desktop doc/texi/faq.texi doc/texi/install.texi doc/texi/ocp.texi goodies/pack/Makefile goodies/helpc/Makefile Makefile
-- 
1.8.3.4


From 38474a5b37bce6047ac764b73348ef7cabbbfdb3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Sat, 19 Jul 2014 00:40:10 +0000
Subject: [PATCH 4/6] Replace hardcoded data and doc dirs

Make use of the --datadir and --docdir args to configure.

Note the default docdir doesn't get the DIR_SUFFIX anymore.
---
 Makefile.in       | 24 ++++++++++++------------
 Rules.make.in     |  3 +++
 boot/kickload.c   |  8 ++++----
 config.h.in       |  1 +
 configure.ac      |  4 ++++
 doc/texi/Makefile |  6 +++---
 6 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index aa21c6d..913a672 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -35,12 +35,12 @@ endif
 
 
 install: all
-	mkdir -p "$(DESTDIR)$(PREFIX)/share/doc/ocp$(DIR_SUFFIX)"
-	$(CP) AUTHORS BUGS COPYING CREDITS KEYBOARD_REMAPS SUID TODO "$(DESTDIR)$(PREFIX)/share/doc/ocp$(DIR_SUFFIX)"
-	mkdir -p "$(DESTDIR)$(PREFIX)/share/ocp$(DIR_SUFFIX)/data"
-	$(CP) ocp.hlp "$(DESTDIR)$(PREFIX)/share/ocp$(DIR_SUFFIX)/data"
-	mkdir -p "$(DESTDIR)$(PREFIX)/share/ocp$(DIR_SUFFIX)/etc"
-	$(CP) ocp.ini "$(DESTDIR)$(PREFIX)/share/ocp$(DIR_SUFFIX)/etc"
+	mkdir -p "$(DESTDIR)$(DOCDIR)"
+	$(CP) AUTHORS BUGS COPYING CREDITS KEYBOARD_REMAPS SUID TODO "$(DESTDIR)$(DOCDIR)"
+	mkdir -p "$(DESTDIR)$(DATADIR)/ocp$(DIR_SUFFIX)/data"
+	$(CP) ocp.hlp "$(DESTDIR)$(DATADIR)/ocp$(DIR_SUFFIX)/data"
+	mkdir -p "$(DESTDIR)$(DATADIR)/ocp$(DIR_SUFFIX)/etc"
+	$(CP) ocp.ini "$(DESTDIR)$(DATADIR)/ocp$(DIR_SUFFIX)/etc"
 	mkdir -p "$(DESTDIR)$(LIBDIR)"
 	$(CP) libocp$(LIB_SUFFIX) "$(DESTDIR)$(LIBDIR)"
 	mkdir -p "$(DESTDIR)$(LIBDIR)/autoload"
@@ -65,13 +65,13 @@ endif
 	$(MAKE) -C doc DESTDIR="$(DESTDIR)" install TOPDIR="../$(TOPDIR)"
 
 ifeq ($(HAVE_X11),1)
-	mkdir -p "$(DESTDIR)$(PREFIX)/share/applications" "$(DESTDIR)$(PREFIX)/share/icons/hicolor/16x16/apps/" "$(DESTDIR)$(PREFIX)/share/icons/hicolor/48x48/apps/"
-	$(CP) desktop/opencubicplayer.xpm "$(DESTDIR)$(PREFIX)/share/icons/hicolor/48x48/apps/opencubicplayer.xpm"
-	$(CP) desktop/opencubicplayer_mini.xpm "$(DESTDIR)$(PREFIX)/share/icons/hicolor/16x16/apps/opencubicplayer.xpm"
+	mkdir -p "$(DESTDIR)$(DATAROOTDIR)/applications" "$(DESTDIR)$(DATAROOTDIR)/icons/hicolor/16x16/apps/" "$(DESTDIR)$(DATAROOTDIR)/icons/hicolor/48x48/apps/"
+	$(CP) desktop/opencubicplayer.xpm "$(DESTDIR)$(DATAROOTDIR)/icons/hicolor/48x48/apps/opencubicplayer.xpm"
+	$(CP) desktop/opencubicplayer_mini.xpm "$(DESTDIR)$(DATAROOTDIR)/icons/hicolor/16x16/apps/opencubicplayer.xpm"
 endif
 
 ifneq ($(DESKTOP_FILE_INSTALL),)
-	$(DESKTOP_FILE_INSTALL) --vendor="cubic.org" --dir="$(DESTDIR)$(PREFIX)/share/applications" desktop/opencubicplayer.desktop
+	$(DESKTOP_FILE_INSTALL) --vendor="cubic.org" --dir="$(DESTDIR)$(DATAROOTDIR)/applications" desktop/opencubicplayer.desktop
 endif
 	$(MAKE) -C asm_emu TOPDIR=../$(TOPDIR) install
 	$(MAKE) -C boot TOPDIR=../$(TOPDIR) install
@@ -131,8 +131,8 @@ endif
 	$(MAKE) -C stuff TOPDIR=../$(TOPDIR) uninstall
 	$(MAKE) -C medialib TOPDIR=../$(TOPDIR) uninstall
 	$(MAKE) -C doc TOPDIR="../$(TOPDIR)" uninstall
-	rm -Rf "$(DESTDIR)$(PREFIX)/share/doc/ocp$(DIR_SUFFIX)" "$(DESTDIR)$(PREFIX)/share/ocp$(DIR_SUFFIX)" "$(DESTDIR)$(LIBDIR)" "$(DESTDIR)$(BINDIR)/ocp$(DIR_SUFFIX)" "$(DESTDIR)$(BINDIR)/ocp" "$(DESTDIR)$(BINDIR)/ocp-curses" "$(DESTDIR)$(BINDIR)/ocp-sdl" "$(DESTDIR)$(BINDIR)/ocp-vcsa" "$(DESTDIR)$(BINDIR)/ocp-x11" "$(DESTDIR)$(BINDIR)/ultrafix.sh"
-	rm -f "$(DESTDIR)$(PREFIX)/share/applications/opencubicplayer.desktop" "$(DESTDIR)$(PREFIX)/share/icons/hicolor/16x16/apps/opencubicplayer.xpm" "$(DESTDIR)$(PREFIX)/share/icons/hicolor/48x48/apps/opencubicplayer.xpm"
+	rm -Rf "$(DESTDIR)$(DOCDIR)" "$(DESTDIR)$(DATADIR)/ocp$(DIR_SUFFIX)" "$(DESTDIR)$(LIBDIR)" "$(DESTDIR)$(BINDIR)/ocp$(DIR_SUFFIX)" "$(DESTDIR)$(BINDIR)/ocp" "$(DESTDIR)$(BINDIR)/ocp-curses" "$(DESTDIR)$(BINDIR)/ocp-sdl" "$(DESTDIR)$(BINDIR)/ocp-vcsa" "$(DESTDIR)$(BINDIR)/ocp-x11" "$(DESTDIR)$(BINDIR)/ultrafix.sh"
+	rm -f "$(DESTDIR)$(DATAROOTDIR)/applications/opencubicplayer.desktop" "$(DESTDIR)$(DATAROOTDIR)/icons/hicolor/16x16/apps/opencubicplayer.xpm" "$(DESTDIR)$(DATAROOTDIR)/icons/hicolor/48x48/apps/opencubicplayer.xpm"
 
 dirs:
 	$(MAKE) -C asm_emu TOPDIR=../$(TOPDIR)
diff --git a/Rules.make.in b/Rules.make.in
index f1f7e98..7405eb5 100644
--- a/Rules.make.in
+++ b/Rules.make.in
@@ -2,9 +2,12 @@
 
 PREFIX=@PREFIX@
 LIBDIR=@LIBDIR@
+DOCDIR=@DOCDIR@
 INFODIR=@INFODIR@
 BINDIR=@BINDIR@
 SYSCONFDIR=@SYSCONFDIR@
+DATADIR=@DATADIR@
+DATAROOTDIR=@DATAROOTDIR@
 DESKTOP_FILE_INSTALL=@DESKTOP_FILE_INSTALL@
 HAIKU=@HAIKU@
 
diff --git a/boot/kickload.c b/boot/kickload.c
index 6b4818c..73c9e4c 100644
--- a/boot/kickload.c
+++ b/boot/kickload.c
@@ -159,9 +159,9 @@ static const char *locate_ocp_ini(void)
 		} else*/if ((retval=locate_ocp_ini_try(temp)))
 				return retval;
 	}
-	if ((retval=locate_ocp_ini_try(PREFIX "/share/ocp" DIR_SUFFIX "/etc/")))
+	if ((retval=locate_ocp_ini_try(DATADIR "/ocp" DIR_SUFFIX "/etc/")))
 		return retval;
-	if ((retval=locate_ocp_ini_try(PREFIX "/share/ocp/" DIR_SUFFIX)))
+	if ((retval=locate_ocp_ini_try(DATADIR "/share/ocp/" DIR_SUFFIX)))
 		return retval;
 	if ((retval=locate_ocp_ini_try(PREFIX "/etc/ocp/" DIR_SUFFIX)))
 		return retval;
@@ -198,9 +198,9 @@ static const char *locate_ocp_hlp(void)
 	if ((temp=getenv("OCPDIR")))
 		if ((retval=locate_ocp_hlp_try(temp)))
 			return retval;
-	if ((retval=locate_ocp_hlp_try(PREFIX "/share/ocp" DIR_SUFFIX "/")))
+	if ((retval=locate_ocp_hlp_try(DATADIR "/ocp" DIR_SUFFIX "/")))
 		return retval;
-	if ((retval=locate_ocp_hlp_try(PREFIX "/share/ocp" DIR_SUFFIX "/data/")))
+	if ((retval=locate_ocp_hlp_try(DATADIR "/ocp" DIR_SUFFIX "/data/")))
 		return retval;
 	if ((retval=locate_ocp_hlp_try(LIBDIR)))
 		return retval;
diff --git a/config.h.in b/config.h.in
index 972a958..774b2de 100644
--- a/config.h.in
+++ b/config.h.in
@@ -256,6 +256,7 @@
 
 #define PREFIX "/usr/local"
 #define LIBDIR "/usr/lib/ocp"
+#define DATADIR "/usr/share"
 #define DIR_SUFFIX ""
 
 #define LIB_SUFFIX ".so"
diff --git a/configure.ac b/configure.ac
index 1efdc26..add9bd8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -573,8 +573,12 @@ AC_DEFINE_UNQUOTED(LIBDIR, "$LIBDIR")
 AS_AC_EXPAND(BINDIR, $exec_prefix/bin)
 
 AS_AC_EXPAND(PREFIX, $prefix)
+AS_AC_EXPAND(DOCDIR, $docdir)
 AS_AC_EXPAND(INFODIR, $infodir)
 AS_AC_EXPAND(SYSCONFDIR, $sysconfdir)
+AS_AC_EXPAND(DATADIR, $datadir)
+AS_AC_EXPAND(DATAROOTDIR, $datarootdir)
+AC_DEFINE_UNQUOTED(DATADIR, "$DATADIR")
 AC_DEFINE_UNQUOTED(PREFIX, "$PREFIX")
 
 
diff --git a/doc/texi/Makefile b/doc/texi/Makefile
index 55ecaaa..3052d90 100644
--- a/doc/texi/Makefile
+++ b/doc/texi/Makefile
@@ -19,12 +19,12 @@ install: all
 	mkdir -p "$(DESTDIR)$(INFODIR)"
 	$(CP) ocp.info.gz "$(DESTDIR)$(INFODIR)"
 	install-info --dir-file="$(DESTDIR)$(INFODIR)/dir" "$(DESTDIR)$(INFODIR)/ocp.info.gz" || true
-	mkdir -p "$(DESTDIR)$(PREFIX)/share/doc/ocp$(DIR_SUFFIX)/html"
-	$(CP) -R ocp.html/* "$(DESTDIR)$(PREFIX)/share/doc/ocp$(DIR_SUFFIX)/html"
+	mkdir -p "$(DESTDIR)$(DOCDIR)/html"
+	$(CP) -R ocp.html/* "$(DESTDIR)$(DOCDIR)/html"
 uninstall:
 	install-info --delete --dir-file="$(DESTDIR)$(INFODIR)/dir" "$(DESTDIR)$(INFODIR)/ocp.info.gz"
 	rm -f "$(DESTDIR)$(INFODIR)/ocp.info.gz"
-	rm -Rf "$(DESTDIR)$(PREFIX)/share/doc/ocp$(DIR_SUFFIX)/html"
+	rm -Rf "$(DESTDIR)$(DOCDIR)/html"
 else
 all:
 
-- 
1.8.3.4


From edf10b908a899f01cf62a2d3bd91b7de4711d4b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Sat, 19 Jul 2014 00:43:17 +0000
Subject: [PATCH 5/6] Work around makeinfo error

Force POSIX locale to work around a makeinfo error:
"cannot select column #1 in multitable."
---
 doc/texi/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/texi/Makefile b/doc/texi/Makefile
index 3052d90..25d5bf9 100644
--- a/doc/texi/Makefile
+++ b/doc/texi/Makefile
@@ -9,10 +9,10 @@ all: ocp.info.gz
 
 ocp.info.gz: $(SOURCES)
 	rm -Rf ocp ocp.html ocp.info ocp.info.gz
-	makeinfo ocp.texi
+	LC_ALL=POSIX makeinfo ocp.texi
 	mv ocp ocp.info
 	gzip ocp.info
-	makeinfo --html ocp.texi
+	LC_ALL=POSIX makeinfo --html ocp.texi
 	mv ocp ocp.html
 
 install: all
-- 
1.8.3.4


From bf526bc639c753c9b7241013a102e58b31968dba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Sat, 19 Jul 2014 01:36:59 +0000
Subject: [PATCH 6/6] On Haiku, use the correct settings path

On Haiku, settings go to ~/config/settings/app instead
of ~/.app.
---
 boot/kickload.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/boot/kickload.c b/boot/kickload.c
index 73c9e4c..c245b35 100644
--- a/boot/kickload.c
+++ b/boot/kickload.c
@@ -49,6 +49,9 @@
 #include <sys/wait.h>
 #include <time.h>
 #include <unistd.h>
+#ifdef __HAIKU__
+#include <FindDirectory.h>
+#endif
 #include "types.h"
 #include "pmain.h"
 
@@ -405,6 +408,17 @@ int validate_home(void)
 	if (temp[strlen(temp)-1]!='/')
 		strcat(temp, "/");
 	strcat(temp, ".ocp/");
+
+#ifdef __HAIKU__
+	char settingsPath[PATH_MAX];
+	if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settingsPath, sizeof(settingsPath)) == B_OK) {
+		free(temp);
+		temp=malloc(strlen(settingsPath)+1+4+1);
+		strcpy(temp, settingsPath);
+		strcat(temp, "/ocp/");
+	}
+#endif
+
 	_cfConfigDir=temp;
 
 	if (stat(temp, &st)<0)
-- 
1.8.3.4

