Source

pysdl-cffi / utils / mksdl.py

Leonard Ritter ef03574 



Leonard Ritter 73c13c5 
Leonard Ritter ef03574 
Leonard Ritter 73c13c5 
Leonard Ritter ef03574 


Leonard Ritter 73c13c5 
Leonard Ritter ef03574 
Leonard Ritter b999074 
Leonard Ritter 5b7bd1c 

Leonard Ritter ef03574 
Leonard Ritter 0e1ecff 

Leonard Ritter 73c13c5 

Leonard Ritter 5b7bd1c 
Leonard Ritter 73c13c5 















Leonard Ritter 5b7bd1c 




Leonard Ritter eaba51a 


















Leonard Ritter 5b7bd1c 
Leonard Ritter f04f6e5 








































Leonard Ritter 5b7bd1c 


Leonard Ritter ef03574 





Leonard Ritter d17e66f 

Leonard Ritter ef03574 
Leonard Ritter d17e66f 
Leonard Ritter ef03574 





















Leonard Ritter b999074 
Leonard Ritter d010d8a 

Leonard Ritter b999074 
Leonard Ritter ef03574 

Leonard Ritter 73c13c5 








Leonard Ritter ef03574 

Leonard Ritter f04f6e5 

Leonard Ritter 5b7bd1c 

Leonard Ritter 73c13c5 

# SDL downloader & builder

import os
import sys
import argparse

from tentacle import unpack_contents
import shutil

SOURCE = "http://hg.libsdl.org/SDL"
REVISION = "a91717ac8ff1"
THISDIR = os.path.abspath(os.path.dirname(__file__))
basedir = os.path.abspath(os.path.join(THISDIR, '..'))
bindir = os.path.abspath(os.path.join(basedir, 'sdl-bin'))
targetdir = os.path.abspath(os.path.join(basedir, 'sdl-src'))

PATCH_SDL_OSX_GL32 = os.path.join(THISDIR, 'sdl-osx-gl3.2.patch')

args = None

def clone_repo():
    if args.archive:
        unpack_contents(args.archive, targetdir)
    else:
        if not os.path.isdir(targetdir):
            cmd = 'hg clone -r {0} {1} {2}'.format(
                REVISION, SOURCE, targetdir)
            print(cmd)
            if os.system(cmd):
                print("failed :(")
                return
        if sys.platform == 'darwin':
            # try to apply patch
            cmd = 'patch -d {} -p 1 -i {}'.format(targetdir, PATCH_SDL_OSX_GL32)
            if os.system(cmd):
                print("applying patch failed :(")
                return
    return True

def run_win32_build():
    if not clone_repo():
        return
    builddir = os.path.join(targetdir, 'VisualC', 'SDL', 'Release')
    if not os.path.isdir(builddir):
        print("You must build the visual studio solution file in release mode first.")
        return
    if os.path.isdir(bindir):
        print("Removing stale {0}...".format(bindir))
        shutil.rmtree(bindir)
    os.makedirs(bindir)
    shutil.copytree(
        os.path.join(targetdir, 'include'), 
        os.path.join(bindir, 'include'))
    libdir = os.path.join(bindir, 'lib')
    os.makedirs(libdir)
    shutil.copy2(
        os.path.join(builddir, 'SDL2.lib'),
        libdir)
    shutil.copy2(
        os.path.join(builddir, 'SDL2.dll'),
        os.path.join(basedir, 'sdl'))

def run_darwin_build():
    if not clone_repo():
        return
    
    os.chdir(targetdir)
    builddir = os.path.join(targetdir, 'build')
    if not os.path.isdir(builddir):
        os.makedirs(builddir)
    
    os.environ['CFLAGS'] = '-fPIC'
    os.environ['CXXFLAGS'] = '-fPIC'
    os.chdir(builddir)
    cmd = '../configure --with-pic --prefix {0}'.format(bindir)
    print(cmd)
    if os.system(cmd):
        print("failed :(")
        return
    
    cmd = 'make -j 4'
    print(cmd)
    if os.system(cmd):
        print("failed :(")
        return
    
    if os.path.isdir(bindir):
        print("Removing stale {0}...".format(bindir))
        shutil.rmtree(bindir)
    os.makedirs(bindir)
    
    cmd = 'make install'
    print(cmd)
    if os.system(cmd):
        print("failed :(")
        return
    
    # copy over
    shutil.copy2(os.path.join(bindir, 'lib', 'libSDL2-2.0.0.dylib'),
        os.path.join(basedir, 'sdl', 'libSDL2.dylib'))
    
    print("SDL is ready.")

def run_linux_build():
    if not clone_repo():
        return
    
    os.chdir(targetdir)
    builddir = os.path.join(targetdir, 'build')
    if not os.path.isdir(builddir):
        os.makedirs(builddir)
    
    os.environ['CFLAGS'] = '-fPIC'
    os.environ['CXXFLAGS'] = '-fPIC'
    os.chdir(builddir)
    cmd = '../configure --with-pic --prefix {0}'.format(bindir)
    print(cmd)
    if os.system(cmd):
        print("failed :(")
        return
    
    cmd = 'make -j 4'
    print(cmd)
    if os.system(cmd):
        print("failed :(")
        return
    
    if os.path.isdir(bindir):
        print("Removing stale {0}...".format(bindir))
        shutil.rmtree(bindir)
    os.makedirs(bindir)
    
    cmd = 'make install'
    print(cmd)
    if os.system(cmd):
        print("failed :(")
        return
    
    # copy over
    shutil.copy2(os.path.join(bindir, 'lib', 'libSDL2-2.0.so.0.0.0'),
        os.path.join(basedir, 'sdl', 'libSDL2.so'))
    
    print("SDL is ready.")

def run_build():
    global args 
    
    parser = argparse.ArgumentParser(description='check out and build SDL')
    parser.add_argument('archive', metavar='archive', nargs='?',
                   help='archive file to use instead of repository')
    
    args = parser.parse_args()
    
    if sys.platform == 'linux2':
        run_linux_build()
    elif sys.platform == 'darwin':
        run_darwin_build()
    elif sys.platform == 'win32':
        run_win32_build()

if __name__ == '__main__':
    run_build()