From a2b274d1a5d5a076433003e81f7c972db2dcddf8 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 20 Jun 2020 15:37:21 +0000 Subject: [PATCH 1/3] Haiku porting proposal. --- CMakeLists.txt | 6 +++++- src/backends/generic/misc.c | 20 ++++++++++++++++++++ src/backends/unix/main.c | 3 +++ src/backends/unix/system.c | 3 +++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a600c4ca..008f97df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,7 +140,11 @@ endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") list(APPEND yquake2LinkerFlags "-lm -static-libgcc") else() - list(APPEND yquake2LinkerFlags "-lm -rdynamic") + if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Haiku") + list(APPEND yquake2LinkerFlags "-lm -rdynamic") + else() + list(APPEND yquake2LinkerFlags "-lm -lnetwork") + endif() endif() list(APPEND yquake2LinkerFlags ${CMAKE_DL_LIBS}) diff --git a/src/backends/generic/misc.c b/src/backends/generic/misc.c index 973a2cba..aef164ee 100644 --- a/src/backends/generic/misc.c +++ b/src/backends/generic/misc.c @@ -45,6 +45,10 @@ #include // _NSGetExecutablePath #endif +#ifdef __HAIKU__ +#include +#endif + #ifndef PATH_MAX // this is mostly for windows. windows has a MAX_PATH = 260 #define, but allows // longer paths anyway.. this might not be the maximum allowed length, but is @@ -118,6 +122,22 @@ static void SetExecutablePath(char* exePath) // TODO: realpath() ? // TODO: no idea what this is if the executable is in an app bundle +#elif defined(__HAIKU__) + image_info ii; + int32_t id = 0; + + exePath[0] = '\0'; + + for (; get_next_image_info(0, &id, &ii) == B_OK;) + { + if (ii.type == B_APP_IMAGE) + break; + } + + if (ii.type == B_APP_IMAGE) + { + memcpy(exePath, ii.name, PATH_MAX); + } #else diff --git a/src/backends/unix/main.c b/src/backends/unix/main.c index a5e5702c..06bc2ea7 100644 --- a/src/backends/unix/main.c +++ b/src/backends/unix/main.c @@ -30,6 +30,9 @@ #include #include #include +#ifndef FNDELAY +#define FNDELAY O_NDELAY +#endif #include "../../common/header/common.h" diff --git a/src/backends/unix/system.c b/src/backends/unix/system.c index 784362ae..b2d7c992 100644 --- a/src/backends/unix/system.c +++ b/src/backends/unix/system.c @@ -35,6 +35,9 @@ #include #include #include /* for fd_set */ +#ifndef FNDELAY +#define FNDELAY O_NDELAY +#endif #ifdef __APPLE__ #include From 6c4187a6e33131b61625c780130f0ae3346cee54 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 21 Jun 2020 11:00:20 +0000 Subject: [PATCH 2/3] using custom sting copy fn instead --- src/backends/generic/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/generic/misc.c b/src/backends/generic/misc.c index aef164ee..ecfaf620 100644 --- a/src/backends/generic/misc.c +++ b/src/backends/generic/misc.c @@ -136,7 +136,7 @@ static void SetExecutablePath(char* exePath) if (ii.type == B_APP_IMAGE) { - memcpy(exePath, ii.name, PATH_MAX); + Q_strlcpy(exePath, ii.name, PATH_MAX); } #else From 3e63226bad8c45a781aeab98a22aa7171ec31fc8 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 26 Jun 2020 12:43:06 +0000 Subject: [PATCH 3/3] Translate changes to the Makefile build too --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 44cff701..b3e5aa41 100755 --- a/Makefile +++ b/Makefile @@ -277,6 +277,8 @@ else ifeq ($(YQ2_OSTYPE),Windows) override LDFLAGS += -lws2_32 -lwinmm -static-libgcc else ifeq ($(YQ2_OSTYPE), Darwin) override LDFLAGS += -arch $(YQ2_ARCH) +else ifeq ($(YQ2_OSTYPE), Haiku) +override LDFLAGS += -lm -lnetwork endif # Keep symbols hidden.