|
| 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() |
0 commit comments