# 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 simple_build(configure_args=(), make_args=(), install_args=(), library_path=None, override_prefix=None, no_parallel=False, configure_name='./configure'):
#     if isinstance(configure_args, type('')):
#         configure_args = split(configure_args)
#     if isinstance(make_args, type('')):
#         make_args = split(make_args)
#     if isinstance(install_args, type('')):
#         install_args = split(install_args)
#     run(configure_name, '--prefix=' + (override_prefix or build_dir()), *configure_args)
#     make_opts = [] if no_parallel else split(MAKEOPTS)
#     run('make', *(make_opts + list(make_args)))
#     mi = ['make'] + list(install_args) + ['install']
#     run(*mi, library_path=library_path)
# 
# class ModifiedEnv(object):
# 
#     def __init__(self, **kwargs):
#         self.mods = kwargs
# 
#     def apply(self, mods):
#         for k, val in mods.iteritems():
#             if val:
#                 worker_env[k] = val
#             else:
#                 worker_env.pop(k, None)
# 
#     def __enter__(self):
#         self.orig = {k: worker_env.get(k) for k in self.mods}
#         self.apply(self.mods)
# 
#     def __exit__(self, *args):
#         self.apply(self.orig)


from .constants import PREFIX, LDFLAGS, CFLAGS, LIBDIR, islinux
from .utils import simple_build, ModifiedEnv
#!/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)



def main(args):
    with ModifiedEnv(
            LIBUSB_CFLAGS="-I%s/include/libusb-1.0" % PREFIX,
            LIBUSB_LIBS='-lusb-1.0',
            CFLAGS=CFLAGS + ' -DHAVE_ICONV',
            LDFLAGS=LDFLAGS + ' -liconv',
            LD_LIBRARY_PATH=LIBDIR,
    ):
        conf = '--disable-mtpz --disable-dependency-tracking --disable-static --with-libiconv-prefix={0}'.format(PREFIX)
        if islinux:

# 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 simple_build(configure_args=(), make_args=(), install_args=(), library_path=None, override_prefix=None, no_parallel=False, configure_name='./configure'):
#     if isinstance(configure_args, type('')):
#         configure_args = split(configure_args)
#     if isinstance(make_args, type('')):
#         make_args = split(make_args)
#     if isinstance(install_args, type('')):
#         install_args = split(install_args)
#     run(configure_name, '--prefix=' + (override_prefix or build_dir()), *configure_args)
#     make_opts = [] if no_parallel else split(MAKEOPTS)
#     run('make', *(make_opts + list(make_args)))
#     mi = ['make'] + list(install_args) + ['install']
#     run(*mi, library_path=library_path)
# 
# class ModifiedEnv(object):
# 
#     def __init__(self, **kwargs):
#         self.mods = kwargs
# 
#     def apply(self, mods):
#         for k, val in mods.iteritems():
#             if val:
#                 worker_env[k] = val
#             else:
#                 worker_env.pop(k, None)
# 
#     def __enter__(self):
#         self.orig = {k: worker_env.get(k) for k in self.mods}
#         self.apply(self.mods)
# 
#     def __exit__(self, *args):
#         self.apply(self.orig)


# Path: scripts/pkgs/libmtp.py
from .constants import PREFIX, LDFLAGS, CFLAGS, LIBDIR, islinux
from .utils import simple_build, ModifiedEnv

#!/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)



def main(args):
    with ModifiedEnv(
            LIBUSB_CFLAGS="-I%s/include/libusb-1.0" % PREFIX,
            LIBUSB_LIBS='-lusb-1.0',
            CFLAGS=CFLAGS + ' -DHAVE_ICONV',
            LDFLAGS=LDFLAGS + ' -liconv',
            LD_LIBRARY_PATH=LIBDIR,
    ):
        conf = '--disable-mtpz --disable-dependency-tracking --disable-static --with-libiconv-prefix={0}'.format(PREFIX)
        if islinux:

            conf += ' --with-udev={0}/udev'.format(PREFIX)