Enable conditional compilation for ZIP/zlib support.

This commit is contained in:
Stephen Anthony 2019-04-24 15:36:20 -02:30
parent c3483d1553
commit 00e464afc3
12 changed files with 123 additions and 85 deletions

105
configure vendored
View File

@ -13,9 +13,6 @@
# use environment vars if set
CXXFLAGS="$CXXFLAGS $CPPFLAGS"
# default lib behaviour yes/no/auto
_libpng=auto
# default option behaviour yes/no
_build_windowed=yes
_build_sound=yes
@ -23,6 +20,7 @@ _build_debugger=yes
_build_joystick=yes
_build_cheats=yes
_build_png=yes
_build_zip=yes
_build_static=no
_build_profile=no
_build_debug=no
@ -201,6 +199,8 @@ Optional Features:
--disable-cheats
--enable-png enable/disable PNG image support [enabled]
--disable-png
--enable-zip enable/disable ZIP file support [enabled]
--disable-zip
--enable-windowed enable/disable windowed rendering modes [enabled]
--disable-windowed
--enable-shared build shared binary [enabled]
@ -210,7 +210,6 @@ Optional Features:
--disable-profile
--enable-debug build with debugging symbols [disabled]
--disable-debug
--force-builtin-libpng force use of built-in libpng library [auto]
Optional Libraries:
--with-sdl-prefix=DIR Prefix where the sdl2-config script is installed (optional)
@ -242,6 +241,8 @@ for ac_option in $@; do
--disable-cheats) _build_cheats=no ;;
--enable-png) _build_png=yes ;;
--disable-png) _build_png=no ;;
--enable-zip) _build_zip=yes ;;
--disable-zip) _build_zip=no ;;
--enable-windowed) _build_windowed=yes ;;
--disable-windowed) _build_windowed=no ;;
--enable-shared) _build_static=no ;;
@ -251,7 +252,6 @@ for ac_option in $@; do
--disable-profile) _build_profile=no ;;
--enable-debug) _build_debug=yes ;;
--disable-debug) _build_debug=false ;;
--force-builtin-libpng) _libpng=no ;;
--with-sdl-prefix=*)
arg=`echo $ac_option | cut -d '=' -f 2`
_sdlpath="$arg:$arg/bin"
@ -590,31 +590,11 @@ if test -n "$_host_prefix"; then
_strip="$_host_prefix-$_strip"
fi
#
# Check for libpng
#
echocheck "libpng"
if test "$_libpng" = auto ; then
_libpng=no
cat > $TMPC << EOF
#include <stdio.h>
#include <png.h>
int main(void) { return printf("%s\n", PNG_HEADER_VERSION_STRING); }
EOF
cc_check $LDFLAGS $CXXFLAGS $LIBPNG_CFLAGS $LIBPNG_LIBS `pkg-config --libs libpng` && _libpng=yes
fi
if test "$_libpng" = yes ; then
_zlib=auto
echo "$_libpng"
else
echo "none found, using built-in version"
fi
#
# Check for ZLib
#
if test "$_zlib" = auto ; then
echocheck "zlib"
echocheck "zlib"
if test "$_build_zip" = yes ; then
_zlib=no
cat > $TMPC << EOF
#include <string.h>
@ -626,9 +606,38 @@ EOF
if test "$_zlib" = yes ; then
echo "$_zlib"
else
echo "zlib missing"
exit 1
echo "disabled"
_build_png=no
_build_zip=no
fi
else
echo "disabled"
_build_png=no
_build_zip=no
fi
#
# Check for libpng
#
echocheck "libpng"
if test "$_build_png" = yes ; then
_libpng=no
cat > $TMPC << EOF
#include <stdio.h>
#include <png.h>
int main(void) { return printf("%s\n", PNG_HEADER_VERSION_STRING); }
EOF
cc_check $LDFLAGS $CXXFLAGS $LIBPNG_CFLAGS $LIBPNG_LIBS `pkg-config --libs libpng` && _libpng=yes
if test "$_libpng" = yes ; then
echo "$_libpng"
else
echo "disabled"
_build_png=no
fi
else
echo "disabled"
_build_png=no
fi
#
@ -682,6 +691,14 @@ else
echo
fi
if test "$_build_zip" = yes ; then
echo_n " ZIP file support enabled"
echo
else
echo_n " ZIP file support disabled"
echo
fi
if test "$_build_windowed" = "yes" ; then
echo_n " Windowed rendering modes enabled"
echo
@ -777,20 +794,6 @@ case $_host_os in
;;
esac
if test "$_libpng" = yes ; then
LIBS="$LIBS -lpng"
else
MODULES="$MODULES $LIBPNG"
INCLUDES="$INCLUDES -I$LIBPNG"
fi
if test "$_zlib" = yes ; then
LIBS="$LIBS -lz"
else
MODULES="$MODULES $ZLIB"
INCLUDES="$INCLUDES -I$ZLIB"
fi
if test "$_build_windowed" = yes ; then
DEFINES="$DEFINES -DWINDOWED_SUPPORT"
fi
@ -817,6 +820,22 @@ fi
if test "$_build_png" = yes ; then
DEFINES="$DEFINES -DPNG_SUPPORT"
if test "$_libpng" = yes ; then
LIBS="$LIBS -lpng"
else
MODULES="$MODULES $LIBPNG"
INCLUDES="$INCLUDES -I$LIBPNG"
fi
fi
if test "$_build_zip" = yes ; then
DEFINES="$DEFINES -DZIP_SUPPORT"
if test "$_zlib" = yes ; then
LIBS="$LIBS -lz"
else
MODULES="$MODULES $ZLIB"
INCLUDES="$INCLUDES -I$ZLIB"
fi
fi
if test "$_build_profile" = no ; then

View File

@ -19,6 +19,10 @@
#define FSNODE_FACTORY_HXX
class AbstractFSNode;
#if defined(ZIP_SUPPORT)
#include "FSNodeZIP.hxx"
#endif
#if defined(BSPF_UNIX) || defined(BSPF_MACOS)
#include "FSNodePOSIX.hxx"
#elif defined(BSPF_WINDOWS)
@ -28,11 +32,9 @@ class AbstractFSNode;
#else
#error Unsupported platform in FSNodeFactory!
#endif
#include "FSNodeZIP.hxx"
/**
This class deals with creating the different FSNode implementations.
I think you can see why this mess was put into a factory class :)
@author Stephen Anthony
*/
@ -47,16 +49,18 @@ class FilesystemNodeFactory
switch(type)
{
case Type::SYSTEM:
#if defined(BSPF_UNIX) || defined(BSPF_MACOS)
#if defined(BSPF_UNIX) || defined(BSPF_MACOS)
return make_unique<FilesystemNodePOSIX>(path);
#elif defined(BSPF_WINDOWS)
#elif defined(BSPF_WINDOWS)
return make_unique<FilesystemNodeWINDOWS>(path);
#elif defined(__LIB_RETRO__)
#elif defined(__LIB_RETRO__)
return make_unique<FilesystemNodeLIBRETRO>(path);
#endif
#endif
break;
case Type::ZIP:
#if defined(ZIP_SUPPORT)
return make_unique<FilesystemNodeZIP>(path);
#endif
break;
}
return nullptr;

View File

@ -15,6 +15,8 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#if defined(ZIP_SUPPORT)
#include <set>
#include "bspf.hxx"
@ -210,3 +212,5 @@ AbstractFSNodePtr FilesystemNodeZIP::getParent() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
unique_ptr<ZipHandler> FilesystemNodeZIP::myZipHandler = make_unique<ZipHandler>();
#endif // ZIP_SUPPORT

View File

@ -15,6 +15,8 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#if defined(ZIP_SUPPORT)
#ifndef FS_NODE_ZIP_HXX
#define FS_NODE_ZIP_HXX
@ -119,3 +121,5 @@ class FilesystemNodeZIP : public AbstractFSNode
};
#endif
#endif // ZIP_SUPPORT

View File

@ -15,6 +15,8 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#if defined(ZIP_SUPPORT)
#include <zlib.h>
#include "Bankswitch.hxx"
@ -540,3 +542,5 @@ ZipHandler::ZipEcd::ZipEcd()
cdStartDiskOffset(0)
{
}
#endif /* ZIP_SUPPORT */

View File

@ -15,6 +15,8 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#if defined(ZIP_SUPPORT)
#ifndef ZIP_HANDLER_HXX
#define ZIP_HANDLER_HXX
@ -318,3 +320,5 @@ class ZipHandler
};
#endif /* ZIP_HANDLER_HXX */
#endif /* ZIP_SUPPORT */

View File

@ -18,8 +18,6 @@
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include <zlib.h>
#include "bspf.hxx"
#include "FSNodeFactory.hxx"
#include "FSNode.hxx"
@ -39,9 +37,11 @@ FilesystemNode::FilesystemNode(AbstractFSNodePtr realNode)
FilesystemNode::FilesystemNode(const string& p)
{
// Is this potentially a ZIP archive?
#if defined(ZIP_SUPPORT)
if(BSPF::containsIgnoreCase(p, ".zip"))
_realNode = FilesystemNodeFactory::create(p, FilesystemNodeFactory::Type::ZIP);
else
#endif
_realNode = FilesystemNodeFactory::create(p, FilesystemNodeFactory::Type::SYSTEM);
}
@ -107,15 +107,6 @@ string FilesystemNode::getPathWithExt(const string& ext) const
return (pos != string::npos) ? s.replace(pos, string::npos, ext) : s + ext;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string FilesystemNode::getShortPathWithExt(const string& ext) const
{
string s = _realNode->getShortPath();
size_t pos = s.find_last_of(".");
return (pos != string::npos) ? s.replace(pos, string::npos, ext) : s + ext;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FilesystemNode::hasParent() const
{
@ -173,27 +164,31 @@ uInt32 FilesystemNode::read(BytePtr& image) const
{
uInt32 size = 0;
// First let the private subclass attempt to open the file
if((size = _realNode->read(image)) > 0)
return size;
// File must actually exist
if(!(exists() && isReadable()))
throw runtime_error("File not found/readable");
// Otherwise, assume the file is either gzip'ed or not compressed at all
gzFile f = gzopen(getPath().c_str(), "rb");
if(f)
{
image = make_unique<uInt8[]>(512 * 1024);
size = gzread(f, image.get(), 512 * 1024);
gzclose(f);
// First let the private subclass attempt to open the file
if((size = _realNode->read(image)) > 0)
return size;
if(size == 0)
// Otherwise, the default behaviour is to read from a normal C++ ifstream
image = make_unique<uInt8[]>(512 * 1024);
ifstream in(getPath(), std::ios::binary);
if(in)
{
in.seekg(0, std::ios::end);
std::streampos length = in.tellg();
in.seekg(0, std::ios::beg);
if(length == 0)
throw runtime_error("Zero-byte file");
return size;
size = std::min(uInt32(length), 512u * 1024u);
in.read(reinterpret_cast<char*>(image.get()), size);
}
else
throw runtime_error("ZLIB open/read error");
throw runtime_error("File open/read error");
return size;
}

View File

@ -253,7 +253,6 @@ class FilesystemNode
*/
string getNameWithExt(const string& ext) const;
string getPathWithExt(const string& ext) const;
string getShortPathWithExt(const string& ext) const; // FIXME - dead code
private:
AbstractFSNodePtr _realNode;

View File

@ -84,7 +84,10 @@ OSystem::OSystem()
myFeatures += "Cheats ";
#endif
#ifdef PNG_SUPPORT
myFeatures += "PNG";
myFeatures += "PNG ";
#endif
#ifdef ZIP_SUPPORT
myFeatures += "ZIP";
#endif
// Get build info
@ -651,10 +654,10 @@ double OSystem::dispatchEmulation(EmulationWorker& emulationWorker)
case DispatchResult::Status::fatal:
#ifdef DEBUGGER_SUPPORT
myDebugger->startWithFatalError(dispatchResult.getMessage());
break;
#else
throw runtime_error(dispatchResult.getMessage());
cerr << dispatchResult.getMessage() << endl;
#endif
break;
default:
throw runtime_error("invalid emulation dispatch result");

View File

@ -3031,6 +3031,7 @@
DEBUGGER_SUPPORT,
JOYSTICK_SUPPORT,
PNG_SUPPORT,
ZIP_SUPPORT,
SOUND_SUPPORT,
WINDOWED_SUPPORT,
BSPF_MACOS,
@ -3086,6 +3087,7 @@
DEBUGGER_SUPPORT,
JOYSTICK_SUPPORT,
PNG_SUPPORT,
ZIP_SUPPORT,
SOUND_SUPPORT,
WINDOWED_SUPPORT,
BSPF_MACOS,

View File

@ -178,7 +178,7 @@ bool FilesystemNodePOSIX::getChildren(AbstractFSList& myList, ListMode mode,
(mode == FilesystemNode::ListMode::DirectoriesOnly && !entry._isDirectory))
continue;
myList.emplace_back(new FilesystemNodePOSIX(entry));
myList.emplace_back(make_shared<FilesystemNodePOSIX>(entry));
}
closedir(dirp);

View File

@ -157,7 +157,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\yacc;..\emucore;..\emucore\tia;..\emucore\tia\frame-manager;..\common;..\common\tv_filters;..\gui;..\debugger\gui;..\debugger;..\windows;..\cheat;..\zlib;..\libpng;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;DEBUG_BUILD;SDL_SUPPORT;PNG_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;DEBUG_BUILD;SDL_SUPPORT;PNG_SUPPORT;ZIP_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@ -193,7 +193,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\yacc;..\emucore;..\emucore\tia;..\emucore\tia\frame-manager;..\common;..\common\tv_filters;..\gui;..\debugger\gui;..\debugger;..\windows;..\cheat;..\zlib;..\libpng;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;DEBUG_BUILD;SDL_SUPPORT;PNG_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;DEBUG_BUILD;SDL_SUPPORT;PNG_SUPPORT;ZIP_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@ -226,7 +226,7 @@
<OmitFramePointers>true</OmitFramePointers>
<WholeProgramOptimization>false</WholeProgramOptimization>
<AdditionalIncludeDirectories>..\yacc;..\emucore;..\emucore\tia;..\emucore\tia\frame-manager;..\common;..\common\tv_filters;..\gui;..\debugger\gui;..\debugger;..\windows;..\cheat;..\zlib;..\libpng;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;NDEBUG;SDL_SUPPORT;PNG_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;NDEBUG;SDL_SUPPORT;PNG_SUPPORT;ZIP_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<PrecompiledHeader>
@ -260,7 +260,7 @@
<OmitFramePointers>true</OmitFramePointers>
<WholeProgramOptimization>false</WholeProgramOptimization>
<AdditionalIncludeDirectories>..\yacc;..\emucore;..\emucore\tia;..\emucore\tia\frame-manager;..\common;..\common\tv_filters;..\gui;..\debugger\gui;..\debugger;..\windows;..\cheat;..\zlib;..\libpng;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;NDEBUG;SDL_SUPPORT;PNG_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;NDEBUG;SDL_SUPPORT;PNG_SUPPORT;ZIP_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<PrecompiledHeader>
@ -298,7 +298,7 @@
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<OmitFramePointers>true</OmitFramePointers>
<AdditionalIncludeDirectories>..\yacc;..\emucore;..\emucore\tia;..\emucore\tia\frame-manager;..\common;..\common\tv_filters;..\gui;..\debugger\gui;..\debugger;..\windows;..\cheat;..\zlib;..\libpng;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;NDEBUG;SDL_SUPPORT;PNG_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;NDEBUG;SDL_SUPPORT;PNG_SUPPORT;ZIP_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<PrecompiledHeader>
@ -335,7 +335,7 @@
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<OmitFramePointers>true</OmitFramePointers>
<AdditionalIncludeDirectories>..\yacc;..\emucore;..\emucore\tia;..\emucore\tia\frame-manager;..\common;..\common\tv_filters;..\gui;..\debugger\gui;..\debugger;..\windows;..\cheat;..\zlib;..\libpng;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;NDEBUG;SDL_SUPPORT;PNG_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>BSPF_WINDOWS;WIN32;NDEBUG;SDL_SUPPORT;PNG_SUPPORT;ZIP_SUPPORT;JOYSTICK_SUPPORT;DEBUGGER_SUPPORT;WINDOWED_SUPPORT;SOUND_SUPPORT;CHEATCODE_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<PrecompiledHeader>