From 32cec1e3d094985c241243ba8d7ce01f86a5ff12 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Thu, 5 May 2016 14:20:09 +0200 Subject: [PATCH 1/6] Apply sys and user dirs patch by @nvinson --- .gitignore | 5 +-- src/CGame.cpp | 6 +++- src/CMainMenu.cpp | 6 ++-- src/CSdl.cpp | 18 +++++++--- src/CSounds.cpp | 33 ++++++++++++----- src/CSwv_module.cpp | 2 -- src/Main.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++- src/Main.h | 9 +++-- src/Utils.cpp | 2 +- 9 files changed, 144 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 516daa9..2d3827f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,8 +20,9 @@ nbproject/* # src src/Config.h +*.orig +*.rej # others debug.html - - +*.patch diff --git a/src/CGame.cpp b/src/CGame.cpp index aecd6b6..60d38b7 100644 --- a/src/CGame.cpp +++ b/src/CGame.cpp @@ -118,6 +118,7 @@ bool CGame::LoadGame() { char buf[255]; int i = 0; + String tmp (sys_datadir); AppendToLog( LOG_DASH ); AppendToLog("Loading Game..."); @@ -163,7 +164,10 @@ bool CGame::LoadGame() UpdateSplash(); // UPDATESPLASH... // search for vehicles - if ( Swv.SearchAndLoad( "autos" ) != SWV_SUCCESS ) return false; + tmp.resize(strlen(sys_datadir)); + tmp.append("/autos"); + if ( Swv.SearchAndLoad( tmp.c_str() ) != SWV_SUCCESS ) + return false; // check for vehicle number if ( Swv.GetVehicles() < 4 ) diff --git a/src/CMainMenu.cpp b/src/CMainMenu.cpp index 5a27153..d454310 100644 --- a/src/CMainMenu.cpp +++ b/src/CMainMenu.cpp @@ -1123,8 +1123,9 @@ void CMainMenu::SaveSettings() FILE *fp = NULL; char header[3] = { 'S', 'W', 'P' }; + String strPref(String(usr_cfgdir) + "/pref"); - if ( ( fp = fopen( "pref", "wb" ) ) == NULL ) + if ( ( fp = fopen( strPref.c_str(), "wb" ) ) == NULL ) { AppendToLog( "Error writing to /pref file !" ); return; @@ -1169,8 +1170,9 @@ void CMainMenu::LoadSettings() FILE *fp = NULL; char header[3]; bool success = true; + String strPref(String(usr_cfgdir) + "/pref"); - if ( ( fp = fopen( "pref", "rb" ) ) == NULL ) + if ( ( fp = fopen( strPref.c_str(), "wb" ) ) == NULL ) { AppendToLog( "Error opening /pref file !" ); success = false; diff --git a/src/CSdl.cpp b/src/CSdl.cpp index 8e7e4ae..641365f 100644 --- a/src/CSdl.cpp +++ b/src/CSdl.cpp @@ -1300,9 +1300,6 @@ SDL_Surface* CSdl::LoadBitmap( const char *filename, Uint32 color_key, Uint8 alp SDL_Surface *sdl_surf = NULL; - char filename_buf[255]; - sprintf( filename_buf, "../%s", filename ); - if ( ( sdl_surf = SDL_LoadBMP( filename_buf )) == NULL ) { LOG("...failed to load graphics from : " << filename_buf ); @@ -1341,8 +1338,21 @@ SDL_Surface* CSdl::LoadBitmap( const char *filename, int32_t file_offset, Uint32 SDL_Surface *sdl_surf = NULL; // temp surface FILE *fp = NULL; // file pointer SDL_RWops *sdl_rw = NULL; // sdl_read_write_operations + String tmp; - if ( ( fp = fopen( filename, "rb")) == NULL ) +#ifdef LINUX_BUILD + if ( filename[0] != '/' ) + { + tmp = String(sys_datadir).append("/autos/").append(filename); + } + else + { + tmp = String(filename); + } +#else + tmp = String(filename); +#endif + if ( ( fp = fopen( tmp.c_str(), "rb")) == NULL ) { LOG("...failed to open file : " << filename ); return NULL; diff --git a/src/CSounds.cpp b/src/CSounds.cpp index fdab2b9..e4a88d7 100644 --- a/src/CSounds.cpp +++ b/src/CSounds.cpp @@ -52,14 +52,31 @@ bool CSounds::Initialize( CSdl *pSdl ) this->_sdl = pSdl; #if defined(WITH_FMOD) || defined(WITH_SDLMIXER) - -#define LOAD_SOUND( container, name, buffered ) if ( (sounds[container] = _sdl->LoadSound( name, buffered )) == -1 ) { \ - LOG( "Failed to load " << name << " ! "); \ - return false; } - -#define LOAD_MUSIC( container, name ) if ( (music[container] = _sdl->LoadSound( name, false, true )) == -1 ) { \ - LOG( "Failed to load music " << name << " ! "); \ - return false; } + String tmp (sys_datadir); + +#define LOAD_SOUND( container, name, buffered) \ + do { \ + tmp.append("/").append(name); \ + sounds[container] = \ + _sdl->LoadSound( tmp.c_str(), buffered ); \ + if ( sounds[container] == -1 ) { \ + LOG( "Failed to load " << name << " ! " ); \ + return false; \ + } \ + tmp.resize(strlen(sys_datadir)); \ + } while(0) + +#define LOAD_MUSIC( container, name) \ + do { \ + tmp.append("/").append(name); \ + music[container] = \ + _sdl->LoadSound( tmp.c_str(), false, true ); \ + if ( music[container] == -1 ) { \ + LOG( "Failed to load music " << name << " ! " ); \ + return false; \ + } \ + tmp.resize(strlen(sys_datadir)); \ + } while(0) LOAD_SOUND( SND_CRASHLIGHT1, "sound/crash3.wav", true ); LOAD_SOUND( SND_CRASHLIGHT2, "sound/crash2.wav", true ); diff --git a/src/CSwv_module.cpp b/src/CSwv_module.cpp index c77f37c..a11c519 100644 --- a/src/CSwv_module.cpp +++ b/src/CSwv_module.cpp @@ -206,8 +206,6 @@ int CSwv_module::Load( char *filename, SWV_HEADER *swv_file ) // << " name: " << swv_file->pfiles[i].filename); // } - // set module filename - sprintf( swv_file->filename, "%s", filename ); if ( fp != NULL ) fclose( fp ); diff --git a/src/Main.cpp b/src/Main.cpp index 04290e5..3af6e4e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -45,6 +45,13 @@ #include "Main.h" +const char *sys_datadir; +const char *usr_cfgdir; +const char *usr_datadir; + +char *ART_FILE; +char *BINDINGS_FILE; + int main( int argc, char *argv[] ) { bool hardware_support = true; @@ -59,12 +66,88 @@ int main( int argc, char *argv[] ) * ATI Mobility type of video cards. */ bool fullscreen = false; + String tmp; #ifdef LINUX_BUILD + sys_datadir = getenv("SAVAGEWHEELS_SYS_DATADIR"); + if (sys_datadir == NULL) + { + fprintf(stderr, "SAVAGEWHEELS_SYS_DATADIR not set.\n"); + return 1; + } + sys_datadir = strdup(sys_datadir); + + usr_cfgdir = getenv("SAVAGEWHEELS_USR_CONFDIR"); + if (usr_cfgdir == NULL) + { + fprintf(stderr, "SAVAGEWHEELS_USR_CONFDIR not set.\n"); + return 1; + } + usr_cfgdir = strdup(usr_cfgdir); + + usr_datadir = getenv("SAVAGEWHEELS_USR_DATADIR"); + if (usr_datadir == NULL) + { + fprintf(stderr, "SAVAGEWHEELS_USR_DATADIR not set.\n"); + return 1; + } + usr_datadir = strdup(usr_datadir); + + if (sys_datadir == NULL || usr_cfgdir == NULL || usr_datadir == NULL) + { + fprintf(stderr, "Insufficient memory. Execution aborted.\n"); + return 1; + } + setenv("SDL_VIDEO_CENTERED", "1", 1); #else + sys_datadir = usr_cfgdir = usr_datadir = "./"; _putenv("SDL_VIDEO_CENTERED=1"); #endif + int len; + len = snprintf(NULL, 0, "%s/graphics/gfxdata.kdf", sys_datadir); + if (len < 0) + { + fprintf(stderr, + "Unable to store '%s/graphics/gfxdata.kdf': %s\n", + sys_datadir, strerror(errno)); + return 1; + } + if (len == INT_MAX) + { + fprintf(stderr, "Unable to store '%s/graphics/gfxdata.kdf': " + "Path too log\n", sys_datadir); + return 1; + } + ART_FILE = new (std::nothrow) char[len + 1]; + if (ART_FILE == NULL) + { + fprintf(stderr, "Insufficent memory. Execution aborted.\n"); + return 1; + } + sprintf(ART_FILE, "%s/graphics/gfxdata.kdf", sys_datadir); + + len = snprintf(NULL, 0, "%s/bindings.xml", usr_cfgdir); + if (len < 0) + { + fprintf(stderr, + "Unable to store '%s/bindings.xml': %s\n", usr_cfgdir, + strerror(errno)); + return 1; + } + if (len == INT_MAX) + { + fprintf(stderr, "Unable to store '%s/bindings.xml': " + "Path too log\n", usr_cfgdir); + return 1; + } + BINDINGS_FILE = new (std::nothrow) char[len + 1]; + if (BINDINGS_FILE == NULL) + { + fprintf(stderr, "Insufficent memory. Execution aborted.\n"); + return 1; + } + sprintf(BINDINGS_FILE, "%s/bindings.xml", usr_cfgdir); if (argc > 1) { for (int i = 1; i < argc; i++) { @@ -106,7 +189,8 @@ int main( int argc, char *argv[] ) * Load & Start Game */ - OpenLog("debug.html"); + tmp = String(usr_datadir).append("/debug.html"); + OpenLog(tmp.c_str()); CGame game; game.Execute(fullscreen, hardware_support); diff --git a/src/Main.h b/src/Main.h index 38b1555..93b9c6a 100644 --- a/src/Main.h +++ b/src/Main.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -86,8 +87,6 @@ #include "Config.h" // --- global game defines -#define ART_FILE "graphics/gfxdata.kdf" -#define BINDINGS_FILE "bindings.xml" #define LOAD_OK (-1) #define LOAD_FAILED (0) #define HRESULT(x) ( (x) == NULL : LOAD_OK ? LOAD_FAILED ) @@ -102,6 +101,12 @@ typedef std::string String; typedef std::ostringstream OutputSStream; +extern const char *sys_datadir; +extern const char *usr_cfgdir; +extern const char *usr_datadir; + +extern char *ART_FILE; +extern char *BINDINGS_FILE; //#include "pstdint.h" // portable types #include "Utils.h" #include "CKdf.h" diff --git a/src/Utils.cpp b/src/Utils.cpp index 215e018..8200edc 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -263,7 +263,7 @@ bool OpenLog ( const char* filename ) String time( GetFormattedTime() ); // open debug file - debug_file.open ( "debug.html", std::ios::out ); //ios::ate ); + debug_file.open ( filename, std::ios::out ); //ios::ate ); if ( ! debug_file.good() ) return false; From 0f06d3ca2c74d787af55d0f5ca2a9a814478c744 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Thu, 5 May 2016 14:40:50 +0200 Subject: [PATCH 2/6] Apply CMake patch by @nvinson --- CMakeLists.txt | 76 ++++++++++++++++++++++++++++++++++--------------- savagewheels.in | 42 +++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 23 deletions(-) create mode 100755 savagewheels.in diff --git a/CMakeLists.txt b/CMakeLists.txt index ba940a2..e4f4ae4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,18 +11,29 @@ set(APP_VER_PATCH "0") find_package(SDL REQUIRED) ### Install targets (see: http://www.cmake.org/Wiki/CMake_RPATH_handling) -if (NOT INSTALL_DIR) - set(INSTALL_DIR "./") +if (UNIX) + include (GNUInstallDirs) +else() + if (NOT INSTALL_DIR) + set(INSTALL_DIR "./") + endif() + set(CMAKE_INSTALL_BINDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_SBINDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_LIBEXECDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_SYSCONFDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_SHAREDSTATEDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_LOCALSTATEDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_LIBDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_INCLUDEDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_OLDINCLUDEDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_DATAROOTDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_DATADIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_INFODIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_LOCALEDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_MANDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_DOCDIR "${INSTALL_DIR}") endif() -# when building, don't use the install RPATH already -# (but later on when installing) -SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) - -# add the automatically determined parts of the RPATH -SET(CMAKE_INSTALL_RPATH "${INSTALL_DIR}/") -SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - ### sources include_directories(src/) include_directories(tinyxml/) @@ -115,7 +126,7 @@ elseif(SOUND STREQUAL "FMOD") # FModEx API # check if path to FMod is defined - if(NOT DEFINED ${FMOD_PATH}) + if(NOT DEFINED FMOD_PATH) set(FMOD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/libs/fmod/api") endif() @@ -166,13 +177,15 @@ elseif(SOUND STREQUAL "FMOD") add_definitions(-DWITH_FMOD) - add_custom_command(TARGET savagewheels POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${FMOD_LIBRARY_SO_PATH} - $) - - INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${FMOD_SO_NAME}" - DESTINATION ${INSTALL_DIR}) + if (WIN32) + add_custom_command(TARGET savagewheels POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_if_different + "${FMOD_LIBRARY_SO_PATH}" + "$") + + INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${FMOD_SO_NAME}" + DESTINATION "${INSTALL_DIR}") + endif() endif() else() @@ -236,15 +249,32 @@ configure_file ( "${PROJECT_SOURCE_DIR}/Config.h.in" "${PROJECT_SOURCE_DIR}/src/Config.h") -INSTALL(TARGETS savagewheels RUNTIME DESTINATION ${INSTALL_DIR}) -INSTALL(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" DESTINATION ${INSTALL_DIR}) + +INSTALL(TARGETS savagewheels RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}") +if (WIN32 AND NOT UNIX) + INSTALL(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" DESTINATION "${INSTALL_DIR}") +else() + configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/savagewheels.in" + "${CMAKE_CURRENT_BINARY_DIR}/savagewheels.sh" + @ONLY) + INSTALL(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/savagewheels.sh" + DESTINATION "${CMAKE_INSTALL_BINDIR}" RENAME savagewheels) +endif() + INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/README.md" "${CMAKE_CURRENT_SOURCE_DIR}/HISTORY" "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" - DESTINATION ${INSTALL_DIR}) -INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/" - DESTINATION ${INSTALL_DIR} + "${CMAKE_CURRENT_SOURCE_DIR}/bin/LICENSE.mikmod.txt" + "${CMAKE_CURRENT_SOURCE_DIR}/bin/Readme.html" + "${CMAKE_CURRENT_SOURCE_DIR}/bin/README-SDL_mixer.txt" + "${CMAKE_CURRENT_SOURCE_DIR}/bin/README-SDL.txt" + DESTINATION "${CMAKE_INSTALL_DOCDIR}") +INSTALL(FILES + "${CMAKE_CURRENT_SOURCE_DIR}/bin/bindings.xml" + DESTINATION "${CMAKE_INSTALL_DATADIR}") +INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/help" + DESTINATION "${CMAKE_INSTALL_DOCDIR}/help" PATTERN "debug.html" EXCLUDE PATTERN "pref" EXCLUDE) diff --git a/savagewheels.in b/savagewheels.in new file mode 100755 index 0000000..c1b4c68 --- /dev/null +++ b/savagewheels.in @@ -0,0 +1,42 @@ +#!/bin/sh + +export SAVAGEWHEELS_SYS_DATADIR="${SAVAGEWHEELS_SYS_DATADIR-@CMAKE_INSTALL_DATADIR@}" +export SAVAGEWHEELS_LIBEXECDIR="${SAVAGEWHEELS_LIBEXECDIR-@CMAKE_INSTALL_LIBEXECDIR@}" +export SAVAGEWHEELS_USR_CONFDIR="${SAVAGEWHEELS_USR_CONFDIR-${HOME}/.config/savagewheels}" +export SAVAGEWHEELS_USR_DATADIR="${SAVAGEWHEELS_USR_DATADIR-${HOME}/.local/share/savagewheels}" + +if [ ! -d ${SAVAGEWHEELS_USR_CONFDIR} ]; then + if [ -e ${SAVAGEWHEELS_USR_CONFDIR} ]; then + printf "${SAVAGEWHEELS_USR_CONFDIR} exists but is not a directory.\n" >&2 + printf " Please remove.\n" >&2 + exit 1 + fi + mkdir -p ${SAVAGEWHEELS_USR_CONFDIR} + if [ $? -ne 0 ]; then + printf "Failed to create ${SAVAGEWHEELS_USR_CONFDIR}\n" >&2 + exit 1 + fi +fi + +if [ ! -d ${SAVAGEWHEELS_USR_DATADIR} ]; then + if [ -e ${SAVAGEWHEELS_USR_DATADIR} ]; then + printf "${SAVAGEWHEELS_USR_DATADIR} exists but is not a directory.\n" >&2 + printf " Please remove.\n" >&2 + exit 1 + fi + mkdir -p ${SAVAGEWHEELS_USR_DATADIR} + if [ $? -ne 0 ]; then + printf "Failed to create ${SAVAGEWHEELS_USR_DATADIR}\n" >&2 + exit 1 + fi +fi + +if [ ! -e ${SAVAGEWHEELS_USR_CONFDIR}/bindings.xml ]; then + cp ${SAVAGEWHEELS_SYS_DATADIR}/bindings.xml ${SAVAGEWHEELS_USR_CONFDIR} + if [ $? -ne 0 ]; then + printf "Failed to create ${SAVAGEWHEELS_USR_CONFDIR}/bindings.xml\n" >&2 + exit 1 + fi +fi + +exec ${SAVAGEWHEELS_LIBEXECDIR}/savagewheels "$@" From 9b12f3c3016791d26ff310f18237b407b454817b Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Thu, 5 May 2016 14:44:55 +0200 Subject: [PATCH 3/6] Bump version to 1.6.1 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4f4ae4..7bf0783 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(savagewheels) set(APP_ARCH "") set(APP_VER_MAJ "1") set(APP_VER_MIN "6") -set(APP_VER_PATCH "0") +set(APP_VER_PATCH "1") ### check for required libs find_package(SDL REQUIRED) From 8ce4392f4b28ff561ad065a189b6d44709dfdcca Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Thu, 5 May 2016 22:28:59 +0200 Subject: [PATCH 4/6] Several fixes for Arch Linux PKGBUILD packaging Use 'INSTALL_DATADIR' and 'INSTALL_LIBEXECDIR' in 'savagewheels.in', so to be able to override them. Package 'autos', 'graphics' and 'sound' dirs, only if available in the bin/ dir. Self-extracting executables and PKGBUILD will use that to construct the game package. Other pkg systems may just skip it by not copying these folders in the game bin/ folder prior to packaging. --- CMakeLists.txt | 247 ++++++++++++++++++++++++++---------------------- savagewheels.in | 4 +- 2 files changed, 136 insertions(+), 115 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bf0783..6c89dde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 2.8) -project(savagewheels) +project(savagewheels) ### Defaults set(APP_ARCH "") @@ -10,7 +10,7 @@ set(APP_VER_PATCH "1") ### check for required libs find_package(SDL REQUIRED) -### Install targets (see: http://www.cmake.org/Wiki/CMake_RPATH_handling) +### Install targets if (UNIX) include (GNUInstallDirs) else() @@ -39,40 +39,39 @@ include_directories(src/) include_directories(tinyxml/) set( - SOURCES + SOURCES src/CBufferedReader.cpp - src/Bindings.cpp - src/CDeadToy.cpp - src/CKdf.cpp - src/CSdl.cpp - src/CSwv_module.cpp - src/CVehicle.cpp - src/Utils.cpp - src/CAnimation.cpp - src/CGame.cpp - src/CMainMenu.cpp + src/Bindings.cpp + src/CDeadToy.cpp + src/CKdf.cpp + src/CSdl.cpp + src/CSwv_module.cpp + src/CVehicle.cpp + src/Utils.cpp + src/CAnimation.cpp + src/CGame.cpp + src/CMainMenu.cpp src/CSounds.cpp src/CTimer.cpp src/Main.cpp tinyxml/tinystr.cpp tinyxml/tinyxml.cpp tinyxml/tinyxmlerror.cpp - tinyxml/tinyxmlparser.cpp + tinyxml/tinyxmlparser.cpp ) ### specify executable - set(RES_FILES "") if(MINGW) - # include a Windows resource file + # include a Windows resource file set(RES_FILES "src/res.rc") set(CMAKE_RC_COMPILER_INIT windres) ENABLE_LANGUAGE(RC) SET(CMAKE_RC_COMPILE_OBJECT " -O coff -i -o ") - - add_executable(savagewheels ${SOURCES} ${RES_FILES}) + + add_executable(savagewheels ${SOURCES} ${RES_FILES}) else() - add_executable(savagewheels ${SOURCES}) + add_executable(savagewheels ${SOURCES}) endif() ### add required libarires @@ -88,7 +87,7 @@ endif() ## SDL if (UNIX AND NOT WIN32) # Linux - + # set(SDL_LIB_NAME "libSDL.so") # find_library( # SDL_LIBRARY_SO @@ -96,27 +95,27 @@ if (UNIX AND NOT WIN32) # PATHS "/usr/lib" "/usr/local/lib/" # HINTS $ENV{SDLDIR} ${SDL_LIBRARY} "${CMAKE_CURRENT_SOURCE_DIR}/libs") add_definitions(`sdl-config --cflags`) - add_definitions(`sdl-config --libs`) + add_definitions(`sdl-config --libs`) else() # Windows - + set(SDL_LIB_NAME "SDL.dll") - + add_definitions(-lpthread) include_directories(${SDL_INCLUDE_DIR}) link_directories($ENV{SDLDIR}\\lib) set(SDL_LIBRARY_SO $ENV{SDLDIR}\\bin\\SDL.dll) - + message(STATUS "Found libSDL.so/DLL at ${SDL_LIBRARY}") - + # copy the SDL DLL file to the install dir add_custom_command(TARGET savagewheels POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SDL_LIBRARY_SO} - $) - + $) + INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/SDL.dll" DESTINATION ${INSTALL_DIR}) - + endif() ## SOUND libraries @@ -125,101 +124,100 @@ if (SOUND STREQUAL "NO") elseif(SOUND STREQUAL "FMOD") # FModEx API - # check if path to FMod is defined - if(NOT DEFINED FMOD_PATH) - set(FMOD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/libs/fmod/api") - endif() + # check if path to FMod is defined + if(NOT DEFINED FMOD_PATH) + set(FMOD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/libs/fmod/api") + endif() add_definitions(-I${FMOD_PATH}/inc) link_directories(${FMOD_PATH}/lib) - if (UNIX AND NOT WIN32) - # Linux - - if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32) - set(FMOD_LIB_NAME "libfmodex64.so") - set(FMOD_SO_NAME "libfmodex64.so") - else() - set(FMOD_LIB_NAME "libfmodex.so") - set(FMOD_SO_NAME "libfmodex.so") - endif() - - # just in case check also in the system folders - add_definitions(-I/usr/include/fmodex) - else() - # Windows - - set(FMOD_LIB_NAME "libfmodex.a") - if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32) - set(FMOD_SO_NAME "fmodex64.dll") - else() - set(FMOD_SO_NAME "fmodex.dll") - endif() - endif() + if (UNIX AND NOT WIN32) + # Linux + + if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32) + set(FMOD_LIB_NAME "libfmodex64.so") + set(FMOD_SO_NAME "libfmodex64.so") + else() + set(FMOD_LIB_NAME "libfmodex.so") + set(FMOD_SO_NAME "libfmodex.so") + endif() + + # just in case check also in the system folders + add_definitions(-I/usr/include/fmodex) + else() + # Windows + + set(FMOD_LIB_NAME "libfmodex.a") + if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32) + set(FMOD_SO_NAME "fmodex64.dll") + else() + set(FMOD_SO_NAME "fmodex.dll") + endif() + endif() - # add FMod Ex (if present) - find_library( - FMOD_LIBRARY - NAMES ${FMOD_LIB_NAME} - PATHS "/usr/lib" "/usr/local/lib/" - HINTS "${FMOD_PATH}/lib") - - find_library( - FMOD_LIBRARY_SO_PATH - NAMES ${FMOD_SO_NAME} - PATHS "/usr/lib" "/usr/local/lib/" - HINTS "${FMOD_PATH}" "${FMOD_PATH}/lib") - - if (NOT FMOD_LIBRARY) - message(STATUS "FModEx lib - ${FMOD_LIB_NAME} not found! Will compile without sound support.") - else() - message(STATUS "Found FModEx lib at ${FMOD_LIBRARY}. Found FModEx DLL at ${FMOD_LIBRARY_SO_PATH}.") - - add_definitions(-DWITH_FMOD) - - if (WIN32) - add_custom_command(TARGET savagewheels POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${FMOD_LIBRARY_SO_PATH}" - "$") - - INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${FMOD_SO_NAME}" - DESTINATION "${INSTALL_DIR}") - endif() - endif() + # add FMod Ex (if present) + find_library( + FMOD_LIBRARY + NAMES ${FMOD_LIB_NAME} + PATHS "/usr/lib" "/usr/local/lib/" + HINTS "${FMOD_PATH}/lib") + + find_library( + FMOD_LIBRARY_SO_PATH + NAMES ${FMOD_SO_NAME} + PATHS "/usr/lib" "/usr/local/lib/" + HINTS "${FMOD_PATH}" "${FMOD_PATH}/lib") + + if (NOT FMOD_LIBRARY) + message(STATUS "FModEx lib - ${FMOD_LIB_NAME} not found! Will compile without sound support.") + else() + message(STATUS "Found FModEx lib at ${FMOD_LIBRARY}. Found FModEx DLL at ${FMOD_LIBRARY_SO_PATH}.") + + add_definitions(-DWITH_FMOD) + + if (WIN32) + add_custom_command(TARGET savagewheels POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_if_different + "${FMOD_LIBRARY_SO_PATH}" + "$") + + INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${FMOD_SO_NAME}" + DESTINATION "${INSTALL_DIR}") + endif() + endif() else() + # SDL_mixer API find_package(SDL_mixer REQUIRED) add_definitions(-DWITH_SDLMIXER) set(SOUND "SDL_MIXER") - # Copy SDL_mixer.dll and libmikmod-2.dll to installation directory - if (WIN32) - INSTALL(FILES "${SDL_MIXER_LIBRARIES}" DESTINATION ${INSTALL_DIR}) - - # Find mikmod DLL for playing music - find_library(SDL_MIXER_MIKMOD_LIBRARY - NAMES libmikmod-2 - HINTS - ENV SDLMIXERDIR - ENV SDLDIR - PATH_SUFFIXES lib) - - if (NOT SDL_MIXER_MIKMOD_LIBRARY) - message(STATUS "SDL_mixer libmikmod-2 dependency was NOT FOUND! Game will run WITHOUT music.") - endif() - - INSTALL(FILES "${SDL_MIXER_MIKMOD_LIBRARY}" DESTINATION ${INSTALL_DIR}) - endif() + # Copy SDL_mixer.dll and libmikmod-2.dll to installation directory + if (WIN32) + INSTALL(FILES "${SDL_MIXER_LIBRARIES}" DESTINATION ${INSTALL_DIR}) + + # Find mikmod DLL for playing music + find_library(SDL_MIXER_MIKMOD_LIBRARY + NAMES libmikmod-2 + HINTS + ENV SDLMIXERDIR + ENV SDLDIR + PATH_SUFFIXES lib) + + if (NOT SDL_MIXER_MIKMOD_LIBRARY) + message(STATUS "SDL_mixer libmikmod-2 dependency was NOT FOUND! Game will run WITHOUT music.") + endif() + + INSTALL(FILES "${SDL_MIXER_MIKMOD_LIBRARY}" DESTINATION ${INSTALL_DIR}) + endif() endif() ### link required libraries - target_link_libraries(savagewheels ${SDL_LIBRARY} ${FMOD_LIBRARY} ${SDLMIXER_LIBRARY}) ### additional defines - if (UNIX AND NOT WIN32) add_definitions(-DLINUX_BUILD) endif() @@ -232,7 +230,6 @@ endif() message(STATUS "Build type is ${CMAKE_BUILD_TYPE}") ### set architecture - if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32) add_definitions(-DARCH_X64) set(APP_ARCH "x64") @@ -244,16 +241,23 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") endif() -### Configure compile time header file +### Configure compile time header file configure_file ( "${PROJECT_SOURCE_DIR}/Config.h.in" "${PROJECT_SOURCE_DIR}/src/Config.h") - INSTALL(TARGETS savagewheels RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}") if (WIN32 AND NOT UNIX) INSTALL(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" DESTINATION "${INSTALL_DIR}") else() + # address Arch Linux packaging by explicitly specifying data dirs + if (NOT INSTALL_DATADIR) + set(INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}") + endif() + if (NOT INSTALL_LIBEXECDIR) + set(INSTALL_LIBEXECDIR "${CMAKE_INSTALL_LIBEXECDIR}") + endif() + configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/savagewheels.in" "${CMAKE_CURRENT_BINARY_DIR}/savagewheels.sh" @ONLY) @@ -274,10 +278,27 @@ INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/bin/bindings.xml" DESTINATION "${CMAKE_INSTALL_DATADIR}") INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/help" - DESTINATION "${CMAKE_INSTALL_DOCDIR}/help" + DESTINATION "${CMAKE_INSTALL_DOCDIR}" PATTERN "debug.html" EXCLUDE PATTERN "pref" EXCLUDE) - + +# add data folders only if they are already present +if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/autos") + INSTALL(DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}/bin/autos" + DESTINATION "${CMAKE_INSTALL_DATADIR}") +endif() +if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/sound") + INSTALL(DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}/bin/sound" + DESTINATION "${CMAKE_INSTALL_DATADIR}") +endif() +if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/graphics") + INSTALL(DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}/bin/graphics" + DESTINATION "${CMAKE_INSTALL_DATADIR}") +endif() + ### build a CPack driven installer package include (InstallRequiredSystemLibraries) @@ -303,7 +324,7 @@ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") # Debian DEB package stuff if (${CPACK_GENERATOR} STREQUAL "DEB") set(CPACK_PACKAGING_INSTALL_PREFIX "/opt") - set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEB_ARCH}) + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEB_ARCH}) set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libstdc++6, libsdl1.2debian (>= 1.2.11)") # require SDL_mixer if support is enabled if(SOUND STREQUAL "SDL_MIXER") @@ -314,7 +335,7 @@ endif() set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") #set(CPACK_INSTALLED_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/bin;/.") -#set(CPACK_IGNORE_FILES +#set(CPACK_IGNORE_FILES #"~$" #"^.*/.git/" #"^${PROJECT_SOURCE_DIR}/bin/pref" diff --git a/savagewheels.in b/savagewheels.in index c1b4c68..a4ad128 100755 --- a/savagewheels.in +++ b/savagewheels.in @@ -1,7 +1,7 @@ #!/bin/sh -export SAVAGEWHEELS_SYS_DATADIR="${SAVAGEWHEELS_SYS_DATADIR-@CMAKE_INSTALL_DATADIR@}" -export SAVAGEWHEELS_LIBEXECDIR="${SAVAGEWHEELS_LIBEXECDIR-@CMAKE_INSTALL_LIBEXECDIR@}" +export SAVAGEWHEELS_SYS_DATADIR="${SAVAGEWHEELS_SYS_DATADIR-@INSTALL_DATADIR@}" +export SAVAGEWHEELS_LIBEXECDIR="${SAVAGEWHEELS_LIBEXECDIR-@INSTALL_LIBEXECDIR@}" export SAVAGEWHEELS_USR_CONFDIR="${SAVAGEWHEELS_USR_CONFDIR-${HOME}/.config/savagewheels}" export SAVAGEWHEELS_USR_DATADIR="${SAVAGEWHEELS_USR_DATADIR-${HOME}/.local/share/savagewheels}" From 93ccfb283873af8ba102aa6d431bc9a8af65355c Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Sun, 8 May 2016 13:40:49 +0200 Subject: [PATCH 5/6] Add Linux freedesktop entry and icon --- savagewheels.desktop | 13 +++++++++++++ sw1.png | Bin 0 -> 1680 bytes 2 files changed, 13 insertions(+) create mode 100644 savagewheels.desktop create mode 100644 sw1.png diff --git a/savagewheels.desktop b/savagewheels.desktop new file mode 100644 index 0000000..e1a6f36 --- /dev/null +++ b/savagewheels.desktop @@ -0,0 +1,13 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=SavageWheels +GenericName=Action/Arcade Game +Version=1.6 +Type=Application +Categories=Game;ActionGame;Racing; +Keywords=Game;Arcade;2D;Cars;Racing +Comment=2D car crashing game similar to the old classic Destruction Derby +TryExec=savagewheels +Exec=savagewheels +Terminal=false +Icon=sw1 \ No newline at end of file diff --git a/sw1.png b/sw1.png new file mode 100644 index 0000000000000000000000000000000000000000..339554e0569093257750ce5119a34a3c854b0cad GIT binary patch literal 1680 zcmV;B25004R>004l5008;`004mK004C`008P>0026e000+ooVrmw0006~ zP)t-s1_S{e6$>mQ6c!8uB^nKEQ7kyM+*l8 zbwwbWZ921yPH77+>!2?T>wDT-V!uZB$1t7Y4>an`eJ%A{U}TQeFB1Y|rFx{*_^ zi%}&U5pqHvdrKsfV>7mkRHcDTGb0l!8w`U`CA)z{#EMEvH66>DUD>s7Y(O459tVF* z9K)1UqH8tNl~RRSExLR=j$tyxn_A+rbla+Hw1Z4tIv+J24R}8etaCfnnOSv7BGQpf z!-zv$HW(un3X)zf=(>aCw0h#Lam}A*AQ1$4Lk^&3F4>({Oe_=3j7fw~BVqpu6bNY zGTftL$&^|Y4hVBS4b78MqGcnRWHPaKJEn6xif&9;H4|et3yMw=qHQ>pS{lQJL{K~< zT0$pDCJwZDJ&jQkQ#BgDl3j^#Lrgm&Gad%WheNr3LC&dWky8?^ZY-pEKtLoAsbw0= zqH)BOVbZH9~chFooHDz3#4EbKr$e6PAEes2*ZOss&XwdAq;R= zG8zyBym~T4E)+N=4nr^++@V~0Su(S5C*Y-8t!f{8Qz4C5B-EQ!d`S?oeMVs~4X=7Q zvwAhPf^xW!2A0y4v5(EGM13O7XK~y-)b(8B`6Gs%rPl%9IrJ0BX!Gh6QG_W8jEHM``aU;8- z0$GHh3o4M>h#{a7qOw{wY%KNCs#saC;H9NjZEa~r(EgOUY?#4EeH8HnTLjnV+X{;dNhvsqj^V1s$vd=Q9>S-hRF#@ z6M#b$kLiGgjUGQS!g7dMjwO}I5GJmiBw-YTTTXp-ngqz?%{!y?w+RTLvrZ+MBCbdk z06AiiagBGb-v!12C{xp1f?B2(XA|-Cb($9Cw}jnkGw~;D!)+#GukIA?!=g zyT1|7uNc43X=i9QE?(kNwKy(~Drt$qsc$K;mxRgVx!|&f$fD&txr$guRHapJN0AN+ zT)q-?yPLz&7(=3Qb@Hr?5Id$SgK}SG#Gn_>wJUCSI2?}pzX!NJImIzZGO6mQEC?*s zL)wjXH&0O@>UY4c$=h6?jlVOZsB%0}PJz4H8ahqy05UK!G%YYQEipAzGBP?b zFgi0gD=;xSFfhwmtQ`OV03~!qSaf7zbY(hiZ)9m^c>ppnF*7YNH7zqSR4_0)Gch_d aH7hVOIxsNty5MX80000 Date: Sun, 8 May 2016 14:16:03 +0200 Subject: [PATCH 6/6] Fix self-extract build `run.sh` script now used only when a self-extrcat build is invoked via CPack. --- CMakeLists.txt | 11 ++++++++--- HISTORY | 3 +++ build.sh | 29 ++++++----------------------- run.sh | 4 +++- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c89dde..fe8f523 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,9 +247,7 @@ configure_file ( "${PROJECT_SOURCE_DIR}/src/Config.h") INSTALL(TARGETS savagewheels RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}") -if (WIN32 AND NOT UNIX) - INSTALL(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" DESTINATION "${INSTALL_DIR}") -else() +if (UNIX AND NOT WIN32) # address Arch Linux packaging by explicitly specifying data dirs if (NOT INSTALL_DATADIR) set(INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}") @@ -261,8 +259,15 @@ else() configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/savagewheels.in" "${CMAKE_CURRENT_BINARY_DIR}/savagewheels.sh" @ONLY) + INSTALL(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/savagewheels.sh" DESTINATION "${CMAKE_INSTALL_BINDIR}" RENAME savagewheels) + + # add run.sh if building a static distro + if (CMAKE_BUILD_STATIC) + INSTALL(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" + DESTINATION "./") + endif() endif() INSTALL(FILES diff --git a/HISTORY b/HISTORY index 4cd1671..cf20753 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,9 @@ Savage Wheels Release HISTORY ----------------------------- +V1.6.1 Patch + * added Linux configurable game data directories + V1.6 Release * added support for SDL_mixer sound library. It is now the default sound library used. diff --git a/build.sh b/build.sh index 1b25afe..15a12fc 100755 --- a/build.sh +++ b/build.sh @@ -12,14 +12,6 @@ CPACK="$(which cpack)" VERMAJ=`perl -nle 'print $1 if /.*VER_MAJ\s(\d+).*/' src/Main.h` VERMIN=`perl -nle 'print $1 if /.*VER_MIN\s(\d+).*/' src/Main.h` VERSION="$VERMAJ.$VERMIN" -#ARCH="$(uname -m)" -#TMP_PATH="$CUR_DIR/build/savagewheels-$VERSION-linux" - -#if [ $ARCH = "x86_64" ]; then -# TMP_PATH="$TMP_PATH-x64" -#else -# TMP_PATH="$TMP_PATH-$ARCH" -#fi usage() { echo "dist-build.sh - Savage Wheels ${VERMAJ}.${VERMIN} distributable package build script" @@ -32,10 +24,6 @@ usage() { cleanup() { echo "Cleaning up old files ..." - #if [ -e $TMP_PATH ]; then - # rm -rf $TMP_PATH - #fi - cd $BUILD_PATH make clean cd .. @@ -47,12 +35,6 @@ cleanup() { build() { echo "Building package ..." - - mkdir $TMP_PATH - if [ ! -e $TMP_PATH ]; then - echo "Dist path could not be created - $TMP_PATH" - exit - fi if [ ! -e $CMAKE ]; then echo "CMake was not found - $CMAKE" @@ -64,7 +46,9 @@ build() { fi cd $BUILD_PATH - $CMAKE cmake -G "Unix Makefiles" ../ -DCMAKE_BUILD_TYPE:STRING=Release + $CMAKE cmake -G "Unix Makefiles" ../ \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DCMAKE_BUILD_STATIC=1 make -j$CPU_CORES $CPACK @@ -77,10 +61,9 @@ build() { if [ "$1" = "clean" ]; then cleanup -#elif [ "$1" = "build" ]; then -else +elif [ "$1EMPTY" = "EMPTY" ]; then cleanup build -#else -# usage +else + usage fi diff --git a/run.sh b/run.sh index 8f16d25..27440d0 100644 --- a/run.sh +++ b/run.sh @@ -4,6 +4,8 @@ CUR_DIR="$(dirname $(readlink -f $0))" export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUR_DIR:. +export SAVAGEWHEELS_SYS_DATADIR="$CUR_DIR/share" +export SAVAGEWHEELS_LIBEXECDIR="$CUR_DIR/libexec" # Run the game -exec ./savagewheels "$@" +exec bin/savagewheels "$@"