# Path: scripts/pkgs/constants.py
# def uniq(vals):
#     def cpu_count():
# def build_dir():
# def set_build_dir(x):
# def current_source():
# def set_current_source(x):
# def set_tdir(x):
# def mkdtemp(prefix=''):
# def putenv(**kw):
# ROOT = 'C:\\' if iswindows else '/'
# SW = ROOT + 'sw'
# SOURCES = ROOT + 'sources'
# PATCHES = ROOT + 'patches'
# SCRIPTS = ROOT + 'scripts'
# CALIBRE_DIR = ROOT + 'calibre'
# PREFIX = os.path.join(SW, 'sw')
# BIN = os.path.join(PREFIX, 'bin')
# PYTHON = os.path.join(PREFIX, 'private', 'python', 'python.exe') if iswindows else os.path.join(BIN, 'python')
#     CFLAGS = CPPFLAGS = LIBDIR = LDFLAGS = ''
#     CFLAGS = worker_env['CFLAGS'] = '-I' + os.path.join(PREFIX, 'include')
#     CPPFLAGS = worker_env['CPPFLAGS'] = '-I' + os.path.join(PREFIX, 'include')
#     LIBDIR = os.path.join(PREFIX, 'lib')
#     LDFLAGS = worker_env['LDFLAGS'] = '-L{0} -Wl,-rpath-link,{0}'.format(LIBDIR)
#     LDFLAGS = worker_env['LDFLAGS'] = '-headerpad_max_install_names -L{}'.format(LIBDIR)
# MAKEOPTS = '-j%d' % cpu_count()
# PKG_CONFIG_PATH = worker_env['PKG_CONFIG_PATH'] = os.path.join(PREFIX, 'lib', 'pkgconfig')
# CMAKE = os.path.join(PREFIX, 'bin', 'cmake') if isosx else 'cmake'
# QT_PREFIX = os.path.join(PREFIX, 'qt')
# QT_DLLS = ['Qt5' + x for x in (
#     'Core', 'Gui', 'Network', 'PrintSupport', 'Positioning', 'Sensors', 'Sql',
#     'Svg', 'WebKit', 'WebKitWidgets', 'Widgets', 'Multimedia', 'OpenGL',
#     'MultimediaWidgets', 'Xml',  # 'XmlPatterns',
# )]
# QT_PLUGINS = [
#     'imageformats', 'iconengines', 'mediaservice', 'platforms',
#     'playlistformats', 'sqldrivers',
#     # 'audio', 'printsupport', 'bearer', 'position',
# ]
# PYQT_MODULES = ('Qt', 'QtCore', 'QtGui', 'QtNetwork',  # 'QtMultimedia', 'QtMultimediaWidgets',
#                 'QtPrintSupport', 'QtSensors', 'QtSvg', 'QtWebKit', 'QtWebKitWidgets', 'QtWidgets')
# CODESIGN_KEYCHAIN = '/Users/kovid/codesign.keychain'
#     class SYSTEM_INFO(ctypes.Structure):
# 
# Path: scripts/pkgs/utils.py
# def run(*args, **kw):
#     if len(args) == 1 and isinstance(args[0], type('')):
#         cmd = split(args[0])
#     else:
#         cmd = args
#     print(' '.join(pipes.quote(x) for x in cmd))
#     sys.stdout.flush()
#     env = current_env(library_path=kw.get('library_path'))
#     try:
#         p = subprocess.Popen(cmd, env=env, cwd=kw.get('cwd'))
#     except EnvironmentError as err:
#         if err.errno == errno.ENOENT:
#             raise SystemExit('Could not find the program: %s' % cmd[0])
#         raise
#     rc = p.wait()
#     if kw.get('no_check'):
#         return rc
#     if rc != 0:
#         print('The following command failed, with return code:', rc)
#         print(' '.join(pipes.quote(x) for x in cmd))
#         print('Dropping you into a shell')
#         sys.stdout.flush()
#         run_shell(library_path=kw.get('library_path'))
#         raise SystemExit(1)
# 
# def install_binaries(pattern, destdir='lib', do_symlinks=False, fname_map=os.path.basename):
#     dest = os.path.join(build_dir(), destdir)
#     ensure_dir(dest)
#     files = glob.glob(pattern)
#     files.sort(key=len, reverse=True)
#     if not files:
#         raise ValueError('The pattern %s did not match any actual files' % pattern)
#     for f in files:
#         dst = os.path.join(dest, fname_map(f))
#         islink = lcopy(f, dst)
#         if not islink:
#             os.chmod(dst, 0o755)
#         if iswindows and os.path.exists(f + '.manifest'):
#             shutil.copy(f + '.manifest', dst + '.manifest')
#     if do_symlinks:
#         library_symlinks(files[0], destdir=destdir)
# 
# def copy_headers(pattern, destdir='include'):
#     dest = os.path.join(build_dir(), destdir)
#     ensure_dir(dest)
#     files = glob.glob(pattern)
#     for f in files:
#         dst = os.path.join(dest, os.path.basename(f))
#         if os.path.isdir(f):
#             shutil.copytree(f, dst)
#         else:
#             shutil.copy2(f, dst)


from .constants import iswindows
from .utils import run, install_binaries, copy_headers
#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>

from __future__ import (unicode_literals, division, absolute_import,
                        print_function)



if iswindows:
    def main(args):
        run('nmake -f win32/Makefile.msc')
        run('nmake -f win32/Makefile.msc test')
        install_binaries('zlib1.dll*', 'bin')
        install_binaries('zlib.lib'), install_binaries('zdll.*')

# Path: scripts/pkgs/constants.py
# def uniq(vals):
#     def cpu_count():
# def build_dir():
# def set_build_dir(x):
# def current_source():
# def set_current_source(x):
# def set_tdir(x):
# def mkdtemp(prefix=''):
# def putenv(**kw):
# ROOT = 'C:\\' if iswindows else '/'
# SW = ROOT + 'sw'
# SOURCES = ROOT + 'sources'
# PATCHES = ROOT + 'patches'
# SCRIPTS = ROOT + 'scripts'
# CALIBRE_DIR = ROOT + 'calibre'
# PREFIX = os.path.join(SW, 'sw')
# BIN = os.path.join(PREFIX, 'bin')
# PYTHON = os.path.join(PREFIX, 'private', 'python', 'python.exe') if iswindows else os.path.join(BIN, 'python')
#     CFLAGS = CPPFLAGS = LIBDIR = LDFLAGS = ''
#     CFLAGS = worker_env['CFLAGS'] = '-I' + os.path.join(PREFIX, 'include')
#     CPPFLAGS = worker_env['CPPFLAGS'] = '-I' + os.path.join(PREFIX, 'include')
#     LIBDIR = os.path.join(PREFIX, 'lib')
#     LDFLAGS = worker_env['LDFLAGS'] = '-L{0} -Wl,-rpath-link,{0}'.format(LIBDIR)
#     LDFLAGS = worker_env['LDFLAGS'] = '-headerpad_max_install_names -L{}'.format(LIBDIR)
# MAKEOPTS = '-j%d' % cpu_count()
# PKG_CONFIG_PATH = worker_env['PKG_CONFIG_PATH'] = os.path.join(PREFIX, 'lib', 'pkgconfig')
# CMAKE = os.path.join(PREFIX, 'bin', 'cmake') if isosx else 'cmake'
# QT_PREFIX = os.path.join(PREFIX, 'qt')
# QT_DLLS = ['Qt5' + x for x in (
#     'Core', 'Gui', 'Network', 'PrintSupport', 'Positioning', 'Sensors', 'Sql',
#     'Svg', 'WebKit', 'WebKitWidgets', 'Widgets', 'Multimedia', 'OpenGL',
#     'MultimediaWidgets', 'Xml',  # 'XmlPatterns',
# )]
# QT_PLUGINS = [
#     'imageformats', 'iconengines', 'mediaservice', 'platforms',
#     'playlistformats', 'sqldrivers',
#     # 'audio', 'printsupport', 'bearer', 'position',
# ]
# PYQT_MODULES = ('Qt', 'QtCore', 'QtGui', 'QtNetwork',  # 'QtMultimedia', 'QtMultimediaWidgets',
#                 'QtPrintSupport', 'QtSensors', 'QtSvg', 'QtWebKit', 'QtWebKitWidgets', 'QtWidgets')
# CODESIGN_KEYCHAIN = '/Users/kovid/codesign.keychain'
#     class SYSTEM_INFO(ctypes.Structure):
# 
# Path: scripts/pkgs/utils.py
# def run(*args, **kw):
#     if len(args) == 1 and isinstance(args[0], type('')):
#         cmd = split(args[0])
#     else:
#         cmd = args
#     print(' '.join(pipes.quote(x) for x in cmd))
#     sys.stdout.flush()
#     env = current_env(library_path=kw.get('library_path'))
#     try:
#         p = subprocess.Popen(cmd, env=env, cwd=kw.get('cwd'))
#     except EnvironmentError as err:
#         if err.errno == errno.ENOENT:
#             raise SystemExit('Could not find the program: %s' % cmd[0])
#         raise
#     rc = p.wait()
#     if kw.get('no_check'):
#         return rc
#     if rc != 0:
#         print('The following command failed, with return code:', rc)
#         print(' '.join(pipes.quote(x) for x in cmd))
#         print('Dropping you into a shell')
#         sys.stdout.flush()
#         run_shell(library_path=kw.get('library_path'))
#         raise SystemExit(1)
# 
# def install_binaries(pattern, destdir='lib', do_symlinks=False, fname_map=os.path.basename):
#     dest = os.path.join(build_dir(), destdir)
#     ensure_dir(dest)
#     files = glob.glob(pattern)
#     files.sort(key=len, reverse=True)
#     if not files:
#         raise ValueError('The pattern %s did not match any actual files' % pattern)
#     for f in files:
#         dst = os.path.join(dest, fname_map(f))
#         islink = lcopy(f, dst)
#         if not islink:
#             os.chmod(dst, 0o755)
#         if iswindows and os.path.exists(f + '.manifest'):
#             shutil.copy(f + '.manifest', dst + '.manifest')
#     if do_symlinks:
#         library_symlinks(files[0], destdir=destdir)
# 
# def copy_headers(pattern, destdir='include'):
#     dest = os.path.join(build_dir(), destdir)
#     ensure_dir(dest)
#     files = glob.glob(pattern)
#     for f in files:
#         dst = os.path.join(dest, os.path.basename(f))
#         if os.path.isdir(f):
#             shutil.copytree(f, dst)
#         else:
#             shutil.copy2(f, dst)


# Path: scripts/pkgs/zlib.py
from .constants import iswindows
from .utils import run, install_binaries, copy_headers

#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>

from __future__ import (unicode_literals, division, absolute_import,
                        print_function)



if iswindows:
    def main(args):
        run('nmake -f win32/Makefile.msc')
        run('nmake -f win32/Makefile.msc test')
        install_binaries('zlib1.dll*', 'bin')
        install_binaries('zlib.lib'), install_binaries('zdll.*')

        copy_headers('zconf.h'), copy_headers('zlib.h')