Skip to content

Commit a12f289

Browse files
authored
Merge pull request kivy#1145 from AndreMiras/feature/ticket854_zbar_support
Adds zbar (and dependencies) support, refs kivy#854
2 parents fbcd9e1 + 30e72c4 commit a12f289

File tree

6 files changed

+184
-0
lines changed

6 files changed

+184
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
from pythonforandroid.toolchain import shprint, current_directory
3+
from pythonforandroid.recipe import Recipe
4+
from multiprocessing import cpu_count
5+
import sh
6+
7+
8+
class LibIconvRecipe(Recipe):
9+
10+
version = '1.15'
11+
12+
url = 'https://ftp.gnu.org/pub/gnu/libiconv/libiconv-{version}.tar.gz'
13+
14+
patches = ['libiconv-1.15-no-gets.patch']
15+
16+
def should_build(self, arch):
17+
return not os.path.exists(
18+
os.path.join(self.ctx.get_libs_dir(arch.arch), 'libiconv.so'))
19+
20+
def build_arch(self, arch):
21+
super(LibIconvRecipe, self).build_arch(arch)
22+
env = self.get_recipe_env(arch)
23+
with current_directory(self.get_build_dir(arch.arch)):
24+
shprint(
25+
sh.Command('./configure'),
26+
'--host=' + arch.toolchain_prefix,
27+
'--prefix=' + self.ctx.get_python_install_dir(),
28+
_env=env)
29+
shprint(sh.make, '-j' + str(cpu_count()), _env=env)
30+
libs = ['lib/.libs/libiconv.so']
31+
self.install_libs(arch, *libs)
32+
33+
34+
recipe = LibIconvRecipe()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
hack until gzip pulls a newer gnulib version
2+
3+
From 66712c23388e93e5c518ebc8515140fa0c807348 Mon Sep 17 00:00:00 2001
4+
From: Eric Blake <eblake@redhat.com>
5+
Date: Thu, 29 Mar 2012 13:30:41 -0600
6+
Subject: [PATCH] stdio: don't assume gets any more
7+
8+
Gnulib intentionally does not have a gets module, and now that C11
9+
and glibc have dropped it, we should be more proactive about warning
10+
any user on a platform that still has a declaration of this dangerous
11+
interface.
12+
13+
--- a/srclib/stdio.in.h
14+
+++ b/srclib/stdio.in.h
15+
@@ -744,7 +744,6 @@ _GL_WARN_ON_USE (getline, "getline is un
16+
removed it. */
17+
#undef gets
18+
#if HAVE_RAW_DECL_GETS && !defined __cplusplus
19+
-_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
20+
#endif
21+
22+
#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import os
2+
from pythonforandroid.toolchain import shprint, current_directory
3+
from pythonforandroid.recipe import Recipe
4+
from multiprocessing import cpu_count
5+
import sh
6+
7+
8+
class LibZBarRecipe(Recipe):
9+
10+
version = '0.10'
11+
12+
url = 'https://github.com/ZBar/ZBar/archive/{version}.zip'
13+
14+
depends = ['hostpython2', 'python2', 'libiconv']
15+
16+
patches = ["werror.patch"]
17+
18+
def should_build(self, arch):
19+
return not os.path.exists(
20+
os.path.join(self.ctx.get_libs_dir(arch.arch), 'libzbar.so'))
21+
22+
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
23+
env = super(LibZBarRecipe, self).get_recipe_env(arch, with_flags_in_cc)
24+
libiconv = self.get_recipe('libiconv', self.ctx)
25+
libiconv_dir = libiconv.get_build_dir(arch.arch)
26+
env['CFLAGS'] += ' -I' + os.path.join(libiconv_dir, 'include')
27+
env['LDSHARED'] = env['CC'] + \
28+
' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
29+
env['LDFLAGS'] += " -landroid -liconv"
30+
return env
31+
32+
def build_arch(self, arch):
33+
super(LibZBarRecipe, self).build_arch(arch)
34+
env = self.get_recipe_env(arch)
35+
with current_directory(self.get_build_dir(arch.arch)):
36+
shprint(sh.Command('autoreconf'), '-vif', _env=env)
37+
shprint(
38+
sh.Command('./configure'),
39+
'--host=' + arch.toolchain_prefix,
40+
'--target=' + arch.toolchain_prefix,
41+
'--prefix=' + self.ctx.get_python_install_dir(),
42+
# Python bindings are compiled in a separated recipe
43+
'--with-python=no',
44+
'--with-gtk=no',
45+
'--with-qt=no',
46+
'--with-x=no',
47+
'--with-jpeg=no',
48+
'--with-imagemagick=no',
49+
'--enable-pthread=no',
50+
'--enable-video=no',
51+
'--enable-shared=yes',
52+
'--enable-static=no',
53+
_env=env)
54+
shprint(sh.make, '-j' + str(cpu_count()), _env=env)
55+
libs = ['zbar/.libs/libzbar.so']
56+
self.install_libs(arch, *libs)
57+
58+
59+
recipe = LibZBarRecipe()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/configure.ac b/configure.ac
2+
index 256aedb..727caba 100644
3+
--- a/configure.ac
4+
+++ b/configure.ac
5+
@@ -3,7 +3,7 @@ AC_PREREQ([2.61])
6+
AC_INIT([zbar], [0.10], [spadix@users.sourceforge.net])
7+
AC_CONFIG_AUX_DIR(config)
8+
AC_CONFIG_MACRO_DIR(config)
9+
-AM_INIT_AUTOMAKE([1.10 -Wall -Werror foreign subdir-objects std-options dist-bzip2])
10+
+AM_INIT_AUTOMAKE([1.10 -Wall foreign subdir-objects std-options dist-bzip2])
11+
AC_CONFIG_HEADERS([include/config.h])
12+
AC_CONFIG_SRCDIR(zbar/scanner.c)
13+
LT_PREREQ([2.2])
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
from pythonforandroid.recipe import PythonRecipe
3+
4+
5+
class ZBarRecipe(PythonRecipe):
6+
7+
version = '0.10'
8+
9+
# For some reason the version 0.10 on PyPI is not the same as the ones
10+
# in sourceforge and GitHub. The one in PyPI has a setup.py.
11+
# url = 'https://github.com/ZBar/ZBar/archive/{version}.zip'
12+
url = 'https://pypi.python.org/packages/e0/5c/' + \
13+
'bd2a96a9f2adacffceb4482cdd56831735ab5a67ea6a60c0a8757c17b62e' + \
14+
'/zbar-{version}.tar.gz'
15+
16+
call_hostpython_via_targetpython = False
17+
18+
depends = ['hostpython2', 'python2', 'setuptools', 'libzbar']
19+
20+
patches = ["zbar-0.10-python-crash.patch"]
21+
22+
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
23+
env = super(ZBarRecipe, self).get_recipe_env(arch, with_flags_in_cc)
24+
libzbar = self.get_recipe('libzbar', self.ctx)
25+
libzbar_dir = libzbar.get_build_dir(arch.arch)
26+
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
27+
env['CFLAGS'] += ' -I' + os.path.join(libzbar_dir, 'include')
28+
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
29+
# TODO
30+
env['LDSHARED'] = env['CC'] + \
31+
' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
32+
# TODO: hardcoded Python version
33+
env['LDFLAGS'] += " -landroid -lpython2.7 -lzbar"
34+
return env
35+
36+
37+
recipe = ZBarRecipe()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
https://sourceforge.net/p/zbar/patches/37/
2+
3+
fix from Debian for crashes when importing the python module.
4+
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=702499
5+
6+
this doesn't happen on some arches as the data naturally ends up with zero
7+
data after the structure, but on some (like arm), it isn't so we crash when
8+
python walks the list.
9+
10+
--- a/imagescanner.c
11+
+++ b/imagescanner.c
12+
@@ -68,6 +68,7 @@ imagescanner_get_results (zbarImageScanner *self,
13+
14+
static PyGetSetDef imagescanner_getset[] = {
15+
{ "results", (getter)imagescanner_get_results, },
16+
+ { NULL },
17+
};
18+
19+
static PyObject*

0 commit comments

Comments
 (0)