예제 #1
0
def main(dependencies, msvcr71_preparation, msys_preparation):
    """Build the dependencies according to the command line options."""

    options, args = command_line()
    if options.arg_help:
        print_("These are the Pygame library dependencies:")
        for dep in dependencies:
            print_(" ", dep.name)
        return 0
    try:
        chosen_deps = choose_dependencies(dependencies, options, args)
    except ChooseError:
        print_(geterror())
        return 1
    if not chosen_deps:
        if not args:
            print_("No libraries specified.")
        elif options.build_all:
            print_("All libraries excluded")
    if options.msvcr71:
        chosen_deps.insert(0, msvcr71_preparation)
    if chosen_deps:
        chosen_deps.insert(0, msys_preparation)
    try:
        m = msys.Msys(options.msys_directory)
    except msys.MsysException:
        print_(geterror())
        return 1
    start_time = None
    return_code = 1
    set_environment_variables(m, options)
    try:
        configure(chosen_deps)
    except BuildError:
        print_("Build aborted:", geterror())
    else:
        print_("\n=== Starting build ===")
        start_time = time.time()  # For file timestamp checks.
        try:
            build(chosen_deps, m)
        except BuildError:
            print_("Build aborted:", geterror())
        else:
            # A successful build!
            return_code = 0
    summary(dependencies, m, start_time, chosen_deps)

    # MinGW configure file for setup.py (optional).
    try:
        import mingwcfg
    except ImportError:
        pass
    else:
        mingwcfg.write(m.mingw_root)

    return return_code
예제 #2
0
def main(dependencies, msvcr90_preparation, msys_preparation):
    """Build the dependencies according to the command line options."""

    options, args = command_line()
    if options.arg_help:
        print_("These are the Pygame library dependencies:")
        for dep in dependencies:
            print_(" ", dep.name)
        return 0
    try:
        chosen_deps = choose_dependencies(dependencies, options, args)
    except ChooseError:
        print_(geterror())
        return 1
    print_("Destination directory:", options.destination_dir)
    if not chosen_deps:
        if not args:
            print_("No libraries specified.")
        elif options.build_all:
            print_("All libraries excluded")
    chosen_deps.insert(0, msvcr90_preparation)
    chosen_deps.insert(0, msys_preparation)
    try:
        msys_directory = options.msys_directory
    except AttributeError:
        msys_directory = None
    try:
        m = msys.Msys(msys_directory)
    except msys.MsysException:
        print_(geterror())
        return 1
    start_time = None
    return_code = 1
    set_environment_variables(m, options)
    print_("\n=== Starting build ===")
    start_time = time.time()  # For file timestamp checks.
    try:
        build(chosen_deps, m)
    except BuildError:
        print_("Build aborted:", geterror())
    else:
        # A successful build!
        return_code = 0
    summary(dependencies, m, start_time, chosen_deps, options)

    return return_code
예제 #3
0
def main(dest_dir=None):
    # Top level directories.
    if dest_dir is None:
        dest_dir = prebuilt_dir
    if re.match(r'([A-Za-z]:){0,1}[^"<>:|?*]+$', dest_dir) is None:
        print "Invalid directory path name %s" % dest_dir
        return 1
    dest_dir = os.path.abspath(dest_dir)
    if os.path.isdir(dest_dir):
        if not confirm("Directory %s already exists;\ncontinue" % dest_dir):
            return 1
    mkdir(dest_dir)
    m = msys.Msys()
    src_dir = os.path.join(m.msys_root, 'local')
    prebuilt_template = os.path.abspath('prebuilt-template')
    dest_lib_dir = os.path.join(dest_dir, lib_subdir)
    
    # Read setup file.
    src_file = os.path.join(prebuilt_template, 'Setup_Win.in')
    file_copy(src_file, dest_dir)
    deps =  read_setup_file(src_file)
    setup_in = open(src_file)
    match = re.compile('[A-Z_][A-Z0-9_]* *=(.*)').match
    header_dir_pat = re.compile(' -I([^ ]+)')
    lib_pat = re.compile(' -l([^ ]+)')
    macros = []
    for line in setup_in:
        matches = match(line)
        if matches is not None:
            flags = matches.group(1)
            header_dirs = header_dir_pat.findall(flags)
            libs = lib_pat.findall(flags)
            macros.append((header_dirs, libs))

    # Copy DLLs.
    src_bin_dir = os.path.join(src_dir, 'bin')
    have_dlls = set()
    for dep in deps:
        path_elements = dep.library_dirs[0].split('/')  # / required by setup.
        dll_name = path_elements[-1]
        src_dll_path = os.path.join(src_bin_dir, dll_name)
        if os.path.exists(src_dll_path):
            if path_elements[0] == '.':
                path_elements = path_elements[2:]
            else:
                path_elements = path_elements[1:]
            dest_dll_dir = dest_dir
            for dir_name in path_elements[:-1]:
                dest_dll_dir = os.path.join(dest_dll_dir, dir_name)
                mkdir(dest_dll_dir)
            file_copy(os.path.join(src_bin_dir, dll_name),
                      os.path.join(dest_dll_dir, dll_name))
            have_dlls.add(dep.name[8:])
    
    # Copy required import libraries only.
    copied_files = set()
    src_lib_dir = os.path.join(src_dir, 'lib')
    mkdir(dest_lib_dir)
    for ignore, libs in macros:
        use = False
        for lib in libs:
            if lib in have_dlls:
                use = True
                break
        if use and lib not in copied_files:
            copied_files.add(lib)
            lib_name = 'lib%s.dll.a' % lib
            src_lib_path = os.path.join(src_lib_dir, lib_name)
            if not os.path.exists(src_lib_path):
                print "Missing import library %s" % lib_name
                return 1
            file_copy(src_lib_path, os.path.join(dest_lib_dir, lib_name))

    # Copy required header directories only.
    copied_dirs = set()
    for header_dirs, libs in macros:
        use = False
        for lib in libs:
            if lib in have_dlls:
                use = True
                break
        if use:
            for header_dir in header_dirs:
                path_elements = header_dir.split('/')
                if path_elements[0] == '.':
                    path_elements = path_elements[2:]
                else:
                    path_elements = path_elements[1:]
                src_header_dir = os.path.join(src_dir, *path_elements)
                if not os.path.exists(src_header_dir):
                    print "Missing include directory %s" % src_header_dir
                    return 1
                dest_header_dir = dest_dir
                for dir_name in path_elements:
                    dest_header_dir = os.path.join(dest_header_dir, dir_name)
                    mkdir(dest_header_dir)
                if not src_header_dir in copied_dirs:
                    copy_dir(src_header_dir, dest_header_dir)
                    copied_dirs.add(src_header_dir)

    # msvcr71.dll linking support.
    src_msvcr71_dir = os.path.join(src_dir, 'lib', 'msvcr71')
    dest_msvcr71_dir = os.path.join(dest_dir, 'lib', 'msvcr71')
    copy_dir(src_msvcr71_dir, dest_msvcr71_dir)

    # Def file bat.
    make_defs = open(os.path.join(dest_lib_dir, 'MakeDefs.bat'), 'w')
    try:
        make_defs.write('@echo off\n'
                        'rem Make .def files needed for .lib file creation.\n'
                        'rem Requires pexports.exe on the search path\n'
                        'rem (found in altbinutils-pe as SourceForge,\n'
                        'rem http://sourceforge.net/projects/mingwrep/).\n\n')
        for dep in deps:
            dll_name = os.path.split(dep.library_dirs[0])[1]
            lib = dep.name[8:]
            lib_name = 'lib%s.dll.a' % lib
            if os.path.exists(os.path.join(dest_lib_dir, lib_name)):
                start = ''
            else:
                start = 'rem '
            make_defs.write('%spexports %s >%s.def\n' %
                            (start, dll_name, lib))
    finally:
        make_defs.close()

    # Lib import files bat.
    make_libs = open(os.path.join(dest_lib_dir, 'MakeLibs.bat'), 'w')
    try:
        make_libs.write('@echo off\n'
                        'rem Make .lib import libraries.\n'
                        'rem Requires Visual C++ Studio or Toolkit.\n'
                        'rem VCVARS32.BAT (VCVARS64.BAT (?) for 64 bit build)\n'
                        'rem must be run first to use LIB.EXE.\n\n')
        for dep in deps:
            dll_name = os.path.split(dep.library_dirs[0])[1]
            lib = dep.name[8:]
            lib_name = 'lib%s.dll.a' % lib
            if os.path.exists(os.path.join(dest_lib_dir, lib_name)):
                start = ''
            else:
                start = 'rem '
            make_libs.write('%sLIB.EXE /NOLOGO /DEF:%s.def /MACHINE:IX86 /OUT:%s.lib\n' %
                            (start, lib, lib))
    finally:
        make_libs.close()

    # Top level make batch file for 32 bit build.
    file_copy(os.path.join(prebuilt_template, 'Make32.bat'), dest_lib_dir)

    return 0
예제 #4
0
test_dir = './testdir'
if not os.path.isdir(test_dir):
    print "Test directory %s not found." % test_dir

os.environ['LOCALBASE'] = test_dir
sys.path.append('..')

import dll
import config_msys
import msys

import unittest

cwd = os.getcwd()
m = msys.Msys(require_mingw=False)
os.environ['SDL_CONFIG'] = m.windows_to_msys(
    os.path.join(cwd, 'test-sdl-config'))
dependencies = dict([(dep.name, dep) for dep in config_msys.main()])
del m


class Dependency(object):
    # Holds dependency info
    def __init__(self,
                 name=None,
                 inc_dir_rel=None,
                 lib_dir_rel=None,
                 libs=None,
                 cflags=None):
        if libs is None:
예제 #5
0
def main(dependencies, msys_preparation):
    """Build the dependencies according to the command line options."""

    options, args = command_line()
    if options.arg_help:
        print_("These are the Pygame library dependencies:")
        for dep in dependencies:
            print_(" ", dep.name)
        return 0
        
    # Only building against msvcrt.dll for now.
    options.msvcrt_version = 60
    
    try:
        chosen_deps = choose_dependencies(dependencies, options, args)
    except ChooseError:
        print_(geterror())
        return 1
    if not chosen_deps:
        if not args:
            print_("No libraries specified.")
        elif options.build_all:
            print_("All libraries excluded")
    print_("Linking to C runtime library msvcrt.dll.")
    if chosen_deps and not options.clean_only:
        chosen_deps.insert(0, msys_preparation)
    try:
        m = msys.Msys(options.msys_directory)
    except msys.MsysException:
        print_(geterror())
        return 1
    print_("Using MSYS in directory:", m.msys_root)
    print_("MinGW directory:", m.mingw_root)
    start_time = None
    return_code = 1
    set_environment_variables(m, options)
    if not options.clean_only:
        print_("Destination directory:",
               m.msys_to_windows(m.environ['PREFIX']).replace('/', os.sep))
    print_("common CPPFLAGS:", m.environ.get('CPPFLAGS', ''))
    print_("common CFLAGS:", m.environ.get('CFLAGS', ''))
    print_("common LDFLAGS:", m.environ.get('LDFLAGS', ''))
    sources = hunt_paths
    if options.sources:
        sources = options.sources.split(';')
    print_("library source directories search paths: %s" % (';'.join(sources),))
    try:
        configure(chosen_deps, sources)
    except BuildError:
        print_("Build aborted:", geterror())
    else:
        if options.clean_only:
            print_("\n=== Performing clean ===")
        else:
            print_("\n=== Starting build ===")
        start_time = time.time()  # For file timestamp checks.
        try:
            build(chosen_deps, m)
        except BuildError:
            print_("Build aborted:", geterror())
        else:
            # A successful build!
            return_code = 0
    if not options.clean_only:
        summary(dependencies, m, start_time, chosen_deps)

    # MinGW configure file for setup.py (optional).
    try:
        import mingwcfg
    except ImportError:
        pass
    else:
        mingwcfg.write(m.mingw_root)

    if options.finish_alert or options.finish_alert_ntimes > 0:
        if options.finish_alert_ntimes > 0:
            m.environ['BDNTIMES'] = "%i" % (options.finish_alert_ntimes,)
        alert.build(m)
    return return_code
예제 #6
0
     print_(e)
     return 1
 print_("Destination directory:", options.destination_dir)
 if not chosen_deps:
     if not args:
         print_("No libraries specified.")
     elif options.build_all:
         print_("All libraries excluded")
 chosen_deps.insert(0, msvcr90_preparation)
 chosen_deps.insert(0, msys_preparation)
 try:
     msys_directory = options.msys_directory
 except AttributeError:
     msys_directory = None
 try:
     m = msys.Msys(msys_directory)
 except msys.MsysException, e:
     print_(e)
     return 1
 start_time = None
 return_code = 1
 set_environment_variables(m, options)
 print_("\n=== Starting build ===")
 start_time = time.time()  # For file timestamp checks.
 try:
     build(chosen_deps, m)
 except BuildError, e:
     print_("Build aborted:", e)
 else:
     # A successful build!
     return_code = 0
예제 #7
0
def main():
    m = msys.Msys(require_mingw=False)
    print_('\nHunting dependencies...')
    DEPS = [
        DependencyProg('SDL', 'SDL_CONFIG', 'sdl-config', '1.2.13', m),
        Dependency('FONT', 'SDL_ttf.h', 'libSDL_ttf.dll.a'),
        Dependency('IMAGE', 'SDL_image.h', 'libSDL_image.dll.a'),
        Dependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer.dll.a'),
        Dependency('PNG', 'png.h', 'libpng.dll.a'),
        Dependency('JPEG', 'jpeglib.h', 'libjpeg.dll.a'),
        Dependency('PORTMIDI', 'portmidi.h', 'libportmidi.dll.a'),
        Dependency('PORTTIME', 'portmidi.h', 'libportmidi.dll.a'),
        DependencyDLL('TIFF'),
        DependencyDLL('VORBISFILE'),
        DependencyDLL('VORBIS'),
        DependencyDLL('OGG'),
        DependencyDLL('FREETYPE'),
        DependencyDLL('Z'),
    ]

    if not DEPS[0].found:
        print_('Unable to run "sdl-config". Please make sure a development version of SDL is installed.')
        sys.exit(1)

    if localbase:
        incdirs = [localbase+d for d in origincdirs]
        libdirs = [localbase+d for d in origlibdirs]
    else:
        incdirs = []
        libdirs = []
    incdirs += [m.msys_to_windows("/usr/local"+d) for d in origincdirs]
    libdirs += [m.msys_to_windows("/usr/local"+d) for d in origlibdirs]
    if m.mingw_root is not None:
        incdirs += [m.msys_to_windows("/mingw"+d) for d in origincdirs]
        libdirs += [m.msys_to_windows("/mingw"+d) for d in origlibdirs]
    for arg in string.split(DEPS[0].cflags):
        if arg[:2] == '-I':
            incdirs.append(arg[2:])
        elif arg[:2] == '-L':
            libdirs.append(arg[2:])
    dll_deps = []
    for d in DEPS:
        d.configure(incdirs, libdirs)
        if d.needs_dll:
            dll_dep = DependencyDLL(d.name)
            dll_dep.configure(incdirs, libdirs, d.lib_dir)
            dll_deps.append(dll_dep)

    DEPS += dll_deps
    for d in get_definitions():
        DEPS.append(DependencyWin(d.name, d.value))
    for d in DEPS:
        if isinstance(d, DependencyDLL):
            if d.lib_dir == '':
                print_("DLL for %-12s: not found" % d.lib_name)
            else:
                print_("DLL for %-12s: %s" % (d.lib_name, d.lib_dir))

    for d in DEPS[1:]:
        if not d.found:
            if "-auto" not in sys.argv:
                logging.warning(
                    "Some pygame dependencies were not found. "
                    "Pygame can still compile and install, but games that "
                    "depend on those missing dependencies will not run. "
                    "Use -auto to continue building without all dependencies. "
                )
                raise SystemExit("Missing dependencies")
            break

    return DEPS
예제 #8
0
 def setUp(self):
     self.msys = msys.Msys()
     self.testscript_path = os.path.abspath('.\\testscript')
     open(self.testscript_path, 'wb').write('echo $XXXYYYZZZ\n')
     self.msys.environ['XXXYYYZZZ'] = 'passed'
예제 #9
0
 def setUp(self):
     self.msys = msys.Msys()
예제 #10
0
def main():
    m = msys.Msys(require_mingw=False)
    print_('\nHunting dependencies...')
    DEPS = [
        DependencyProg('SDL', 'SDL_CONFIG', 'sdl-config', '1.2.13', m),
        Dependency('FONT', 'SDL_ttf.h', 'libSDL_ttf.dll.a'),
        Dependency('IMAGE', 'SDL_image.h', 'libSDL_image.dll.a'),
        Dependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer.dll.a'),
        DependencyProg('SMPEG', 'SMPEG_CONFIG', 'smpeg-config', '0.4.3', m),
        Dependency('PNG', 'png.h', 'libpng.dll.a'),
        Dependency('JPEG', 'jpeglib.h', 'libjpeg.dll.a'),
        Dependency('PORTMIDI', 'portmidi.h', 'libportmidi.dll.a'),
        Dependency('PORTTIME', 'portmidi.h', 'libportmidi.dll.a'),
        Dependency('AVFORMAT', 'libavformat/avformat.h', 'libavformat.dll.a',
                   ['avformat', 'avcodec', 'avutil']),
        Dependency('SWSCALE', 'libswscale/swscale.h', 'libswscale.dll.a',
                   ['swscale', 'avutil']),
        DependencyDLL('TIFF'),
        DependencyDLL('VORBISFILE'),
        DependencyDLL('VORBIS'),
        DependencyDLL('OGG'),
        DependencyDLL('FREETYPE'),
        DependencyDLL('Z'),
        DependencyDLL('AVCODEC'),
        DependencyDLL('AVUTIL'),
    ]

    if not DEPS[0].found:
        print_(
            'Unable to run "sdl-config". Please make sure a development version of SDL is installed.'
        )
        sys.exit(1)

    if localbase:
        incdirs = [localbase + d for d in origincdirs]
        libdirs = [localbase + d for d in origlibdirs]
    else:
        incdirs = []
        libdirs = []
    incdirs += [m.msys_to_windows("/usr/local" + d) for d in origincdirs]
    libdirs += [m.msys_to_windows("/usr/local" + d) for d in origlibdirs]
    if m.mingw_root is not None:
        incdirs += [m.msys_to_windows("/mingw" + d) for d in origincdirs]
        libdirs += [m.msys_to_windows("/mingw" + d) for d in origlibdirs]
    for arg in string.split(DEPS[0].cflags):
        if arg[:2] == '-I':
            incdirs.append(arg[2:])
        elif arg[:2] == '-L':
            libdirs.append(arg[2:])
    dll_deps = []
    for d in DEPS:
        d.configure(incdirs, libdirs)
        if d.needs_dll:
            dll_dep = DependencyDLL(d.name)
            dll_dep.configure(incdirs, libdirs, d.lib_dir)
            dll_deps.append(dll_dep)

    DEPS += dll_deps
    for d in get_definitions():
        DEPS.append(DependencyWin(d.name, d.value))
    for d in DEPS:
        if isinstance(d, DependencyDLL):
            if d.lib_dir == '':
                print_("DLL for %-12s: not found" % d.lib_name)
            else:
                print_("DLL for %-12s: %s" % (d.lib_name, d.lib_dir))

    for d in DEPS[1:]:
        if not d.found:
            if "-auto" not in sys.argv and not confirm("""
Warning, some of the pygame dependencies were not found. Pygame can still
compile and install, but games that depend on those missing dependencies
will not run. Would you like to continue the configuration?"""):
                raise SystemExit()
            break

    return DEPS