From 480f35785b23c25194d5b6c00df041597e6547ac Mon Sep 17 00:00:00 2001
From: Augustin Cavalier <waddlesplash@gmail.com>
Date: Sat, 13 Dec 2014 18:01:23 -0500
Subject: [PATCH] Fix build on Haiku.

---
 Makefile           | 16 ++++++++--------
 config.h           |  1 -
 main/main.c        | 11 ++++++-----
 rsp_hle/wintypes.h | 12 ++++--------
 4 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/Makefile b/Makefile
index e1370e5..ffdc78d 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ CC		=gcc
 CXX		=g++
 
 #CFLAGS		=-DX86 -O3 -mpentium -Wall -DEMU64_DEBUG
-CFLAGS		=-DX86 -O3 -fexpensive-optimizations -fomit-frame-pointer -funroll-loops -ffast-math -fno-strict-aliasing -mcpu=athlon -Wall -pipe
+CFLAGS		=-DX86 -O3 -fexpensive-optimizations -fomit-frame-pointer -funroll-loops -ffast-math -fno-strict-aliasing -Wall -pipe -DWITH_HOME=\"$(WITH_HOME)\" -DNOGUI_VERSION
 #CFLAGS		=-DX86 -O3 -mcpu=pentium -Wall -g -pg
 #CFLAGS		=-DX86 -Wall -pipe -g3 -DEMU64_DEBUG
 #CFLAGS		=-DX86 -Wall -pipe -g -DEMU64_DEBUG -DCOMPARE_CORE
@@ -153,7 +153,7 @@ HEADER		=main/rom.h \
 		r4300/recomp.h \
 		memory/pif.h
 
-LIB		=-lz -lm
+LIB		=-lz
 
 ifneq ("$(shell grep GTK2 config.h)","\#define GTK2_SUPPORT 1")
 GTK_FLAGS	=`gtk-config --cflags`
@@ -206,7 +206,7 @@ main/gui_gtk/romproperties.o:	main/gui_gtk/romproperties.c
 				$(CC) $(CFLAGS) -c -o $@ $< $(GTK_FLAGS)
 
 main/gui_gtk/config.o:		main/gui_gtk/config.c
-				$(CC) $(CFLAGS) -c -o $@ $< $(GTK_FLAGS)
+				$(CC) $(CFLAGS) -c -o $@ $<
 
 main/gui_gtk/dirbrowser.o:	main/gui_gtk/dirbrowser.c
 				$(CC) $(CFLAGS) -c -o $@ $< $(GTK_FLAGS)
@@ -218,7 +218,7 @@ main/vcr_compress.o:		main/vcr_compress.cpp
 				$(CXX) $(CXXFLAGS) -c -o $@ $< `avifile-config --cflags`
 
 mupen64_input/main.o:		mupen64_input/main.c
-				$(CC) $(CFLAGS) -DUSE_GTK -c -o $@ $< $(GTK_FLAGS) `sdl-config --cflags`
+				$(CC) $(CFLAGS) -c -o $@ $< `sdl-config --cflags`
 
 blight_input/plugin.o:		blight_input/plugin.c
 				$(CC) $(CFLAGS) "-DPACKAGE=\"$(shell grep PACKAGE blight_input/package | cut -d "=" -f 2)\"" "-DVERSION=\"$(shell grep VERSION blight_input/package | cut -d "=" -f 2)\"" `sdl-config --cflags` -DGUI_SDL -c -o $@ $<
@@ -243,13 +243,13 @@ blight_input/pad.o:		blight_input/pad.c
 				$(CC) $(CFLAGS) -DGUI_SDL -c -o $@ $<
 
 rsp_hle/main.o:			rsp_hle/main.c
-				$(CC) $(CFLAGS) $(GTK_FLAGS) -DUSE_GTK -c -o $@ $<
+				$(CC) $(CFLAGS) -c -o $@ $<
 
 mupen64_audio/main.o:		mupen64_audio/main.c
 				$(CC) $(CFLAGS) $(GTK_FLAGS) -DUSE_GTK -c -o $@ $<
 
 jttl_audio/main.o:		jttl_audio/main.c
-				$(CC) $(CFLAGS) $(GTK_FLAGS) -DUSE_GTK `sdl-config --cflags` -c -o $@ $<
+				$(CC) $(CFLAGS) `sdl-config --cflags` -c -o $@ $<
 
 mupen64_soft_gfx/main.o:	mupen64_soft_gfx/main.cpp
 				$(CXX) $(CFLAGS) `sdl-config --cflags` -c -o $@ $<
@@ -342,7 +342,7 @@ glN64/F3DWRUS.o:		glN64/F3DWRUS.cpp
 				$(CXX) $(CFLAGS) -D__LINUX__ -DX86_ASM `sdl-config --cflags` -c -o $@ $<
 
 mupen64_nogui:	$(OBJ) $(OBJ_X86) main/main.o main/gui_gtk/config.o
-		$(CC) $^ $(LIB) -Wl,-export-dynamic -L/usr/X11R6/lib `sdl-config --libs` -lGL -lpthread -ldl -o $@
+		$(CC) $^ $(LIB) -Wl,-export-dynamic -L/usr/X11R6/lib `sdl-config --libs` -lGL -o $@
 		strip --strip-all $@
 
 ifneq ("$(shell grep VCR config.h)","\#define VCR_SUPPORT 1")
@@ -363,7 +363,7 @@ mupen64_oldgui:	$(OBJ) $(OBJ_X86) main/main_gtk.o
 		strip --strip-all $@
 
 plugins/mupen64_input.so: $(OBJ_INPUT)
-			  $(CC) $^ -Wl,-Bsymbolic -shared $(GTK_LIBS) -o $@
+			  $(CC) $^ -Wl,-Bsymbolic -shared -o $@
 			  strip --strip-all $@
 
 plugins/blight_input.so: $(OBJ_BLIGHT)
diff --git a/config.h b/config.h
index f2ef9b7..303d655 100644
--- a/config.h
+++ b/config.h
@@ -1,7 +1,6 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
-#undef WITH_HOME
 #undef VCR_SUPPORT
 #define GTK2_SUPPORT 1
 
diff --git a/main/main.c b/main/main.c
index 00a12a0..78ed1c9 100644
--- a/main/main.c
+++ b/main/main.c
@@ -37,6 +37,7 @@
 
 #include <stdlib.h>
 #include <unistd.h>
+#include <dirent.h>
 
 #include "main.h"
 #include "guifuncs.h"
@@ -263,7 +264,7 @@ int main (int argc, char *argv[])
 	     unsigned char byte;
 	     dest = fopen(temp, "wb");
 	     strcpy(orig, WITH_HOME);
-	     strcat(orig, "share/mupen64/mupen64.ini");
+	     strcat(orig, "data/mupen64/mupen64.ini");
 	     src = fopen(orig, "rb");
 	     while(fread(&byte, 1, 1, src))
 	       fwrite(&byte, 1, 1, dest);
@@ -275,7 +276,7 @@ int main (int argc, char *argv[])
 	strcpy(temp, g_WorkingDir);
 	strcat(temp, "lang");
 	strcpy(orig, WITH_HOME);
-	strcat(orig, "share/mupen64/lang");
+	strcat(orig, "data/mupen64/lang");
 	symlink(orig, temp);
 	
 	/*strcpy(temp, g_WorkingDir);
@@ -288,14 +289,14 @@ int main (int argc, char *argv[])
 	strcat(temp, "plugins");
 	mkdir(temp, 0700);
 	strcpy(orig, WITH_HOME);
-	strcat(orig, "share/mupen64/plugins");
+	strcat(orig, "data/mupen64/plugins");
 	dir = opendir(orig);
 	while((entry = readdir(dir)) != NULL)
 	  {
 	     if(strcmp(entry->d_name + strlen(entry->d_name) - 3, ".so"))
 	       {
 		  strcpy(orig, WITH_HOME);
-		  strcat(orig, "share/mupen64/plugins/");
+		  strcat(orig, "data/mupen64/plugins/");
 		  strcat(orig, entry->d_name);
 		  src = fopen(orig, "rb");
 		  if(src == NULL) continue;
@@ -321,7 +322,7 @@ int main (int argc, char *argv[])
 		  strcat(temp, "plugins/");
 		  strcat(temp, entry->d_name);
 		  strcpy(orig, WITH_HOME);
-		  strcat(orig, "share/mupen64/plugins/");
+		  strcat(orig, "data/mupen64/plugins/");
 		  strcat(orig, entry->d_name);
 		  symlink(orig, temp);
 	       }
diff --git a/rsp_hle/wintypes.h b/rsp_hle/wintypes.h
index 7e01c9d..0d820b2 100644
--- a/rsp_hle/wintypes.h
+++ b/rsp_hle/wintypes.h
@@ -1,7 +1,7 @@
 #ifndef __WINTYPES_H__
 #define __WINTYPES_H__
 
-#include <sys/types.h>
+#include <SupportDefs.h>
 
 typedef int HWND;
 typedef int HINSTANCE;
@@ -12,14 +12,10 @@ typedef void* LPVOID;
 #define _cdecl
 #define WINAPI
 
-typedef u_int32_t		DWORD;
-typedef u_int16_t		WORD;
-typedef u_int8_t			BYTE, byte;
+typedef uint32		DWORD;
+typedef uint16		WORD;
+typedef uint8			BYTE, byte;
 typedef int			BOOL, BOOLEAN;
-#define __int8                  char
-#define __int16                 short
-#define __int32	                int
-#define __int64                 long long
 
 /** HRESULT stuff **/
 typedef long				HRESULT;
-- 
1.8.3.4

