Exemple #1
0
def main(args):
    if iswindows:
        run(*('cscript.exe configure.js include={0}/include'
              ' include={0}/include/libxml2 lib={0}/lib prefix={0}'
              ' zlib=yes iconv=no'.format(PREFIX.replace(os.sep,
                                                         '/')).split()),
            cwd='win32')
        for f in walk('.'):
            bname = os.path.basename(f)
            if bname.startswith('Makefile'):
                replace_in_file(f, '/OPT:NOWIN98', '', missing_ok=True)
            elif bname == 'xsltconfig.h':
                replace_in_file(f, '@WITH_PROFILER@', '1')
        run(f'"{NMAKE}" /f Makefile.msvc', cwd='win32')
        install_tree('libxslt', 'include')
        install_tree('libexslt', 'include')
        for f in walk('.'):
            if f.endswith('.dll'):
                install_binaries(f, 'bin')
            elif f.endswith('.lib'):
                install_binaries(f)
    else:
        env = {}
        if ismacos:
            env['PATH'] = BIN + os.pathsep + os.environ['PATH']
        with ModifiedEnv(**env):
            simple_build('--disable-dependency-tracking --disable-static'
                         ' --enable-shared --without-python --without-debug')
Exemple #2
0
def main(args):
    if iswindows:
        windows_cmake_build()
        install_binaries('build/jpegtran-static.exe',
                         'bin',
                         fname_map=lambda x: 'jpegtran-calibre.exe')
        install_binaries('build/cjpeg-static.exe',
                         'bin',
                         fname_map=lambda x: 'cjpeg-calibre.exe')
    else:
        env = {}
        if ismacos:
            env['PATH'] = BIN + os.pathsep + os.environ['PATH']
            env['LIBTOOLIZE'] = 'glibtoolize'
            env['LIBTOOL'] = 'glibtool'
        with ModifiedEnv(**env):
            run('autoreconf -fiv')
        conf = ('--disable-dependency-tracking --disable-shared --with-jpeg8'
                ' --without-turbojpeg')
        env = {}
        if ismacos:
            conf += f' --host x86_64-apple-darwin NASM={BIN}/nasm'
            replace_in_file(
                'configure',
                re.compile(br'^PKG_CHECK_MODULES.libpng.+?\bfi\b',
                           re.M | re.DOTALL),
                'HAVE_LIBPNG=1\nHAVE_LIBPNG_TRUE="#"\n')
        simple_build(conf,
                     override_prefix=os.path.join(build_dir(), 'private',
                                                  'mozjpeg'))
Exemple #3
0
def main(args):
    if iswindows:
        with current_dir('msvc'):
            msbuild('Hunspell.sln', configuration='Release_dll')
            dll = lib = False
            for f in walk('.'):
                if os.path.basename(f) == 'libhunspell.dll':
                    install_binaries(f, 'bin')
                    dll = True
                elif os.path.basename(f) == 'libhunspell.lib':
                    install_binaries(f, 'lib')
                    lib = True
            if not dll or not lib:
                raise Exception('Failed to find the hunspell dlls')
        # from bypy.utils import run_shell
        # run_shell()
        copy_headers('src/hunspell/*.hxx', destdir='include/hunspell')
        copy_headers('src/hunspell/*.h', destdir='include/hunspell')
        copy_headers('msvc/*.h', destdir='include/hunspell')
    else:
        env = {}
        if ismacos:
            env['PATH'] = BIN + os.pathsep + os.environ['PATH']
            env['LIBTOOLIZE'] = 'glibtoolize'
            env['LIBTOOL'] = 'glibtool'
        with ModifiedEnv(**env):
            run('autoreconf -fiv')
        conf = '--disable-dependency-tracking'
        env = {}
        if ismacos:
            conf += ' --host x86_64-apple-darwin'
        simple_build(conf)
Exemple #4
0
def unix_python2(args):
    env = {'CFLAGS': CFLAGS + ' -DHAVE_LOAD_EXTENSION'}
    replace_in_file('setup.py', re.compile(b'def detect_tkinter.+:'),
                    lambda m: m.group() + b'\n' + b' ' * 8 + b'return 0')
    conf = ('--prefix={} --with-threads --enable-ipv6 --enable-unicode={}'
            ' --with-system-expat --with-pymalloc --without-ensurepip').format(
                build_dir(), ('ucs2' if ismacos or iswindows else 'ucs4'))
    if islinux:
        conf += ' --with-system-ffi --enable-shared'
        # Needed as the system openssl is too old, causing the _ssl module
        # to fail
        env['LD_LIBRARY_PATH'] = LIBDIR
    elif ismacos:
        conf += (f' --enable-framework={build_dir()}/python'
                 ' --with-signal-module')
        # Needed for readline detection
        env['MACOSX_DEPLOYMENT_TARGET'] = '10.9'

    with ModifiedEnv(**env):
        simple_build(conf, relocate_pkgconfig=False)

    bindir = os.path.join(build_dir(), 'bin')
    P = os.path.join(bindir, 'python')
    replace_in_file(P + '-config', re.compile(br'^#!.+/bin/', re.MULTILINE),
                    '#!' + PREFIX + '/bin/')
    if ismacos:
        bindir = os.path.join(build_dir(), 'bin')
        for f in os.listdir(bindir):
            link = os.path.join(bindir, f)
            if os.path.islink(link):
                fp = os.readlink(link)
                nfp = fp.replace(build_dir(), PREFIX)
                if nfp != fp:
                    os.unlink(link)
                    os.symlink(nfp, link)
Exemple #5
0
def main(args):
    replace_in_file('setup.py', 'self._want_assembly_kept = sys',
                    'self._want_assembly_kept = False and sys')
    # the exports in this file lead to linker errors with invalid export
    # specification
    replace_in_file('setup.py',
                    "export_symbol_file = 'com/win32com/src/PythonCOM.def',",
                    '')
    # get rid of some not needed modules and modules that dont build
    replace_in_file(
        'setup.py', 'def _why_cant_build_extension(self, ext):',
        '''def _why_cant_build_extension(self, ext):
        if ext.name in ('exchdapi', 'exchange', 'mapi', 'pythonservice',
                'win32ui', 'win32uiole', 'dde', 'Pythonwin'):
            return 'disabled by Kovid'
        ''')
    # dont copy the MFC Dlls since we have disabled the modules
    # that use them
    replace_in_file(
        'setup.py',
        re.compile(r'^\s+# The MFC DLLs.+?^\s+def ', re.DOTALL | re.MULTILINE),
        '    def ')
    # dont build scintilla (used by the disabled pythonwin)
    replace_in_file('setup.py', 'self._build_scintilla()', '')

    # CLSID_PropertyChangeArray is not useable
    replace_in_file('com/win32comext/propsys/src/propsys.cpp',
                    '#ifndef CLSID_PropertyChangeArray', '#if 0')
    replace_in_file(
        'com/win32comext/propsys/src/propsys.cpp',
        re.compile(r'PYCOM_INTERFACE_CLSID_ONLY\s*\(PropertyChangeArray\),'),
        '')
    # Undefined symbol
    replace_in_file(
        'win32/src/win32job.i',
        '#define JOB_OBJECT_RESERVED_LIMIT_VALID_FLAGS JOB_OBJECT_RESERVED_LIMIT_VALID_FLAGS',  # noqa
        '')
    # fix win32com trying to write to paths inside the installation folder
    replace_in_file(
        'com/win32com/__init__.py', "__gen_path__ = ''",
        'import tempfile; __gen_path__ = os.path.join(tempfile.gettempdir(), "gen_py", "%d.%d" % (sys.version_info[0], sys.version_info[1]))'
    )  # noqa
    replace_in_file('com/win32com/client/gencache.py', 'except IOError:',
                    'except Exception:')
    p = windows_sdk_paths()
    with ModifiedEnv(MSSDK_INCLUDE=p['include'], MSSDK_LIB=p['lib']):
        run(PYTHON, 'setup.py', 'build',
            '--plat-name=' + ('win-amd64' if is64bit else 'win32'))
        run(PYTHON, 'setup.py', '-q', 'install', '--root', build_dir())
    base = os.path.relpath(PREFIX, '/')
    q = os.listdir(build_dir())[0]
    os.rename(os.path.join(build_dir(), base, 'private'),
              os.path.join(build_dir(), 'private'))
    rmtree(os.path.join(build_dir(), q))
    rmtree(
        os.path.join(build_dir(),
                     'private/python/Lib/site-packages/pythonwin'))
Exemple #6
0
def main(args):
    with ModifiedEnv(LD_LIBRARY_PATH=LIBDIR,
                     PATH=f'{PREFIX}/bin:' + os.environ['PATH']):
        os.makedirs(os.path.join(f'{PREFIX}/lib/dbus-1.0/include'),
                    exist_ok=True)
        meson_build(force_posix_threads='true',
                    gtk_doc='false',
                    man='false',
                    selinux='disabled',
                    iconv='external')
Exemple #7
0
def main(args):
    env = {}
    p = PREFIX.replace(os.sep, '/')
    env = dict(
        UNRAR_INCLUDE='{}/include'.format(p),
        UNRAR_LIBDIRS='{0}/lib'.format(p),
    )
    with ModifiedEnv(**env):
        python_build()
    python_install()
Exemple #8
0
def main(args):
    cflags = CFLAGS
    env = {}
    if ismacos:
        if len(UNIVERSAL_ARCHES) > 1:
            env['CC'] = 'clang ' + ' '.join(f'-arch {x}'
                                            for x in UNIVERSAL_ARCHES)
            env['CPP'] = 'clang -E'
    env['CFLAGS'] = cflags
    with ModifiedEnv(**env):
        simple_build('--disable-dependency-tracking')
Exemple #9
0
def main(args):
    with ModifiedEnv(PATH=BIN + os.pathsep + os.environ['PATH']):
        simple_build()
    files = set()
    for path in walk(os.path.join(build_dir(), 'bin')):
        files.add(os.path.abspath(os.path.realpath(path)))
    for path in walk(build_dir()):
        if path.endswith('/Config.pm'):
            files.add(os.path.abspath(os.path.realpath(path)))
    for path in files:
        replace_in_file(path, build_dir(), PREFIX, missing_ok=True)
Exemple #10
0
def main(args):
    env = {}
    p = PREFIX.replace(os.sep, '/')
    env = dict(
        LIBXML_INCLUDE_DIRS='{0}/include{1}{0}/include/libxml2'.format(p, os.pathsep),
        LIBXML_LIB_DIRS='{0}/lib'.format(p),
        LIBXML_LIBS='libxml2' if iswindows else 'xml2',
    )
    with ModifiedEnv(**env):
        python_build()
    python_install()
Exemple #11
0
def main(args):
    if iswindows:
        # On windows we dont actually build sqlite as the python build script
        # downloads its own version locked sqlite. We just install the headers
        copy_headers('sqlite3*.h')
        return
    cflags = CFLAGS
    if ismacos:
        cflags += ' -O2 -DSQLITE_ENABLE_LOCKING_STYLE'
    with ModifiedEnv(CFLAGS=cflags):
        simple_build('--disable-dependency-tracking --disable-static')
Exemple #12
0
def main(args):
    with ModifiedEnv(FREETYPE_CFLAGS='-I%s/include/freetype2' % PREFIX,
                     FREETYPE_LIBS='-L%s/lib -lfreetype -lz -lbz2' % PREFIX):
        simple_build(
            '--disable-dependency-tracking --disable-static --disable-docs'
            f' --with-expat={PREFIX} --with-add-fonts=/usr/share/fonts',
            library_path=True)
    for f in walk(os.path.join(build_dir(), 'etc')):
        if os.path.islink(f):
            x = os.path.realpath(f)
            os.unlink(f)
            shutil.copy2(x, f)
Exemple #13
0
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)
        simple_build(conf)
Exemple #14
0
def main(args):
    env = {}
    p = PREFIX.replace(os.sep, '/')
    env = dict(
        UNRAR_INCLUDE='{}/include'.format(p),
        UNRAR_LIBDIRS='{0}/lib'.format(p),
    )
    if iswindows:
        replace_in_file('src/unrardll/wrapper.cpp', ' ssize_t written',
                        ' Py_ssize_t written')
    with ModifiedEnv(**env):
        python_build()
    python_install()
Exemple #15
0
def main(args):
    # make install tries to write to $HOME/.terminfo
    with ModifiedEnv(HOME=build_dir()):
        simple_build(
            '--with-shared --without-debug --without-ada --enable-widec'
            ' --with-normal --enable-pc-files'
            f' --with-pkg-config-libdir={PKG_CONFIG_PATH}'
            # without the following ncurses will look in the BUILD_DIR
            # for terminfo files even on target systems. Instead use
            # a bunch of common locations.
            ' --with-terminfo-dirs=/usr/share/terminfo:/etc/terminfo:'
            '/lib/terminfo:/usr/lib/terminfo'
            ' --with-default-terminfo-dir=/usr/share/terminfo', )
Exemple #16
0
def main(args):
    # the makefile stupidly uses a comma as a separator for sed which breaks when there
    # are multiple entries being substituted
    replace_in_file('Makefile.am', re.compile(rb"'s,.+?'"),
                    lambda m: m.group().replace(b',', b'`'))
    replace_in_file('Makefile.in', re.compile(rb"'s,.+?'"),
                    lambda m: m.group().replace(b',', b'`'))
    with ModifiedEnv(FREETYPE_CFLAGS='-I%s/include/freetype2' % PREFIX,
                     FREETYPE_LIBS='-L%s/lib -lfreetype -lz -lbz2' % PREFIX):
        simple_build(
            '--disable-dependency-tracking --disable-static --disable-docs'
            f' --with-expat={PREFIX} --with-add-fonts=/usr/share/fonts',
            library_path=True)
    for f in walk(os.path.join(build_dir(), 'etc')):
        if os.path.islink(f):
            x = os.path.realpath(f)
            os.unlink(f)
            shutil.copy2(x, f)
Exemple #17
0
def unix_python(args):
    env = {
        'CFLAGS':
        CFLAGS + f' -DHAVE_LOAD_EXTENSION -I{PREFIX}/include/ncursesw'
    }
    replace_in_file('setup.py', re.compile(b'def detect_tkinter.+:'),
                    lambda m: m.group() + b'\n' + b' ' * 8 + b'return 0')
    conf = ('--enable-ipv6 --with-system-expat --with-pymalloc'
            ' --with-lto --enable-optimizations'
            ' --enable-loadable-sqlite-extensions'
            ' --without-ensurepip --with-c-locale-coercion')
    install_args = ()
    if islinux:
        conf += f' --with-system-ffi --enable-shared --prefix={build_dir()}'
        # Needed as the system openssl is too old, causing the _ssl module
        # to fail
        env['LD_LIBRARY_PATH'] = LIBDIR
    elif ismacos:
        conf += f' --enable-framework={build_dir()}/python'
        conf += f' --with-openssl={PREFIX}'
        if len(UNIVERSAL_ARCHES) > 1:
            conf += ' --enable-universalsdk --with-universal-archs=universal2'
            # Without ARCHFLAGS the extensions are built for only one arch
            env['ARCHFLAGS'] = ' '.join(f'-arch {x}' for x in UNIVERSAL_ARCHES)
        # Needed for readline detection
        env['MACOSX_DEPLOYMENT_TARGET'] = '10.14'
        env['LDFLAGS'] = LDFLAGS.replace('-headerpad_max_install_names', '')
        # dont install IDLE and PythonLauncher
        replace_in_file(
            'Mac/Makefile.in',
            'installapps: install_Python install_PythonLauncher install_IDLE',
            'installapps: install_Python')
        # needed to build universal 3rd party python extensions. See
        # _supports_arm64_builds() in _osx_support.py
        replace_in_file('Lib/_osx_support.py', 'osx_version >= (11, 0)',
                        'osx_version >= (10, 15)')
        install_args = (f'PYTHONAPPSDIR={build_dir()}', )

    with ModifiedEnv(**env):
        simple_build(conf, relocate_pkgconfig=False, install_args=install_args)

    bindir = os.path.join(build_dir(), 'bin')

    def replace_bdir(f, raw=None):
        if raw is None:
            raw = f.read()
        f.seek(0), f.truncate()
        f.write(
            raw.replace(f'{build_dir()}'.encode('utf-8'),
                        PREFIX.encode('utf-8')))

    if ismacos:
        for f in os.listdir(bindir):
            link = os.path.join(bindir, f)
            with open(link, 'r+b') as f:
                raw = f.read()
                if raw.startswith(b'#!/'):
                    replace_bdir(f, raw)
            if os.path.islink(link):
                fp = os.readlink(link)
                nfp = fp.replace(build_dir(), PREFIX)
                if nfp != fp:
                    os.unlink(link)
                    os.symlink(nfp, link)
        libdir = glob.glob(f'{build_dir()}/python/Python.framework/'
                           'Versions/Current/lib/python*')[0]
        for x in ('config-*-darwin/python-config.py',
                  '_sysconfigdata__darwin_darwin.py'):
            with open(glob.glob(f'{libdir}/{x}')[0], 'r+b') as f:
                replace_bdir(f)
    else:
        replace_in_file(os.path.join(bindir, 'python3-config'),
                        re.compile(br'^prefix=".+?"', re.MULTILINE),
                        f'prefix="{PREFIX}"')
        libdir = os.path.join(build_dir(), 'lib')
        for x in (
                'python*/config-*-linux-gnu/python-config.py',
                'python*/_sysconfigdata__linux_*-linux-gnu.py',
        ):
            with open(glob.glob(f'{libdir}/{x}')[0], 'r+b') as f:
                replace_bdir(f)
    os.symlink('python3', os.path.join(bindir, 'python'))
Exemple #18
0
def unix_python(args):
    env = {
        'CFLAGS': CFLAGS +
        f' -DHAVE_LOAD_EXTENSION -I{PREFIX}/include/ncursesw'
    }
    replace_in_file('setup.py', re.compile(b'def detect_tkinter.+:'),
                    lambda m: m.group() + b'\n' + b' ' * 8 + b'return 0')
    conf = ('--enable-ipv6 --with-system-expat --with-pymalloc'
            ' --with-lto --enable-optimizations'
            ' --without-ensurepip --with-c-locale-coercion')
    install_args = ()
    if islinux:
        conf += f' --with-system-ffi --enable-shared --prefix={build_dir()}'
        # Needed as the system openssl is too old, causing the _ssl module
        # to fail
        env['LD_LIBRARY_PATH'] = LIBDIR
    elif ismacos:
        conf += f' --enable-framework={build_dir()}/python'
        conf += f' --with-openssl={PREFIX}'
        # Needed for readline detection
        env['MACOSX_DEPLOYMENT_TARGET'] = '10.14'
        env['LDFLAGS'] = LDFLAGS.replace('-headerpad_max_install_names', '')
        cwd = os.getcwd()
        replace_in_file(
            'configure',
            "PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'",
            f"PYTHON_FOR_BUILD='PYTHONEXECUTABLE={cwd}/$(BUILDPYTHON) PYTHONPATH={cwd}/Lib ./$(BUILDPYTHON)'"  # noqa
        )
        # dont install IDLE and PythonLauncher
        replace_in_file(
            'Mac/Makefile.in',
            'installapps: install_Python install_PythonLauncher install_IDLE',
            'installapps: install_Python'
        )
        install_args = (f'PYTHONAPPSDIR={build_dir()}',)

    with ModifiedEnv(**env):
        simple_build(conf, relocate_pkgconfig=False, install_args=install_args)

    bindir = os.path.join(build_dir(), 'bin')

    def replace_bdir(f, raw=None):
        if raw is None:
            raw = f.read()
        f.seek(0), f.truncate()
        f.write(raw.replace(
            f'{build_dir()}'.encode('utf-8'), PREFIX.encode('utf-8')))

    if ismacos:
        for f in os.listdir(bindir):
            link = os.path.join(bindir, f)
            with open(link, 'r+b') as f:
                raw = f.read()
                if raw.startswith(b'#!/'):
                    replace_bdir(f, raw)
            if os.path.islink(link):
                fp = os.readlink(link)
                nfp = fp.replace(build_dir(), PREFIX)
                if nfp != fp:
                    os.unlink(link)
                    os.symlink(nfp, link)
        libdir = glob.glob(
            f'{build_dir()}/python/Python.framework/'
            'Versions/Current/lib/python*')[0]
        for x in (
            'config-*-darwin/python-config.py',
            '_sysconfigdata__darwin_darwin.py'
        ):
            with open(glob.glob(f'{libdir}/{x}')[0], 'r+b') as f:
                replace_bdir(f)
    else:
        replace_in_file(os.path.join(bindir, 'python3-config'),
                        re.compile(br'^prefix=".+?"', re.MULTILINE),
                        f'prefix="{PREFIX}"')
    os.symlink('python3', os.path.join(bindir, 'python'))