Commits

Gabriel Jacobo  committed 9fbcd8b

Schafer module reshuffling

  • Participants
  • Parent commits ff49716

Comments (0)

Files changed (17)

 tmp
 host
 .idea
+.pyc
+

File tools/modules/env.py

 from copy import deepcopy
 import os
+from os.path import join
+
+class Target(object):
+    pass
+
+class Builds(object):
+    pass
+
+
+def get_target(platform, project_root = '.', dist=None, tmp=None):
+    """ Set up some target system variables """
+    from schafer import ROOT_DIR
+    target = Target()
+    target.platform = platform
+    dist_dir = join (ROOT_DIR, 'dist', platform) if dist == None else dist
+    tmp_dir = join (ROOT_DIR, 'tmp', platform) if tmp == None else tmp
+    target.dist = dist_dir
+    target.tmp = tmp_dir
+    target.builds = Builds()
+    target.builds.PYTHON = join(tmp_dir, 'python')
+    target.builds.SDL = join(tmp_dir, 'sdl')
+    target.builds.SDL_IMAGE = join(tmp_dir, 'sdl_image')
+    target.builds.SDL_TTF = join(tmp_dir, 'sdl_ttf')
+    target.builds.FREETYPE = join(tmp_dir, 'freetype')
+    target.builds.PNG = join(tmp_dir, 'png')
+    target.builds.JPG = join(tmp_dir, 'jpg')
+    target.builds.ZLIB = join(tmp_dir, 'zlib')
+    target.builds.IGNIFUGA = join(tmp_dir, 'ignifuga')
+
+    target.python_headers = join(target.builds.PYTHON, 'Include')
+    target.sdl_headers = join(dist_dir, 'include', 'SDL')
+
+    target.project_root = project_root
+    target.project = join(project_root, 'build')
+
+    return target
+
+
 
 def prepare_linux64_env():
     """ Set up the environment variables for Linux64 compilation"""
     env['STRIP'] = "arm-linux-androideabi-strip --strip-unneeded"
     env['MAKE'] = 'make V=0 -k -j4 HOSTPYTHON=%s HOSTPGEN=%s CROSS_COMPILE=arm-eabi- CROSS_COMPILE_TARGET=yes' % (HOSTPYTHON, HOSTPGEN)
 
-    env['DIST_DIR'] = DIST_DIR
-    env['TMP_DIR'] = TMP_DIR
     return env
 
 
     env = deepcopy(os.environ)
     #env['PATH'] = "%s/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/:%s:%s/tools:/usr/local/bin:/usr/bin:/bin:%s" % (ANDROID_NDK, ANDROID_NDK, ANDROID_SDK, '') #env['PATH'])
     env['ARCH'] = "win32"
-    #env['CFLAGS'] ="-I %s" % (join(BUILDS['PYTHON'], 'PC'),)
+    #env['CFLAGS'] ="-I %s" % (join(target.builds.PYTHON, 'PC'),)
     # Force LIBC functions (otherwise you get undefined SDL_sqrt, SDL_cos, etc
     # Force a dummy haptic and mm joystick (otherwise there a bunch of undefined symbols from SDL_haptic.c and SDL_joystick.c).
     # The cross platform configuration of SDL doesnt work fine at this moment and it doesn't define these variables as it should
     env['OBJDUMP'] = "i586-mingw32msvc-objdump"
     env['RESCOMP'] = "i586-mingw32msvc-windres"
     env['MAKE'] = 'make V=0 -k -j4 HOSTPYTHON=%s HOSTPGEN=%s CROSS_COMPILE=mingw32msvc CROSS_COMPILE_TARGET=yes' % (HOSTPYTHON, HOSTPGEN)
-    env['DIST_DIR'] = DIST_DIR
-    env['TMP_DIR'] = TMP_DIR
     return env

File tools/modules/log.py

+#Copyright (c) 2010-2012, Gabriel Jacobo
+#All rights reserved.
+#Permission to use this file is granted under the conditions of the Ignifuga Game Engine License
+#whose terms are available in the LICENSE file or at http://www.ignifuga.org/license
+
+# Schafer Module: Log utility functions
+# Author: Gabriel Jacobo <gabriel@mdqinc.com>
+
+
+class bcolors:
+    HEADER = '\033[95m'
+    OKBLUE = '\033[94m'
+    OKGREEN = '\033[92m'
+    WARNING = '\033[93m'
+    FAIL = '\033[91m'
+    ENDC = '\033[0m'
+
+class loglevel:
+    DEBUG = 5
+    INFO = 10
+    WARNING = 20
+    ERROR = 30
+
+def info(msg):
+    log(msg, loglevel.INFO)
+def warn(msg):
+    log(msg, loglevel.WARNING)
+def error(msg):
+    log(msg, loglevel.ERROR)
+
+def log(msg, level = loglevel.DEBUG):
+    if level < 10:
+        # Debug
+        print bcolors.OKBLUE + "* " + msg + bcolors.ENDC
+    elif level < 20:
+        # Info
+        print bcolors.OKGREEN + "* " + msg + bcolors.ENDC
+    elif level < 30:
+        # Warning
+        print bcolors.WARNING + "* " + msg + bcolors.ENDC
+    elif level < 50:
+        # Error
+        print bcolors.FAIL + "* " + msg + bcolors.ENDC

File tools/modules/project/android.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, make_python_freeze
+from ..log import log, error
+from schafer import prepare_source, make_python_freeze
 
-def make(options, env, DIST_DIR, BUILDS, sources, cython_src, cfiles):
+def make(options, env, target, sources, cython_src, cfiles):
     from schafer import SED_CMD, ANDROID_SDK, ANDROID_NDK
 
     # Copy/update the skeleton
     for cfile in cfiles:
         local_cfiles.append(basename(cfile))
 
-    cmd = 'rsync -aqPm --exclude .svn --exclude .hg %s/ %s' % (DIST_DIR, android_project)
-    Popen(shlex.split(cmd), cwd = DIST_DIR).communicate()
+    cmd = 'rsync -aqPm --exclude .svn --exclude .hg %s/ %s' % (target.dist, android_project)
+    Popen(shlex.split(cmd), cwd = target.dist).communicate()
 
     if options.wallpaper:
         # Wallpapers use a slightly different manifest
         error ('Error during compilation of the project')
         exit()
 
-    shutil.move(apk, join(BUILDS['PROJECT'], '..', options.project+'.apk'))
+    shutil.move(apk, join(target.project, '..', options.project+'.apk'))
 
     return True

File tools/modules/project/linux64.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, make_python_freeze
+from ..log import log, error
+from schafer import prepare_source, make_python_freeze
 from ..util import get_sdl_flags, get_freetype_flags, get_png_flags
 
-def make(options, env, DIST_DIR, BUILDS, sources, cython_src, cfiles):
+def make(options, env, target, sources, cython_src, cfiles):
     # Get some required flags
-    sdlflags = get_sdl_flags(DIST_DIR)
-    freetypeflags = get_freetype_flags(DIST_DIR)
-    pngflags = get_png_flags(DIST_DIR)
+    sdlflags = get_sdl_flags(target)
+    freetypeflags = get_freetype_flags(target)
+    pngflags = get_png_flags(target)
 
     sdlflags = sdlflags.replace('-lpthread', '').replace('-ldl', '')
     freetypeflags = freetypeflags.replace('-lpthread', '').replace('-ldl', '')
     pngflags = pngflags.replace('-lpthread', '').replace('-ldl', '')
-    cmd = '%s -static-libgcc -Wl,--no-export-dynamic -Wl,-Bstatic -fPIC %s -I%s -I%s -L%s -lpython2.7 -lutil -lSDL2_ttf -lSDL2_image %s -ljpeg -lm %s %s -Wl,-Bdynamic -lpthread -ldl -o %s' % (env['CC'], sources,join(DIST_DIR, 'include'), join(DIST_DIR, 'include', 'python2.7'), join(DIST_DIR, 'lib'), pngflags, sdlflags, freetypeflags, options.project)
+    cmd = '%s -static-libgcc -Wl,--no-export-dynamic -Wl,-Bstatic -fPIC %s -I%s -I%s -L%s -lpython2.7 -lutil -lSDL2_ttf -lSDL2_image %s -ljpeg -lm %s %s -Wl,-Bdynamic -lpthread -ldl -o %s' % (env['CC'], sources,join(target.dist, 'include'), join(target.dist, 'include', 'python2.7'), join(target.dist, 'lib'), pngflags, sdlflags, freetypeflags, options.project)
     Popen(shlex.split(cmd), cwd = cython_src, env=env).communicate()
 
     if not isfile(join(cython_src, options.project)):
         exit()
     cmd = '%s %s' % (env['STRIP'], join(cython_src, options.project))
     Popen(shlex.split(cmd), cwd = cython_src, env=env).communicate()
-    shutil.move(join(cython_src, options.project), join(BUILDS['PROJECT'], '..', options.project))
+    shutil.move(join(cython_src, options.project), join(target.project, '..', options.project))
 
     return True

File tools/modules/project/mingw32.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, make_python_freeze
+from ..log import log, error
+from schafer import prepare_source, make_python_freeze
 from ..util import get_sdl_flags, get_freetype_flags, get_png_flags
 
-def make(options, env, DIST_DIR, BUILDS, sources, cython_src, cfiles):
+def make(options, env, target, sources, cython_src, cfiles):
     # Get some required flags
-    sdlflags = get_sdl_flags(DIST_DIR)
-    freetypeflags = get_freetype_flags(DIST_DIR)
-    pngflags = get_png_flags(DIST_DIR)
+    sdlflags = get_sdl_flags(target)
+    freetypeflags = get_freetype_flags(target)
+    pngflags = get_png_flags(target)
 
     extralibs = "-lstdc++ -lgcc -lodbc32 -lwsock32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lctl3d32 -lodbc32 -ladvapi32 -lopengl32 -lglu32 -lole32 -loleaut32 -luuid -lgdi32 -limm32 -lversion"
-    cmd = '%s -Wl,--no-export-dynamic -static-libgcc -static -DMS_WIN32 -DMS_WINDOWS -DHAVE_USABLE_WCHAR_T %s -I%s -I%s -L%s -lpython2.7 -mwindows -lmingw32 -lSDL2_ttf -lSDL2_image -lSDL2main -lSDL2 -lpng -ljpeg -lfreetype -lz %s %s %s -o %s' % (env['CC'], sources, join(DIST_DIR, 'include'), join(DIST_DIR, 'include', 'python2.7'), join(DIST_DIR, 'lib'), sdlflags, freetypeflags, extralibs, options.project)
+    cmd = '%s -Wl,--no-export-dynamic -static-libgcc -static -DMS_WIN32 -DMS_WINDOWS -DHAVE_USABLE_WCHAR_T %s -I%s -I%s -L%s -lpython2.7 -mwindows -lmingw32 -lSDL2_ttf -lSDL2_image -lSDL2main -lSDL2 -lpng -ljpeg -lfreetype -lz %s %s %s -o %s' % (env['CC'], sources, join(target.dist, 'include'), join(target.dist, 'include', 'python2.7'), join(target.dist, 'lib'), sdlflags, freetypeflags, extralibs, options.project)
     Popen(shlex.split(cmd), cwd = cython_src, env=env).communicate()
 
     if not isfile(join(cython_src, options.project)):
         exit()
     cmd = '%s %s' % (env['STRIP'], join(cython_src, options.project))
     Popen(shlex.split(cmd), cwd = cython_src, env=env).communicate()
-    shutil.move(join(cython_src, options.project), join(BUILDS['PROJECT'], '..', options.project+'.exe'))
+    shutil.move(join(cython_src, options.project), join(target.project, '..', options.project+'.exe'))
 
     return True

File tools/modules/project/osx.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, make_python_freeze
+from ..log import log, error
+from schafer import prepare_source, make_python_freeze
 from ..util import get_sdl_flags, get_freetype_flags, get_png_flags
 
-def make(options, env, DIST_DIR, BUILDS, sources, cython_src, cfiles):
+def make(options, env, target, sources, cython_src, cfiles):
     # Get some required flags
-    sdlflags = get_sdl_flags(DIST_DIR)
-    freetypeflags = get_freetype_flags(DIST_DIR)
-    pngflags = get_png_flags(DIST_DIR)
+    sdlflags = get_sdl_flags(target)
+    freetypeflags = get_freetype_flags(target)
+    pngflags = get_png_flags(target)
 
-    cmd = '%s -arch i386 -arch x86_64 -static-libgcc -fPIC %s -I%s -I%s -L%s -lobjc -lpython2.7 -lutil -lSDL2_ttf -lSDL2_image %s -ljpeg -lm %s %s -lpthread -ldl -o %s' % (env['CC'], sources,join(DIST_DIR, 'include'), join(DIST_DIR, 'include', 'python2.7'), join(DIST_DIR, 'lib'), pngflags, sdlflags, freetypeflags, options.project)
+    cmd = '%s -arch i386 -arch x86_64 -static-libgcc -fPIC %s -I%s -I%s -L%s -lobjc -lpython2.7 -lutil -lSDL2_ttf -lSDL2_image %s -ljpeg -lm %s %s -lpthread -ldl -o %s' % (env['CC'], sources,join(target.dist, 'include'), join(target.dist, 'include', 'python2.7'), join(target.dist, 'lib'), pngflags, sdlflags, freetypeflags, options.project)
     Popen(shlex.split(cmd), cwd = cython_src, env=env).communicate()
 
     if not isfile(join(cython_src, options.project)):
         exit()
     cmd = '%s %s' % (env['STRIP'], join(cython_src, options.project))
     Popen(shlex.split(cmd), cwd = cython_src, env=env).communicate()
-    shutil.move(join(cython_src, options.project), join(BUILDS['PROJECT'], '..', options.project))
+    shutil.move(join(cython_src, options.project), join(target.project, '..', options.project))
 
     return True

File tools/modules/python/android.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, make_python_freeze
+from ..log import log, error
+from schafer import prepare_source, make_python_freeze, SED_CMD
 
-def make(env, DIST_DIR, BUILDS, freeze_modules, frozen_file):
-    make_python_freeze(freeze_modules, frozen_file)
+def make(env, target, freeze_modules, frozen_file):
+    make_python_freeze('android', freeze_modules, frozen_file)
     # Android is built in shared mode
-    if not isfile(join(BUILDS['PYTHON'], 'pyconfig.h')) or not isfile(join(BUILDS['PYTHON'], 'Makefile')):
-        cmd = './configure --enable-silent-rules LDFLAGS="-Wl,--allow-shlib-undefined" CFLAGS="-mandroid -fomit-frame-pointer --sysroot %s/platforms/android-5/arch-arm" HOSTPYTHON=%s HOSTPGEN=%s --host=arm-eabi --build=i686-pc-linux-gnu --enable-shared --prefix="%s"'% (ANDROID_NDK, HOSTPYTHON, HOSTPGEN, DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON'], env=env).communicate()
-        cmd = SED_CMD + '"s|^INSTSONAME=\(.*.so\).*|INSTSONAME=\\1|g" %s' % (join(BUILDS['PYTHON'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON']).communicate()
+    if not isfile(join(target.builds.PYTHON, 'pyconfig.h')) or not isfile(join(target.builds.PYTHON, 'Makefile')):
+        cmd = './configure --enable-silent-rules LDFLAGS="-Wl,--allow-shlib-undefined" CFLAGS="-mandroid -fomit-frame-pointer --sysroot %s/platforms/android-5/arch-arm" HOSTPYTHON=%s HOSTPGEN=%s --host=arm-eabi --build=i686-pc-linux-gnu --enable-shared --prefix="%s"'% (ANDROID_NDK, HOSTPYTHON, HOSTPGEN, target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON, env=env).communicate()
+        cmd = SED_CMD + '"s|^INSTSONAME=\(.*.so\).*|INSTSONAME=\\1|g" %s' % (join(target.builds.PYTHON, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON).communicate()
     cmd = 'make V=0 -k -j4 HOSTPYTHON=%s HOSTPGEN=%s CROSS_COMPILE=arm-eabi- CROSS_COMPILE_TARGET=yes' % (HOSTPYTHON, HOSTPGEN)
-    Popen(shlex.split(cmd), cwd = BUILDS['PYTHON'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.PYTHON, env=env).communicate()
 
     # Copy some files to the skeleton directory
     try:
-        if isdir(join(DIST_DIR, 'jni', 'python', 'Include')):
-            shutil.rmtree(join(DIST_DIR, 'jni', 'python', 'Include'))
-        shutil.copytree(join(BUILDS['PYTHON'], 'Include'), join(DIST_DIR, 'jni', 'python', 'Include'))
-        shutil.copy(join(BUILDS['PYTHON'], 'pyconfig.h'), join(DIST_DIR, 'jni', 'python', 'pyconfig.h'))
-        shutil.copy(join(BUILDS['PYTHON'], 'libpython2.7.so'), join(DIST_DIR, 'jni', 'python', 'libpython2.7.so'))
+        if isdir(join(target.dist, 'jni', 'python', 'Include')):
+            shutil.rmtree(join(target.dist, 'jni', 'python', 'Include'))
+        shutil.copytree(join(target.builds.PYTHON, 'Include'), join(target.dist, 'jni', 'python', 'Include'))
+        shutil.copy(join(target.builds.PYTHON, 'pyconfig.h'), join(target.dist, 'jni', 'python', 'pyconfig.h'))
+        shutil.copy(join(target.builds.PYTHON, 'libpython2.7.so'), join(target.dist, 'jni', 'python', 'libpython2.7.so'))
         log('Python built successfully')
     except:
         error('Error while building Python for target')

File tools/modules/python/linux64.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, make_python_freeze
+from ..log import log, error
+from schafer import prepare_source, make_python_freeze, SED_CMD
 
-def make(env, DIST_DIR, BUILDS, freeze_modules, frozen_file):
-    if not isfile(join(BUILDS['PYTHON'], 'pyconfig.h')) or not isfile(join(BUILDS['PYTHON'], 'Makefile')):
+def make(env, target, freeze_modules, frozen_file):
+    if not isfile(join(target.builds.PYTHON, 'pyconfig.h')) or not isfile(join(target.builds.PYTHON, 'Makefile')):
         # Linux is built in almost static mode (minus libdl/pthread which make OpenGL fail if compiled statically)
-        cmd = join(DIST_DIR, 'bin', 'sdl2-config' ) + ' --static-libs'
+        cmd = join(target.dist, 'bin', 'sdl2-config' ) + ' --static-libs'
         sdlldflags = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0].replace('-lpthread', '').replace('-ldl', '') # Removing pthread and dl to make them dynamically bound (req'd for Linux)
-        cmd = join(DIST_DIR, 'bin', 'sdl2-config' ) + ' --cflags'
+        cmd = join(target.dist, 'bin', 'sdl2-config' ) + ' --cflags'
         sdlcflags = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
         # Fully static config, doesnt load OpenGL from SDL under Linux for some reason
-        #cmd = './configure --enable-silent-rules LDFLAGS="-Wl,--no-export-dynamic -static-libgcc -static -Wl,-Bstatic %s" CPPFLAGS="-static -fPIC %s" LINKFORSHARED=" " DYNLOADFILE="dynload_stub.o" --disable-shared --prefix="%s"'% (sdlldflags,sdlcflags,DIST_DIR,)
+        #cmd = './configure --enable-silent-rules LDFLAGS="-Wl,--no-export-dynamic -static-libgcc -static -Wl,-Bstatic %s" CPPFLAGS="-static -fPIC %s" LINKFORSHARED=" " DYNLOADFILE="dynload_stub.o" --disable-shared --prefix="%s"'% (sdlldflags,sdlcflags,target.dist,)
         # Mostly static, minus pthread and dl - Linux
-        cmd = './configure --enable-silent-rules LDFLAGS="-Wl,--no-export-dynamic -Wl,-Bstatic" CPPFLAGS="-static -fPIC %s" LINKFORSHARED=" " LDLAST="-static-libgcc -Wl,-Bstatic %s -Wl,-Bdynamic -lpthread -ldl" DYNLOADFILE="dynload_stub.o" --disable-shared --prefix="%s"'% (sdlcflags,sdlldflags,DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON']).communicate()
+        cmd = './configure --enable-silent-rules LDFLAGS="-Wl,--no-export-dynamic -Wl,-Bstatic" CPPFLAGS="-static -fPIC %s" LINKFORSHARED=" " LDLAST="-static-libgcc -Wl,-Bstatic %s -Wl,-Bdynamic -lpthread -ldl" DYNLOADFILE="dynload_stub.o" --disable-shared --prefix="%s"'% (sdlcflags,sdlldflags,target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON).communicate()
         # Patch the Makefile to optimize the static libraries inclusion... - Linux
-        cmd = SED_CMD + '"s|^LIBS=.*|LIBS=-static-libgcc  -Wl,-Bstatic -lutil -lz -Wl,-Bdynamic -lpthread -ldl |g" %s' % (join(BUILDS['PYTHON'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON']).communicate()
-    make_python_freeze(freeze_modules, frozen_file)
-    if isfile(join(DIST_DIR, 'lib', 'libpython2.7.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libpython2.7.a'))
+        cmd = SED_CMD + '"s|^LIBS=.*|LIBS=-static-libgcc  -Wl,-Bstatic -lutil -lz -Wl,-Bdynamic -lpthread -ldl |g" %s' % (join(target.builds.PYTHON, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON).communicate()
+    make_python_freeze('linux64', freeze_modules, frozen_file)
+    if isfile(join(target.dist, 'lib', 'libpython2.7.a')):
+        os.remove(join(target.dist, 'lib', 'libpython2.7.a'))
 
     # Remove setup.py as its of no use here and it tries to compile a lot of extensions that don't work in static mode
-    if isfile(join(BUILDS['PYTHON'],'setup.py')):
-        os.unlink(join(BUILDS['PYTHON'],'setup.py'))
+    if isfile(join(target.builds.PYTHON,'setup.py')):
+        os.unlink(join(target.builds.PYTHON,'setup.py'))
 
     cmd = 'make V=0 install -k -j4'
     # Rebuild Python including the frozen modules!
-    Popen(shlex.split(cmd), cwd = BUILDS['PYTHON'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.PYTHON, env=env).communicate()
 
     # Check success
-    if isfile(join(DIST_DIR, 'lib', 'libpython2.7.a')):
+    if isfile(join(target.dist, 'lib', 'libpython2.7.a')):
         log('Python built successfully')
     else:
         error('Error building python')

File tools/modules/python/mingw32.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, make_python_freeze
+from log import log, error
+from schafer import prepare_source, make_python_freeze, SED_CMD
 
-def make(env, DIST_DIR, BUILDS, freeze_modules, frozen_file):
-    if not isfile(join(BUILDS['PYTHON'], 'pyconfig.h')) or not isfile(join(BUILDS['PYTHON'], 'Makefile')):
+def make(env, target, freeze_modules, frozen_file):
+    if not isfile(join(target.builds.PYTHON, 'pyconfig.h')) or not isfile(join(target.builds.PYTHON, 'Makefile')):
         # Linux is built in almost static mode (minus libdl/pthread which make OpenGL fail if compiled statically)
-        cmd = join(DIST_DIR, 'bin', 'sdl2-config' ) + ' --static-libs'
+        cmd = join(target.dist, 'bin', 'sdl2-config' ) + ' --static-libs'
         sdlldflags = Popen(shlex.split(cmd), stdout=PIPE, env=env).communicate()[0].split('\n')[0].replace('-lpthread', '').replace('-ldl', '') # Removing pthread and dl to make them dynamically bound (req'd for Linux)
-        cmd = join(DIST_DIR, 'bin', 'sdl2-config' ) + ' --cflags'
+        cmd = join(target.dist, 'bin', 'sdl2-config' ) + ' --cflags'
         sdlcflags = Popen(shlex.split(cmd), stdout=PIPE, env=env).communicate()[0].split('\n')[0]
         extralibs = "-lstdc++ -lgcc -lodbc32 -lwsock32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lctl3d32 -lodbc32 -ladvapi32 -lopengl32 -lglu32 -lole32 -loleaut32 -luuid"
-        cmd = './configure --enable-silent-rules LDFLAGS="-Wl,--no-export-dynamic -static-libgcc -static %s %s" CFLAGS="-DMS_WIN32 -DMS_WINDOWS -DHAVE_USABLE_WCHAR_T" CPPFLAGS="-static %s" LINKFORSHARED=" " LIBOBJS="import_nt.o dl_nt.o getpathp.o" THREADOBJ="Python/thread.o" DYNLOADFILE="dynload_win.o" --disable-shared HOSTPYTHON=%s HOSTPGEN=%s --host=i586-mingw32msvc --build=i686-pc-linux-gnu  --prefix="%s"'% (sdlldflags, extralibs, sdlcflags, HOSTPYTHON, HOSTPGEN, DIST_DIR,)
+        cmd = './configure --enable-silent-rules LDFLAGS="-Wl,--no-export-dynamic -static-libgcc -static %s %s" CFLAGS="-DMS_WIN32 -DMS_WINDOWS -DHAVE_USABLE_WCHAR_T" CPPFLAGS="-static %s" LINKFORSHARED=" " LIBOBJS="import_nt.o dl_nt.o getpathp.o" THREADOBJ="Python/thread.o" DYNLOADFILE="dynload_win.o" --disable-shared HOSTPYTHON=%s HOSTPGEN=%s --host=i586-mingw32msvc --build=i686-pc-linux-gnu  --prefix="%s"'% (sdlldflags, extralibs, sdlcflags, HOSTPYTHON, HOSTPGEN, target.dist,)
         # Mostly static, minus pthread and dl - Linux
-        #cmd = './configure --enable-silent-rules LDFLAGS="-Wl,--no-export-dynamic -Wl,-Bstatic" CPPFLAGS="-static -fPIC %s" LINKFORSHARED=" " LDLAST="-static-libgcc -Wl,-Bstatic %s -Wl,-Bdynamic -lpthread -ldl" DYNLOADFILE="dynload_stub.o" --disable-shared --prefix="%s"'% (sdlcflags,sdlldflags,DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON'], env=env).communicate()
+        #cmd = './configure --enable-silent-rules LDFLAGS="-Wl,--no-export-dynamic -Wl,-Bstatic" CPPFLAGS="-static -fPIC %s" LINKFORSHARED=" " LDLAST="-static-libgcc -Wl,-Bstatic %s -Wl,-Bdynamic -lpthread -ldl" DYNLOADFILE="dynload_stub.o" --disable-shared --prefix="%s"'% (sdlcflags,sdlldflags,target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON, env=env).communicate()
 
-        cmd = SED_CMD + '"s|\${LIBOBJDIR}fileblocks\$U\.o||g" %s' % (join(BUILDS['PYTHON'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON']).communicate()
+        cmd = SED_CMD + '"s|\${LIBOBJDIR}fileblocks\$U\.o||g" %s' % (join(target.builds.PYTHON, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON).communicate()
         # Enable NT Threads
-        cmd = SED_CMD + '"s|.*NT_THREADS.*|#define NT_THREADS|g" %s' % (join(BUILDS['PYTHON'], 'pyconfig.h'))
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON']).communicate()
+        cmd = SED_CMD + '"s|.*NT_THREADS.*|#define NT_THREADS|g" %s' % (join(target.builds.PYTHON, 'pyconfig.h'))
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON).communicate()
 
         # Disable PTY stuff that gets activated because of errors in the configure script
-        cmd = SED_CMD + '"s|.*HAVE_OPENPTY.*|#undef HAVE_OPENPTY|g" %s' % (join(BUILDS['PYTHON'], 'pyconfig.h'))
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON']).communicate()
-        cmd = SED_CMD + '"s|.*HAVE__GETPTY.*|#undef HAVE__GETPTY|g" %s' % (join(BUILDS['PYTHON'], 'pyconfig.h'))
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON']).communicate()
-        cmd = SED_CMD + '"s|.*HAVE_DEV_PTMX.*|#undef HAVE_DEV_PTMX|g" %s' % (join(BUILDS['PYTHON'], 'pyconfig.h'))
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON']).communicate()
+        cmd = SED_CMD + '"s|.*HAVE_OPENPTY.*|#undef HAVE_OPENPTY|g" %s' % (join(target.builds.PYTHON, 'pyconfig.h'))
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON).communicate()
+        cmd = SED_CMD + '"s|.*HAVE__GETPTY.*|#undef HAVE__GETPTY|g" %s' % (join(target.builds.PYTHON, 'pyconfig.h'))
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON).communicate()
+        cmd = SED_CMD + '"s|.*HAVE_DEV_PTMX.*|#undef HAVE_DEV_PTMX|g" %s' % (join(target.builds.PYTHON, 'pyconfig.h'))
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON).communicate()
 
     freeze_modules += ['ntpath', 'locale', 'functools']
-    make_python_freeze(freeze_modules, frozen_file)
-    if isfile(join(DIST_DIR, 'lib', 'libpython2.7.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libpython2.7.a'))
+    make_python_freeze('mingw32', freeze_modules, frozen_file)
+    if isfile(join(target.dist, 'lib', 'libpython2.7.a')):
+        os.remove(join(target.dist, 'lib', 'libpython2.7.a'))
 
     cmd = 'make V=0 install -k -j4 HOSTPYTHON=%s HOSTPGEN=%s CROSS_COMPILE=mingw32msvc CROSS_COMPILE_TARGET=yes'  % (HOSTPYTHON, HOSTPGEN)
-    Popen(shlex.split(cmd), cwd = BUILDS['PYTHON'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.PYTHON, env=env).communicate()
 
     # Check success
-    if isfile(join(DIST_DIR, 'lib', 'libpython2.7.a')):
+    if isfile(join(target.dist, 'lib', 'libpython2.7.a')):
         log('Python built successfully')
     else:
         error('Error building python')

File tools/modules/python/osx.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, make_python_freeze
+from ..log import log, error
+from schafer import prepare_source, make_python_freeze, SED_CMD
 
-def make(env, DIST_DIR, BUILDS, freeze_modules, frozen_file):
-    if not isfile(join(BUILDS['PYTHON'], 'pyconfig.h')) or not isfile(join(BUILDS['PYTHON'], 'Makefile')):
-        cmd = join(DIST_DIR, 'bin', 'sdl2-config' ) + ' --static-libs'
+def make(env, target, freeze_modules, frozen_file):
+    if not isfile(join(target.builds.PYTHON, 'pyconfig.h')) or not isfile(join(target.builds.PYTHON, 'Makefile')):
+        cmd = join(target.dist, 'bin', 'sdl2-config' ) + ' --static-libs'
         sdlldflags = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0] #.replace('-lpthread', '').replace('-ldl', '') # Removing pthread and dl to make them dynamically bound (req'd for Linux)
-        cmd = join(DIST_DIR, 'bin', 'sdl2-config' ) + ' --cflags'
+        cmd = join(target.dist, 'bin', 'sdl2-config' ) + ' --cflags'
         sdlcflags = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
         # As static as possible
-        cmd = './configure --enable-silent-rules --with-universal-archs=intel --enable-universalsdk LDFLAGS="-static-libgcc %s" CPPFLAGS="%s" LINKFORSHARED=" " DYNLOADFILE="dynload_stub.o" --disable-shared --prefix="%s"'% (sdlldflags,sdlcflags,DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['PYTHON']).communicate()
-    make_python_freeze(freeze_modules, frozen_file)
-    if isfile(join(DIST_DIR, 'lib', 'libpython2.7.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libpython2.7.a'))
+        cmd = './configure --enable-silent-rules --with-universal-archs=intel --enable-universalsdk LDFLAGS="-static-libgcc %s" CPPFLAGS="%s" LINKFORSHARED=" " DYNLOADFILE="dynload_stub.o" --disable-shared --prefix="%s"'% (sdlldflags,sdlcflags,target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.PYTHON).communicate()
+    make_python_freeze('osx', freeze_modules, frozen_file)
+    if isfile(join(target.dist, 'lib', 'libpython2.7.a')):
+        os.remove(join(target.dist, 'lib', 'libpython2.7.a'))
 
     # Remove setup.py as its of no use here and it tries to compile a lot of extensions that don't work in static mode
-    if isfile(join(BUILDS['PYTHON'],'setup.py')):
-        os.unlink(join(BUILDS['PYTHON'],'setup.py'))
+    if isfile(join(target.builds.PYTHON,'setup.py')):
+        os.unlink(join(target.builds.PYTHON,'setup.py'))
 
     cmd = 'make V=0 install -k -j4'
     # Rebuild Python including the frozen modules!
-    Popen(shlex.split(cmd), cwd = BUILDS['PYTHON'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.PYTHON, env=env).communicate()
 
     # Check success
-    if isfile(join(DIST_DIR, 'lib', 'libpython2.7.a')):
+    if isfile(join(target.dist, 'lib', 'libpython2.7.a')):
         log('Python built successfully')
     else:
         error('Error building python')

File tools/modules/sdl/android.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, SED_CMD, ROOT_DIR
+from ..log import log, error
+from schafer import SED_CMD, ROOT_DIR, SOURCES
+from ..util import prepare_source
 
-def prepare(DIST_DIR, SOURCES, BUILDS):
-    patch_target = not isdir(BUILDS['SDL']) # Keep count if we are starting from scratch to avoid rebuilding excessively too many files
-    prepare_source('SDL Android Skeleton', join(SOURCES['SDL'], 'android-project'), BUILDS['SDL'])
+def prepare(target):
+    patch_target = not isdir(target.builds.SDL) # Keep count if we are starting from scratch to avoid rebuilding excessively too many files
+    prepare_source('SDL Android Skeleton', join(SOURCES['SDL'], 'android-project'), target.builds.SDL)
     if patch_target:
-        cmd = SED_CMD + """'s|^target=.*|target=android-7|g' %s""" % (join(BUILDS['SDL'], 'default.properties'),)
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL']).communicate()
-        if isdir(join(BUILDS['SDL'], 'jni', 'src')):
-            shutil.rmtree(join(BUILDS['SDL'], 'jni', 'src'))
+        cmd = SED_CMD + """'s|^target=.*|target=android-7|g' %s""" % (join(target.builds.SDL, 'default.properties'),)
+        Popen(shlex.split(cmd), cwd = target.builds.SDL).communicate()
+        if isdir(join(target.builds.SDL, 'jni', 'src')):
+            shutil.rmtree(join(target.builds.SDL, 'jni', 'src'))
 
 
     # Copy SDL and SDL_image to the android project structure
-    prepare_source('SDL', SOURCES['SDL'], join(BUILDS['SDL'], 'jni', 'SDL'))
+    prepare_source('SDL', SOURCES['SDL'], join(target.builds.SDL, 'jni', 'SDL'))
     if patch_target:
-        shutil.copy(join(BUILDS['SDL'], 'jni', 'SDL', 'include', 'SDL_config_android.h'), join(BUILDS['SDL'], 'jni', 'SDL', 'include', 'SDL_config.h'))
-    prepare_source('libpng', SOURCES['PNG'], join(BUILDS['SDL'], 'jni', 'png'))
-    prepare_source('libjpeg', SOURCES['JPG'], join(BUILDS['SDL'], 'jni', 'jpeg'))
-    prepare_source('SDL_image', SOURCES['SDL_IMAGE'], join(BUILDS['SDL'], 'jni', 'SDL_image'))
-    if not isfile(join(BUILDS['SDL'], 'jni', 'SDL_image', 'Android.mk')):
-        shutil.copy(join(ROOT_DIR, 'external', 'Android.mk.SDL_image'), join(BUILDS['SDL'], 'jni', 'SDL_image', 'Android.mk'))
+        shutil.copy(join(target.builds.SDL, 'jni', 'SDL', 'include', 'SDL_config_android.h'), join(target.builds.SDL, 'jni', 'SDL', 'include', 'SDL_config.h'))
+    prepare_source('libpng', SOURCES['PNG'], join(target.builds.SDL, 'jni', 'png'))
+    prepare_source('libjpeg', SOURCES['JPG'], join(target.builds.SDL, 'jni', 'jpeg'))
+    prepare_source('SDL_image', SOURCES['SDL_IMAGE'], join(target.builds.SDL, 'jni', 'SDL_image'))
+    if not isfile(join(target.builds.SDL, 'jni', 'SDL_image', 'Android.mk')):
+        shutil.copy(join(ROOT_DIR, 'external', 'Android.mk.SDL_image'), join(target.builds.SDL, 'jni', 'SDL_image', 'Android.mk'))
 
-    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], join(BUILDS['SDL'], 'jni', 'SDL_ttf'))
-    prepare_source('freetype', SOURCES['FREETYPE'], BUILDS['FREETYPE'])
-    shutil.copy(join(SOURCES['FREETYPE'], 'Makefile'), join(BUILDS['FREETYPE'], 'Makefile') )
+    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], join(target.builds.SDL, 'jni', 'SDL_ttf'))
+    prepare_source('freetype', SOURCES['FREETYPE'], target.builds.FREETYPE)
+    shutil.copy(join(SOURCES['FREETYPE'], 'Makefile'), join(target.builds.FREETYPE, 'Makefile') )
 
-    if not isdir(join(BUILDS['SDL'], 'jni', 'freetype')):
-        os.makedirs(join(BUILDS['SDL'], 'jni', 'freetype'))
-        shutil.copy(join(ROOT_DIR, 'external', 'Android.mk.freetype'), join(BUILDS['SDL'], 'jni', 'freetype', 'Android.mk'))
+    if not isdir(join(target.builds.SDL, 'jni', 'freetype')):
+        os.makedirs(join(target.builds.SDL, 'jni', 'freetype'))
+        shutil.copy(join(ROOT_DIR, 'external', 'Android.mk.freetype'), join(target.builds.SDL, 'jni', 'freetype', 'Android.mk'))
 
-def make(env, DIST_DIR, BUILDS):
+def make(env, target):
     # Build freetype
-    if not isfile(join(BUILDS['FREETYPE'], 'config.mk')):
+    if not isfile(join(target.builds.FREETYPE, 'config.mk')):
         env['CFLAGS'] = env['CFLAGS'] + ' -std=gnu99'
-        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --without-bzip2 --host=arm-eabi --build=i686-pc-linux-gnu --disable-shared --enable-static --with-sysroot=%s/platforms/android-5/arch-arm --prefix="%s"'% (ANDROID_NDK,DIST_DIR)
-        Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
+        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --without-bzip2 --host=arm-eabi --build=i686-pc-linux-gnu --disable-shared --enable-static --with-sysroot=%s/platforms/android-5/arch-arm --prefix="%s"'% (ANDROID_NDK,target.dist)
+        Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
-    if isfile(join(BUILDS['FREETYPE'], 'objs', '.libs', 'libfreetype.a')):
-        cmd = 'rsync -aqut --exclude .svn --exclude .hg %s/ %s' % (join(BUILDS['FREETYPE'], 'include'), join(BUILDS['SDL'], 'jni', 'freetype', 'include'))
+    Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
+    if isfile(join(target.builds.FREETYPE, 'objs', '.libs', 'libfreetype.a')):
+        cmd = 'rsync -aqut --exclude .svn --exclude .hg %s/ %s' % (join(target.builds.FREETYPE, 'include'), join(target.builds.SDL, 'jni', 'freetype', 'include'))
         Popen(shlex.split(cmd)).communicate()
-        shutil.copy(join(BUILDS['FREETYPE'], 'objs', '.libs', 'libfreetype.a'), join(BUILDS['SDL'], 'jni', 'freetype', 'libfreetype.a'))
+        shutil.copy(join(target.builds.FREETYPE, 'objs', '.libs', 'libfreetype.a'), join(target.builds.SDL, 'jni', 'freetype', 'libfreetype.a'))
     else:
         error('Error compiling freetype')
         exit()
 
 
     cmd = 'ndk-build'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.SDL, env=env).communicate()
     # Copy some files to the skeleton directory
-    if isdir(join(DIST_DIR, 'jni', 'SDL', 'include')):
-        shutil.rmtree(join(DIST_DIR, 'jni', 'SDL', 'include'))
-    if isdir(join(DIST_DIR, 'jni', 'SDL', 'src')):
-        shutil.rmtree(join(DIST_DIR, 'jni', 'SDL', 'src'))
+    if isdir(join(target.dist, 'jni', 'SDL', 'include')):
+        shutil.rmtree(join(target.dist, 'jni', 'SDL', 'include'))
+    if isdir(join(target.dist, 'jni', 'SDL', 'src')):
+        shutil.rmtree(join(target.dist, 'jni', 'SDL', 'src'))
 
     try:
-        shutil.copytree(join(BUILDS['SDL'], 'jni', 'SDL', 'include'), join(DIST_DIR, 'jni', 'SDL', 'include'))
-        shutil.copytree(join(BUILDS['SDL'], 'jni', 'SDL', 'src'), join(DIST_DIR, 'jni', 'SDL', 'src'))
-        shutil.copy(join(BUILDS['SDL'], 'libs', 'armeabi', 'libSDL2.so'), join(DIST_DIR, 'jni', 'SDL', 'libSDL2.so'))
-        shutil.copy(join(BUILDS['SDL'], 'libs', 'armeabi', 'libSDL2_image.so'), join(DIST_DIR, 'jni', 'SDL_image', 'libSDL2_image.so'))
-        shutil.copy(join(BUILDS['SDL'], 'libs', 'armeabi', 'libSDL2_ttf.so'), join(DIST_DIR, 'jni', 'SDL_ttf', 'libSDL2_ttf.so'))
-        shutil.copy(join(BUILDS['SDL'], 'jni', 'SDL_image', 'SDL_image.h'), join(DIST_DIR, 'jni', 'SDL_image', 'SDL_image.h'))
-        shutil.copy(join(BUILDS['SDL'], 'jni', 'SDL_ttf', 'SDL_ttf.h'), join(DIST_DIR, 'jni', 'SDL_ttf', 'SDL_ttf.h'))
+        shutil.copytree(join(target.builds.SDL, 'jni', 'SDL', 'include'), join(target.dist, 'jni', 'SDL', 'include'))
+        shutil.copytree(join(target.builds.SDL, 'jni', 'SDL', 'src'), join(target.dist, 'jni', 'SDL', 'src'))
+        shutil.copy(join(target.builds.SDL, 'libs', 'armeabi', 'libSDL2.so'), join(target.dist, 'jni', 'SDL', 'libSDL2.so'))
+        shutil.copy(join(target.builds.SDL, 'libs', 'armeabi', 'libSDL2_image.so'), join(target.dist, 'jni', 'SDL_image', 'libSDL2_image.so'))
+        shutil.copy(join(target.builds.SDL, 'libs', 'armeabi', 'libSDL2_ttf.so'), join(target.dist, 'jni', 'SDL_ttf', 'libSDL2_ttf.so'))
+        shutil.copy(join(target.builds.SDL, 'jni', 'SDL_image', 'SDL_image.h'), join(target.dist, 'jni', 'SDL_image', 'SDL_image.h'))
+        shutil.copy(join(target.builds.SDL, 'jni', 'SDL_ttf', 'SDL_ttf.h'), join(target.dist, 'jni', 'SDL_ttf', 'SDL_ttf.h'))
         log('SDL built successfully')
     except:
         error('Error while building SDL for target')

File tools/modules/sdl/linux64.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source
+from ..log import log, error
+from schafer import SOURCES, SED_CMD
+from ..util import prepare_source
 
-def prepare(DIST_DIR, SOURCES, BUILDS):
-    prepare_source('SDL', SOURCES['SDL'], BUILDS['SDL'])
-    prepare_source('SDL_image', SOURCES['SDL_IMAGE'], BUILDS['SDL_IMAGE'])
-    prepare_source('zlib', SOURCES['ZLIB'], BUILDS['ZLIB'])
-    prepare_source('libpng', SOURCES['PNG'], BUILDS['PNG'])
-    shutil.copy(join(BUILDS['PNG'], 'scripts', 'makefile.linux'), join(BUILDS['PNG'], 'Makefile'))
-    prepare_source('libjpeg', SOURCES['JPG'], BUILDS['JPG'])
-    prepare_source('freetype', SOURCES['FREETYPE'], BUILDS['FREETYPE'])
-    shutil.copy(join(SOURCES['FREETYPE'], 'Makefile'), join(BUILDS['FREETYPE'], 'Makefile') )
-    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], BUILDS['SDL_TTF'])
+def prepare(target):
+    prepare_source('SDL', SOURCES['SDL'], target.builds.SDL)
+    prepare_source('SDL_image', SOURCES['SDL_IMAGE'], target.builds.SDL_IMAGE)
+    prepare_source('zlib', SOURCES['ZLIB'], target.builds.ZLIB)
+    prepare_source('libpng', SOURCES['PNG'], target.builds.PNG)
+    shutil.copy(join(target.builds.PNG, 'scripts', 'makefile.linux'), join(target.builds.PNG, 'Makefile'))
+    prepare_source('libjpeg', SOURCES['JPG'], target.builds.JPG)
+    prepare_source('freetype', SOURCES['FREETYPE'], target.builds.FREETYPE)
+    shutil.copy(join(SOURCES['FREETYPE'], 'Makefile'), join(target.builds.FREETYPE, 'Makefile') )
+    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], target.builds.SDL_TTF)
 
 
-def make(env, DIST_DIR, BUILDS):
+def make(env, target):
     # Build zlib
-    if isfile(join(DIST_DIR, 'lib', 'libz.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libz.a'))
-    if not isfile(join(BUILDS['ZLIB'], 'Makefile')):
-        cmd = './configure --static --prefix="%s"'% (DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['ZLIB'], env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libz.a')):
+        os.remove(join(target.dist, 'lib', 'libz.a'))
+    if not isfile(join(target.builds.ZLIB, 'Makefile')):
+        cmd = './configure --static --prefix="%s"'% (target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.ZLIB, env=env).communicate()
     cmd = 'make'
-    Popen(shlex.split(cmd), cwd = BUILDS['ZLIB'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.ZLIB, env=env).communicate()
     cmd = 'make install'
-    Popen(shlex.split(cmd), cwd = BUILDS['ZLIB'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libz.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.ZLIB, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libz.a')):
         log('zlib built successfully')
     else:
         error('Problem building zlib')
         exit()
 
     # Build libpng
-    if isfile(join(DIST_DIR, 'lib', 'libpng.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libpng.a'))
+    if isfile(join(target.dist, 'lib', 'libpng.a')):
+        os.remove(join(target.dist, 'lib', 'libpng.a'))
 
-    cmd = 'make V=0 prefix="%s"' % (DIST_DIR,)
-    Popen(shlex.split(cmd), cwd = BUILDS['PNG'], env=env).communicate()
-    cmd = 'make V=0 install prefix="%s"' % (DIST_DIR,)
-    Popen(shlex.split(cmd), cwd = BUILDS['PNG'], env=env).communicate()
+    cmd = 'make V=0 prefix="%s"' % (target.dist,)
+    Popen(shlex.split(cmd), cwd = target.builds.PNG, env=env).communicate()
+    cmd = 'make V=0 install prefix="%s"' % (target.dist,)
+    Popen(shlex.split(cmd), cwd = target.builds.PNG, env=env).communicate()
     # Remove dynamic libraries to avoid confusions with the linker
-    cmd = 'find %s -name "*.so*" -delete' % join(DIST_DIR, 'lib')
-    Popen(shlex.split(cmd), cwd = join(DIST_DIR, 'lib'), env=env).communicate()
+    cmd = 'find %s -name "*.so*" -delete' % join(target.dist, 'lib')
+    Popen(shlex.split(cmd), cwd = join(target.dist, 'lib'), env=env).communicate()
 
     # Build libjpeg
-    if isfile(join(DIST_DIR, 'lib', 'libjpeg.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libjpeg.a'))
+    if isfile(join(target.dist, 'lib', 'libjpeg.a')):
+        os.remove(join(target.dist, 'lib', 'libjpeg.a'))
 
-    if not isfile(join(BUILDS['JPG'], 'Makefile')):
-        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" LIBTOOL= --disable-shared --enable-static --prefix="%s"'% (DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    if not isfile(join(target.builds.JPG, 'Makefile')):
+        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" LIBTOOL= --disable-shared --enable-static --prefix="%s"'% (target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
         # Fixes for the Makefile
-        cmd = SED_CMD + '"s|\./libtool||g" %s' % (join(BUILDS['JPG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
-        cmd = SED_CMD + '"s|^O = lo|O = o|g" %s' % (join(BUILDS['JPG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
-        cmd = SED_CMD + '"s|^A = la|A = a|g" %s' % (join(BUILDS['JPG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+        cmd = SED_CMD + '"s|\./libtool||g" %s' % (join(target.builds.JPG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
+        cmd = SED_CMD + '"s|^O = lo|O = o|g" %s' % (join(target.builds.JPG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
+        cmd = SED_CMD + '"s|^A = la|A = a|g" %s' % (join(target.builds.JPG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
 
     cmd = 'make V=0 '
-    Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
     cmd = 'make V=0 install-lib'
-    Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
     cmd = 'make V=0 install-headers'
-    Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
 
-    if isfile(join(DIST_DIR, 'lib', 'libjpeg.a')):
+    if isfile(join(target.dist, 'lib', 'libjpeg.a')):
         log('libjpeg built successfully')
     else:
         error('Problem building libjpeg')
         exit()
 
     # Build SDL
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2.a'))
 
-    if not isfile(join(BUILDS['SDL'], 'Makefile')):
-        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --disable-shared --enable-static --prefix="%s"'% (DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL'], env=env).communicate()
+    if not isfile(join(target.builds.SDL, 'Makefile')):
+        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --disable-shared --enable-static --prefix="%s"'% (target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.SDL, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.SDL, env=env).communicate()
     cmd = 'make V=0 install'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.SDL, env=env).communicate()
 
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2.a')):
         log('SDL built successfully')
     else:
         error('Problem building SDL')
         exit()
 
     # Build SDL_Image
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_image.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_image.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2_image.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_image.a'))
 
-    if not isfile(join(BUILDS['SDL_IMAGE'], 'Makefile')):
-        cmd = join(DIST_DIR, 'bin', 'libpng-config' ) + ' --static --cflags'
+    if not isfile(join(target.builds.SDL_IMAGE, 'Makefile')):
+        cmd = join(target.dist, 'bin', 'libpng-config' ) + ' --static --cflags'
         pngcf = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
-        cmd = join(DIST_DIR, 'bin', 'libpng-config' ) + ' --static --ldflags'
+        cmd = join(target.dist, 'bin', 'libpng-config' ) + ' --static --ldflags'
         pngld = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
-        cmd = './configure --enable-silent-rules CFLAGS="%s" LDFLAGS="-static-libgcc" LIBPNG_CFLAGS="%s" LIBPNG_LIBS="%s -ljpeg" --disable-png-shared --disable-jpg-shared --disable-shared --enable-static --with-sdl-prefix="%s" --prefix="%s"'% (env['CFLAGS'], pngcf, pngld, DIST_DIR, DIST_DIR)
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL_IMAGE'], env=env).communicate()
+        cmd = './configure --enable-silent-rules CFLAGS="%s" LDFLAGS="-static-libgcc" LIBPNG_CFLAGS="%s" LIBPNG_LIBS="%s -ljpeg" --disable-png-shared --disable-jpg-shared --disable-shared --enable-static --with-sdl-prefix="%s" --prefix="%s"'% (env['CFLAGS'], pngcf, pngld, target.dist, target.dist)
+        Popen(shlex.split(cmd), cwd = target.builds.SDL_IMAGE, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL_IMAGE'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.SDL_IMAGE, env=env).communicate()
     cmd = 'make V=0 install'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL_IMAGE'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_image.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.SDL_IMAGE, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libSDL2_image.a')):
         log('SDL Image built successfully')
     else:
         error('Problem building SDL Image')
         exit()
 
     # Build freetype
-    if isfile(join(DIST_DIR, 'lib', 'libfreetype.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libfreetype.a'))
+    if isfile(join(target.dist, 'lib', 'libfreetype.a')):
+        os.remove(join(target.dist, 'lib', 'libfreetype.a'))
 
-    if not isfile(join(BUILDS['FREETYPE'], 'config.mk')):
-        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --without-bzip2 --disable-shared --enable-static --with-sysroot=%s --prefix="%s"'% (DIST_DIR,DIST_DIR)
-        Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
+    if not isfile(join(target.builds.FREETYPE, 'config.mk')):
+        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --without-bzip2 --disable-shared --enable-static --with-sysroot=%s --prefix="%s"'% (target.dist,target.dist)
+        Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
     cmd = 'make V=0 install'
-    Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libfreetype.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libfreetype.a')):
         log('Freetype built successfully')
     else:
         error('Problem building Freetype')
         exit()
 
     # Build SDL_ttf
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_ttf.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_ttf.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2_ttf.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_ttf.a'))
 
-    if not isfile(join(BUILDS['SDL_TTF'], 'configure')):
+    if not isfile(join(target.builds.SDL_TTF, 'configure')):
         cmd = './autogen.sh'
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
+        Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
 
-    if not isfile(join(BUILDS['SDL_TTF'], 'Makefile')):
-        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --disable-shared --enable-static --with-sdl-prefix="%s" --with-freetype-prefix="%s" --prefix="%s"'% (DIST_DIR, DIST_DIR, DIST_DIR)
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
+    if not isfile(join(target.builds.SDL_TTF, 'Makefile')):
+        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --disable-shared --enable-static --with-sdl-prefix="%s" --with-freetype-prefix="%s" --prefix="%s"'% (target.dist, target.dist, target.dist)
+        Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
     cmd = 'make V=0 install'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_ttf.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libSDL2_ttf.a')):
         log('SDL TTF built successfully')
     else:
         error('Problem building SDL TTF')

File tools/modules/sdl/mingw32.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, ROOT_DIR
+from ..log import log, error
+from schafer import prepare_source, ROOT_DIR, SOURCES
 
-def prepare(DIST_DIR, SOURCES, BUILDS):
-    prepare_source('SDL', SOURCES['SDL'], BUILDS['SDL'])
-    prepare_source('SDL_image', SOURCES['SDL_IMAGE'], BUILDS['SDL_IMAGE'])
-    prepare_source('zlib', SOURCES['ZLIB'], BUILDS['ZLIB'])
-    prepare_source('libpng', SOURCES['PNG'], BUILDS['PNG'])
-    prepare_source('libjpeg', SOURCES['JPG'], BUILDS['JPG'])
-    prepare_source('freetype', SOURCES['FREETYPE'], BUILDS['FREETYPE'])
-    shutil.copy(join(SOURCES['FREETYPE'], 'Makefile'), join(BUILDS['FREETYPE'], 'Makefile') )
-    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], BUILDS['SDL_TTF'])
+def prepare(target):
+    prepare_source('SDL', SOURCES['SDL'], target.builds.SDL)
+    prepare_source('SDL_image', SOURCES['SDL_IMAGE'], target.builds.SDL_IMAGE)
+    prepare_source('zlib', SOURCES['ZLIB'], target.builds.ZLIB)
+    prepare_source('libpng', SOURCES['PNG'], target.builds.PNG)
+    prepare_source('libjpeg', SOURCES['JPG'], target.builds.JPG)
+    prepare_source('freetype', SOURCES['FREETYPE'], target.builds.FREETYPE)
+    shutil.copy(join(SOURCES['FREETYPE'], 'Makefile'), join(target.builds.FREETYPE, 'Makefile') )
+    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], target.builds.SDL_TTF)
 
-    shutil.copy(join(ROOT_DIR, 'external', 'Makefile.in.zlib'), join(BUILDS['ZLIB'], 'Makefile.in'))
-    shutil.copy(join(ROOT_DIR, 'external', 'Makefile.libpng.mingw32'), join(BUILDS['PNG'], 'Makefile'))
+    shutil.copy(join(ROOT_DIR, 'external', 'Makefile.in.zlib'), join(target.builds.ZLIB, 'Makefile.in'))
+    shutil.copy(join(ROOT_DIR, 'external', 'Makefile.libpng.mingw32'), join(target.builds.PNG, 'Makefile'))
 
-def make(env, DIST_DIR, BUILDS):
+def make(env, target):
     # Build zlib
-    if isfile(join(DIST_DIR, 'lib', 'libz.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libz.a'))
-    if not isfile(join(BUILDS['ZLIB'], 'Makefile')):
-        cmd = './configure --static --prefix="%s"'% (DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['ZLIB'], env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libz.a')):
+        os.remove(join(target.dist, 'lib', 'libz.a'))
+    if not isfile(join(target.builds.ZLIB, 'Makefile')):
+        cmd = './configure --static --prefix="%s"'% (target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.ZLIB, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['ZLIB'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.ZLIB, env=env).communicate()
     cmd = 'make V=0 install'
-    Popen(shlex.split(cmd), cwd = BUILDS['ZLIB'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libz.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.ZLIB, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libz.a')):
         log('zlib built successfully')
     else:
         error('Problem building zlib')
         exit()
 
     # Build libpng
-    if isfile(join(DIST_DIR, 'lib', 'libpng.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libpng.a'))
-    cmd = 'make V=0 prefix="%s"' % (DIST_DIR,)
-    Popen(shlex.split(cmd), cwd = BUILDS['PNG'], env=env).communicate()
-    cmd = 'make V=0 install prefix="%s"' % (DIST_DIR,)
-    Popen(shlex.split(cmd), cwd = BUILDS['PNG'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libpng.a')):
+    if isfile(join(target.dist, 'lib', 'libpng.a')):
+        os.remove(join(target.dist, 'lib', 'libpng.a'))
+    cmd = 'make V=0 prefix="%s"' % (target.dist,)
+    Popen(shlex.split(cmd), cwd = target.builds.PNG, env=env).communicate()
+    cmd = 'make V=0 install prefix="%s"' % (target.dist,)
+    Popen(shlex.split(cmd), cwd = target.builds.PNG, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libpng.a')):
         log('libpng built successfully')
     else:
         error('Problem building libpng')
         exit()
 
     # Build libjpeg
-    if isfile(join(DIST_DIR, 'lib', 'libjpeg.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libjpeg.a'))
+    if isfile(join(target.dist, 'lib', 'libjpeg.a')):
+        os.remove(join(target.dist, 'lib', 'libjpeg.a'))
 
-    if not isfile(join(BUILDS['JPG'], 'Makefile')):
-        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" LIBTOOL= --host=i586-mingw32msvc --disable-shared --enable-static --prefix="%s"'% (DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    if not isfile(join(target.builds.JPG, 'Makefile')):
+        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" LIBTOOL= --host=i586-mingw32msvc --disable-shared --enable-static --prefix="%s"'% (target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
         # Fixes for the Makefile
-        cmd = SED_CMD + '"s|\./libtool||g" %s' % (join(BUILDS['JPG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
-        cmd = SED_CMD + '"s|^O = lo|O = o|g" %s' % (join(BUILDS['JPG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
-        cmd = SED_CMD + '"s|^A = la|A = a|g" %s' % (join(BUILDS['JPG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+        cmd = SED_CMD + '"s|\./libtool||g" %s' % (join(target.builds.JPG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
+        cmd = SED_CMD + '"s|^O = lo|O = o|g" %s' % (join(target.builds.JPG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
+        cmd = SED_CMD + '"s|^A = la|A = a|g" %s' % (join(target.builds.JPG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
 
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
     cmd = 'make V=0 install-lib'
-    Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
     cmd = 'make V=0 install-headers'
-    Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libjpeg.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libjpeg.a')):
         log('libjpeg built successfully')
     else:
         error('Problem building libjpeg')
         exit()
 
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2.a'))
-    if not isfile(join(BUILDS['SDL'], 'Makefile')):
-        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --disable-stdio-redirect --host=i586-mingw32msvc --disable-shared --enable-static --prefix="%s"'% (DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL'], env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libSDL2.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2.a'))
+    if not isfile(join(target.builds.SDL, 'Makefile')):
+        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --disable-stdio-redirect --host=i586-mingw32msvc --disable-shared --enable-static --prefix="%s"'% (target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.SDL, env=env).communicate()
 
         # HACK FIX for SDL problem, this can be removed once SDL fixes this error
-    #            cmd = 'sed -i "s|#define SDL_AUDIO_DRIVER_XAUDIO2.*||g" %s' % (join(BUILDS['SDL'], 'include', 'SDL_config_windows.h'),)
-    #            Popen(shlex.split(cmd), cwd = BUILDS['SDL'], env=env).communicate()
-    #            cmd = 'sed -i "s|#define SDL_AUDIO_DRIVER_DSOUND.*||g" %s' % (join(BUILDS['SDL'], 'include', 'SDL_config_windows.h'),)
-    #            Popen(shlex.split(cmd), cwd = BUILDS['SDL'], env=env).communicate()
+    #            cmd = 'sed -i "s|#define SDL_AUDIO_DRIVER_XAUDIO2.*||g" %s' % (join(target.builds.SDL, 'include', 'SDL_config_windows.h'),)
+    #            Popen(shlex.split(cmd), cwd = target.builds.SDL, env=env).communicate()
+    #            cmd = 'sed -i "s|#define SDL_AUDIO_DRIVER_DSOUND.*||g" %s' % (join(target.builds.SDL, 'include', 'SDL_config_windows.h'),)
+    #            Popen(shlex.split(cmd), cwd = target.builds.SDL, env=env).communicate()
 
 
 
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.SDL, env=env).communicate()
     cmd = 'make V=0 install'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.SDL, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libSDL2.a')):
         log('SDL built successfully')
     else:
         error('Problem building SDL')
         exit()
 
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_image.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_image.a'))
-    if not isfile(join(BUILDS['SDL_IMAGE'], 'Makefile')):
-        cmd = './configure --enable-silent-rules LIBPNG_CFLAGS="-L%s -lpng12 -lz -lm -I%s" LDFLAGS="-static-libgcc" --host=i586-mingw32msvc --disable-shared --enable-static --with-sdl-prefix="%s" --prefix="%s"'% (join(DIST_DIR, 'lib'), join(DIST_DIR, 'include'), DIST_DIR, DIST_DIR)
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL_IMAGE'], env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libSDL2_image.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_image.a'))
+    if not isfile(join(target.builds.SDL_IMAGE, 'Makefile')):
+        cmd = './configure --enable-silent-rules LIBPNG_CFLAGS="-L%s -lpng12 -lz -lm -I%s" LDFLAGS="-static-libgcc" --host=i586-mingw32msvc --disable-shared --enable-static --with-sdl-prefix="%s" --prefix="%s"'% (join(target.dist, 'lib'), join(target.dist, 'include'), target.dist, target.dist)
+        Popen(shlex.split(cmd), cwd = target.builds.SDL_IMAGE, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL_IMAGE'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.SDL_IMAGE, env=env).communicate()
     cmd = 'make V=0 install'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL_IMAGE'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_image.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.SDL_IMAGE, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libSDL2_image.a')):
         log('SDL Image built successfully')
     else:
         error('Problem building SDL Image')
         exit()
 
         # Build freetype
-    if isfile(join(DIST_DIR, 'lib', 'libfreetype.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libfreetype.a'))
-    if not isfile(join(BUILDS['FREETYPE'], 'config.mk')):
+    if isfile(join(target.dist, 'lib', 'libfreetype.a')):
+        os.remove(join(target.dist, 'lib', 'libfreetype.a'))
+    if not isfile(join(target.builds.FREETYPE, 'config.mk')):
         env['CFLAGS'] = env['CFLAGS'] + ' -std=gnu99'
-        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --without-bzip2  --build=i686-pc-linux-gnu --host=i586-mingw32msvc --disable-shared --enable-static --prefix="%s"'% (DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
+        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --without-bzip2  --build=i686-pc-linux-gnu --host=i586-mingw32msvc --disable-shared --enable-static --prefix="%s"'% (target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
     cmd = 'make V=0 install'
-    Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libfreetype.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libfreetype.a')):
         log('Freetype built successfully')
     else:
         error('Problem building Freetype')
         exit()
 
     # Build SDL_ttf
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_ttf.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_ttf.a'))
-    if not isfile(join(BUILDS['SDL_TTF'], 'configure')):
+    if isfile(join(target.dist, 'lib', 'libSDL2_ttf.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_ttf.a'))
+    if not isfile(join(target.builds.SDL_TTF, 'configure')):
         cmd = './autogen.sh'
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
+        Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
 
-    if not isfile(join(BUILDS['SDL_TTF'], 'Makefile')):
-        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --disable-shared --enable-static --disable-sdltest --host=i586-mingw32msvc --with-sdl-prefix="%s" --with-freetype-prefix="%s" --prefix="%s"'% (DIST_DIR, DIST_DIR, DIST_DIR)
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
+    if not isfile(join(target.builds.SDL_TTF, 'Makefile')):
+        cmd = './configure --enable-silent-rules LDFLAGS="-static-libgcc" --disable-shared --enable-static --disable-sdltest --host=i586-mingw32msvc --with-sdl-prefix="%s" --with-freetype-prefix="%s" --prefix="%s"'% (target.dist, target.dist, target.dist)
+        Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
     cmd = 'make V=0 install-libSDL2_ttfincludeHEADERS'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
     cmd = 'make V=0 install-libLTLIBRARIES'
-    Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_ttf.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libSDL2_ttf.a')):
         log('SDL TTF built successfully')
     else:
         error('Problem building SDL TTF')

File tools/modules/sdl/osx.py

 import os, shlex, shutil
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import log, error, prepare_source, SED_CMD
+from ..log import log, error
+from schafer import prepare_source, SED_CMD, SOURCES
 from ..env import prepare_osx_env
 
-def prepare(DIST_DIR, SOURCES, BUILDS):
-    prepare_source('SDL', SOURCES['SDL'], BUILDS['SDL']+'_i386')
-    prepare_source('SDL', SOURCES['SDL'], BUILDS['SDL']+'_x86_64')
-    prepare_source('SDL_image', SOURCES['SDL_IMAGE'], BUILDS['SDL_IMAGE']+'_i386')
-    prepare_source('SDL_image', SOURCES['SDL_IMAGE'], BUILDS['SDL_IMAGE']+'_x86_64')
-    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], BUILDS['SDL_TTF']+'_i386')
-    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], BUILDS['SDL_TTF']+'_x86_64')
-    prepare_source('zlib', SOURCES['ZLIB'], BUILDS['ZLIB'])
-    prepare_source('libpng', SOURCES['PNG'], BUILDS['PNG'])
-    if not isfile(join(BUILDS['PNG'], 'Makefile')):
-        shutil.copy(join(BUILDS['PNG'], 'scripts', 'makefile.darwin'), join(BUILDS['PNG'], 'Makefile'))
+def prepare(target):
+    prepare_source('SDL', SOURCES['SDL'], target.builds.SDL+'_i386')
+    prepare_source('SDL', SOURCES['SDL'], target.builds.SDL+'_x86_64')
+    prepare_source('SDL_image', SOURCES['SDL_IMAGE'], target.builds.SDL_IMAGE+'_i386')
+    prepare_source('SDL_image', SOURCES['SDL_IMAGE'], target.builds.SDL_IMAGE+'_x86_64')
+    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], target.builds.SDL_TTF+'_i386')
+    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], target.builds.SDL_TTF+'_x86_64')
+    prepare_source('zlib', SOURCES['ZLIB'], target.builds.ZLIB)
+    prepare_source('libpng', SOURCES['PNG'], target.builds.PNG)
+    if not isfile(join(target.builds.PNG, 'Makefile')):
+        shutil.copy(join(target.builds.PNG, 'scripts', 'makefile.darwin'), join(target.builds.PNG, 'Makefile'))
         # Force libpng to build universally
         env = prepare_osx_env()
-        cmd = SED_CMD + '-e "s|CFLAGS=|CFLAGS= %s -arch i386 -arch x86_64 |g" %s' % (env['CFLAGS'] if 'CFLAGS' in env else '', join(BUILDS['PNG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['PNG']).communicate()
-        cmd = SED_CMD + '-e "s|LDFLAGS=|LDFLAGS= %s -arch i386 -arch x86_64 |g" %s' % (env['LDFLAGS'] if 'LDFLAGS' in env else '', join(BUILDS['PNG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['PNG']).communicate()
-        cmd = SED_CMD + '-e "s|-dynamiclib|-dynamiclib -arch i386 -arch x86_64 |g" %s' % join(BUILDS['PNG'], 'Makefile')
-        Popen(shlex.split(cmd), cwd = BUILDS['PNG']).communicate()
-        cmd = SED_CMD + '-e "s|prefix=.*|prefix=%s|g" %s' % (join(BUILDS['PNG'], 'Makefile'), DIST_DIR)
-        Popen(shlex.split(cmd), cwd = BUILDS['PNG']).communicate()
-    prepare_source('libjpeg', SOURCES['JPG'], BUILDS['JPG'])
-    prepare_source('freetype', SOURCES['FREETYPE'], BUILDS['FREETYPE'])
-    shutil.copy(join(SOURCES['FREETYPE'], 'Makefile'), join(BUILDS['FREETYPE'], 'Makefile') )
-    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], BUILDS['SDL_TTF'])
+        cmd = SED_CMD + '-e "s|CFLAGS=|CFLAGS= %s -arch i386 -arch x86_64 |g" %s' % (env['CFLAGS'] if 'CFLAGS' in env else '', join(target.builds.PNG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.PNG).communicate()
+        cmd = SED_CMD + '-e "s|LDFLAGS=|LDFLAGS= %s -arch i386 -arch x86_64 |g" %s' % (env['LDFLAGS'] if 'LDFLAGS' in env else '', join(target.builds.PNG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.PNG).communicate()
+        cmd = SED_CMD + '-e "s|-dynamiclib|-dynamiclib -arch i386 -arch x86_64 |g" %s' % join(target.builds.PNG, 'Makefile')
+        Popen(shlex.split(cmd), cwd = target.builds.PNG).communicate()
+        cmd = SED_CMD + '-e "s|prefix=.*|prefix=%s|g" %s' % (join(target.builds.PNG, 'Makefile'), target.dist)
+        Popen(shlex.split(cmd), cwd = target.builds.PNG).communicate()
+    prepare_source('libjpeg', SOURCES['JPG'], target.builds.JPG)
+    prepare_source('freetype', SOURCES['FREETYPE'], target.builds.FREETYPE)
+    shutil.copy(join(SOURCES['FREETYPE'], 'Makefile'), join(target.builds.FREETYPE, 'Makefile') )
+    prepare_source('SDL_ttf', SOURCES['SDL_TTF'], target.builds.SDL_TTF)
 
-def make(env, DIST_DIR, BUILDS):
+def make(env, target):
     universal_cflags = '-arch i386 -arch x86_64'
     # Build all libraries in universal mode (i386 and x86_64)
     # Build zlib
-    if isfile(join(DIST_DIR, 'lib', 'libz.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libz.a'))
-    if not isfile(join(BUILDS['ZLIB'], 'Makefile')):
-        cmd = './configure --static --prefix="%s"'% (DIST_DIR,)
-        Popen(shlex.split(cmd), cwd = BUILDS['ZLIB'], env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libz.a')):
+        os.remove(join(target.dist, 'lib', 'libz.a'))
+    if not isfile(join(target.builds.ZLIB, 'Makefile')):
+        cmd = './configure --static --prefix="%s"'% (target.dist,)
+        Popen(shlex.split(cmd), cwd = target.builds.ZLIB, env=env).communicate()
         # Force zlib to build universally
-        cmd = SED_CMD + '-e "s|CFLAGS=|CFLAGS=%s %s |g" %s' % (universal_cflags, env['CFLAGS'], (join(BUILDS['ZLIB'], 'Makefile')))
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+        cmd = SED_CMD + '-e "s|CFLAGS=|CFLAGS=%s %s |g" %s' % (universal_cflags, env['CFLAGS'], (join(target.builds.ZLIB, 'Makefile')))
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['ZLIB'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.ZLIB, env=env).communicate()
     cmd = 'make V=0 install'
-    Popen(shlex.split(cmd), cwd = BUILDS['ZLIB'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libz.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.ZLIB, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libz.a')):
         log('zlib built successfully')
     else:
         error('Problem building zlib')
         exit()
 
     # Build libpng
-    if isfile(join(DIST_DIR, 'lib', 'libpng.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libpng.a'))
+    if isfile(join(target.dist, 'lib', 'libpng.a')):
+        os.remove(join(target.dist, 'lib', 'libpng.a'))
 
-    cmd = 'make V=0 prefix="%s"' % (DIST_DIR,)
-    Popen(shlex.split(cmd), cwd = BUILDS['PNG'], env=env).communicate()
-    cmd = 'make V=0 install prefix="%s"' % (DIST_DIR,)
-    Popen(shlex.split(cmd), cwd = BUILDS['PNG'], env=env).communicate()
+    cmd = 'make V=0 prefix="%s"' % (target.dist,)
+    Popen(shlex.split(cmd), cwd = target.builds.PNG, env=env).communicate()
+    cmd = 'make V=0 install prefix="%s"' % (target.dist,)
+    Popen(shlex.split(cmd), cwd = target.builds.PNG, env=env).communicate()
     # Remove dynamic libraries to avoid confusions with the linker
     cmd = 'rm *.dylib'
-    Popen(shlex.split(cmd), cwd = join(DIST_DIR, 'lib')).communicate()
+    Popen(shlex.split(cmd), cwd = join(target.dist, 'lib')).communicate()
 
     # Build libjpeg
-    if isfile(join(DIST_DIR, 'lib', 'libjpeg.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libjpeg.a'))
+    if isfile(join(target.dist, 'lib', 'libjpeg.a')):
+        os.remove(join(target.dist, 'lib', 'libjpeg.a'))
 
-    if not isfile(join(BUILDS['JPG'], 'Makefile')):
-        cmd = './configure --enable-silent-rules CFLAGS="%s %s" LDFLAGS="-static-libgcc" LIBTOOL= --disable-shared --enable-static --prefix="%s"' % (universal_cflags, env['CFLAGS'], DIST_DIR)
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    if not isfile(join(target.builds.JPG, 'Makefile')):
+        cmd = './configure --enable-silent-rules CFLAGS="%s %s" LDFLAGS="-static-libgcc" LIBTOOL= --disable-shared --enable-static --prefix="%s"' % (universal_cflags, env['CFLAGS'], target.dist)
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
         # Fixes for the Makefile
-        cmd = SED_CMD + '-e "s|\./libtool||g" %s' % (join(BUILDS['JPG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
-        cmd = SED_CMD + '-e "s|^O = lo|O = o|g" %s' % (join(BUILDS['JPG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
-        cmd = SED_CMD + '-e "s|^A = la|A = a|g" %s' % (join(BUILDS['JPG'], 'Makefile'))
-        Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+        cmd = SED_CMD + '-e "s|\./libtool||g" %s' % (join(target.builds.JPG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
+        cmd = SED_CMD + '-e "s|^O = lo|O = o|g" %s' % (join(target.builds.JPG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
+        cmd = SED_CMD + '-e "s|^A = la|A = a|g" %s' % (join(target.builds.JPG, 'Makefile'))
+        Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
 
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
     cmd = 'make V=0 install-lib'
-    Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
     cmd = 'make V=0 install-headers'
-    Popen(shlex.split(cmd), cwd = BUILDS['JPG'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.JPG, env=env).communicate()
 
-    if isfile(join(DIST_DIR, 'lib', 'libjpeg.a')):
+    if isfile(join(target.dist, 'lib', 'libjpeg.a')):
         log('libjpeg built successfully')
     else:
         error('Problem building libjpeg')
         exit()
 
     # Build freetype
-    if isfile(join(DIST_DIR, 'lib', 'libfreetype.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libfreetype.a'))
+    if isfile(join(target.dist, 'lib', 'libfreetype.a')):
+        os.remove(join(target.dist, 'lib', 'libfreetype.a'))
 
-    if not isfile(join(BUILDS['FREETYPE'], 'config.mk')):
-        cmd = './configure --enable-silent-rules CFLAGS="%s %s" LDFLAGS="-static-libgcc" --without-bzip2 --disable-shared --enable-static --with-sysroot=%s --prefix="%s"'% (universal_cflags, env['CFLAGS'],DIST_DIR,DIST_DIR)
-        Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
+    if not isfile(join(target.builds.FREETYPE, 'config.mk')):
+        cmd = './configure --enable-silent-rules CFLAGS="%s %s" LDFLAGS="-static-libgcc" --without-bzip2 --disable-shared --enable-static --with-sysroot=%s --prefix="%s"'% (universal_cflags, env['CFLAGS'],target.dist,target.dist)
+        Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
     cmd = 'make V=0'
-    Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
+    Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
     cmd = 'make V=0 install'
-    Popen(shlex.split(cmd), cwd = BUILDS['FREETYPE'], env=env).communicate()
-    if isfile(join(DIST_DIR, 'lib', 'libfreetype.a')):
+    Popen(shlex.split(cmd), cwd = target.builds.FREETYPE, env=env).communicate()
+    if isfile(join(target.dist, 'lib', 'libfreetype.a')):
         log('Freetype built successfully')
     else:
         error('Problem building Freetype')
 
     # Build SDL, SDL Image, SDL TTF
     # SDL can not be built with multiple -arch flags, so we build it twice and then lipo the results
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2.a'))
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_i386.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_i386.a'))
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_x86_64.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_x86_64.a'))
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_image.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_image.a'))
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_image_i386.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_image_i386.a'))
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_image_x86_64.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_image_x86_64.a'))
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_ttf.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_ttf.a'))
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_ttf_i386.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_ttf_i386.a'))
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_ttf_x86_64.a')):
-        os.remove(join(DIST_DIR, 'lib', 'libSDL2_ttf_x86_64.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2_i386.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_i386.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2_x86_64.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_x86_64.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2_image.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_image.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2_image_i386.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_image_i386.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2_image_x86_64.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_image_x86_64.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2_ttf.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_ttf.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2_ttf_i386.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_ttf_i386.a'))
+    if isfile(join(target.dist, 'lib', 'libSDL2_ttf_x86_64.a')):
+        os.remove(join(target.dist, 'lib', 'libSDL2_ttf_x86_64.a'))
 
-    sdl_build_i386 = BUILDS['SDL']+'_i386'
-    sdl_build_x86_64 = BUILDS['SDL']+'_x86_64'
-    sdl_image_build_i386 = BUILDS['SDL_IMAGE']+'_i386'
-    sdl_image_build_x86_64 = BUILDS['SDL_IMAGE']+'_x86_64'
-    sdl_ttf_build_i386 = BUILDS['SDL_TTF']+'_i386'
-    sdl_ttf_build_x86_64 = BUILDS['SDL_TTF']+'_x86_64'
+    sdl_build_i386 = target.builds.SDL+'_i386'
+    sdl_build_x86_64 = target.builds.SDL+'_x86_64'
+    sdl_image_build_i386 = target.builds.SDL_IMAGE+'_i386'
+    sdl_image_build_x86_64 = target.builds.SDL_IMAGE+'_x86_64'
+    sdl_ttf_build_i386 = target.builds.SDL_TTF+'_i386'
+    sdl_ttf_build_x86_64 = target.builds.SDL_TTF+'_x86_64'
 
     # i386 builds
     if not isfile(join(sdl_build_i386, 'Makefile')):
-        cmd = './configure --enable-silent-rules CFLAGS="%s -m32" LDFLAGS="-m32 -static-libgcc" --disable-shared --enable-static --prefix="%s"'% (env['CFLAGS'], DIST_DIR)
+        cmd = './configure --enable-silent-rules CFLAGS="%s -m32" LDFLAGS="-m32 -static-libgcc" --disable-shared --enable-static --prefix="%s"'% (env['CFLAGS'], target.dist)
         Popen(shlex.split(cmd), cwd = sdl_build_i386, env=env).communicate()
     cmd = 'make V=0 '
     Popen(shlex.split(cmd), cwd = sdl_build_i386, env=env).communicate()
     Popen(shlex.split(cmd), cwd = sdl_build_i386, env=env).communicate()
 
     if not isfile(join(sdl_image_build_i386, 'Makefile')):
-        cmd = join(DIST_DIR, 'bin', 'libpng-config' ) + ' --static --cflags'
+        cmd = join(target.dist, 'bin', 'libpng-config' ) + ' --static --cflags'
         pngcf = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
-        cmd = join(DIST_DIR, 'bin', 'libpng-config' ) + ' --static --ldflags'
+        cmd = join(target.dist, 'bin', 'libpng-config' ) + ' --static --ldflags'
         pngld = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
         # --disable-imageio is required otherwise the sprite data extracting code for PNGs is never enabled!
-        cmd = './configure --disable-imageio --enable-silent-rules CFLAGS="%s -m32" LDFLAGS="-m32 -static-libgcc" LIBPNG_CFLAGS="%s" LIBPNG_LIBS="%s -ljpeg" --disable-png-shared --disable-jpg-shared --disable-shared --enable-static --disable-sdltest --with-sdl-prefix="%s" --prefix="%s"'% (env['CFLAGS'], pngcf, pngld, DIST_DIR, DIST_DIR)
+        cmd = './configure --disable-imageio --enable-silent-rules CFLAGS="%s -m32" LDFLAGS="-m32 -static-libgcc" LIBPNG_CFLAGS="%s" LIBPNG_LIBS="%s -ljpeg" --disable-png-shared --disable-jpg-shared --disable-shared --enable-static --disable-sdltest --with-sdl-prefix="%s" --prefix="%s"'% (env['CFLAGS'], pngcf, pngld, target.dist, target.dist)
         Popen(shlex.split(cmd), cwd = sdl_image_build_i386, env=env).communicate()
         # There's a bug (http://bugzilla.libsdl.org/show_bug.cgi?id=1429) in showimage compilation that prevents it from working, at least up to 2012-02-23, we just remove it as we don't need it
         cmd = SED_CMD + '-e "s|.*showimage.*||g" %s' % (join(sdl_image_build_i386, 'Makefile'),)
 
     if not isfile(join(sdl_ttf_build_i386, 'configure')):
         cmd = './autogen.sh'
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
+        Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
     if not isfile(join(sdl_ttf_build_i386, 'Makefile')):
-        cmd = './configure --enable-silent-rules CFLAGS="%s -m32" LDFLAGS="-m32 -static-libgcc" --disable-shared --enable-static --with-sdl-prefix="%s" --with-freetype-prefix="%s" --prefix="%s"'% (env['CFLAGS'],DIST_DIR, DIST_DIR, DIST_DIR)
+        cmd = './configure --enable-silent-rules CFLAGS="%s -m32" LDFLAGS="-m32 -static-libgcc" --disable-shared --enable-static --with-sdl-prefix="%s" --with-freetype-prefix="%s" --prefix="%s"'% (env['CFLAGS'],target.dist, target.dist, target.dist)
         Popen(shlex.split(cmd), cwd = sdl_ttf_build_i386, env=env).communicate()
         # There's a bug in showfont compilation that prevents it from working, at least up to 2012-02-23, we just remove it as we don't need it
         #cmd = 'sed -e "s|.*showfont.*||g" -i "" %s' % (join(sdl_ttf_build_i386, 'Makefile'),)
     cmd = 'make V=0 install'
     Popen(shlex.split(cmd), cwd = sdl_ttf_build_i386, env=env).communicate()
 
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2.a')) and isfile(join(DIST_DIR, 'lib', 'libSDL2main.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2.a')) and isfile(join(target.dist, 'lib', 'libSDL2main.a')):
         log('SDL i386 built successfully')
     else:
         error('Problem building SDL i386')
         exit()
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_image.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2_image.a')):
         log('SDL Image i386 built successfully')
     else:
         error('Problem building SDL Image i386')
         exit()
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_ttf.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2_ttf.a')):
         log('SDL TTF built successfully')
     else:
         error('Problem building SDL TTF i386')
         exit()
 
     # Rename libraries with the _i386 suffix
-    cmd = 'mv -f "%s" "%s"' % (join(DIST_DIR, 'lib', 'libSDL2.a'), join(DIST_DIR, 'lib', 'libSDL2_i386.a'))
+    cmd = 'mv -f "%s" "%s"' % (join(target.dist, 'lib', 'libSDL2.a'), join(target.dist, 'lib', 'libSDL2_i386.a'))
     Popen(shlex.split(cmd), env=env).communicate()
-    cmd = 'mv -f "%s" "%s"' % (join(DIST_DIR, 'lib', 'libSDL2main.a'), join(DIST_DIR, 'lib', 'libSDL2main_i386.a'))
+    cmd = 'mv -f "%s" "%s"' % (join(target.dist, 'lib', 'libSDL2main.a'), join(target.dist, 'lib', 'libSDL2main_i386.a'))
     Popen(shlex.split(cmd), env=env).communicate()
-    cmd = 'mv -f "%s" "%s"' % (join(DIST_DIR, 'lib', 'libSDL2_image.a'), join(DIST_DIR, 'lib', 'libSDL2_image_i386.a'))
+    cmd = 'mv -f "%s" "%s"' % (join(target.dist, 'lib', 'libSDL2_image.a'), join(target.dist, 'lib', 'libSDL2_image_i386.a'))
     Popen(shlex.split(cmd), env=env).communicate()
-    cmd = 'mv -f "%s" "%s"' % (join(DIST_DIR, 'lib', 'libSDL2_ttf.a'), join(DIST_DIR, 'lib', 'libSDL2_ttf_i386.a'))
+    cmd = 'mv -f "%s" "%s"' % (join(target.dist, 'lib', 'libSDL2_ttf.a'), join(target.dist, 'lib', 'libSDL2_ttf_i386.a'))
     Popen(shlex.split(cmd), env=env).communicate()
 
     # x86_64 builds
     if not isfile(join(sdl_build_x86_64, 'Makefile')):
-        cmd = './configure --enable-silent-rules CFLAGS="%s -m64" LDFLAGS="-m64 -static-libgcc" --disable-shared --enable-static --prefix="%s"'% (env['CFLAGS'], DIST_DIR)
+        cmd = './configure --enable-silent-rules CFLAGS="%s -m64" LDFLAGS="-m64 -static-libgcc" --disable-shared --enable-static --prefix="%s"'% (env['CFLAGS'], target.dist)
         Popen(shlex.split(cmd), cwd = sdl_build_x86_64, env=env).communicate()
 
     cmd = 'make V=0'
     Popen(shlex.split(cmd), cwd = sdl_build_x86_64, env=env).communicate()
 
     if not isfile(join(sdl_image_build_x86_64, 'Makefile')):
-        cmd = join(DIST_DIR, 'bin', 'libpng-config' ) + ' --static --cflags'
+        cmd = join(target.dist, 'bin', 'libpng-config' ) + ' --static --cflags'
         pngcf = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
-        cmd = join(DIST_DIR, 'bin', 'libpng-config' ) + ' --static --ldflags'
+        cmd = join(target.dist, 'bin', 'libpng-config' ) + ' --static --ldflags'
         pngld = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
         # --disable-imageio is required otherwise the sprite data extracting code for PNGs is never enabled!
-        cmd = './configure --disable-imageio --enable-silent-rules CFLAGS="%s -m64" LDFLAGS="-m64 -static-libgcc" LIBPNG_CFLAGS="%s" LIBPNG_LIBS="%s -ljpeg" --disable-png-shared --disable-jpg-shared --disable-shared --enable-static --disable-sdltest --with-sdl-prefix="%s" --prefix="%s"'% (env['CFLAGS'], pngcf, pngld, DIST_DIR, DIST_DIR)
+        cmd = './configure --disable-imageio --enable-silent-rules CFLAGS="%s -m64" LDFLAGS="-m64 -static-libgcc" LIBPNG_CFLAGS="%s" LIBPNG_LIBS="%s -ljpeg" --disable-png-shared --disable-jpg-shared --disable-shared --enable-static --disable-sdltest --with-sdl-prefix="%s" --prefix="%s"'% (env['CFLAGS'], pngcf, pngld, target.dist, target.dist)
         Popen(shlex.split(cmd), cwd = sdl_image_build_x86_64, env=env).communicate()
         # There's a bug (http://bugzilla.libsdl.org/show_bug.cgi?id=1429) in showimage compilation that prevents it from working, at least up to 2012-02-23, we just remove it as we don't need it
         #cmd = 'sed -e "s|.*showimage.*||g" -i "" %s' % (join(sdl_image_build_x86_64, 'Makefile'),)
 
     if not isfile(join(sdl_ttf_build_x86_64, 'configure')):
         cmd = './autogen.sh'
-        Popen(shlex.split(cmd), cwd = BUILDS['SDL_TTF'], env=env).communicate()
+        Popen(shlex.split(cmd), cwd = target.builds.SDL_TTF, env=env).communicate()
     if not isfile(join(sdl_ttf_build_x86_64, 'Makefile')):
-        cmd = './configure --enable-silent-rules CFLAGS="%s -m64" LDFLAGS="-m64 -static-libgcc" --disable-shared --enable-static --with-sdl-prefix="%s" --with-freetype-prefix="%s" --prefix="%s"'% (env['CFLAGS'],DIST_DIR, DIST_DIR, DIST_DIR)
+        cmd = './configure --enable-silent-rules CFLAGS="%s -m64" LDFLAGS="-m64 -static-libgcc" --disable-shared --enable-static --with-sdl-prefix="%s" --with-freetype-prefix="%s" --prefix="%s"'% (env['CFLAGS'],target.dist, target.dist, target.dist)
         Popen(shlex.split(cmd), cwd = sdl_ttf_build_x86_64, env=env).communicate()
         # There's a bug in showfont compilation that prevents it from working, at least up to 2012-02-23, we just remove it as we don't need it
         cmd = SED_CMD + '-e "s|.*showfont.*||g" %s' % (join(sdl_ttf_build_x86_64, 'Makefile'),)
     cmd = 'make V=0 install'
     Popen(shlex.split(cmd), cwd = sdl_ttf_build_x86_64, env=env).communicate()
 
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2.a')) and isfile(join(DIST_DIR, 'lib', 'libSDL2main.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2.a')) and isfile(join(target.dist, 'lib', 'libSDL2main.a')):
         log('SDL x86_64 built successfully')
     else:
         error('Problem building SDL x86_64')
         exit()
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_image.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2_image.a')):
         log('SDL Image built successfully')
     else:
         error('Problem building SDL Image x86_64')
         exit()
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_ttf.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2_ttf.a')):
         log('SDL TTF built successfully')
     else:
         error('Problem building SDL TTF x86_64')
         exit()
 
     # Rename libraries with the _x86_64 suffix
-    cmd = 'mv -f "%s" "%s"' % (join(DIST_DIR, 'lib', 'libSDL2.a'), join(DIST_DIR, 'lib', 'libSDL2_x86_64.a'))
+    cmd = 'mv -f "%s" "%s"' % (join(target.dist, 'lib', 'libSDL2.a'), join(target.dist, 'lib', 'libSDL2_x86_64.a'))
     Popen(shlex.split(cmd), env=env).communicate()
-    cmd = 'mv -f "%s" "%s"' % (join(DIST_DIR, 'lib', 'libSDL2main.a'), join(DIST_DIR, 'lib', 'libSDL2main_x86_64.a'))
+    cmd = 'mv -f "%s" "%s"' % (join(target.dist, 'lib', 'libSDL2main.a'), join(target.dist, 'lib', 'libSDL2main_x86_64.a'))
     Popen(shlex.split(cmd), env=env).communicate()
-    cmd = 'mv -f "%s" "%s"' % (join(DIST_DIR, 'lib', 'libSDL2_image.a'), join(DIST_DIR, 'lib', 'libSDL2_image_x86_64.a'))
+    cmd = 'mv -f "%s" "%s"' % (join(target.dist, 'lib', 'libSDL2_image.a'), join(target.dist, 'lib', 'libSDL2_image_x86_64.a'))
     Popen(shlex.split(cmd), env=env).communicate()
-    cmd = 'mv -f "%s" "%s"' % (join(DIST_DIR, 'lib', 'libSDL2_ttf.a'), join(DIST_DIR, 'lib', 'libSDL2_ttf_x86_64.a'))
+    cmd = 'mv -f "%s" "%s"' % (join(target.dist, 'lib', 'libSDL2_ttf.a'), join(target.dist, 'lib', 'libSDL2_ttf_x86_64.a'))
     Popen(shlex.split(cmd), env=env).communicate()
 
     # Lipo SDL library versions together
-    cmd = 'lipo -create %s %s -output %s' % (join(DIST_DIR, 'lib', 'libSDL2_i386.a'), join(DIST_DIR, 'lib', 'libSDL2_x86_64.a'), join(DIST_DIR, 'lib', 'libSDL2.a'))
+    cmd = 'lipo -create %s %s -output %s' % (join(target.dist, 'lib', 'libSDL2_i386.a'), join(target.dist, 'lib', 'libSDL2_x86_64.a'), join(target.dist, 'lib', 'libSDL2.a'))
     Popen(shlex.split(cmd), env=env).communicate()
-    cmd = 'ranlib %s' % join(DIST_DIR, 'lib', 'libSDL2.a')
+    cmd = 'ranlib %s' % join(target.dist, 'lib', 'libSDL2.a')
     Popen(shlex.split(cmd), env=env).communicate()
 
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2.a')):
         log('SDL built successfully')
     else:
         error('Problem building SDL')
         exit()
 
-    cmd = 'lipo -create %s %s -output %s' % (join(DIST_DIR, 'lib', 'libSDL2main_i386.a'), join(DIST_DIR, 'lib', 'libSDL2main_x86_64.a'), join(DIST_DIR, 'lib', 'libSDL2main.a'))
+    cmd = 'lipo -create %s %s -output %s' % (join(target.dist, 'lib', 'libSDL2main_i386.a'), join(target.dist, 'lib', 'libSDL2main_x86_64.a'), join(target.dist, 'lib', 'libSDL2main.a'))
     Popen(shlex.split(cmd), env=env).communicate()
-    cmd = 'ranlib %s' % join(DIST_DIR, 'lib', 'libSDL2main.a')
+    cmd = 'ranlib %s' % join(target.dist, 'lib', 'libSDL2main.a')
     Popen(shlex.split(cmd), env=env).communicate()
 
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2main.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2main.a')):
         log('SDL built successfully')
     else:
         error('Problem building SDL')
         exit()
 
     # Lipo SDL Image library versions together
-    cmd = 'lipo -create %s %s -output %s' % (join(DIST_DIR, 'lib', 'libSDL2_image_i386.a'), join(DIST_DIR, 'lib', 'libSDL2_image_x86_64.a'), join(DIST_DIR, 'lib', 'libSDL2_image.a'))
+    cmd = 'lipo -create %s %s -output %s' % (join(target.dist, 'lib', 'libSDL2_image_i386.a'), join(target.dist, 'lib', 'libSDL2_image_x86_64.a'), join(target.dist, 'lib', 'libSDL2_image.a'))
     Popen(shlex.split(cmd), env=env).communicate()
-    cmd = 'ranlib %s' % join(DIST_DIR, 'lib', 'libSDL2_image.a')
+    cmd = 'ranlib %s' % join(target.dist, 'lib', 'libSDL2_image.a')
     Popen(shlex.split(cmd), env=env).communicate()
 
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_image.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2_image.a')):
         log('SDL Image built successfully')
     else:
         error('Problem building SDL Image')
         exit()
 
     # Lipo SDL TTF library versions together
-    cmd = 'lipo -create %s %s -output %s' % (join(DIST_DIR, 'lib', 'libSDL2_ttf_i386.a'), join(DIST_DIR, 'lib', 'libSDL2_ttf_x86_64.a'), join(DIST_DIR, 'lib', 'libSDL2_ttf.a'))
+    cmd = 'lipo -create %s %s -output %s' % (join(target.dist, 'lib', 'libSDL2_ttf_i386.a'), join(target.dist, 'lib', 'libSDL2_ttf_x86_64.a'), join(target.dist, 'lib', 'libSDL2_ttf.a'))
     Popen(shlex.split(cmd), env=env).communicate()
-    cmd = 'ranlib %s' % join(DIST_DIR, 'lib', 'libSDL2_ttf.a')
+    cmd = 'ranlib %s' % join(target.dist, 'lib', 'libSDL2_ttf.a')
     Popen(shlex.split(cmd), env=env).communicate()
 
-    if isfile(join(DIST_DIR, 'lib', 'libSDL2_ttf.a')):
+    if isfile(join(target.dist, 'lib', 'libSDL2_ttf.a')):
         log('SDL TTF built successfully')
     else:
         error('Problem building SDL TTF')

File tools/modules/util.py

 import os, shlex, shutil, re, platform, fnmatch
 from os.path import *
 from subprocess import Popen, PIPE
-from schafer import info, log, error, get_build_platform, prepare_python, HOST_DIST_DIR
+from log import info, log, error
 
 def find_cython():
     cmd = 'which cython'
 
 def check_host_tools():
     """ Check if the required host tools are present """
-    from schafer import HOSTPYTHON, HOSTPGEN, ROOT_DIR
+    from schafer import HOSTPYTHON, HOSTPGEN, ROOT_DIR, HOST_DIST_DIR, prepare_python
     system, arch, distro_name, distro_version, distro_id = get_build_platform()
     supported_platform = False
     if system == 'Linux':
                     break
             if yieldit:
                 yield os.path.join(path, filename)
-def get_sdl_flags(DIST_DIR):
-    cmd = join(DIST_DIR, 'bin', 'sdl2-config' ) + ' --cflags'
+
+def get_sdl_flags(target):
+    cmd = join(target.dist, 'bin', 'sdl2-config' ) + ' --cflags'
     flags = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
-    cmd = join(DIST_DIR, 'bin', 'sdl2-config' ) + ' --static-libs'
+    cmd = join(target.dist, 'bin', 'sdl2-config' ) + ' --static-libs'
     flags = flags + ' ' + Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
     return flags
 
-def get_freetype_flags(DIST_DIR):
-    cmd = join(DIST_DIR, 'bin', 'freetype-config' ) + ' --cflags'
+def get_freetype_flags(target):
+    cmd = join(target.dist, 'bin', 'freetype-config' ) + ' --cflags'
     flags = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
-    cmd = join(DIST_DIR, 'bin', 'freetype-config' ) + ' --libs'
+    cmd = join(target.dist, 'bin', 'freetype-config' ) + ' --libs'
     flags = flags + ' ' + Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
     return flags
 
-def get_png_flags(DIST_DIR):
-    cmd = join(DIST_DIR, 'bin', 'libpng-config' ) + ' --static --cflags'
+def get_png_flags(target):
+    cmd = join(target.dist, 'bin', 'libpng-config' ) + ' --static --cflags'
     flags = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
-    cmd = join(DIST_DIR, 'bin', 'libpng-config' ) + ' --static --ldflags'
+    cmd = join(target.dist, 'bin', 'libpng-config' ) + ' --static --ldflags'
     flags = flags + ' ' + Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
     return flags
 
+def get_build_platform():
+    # Check the host distro
+    arch, exe = platform.architecture()
+    system = platform.system()
+    if system == 'Linux':
+        distro_name, distro_version, distro_id = platform.linux_distribution()
+    elif system == 'Darwin':
+        distro_name, distro_version, distro_id = platform.mac_ver()
+    return system, arch, distro_name, distro_version, distro_id
+
+def get_available_platforms():
+    """ Determine which build platforms are available depending on which platform we are building """
+    system, arch, distro_name, distro_version, distro_id = get_build_platform()
+
+    if system == 'Linux':
+        SED_CMD = 'sed -i '
+        if arch == '64bit':
+            AVAILABLE_PLATFORMS = ['linux64', 'mingw32', 'android']
+        else:
+            AVAILABLE_PLATFORMS = ['mingw32', 'android']
+    elif system == 'Darwin':
+        SED_CMD = 'sed -i "" '
+        AVAILABLE_PLATFORMS = ['osx', 'android', 'iosv6', 'iosv7']
+
+    return AVAILABLE_PLATFORMS, SED_CMD
+
+def prepare_source(name, src, dst):
+    if not isdir(src):
+        error ("Can not find %s source code" % (name,) )
+        exit()
+
+    retval = False
+    if not isdir(dst):
+        retval = True
+
+    cmd = 'rsync -aqut --exclude .svn --exclude .hg --exclude Makefile %s/ %s' % (src, dst)
+    Popen(shlex.split(cmd), cwd = src).communicate()
+
+    return retval

File tools/schafer.py

 # Author: Gabriel Jacobo <gabriel@mdqinc.com>
 # Requires: RSync, Cython, GNU Tools, MINGW32, Android SDK, etc
 
-import os, sys, shutil, shlex, fnmatch, imp, marshal, platform, tempfile, re
+import os, sys, shutil, shlex, imp, marshal
 from subprocess import Popen, PIPE
 from os.path import *
 from optparse import OptionParser
-from copy import deepcopy
 
-class bcolors:
-    HEADER = '\033[95m'
-    OKBLUE = '\033[94m'
-    OKGREEN = '\033[92m'
-    WARNING = '\033[93m'
-    FAIL = '\033[91m'
-    ENDC = '\033[0m'
+########################################################################################################################
+# Host system variables, *fixed* values and locations constant during all the execution
+########################################################################################################################
+ROOT_DIR = abspath(join(dirname(sys.argv[0]), '..'))
 
-class loglevel:
-    DEBUG = 5
-    INFO = 10
-    WARNING = 20
-    ERROR = 30
-
-def info(msg):
-    log(msg, loglevel.INFO)
-def warn(msg):
-    log(msg, loglevel.WARNING)
-def error(msg):
-    log(msg, loglevel.ERROR)
-
-def log(msg, level = loglevel.DEBUG):
-    if level < 10:
-        # Debug
-        print bcolors.OKBLUE + "* " + msg + bcolors.ENDC
-    elif level < 20:
-        # Info
-        print bcolors.OKGREEN + "* " + msg + bcolors.ENDC
-    elif level < 30:
-        # Warning
-        print bcolors.WARNING + "* " + msg + bcolors.ENDC
-    elif level < 50:
-        # Error
-        print bcolors.FAIL + "* " + msg + bcolors.ENDC
-
-def get_build_platform():
-    # Check the host distro
-    arch, exe = platform.architecture()
-    system = platform.system()
-    if system == 'Linux':
-        distro_name, distro_version, distro_id = platform.linux_distribution()
-    elif system == 'Darwin':
-        distro_name, distro_version, distro_id = platform.mac_ver()
-    return system, arch, distro_name, distro_version, distro_id
-
-def get_available_platforms():
-    """ Determine which build platforms are available depending on which platform we are building """
-    system, arch, distro_name, distro_version, distro_id = get_build_platform()
-
-    if system == 'Linux':
-        SED_CMD = 'sed -i '
-        if arch == '64bit':
-            AVAILABLE_PLATFORMS = ['linux64', 'mingw32', 'android']
-        else:
-            AVAILABLE_PLATFORMS = ['mingw32', 'android']
-    elif system == 'Darwin':
-        SED_CMD = 'sed -i "" '
-        AVAILABLE_PLATFORMS = ['osx', 'android', 'iosv6', 'iosv7']
-
-    return AVAILABLE_PLATFORMS, SED_CMD
+from modules.log import log, error, info
+from modules.env import *
+from modules.util import *
 
 AVAILABLE_PLATFORMS, SED_CMD = get_available_platforms()
 
 CYTHON_GIT = 'https://github.com/cython/cython.git'
-ANDROID_NDK_URL = {'Linux': 'http://dl.google.com/android/ndk/android-ndk-r7b-linux-x86.tar.bz2', 'Darwin': 'http://dl.google.com/android/ndk/android-ndk-r7b-darwin-x86.tar.bz2'}
-ANDROID_SDK_URL = {'Linux': 'http://dl.google.com/android/android-sdk_r16-linux.tgz', 'Darwin': 'http://dl.google.com/android/android-sdk_r16-macosx.zip' }
+ANDROID_NDK_URL = {'Linux': 'http://dl.google.com/android/ndk/android-ndk-r7b-linux-x86.tar.bz2',
+                   'Darwin': 'http://dl.google.com/android/ndk/android-ndk-r7b-darwin-x86.tar.bz2'}
+ANDROID_SDK_URL = {'Linux': 'http://dl.google.com/android/android-sdk_r16-linux.tgz',
+                   'Darwin': 'http://dl.google.com/android/android-sdk_r16-macosx.zip' }
+ANDROID_NDK =  os.environ['ANDROID_NDK'] if 'ANDROID_NDK' in os.environ else '/opt/android-ndk'
+ANDROID_SDK =  os.environ['ANDROID_SDK'] if 'ANDROID_SDK' in os.environ else '/opt/android-sdk'
 
-ROOT_DIR = abspath(join(dirname(sys.argv[0]), '..'))
 HOST_DIST_DIR = join(ROOT_DIR, 'host')
 HOSTPYTHON = join(HOST_DIST_DIR, 'bin', 'python')
 HOSTPGEN = join(HOST_DIST_DIR, 'bin', 'pgen')
-TMP_DIR = join (ROOT_DIR, 'tmp')
-DIST_DIR = join (ROOT_DIR, 'dist')
+PATCHES_DIR = join(ROOT_DIR, 'tools', 'patches')
 
 SOURCES = {}
 SOURCES['PYTHON'] = join(ROOT_DIR, 'external', 'Python')
 SOURCES['BITARRAY'] = join(ROOT_DIR, 'external', 'bitarray', 'bitarray')
 SOURCES['IGNIFUGA'] = ROOT_DIR
 
-ANDROID_NDK =  os.environ['ANDROID_NDK'] if 'ANDROID_NDK' in os.environ else '/opt/android-ndk'
-ANDROID_SDK =  os.environ['ANDROID_SDK'] if 'ANDROID_SDK' in os.environ else '/opt/android-sdk'
-PATCHES_DIR = join(ROOT_DIR, 'tools', 'patches')
+########################################################################################################################
 
-PROJECT_ROOT = ""
-BUILDS = {}
-BUILDS['PROJECT'] = ""
-
-PLATFORM_FILE = ""
-BUILDS['PYTHON'] = ""
-PYTHON_HEADERS = ""
-BUILDS['SDL'] = ""
-BUILDS['SDL_IMAGE'] = ""
-BUILDS['SDL_TTF'] = ""
-BUILDS['FREETYPE'] = ""
-SDL_HEADERS = ""
-BUILDS['PNG'] = ""
-BUILDS['JPG'] = ""
-BUILDS['ZLIB'] = ""
-BUILDS['IGNIFUGA'] = ""
-
-from modules.util import *
-from modules.env import *
-
-def setup_variables(dist_dir = join (ROOT_DIR, 'dist'), tmp_dir = join (ROOT_DIR, 'tmp')):
-    """ Set up some global variables """
-    global DIST_DIR, TMP_DIR, HOST_DIST_DIR, HOSTPYTHON, HOSTPGEN, PLATFORM_FILE, BUILDS, PYTHON_HEADERS
-    DIST_DIR = dist_dir
-    TMP_DIR = tmp_dir
-    PLATFORM_FILE = join(TMP_DIR, 'platform')
-    BUILDS['PYTHON'] = join(TMP_DIR, 'python')
-    PYTHON_HEADERS = join(BUILDS['PYTHON'], 'Include')
-    BUILDS['SDL'] = join(TMP_DIR, 'sdl')
-    BUILDS['SDL_IMAGE'] = join(TMP_DIR, 'sdl_image')
-    BUILDS['SDL_TTF'] = join(TMP_DIR, 'sdl_ttf')
-    BUILDS['FREETYPE'] = join(TMP_DIR, 'freetype')
-    SDL_HEADERS = join(DIST_DIR, 'include', 'SDL')
-    BUILDS['PNG'] = join(TMP_DIR, 'png')
-    BUILDS['JPG'] = join(TMP_DIR, 'jpg')
-    BUILDS['ZLIB'] = join(TMP_DIR, 'zlib')
-    BUILDS['IGNIFUGA'] = join(TMP_DIR, 'ignifuga')
-
-    if not isdir(TMP_DIR):
-        os.makedirs(TMP_DIR)
 
 def clean_modules(platforms, modules, everything=False):
     log('Cleaning Build Directories')
         platforms = [platforms,]
 
     for platform in platforms:
-        setup_variables(join (ROOT_DIR, 'dist', platform), join (ROOT_DIR, 'tmp', platform))
+        target = get_target(platform)
         if not everything:
-            if isdir(TMP_DIR):
+            if isdir(target.tmp):
                 if 'ignifuga' in modules:
-                    if isdir(BUILDS['IGNIFUGA']):
-                        shutil.rmtree(BUILDS['IGNIFUGA'])
-                    if isdir(BUILDS['PYTHON']):
-                        shutil.rmtree(BUILDS['PYTHON'])
-                if 'sdl' in modules and isdir(BUILDS['SDL']):
-                    shutil.rmtree(BUILDS['SDL'])
+                    if isdir(target.builds.IGNIFUGA):
+                        shutil.rmtree(target.builds.IGNIFUGA)
+                    if isdir(target.builds.PYTHON):
+                        shutil.rmtree(target.builds.PYTHON)
+                if 'sdl' in modules and isdir(target.builds.SDL):
+                    shutil.rmtree(target.builds.SDL)
         else:
-            if isdir(TMP_DIR):
-                shutil.rmtree(TMP_DIR)
-            if isdir(DIST_DIR):
-                shutil.rmtree(DIST_DIR)
-
-def save_platform(platform):
-    f = open(PLATFORM_FILE, 'w')
-    f.write(platform)
-    f.close()
-
-def read_platform():
-    if not isfile(PLATFORM_FILE):
-        return None
-    f = open (PLATFORM_FILE, 'r')
-    platform = f.read()
-    f.close()
-    return platform
+            if isdir(target.tmp):
+                shutil.rmtree(target.tmp)
+            if isdir(target.dist):
+                shutil.rmtree(target.dist)
 
 def check_ignifuga_libraries(platform):
+    target = get_target(platform)
     if platform in ['linux64', 'mingw32', 'osx']:
-        if isfile(join(DIST_DIR, 'lib', 'libpython2.7.a')):
+        if isfile(join(target.dist, 'lib', 'libpython2.7.a')):
             return True
     elif platform == 'android':
-        if isfile(join(DIST_DIR, 'jni', 'python', 'libpython2.7.so')) and \
-        isfile(join(DIST_DIR, 'jni', 'SDL', 'libSDL2.so')) and \
-        isfile(join(DIST_DIR, 'jni', 'SDL_image', 'libSDL2_image.so')) and \
-        isfile(join(DIST_DIR, 'jni', 'SDL_ttf', 'libSDL2_ttf.so')):
+        if isfile(join(target.dist, 'jni', 'python', 'libpython2.7.so')) and \
+        isfile(join(target.dist, 'jni', 'SDL', 'libSDL2.so')) and \
+        isfile(join(target.dist, 'jni', 'SDL_image', 'libSDL2_image.so')) and \
+        isfile(join(target.dist, 'jni', 'SDL_ttf', 'libSDL2_ttf.so')):
             return True
 
     return False
-    
-def prepare_source(name, src, dst):
-    if not isdir(src):
-        error ("Can not find %s source code" % (name,) )
-        exit()
-
-    retval = False
-    if not isdir(dst):
-        retval = True
-
-    cmd = 'rsync -aqut --exclude .svn --exclude .hg --exclude Makefile %s/ %s' % (src, dst)
-    Popen(shlex.split(cmd), cwd = src).communicate()
-    
-    return retval
 
 # ===============================================================================================================
 # PYTHON BUILDING - Requires Ignifuga building!
 # ===============================================================================================================
 
 def prepare_python(platform, ignifuga_src, python_build):
+    target = get_target(platform)
+    if not isdir(target.tmp):
+        os.makedirs(target.tmp)
+
     if prepare_source('Python', SOURCES['PYTHON'], python_build):
         # Now copy the Setup.dist files
         python_setup = join(ROOT_DIR, 'external', 'Setup.'+platform)
         if ignifuga_src != None:
             if platform in ['linux64', 'mingw32', 'osx']:
                 # Get some required flags
-                cmd = join(DIST_DIR, 'bin', 'sdl2-config' ) + ' --cflags'
+                cmd = join(target.dist, 'bin', 'sdl2-config' ) + ' --cflags'
                 sdlflags = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
-                cmd = join(DIST_DIR, 'bin', 'sdl2-config' ) + ' --static-libs'
+                cmd = join(target.dist, 'bin', 'sdl2-config' ) + ' --static-libs'
                 sdlflags = sdlflags + ' ' + Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
-                cmd = join(DIST_DIR, 'bin', 'freetype-config' ) + ' --cflags'
+                cmd = join(target.dist, 'bin', 'freetype-config' ) + ' --cflags'
                 freetypeflags = Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
-                cmd = join(DIST_DIR, 'bin', 'freetype-config' ) + ' --libs'
+                cmd = join(target.dist, 'bin', 'freetype-config' ) + ' --libs'
                 freetypeflags = freetypeflags + ' ' + Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].split('\n')[0]
 
             if platform == 'linux64' or platform == 'osx':
-                ignifuga_module = "\nignifuga %s -I%s -lSDL2_ttf -lSDL2_image -lSDL2 -lpng12 -ljpeg %s %s\n" % (' '.join(ignifuga_src),BUILDS['IGNIFUGA'], sdlflags, freetypeflags)
+                ignifuga_module = "\nignifuga %s -I%s -lSDL2_ttf -lSDL2_image -lSDL2 -lpng12 -ljpeg %s %s\n" % (' '.join(ignifuga_src),target.builds.IGNIFUGA, sdlflags, freetypeflags)
 
             elif platform== 'android':
                 # Hardcoded for now
-                sdlflags = '-I%s -I%s -I%s -lSDL2_ttf -lSDL2_image -lSDL2 -ldl -lGLESv1_CM -lGLESv2 -llog' % (join(BUILDS['SDL'], 'jni', 'SDL', 'include'), join(BUILDS['SDL'], 'jni', 'SDL_image'), join(BUILDS['SDL'], 'jni', 'SDL_ttf'))
+                sdlflags = '-I%s -I%s -I%s -lSDL2_ttf -lSDL2_image -lSDL2 -ldl -lGLESv1_CM -lGLESv2 -llog' % (join(target.builds.SDL, 'jni', 'SDL', 'include'), join(target.builds.SDL, 'jni', 'SDL_image'), join(target.builds.SDL, 'jni', 'SDL_ttf'))
 
                 # Patch some problems with cross compilation
                 cmd = 'patch -p0 -i %s -d %s' % (join(PATCHES_DIR, 'python.android.diff'), python_build)
                 Popen(shlex.split(cmd)).communicate()
-                ignifuga_module = "\nignifuga %s -I%s -L%s %s\n" % (' '.join(ignifuga_src), BUILDS['IGNIFUGA'], join(BUILDS['SDL'], 'libs', 'armeabi'), sdlflags)
+                ignifuga_module = "\nignifuga %s -I%s -L%s %s\n" % (' '.join(ignifuga_src), target.builds.IGNIFUGA, join(target.builds.SDL, 'libs', 'armeabi'), sdlflags)
 
             elif platform == 'mingw32':
                 # Remove some perjudicial flags
                 # Patch some problems with cross compilation
                 cmd = 'patch -p0 -i %s -d %s' % (join(PATCHES_DIR, 'python.mingw32.diff'), python_build)
                 Popen(shlex.split(cmd)).communicate()
-                cmd = SED_CMD + '"s|Windows.h|windows.h|g" %s' % (join(BUILDS['PYTHON'], 'Modules', 'signalmodule.c'),)
-                Popen(shlex.split(cmd), cwd = BUILDS['PYTHON'] ).communicate()
+                cmd = SED_CMD + '"s|Windows.h|windows.h|g" %s' % (join(target.builds.PYTHON, 'Modules', 'signalmodule.c'),)
+                Popen(shlex.split(cmd), cwd = target.builds.PYTHON ).communicate()
 
                 # Copy some additional files in the right place
-                shutil.copy(join(BUILDS['PYTHON'], 'PC', 'import_nt.c'), join(BUILDS['PYTHON'], 'Python', 'import_nt.c'))
-                shutil.copy(join(BUILDS['PYTHON'], 'PC', 'dl_nt.c'), join(BUILDS['PYTHON'], 'Python', 'dl_nt.c'))
-                shutil.copy(join(BUILDS['PYTHON'], 'PC', 'getpathp.c'), join(BUILDS['PYTHON'], 'Python', 'getpathp.c'))
-                shutil.copy(join(BUILDS['PYTHON'], 'PC', 'errmap.h'), join(BUILDS['PYTHON'], 'Objects', 'errmap.h'))
+                shutil.copy(join(target.builds.PYTHON, 'PC', 'import_nt.c'), join(target.builds.PYTHON, 'Python', 'import_nt.c'))
+                shutil.copy(join(target.builds.PYTHON, 'PC', 'dl_nt.c'), join(target.builds.PYTHON, 'Python', 'dl_nt.c'))
+                shutil.copy(join(target.builds.PYTHON, 'PC', 'getpathp.c'), join(target.builds.PYTHON, 'Python', 'getpathp.c'))
+                shutil.copy(join(target.builds.PYTHON, 'PC', 'errmap.h'), join(target.builds.PYTHON, 'Objects', 'errmap.h'))
 
-                ignifuga_module = "\nignifuga %s -I%s -I%s -lSDL2_ttf -lSDL2_image %s %s -lpng12 -ljpeg -lz\n" % (' '.join(ignifuga_src), BUILDS['IGNIFUGA'], join(BUILDS['PYTHON'], 'Include'), sdlflags, freetypeflags)
+                ignifuga_module = "\nignifuga %s -I%s -I%s -lSDL2_ttf -lSDL2_image %s %s -lpng12 -ljpeg -lz\n" % (' '.join(ignifuga_src), target.builds.IGNIFUGA, join(target.builds.PYTHON, 'Include'), sdlflags, freetypeflags)
 
             
             f = open(setupfile, 'at')
     # For profiling
     freeze_modules += ['cProfile', 'runpy', 'pkgutil']
 
+    target = get_target(platform)
     mod = __import__('modules.python.'+platform, fromlist=['make'])
-    mod.make(env, DIST_DIR, BUILDS, freeze_modules, join(BUILDS['PYTHON'], 'Python', 'frozen.c'))
+    mod.make(env, target, freeze_modules, join(target.builds.PYTHON, 'Python', 'frozen.c'))
 
 
-def make_python_freeze(modules, froze