From be0a143e159ab7885ede1e8f3f944e9f30b9edd4 Mon Sep 17 00:00:00 2001 From: Alexander Pavlov Date: Sat, 18 Nov 2023 23:04:31 +0300 Subject: [PATCH] Added install to system for FreeBSD and OpenBSD. --- CMakeLists.txt | 1 + README.md | 1 + SamTFE/Sources/CMakeLists.txt | 47 +++++++++++++++++++------------- SamTFE/Sources/Engine/Engine.cpp | 25 +++++++++++++++++ SamTSE/Sources/CMakeLists.txt | 47 +++++++++++++++++++------------- SamTSE/Sources/Engine/Engine.cpp | 25 +++++++++++++++++ 6 files changed, 108 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95c9cfe9..5aa32c7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ option(USE_SYSTEM_SDL2 "Use systems sdl2 development files" On) option(USE_SYSTEM_ZLIB "Use systems zlib development files" On) option(USE_SYSTEM_VULKAN "Use systems vulkan development files" On) option(USE_CCACHE "Set to ON to use ccache if present in the system" ${USE_CCACHE}) +option(USE_SYSTEM_INSTALL "Install to systems directories" Off) # fallback for cmake versions without add_compile_options # RAKE! Borrowed from dhewm3 project if(NOT COMMAND add_compile_options) diff --git a/README.md b/README.md index 14f331b2..42581887 100644 --- a/README.md +++ b/README.md @@ -408,6 +408,7 @@ Supported OS ----------- * `Linux` * `FreeBSD` +* `OpenBSD` * `Windows` * `Raspberry PI OS` * `macOS` diff --git a/SamTFE/Sources/CMakeLists.txt b/SamTFE/Sources/CMakeLists.txt index bc73ab78..07b65c87 100644 --- a/SamTFE/Sources/CMakeLists.txt +++ b/SamTFE/Sources/CMakeLists.txt @@ -13,6 +13,7 @@ option(USE_SYSTEM_SDL2 "Use systems sdl2 development files" On) option(USE_SYSTEM_ZLIB "Use systems zlib development files" On) option(USE_SYSTEM_VULKAN "Use systems vulkan development files" On) option(USE_CCACHE "Set to ON to use ccache if present in the system" ${USE_CCACHE}) +option(USE_SYSTEM_INSTALL "Install to systems directories" Off) # fallback for cmake versions without add_compile_options # RAKE! Borrowed from dhewm3 project if(NOT COMMAND add_compile_options) @@ -126,6 +127,21 @@ endif() ############################################################### ############################################################### +# Set up some sanity stuff... +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU|kFreeBSD") + SET(LINUX TRUE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format") +endif() +if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + SET(FREEBSD TRUE) +endif() +if(APPLE) + SET(MACOSX TRUE) +endif() +if(MSVC) + SET(WINDOWS TRUE) +endif() # RAKE! Where to install the binaries. if(CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" OR CMAKE_INSTALL_PREFIX STREQUAL "") # Only works for linux since I don't @@ -139,12 +155,17 @@ if(CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" OR CMAKE_INSTALL_PREFIX STREQUAL " else() set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../") # set install path to project root directory since endif() # since one wasn't set during config - set(LOCAL_INSTALL TRUE) - message(STATUS "Using LOCAL Install") + if(NOT USE_SYSTEM_INSTALL) + set(LOCAL_INSTALL TRUE) + message(STATUS "Using LOCAL Install") + endif() endif() -if(CMAKE_INSTALL_PREFIX STREQUAL "/usr" ) # Only works for linux since I don't know what default is for windows/macos/freebsd. +if(CMAKE_INSTALL_PREFIX STREQUAL "/usr" OR USE_SYSTEM_INSTALL) set(LOCAL_INSTALL FALSE) message(STATUS "Using SYSTEM Install") + if(FREEBSD) + set(CMAKE_INSTALL_PREFIX "/usr/local") + endif() endif() # ImageMagic needed for SYSTEM INSTALL @@ -157,22 +178,6 @@ if(NOT LOCAL_INSTALL) endif() endif() -# Set up some sanity stuff... -if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU|kFreeBSD") - SET(LINUX TRUE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format") -endif() -if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") - SET(FREEBSD TRUE) -endif() -if(APPLE) - SET(MACOSX TRUE) -endif() -if(MSVC) - SET(WINDOWS TRUE) -endif() - # remove clang spam. if(MACOSX OR FREEBSD) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-nullability-completeness") @@ -243,6 +248,10 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(CMAKE_INSTALL_LIBDIR "/usr/lib64") endif() +if(FREEBSD) + set(CMAKE_INSTALL_LIBDIR "/usr/local/lib") +endif() + message(STATUS "Arch bits: ${CMAKE_ARCH_BITS}") if(DEBIAN_FOUND OR UBUNTU_FOUND) diff --git a/SamTFE/Sources/Engine/Engine.cpp b/SamTFE/Sources/Engine/Engine.cpp index 90849edf..e99bf34d 100644 --- a/SamTFE/Sources/Engine/Engine.cpp +++ b/SamTFE/Sources/Engine/Engine.cpp @@ -742,7 +742,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) CPrintF(TRANSV("Running %d-bit version\n"), sys_iGameBits); #ifdef PLATFORM_UNIX +#ifdef PLATFORM_FREEBSD + int _isystempath = strncmp((const char *)strExePath, (const char *) "/usr/local/bin/", (size_t) 15 ); +#else int _isystempath = strncmp((const char *)strExePath, (const char *) "/usr/bin/", (size_t) 9 ); +#endif if( _isystempath == 0 ) { sys_iSysPath = 1; // using system path } else { @@ -751,6 +755,10 @@ ENGINE_API void SE_InitEngine(CTString strGameID) // get library path for mods _fnmModLibPath = ""; +#ifdef PLATFORM_FREEBSD + if( sys_iSysPath == 1 ) { + _fnmModLibPath = "/usr/local/lib/" + strGameID + "/"; +#else if( sys_iSysPath == 1 && sys_iGameBits == 64 && _pFileSystem->IsDirectory((const char *) "/usr/lib/aarch64-linux-gnu/" + strGameID)) { _fnmModLibPath = "/usr/lib/aarch64-linux-gnu/" + strGameID + "/"; } else if( sys_iSysPath == 1 && sys_iGameBits == 32 && _pFileSystem->IsDirectory((const char *) "/usr/lib/arm-linux-gnueabihf/" + strGameID)) { @@ -769,6 +777,7 @@ ENGINE_API void SE_InitEngine(CTString strGameID) _fnmModLibPath = "/usr/lib64/" + strGameID + "/"; } else if( sys_iSysPath == 1 && sys_iGameBits == 32 && _pFileSystem->IsDirectory((const char *) "/usr/lib//" + strGameID)) { _fnmModLibPath = "/usr/lib/" + strGameID + "/"; +#endif } else if( sys_iSysPath == 0 ) { _fnmModLibPath = _fnmApplicationPath; } else { @@ -798,7 +807,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) _fnm_TestFile = "1_00_music.gro"; } CPrintF(TRANSV("Testing file: %s\n"), (const char *) _fnm_TestFile); +#ifdef PLATFORM_FREEBSD + _fnm_usr_TestFile = "/usr/local/share/" + strGameID + "/" + _fnm_TestFile; // data in usr +#else _fnm_usr_TestFile = "/usr/share/" + strGameID + "/" + _fnm_TestFile; // data in usr +#endif _fnm_local_TestFile = _fnmUserDir + _fnm_TestFile; // data in home .local _fnm_home_TestFile = (const char *)_fnmUserDataPath + _fnm_TestFile; // test @@ -806,7 +819,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) CPrintF(TRANSV("Testing system path: %s\n"), (const char *) _fnm_usr_TestFile); CPrintF(TRANSV("Testing local path: %s\n"), (const char *) _fnm_local_TestFile); if( access((const char *) _fnm_usr_TestFile, F_OK) == 0 ) { +#ifdef PLATFORM_FREEBSD + _fnmApplicationPath = "/usr/local/share/" + strGameID + "/"; // all game data +#else _fnmApplicationPath = "/usr/share/" + strGameID + "/"; // all game data +#endif CPrintF(TRANSV("Found usr path: %s\n"), (const char *) _fnmUserDataPath); } else if( access((const char *) _fnm_local_TestFile, F_OK) == 0 ) { _fnmApplicationPath = _fnmUserDir; // all game data @@ -814,7 +831,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) } else { // search in home dir // BOOL YesNoMessage(const char *strFormat, ...) +#ifdef PLATFORM_FREEBSD + InfoMessage(TRANS("No game files were found in /usr/local/share/%s/\n or %s\nThe home directory will be searched."),(const char *) strGameID,(const char *) _fnmUserDir); +#else InfoMessage(TRANS("No game files were found in /usr/share/%s/\n or %s\nThe home directory will be searched."),(const char *) strGameID,(const char *) _fnmUserDir); +#endif struct passwd *pw = getpwuid(getuid()); const char *_homedir = pw->pw_dir; _testfiledone = 0; @@ -832,7 +853,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) } else { CPrintF(TRANSV("ERROR: Game data not ound!\n")); _fnmUserDataPath = ""; +#ifdef PLATFORM_FREEBSD + FatalError(TRANSV("Failed to search game data!\nPlease put the game data in the paths:\n/usr/local/share/%s/\n or %s\n or somewhere in your home directory\nSee the log for more details.\nGame log is here: ~/.local/share/Serious-Engine/%s/SeriousSam.log"),(const char *) strGameID,(const char *) _fnmUserDir,(const char *) strGameID); +#else FatalError(TRANSV("Failed to search game data!\nPlease put the game data in the paths:\n/usr/share/%s/\n or %s\n or somewhere in your home directory\nSee the log for more details.\nGame log is here: ~/.local/share/Serious-Engine/%s/SeriousSam.log"),(const char *) strGameID,(const char *) _fnmUserDir,(const char *) strGameID); +#endif } } } else { diff --git a/SamTSE/Sources/CMakeLists.txt b/SamTSE/Sources/CMakeLists.txt index 96913685..5e9a8214 100644 --- a/SamTSE/Sources/CMakeLists.txt +++ b/SamTSE/Sources/CMakeLists.txt @@ -13,6 +13,7 @@ option(USE_SYSTEM_SDL2 "Use systems sdl2 development files" On) option(USE_SYSTEM_ZLIB "Use systems zlib development files" On) option(USE_SYSTEM_VULKAN "Use systems vulkan development files" On) option(USE_CCACHE "Set to ON to use ccache if present in the system" ${USE_CCACHE}) +option(USE_SYSTEM_INSTALL "Install to systems directories" Off) # fallback for cmake versions without add_compile_options # RAKE! Borrowed from dhewm3 project if(NOT COMMAND add_compile_options) @@ -126,6 +127,21 @@ endif() ############################################################### ############################################################### +# Set up some sanity stuff... +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU|kFreeBSD") + SET(LINUX TRUE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format") +endif() +if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + SET(FREEBSD TRUE) +endif() +if(APPLE) + SET(MACOSX TRUE) +endif() +if(MSVC) + SET(WINDOWS TRUE) +endif() # RAKE! Where to install the binaries. if(CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" OR CMAKE_INSTALL_PREFIX STREQUAL "") # Only works for linux since I don't @@ -139,12 +155,17 @@ if(CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" OR CMAKE_INSTALL_PREFIX STREQUAL " else() set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../") # set install path to project root directory since endif() # since one wasn't set during config - set(LOCAL_INSTALL TRUE) - message(STATUS "Using LOCAL Install") + if(NOT USE_SYSTEM_INSTALL) + set(LOCAL_INSTALL TRUE) + message(STATUS "Using LOCAL Install") + endif() endif() -if(CMAKE_INSTALL_PREFIX STREQUAL "/usr" ) # Only works for linux since I don't know what default is for windows/macos/freebsd. +if(CMAKE_INSTALL_PREFIX STREQUAL "/usr" OR USE_SYSTEM_INSTALL) set(LOCAL_INSTALL FALSE) message(STATUS "Using SYSTEM Install") + if(FREEBSD) + set(CMAKE_INSTALL_PREFIX "/usr/local") + endif() endif() # ImageMagic needed for SYSTEM INSTALL @@ -157,22 +178,6 @@ if(NOT LOCAL_INSTALL) endif() endif() -# Set up some sanity stuff... -if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU|kFreeBSD") - SET(LINUX TRUE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format") -endif() -if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") - SET(FREEBSD TRUE) -endif() -if(APPLE) - SET(MACOSX TRUE) -endif() -if(MSVC) - SET(WINDOWS TRUE) -endif() - # remove clang spam. if(MACOSX OR FREEBSD) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-nullability-completeness") @@ -243,6 +248,10 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(CMAKE_INSTALL_LIBDIR "/usr/lib64") endif() +if(FREEBSD) + set(CMAKE_INSTALL_LIBDIR "/usr/local/lib") +endif() + message(STATUS "Arch bits: ${CMAKE_ARCH_BITS}") if(DEBIAN_FOUND OR UBUNTU_FOUND) diff --git a/SamTSE/Sources/Engine/Engine.cpp b/SamTSE/Sources/Engine/Engine.cpp index 90849edf..e99bf34d 100644 --- a/SamTSE/Sources/Engine/Engine.cpp +++ b/SamTSE/Sources/Engine/Engine.cpp @@ -742,7 +742,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) CPrintF(TRANSV("Running %d-bit version\n"), sys_iGameBits); #ifdef PLATFORM_UNIX +#ifdef PLATFORM_FREEBSD + int _isystempath = strncmp((const char *)strExePath, (const char *) "/usr/local/bin/", (size_t) 15 ); +#else int _isystempath = strncmp((const char *)strExePath, (const char *) "/usr/bin/", (size_t) 9 ); +#endif if( _isystempath == 0 ) { sys_iSysPath = 1; // using system path } else { @@ -751,6 +755,10 @@ ENGINE_API void SE_InitEngine(CTString strGameID) // get library path for mods _fnmModLibPath = ""; +#ifdef PLATFORM_FREEBSD + if( sys_iSysPath == 1 ) { + _fnmModLibPath = "/usr/local/lib/" + strGameID + "/"; +#else if( sys_iSysPath == 1 && sys_iGameBits == 64 && _pFileSystem->IsDirectory((const char *) "/usr/lib/aarch64-linux-gnu/" + strGameID)) { _fnmModLibPath = "/usr/lib/aarch64-linux-gnu/" + strGameID + "/"; } else if( sys_iSysPath == 1 && sys_iGameBits == 32 && _pFileSystem->IsDirectory((const char *) "/usr/lib/arm-linux-gnueabihf/" + strGameID)) { @@ -769,6 +777,7 @@ ENGINE_API void SE_InitEngine(CTString strGameID) _fnmModLibPath = "/usr/lib64/" + strGameID + "/"; } else if( sys_iSysPath == 1 && sys_iGameBits == 32 && _pFileSystem->IsDirectory((const char *) "/usr/lib//" + strGameID)) { _fnmModLibPath = "/usr/lib/" + strGameID + "/"; +#endif } else if( sys_iSysPath == 0 ) { _fnmModLibPath = _fnmApplicationPath; } else { @@ -798,7 +807,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) _fnm_TestFile = "1_00_music.gro"; } CPrintF(TRANSV("Testing file: %s\n"), (const char *) _fnm_TestFile); +#ifdef PLATFORM_FREEBSD + _fnm_usr_TestFile = "/usr/local/share/" + strGameID + "/" + _fnm_TestFile; // data in usr +#else _fnm_usr_TestFile = "/usr/share/" + strGameID + "/" + _fnm_TestFile; // data in usr +#endif _fnm_local_TestFile = _fnmUserDir + _fnm_TestFile; // data in home .local _fnm_home_TestFile = (const char *)_fnmUserDataPath + _fnm_TestFile; // test @@ -806,7 +819,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) CPrintF(TRANSV("Testing system path: %s\n"), (const char *) _fnm_usr_TestFile); CPrintF(TRANSV("Testing local path: %s\n"), (const char *) _fnm_local_TestFile); if( access((const char *) _fnm_usr_TestFile, F_OK) == 0 ) { +#ifdef PLATFORM_FREEBSD + _fnmApplicationPath = "/usr/local/share/" + strGameID + "/"; // all game data +#else _fnmApplicationPath = "/usr/share/" + strGameID + "/"; // all game data +#endif CPrintF(TRANSV("Found usr path: %s\n"), (const char *) _fnmUserDataPath); } else if( access((const char *) _fnm_local_TestFile, F_OK) == 0 ) { _fnmApplicationPath = _fnmUserDir; // all game data @@ -814,7 +831,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) } else { // search in home dir // BOOL YesNoMessage(const char *strFormat, ...) +#ifdef PLATFORM_FREEBSD + InfoMessage(TRANS("No game files were found in /usr/local/share/%s/\n or %s\nThe home directory will be searched."),(const char *) strGameID,(const char *) _fnmUserDir); +#else InfoMessage(TRANS("No game files were found in /usr/share/%s/\n or %s\nThe home directory will be searched."),(const char *) strGameID,(const char *) _fnmUserDir); +#endif struct passwd *pw = getpwuid(getuid()); const char *_homedir = pw->pw_dir; _testfiledone = 0; @@ -832,7 +853,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) } else { CPrintF(TRANSV("ERROR: Game data not ound!\n")); _fnmUserDataPath = ""; +#ifdef PLATFORM_FREEBSD + FatalError(TRANSV("Failed to search game data!\nPlease put the game data in the paths:\n/usr/local/share/%s/\n or %s\n or somewhere in your home directory\nSee the log for more details.\nGame log is here: ~/.local/share/Serious-Engine/%s/SeriousSam.log"),(const char *) strGameID,(const char *) _fnmUserDir,(const char *) strGameID); +#else FatalError(TRANSV("Failed to search game data!\nPlease put the game data in the paths:\n/usr/share/%s/\n or %s\n or somewhere in your home directory\nSee the log for more details.\nGame log is here: ~/.local/share/Serious-Engine/%s/SeriousSam.log"),(const char *) strGameID,(const char *) _fnmUserDir,(const char *) strGameID); +#endif } } } else {