[SUPPORTIVE PATCH 0.27.200] build and use zlib-1.2.8 on older systems

Tomi Ollila tomi.ollila at iki.fi
Sat Sep 8 07:17:48 PDT 2018


¡¡ NOT TO BE MERGED TO NOTMUCH REPOSITORY !!

This is an update to id:1397809386-23356-1-git-send-email-tomi.ollila at iki.fi

sent almost 4 1/2 years ago. That version has not applied in ~2 years now...

I've been rebasing this version on top of current master with
git pull --rebase --autostash since the previous version broke.
Although my current notmuch build environment has had new enough zlib for
most of that time, i've kept this change along just that if anyone asks...
After sending this I can drop this from my active tree.

This version is a bit more robust for ./configre changes, but we'll see how
long that last (or if anyone ever cares) :D

--8<----8<----8<--

Recent notmuch requires zlib 1.2.5.2 or newer; systems that have older
versions of zlib installed can use this change to use zlib 1.2.8 with
notmuch, but keep the current one to be used by default.
---
 compat/build-zlib-1.2.8.py | 99 ++++++++++++++++++++++++++++++++++++++++++++++
 configure                  | 16 ++++++++
 2 files changed, 115 insertions(+)
 create mode 100755 compat/build-zlib-1.2.8.py

diff --git a/compat/build-zlib-1.2.8.py b/compat/build-zlib-1.2.8.py
new file mode 100755
index 000000000000..1e089ba1e469
--- /dev/null
+++ b/compat/build-zlib-1.2.8.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# $ build-zlib.py $
+#
+# Author: Tomi Ollila,
+# SPDX-License-Identifier: Unlicense
+#
+# Created: Sat 12 Apr 2014 17:51:42 EEST too
+# Last modified: Sun 19 Mar 2017 18:44:27 +0200 too
+
+# Not using string.format() for python 2.5 compatibility.
+# Not using print due to python version 2 & 3 differences.
+
+import sys
+import os
+try:  # Python 3
+    from urllib.request import urlopen
+except ImportError:  # Python 2
+    from urllib import urlopen
+import shutil
+import hashlib
+
+ZLIBurl='http://prdownloads.sourceforge.net/libpng/zlib-1.2.8.tar.gz?download'
+ZLIBtgz='zlib-1.2.8.tar.gz'
+ZLIBsum='36658cb768a54c1d4dec43c3116c27ed893e88b02ecfcb44f2166f9c0b7f2a0d'
+ZLIBdir='zlib-1.2.8'
+
+
+class Die(Exception):
+    def __init__(self, *_list):
+        sys.stderr.write("\n")
+        sys.stderr.write(_list[0] % _list[1:])
+        sys.stderr.write("\n\n")
+        raise SystemExit(1)
+    pass
+
+
+def dl_zlibtgz():
+    sys.stdout.write("Downloading %s...\n" % ZLIBtgz)
+    response = urlopen(ZLIBurl)
+    # python3 throws urllib.error.HTTPError, python2 does not.
+    if response.getcode() != 200:
+        sys.stderr.write(response.read(4096))  # max 4096 octets
+        exit(1)
+    outfile = open(ZLIBtgz, 'wb')
+    shutil.copyfileobj(response, outfile)
+    pass
+
+
+def main():
+    dn0 = os.path.dirname(sys.argv[0])
+    if dn0 != '.':
+        os.chdir(dn0)
+        pass
+    del dn0
+    if not os.path.isfile(ZLIBtgz):
+        dl_zlibtgz()
+        pass
+
+    sys.stdout.write("Checksumming %s...\n" % ZLIBtgz)
+    infile = open(ZLIBtgz, 'rb')
+    sha256 = hashlib.sha256()
+    while True:
+        data = infile.read(65536)
+        if not data:
+            break
+        sha256.update(data)
+        pass
+    sys.stdout.write(" Expt'd sha256 %s\n" % ZLIBsum)
+    hexdigest = sha256.hexdigest()
+    sys.stdout.write(" Actual sha256 %s\n" % hexdigest)
+    if hexdigest != ZLIBsum:
+        raise Die("File '%s' checksum mismatch", ZLIBtgz)
+    pass
+
+    target = ZLIBdir + '/libz.a'
+    if os.path.isfile(target):
+        sys.stdout.write("'%s' exists. OK.\n" % target)
+        raise SystemExit(0)
+
+    def x(*args):
+        sys.stdout.write('x ' + ' '.join(args) + '\n')
+        os.spawnvp(os.P_WAIT, args[0], args)
+        pass
+
+    sys.stdout.write('Building %s\n' % ZLIBdir)
+    x ('rm', '-rf', ZLIBdir)
+    x ('tar', '-zxf', ZLIBtgz)
+    os.chdir(ZLIBdir)
+    cwd = os.getcwd()
+    x ('./configure', '--static', '--includedir', cwd)
+    x ('make')
+    os.chdir('..')
+    if not os.path.isfile(target):
+        raise Die("Could not build '%s' for some reason!", target)
+
+if __name__ == '__main__':
+    main()
+    pass  # pylint: disable=W0107
diff --git a/configure b/configure
index ab7e1610a0c5..6a9f0e00486e 100755
--- a/configure
+++ b/configure
@@ -51,6 +51,22 @@ if [ "$srcdir" != "." ]; then
     cp -a "$srcdir"/bindings/ruby/extconf.rb bindings/ruby
 fi
 
+# XXX unofficial supportive patch to use self-built zlib XXX
+"$srcdir"/compat/build-zlib-1.2.8.py || exit 1
+LDFLAGS=$NOTMUCH_SRCDIR/compat/zlib-1.2.8/libz.a${LDFLAGS:+ $LDFLAGS}
+printf > compat/zlib-1.2.8/zlib.pc '%s\n' \
+   "prefix=$NOTMUCH_SRCDIR/compat/zlib-1.2.8" \
+   'includedir=${prefix}' \
+   ''\
+   'Name: zlib' \
+   'Description: zlib compression library' \
+   'Version: 1.2.8' \
+   ''\
+   'Requires:' \
+   'Cflags: -I${includedir}'
+PKG_CONFIG_PATH=$PWD/compat/zlib-1.2.8${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
+# XXX end XXX
+
 # Set several defaults (optionally specified by the user in
 # environment variables)
 CC=${CC:-cc}
-- 
2.13.3



More information about the notmuch mailing list