Link against system Crypto++ if available
authorToni Spets <toni.spets@iki.fi>
Tue, 1 Mar 2011 21:25:07 +0000 (23:25 +0200)
committerToni Spets <toni.spets@iki.fi>
Tue, 1 Mar 2011 21:25:07 +0000 (23:25 +0200)
configure.ac
src/CryptHelpers.cpp
src/Makefile.am

index 1455b07..0903093 100644 (file)
@@ -177,6 +177,7 @@ SM_LIBUSB
 
 have_ffmpeg=no
 have_libresample=no
+have_libcryptopp=no
 
 # search for system libs if not building for arcade
 if test "$itg_arcade" = "no"; then
@@ -190,6 +191,15 @@ if test "$itg_arcade" = "no"; then
                LIBS="$LIBS -lresample"
        fi
 
+       # there has to be a better way... -hifi
+       AC_LANG([C++])
+       AC_CHECK_HEADER([crypto++/cryptlib.h], have_libcryptopp=yes, have_libcryptopp=no)
+       AC_LANG([C])
+       if test "$have_libcryptopp" = "yes"; then
+               LIBS="$LIBS -lcrypto++"
+               AC_DEFINE(HAVE_LIBCRYPTOPP, 1, [system CryptoPP available])
+       fi
+
        if test "$have_libavcodec" = "yes"; then
          AC_MSG_CHECKING([for libavcodec >= 0.6.1])
          AC_TRY_RUN([
@@ -234,6 +244,7 @@ fi
 
 AM_CONDITIONAL(HAVE_FFMPEG, test "$have_ffmpeg" = "yes")
 AM_CONDITIONAL(HAVE_LIBRESAMPLE, test "$have_libresample" = "yes")
+AM_CONDITIONAL(HAVE_LIBCRYPTOPP, test "$have_libcryptopp" = "yes")
 
 SM_CHECK_CRASH_HANDLER
 
index 1a53a4b..fdb5878 100755 (executable)
@@ -6,12 +6,21 @@
 
 // crypt headers
 #include <typeinfo>
-#include "crypto561/files.h"
-#include "crypto561/filters.h"
-#include "crypto561/cryptlib.h"
-#include "crypto561/sha.h"
-#include "crypto561/rsa.h"
-#include "crypto561/osrng.h"
+#if defined(HAVE_LIBCRYPTOPP)
+       #include <crypto++/files.h>
+       #include <crypto++/filters.h>
+       #include <crypto++/cryptlib.h>
+       #include <crypto++/sha.h>
+       #include <crypto++/rsa.h>
+       #include <crypto++/osrng.h>
+#else
+       #include "crypto561/files.h"
+       #include "crypto561/filters.h"
+       #include "crypto561/cryptlib.h"
+       #include "crypto561/sha.h"
+       #include "crypto561/rsa.h"
+       #include "crypto561/osrng.h"
+#endif
 #if defined(_MSC_VER) && !defined(_XBOX) && _MSC_VER <= 1310
 #if defined(_DEBUG)
 #pragma comment(lib, "crypto561/cryptlib_vs2003/Win32/output/debug/cryptlib_vs2003.lib")
@@ -52,7 +61,24 @@ private:
        bool m_waiting;
 };
 
-class RageFileSource : public SourceTemplate<RageFileStore>
+template <class T>
+class RageSourceTemplate : public Source
+{
+public:
+       RageSourceTemplate<T>(BufferedTransformation *attachment, T _store)
+               : Source(attachment), m_store(_store) {}
+        size_t Pump2(lword &byteCount, bool blocking=true)
+                {return m_store.TransferTo2(*AttachedTransformation(), byteCount, DEFAULT_CHANNEL, blocking);}
+        size_t PumpMessages2(unsigned int &messageCount, bool blocking=true)
+                {return m_store.TransferMessagesTo2(*AttachedTransformation(), messageCount, DEFAULT_CHANNEL, blocking);}
+        bool SourceExhausted() const
+                {return !m_store.AnyRetrievable() && !m_store.AnyMessages();}
+
+protected:
+        T m_store;
+};
+
+class RageFileSource : public RageSourceTemplate<RageFileStore>
 {
 public:
        typedef FileStore::Err Err;
@@ -60,7 +86,7 @@ public:
        typedef FileStore::ReadErr ReadErr;
 
        RageFileSource( RageFileBasic *pFile, bool pumpAll, BufferedTransformation *attachment = NULL )
-               : SourceTemplate<RageFileStore>(attachment,RageFileStore(pFile)) {SourceInitialize(pumpAll, MakeParameters("InputBinaryMode", true, false));}
+               : RageSourceTemplate<RageFileStore>(attachment,RageFileStore(pFile)) {SourceInitialize(pumpAll, MakeParameters("InputBinaryMode", true, false));}
 };
 
 RageFileStore::ReadErr::ReadErr( const RageFileBasic &f ):
index b4a45f0..3d3aaef 100755 (executable)
@@ -21,8 +21,17 @@ else
 LIBS += -nodefaultlibs -Wl,-Bstatic -lstdc++ $(LUA_LIBS) -lXrandr -lXrender -lmad -lgcc -lgcc_eh -Wl,-Bdynamic -lpthread -lusb -lc
 endif
 
+STATIC_LIBS =
+
 if !HAVE_LIBRESAMPLE
-all: $(srcdir)/libresample/libresample.a $(srcdir)/crypto561/libcryptopp.a
+       $(STATIC_LIBS) += $(srcdir)/libresample/libresample.a
+endif
+
+if !HAVE_LIBCRYPTOPP
+       $(STATIC_LIBS) += $(srcdir)/crypto561/libcryptopp.a
+endif
+
+all: $(STATIC_LIBS)
 
 clean-local: clean_libresample
 
@@ -31,9 +40,6 @@ clean_libresample:
 
 $(srcdir)/libresample/libresample.a:
        cd $(srcdir)/libresample && autoconf && sh ./configure && make
-else
-all: $(srcdir)/crypto561/libcryptopp.a
-endif
 
 $(srcdir)/crypto561/libcryptopp.a:
        cd $(srcdir)/crypto561 && make -f GNUmakefile
@@ -445,8 +451,7 @@ main_SOURCES = $(Screens) \
 main_LDADD = \
                  $(AUDIO_LIBS) \
                  $(SDL_LIBS) \
-                 $(XLIBS) \
-                 $(srcdir)/crypto561/libcryptopp.a
+                 $(XLIBS)
 
 openitg_SOURCES = $(main_SOURCES)
 
@@ -454,6 +459,10 @@ if !HAVE_LIBRESAMPLE
 main_LDADD += $(srcdir)/libresample/libresample.a
 endif
 
+if !HAVE_LIBCRYPTOPP
+main_LDADD += $(srcdir)/crypto561/libcryptopp.a
+endif
+
 if !HAVE_FFMPEG
 openitg_LDADD = $(main_LDADD) \
        $(srcdir)/ffmpeg/lib/libavformat.a $(srcdir)/ffmpeg/lib/libavcodec.a
@@ -523,9 +532,12 @@ test_file_errors_SOURCES = \
                tests/test_file_errors.cpp \
                MsdFile.cpp MsdFile.h \
                XmlFile.cpp XmlFile.h \
-               $(srcdir)/crypto561/libcryptopp.a \
                CryptManager.cpp CryptManager.h $(cryptopp) $(crypto)
 
+if !HAVE_LIBCRYPTOPP
+test_file_errors_SOURCES += $(srcdir)/crypto561/libcryptopp.a
+endif
+
 TESTS += test_timing_data
 test_timing_data_SOURCES = \
                $(all_test_SOURCES) \