Skip to content

Commit

Permalink
Added install to system for FreeBSD and OpenBSD.
Browse files Browse the repository at this point in the history
  • Loading branch information
tx00100xt committed Nov 18, 2023
1 parent 243b2b1 commit be0a143
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 38 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ Supported OS
-----------
* `Linux`
* `FreeBSD`
* `OpenBSD`
* `Windows`
* `Raspberry PI OS`
* `macOS`
Expand Down
47 changes: 28 additions & 19 deletions SamTFE/Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions SamTFE/Sources/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)) {
Expand All @@ -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 {
Expand Down Expand Up @@ -798,23 +807,35 @@ 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
if( access((const char *) _fnm_home_TestFile, F_OK) != 0 ) {
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
CPrintF(TRANSV("Found local path: %s\n"), (const char *) _fnmUserDataPath);
} 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;
Expand All @@ -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 {
Expand Down
47 changes: 28 additions & 19 deletions SamTSE/Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions SamTSE/Sources/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)) {
Expand All @@ -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 {
Expand Down Expand Up @@ -798,23 +807,35 @@ 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
if( access((const char *) _fnm_home_TestFile, F_OK) != 0 ) {
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
CPrintF(TRANSV("Found local path: %s\n"), (const char *) _fnmUserDataPath);
} 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;
Expand All @@ -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 {
Expand Down

0 comments on commit be0a143

Please sign in to comment.