Commits

Lenard Lindstrom  committed 625543b

dep build fix and polished up prebuilt make script

  • Participants
  • Parent commits 201f850

Comments (0)

Files changed (6)

File MakePrebuilt.bat

+@echo off
+rem Make the prebuilt package from the libraries built with
+rem msys_build_deps.py. Takes one optional argument, the
+rem name of the output directory.
+rem
+rem This batch file needs python.exe, pexports.exe
+rem (found in altbinutils-pe at SourceForge,
+rem http://sourceforge.net/projects/mingwrep/) and
+rem Visual C's VCVARS32.BAT in the executables search path.
+rem Otherwise run make_prebuilt.py first, then the batch
+rem files MakeDefs.bat and MakeLibs.bat afterward.
+
+python.exe make_prebuilt.py %1
+if errorlevel 1 goto done
+if "%1"=="" goto useprebuilt
+cd "%1"
+goto domake
+:useprebuilt
+cd prebuilt
+:domake
+cd lib
+CALL Make32.bat
+cd ..\..
+:done
+
+

File make_prebuilt.py

 import sys
 
 prebuilt_dir = 'prebuilt'
+lib_subdir = 'lib'
+
+class MakePrebuiltError(Exception):
+    pass
 
 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)
+    if os.path.isdir(dest):
+        dest = os.path.join(dest, os.path.split(src)[1])
     s = open(src, 'rb')
     try:
         d = open(dest, 'wb')
         try:
             d.write(s.read())
+            print "%s => %s" % (src, dest)
         finally:
             d.close()
     finally:
         return 0
     return 1
 
+created_dirs = set()
+
 def mkdir(path):
-    if path == '.':
-        raise IOError("What the")
-    if not os.path.exists(path):
+    path = os.path.abspath(path)
+    if path in created_dirs:
+        pass
+    elif 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)
+        created_dirs.add(path)
+    elif not os.path.isdir(path):
+        raise MakePrebuiltError("%s is not a directory" % path)
 
-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), '.')
+def main(dest_dir=None):
+    # Top level directories.
+    if dest_dir is None:
+        dest_dir = prebuilt_dir
+    dest_dir = os.path.abspath(dest_dir)
+    if os.path.isdir(dest_dir):
+        if not confirm("Directory %s already exists;\ncontinue" % dest_dir):
+            return 1
+    mkdir(dest_dir)
+    m = msys.Msys()
+    src_dir = os.path.join(m.msys_root, 'local')
+    prebuilt_template = os.path.abspath('prebuilt-template')
+    dest_lib_dir = os.path.join(dest_dir, lib_subdir)
+    
+    # Read setup file.
+    src_file = os.path.join(prebuilt_template, 'Setup_Win.in')
+    file_copy(src_file, dest_dir)
+    deps =  read_setup_file(src_file)
+    setup_in = open(src_file)
+    match = re.compile('[A-Z_][A-Z0-9_]* *=(.*)').match
+    header_dir_pat = re.compile(' -I([^ ]+)')
+    lib_pat = re.compile(' -l([^ ]+)')
+    macros = []
+    for line in setup_in:
+        matches = match(line)
+        if matches is not None:
+            flags = matches.group(1)
+            header_dirs = header_dir_pat.findall(flags)
+            libs = lib_pat.findall(flags)
+            macros.append((header_dirs, libs))
+
+    # Copy DLLs.
+    src_bin_dir = os.path.join(src_dir, 'bin')
+    have_dlls = set()
+    for dep in deps:
+        path_elements = dep.library_dirs[0].split('/')  # / required by setup.
+        dll_name = path_elements[-1]
+        src_dll_path = os.path.join(src_bin_dir, dll_name)
+        if os.path.exists(src_dll_path):
+            if path_elements[0] == '.':
+                path_elements = path_elements[2:]
+            else:
+                path_elements = path_elements[1:]
+            dest_dll_dir = dest_dir
+            for dir_name in path_elements[:-1]:
+                dest_dll_dir = os.path.join(dest_dll_dir, dir_name)
+                mkdir(dest_dll_dir)
+            file_copy(os.path.join(src_bin_dir, dll_name),
+                      os.path.join(dest_dll_dir, dll_name))
+            have_dlls.add(dep.name[8:])
+    
+    # Copy required import libraries only.
+    copied_files = set()
+    src_lib_dir = os.path.join(src_dir, 'lib')
+    mkdir(dest_lib_dir)
+    for ignore, libs in macros:
+        use = False
+        for lib in libs:
+            if lib in have_dlls:
+                use = True
+                break
+        if use and lib not in copied_files:
+            copied_files.add(lib)
+            lib_name = 'lib%s.dll.a' % lib
+            src_lib_path = os.path.join(src_lib_dir, lib_name)
+            if not os.path.exists(src_lib_path):
+                print "Missing import library %s" % lib_name
+                return 1
+            file_copy(src_lib_path, os.path.join(dest_lib_dir, lib_name))
+
+    # Copy required header directories only.
+    copied_dirs = set()
+    for header_dirs, libs in macros:
+        use = False
+        for lib in libs:
+            if lib in have_dlls:
+                use = True
+                break
+        if use:
+            for header_dir in header_dirs:
+                path_elements = header_dir.split('/')
+                if path_elements[0] == '.':
+                    path_elements = path_elements[2:]
+                else:
+                    path_elements = path_elements[1:]
+                src_header_dir = os.path.join(src_dir, *path_elements)
+                if not os.path.exists(src_header_dir):
+                    print "Missing include directory %s" % src_header_dir
+                    return 1
+                dest_header_dir = dest_dir
+                for dir_name in path_elements:
+                    dest_header_dir = os.path.join(dest_header_dir, dir_name)
+                    mkdir(dest_header_dir)
+                if not src_header_dir in copied_dirs:
+                    copy_dir(src_header_dir, dest_header_dir)
+                    copied_dirs.add(src_header_dir)
+
+    # msvcr71.dll linking support.
+    src_msvcr71_dir = os.path.join(src_dir, 'lib', 'msvcr71')
+    dest_msvcr71_dir = os.path.join(dest_dir, 'lib', 'msvcr71')
+    copy_dir(src_msvcr71_dir, dest_msvcr71_dir)
+
+    # Def file bat.
+    make_defs = open(os.path.join(dest_lib_dir, 'MakeDefs.bat'), 'w')
+    try:
+        make_defs.write('@echo off\n'
+                        'rem Make .def files needed for .lib file creation.\n'
+                        'rem Requires pexports.exe on the search path\n'
+                        'rem (found in altbinutils-pe as SourceForge,\n'
+                        'rem http://sourceforge.net/projects/mingwrep/).\n\n')
+        for dep in deps:
+            dll_name = os.path.split(dep.library_dirs[0])[1]
+            lib = dep.name[8:]
+            lib_name = 'lib%s.dll.a' % lib
+            if os.path.exists(os.path.join(dest_lib_dir, lib_name)):
+                start = ''
+            else:
+                start = 'rem '
+            make_defs.write('%spexports %s >%s.def\n' %
+                            (start, dll_name, lib))
+    finally:
+        make_defs.close()
+
+    # Lib import files bat.
+    make_libs = open(os.path.join(dest_lib_dir, 'MakeLibs.bat'), 'w')
+    try:
+        make_libs.write('@echo off\n'
+                        'rem Make .lib import libraries.\n'
+                        'rem Requires Visual C++ Studio or Toolkit.\n'
+                        'rem VCVARS32.BAT (VCVARS64.BAT (?) for 64 bit build)\n'
+                        'rem must be run first to use LIB.EXE.\n\n')
+        for dep in deps:
+            dll_name = os.path.split(dep.library_dirs[0])[1]
+            lib = dep.name[8:]
+            lib_name = 'lib%s.dll.a' % lib
+            if os.path.exists(os.path.join(dest_lib_dir, lib_name)):
+                start = ''
+            else:
+                start = 'rem '
+            make_libs.write('%sLIB.EXE /NOLOGO /DEF:%s.def /MACHINE:IX86 /OUT:%s.lib\n' %
+                            (start, lib, lib))
+    finally:
+        make_libs.close()
+
+    # Top level make batch file for 32 bit build.
+    file_copy(os.path.join(prebuilt_template, 'Make32.bat'), dest_lib_dir)
+
+    return 0
 
 if __name__ =='__main__':
-    prebuilt_dir = None
+    dest_dir = None
     if len(sys.argv) > 1:
-        prebuilt_dir = sys.argv[1]
-    main(prebuilt_dir)
+        dest_dir = sys.argv[1]
+    try:
+        sys.exit(main(dest_dir))
+    except MakePrebuiltError, e:
+        print "*** %s; execution halted" % e
+        sys.exit(1)

File msys_build_deps.py

 
 if [ x$BDINST == x1 ]; then
   make install
+  
+  # Sorry, but no one else recognizes png12
+  cp -f /usr/local/lib/libpng12.dll.a /usr/local/lib/libpng.dll.a
 fi
 
 if [ x$BDSTRIP == x1 ]; then

File prebuilt-template/Make32.bat

+@echo off
+rem Builds the Visual C import 32 bit libraries.
+rem Requires pexports (see MakeDefs.bat) and VCVARS32.BAT on
+rem the executable search path.
+
+CALL VCVARS32.BAT
+CALL MakeDefs.bat
+CALL MakeLibs.bat

File prebuilt-template/Setup_Win.in

 IMAGE = -lSDL_image
 MIXER = -lSDL_mixer
 SMPEG = -Iprebuilt/include/smpeg -lsmpeg
-PNG = -Iprebuilt/include/libpng12 -lpng12
+PNG = -lpng
 JPEG = -ljpeg
 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_image -lSDL -ljpef -lpng -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_png -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

File prebuilt-template/readme.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html>
+<head>
+    <title>Prebuilt library sources</title>
+    <style type='text/css'>
+    body {
+      font-family: arial, helvetica, sans-serif;
+      font-size: 1em;
+      color: black;
+      background-color: #aaeebb;
+    }
+
+    h1 {
+      font-size: 2em;
+      color: black;
+      background-color: #c2fc20;
+      text-align: center;
+      border: medium black solid;
+    }
+
+    h4 { 
+      font-size: 1.1em;
+    }
+
+    table { 
+      border-top: 1px solid #888888;
+      border-left: 1px solid #888888;
+      border-spacing: 0px; border-collapse: collapse;
+    }
+
+    td {
+      border-bottom: 1px solid #888888;
+      border-right: 1px solid #888888;
+      padding: 3px;
+    }
+
+    th {
+      background: #eeeeee;
+      border-bottom: 1px solid #888888;
+      border-right: 1px solid #888888;
+      padding: 3px;
+      }
+
+    .footnote { 
+      font-size: 0.9em;
+      font-style: italic;
+    }
+
+    .divider { 
+      line-height: 5;
+    }
+    </style>
+</head>
+<body>
+<h3>pygame dependencies on windows</h3>
+
+<p>
+These dependencies are built for Pygame 1.9.0 and Python 2.4 and later.
+They were built using the <tt>msys_build_deps.py</tt> script included with the Pygame source files.
+The dependencies were compiled and linked with MinGW.
+See the wiki at <a href="http://www.pygame.org/wiki/index">pygame.org</a> for details.
+There size was reduced using <tt>strip --strip-all</tt>.
+They link to the Windows C library msvcr71.dll, which is provided with Python.
+This list of libraries shows the version used in the prebuilt as well as a link to the actual source bundle used.
+</p>
+
+<table>
+    <tr>
+        <td><a href="http://www.libsdl.org/">SDL 1.2(.13) revision 4114 from SVN</a></td>
+        <td>svn co -r 4114 http://svn.libsdl.org/branches/SDL-1.2</td>
+    </tr>
+    
+    <tr>
+        <td><a href="http://www.zlib.net/">zlib 1.2.3</a></td>
+        <td><a href="http://www.zlib.net/zlib-1.2.3.tar.gz">zlib-1.2.3.tar.gz</a></td>
+    </tr>
+    
+    <tr>
+        <td><a href="http://libpng.sourceforge.net/">libpng 1.2.32</a></td>
+        <td><a href="http://sourceforge.net/project/showfiles.php?group_id=5624">PNG reference library: libpng</a> at <a href="http://sourceforge.net/">SourceForge.net</a></td>
+    </tr>
+    
+    <tr>
+        <td><a href="http://www.ijg.org/">libjpeg 6b</a></td>
+        <td><a href="http://www.ijg.org/files/jpegsrc.v6b.tar.gz">jpegsrc.v6b.tar.gz</a></td>
+    </tr>
+    
+    <tr>
+        <td><a href="http://www.libtiff.org/">libtiff 3.8.2</a></td>
+        <td><a href="ftp://ftp.remotesensing.org/pub/libtiff/tiff-3.8.2.tar.gz">tiff-3.8.2.tar.gz</a></td>
+    </tr>
+    
+    <tr>
+        <td><a href="http://www.libsdl.org/projects/SDL_image/">SDL_image 1.2.6</a></td>
+        <td><a href="http://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.6.zip">SDL_image-1.2.6.zip</a></td>
+    </tr>
+    
+    <tr>
+        <td><a href="http://www.freetype.org/">freetype 2.3.5</a></td>
+        <td><a href="http://sourceforge.net/project/showfiles.php?group_id=3157">The FreeType Project</a> at <a href="http://sourceforge.net/">SourceForge.net</a></td>
+    </tr>
+
+    <tr>
+        <td><a href="http://www.libsdl.org/projects/SDL_ttf/">SDL_ttf 2.0.9</a></td>
+        <td><a href="http://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-2.0.9.zip">SDL_ttf-2.0.9.zip</a></td>
+    </tr>
+
+    <tr>
+        <td><a href="http://www.vorbis.com/">libvorbis 1.2.0</a></td>
+        <td><a href="http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.0.zip">libvorbis-1.2.0.zip</a></td>
+    </tr>
+
+    <tr>
+        <td><a href="http://www.vorbis.com/">libogg 1.1.3</a></td>
+        <td><a href="http://downloads.xiph.org/releases/ogg/libogg-1.1.3.zip">libogg-1.1.3.zip</a></td>
+    </tr>
+
+    <tr>
+        <td><a href="http://flac.sourceforge.net/">FLAC 1.2.1</a></td>
+        <td><a href="http://sourceforge.net/project/showfiles.php?group_id=13478&amp;package_id=12677">flac-1.2.1-src.tar.gz</a> at <a href="http://sourceforge.net">SourceForge.net</a></td>
+    </tr>
+
+    <tr>
+        <td><a href="http://www.libsdl.org/projects/SDL_mixer/">SDL_mixer (1.2.8) revision 3942 from SVN</a></td>
+        <td>svn co -r 3942 http://svn.libsdl.org/trunk/SDL_mixer SDL_mixer-1.2</td>
+    </tr>
+
+    <tr>
+        <td><a href="http://icculus.org/smpeg/">smpeg revision 370 from SVN</a></td>
+        <td>svn co -r 370 svn://svn.icculus.org/smpeg/trunk smpeg</td>
+    </tr>
+</table>
+</body>
+</html>