# Path: scripts/pkgs/constants.py
# def build_dir():
#     return _build_dir
# 
# PREFIX = os.path.join(SW, 'sw')
# 
# MAKEOPTS = '-j%d' % cpu_count()
# 
# 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 replace_in_file(path, old, new, missing_ok=False):
#     if isinstance(old, type('')):
#         old = old.encode('utf-8')
#     if isinstance(new, type('')):
#         new = new.encode('utf-8')
#     with open(path, 'r+b') as f:
#         raw = f.read()
#         if isinstance(old, bytes):
#             nraw = raw.replace(old, new)
#         else:
#             nraw = old.sub(new, raw)
#         if raw == nraw and not missing_ok:
#             raise ValueError('Failed (pattern not found) to patch: ' + path)
#         f.seek(0), f.truncate()
#         f.write(nraw)
# 
# 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)


import os
import re
import shutil
from .constants import build_dir, PREFIX, MAKEOPTS
from .utils import run, replace_in_file, 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)



def main(args):
    # dbus chooses where to look for config files based on values fed to
    # ./configure, so we cannot configure to install it to prefix
    run('./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-dependency-tracking --disable-static'
        ' --disable-doxygen-docs --disable-xml-docs --disable-systemd --without-systemdsystemunitdir'
        ' --with-console-auth-dir=/run/console/ --disable-tests')

# Path: scripts/pkgs/constants.py
# def build_dir():
#     return _build_dir
# 
# PREFIX = os.path.join(SW, 'sw')
# 
# MAKEOPTS = '-j%d' % cpu_count()
# 
# 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 replace_in_file(path, old, new, missing_ok=False):
#     if isinstance(old, type('')):
#         old = old.encode('utf-8')
#     if isinstance(new, type('')):
#         new = new.encode('utf-8')
#     with open(path, 'r+b') as f:
#         raw = f.read()
#         if isinstance(old, bytes):
#             nraw = raw.replace(old, new)
#         else:
#             nraw = old.sub(new, raw)
#         if raw == nraw and not missing_ok:
#             raise ValueError('Failed (pattern not found) to patch: ' + path)
#         f.seek(0), f.truncate()
#         f.write(nraw)
# 
# 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/dbus.py
import os
import re
import shutil
from .constants import build_dir, PREFIX, MAKEOPTS
from .utils import run, replace_in_file, 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)



def main(args):
    # dbus chooses where to look for config files based on values fed to
    # ./configure, so we cannot configure to install it to prefix
    run('./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-dependency-tracking --disable-static'
        ' --disable-doxygen-docs --disable-xml-docs --disable-systemd --without-systemdsystemunitdir'
        ' --with-console-auth-dir=/run/console/ --disable-tests')

    run('make ' + MAKEOPTS)