Commits

Lenard Lindstrom  committed 8a239e4

Preliminary Windows prebuilt make utility

  • Participants
  • Parent commits 4186328

Comments (0)

Files changed (2)

File make_prebuilt.py

+# This is a work in progress
+
+import msys
+from distutils.extension import read_setup_file
+
+import os
+import re
+import sys
+
+prebuilt_dir = 'prebuilt'
+
+def file_copy(src, dest):
+    if dest == '.':
+        dest = os.path.split(src)[1]
+    if dest == src:
+        raise IOError("%s: Source and destination are the same" % src)
+    s = open(src, 'rb')
+    try:
+        d = open(dest, 'wb')
+        try:
+            d.write(s.read())
+        finally:
+            d.close()
+    finally:
+        s.close()
+
+def find_import_libraries(path, roots):
+    match = re.compile(r'lib(%s)\.dll\.a$' % '|'.join(roots)).match
+    return [name for name in os.listdir(path) if match(name) is not None]
+
+def copy_dir(src, dest):
+    if dest == '.':
+        ignore, dest = os.path.split(src)
+    if src == dest:
+        raise IOError("%s: Source and destination are identical" % src)
+    mkdir(dest)
+    for name in os.listdir(src):
+        src_path = os.path.join(src, name)
+        if os.path.isfile(src_path):
+            file_copy(src_path, os.path.join(dest, name))
+
+def confirm(message):
+    "ask a yes/no question, return result"
+    reply = msys.msys_raw_input("\n%s [Y/n]:" % message)
+    if reply and reply[0].lower() == 'n':
+        return 0
+    return 1
+
+def mkdir(path):
+    if path == '.':
+        raise IOError("What the")
+    if not os.path.exists(path):
+        os.mkdir(path)
+    elif os.path.isdir(path):
+        if not confirm("Directory %s already exists; continue" % path):
+            sys.exit(0)
+    else:
+        print "*** %s is not a directory; execution halted"
+        sys.exit(1)
+
+def main(prebuilt_dir=None):
+    if prebuilt_dir is None:
+        prebuilt_dir = prebuilt
+    mkdir(prebuilt_dir)
+    os.chdir(prebuilt_dir)
+    file_copy(os.path.join('..', 'prebuilt-template', 'Setup_Win.in'), '.')
+    deps = [dep for dep in read_setup_file('Setup_Win.in')
+                if dep.name.startswith('COPYLIB_')]
+    mkdir('lib')
+    os.chdir('lib')
+#    file_copy(os.path.join('..', '..', 'prebuilt-template', 'makelibs.bat'), '.')
+    local_dir = os.path.join(msys.Msys().msys_root, 'local')
+    src_dir_path = os.path.join(local_dir, 'bin')
+    for d in deps:
+        ignore, dll_file = os.path.split(d.library_dirs[0])
+        try:
+            file_copy(os.path.join(src_dir_path, dll_file), '.')
+        except Exception:
+            pass
+    src_dir_path = os.path.join(local_dir, 'lib')
+    import_libs = find_import_libraries(src_dir_path, [d.name[8:] for d in deps])
+    for lib in import_libs:
+        file_copy(os.path.join(src_dir_path, lib), '.')
+    os.chdir('..')
+    src_dir_path = os.path.join(local_dir, 'include')
+    copy_dir(src_dir_path, '.')
+    os.chdir('include')
+    for d in ['SDL', 'libpng12', 'ogg', 'smpeg', 'vorbis']:
+        copy_dir(os.path.join(src_dir_path, d), '.')
+
+if __name__ =='__main__':
+    prebuilt_dir = None
+    if len(sys.argv) > 1:
+        prebuilt_dir = sys.argv[1]
+    main(prebuilt_dir)

File prebuilt-template/Setup_Win.in

+# Pygame 1.9.0 Windows dependency macros.
+SDL = -Iprebuilt/include -Iprebuilt/include/SDL -Lprebuilt/lib -lSDL
+FONT = -lSDL_ttf
+IMAGE = -lSDL_image
+MIXER = -lSDL_mixer
+SMPEG = -Iprebuilt/include/smpeg -lsmpeg
+PNG = -Iprebuilt/include/libpng12 -lpng12
+JPEG = -ljpeg
+SCRAP = -luser32 -lgdi32
+COPYLIB_SDL -Lprebuilt/lib/SDL.dll
+COPYLIB_SDL_ttf -lSDL -lfreetype -Lprebuilt/lib/SDL_ttf.dll
+COPYLIB_SDL_image -lSDL -ljpef -lpng12 -ltiff -Lprebuilt/lib/SDL_image.dll
+COPYLIB_SDL_mixer -lSDL -lvorbisfile -lsmpeg -Lprebuilt/lib/SDL_mixer.dll
+COPYLIB_freetype -lz -Lprebuilt/lib/libfreetype-6.dll
+COPYLIB_smpeg -lSDL -Lprebuilt/lib/smpeg.dll
+COPYLIB_tiff -ljpeg -lz -Lprebuilt/lib/libtiff.dll
+COPYLIB_png12 -lz -Lprebuilt/lib/libpng12-0.dll
+COPYLIB_jpeg -Lprebuilt/lib/jpeg.dll
+COPYLIB_z -Lprebuilt/lib/zlib1.dll
+COPYLIB_vorbisfile -lvorbis -Lprebuilt/lib/libvorbisfile-3.dll
+COPYLIB_vorbis -logg -Lprebuilt/lib/libvorbis-0.dll
+COPYLIB_ogg -Lprebuilt/lib/libogg-0.dll