-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds zbar (and dependencies) support, refs #854
- zbar Python extension - zbar library - iconv library
- Loading branch information
1 parent
55e9daa
commit 30e72c4
Showing
6 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
from pythonforandroid.toolchain import shprint, current_directory | ||
from pythonforandroid.recipe import Recipe | ||
from multiprocessing import cpu_count | ||
import sh | ||
|
||
|
||
class LibIconvRecipe(Recipe): | ||
|
||
version = '1.15' | ||
|
||
url = 'https://ftp.gnu.org/pub/gnu/libiconv/libiconv-{version}.tar.gz' | ||
|
||
patches = ['libiconv-1.15-no-gets.patch'] | ||
|
||
def should_build(self, arch): | ||
return not os.path.exists( | ||
os.path.join(self.ctx.get_libs_dir(arch.arch), 'libiconv.so')) | ||
|
||
def build_arch(self, arch): | ||
super(LibIconvRecipe, self).build_arch(arch) | ||
env = self.get_recipe_env(arch) | ||
with current_directory(self.get_build_dir(arch.arch)): | ||
shprint( | ||
sh.Command('./configure'), | ||
'--host=' + arch.toolchain_prefix, | ||
'--prefix=' + self.ctx.get_python_install_dir(), | ||
_env=env) | ||
shprint(sh.make, '-j' + str(cpu_count()), _env=env) | ||
libs = ['lib/.libs/libiconv.so'] | ||
self.install_libs(arch, *libs) | ||
|
||
|
||
recipe = LibIconvRecipe() |
22 changes: 22 additions & 0 deletions
22
pythonforandroid/recipes/libiconv/libiconv-1.15-no-gets.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
hack until gzip pulls a newer gnulib version | ||
|
||
From 66712c23388e93e5c518ebc8515140fa0c807348 Mon Sep 17 00:00:00 2001 | ||
From: Eric Blake <eblake@redhat.com> | ||
Date: Thu, 29 Mar 2012 13:30:41 -0600 | ||
Subject: [PATCH] stdio: don't assume gets any more | ||
|
||
Gnulib intentionally does not have a gets module, and now that C11 | ||
and glibc have dropped it, we should be more proactive about warning | ||
any user on a platform that still has a declaration of this dangerous | ||
interface. | ||
|
||
--- a/srclib/stdio.in.h | ||
+++ b/srclib/stdio.in.h | ||
@@ -744,7 +744,6 @@ _GL_WARN_ON_USE (getline, "getline is un | ||
removed it. */ | ||
#undef gets | ||
#if HAVE_RAW_DECL_GETS && !defined __cplusplus | ||
-_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); | ||
#endif | ||
|
||
#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
from pythonforandroid.toolchain import shprint, current_directory | ||
from pythonforandroid.recipe import Recipe | ||
from multiprocessing import cpu_count | ||
import sh | ||
|
||
|
||
class LibZBarRecipe(Recipe): | ||
|
||
version = '0.10' | ||
|
||
url = 'https://github.com/ZBar/ZBar/archive/{version}.zip' | ||
|
||
depends = ['hostpython2', 'python2', 'libiconv'] | ||
|
||
patches = ["werror.patch"] | ||
|
||
def should_build(self, arch): | ||
return not os.path.exists( | ||
os.path.join(self.ctx.get_libs_dir(arch.arch), 'libzbar.so')) | ||
|
||
def get_recipe_env(self, arch=None, with_flags_in_cc=True): | ||
env = super(LibZBarRecipe, self).get_recipe_env(arch, with_flags_in_cc) | ||
libiconv = self.get_recipe('libiconv', self.ctx) | ||
libiconv_dir = libiconv.get_build_dir(arch.arch) | ||
env['CFLAGS'] += ' -I' + os.path.join(libiconv_dir, 'include') | ||
env['LDSHARED'] = env['CC'] + \ | ||
' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' | ||
env['LDFLAGS'] += " -landroid -liconv" | ||
return env | ||
|
||
def build_arch(self, arch): | ||
super(LibZBarRecipe, self).build_arch(arch) | ||
env = self.get_recipe_env(arch) | ||
with current_directory(self.get_build_dir(arch.arch)): | ||
shprint(sh.Command('autoreconf'), '-vif', _env=env) | ||
shprint( | ||
sh.Command('./configure'), | ||
'--host=' + arch.toolchain_prefix, | ||
'--target=' + arch.toolchain_prefix, | ||
'--prefix=' + self.ctx.get_python_install_dir(), | ||
# Python bindings are compiled in a separated recipe | ||
'--with-python=no', | ||
'--with-gtk=no', | ||
'--with-qt=no', | ||
'--with-x=no', | ||
'--with-jpeg=no', | ||
'--with-imagemagick=no', | ||
'--enable-pthread=no', | ||
'--enable-video=no', | ||
'--enable-shared=yes', | ||
'--enable-static=no', | ||
_env=env) | ||
shprint(sh.make, '-j' + str(cpu_count()), _env=env) | ||
libs = ['zbar/.libs/libzbar.so'] | ||
self.install_libs(arch, *libs) | ||
|
||
|
||
recipe = LibZBarRecipe() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/configure.ac b/configure.ac | ||
index 256aedb..727caba 100644 | ||
--- a/configure.ac | ||
+++ b/configure.ac | ||
@@ -3,7 +3,7 @@ AC_PREREQ([2.61]) | ||
AC_INIT([zbar], [0.10], [spadix@users.sourceforge.net]) | ||
AC_CONFIG_AUX_DIR(config) | ||
AC_CONFIG_MACRO_DIR(config) | ||
-AM_INIT_AUTOMAKE([1.10 -Wall -Werror foreign subdir-objects std-options dist-bzip2]) | ||
+AM_INIT_AUTOMAKE([1.10 -Wall foreign subdir-objects std-options dist-bzip2]) | ||
AC_CONFIG_HEADERS([include/config.h]) | ||
AC_CONFIG_SRCDIR(zbar/scanner.c) | ||
LT_PREREQ([2.2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
from pythonforandroid.recipe import PythonRecipe | ||
|
||
|
||
class ZBarRecipe(PythonRecipe): | ||
|
||
version = '0.10' | ||
|
||
# For some reason the version 0.10 on PyPI is not the same as the ones | ||
# in sourceforge and GitHub. The one in PyPI has a setup.py. | ||
# url = 'https://github.com/ZBar/ZBar/archive/{version}.zip' | ||
url = 'https://pypi.python.org/packages/e0/5c/' + \ | ||
'bd2a96a9f2adacffceb4482cdd56831735ab5a67ea6a60c0a8757c17b62e' + \ | ||
'/zbar-{version}.tar.gz' | ||
|
||
call_hostpython_via_targetpython = False | ||
|
||
depends = ['hostpython2', 'python2', 'setuptools', 'libzbar'] | ||
|
||
patches = ["zbar-0.10-python-crash.patch"] | ||
|
||
def get_recipe_env(self, arch=None, with_flags_in_cc=True): | ||
env = super(ZBarRecipe, self).get_recipe_env(arch, with_flags_in_cc) | ||
libzbar = self.get_recipe('libzbar', self.ctx) | ||
libzbar_dir = libzbar.get_build_dir(arch.arch) | ||
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir() | ||
env['CFLAGS'] += ' -I' + os.path.join(libzbar_dir, 'include') | ||
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' | ||
# TODO | ||
env['LDSHARED'] = env['CC'] + \ | ||
' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' | ||
# TODO: hardcoded Python version | ||
env['LDFLAGS'] += " -landroid -lpython2.7 -lzbar" | ||
return env | ||
|
||
|
||
recipe = ZBarRecipe() |
19 changes: 19 additions & 0 deletions
19
pythonforandroid/recipes/zbar/zbar-0.10-python-crash.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
https://sourceforge.net/p/zbar/patches/37/ | ||
|
||
fix from Debian for crashes when importing the python module. | ||
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=702499 | ||
|
||
this doesn't happen on some arches as the data naturally ends up with zero | ||
data after the structure, but on some (like arm), it isn't so we crash when | ||
python walks the list. | ||
|
||
--- a/imagescanner.c | ||
+++ b/imagescanner.c | ||
@@ -68,6 +68,7 @@ imagescanner_get_results (zbarImageScanner *self, | ||
|
||
static PyGetSetDef imagescanner_getset[] = { | ||
{ "results", (getter)imagescanner_get_results, }, | ||
+ { NULL }, | ||
}; | ||
|
||
static PyObject* |