Dariusz Dwornikowski <dariusz.dwornikow...@cs.put.poznan.pl> writes:

> Since the package depends on physfs 2.1, which has not been release
> yet, we need to wait for the upstream of physfs to release 2.1 and for
> the package to be in Debian. For now, raceintospace is ready in
> pkg-games git and can go to Debian when physfs is ready. 

Thanks for your efforts in packaging raceintospace. I've noticed that
Hedgewars used to have a similar problem, which they've solved by adding
a compatibility layer for PhysFS 2.0. Using this as a starting point, I
saw that only one more function had to be provided, which I backported
from the 2.1 branch with some minor modifications. With the attached
patch, raceintospace compiles and runs with the PhysFS library from
sid. The compatibility layer checks for the version number of PhysFS, so
once 2.1 is packaged, the code should automatically stop being included.

The only slight drawback is that Hedgewars is GPL-2 only, so it will no
longer be possible to ship raceintospace binaries as GPL-2+. But since
this is only a temporary situation, I think this can be justified.

Hendrik

diff -ruN -x .git -x .pc raceintospace.orig/lib/CMakeLists.txt raceintospace/lib/CMakeLists.txt
--- raceintospace.orig/lib/CMakeLists.txt	2014-09-13 13:54:07.680088605 +0200
+++ raceintospace/lib/CMakeLists.txt	2014-09-12 23:07:12.263649649 +0200
@@ -124,9 +124,9 @@
 # I want 2.1 features, even if they're not out yet, so I made my own tarball
 #set (physfs_Version 2.0.3)
 #set (physfs_URL http://icculus.org/physfs/downloads/physfs-${physfs_Version}.tar.bz2)
-set (physfs_Version 2.1.0-pre20121013)
-set (physfs_URL https://s3.amazonaws.com/willglynn/physfs-${physfs_Version}.tgz)
-set (physfs_Dir ${CMAKE_CURRENT_BINARY_DIR}/physfs-${physfs_Version})
+#set (physfs_Version 2.1.0-pre20121013)
+#set (physfs_URL https://s3.amazonaws.com/willglynn/physfs-${physfs_Version}.tgz)
+#set (physfs_Dir ${CMAKE_CURRENT_BINARY_DIR}/physfs-${physfs_Version})
 
 # physfs 2.0.3 complains about FSPathMakeRef et al being deprecated, and warnings are treated as errors
 # Turn it back into a warning instead
@@ -134,14 +134,14 @@
   set (physfs_Flags -Wno-error=deprecated-declarations)
 endif (APPLE)
 
-ExternalProject_Add(ext_physfs
-  DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/downloads
-  URL ${physfs_URL}
-  PREFIX ${physfs_Dir}
-  CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${LocalPrefix} -DPHYSFS_ARCHIVE_7Z=false -DPHYSFS_ARCHIVE_GRP=false -DPHYSFS_ARCHIVE_WAD=false -DPHYSFS_ARCHIVE_HOG=false -DPHYSFS_ARCHIVE_MVL=false -DPHYSFS_ARCHIVE_QPAK=false -DPHYSFS_ARCHIVE_ISO9660=false -DPHYSFS_HAVE_CDROM_SUPPORT=false -DPHYSFS_BUILD_SHARED=false -DPHYSFS_BUILD_TEST=false -DCMAKE_C_FLAGS=${physfs_Flags}
-  )
+#ExternalProject_Add(ext_physfs
+#  DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/downloads
+#  URL ${physfs_URL}
+#  PREFIX ${physfs_Dir}
+#  CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${LocalPrefix} -DPHYSFS_ARCHIVE_7Z=false -DPHYSFS_ARCHIVE_GRP=false -DPHYSFS_ARCHIVE_WAD=false -DPHYSFS_ARCHIVE_HOG=false -DPHYSFS_ARCHIVE_MVL=false -DPHYSFS_ARCHIVE_QPAK=false -DPHYSFS_ARCHIVE_ISO9660=false -DPHYSFS_HAVE_CDROM_SUPPORT=false -DPHYSFS_BUILD_SHARED=false -DPHYSFS_BUILD_TEST=false -DCMAKE_C_FLAGS=${physfs_Flags}
+#  )
 
-add_dependencies(libs ext_physfs)
+#add_dependencies(libs ext_physfs)
 
 
 ###
diff -ruN -x .git -x .pc raceintospace.orig/src/game/CMakeLists.txt raceintospace/src/game/CMakeLists.txt
--- raceintospace.orig/src/game/CMakeLists.txt	2014-09-13 13:54:07.684088605 +0200
+++ raceintospace/src/game/CMakeLists.txt	2014-09-13 13:05:05.191946197 +0200
@@ -55,6 +55,7 @@
   news_suq.cpp
   options.cpp
   pace.cpp
+  physfscompat.cpp
   place.cpp
   port.cpp
   prefs.cpp
diff -ruN -x .git -x .pc raceintospace.orig/src/game/file.cpp raceintospace/src/game/file.cpp
--- raceintospace.orig/src/game/file.cpp	2014-09-13 13:54:07.688088605 +0200
+++ raceintospace/src/game/file.cpp	2014-09-12 23:15:22.191673360 +0200
@@ -4,6 +4,7 @@
 #include <stdexcept>
 
 #include "file.h"
+#include "physfscompat.h"
 
 #define m_phys_handle ((PHYSFS_File*)m_handle)
 
diff -ruN -x .git -x .pc raceintospace.orig/src/game/filesystem.cpp raceintospace/src/game/filesystem.cpp
--- raceintospace.orig/src/game/filesystem.cpp	2014-09-13 13:54:07.688088605 +0200
+++ raceintospace/src/game/filesystem.cpp	2014-09-12 23:32:07.607722019 +0200
@@ -8,6 +8,7 @@
 
 #include "raceintospace_config.h"
 #include "filesystem.h"
+#include "physfscompat.h"
 
 using boost::format;
 
diff -ruN -x .git -x .pc raceintospace.orig/src/game/physfscompat.cpp raceintospace/src/game/physfscompat.cpp
--- raceintospace.orig/src/game/physfscompat.cpp	1970-01-01 01:00:00.000000000 +0100
+++ raceintospace/src/game/physfscompat.cpp	2014-09-13 13:49:16.032074490 +0200
@@ -0,0 +1,145 @@
+/*
+ * PhysFS compatibility layer from Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2014 Andrey Korotaev <unc...@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <stddef.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include "physfscompat.h"
+#include "utils.h"
+#include "logging.h"
+
+#ifdef _PHYSFS_COMPAT
+
+LOG_DEFAULT_CATEGORY(filesys)
+
+PHYSFS_DECL int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat)
+{
+    PHYSFS_File * handle;
+
+    if (PHYSFS_exists(fname))
+    {
+        handle = PHYSFS_openRead(fname);
+        if (handle)
+        {
+            stat->filesize = PHYSFS_fileLength(handle);
+            PHYSFS_close(handle);
+            handle = 0;
+        }
+        else
+            stat->filesize = -1;
+
+        stat->modtime = PHYSFS_getLastModTime(fname);
+        stat->createtime = -1;
+        stat->accesstime = -1;
+
+        if (PHYSFS_isSymbolicLink(fname))
+            stat->filetype = PHYSFS_FILETYPE_SYMLINK;
+        else if (PHYSFS_isDirectory(fname))
+            stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
+        else stat->filetype = PHYSFS_FILETYPE_REGULAR;
+
+        stat->readonly = 0; /* not supported */
+
+        /* success */
+        return 1;
+    }
+
+    /* does not exist, can't stat */
+    return 0;
+}
+
+PHYSFS_DECL PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer,
+                                           PHYSFS_uint64 len)
+{
+    return PHYSFS_read(handle, buffer, 1, len);
+}
+
+
+PHYSFS_DECL PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle,
+                                            const void *buffer,
+                                            PHYSFS_uint64 len)
+{
+    return PHYSFS_write(handle, buffer, 1, len);
+}
+
+/* Compatibility wrapper around PHYSFS_getPrefDir, essentially a backport
+   from PhysFS upstream, with minor modifications by Hendrik Weimer
+   <hend...@enyo.de>. The PhysFS license text is reproduced below.
+
+   Copyright (c) 2001-2011 Ryan C. Gordon and others.
+
+   This software is provided 'as-is', without any express or implied warranty.
+   In no event will the authors be held liable for any damages arising from
+   the use of this software.
+
+   Permission is granted to anyone to use this software for any purpose,
+   including commercial applications, and to alter it and redistribute it
+   freely, subject to the following restrictions:
+
+   1. The origin of this software must not be misrepresented; you must not
+   claim that you wrote the original software. If you use this software in a
+   product, an acknowledgment in the product documentation would be
+   appreciated but is not required.
+
+   2. Altered source versions must be plainly marked as such, and must not be
+   misrepresented as being the original software.
+
+   3. This notice may not be removed or altered from any source distribution.
+
+       Ryan C. Gordon <iccu...@icculus.org>
+*/
+   
+PHYSFS_DECL const char *PHYSFS_getPrefDir(const char *org, const char *app)
+{
+    const char *envr = getenv("XDG_DATA_HOME");
+    const char *append = "/";
+    char *retval = NULL;
+    size_t len = 0;
+    struct stat st;
+
+    if (!envr)
+    {
+        /* You end up with "$HOME/.local/share/Game Name 2" */
+        envr = getenv("HOME"); 
+        append = "/.local/share/";
+    } /* if */
+
+    if(!envr)
+    {
+        CRITICAL1("could not find preferences directory");
+        exit(EXIT_FAILURE);
+    }
+
+    len = strlen(envr) + strlen(append) + strlen(app) + 2;
+    retval = (char *) xmalloc(len);
+    snprintf(retval, len, "%s%s%s/", envr, append, app);
+
+    if(stat(retval, &st) && (errno == ENOENT))
+        mkdir(retval, 0755);
+
+    return retval;
+
+}
+
+#endif /* _PHYSFS_COMPAT */
diff -ruN -x .git -x .pc raceintospace.orig/src/game/physfscompat.h raceintospace/src/game/physfscompat.h
--- raceintospace.orig/src/game/physfscompat.h	1970-01-01 01:00:00.000000000 +0100
+++ raceintospace/src/game/physfscompat.h	2014-09-13 13:51:04.280079729 +0200
@@ -0,0 +1,73 @@
+/*
+ * PhysFS compatibility layer from Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2014 Andrey Korotaev <unc...@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _PHYSFSCOMPAT_H
+#define _PHYSFSCOMPAT_H
+
+#include "physfs.h"
+
+#if PHYSFS_VER_MAJOR == 2
+#if PHYSFS_VER_MINOR == 0
+
+#define _PHYSFS_COMPAT
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PHYSFS_DECL __EXPORT__
+
+typedef enum PHYSFS_FileType
+{
+    PHYSFS_FILETYPE_REGULAR,
+    PHYSFS_FILETYPE_DIRECTORY,
+    PHYSFS_FILETYPE_SYMLINK,
+    PHYSFS_FILETYPE_OTHER
+} PHYSFS_FileType;
+
+typedef struct PHYSFS_Stat
+{
+    PHYSFS_sint64 filesize;
+    PHYSFS_sint64 modtime;
+    PHYSFS_sint64 createtime;
+    PHYSFS_sint64 accesstime;
+    PHYSFS_FileType filetype;
+    int readonly;
+} PHYSFS_Stat;
+
+PHYSFS_DECL int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat);
+
+PHYSFS_DECL PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer,
+                                           PHYSFS_uint64 len);
+
+
+PHYSFS_DECL PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle,
+                                            const void *buffer,
+                                            PHYSFS_uint64 len);
+
+PHYSFS_DECL const char *PHYSFS_getPrefDir(const char *org, const char *app);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PHYSFS_VER_MAJOR == 2 */
+#endif /* PHYSFS_VER_MINOR == 0 */
+
+#endif /* _PHYSFSCOMPAT_H */

Reply via email to