pygame /

#!/usr/bin/env python
# For MinGW build requires Python 2.4 or better and win32api.

"""Quick tool to help setup the needed paths and flags
in your Setup file. This will call the appropriate sub-config
scripts automatically.

each platform config file only needs a "main" routine
that returns a list of instances. the instances must
contain the following variables. 
name: name of the dependency, as references in Setup (SDL, FONT, etc)
inc_dir: path to include
lib_dir: library directory
lib: name of library to be linked to
found: true if the dep is available
cflags: extra compile flags

import msysio
import mingwcfg
import sys, os, shutil, string

def print_(*args, **kwds):
    """Simular to the Python 3.0 print function"""
    # This not only supports MSYS but is also a head start on the move to
    # Python 3.0. Also, this function can be overridden for testing.
    msysio.print_(*args, **kwds)

def confirm(message):
    "ask a yes/no question, return result"
    reply = msysio.raw_input_("\n%s [Y/n]:" % message)
    if reply and string.lower(reply[0]) == 'n':
        return 0
    return 1

def is_msys_mingw():
    """Return true if this in an MinGW/MSYS build

    The user may prompted for confirmation so only call this function
    if msysio.is_msys():
        return 1
    if ('MINGW_ROOT_DIRECTORY' in os.environ or
        return confirm("Is this an mingw/msys build")
    return 0

def prepdep(dep, basepath):
    "add some vars to a dep"
    if dep.libs:
        dep.line = + ' ='
        for lib in dep.libs:
            dep.line += ' -l' + lib
        dep.line = + ' = -I.'
    dep.varname = '$('')'
    if not dep.found:
        if == 'SDL': #fudge if this is unfound SDL
            dep.line = 'SDL = -I/NEED_INC_PATH_FIX -L/NEED_LIB_PATH_FIX -lSDL'
            dep.varname = '$('')'
            dep.found = 1

    inc = lid = lib = ""
    if basepath:
        if dep.inc_dir: inc = ' -I$(BASE)'+dep.inc_dir[len(basepath):]
        if dep.lib_dir: lid = ' -L$(BASE)'+dep.lib_dir[len(basepath):]
        if dep.inc_dir: inc = ' -I' + dep.inc_dir
        if dep.lib_dir: lid = ' -L' + dep.lib_dir
    libs = ''
    for lib in dep.libs: 
        libs += ' -l' + lib

        dep.line = + libs + lid
        dep.line =' =' + inc + lid + ' ' + dep.cflags + libs

def writesetupfile(deps, basepath, additional_lines):
    "create a modified copy of"
    origsetup = open('', 'r')
    newsetup = open('Setup', 'w')
    line = ''
    while line.find('#--StartConfig') == -1:
        line = origsetup.readline()
    while line.find('#--EndConfig') == -1:
        line = origsetup.readline()

    if basepath:
        newsetup.write('BASE = ' + basepath + '\n')
    for d in deps:
        newsetup.write(d.line + '\n')

    lines = origsetup.readlines()
    for line in lines:
        useit = 1
        if not line.startswith('COPYLIB'):
            for d in deps:
                if line.find(d.varname)!=-1 and not d.found:
                    useit = 0
        if useit:

def main():
    additional_platform_setup = []
    if sys.platform == 'win32' and not is_msys_mingw():
        print_('Using WINDOWS configuration...\n')
        import config_win as CFG
    elif sys.platform == 'win32':
        print_('Using WINDOWS mingw/msys configuration...\n')
        import config_msys as CFG
    elif sys.platform == 'darwin':
        print_('Using Darwin configuration...\n')
        import config_darwin as CFG
        additional_platform_setup = file("", "r").readlines()
        print_('Using UNIX configuration...\n')
        import config_unix as CFG
    if os.path.isfile('Setup'):
        if "-auto" in sys.argv or confirm('Backup existing "Setup" file'):
            shutil.copyfile('Setup', 'Setup.bak')
    if not "-auto" in sys.argv and os.path.isdir('build'):
        if confirm('Remove old build directory (force recompile)'):
            shutil.rmtree('build', 0)

    deps = CFG.main()
    if deps:
        basepath = None
        for d in deps:
            prepdep(d, basepath)
        writesetupfile(deps, basepath, additional_platform_setup)
        print_("""\nIf you get compiler errors during install, doublecheck
the compiler flags in the "Setup" file.\n""")
        print_("""\nThere was an error creating the Setup file, check for errors
or make a copy of "" and edit by hand.""")

if __name__ == '__main__': main()