From b9f320b74352a88649f498af9a9fc608fa45d558 Mon Sep 17 00:00:00 2001 From: Michael McMaster Date: Tue, 4 Oct 2011 15:02:25 +1000 Subject: [PATCH] Added android support. --- FileReader.cc | 1 + FileWriter.cc | 1 + INSTALL | 2 ++ INSTALL.Android | 40 +++++++++++++++++++++++++ Makefile.am | 25 ++++++++++++++-- NEWS | 3 ++ VERSION | 2 +- android/zipper/Android.mk | 42 +++++++++++++++++++++++++++ autodeb.sh | 4 +-- configure.ac | 6 +++- debian/changelog | 6 ++++ port/strerror_gnu.cc | 38 ++++++++++++++++++++++++ strerror.cc => port/strerror_posix.cc | 14 +++------ zip.cc | 1 + zipper.cc | 1 + 15 files changed, 169 insertions(+), 17 deletions(-) create mode 100644 INSTALL.Android create mode 100644 android/zipper/Android.mk create mode 100644 port/strerror_gnu.cc rename strerror.cc => port/strerror_posix.cc (78%) diff --git a/FileReader.cc b/FileReader.cc index b43c393..054c24e 100644 --- a/FileReader.cc +++ b/FileReader.cc @@ -25,6 +25,7 @@ #include #include #include +#include using namespace zipper; diff --git a/FileWriter.cc b/FileWriter.cc index 94cb48b..53e7de7 100644 --- a/FileWriter.cc +++ b/FileWriter.cc @@ -27,6 +27,7 @@ #include #include #include +#include using namespace zipper; diff --git a/INSTALL b/INSTALL index 1f62fb9..91ff44f 100644 --- a/INSTALL +++ b/INSTALL @@ -1,6 +1,8 @@ libzipper Michael McMaster +* Refer to INSTALL.Android for Google Android NDK compilation information. + Pre-Requisites g++ (4.5.3) make (GNU make 3.81) diff --git a/INSTALL.Android b/INSTALL.Android new file mode 100644 index 0000000..e72f196 --- /dev/null +++ b/INSTALL.Android @@ -0,0 +1,40 @@ +libzipper +Michael McMaster + +Pre-Requisites + Android NDK (tested with android-ndk-r6) + Existing Android project + +NDK Limitations + * Your Application.mk file must enable C++ exceptions with: + APP_CPPFLAGS := -fexceptions -frtti + Although the NDK supports exceptions as of r5, they are disabled by + default for backwards compatibility. + + * Your Application.mk file must specify a C++ STL implementation with + exception support. As of r6, only gnustl_static provides exception support. + APP_STL := gnustl_static + +Note that this port doesn't include any JNI interface code. It is expected that +libzipper will be called from other native code libraries, and not directly +from Java. + +Including libzipper in your NDK project: +1) Modify your Application.mk file to include the module, and + set APP_CPPFLAGS and APP_STL as stated under "NDK Limitations" above. + + APP_CPPFLAGS += -fexceptions -frtti + APP_STL := gnustl_static + APP_MODULES += zipper + +2) Modify your applications Android.mk file to import the libzipper module: + + LOCAL_STATIC_LIBRARIES += libzipper + $(call import-module,zipper) + +3) Set the NDK_MODULE_PATH variable to include the libzipper source directory + when calling ndk-build. + eg. If libzipper was extracted to /tmp/libzipper-1.0.3: + + cd /path/to/your/ndk/application + ndk-build NDK_MODULE_PATH="/tmp/libzipper-1.0.3/android" diff --git a/Makefile.am b/Makefile.am index e8cc63f..3c36fae 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,16 +17,28 @@ include doxygen.am -dist_noinst_SCRIPTS = autogen.sh +dist_noinst_SCRIPTS = \ + autogen.sh + +DIST_COMMON = \ + config.guess \ + config.sub \ + depcomp \ + install-sh \ + ltmain.sh \ + missing + pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libzipper1.pc EXTRA_DIST = \ COPYING \ INSTALL \ + INSTALL.Android \ NEWS \ README \ - VERSION + VERSION \ + android/zipper/Android.mk lib_LTLIBRARIES = libzipper.la @@ -44,13 +56,20 @@ libzipper_la_SOURCES = \ gzip.hh \ Reader.cc \ split.hh \ - strerror.cc \ strerror.hh \ util.hh \ Writer.cc \ zip.hh \ zip.cc +if HAVE_GNU_STRERROR +libzipper_la_SOURCES += \ + port/strerror_gnu.cc +else +libzipper_la_SOURCES += \ + port/strerror_posix.cc +endif + # Public API headers go here, for installation to /usr/include include_HEADERS = zipper.hh diff --git a/NEWS b/NEWS index 85a043f..108d837 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +2011-10-04 Version 1.0.3 + - Added Android NDK support + 2011-09-07 Version 1.0.2 - Fixed a bug in deflate, which caused it to exit prematurely and report valid files as corrupt. diff --git a/VERSION b/VERSION index 6d7de6e..21e8796 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.2 +1.0.3 diff --git a/android/zipper/Android.mk b/android/zipper/Android.mk new file mode 100644 index 0000000..48ebedc --- /dev/null +++ b/android/zipper/Android.mk @@ -0,0 +1,42 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_CFLAGS := -W -Wall -Werror -D_POSIX_C_SOURCE=200112 + +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../ + +# bionic /sys/types.h fails with -std=c++0x, as it doesn't include +# stdint.h, but tries to use uint64_t. +LOCAL_CPPFLAGS := -std=gnu++0x +LOCAL_EXPORT_CPPFLAGS := -std=gnu++0x + +# libzipper throws exceptions +LOCAL_CPPFLAGS += -fexceptions -frtti +LOCAL_EXPORT_CPPFLAGS += -fexceptions -frtti + +LOCAL_CPP_EXTENSION := .cc + +LOCAL_LDLIBS := -lz +LOCAL_EXPORT_LDLIBS := -lz + +LOCAL_MODULE := zipper +LOCAL_MODULE_FILENAME := libzipper + +LOCAL_SRC_FILES :=\ + ../../CompressedFile.cc \ + ../../deflate.cc \ + ../../gzip.cc \ + ../../zip.cc \ + ../../Compressor.cc \ + ../../Exception.cc \ + ../../Reader.cc \ + ../../zipper.cc \ + ../../Container.cc \ + ../../FileReader.cc \ + ../../Decompressor.cc \ + ../../FileWriter.cc \ + ../../Writer.cc \ + ../../port/strerror_posix.cc \ + +include $(BUILD_STATIC_LIBRARY) diff --git a/autodeb.sh b/autodeb.sh index b5ee069..b15c1a9 100755 --- a/autodeb.sh +++ b/autodeb.sh @@ -33,10 +33,10 @@ cp -a ${SRC}/debian libzipper-${VERSION} cd libzipper-${VERSION} dpkg-buildpackage -rfakeroot -if ! lintian --color auto --fail-on-warnings -i ${BUILD}/libzipper_1.0.2-1.dsc; then +if ! lintian --color auto --fail-on-warnings -i ${BUILD}/libzipper_1.0.3-1.dsc; then echo "Build failed" exit 1; -elif ! lintian --color auto --fail-on-warnings -i ${BUILD}/libzipper_1.0.2-1_amd64.changes; then +elif ! lintian --color auto --fail-on-warnings -i ${BUILD}/libzipper_1.0.3-1_amd64.changes; then echo "Build failed" exit 1; else diff --git a/configure.ac b/configure.ac index 51dec69..1ed643a 100644 --- a/configure.ac +++ b/configure.ac @@ -27,7 +27,11 @@ AM_MAINTAINER_MODE AC_SUBST([libzipper_version], m4_esyscmd_s([cat VERSION])) AC_PROG_CXX -AC_PROG_LIBTOOL +AC_LANG([C++]) +AM_PROG_LIBTOOL + +AC_FUNC_STRERROR_R +AM_CONDITIONAL(HAVE_GNU_STRERROR,[test x$ac_cv_func_strerror_r_char_p = xyes]) DX_DOXYGEN_FEATURE([ON]) DX_HTML_FEATURE([ON]) diff --git a/debian/changelog b/debian/changelog index 1d78d64..d2d8fac 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +libzipper (1.0.3-1) unstable; urgency=low + + * Added Android NDK support + + -- Michael McMaster Tue, 04 Oct 2011 13:22:11 +1000 + libzipper (1.0.2-1) unstable; urgency=low * Fixed a bug in the deflate methods, which would report corrupt data for diff --git a/port/strerror_gnu.cc b/port/strerror_gnu.cc new file mode 100644 index 0000000..d41eddb --- /dev/null +++ b/port/strerror_gnu.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2011 Michael McMaster +// +// This file is part of libzipper. +// +// libzipper 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, either version 3 of the License, or +// (at your option) any later version. +// +// libzipper 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 libzipper. If not, see . + +#define _GNU_SOURCE + +#include "../strerror.hh" + +#include + +using namespace zipper; + +std::string +zipper::strerror(int errnum) +{ + char buf[1024]; + const char* message(NULL); + + // The GNU-specific strerror_r may use the provided buffer, OR a static + // buffer. + message = strerror_r(errnum, buf, sizeof(buf)); + + return std::string(message); +} + diff --git a/strerror.cc b/port/strerror_posix.cc similarity index 78% rename from strerror.cc rename to port/strerror_posix.cc index 4b6a022..83f4f8f 100644 --- a/strerror.cc +++ b/port/strerror_posix.cc @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with libzipper. If not, see . -#include "strerror.hh" +#include "../strerror.hh" #include @@ -25,23 +25,17 @@ std::string zipper::strerror(int errnum) { char buf[1024]; - char* message(NULL); + const char* message(NULL); -#ifdef _GNU_SOURCE - // The GNU-specific strerror_r may use the provided buffer, OR a static - // buffer. - message = strerror_r(errnum, buf, sizeof(buf)); - -#elif (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) +#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) int error(strerror_r(errnum, buf, sizeof(buf))); if (error != 0) { message = "Unknown error"; } - #else // Thread-unsafe fallback - message = strerror(errnum); + message = ::strerror(errnum); #endif return std::string(message); diff --git a/zip.cc b/zip.cc index caca8ef..1655072 100644 --- a/zip.cc +++ b/zip.cc @@ -294,6 +294,7 @@ namespace centralDirectoryEntries ) ); + (void) isZip; // Avoid unused warning. assert(isZip); std::vector buffer(centralDirectoryBytes); diff --git a/zipper.cc b/zipper.cc index 64f1014..52c6c1c 100644 --- a/zipper.cc +++ b/zipper.cc @@ -17,6 +17,7 @@ #include "zipper.hh" #include "split.hh" +#include #include "strerror.hh" #include -- 2.38.5