From 39d78014135554764b6d847ed4ad2c4fe02af2f4 Mon Sep 17 00:00:00 2001
From: TURX <turx2003@gmail.com>
Date: Sun, 19 Jan 2020 22:57:40 +0800
Subject: fix Haiku support


diff --git a/Makefile b/Makefile
index 938c6a6..64de6f3 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ include config.mak
 
 install:
 	install -d "$(DESTDIR)$(prefix)/bin"
-	install -d "$(DESTDIR)$(prefix)/include"
+	install -d "$(DESTDIR)$(includedir)"
 	install -d "$(DESTDIR)$(libdir)"
 	install -d "$(DESTDIR)$(moduledir)"
 ifeq ($(extra_versioning), true)
@@ -52,7 +52,7 @@ uninstall:
 	for subdir in $$list; do \
 		$(MAKE) DESTDIR=$(DESTDIR) -C $$subdir $@ || exit 1; \
 	done
-	rm -rf "$(DESTDIR)$(prefix)/include/mlt"
+	rm -rf "$(DESTDIR)$(includedir)/mlt"
 	rm -rf "$(DESTDIR)$(mltdatadir)"
 ifeq ($(compat_dirs), true)
 	rm -rf "$(DESTDIR)$(prefix)/share/mlt"
diff --git a/configure b/configure
index a32a75c..7dff1e1 100755
--- a/configure
+++ b/configure
@@ -18,6 +18,7 @@ General build options:
   --libdir=directory         - lib directory (default: $prefix/lib)
   --datadir=directory        - data directory (default: $prefix/share)
   --mandir=directory         - man documentation directory (default: $prefix/share/man)
+  --includedir=directory     - headers directory (default: $prefix/include)
   --rename-melt              - Give melt executable a different name (it will not be versioned)
   --enable-extra-versioning  - Version melt and the data and modules directories
   --enable-gpl               - Enable GPLv2 components
@@ -58,6 +59,7 @@ build_config()
 		echo "bindir=$prefix/bin"
 		echo "datadir=$datadir"
 		echo "mandir=$mandir"
+		echo "includedir=$includedir"
 		echo "extra_versioning=$extra_versioning"
 		echo "melt_noversion=$melt_noversion"
 		echo "targetos=$targetos"
@@ -131,6 +133,16 @@ build_config()
 		echo "RDYNAMIC=-rdynamic"
 		echo "LDFLAGS+=-Wl,--as-needed"
 		;;
+		Haiku)
+		[ "$optimisations" = "true" ] &&
+			echo "OPTIMISATIONS+=-ffast-math"
+		echo "CFLAGS+=-fPIC"
+		echo "CXXFLAGS+=-fPIC"
+		echo "SHFLAGS=-shared"
+		echo "LIBDL="
+		echo "RDYNAMIC="
+		echo "LDFLAGS+=-Wl,--no-undefined -Wl,--as-needed"
+		;;
 		MinGW)
 		[ "$windeploy" = false ] &&
 			echo "CFLAGS+=-DNODEPLOY"
@@ -178,7 +190,7 @@ build_pkgconfig()
 	(
 		echo exec_prefix=$prefix
 		echo libdir=$libdir
-		echo includedir=$prefix/include
+		echo includedir=$includedir
 		echo datadir=$datadir
 		echo mandir=$mandir
 		echo version=$version
@@ -194,7 +206,7 @@ build_pkgconfig()
 	(
 		echo exec_prefix=$prefix
 		echo libdir=$libdir
-		echo includedir=$prefix/include
+		echo includedir=$includedir
 		echo datadir=$datadir
 		echo mandir=$mandir
 		echo version=$version
@@ -229,6 +241,7 @@ export amd64=false
 export extra_versioning=false
 export melt_noversion=false
 export windeploy=true
+export includedir=$includedir
 
 # Define the compiler used in tests (gcc is not installed everywhere)
 : ${CC:=gcc}
@@ -264,6 +277,7 @@ do
 		--libdir=* )			libdir="${i#--libdir=}" ;;
 		--datadir=* )			datadir="${i#--datadir=}" ;;
 		--mandir=* )			mandir="${i#--mandir=}" ;;
+		--includedir=* )		includedir="${i#--includedir=}" ;;
 		--rename-melt=* )		meltname="${i#--rename-melt=}"; melt_noversion=true ;;
 		--enable-extra-versioning )	extra_versioning=true ;;
 		--enable-debug )		optimisations=false ;;
@@ -322,6 +336,7 @@ export LIBSUF
 [ "$libdir" = "" ] && libdir=$prefix/lib
 [ "$datadir" = "" ] && datadir=$prefix/share
 [ "$mandir" = "" ] && mandir=$prefix/share/man
+[ "$includedir" = "" ] && includedir=$prefix/include
 
 export unversionedmoduledir=${libdir}/mlt
 export unversionedmltdatadir=${datadir}/mlt
diff --git a/src/framework/Makefile b/src/framework/Makefile
index 654883f..395e795 100644
--- a/src/framework/Makefile
+++ b/src/framework/Makefile
@@ -128,8 +128,8 @@ install:
 		ln -sf $(TARGET) $(DESTDIR)$(libdir)/$(SONAME) ; \
 		ln -sf $(TARGET) $(DESTDIR)$(libdir)/$(NAME) ; \
 	fi
-	install -d "$(DESTDIR)$(prefix)/include/mlt/framework"
-	install -m 644 $(INCS) "$(DESTDIR)$(prefix)/include/mlt/framework"
+	install -d "$(DESTDIR)$(includedir)/mlt/framework"
+	install -m 644 $(INCS) "$(DESTDIR)$(includedir)/mlt/framework"
 	install -d "$(DESTDIR)$(mltdatadir)"
 	install -m 644 metaschema.yaml "$(DESTDIR)$(mltdatadir)"
 
@@ -148,7 +148,7 @@ uninstall:
 		fi ; \
 		rm -f "$(DESTDIR)$(libdir)/libmlt.def" ; \
 	fi
-	rm -rf "$(DESTDIR)$(prefix)/include/mlt/framework"
+	rm -rf "$(DESTDIR)$(includedir)/mlt/framework"
 	rm -f "$(DESTDIR)$(mltdatadir)/metaschema.yaml"
 
 ifneq ($(wildcard .depend),)
diff --git a/src/framework/configure b/src/framework/configure
index 601b20c..a16a566 100755
--- a/src/framework/configure
+++ b/src/framework/configure
@@ -1,4 +1,5 @@
 #!/bin/sh
-echo "framework	-I$prefix/include -I$prefix/include/mlt -D_REENTRANT	-L$libdir -lmlt" >> ../../packages.dat
+
+echo "framework	-I$includedir -I$includedir/mlt -D_REENTRANT	-L$libdir -lmlt" >> ../../packages.dat
 
 echo > config.mak
diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c
index 21f0240..f8241ca 100644
--- a/src/framework/mlt_consumer.c
+++ b/src/framework/mlt_consumer.c
@@ -1191,9 +1191,13 @@ static void consumer_work_start( mlt_consumer self )
 
 		priority.sched_priority = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( self ), "priority" );
 		pthread_attr_init( &thread_attributes );
+#ifndef __HAIKU__
 		pthread_attr_setschedpolicy( &thread_attributes, SCHED_OTHER );
+#endif
 		pthread_attr_setschedparam( &thread_attributes, &priority );
+#ifndef __HAIKU__
 		pthread_attr_setinheritsched( &thread_attributes, PTHREAD_EXPLICIT_SCHED );
+#endif
 		pthread_attr_setscope( &thread_attributes, PTHREAD_SCOPE_SYSTEM );
 
 		while ( n-- )
@@ -1779,9 +1783,13 @@ static void mlt_thread_create( mlt_consumer self, thread_function_t function )
 		{
 			pthread_attr_t thread_attributes;
 			pthread_attr_init( &thread_attributes );
+#ifndef __HAIKU__
 			pthread_attr_setschedpolicy( &thread_attributes, SCHED_OTHER );
+#endif
 			pthread_attr_setschedparam( &thread_attributes, &priority );
+#ifndef __HAIKU__
 			pthread_attr_setinheritsched( &thread_attributes, PTHREAD_EXPLICIT_SCHED );
+#endif
 			pthread_attr_setscope( &thread_attributes, PTHREAD_SCOPE_SYSTEM );
 			priv->ahead_thread = malloc( sizeof( pthread_t ) );
 			pthread_t *handle = priv->ahead_thread;
diff --git a/src/framework/mlt_slices.c b/src/framework/mlt_slices.c
index 60b17cd..63e5dae 100644
--- a/src/framework/mlt_slices.c
+++ b/src/framework/mlt_slices.c
@@ -200,7 +200,9 @@ mlt_slices mlt_slices_init( int threads, int policy, int priority )
 		policy = SCHED_OTHER;
 	if ( priority < 0 )
 		priority = sched_get_priority_max( policy );
+#ifndef __HAIKU__
 	pthread_attr_setschedpolicy( &tattr, policy );
+#endif
 	param.sched_priority = priority;
 	pthread_attr_setschedparam( &tattr, &param );
 
diff --git a/src/mlt++/Makefile b/src/mlt++/Makefile
index 5fe19b6..6bc97f5 100644
--- a/src/mlt++/Makefile
+++ b/src/mlt++/Makefile
@@ -86,8 +86,8 @@ install:
 		ln -sf $(TARGET) $(DESTDIR)$(libdir)/$(SONAME) ; \
 		ln -sf $(TARGET) $(DESTDIR)$(libdir)/$(NAME) ; \
 	fi
-	$(INSTALL) -d "$(DESTDIR)$(prefix)/include/mlt++"
-	$(INSTALL) -m 644 $(HEADERS) "$(DESTDIR)$(prefix)/include/mlt++"
+	$(INSTALL) -d "$(DESTDIR)$(includedir)/mlt++"
+	$(INSTALL) -m 644 $(HEADERS) "$(DESTDIR)$(includedir)/mlt++"
 
 uninstall:
 	rm -f "$(DESTDIR)$(libdir)/$(TARGET)"
@@ -104,7 +104,7 @@ uninstall:
 		fi ; \
 		rm -f "$(DESTDIR)$(libdir)/libmlt++.def" ; \
 	fi
-	rm -rf "$(DESTDIR)$(prefix)/include/mlt++"
+	rm -rf "$(DESTDIR)$(includedir)/mlt++"
 
 ifneq ($(wildcard .depend),)
 include .depend
diff --git a/src/mlt++/configure b/src/mlt++/configure
index 48e1fd9..432ca71 100755
--- a/src/mlt++/configure
+++ b/src/mlt++/configure
@@ -1,6 +1,6 @@
 #!/bin/sh
 echo "soversion=3" > config.mak
-echo "mlt++	-I$prefix/include -I$prefix/include/mlt++ -D_REENTRANT	-L$libdir -lmlt++" >> ../../packages.dat
+echo "mlt++	-I$includedir -I$includedir/mlt++ -D_REENTRANT	-L$libdir -lmlt++" >> ../../packages.dat
 
 WARNINGS="-W -Wwrite-strings -Wcast-qual -Wpointer-arith -Wcast-align -Wredundant-decls"
 
@@ -10,7 +10,7 @@ case $targetos in
                 echo "CXXFLAGS+=-Wall -fPIC"
 		echo "LIBFLAGS=-dynamiclib -single_module"
 		;;
-	Linux|FreeBSD|NetBSD|GNU/kFreeBSD|GNU)
+	Linux|FreeBSD|NetBSD|GNU/kFreeBSD|GNU|Haiku)
 		echo LIBSUF=.so
 		echo "CXXFLAGS+=-Wall $WARNINGS -fPIC -DPIC"
 		echo "LIBFLAGS=-shared"
diff --git a/src/modules/decklink/consumer_decklink.cpp b/src/modules/decklink/consumer_decklink.cpp
index 2ffdef0..c659c64 100644
--- a/src/modules/decklink/consumer_decklink.cpp
+++ b/src/modules/decklink/consumer_decklink.cpp
@@ -657,7 +657,9 @@ protected:
 			return;
 
 		pthread_attr_init(&tattr);
+#ifndef __HAIKU__
 		pthread_attr_setschedpolicy(&tattr, SCHED_FIFO);
+#endif
 
 		if ( !strcmp( "max", mlt_properties_get( properties, "priority" ) ) )
 			param.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1;
diff --git a/src/modules/decklink/producer_decklink.cpp b/src/modules/decklink/producer_decklink.cpp
index 43e7fa4..75a7c5d 100644
--- a/src/modules/decklink/producer_decklink.cpp
+++ b/src/modules/decklink/producer_decklink.cpp
@@ -457,7 +457,9 @@ public:
 				struct sched_param param;
 
 				pthread_attr_init(&tattr);
+#ifndef __HAIKU__
 				pthread_attr_setschedpolicy(&tattr, SCHED_FIFO);
+#endif
 
 				if ( !strcmp( "max", mlt_properties_get( properties, "priority" ) ) )
 					param.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1;
-- 
2.24.1


From 62fb1f5235e41426c4dd095a3a394d6640357b4b Mon Sep 17 00:00:00 2001
From: begasus <begasus@gmail.com>
Date: Tue, 21 Jan 2020 09:51:23 +0000
Subject: Fix SDL module


diff --git a/src/modules/sdl/Makefile b/src/modules/sdl/Makefile
index b789750..3a6f0cd 100644
--- a/src/modules/sdl/Makefile
+++ b/src/modules/sdl/Makefile
@@ -22,6 +22,8 @@ endif
 ifeq ($(targetos),Darwin)
 CFLAGS += -ObjC
 LDFLAGS += -lobjc -framework Foundation
+else ifeq ($(targetos), Haiku)
+LDFLAGS +=
 else ifneq ($(targetos), MinGW)
 LDFLAGS += -lX11
 endif
diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c
index 7de5309..10435ee 100644
--- a/src/modules/sdl/consumer_sdl.c
+++ b/src/modules/sdl/consumer_sdl.c
@@ -936,7 +936,7 @@ static int consumer_get_dimensions( int *width, int *height )
 	// Get the wm structure
 	if ( SDL_GetWMInfo( &wm ) == 1 )
 	{
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__HAIKU__)
 		// Check that we have the X11 wm
 		if ( wm.subsystem == SDL_SYSWM_X11 ) 
 		{
diff --git a/src/modules/sdl/consumer_sdl_still.c b/src/modules/sdl/consumer_sdl_still.c
index cc1fe28..1cc84fd 100644
--- a/src/modules/sdl/consumer_sdl_still.c
+++ b/src/modules/sdl/consumer_sdl_still.c
@@ -604,7 +604,7 @@ static int consumer_get_dimensions( int *width, int *height )
 	// Get the wm structure
 	if ( SDL_GetWMInfo( &wm ) == 1 )
 	{
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__HAIKU__)
 		// Check that we have the X11 wm
 		if ( wm.subsystem == SDL_SYSWM_X11 ) 
 		{
-- 
2.24.1


From 817770b0895be8a5c452b969f08d2bcae24a7cca Mon Sep 17 00:00:00 2001
From: begasus <begasus@gmail.com>
Date: Tue, 21 Jan 2020 09:52:54 +0000
Subject: Fix SDL2 module


diff --git a/src/modules/sdl2/Makefile b/src/modules/sdl2/Makefile
index 032d33d..51c1009 100644
--- a/src/modules/sdl2/Makefile
+++ b/src/modules/sdl2/Makefile
@@ -16,6 +16,8 @@ OBJS = factory.o \
 ifeq ($(targetos),Darwin)
 CFLAGS += -ObjC
 LDFLAGS += -lobjc -framework Foundation
+else ifeq ($(targetos), Haiku)
+LDFLAGS +=
 else ifneq ($(targetos), MinGW)
 LDFLAGS += -lX11
 endif
-- 
2.24.1


