| 1 | #!/bin/bash |
| 2 | |
| 3 | # This script can be used on Linux hosts to build native libzbar binaries. |
| 4 | # sudo apt-get install pkg-config libx11-dev libx11-6 libv4l-dev libxv-dev libxext-dev libjpeg-dev |
| 5 | # |
| 6 | # It can also be used to cross-compile to Windows: |
| 7 | # $ sudo apt-get install mingw-w64 mingw-w64-tools win-iconv-mingw-w64-dev |
| 8 | # For a Windows x86 (32-bit) target, run: |
| 9 | # $ GCC_TRIPLET_HOST="i686-w64-mingw32" BUILD_TYPE="wine" ./contrib/make_zbar.sh |
| 10 | # Or for a Windows x86_64 (64-bit) target, run: |
| 11 | # $ GCC_TRIPLET_HOST="x86_64-w64-mingw32" BUILD_TYPE="wine" ./contrib/make_zbar.sh |
| 12 | |
| 13 | ZBAR_VERSION="bb05ec54eec57f8397cb13fb9161372a281a1219" |
| 14 | # ^ tag 0.23.93 |
| 15 | |
| 16 | set -e |
| 17 | |
| 18 | . "$(dirname "$0")/build_tools_util.sh" || (echo "Could not source build_tools_util.sh" && exit 1) |
| 19 | |
| 20 | here="$(dirname "$(realpath "$0" 2> /dev/null || grealpath "$0")")" |
| 21 | CONTRIB="$here" |
| 22 | PROJECT_ROOT="$CONTRIB/.." |
| 23 | |
| 24 | pkgname="zbar" |
| 25 | info "Building $pkgname..." |
| 26 | |
| 27 | ( |
| 28 | cd "$CONTRIB" |
| 29 | if [ ! -d zbar ]; then |
| 30 | git clone https://github.com/mchehab/zbar.git |
| 31 | fi |
| 32 | cd zbar |
| 33 | if ! $(git cat-file -e ${ZBAR_VERSION}) ; then |
| 34 | info "Could not find requested version $ZBAR_VERSION in local clone; fetching..." |
| 35 | git fetch --all |
| 36 | fi |
| 37 | git reset --hard |
| 38 | git clean -dfxq |
| 39 | git checkout "${ZBAR_VERSION}^{commit}" |
| 40 | |
| 41 | if [ "$BUILD_TYPE" = "wine" ] ; then |
| 42 | echo "libzbar_la_LDFLAGS += -Wc,-static" >> zbar/Makefile.am |
| 43 | echo "LDFLAGS += -Wc,-static" >> Makefile.am |
| 44 | fi |
| 45 | if ! [ -x configure ] ; then |
| 46 | autoreconf -vfi || fail "Could not run autoreconf for $pkgname. Please make sure you have automake and libtool installed, and try again." |
| 47 | fi |
| 48 | if ! [ -r config.status ] ; then |
| 49 | if [ "$BUILD_TYPE" = "wine" ] ; then |
| 50 | # windows target |
| 51 | AUTOCONF_FLAGS="$AUTOCONF_FLAGS \ |
| 52 | --with-x=no \ |
| 53 | --enable-video=yes \ |
| 54 | --with-jpeg=no \ |
| 55 | --with-directshow=yes \ |
| 56 | --disable-dependency-tracking" |
| 57 | elif [ $(uname) == "Darwin" ]; then |
| 58 | # macos target |
| 59 | AUTOCONF_FLAGS="$AUTOCONF_FLAGS \ |
| 60 | --with-x=no \ |
| 61 | --enable-video=no \ |
| 62 | --with-jpeg=no" |
| 63 | else |
| 64 | # linux target |
| 65 | AUTOCONF_FLAGS="$AUTOCONF_FLAGS \ |
| 66 | --with-x=yes \ |
| 67 | --enable-video=yes \ |
| 68 | --with-jpeg=yes" |
| 69 | fi |
| 70 | ./configure \ |
| 71 | $AUTOCONF_FLAGS \ |
| 72 | --prefix="$here/$pkgname/dist" \ |
| 73 | --enable-pthread=no \ |
| 74 | --enable-doc=no \ |
| 75 | --with-python=no \ |
| 76 | --with-gtk=no \ |
| 77 | --with-qt=no \ |
| 78 | --with-java=no \ |
| 79 | --with-imagemagick=no \ |
| 80 | --with-dbus=no \ |
| 81 | --enable-codes=qrcode \ |
| 82 | --disable-static \ |
| 83 | --enable-shared || fail "Could not configure $pkgname. Please make sure you have a C compiler installed and try again." |
| 84 | fi |
| 85 | make "-j$CPU_COUNT" || fail "Could not build $pkgname" |
| 86 | make install || fail "Could not install $pkgname" |
| 87 | . "$here/$pkgname/dist/lib/libzbar.la" |
| 88 | host_strip "$here/$pkgname/dist/lib/$dlname" |
| 89 | cp -fpv "$here/$pkgname/dist/lib/$dlname" "$PROJECT_ROOT/electrum" || fail "Could not copy the $pkgname binary to its destination" |
| 90 | info "$dlname has been placed in the inner 'electrum' folder." |
| 91 | if [ -n "$DLL_TARGET_DIR" ] ; then |
| 92 | cp -fpv "$here/$pkgname/dist/lib/$dlname" "$DLL_TARGET_DIR/" || fail "Could not copy the $pkgname binary to DLL_TARGET_DIR" |
| 93 | fi |
| 94 | ) |