Lenard Lindstrom avatar Lenard Lindstrom committed a4b8ac4

Add pygame.freetype.Family class

The Family class collects together all files of a font family into one object.
So attributes like italic will use the appropriate font face file, if found.
Internally the Family class maintains Face instances for each file of the
family that is used.

Comments (0)

Files changed (25)

-include Setup.in Setup_Darwin.in Setup_Unix.in Setup_Win_Common.in *.py WHATSNEW readme.txt install.html readme.html LGPL
+include Setup.in Setup_Darwin.in Setup_Unix.in Setup_Win_Common.in *.py WHATSNEW readme.rst install.html readme.html LGPL
 
 recursive-include docs *
 recursive-include lib *
 #This file defines platform specific modules for mac os x
 sdlmain_osx src/sdlmain_osx.m $(SDL) $(DEBUG)
-_camera src/_camera.c src/camera_mac.m $(SDL) $(DEBUG)
+#_camera src/_camera.c src/camera_mac.m $(SDL) $(DEBUG)
                 DEPS[DEPS.index(d)] = d[0]
     
     for d in DEPS:
-      d.configure(incdirs, libdirs)
+        d.configure(incdirs, libdirs)
     DEPS[0].cflags = '-Ddarwin '+ DEPS[0].cflags
     return DEPS
 

docs/reST/ref/event.rst

 ``pygame.event.set_allowed()`` and ``pygame.event.set_blocked()`` to work with
 this filtering. All events default to allowed.
 
+The event subsystem should be called from the main thread.  If you want to post
+events into the queue from other threads, please use the fastevent package.
+
 Joysticks will not send any events until the device has been initialized.
 
 An Event object contains an event type and a readonly set of member data. The

docs/reST/ref/freetype.rst

       | :sg:`resolution -> int`
 
       Gets the pixel size used in scaling face glyphs for this Face instance.
+
+.. class:: Face
+
+   | :sl:`Creates a new Face instance from a supported font file.`
+   | :sg:`Face(file, style=STYLE_NONE, ptsize=-1, face_index=0, vertical=0, ucs4=0, resolution=0) -> Face`
+
+   'file' can be either a string representing the font's filename, a file-like
+   object containing the font, or None; in this last case the default, built-in
+   font will be used.
+
+   Optionally, a \*ptsize* argument may be specified to set the default size in
+   points which will be used to render the face. Such size can also be
+   specified manually on each method call. Because of the way the caching
+   system works, specifying a default size on the constructor doesn't imply a
+   performance gain over manually passing the size on each function call.
+
+   If the font file has more than one face, the \*index* argument may be
+   specified to specify which face index to load. Defaults to 0; face loading
+   will fail if the given index is not contained in the font.
+
+   The 'style' argument will set the default style (oblique, underline, strong)
+   used to draw this face. This style may be overriden on any ``Face.render()``
+   call.
+
+   The optional vertical argument, an integer, sets the default orientation
+   for the face: 0 (False) for horizontal, any other value (True) for vertical.
+   See :attr:`Face.vertical`.
+
+   The optional ucs4 argument, an integer, sets the default text translation
+   mode: 0 (False) recognize UTF-16 surrogate pairs, any other value (True),
+   to treat unicode text as UCS-4, with no surrogate pairs. See
+   :attr:`Face.ucs4`.
+
+   The optional resolution argument sets the pixel size, in dots per inch,
+   to use for scaling glyphs for this Face instance. If 0 then the default
+   module value, set by :meth:`freetype.init`, is used. The Face object's
+   resolution can only be changed by reinitializing the instance.
+
+   .. attribute:: name
+
+      | :sl:`Gets the name of the font face.`
+      | :sg:`name -> string`
+
+      Read only. Returns the real (long) name of the font type face, as
+      specified on the font file.
+
+   .. attribute:: path
+
+      | :sl:`Gets the path of the font file`
+      | :sg:`path -> unicode`
+
+      Read only. Returns the path of the loaded font file
+
+   .. method:: get_rect
+
+      | :sl:`Gets the size and offset of rendered text`
+      | :sg:`get_rect(text, style=STYLE_DEFAULT, rotation=0, ptsize=default) -> rect`
+
+      Gets the final dimensions and origin, in pixels, of 'text' using the
+      current point size, style, rotation and orientation. These are either
+      taken from the arguments, if given, else from the default values set
+      for the face object.
+
+      Returns a rect containing the width and height of the text's bounding
+      box and the position of the text's origin. The origin can be used
+      to align separately rendered pieces of text. It gives the baseline
+      position and bearing at the start of the text.
+
+      If text is a char (byte) string, then its encoding is assumed to be
+      ``LATIN1``.
+
+   .. method:: get_metrics
+
+      | :sl:`Gets glyph metrics for the face's characters`
+      | :sg:`get_metrics(text, ptsize=default) -> [(...), ...]`
+
+      Returns the glyph metrics for each character in 'text'.
+
+      The glyph metrics are returned inside a list; each character will be
+      represented as a tuple inside the list with the following values:
+
+      ::
+
+          (min_x, max_x, min_y, max_y, horizontal_advance_x, horizontal_advance_y)
+
+      The bounding box min_x, max_y, min_y, and max_y values are returned as
+      grid-fitted pixel coordinates of type int. The advance values are 
+      float values.
+
+      The calculations are done using the face's default size in points.
+      Optionally you may specify another point size to use.
+
+      The metrics are adjusted for the current rotation, strong, and oblique
+      settings.
+
+      If text is a char (byte) string, then its encoding is assumed to be
+      ``LATIN1``.
+
+   .. attribute:: height
+
+      | :sl:`Gets the unscaled height of the face in font units`
+      | :sg:`height -> int`
+
+      Read only. Gets the height of the face. This is the average value of all
+      glyphs in the face.
+
+   .. method:: ascender
+
+      | :sl:`get the unscaled ascent of the face in font units`
+      | :sg:`ascender -> int`
+
+      Read only. Return the number of units from the face's baseline to
+      the top of the bounding box.
+
+   .. attribute:: descender
+
+      | :sl:`get the unscaled descent of the face in font units`
+      | :sg:`descender -> int`
+
+      Read only. Return the height in font units for the face descent.
+      The descent is the number of units from the face's baseline to the
+      bottom of the bounding box.
+
+   .. attribute:: get_sized_ascender
+
+      | :sl:`Gets the scaled ascent the face in pixels`
+      | :sg:`get_sized_ascender() -> int`
+
+      Return the number of units from the face's baseline to the top of the
+      bounding box. It is not adjusted for strong or rotation.
+
+   .. method:: get_sized_descender
+
+      | :sl:`Gets the scaled descent the face in pixels`
+      | :sg:`get_sized_descender() -> int`
+
+      Return the number of pixels from the face's baseline to the top of the
+      bounding box. It is not adjusted for strong or rotation.
+
+   .. attribute:: get_sized_height
+
+      | :sl:`Gets the scaled height of the face in pixels`
+      | :sg:`get_sized_height() -> int`
+
+      Read only. Gets the height of the face. This is the average value of all
+      glyphs in the face. It is not adjusted for strong or rotation.
+
+   .. method:: get_sized_glyph_height
+
+      | :sl:`Gets the scaled height of the face in pixels`
+      | :sg:`get_sized_glyph_height() -> int`
+
+      Return the glyph bounding box height of the face in pixels.
+      This is the average value of all glyphs in the face.
+      It is not adjusted for strong or rotation.
+
+   .. method:: render
+
+      | :sl:`Renders text on a surface`
+      | :sg:`render(text, fgcolor, bgcolor=None, style=STYLE_DEFAULT, rotation=0, ptsize=default) -> (Surface, Rect)`
+
+      Renturns a new :mod:`pygame.Surface`, with the text rendered to it
+      in the color given by 'fgcolor'. If ``bgcolor`` is given, the surface
+      will be filled with this color. If no background color is given,
+      the surface is filled with zero alpha opacity. Normally the returned
+      surface has a 32 bit pixel size. However, if ``bgcolor`` is ``None``
+      and antialiasing is disabled a two color 8 bit surface with colorkey
+      set for the background color is returned.
+
+      The return value is a tuple: the new surface and the bounding
+      rectangle giving the size and origin of the rendered text.
+
+      If an empty string is passed for text then the returned Rect is zero
+      width and the height of the face. If dest is None the returned surface is
+      the same dimensions as the boundary rect. The rect will test False.
+
+      The rendering is done using the face's default size in points and its
+      default style, without any rotation, and taking into account faces which
+      are set to be drawn vertically via the :meth:`Face.vertical` attribute.
+      Optionally you may specify another point size to use via the 'ptsize'
+      argument, a text rotation via the 'rotation' argument, or a new text
+      style via the 'style' argument.
+
+      If text is a char (byte) string, then its encoding is assumed to be
+      ``LATIN1``.
+
+   .. method:: render_to
+
+      | :sl:`Renders text to an existing surface`
+      | :sg:`render(surf, dest, text, fgcolor, bgcolor=None, style=STYLE_DEFAULT, rotation=0, ptsize=default) -> Rect`
+
+      Renders the string 'text' to a :mod:`pygame.Surface` 'surf',
+      using the color 'fgcolor'.
+
+      Argument 'dest' is an (x, y) surface coordinate pair. If either x
+      or y is not an integer it is converted to one if possible.
+      Any sequence, including Rect, for which the first two elements are
+      positions x and y is accepted.
+
+      If a background color is given, the surface is first filled with that
+      color. The text is blitted next. Both the background fill and text
+      rendering involve full alpha blits. That is, the alpha values of
+      both the foreground and background colors, as well as those of the
+      destination surface if it has per-pixel alpha.
+
+      The return value is a rectangle giving the size and position of the
+      rendered text within the surface.
+
+      If an empty string is passed for text then the returned Rect is zero
+      width and the height of the face. The rect will test False.
+
+      By default, the point size and style set for the face are used
+      if not passed as arguments. The text is unrotated unless a non-zero
+      rotation value is given.
+
+      If text is a char (byte) string, then its encoding is assumed to be
+      ``LATIN1``.
+
+   .. method:: render_raw
+
+      | :sl:`Renders text as a string of bytes`
+      | :sg:`render_raw(text, style=STYLE_DEFAULT, rotation=0, ptsize=default, invert=False) -> (bytes, (int, int))`
+
+      Like ``Face.render()`` but the tuple returned is an 8 bit
+      monochrome string of bytes and its size. The forground color is 255, the
+      background 0, useful as an alpha mask for a foreground pattern.
+
+   .. method:: render_raw_to
+
+      | :sl:`Renders text as a string of ints to an array`
+      | :sg:`render_raw_to(array, text, dest=None, style=STYLE_DEFAULT, rotation=0, ptsize=default, invert=False) -> (int, int)`
+
+      Render to an array object exposing an array struct interface. The array
+      must be two dimensional with integer items. The default dest value, None,
+      is equivalent to (0, 0).
+
+   .. attribute:: style
+
+      | :sl:`Gets or sets the face's style`
+      | :sg:`style -> int`
+
+      Gets or sets the default style of the Face. This default style will be
+      used for all text rendering and size calculations unless overriden
+      specifically in the \`render()` or \`get_size()` calls. The style value
+      may be a bitwise ``OR`` of one or more of the following constants:
+
+      ::
+
+          STYLE_NONE
+          STYLE_ITALIC
+          STYLE_BOLD
+          STYLE_UNDERLINE
+          STYLE_OBLIQUE
+          STYLE_STRONG
+	  STYLE_WIDE
+
+      These constants may be found on the FreeType constants module.
+      Optionally, the default style can be modified or obtained accessing the
+      individual style attributes (underline, oblique, strong).
+
+   .. attribute:: italic
+
+      | :sl:`Gets or sets the faces's italic style`
+      | :sg:`bold -> bool`
+
+      Gets or sets whether an italic face is used. This
+      default style value will be used for all text rendering and size
+      calculations unless overriden specifically in the \`render()` or
+      \`get_size()` calls, via the 'style' parameter.
+
+   .. attribute:: bold
+
+      | :sl:`Gets or sets the faces's italic style`
+      | :sg:`bold -> bool`
+
+      Gets or sets whether a bold face is used. This
+      default style value will be used for all text rendering and size
+      calculations unless overriden specifically in the \`render()` or
+      \`get_size()` calls, via the 'style' parameter.
+
+   .. attribute:: underline
+
+      | :sl:`Gets or sets the face's underline style`
+      | :sg:`underline -> bool`
+
+      Gets or sets whether the face will be underlined when drawing text. This
+      default style value will be used for all text rendering and size
+      calculations unless overriden specifically in the \`render()` or
+      \`get_size()` calls, via the 'style' parameter.
+
+   .. attribute:: strong
+
+      | :sl:`Gets or sets the face's strong style`
+      | :sg:`strong -> bool`
+
+      Gets or sets whether the face will be bold when drawing text. This
+      default style value will be used for all text rendering and size
+      calculations unless overriden specifically in the \`render()` or
+      \`get_size()` calls, via the 'style' parameter.
+
+   .. attribute:: oblique
+
+      | :sl:`Gets or sets the face's oblique style`
+      | :sg:`oblique -> bool`
+
+      Gets or sets whether the face will be rendered as oblique. This
+      default style value will be used for all text rendering and size
+      calculations unless overriden specifically in the \`render()` or
+      \`get_size()` calls, via the 'style' parameter.
+
+   .. attribute:: wide
+
+      | :sl:`Gets or sets the face's wide style`
+      | :sg:`wide -> bool`
+
+      Gets or sets whether the face will be stretched horizontally
+      when drawing text. It produces a result simular to font.Font's
+      bold. This style is only available for unrotated text.
+
+   .. attribute:: strength
+
+      | :sl:`Gets or sets the strength of the strong or wide styles`
+      | :sg:`strength -> float`
+
+      The amount by which a face glyph's size is enlarged for the
+      strong or wide transformations, as a fraction of the untransformed
+      size. For the wide style only the horizontal dimension is
+      increased. For strong text both the horizontal and vertical
+      dimensions are enlarged. A wide style of strength 1/12 is
+      equivalent to the font.Font bold style. The default is 1/36.
+
+   .. attribute:: underline_adjustment
+
+      | :sl:`Gets or sets an adjustment factor for the underline position`
+      | :sg:`underline_adjustment -> float`
+
+      Gets or sets a factor which, when positive, is multiplied with the
+      face's underline offset to adjust the underline position. A negative
+      value turns an underline into a strikethrough or overline. It is
+      multiplied with the ascender. Accepted values are between -2.0 and 2.0
+      inclusive. A value of 0.5 closely matches Tango underlining. A value of
+      1.0 mimics SDL_ttf.
+
+   .. attribute:: fixed_width
+
+      | :sl:`Gets whether the face is fixed-width`
+      | :sg:`fixed_width -> bool`
+
+      Read only. Returns whether this Face is a fixed-width (bitmap) face.
+
+      Note that scalable faces whose glyphs are all the same width (i.e.
+      monospace ``TTF`` fonts used for programming) are not considered fixed
+      width.
+
+   .. attribute:: antialiased
+
+      | :sl:`Face antialiasing mode`
+      | :sg:`antialiased -> bool`
+
+      Gets or sets the face's antialiasing mode. This defaults to ``True`` on
+      all faces, which are rendered with full 8 bit blending.
+
+      Setting this to ``False`` will enable monochrome rendering. This should
+      provide a small speed gain and reduce cache memory size.
+
+   .. attribute:: kerning
+
+      | :sl:`Character kerning mode`
+      | :sg:`kerning -> bool`
+
+      Gets or sets the face's kerning mode. This defaults to False on all
+      faces, which will be rendered by default without kerning.
+
+      Setting this to true will change all rendering methods to do kerning
+      between character pairs for surface size calculation and all
+      render operations.
+
+   .. attribute:: vertical
+
+      | :sl:`Face vertical mode`
+      | :sg:`vertical -> bool`
+
+      Gets or sets whether the face is a vertical face such as faces in fonts
+      representing Kanji glyphs or other styles of vertical writing.
+
+      Changing this attribute will cause the face to be rendering vertically,
+      and affects all other methods which manage glyphs or text layouts to use
+      vertical metrics accordingly.
+
+      Note that the FreeType library doesn't automatically detect whether a
+      face contains glyphs which are always supposed to be drawn vertically, so
+      this attribute must be set manually by the user.
+
+      Also note that several face formats (specially bitmap based ones) don't
+      contain the necessary metrics to draw glyphs vertically, so drawing in
+      those cases will give unspecified results.
+
+   .. attribute:: origin
+
+      | :sl:`Face render to text origin mode`
+      | :sg:`vertical -> bool`
+
+      If set True, then when rendering to an existing surface, the position
+      is taken to be that of the text origin. Otherwise the render position is
+      the top-left corner of the text bounding box.
+
+   .. attribute:: pad
+
+      | :sl:`padded boundary mode`
+      | :sg:`pad -> bool`
+
+      If set True, then the text boundary rectangle will be inflated to match
+      that of font.Font. Otherwise, the boundary rectangle is just large
+      enough for the text.
+
+   .. attribute:: ucs4
+
+      | :sl:`Enables UCS-4 mode`
+      | :sg:`ucs4 -> bool`
+
+      Gets or sets the decoding of Unicode textdecoding. By default, the
+      freetype module performs UTF-16 surrogate pair decoding on Unicode text.
+      This allows 32-bit escape sequences ('\Uxxxxxxxx') between 0x10000 and
+      0x10FFFF to represent their corresponding UTF-32 code points on Python
+      interpreters built with a UCS-2 unicode type (on Windows, for instance).
+      It also means character values within the UTF-16 surrogate area (0xD800
+      to 0xDFFF) are considered part of a surrogate pair. A malformed surrogate
+      pair will raise an UnicodeEncodeError. Setting ucs4 True turns surrogate
+      pair decoding off, letting interpreters with a UCS-4 unicode type access
+      the full UCS-4 character range.
+
+   .. attribute:: resolution
+
+      | :sl:`Output pixel resolution in dots per inch`
+      | :sg:`resolution -> int`
+
+      Gets the pixel size used in scaling face glyphs for this Face instance.
 import pygame.surflock
 import pygame.color
 Color = color.Color
+import pygame._view
+
 __version__ = ver
 
 #next, the "standard" modules
     import pygame.mac_scrap
     import pygame.bufferproxy
     import pygame.colordict
+    import pygame._view
 
 #make Rects pickleable
 try:

lib/_numpysurfarray.py

                   rint as numpy_rint, uint32 as numpy_uint32, \
                   ndarray as numpy_ndarray
 
-numpy_floats = [numpy.float, numpy.float32, numpy.float64, numpy.float96]
+#float96 not available on all numpy versions.
+numpy_floats = []
+for type_name in "float float32 float64 float96".split():
+    if hasattr(numpy, type_name):
+        numpy_floats.append(getattr(numpy, type_name))
+
 
 def blit_array (surface, array):
     """pygame.surfarray.blit_array(Surface, array): return None
            step = step - 1
            if c == black:
                maskitem = maskitem | 1
+               fillitem = fillitem | 1
            elif c == white:
                maskitem = maskitem | 1
-               fillitem = fillitem | 1
            elif c == xor:
                fillitem = fillitem | 1
            if not step:
 """Enhanced Pygame module for loading and rendering font faces"""
 
 from pygame._freetype import *
+from pygame.sysfont import SysFont as _SysFont, match_font, get_fonts
 
 def SysFont(name, size, bold=0, italic=0, constructor=None):
     """pygame.ftfont.SysFont(name, size, bold=False, italic=False, constructor=None) -> Font
     return _SysFont(name, size, bold, italic, constructor)
 
 
+class Family(object):
+
+    def __init__(self, name, style=STYLE_NONE):
+        self._italic = bool(style & STYLE_ITALIC)
+        self._bold = bool(style & STYLE_BOLD)
+        self._path = match_font(name, self._italic, self._bold)
+        if self._path is None:
+            raise error("Font family not found")
+        self._cache = {(self._italic, self._bold): self._path}
+
+    def __get_name(self):
+        pass
+
+    name = property(__get_name, None, None, "type str")
+
+    def __get_path(self):
+        pass
+
+    path = property(__get_path, None, None, "type str")
+
+    def __get_style(self):
+        pass
+
+    def __set_style(self, value):
+        pass
+
+    style = property(__get_style, __set_style, None, "type bool")
+
+    def __get_italic(self):
+        pass
+
+    def __set_italic(self, value):
+        pass
+
+    italic = property(__get_italic, __set_italic, None, "type bool")
+
+    def __get_bold(self):
+        pass
+
+    def __set_bold(self, value):
+        pass
+
+    bold = property(__get_bold, __set_bold, None, "type bool")
+
+    def __get_underline(self):
+        pass
+
+    def __set_underline(self, value):
+        pass
+
+    underline = property(__get_underline, __set_underline, None, "type bool")
+
+    def __get_oblique(self):
+        pass
+
+    def __set_oblique(self, value):
+        pass
+
+    oblique = property(__get_oblique, __set_oblique, None, "type bool")
+
+    def __get_strong(self):
+        pass
+
+    def __set_strong(self, value):
+        pass
+
+    strong = property(__get_strong, __set_strong, None, "type bool")
+
+    def __get_wide(self):
+        pass
+
+    def __set_wide(self, value):
+        pass
+
+    wide = property(__get_wide, __set_wide, None, "type bool")
+
+    def __get_strength(self):
+        pass
+
+    def __set_strength(self, value):
+        pass
+
+    strength = property(__get_strength, __set_strength, None, "type float")
+
+    def __get_underline_adjustment(self):
+        pass
+
+    def __set_underline_adjustment(self, value):
+        pass
+
+    underline_adjustment = property(__get_underline_adjustment,
+                                    __set_underline_adjustment,
+                                    None,
+                                    "type float")
+
+    def __get_fixed_width(self):
+        pass
+
+    fixed_width = property(__get_fixed_width, None, None, "type bool")
+
+    def __get_antialiased(self):
+        pass
+
+    def __set_antialiased(self, value):
+        pass
+
+    antialiased = property(__get_antialiased,
+                           __set_antialiased,
+                           None,
+                           "type bool")
+
+    def __get_kerning(self):
+        pass
+
+    def __set_kerning(self, value):
+        pass
+
+    kerning = property(__get_kerning, __set_kerning, None, "type bool")
+
+    def __get_vertical(self):
+        pass
+
+    def __set_vertical(self, value):
+        pass
+
+    vertical = property(__get_vertical, __set_vertical, None, "type bool")
+
+    def __get_origin(self):
+        pass
+
+    def __set_origin(self, value):
+        pass
+
+    origin = property(__get_origin, __set_origin, None, "type bool")
+
+    def __get_pad(self):
+        pass
+
+    def __set_pad(self, value):
+        pass
+
+    pad = property(__get_pad, __set_pad, None, "type bool")
+
+    def __get_ucs4(self):
+        pass
+
+    def __set_ucs4(self, value):
+        pass
+
+    ucs4 = property(__get_ucs4, __set_ucs4, None, "type bool")
+
+    def __get_height(self):
+        pass
+
+    height = property(__get_height, None, None, "type int")
+
+    def __get_ascender(self):
+        pass
+
+    ascender = property(__get_ascender, None, None, "type int")
+
+    def __get_descender(self):
+        pass
+
+    descender = property(__get_descender, None, None, "type int")
+
+    def __get_resolution(self):
+        pass
+
+    resolution = property(__get_resolution, None, None, "type int")
+
+    def get_rect(text, style=STYLE_DEFAULT, rotation=0, ptsize=default):
+        pass
+
+    def get_metrics(text, ptsize=default):
+        pass
+
+    def get_sized_ascender():
+        pass
+
+    def get_sized_descender():
+        pass
+
+    def get_sized_height():
+        pass
+
+    def get_sized_glyph_height():
+        pass
+
+    def render(text,
+               fgcolor,
+               bgcolor=None,
+               style=STYLE_DEFAULT,
+               rotation=0,
+               ptsize=default):
+        pass
+
+    def render_to(dest,
+                  text,
+                  fgcolor,
+                  bgcolor=None,
+                  style=STYLE_DEFAULT,
+                  rotation=0,
+                  ptsize=default):
+        pass
+
+    def render_raw(text,
+                   style=STYLE_DEFAULT,
+                   rotation=0,
+                   ptsize=default,
+                   invert=False):
+        pass
+
+    def render_raw_to(array,
+                      text,
+                      dest=None,
+                      style=STYLE_DEFAULT,
+                      rotation=0,
+                      ptsize=default,
+                      invert=False):
+        pass
         ignore, dest = os.path.split(src)
     if src == dest:
         raise IOError("%s: Source and destination are identical" % src)
-    mkdir(dest)
+    makedirs(dest)
     for name in os.listdir(src):
         src_path = os.path.join(src, name)
         if os.path.isfile(src_path):
 
 created_dirs = set()
 
-def mkdir(path):
+def makedirs(path):
     path = os.path.abspath(path)
     if path in created_dirs:
         pass
     elif not os.path.exists(path):
-        os.mkdir(path)
+        os.makedirs(path)
         created_dirs.add(path)
     elif not os.path.isdir(path):
         raise MakePrebuiltError("%s is not a directory" % path)
     if not force and os.path.isdir(dest_dir):
         if not confirm("Directory %s already exists;\ncontinue" % dest_dir):
             return 1
-    mkdir(dest_dir)
+    makedirs(dest_dir)
     if not src_dir:
         try:
             m = msys.Msys()
     prebuilt_template = os.path.abspath('prebuilt-template')
     dest_lib_dir = os.path.join(dest_dir, lib_subdir)
     
+    # msvcr71.dll or msvcr90.dll linking support.
+    src_msvcr71_dir = os.path.join(src_dir, 'lib', 'msvcr71')
+    have_msvcr71 = os.path.isdir(src_msvcr71_dir)
+    src_msvcr90_dir = os.path.join(src_dir, 'lib', 'msvcr90')
+    have_msvcr90 = os.path.isdir(src_msvcr90_dir)
+    if have_msvcr71 and have_msvcr90:
+        print_("Conflicting builds: "
+               "found both msvcr71.dll and msvcr90.dll linkage")
+        return 1
+    if have_msvcr71:
+        dest_msvcr71_dir = os.path.join(dest_dir, 'lib', 'msvcr71')
+        copy_dir(src_msvcr71_dir, dest_msvcr71_dir)
+    elif have_msvcr90:
+        dest_msvcr90_dir = os.path.join(dest_dir, 'lib', 'msvcr90')
+        copy_dir(src_msvcr90_dir, dest_msvcr90_dir)
+
     # Read setup file.
     src_file = os.path.join(prebuilt_template, 'Setup_Win.in')
     file_copy(src_file, dest_dir)
             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)
+                makedirs(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)
+    makedirs(dest_lib_dir)
     for ignore, libs in macros:
         use = False
         for lib in libs:
                 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)
+                    makedirs(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)
             os.path.join(src_dir, 'include', 'SDL', 'SDL_config_win32.h'),
             os.path.join(dest_dir, 'include', 'SDL', 'SDL_config.h'))
 
-    # 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:
 
 """MSYS specifics for Msys terminal IO and for running shell scripts
 
-Configured for MSYS 1.0.13.
+Configured for MSYS 1.0.17.
 
 exports msys_raw_input, MsysException, Msys
 
     def encode_script(s):
         return s
 
-FSTAB_REGEX = (r'^[ \t]*(?P<path>'
-               r'([a-zA-Z]:){0,1}([\\/][^\s*^?:%\\/]+)+)'
+FSTAB_REGEX = (r'^[ \t]*'
+               r'(?P<path>([a-zA-Z]:)?[^\s*^?:%]+)'
                r'[ \t]+/mingw(\s|$)'
                )
 
     """
     
     #!! Leave until known if new MSYS package manager makes a registry entry.
-    
-    subkey = (
-        'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MSYS-1.0_is1')
-    try:
-        key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey)
+    subkey = ('Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall'
+              '\\{AC2C1BDB-1E91-4F94-B99C-E716FE2E9C75}_is1')
+    for hkey in [_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE]:
         try:
-            return _winreg.QueryValueEx(key, 'Inno Setup: App Path')[0].encode()
-        finally:
-            key.Close()
-    except WindowsError:
-        raise LookupError("MSYS not found in the registry")
-
+            key = _winreg.OpenKey(hkey, subkey)
+            try:
+                mingw_path = _winreg.QueryValueEx(key, 'Inno Setup: App Path')[0].encode()
+            finally:
+                key.Close()
+        except WindowsError:
+            pass
+        else:
+            return os.path.join(mingw_path, 'msys', '1.0')
+    raise LookupError("MSYS not found in the registry")
+        
 def as_shell(msys_root):
     """Append MSYS shell program to MSYS root directory path"""
 
                        doc="True if the execution environment is MSYS")
 
     def windows_to_msys(self, path):
-        """Return an MSYS translation of an absolute Windows path
+        """Return an MSYS translation of a Windows path
 
         """
         
+        path = os.path.abspath(path)
         msys_root = self.msys_root
         mingw_root = self.mingw_root
         path_lower = path.lower()
         if mingw_root is not None and path_lower.startswith(mingw_root.lower()):
             return '/mingw' + path[len(mingw_root):].replace(os.sep, '/')
         drive, tail = os.path.splitdrive(path)
-        tail = tail.replace(os.sep, '/')
-        return '/%s%s' % (drive[0], tail)
+        drive_mount_point = drive[0].lower()
+        drive_subpath = tail.replace(os.sep, '/')
+        return '/%s%s' % (drive_mount_point, drive_subpath)
 
     def msys_to_windows(self, path):
         """Return a Windows translation of an MSYS path

msys_build_deps.py

   PREFIX - Destination directory
   MSYS_ROOT_DIRECTORY - MSYS home directory (may omit 1.0 subdirectory)
   CPPFLAGS - preprocessor options, appended to options set by the program
-  LDFLAGS - linker options - prepended to flags set by the program
-  CPATH - C/C++ header file paths - appended to the paths used by this program
+  CFLAGS - compiler flags, appended to options set by the program
+  LDFLAGS - linker options, prepended to flags set by the program
 
 To get a list of command line options run
 
 
 This program has been tested against the following libraries:
 
-SDL 1.2.14 
-SDL_image 1.2.10
-SDL_mixer 1.2.11 and revision 6ed75d34edc9 tip from hg
-SDL_ttf 2.0.9
-smpeg revision 389 from SVN
-freetype 2.3.12
-libogg 1.2.0
-libvorbis 1.3.1
+SDL 1.2(.14+) hg changeset c5d651a8b679
+SDL_image 1.2(.10+) hg changset 45748e6e2f81
+SDL_mixer 1.2.12 hg changeset b455bc681654
+SDL_ttf 2.0.11 hg changeset d9a600fa3c4a
+smpeg SVN revision 391 (built separately with MSVC++)
+freetype 2.4.8
+libogg 1.3.0
+libvorbis 1.3.2
 FLAC 1.2.1
-mikmod 3.1.12 patched (included with SDL_mixer 1.2.11)
-tiff 3.9.4
-libpng 1.4.3
-jpeg 8b
+mikmod 3.1.12 patched (included with SDL_mixer 1.2.12)
+tiff 4.0b7
+libpng 1.6.0b1
+jpeg 8c
 zlib 1.2.5
-PortMidi revision 201 from SVN
-ffmpeg revision 24482 from SVN (swscale revision 31785)
+PortMidi revision 217 from SVN
+untested with GCC 4.6.1: ffmpeg revision 24482 from SVN (swscale revision 31785)
 
 The build environment used: 
 
-GCC 4.5.0
-MSYS 1.0.13
+GCC 4.6.1
+MSYS 1.0.17
 dx7 headers
-yasm 1.0.1
-
-see mingw_installer.py and msys_installer.py
+yasm 1.2.0
 
 
 The build has been performed on Windows XP, SP3.
         return '-L' + p
     return ''
 
+def as_linker_option(p):
+    """Return as an ld library path argument"""
+    
+    if p:
+        return '-Wl,' + p
+    return ''
+
+def as_preprocessor_header_path(p):
+    """Return as a C preprocessor header include path argument"""
+    
+    if p:
+        return '-I' + p
+    return ''
+
+def as_macro_define(m, v):
+    """Return as a C preprocessor command line macro definition"""
+    
+    if v:
+        return '-D%s=%s' % (m, v)
+    return '-D%s' % (m,)
+        
 def merge_strings(*args, **kwds):
     """Returns non empty string joined by sep
 
     sep = kwds.get('sep', '')
     return sep.join([s for s in args if s])
 
+def get_python_msvcrt_version():
+    """Return the Visual C runtime version Python is linked to, as an int"""
+    
+    python_version = sys.version_info[0:2]
+    if python_version < (2.4):
+        return 60
+    if python_version < (2.6):
+        return 71
+    return 90
+    
 class BuildError(Exception):
     """Raised for missing source paths and failed script runs"""
     pass
 
     def build(self, msys):
         if self.path is not None:
-            msys.environ['BDWD'] = msys.windows_to_msys(self.path)
-            return_code = msys.run_shell_script(self.shell_script)
+            env_home = msys.environ.get('HOME', None)
+            msys.environ['HOME'] = self.path
+            try:
+                return_code = msys.run_shell_script(self.shell_script)
+            finally:
+                if env_home is not None:
+                    msys.environ['HOME'] = env_home
+                else:
+                    del msys.environ['HOME']
             if return_code != 0:
                 raise BuildError("The build for %s failed with code %d" %
                                  (self.name, return_code))
             raise BuildError("Preparation '%s' failed with code %d" %
                              (self.name, return_code))
 
-def configure(dependencies):
+def configure(dependencies, hunt_paths):
     """Find source directories of all dependencies"""
     
     success = True
              "no more user input is required. The build process will"
              "abort on the first error, as library build order is important.\n"
              "\n"
-             "See --include and --help-args.\n"
+             "See --help-args.\n"
              "\n"
              "For more details see the program's document string\n")
     
     parser.add_option('-a', '--all', action='store_true', dest='build_all',
                       help="Include all libraries in the build")
     parser.set_defaults(build_all=False)
-    parser.add_option('--no-msvcr71', action='store_false', dest='msvcr71',
-                      help="Do not link to msvcr71.dll")
-    parser.set_defaults(msvcr71=True)
+    parser.add_option('--msvcr-version', action='store', dest='msvcrt_version',
+                      type='choice', choices=['60', '71', '90'],
+                      help="Visual C runtime library version")
+    parser.set_defaults(msvcrt_version=get_python_msvcrt_version())
     parser.add_option('--no-configure', action='store_false', dest='configure',
                       help="Do not prepare the makefiles")
     parser.set_defaults(configure=True)
                       help="MSYS directory path, which may include"
                            " the 1.x subdirectory")
     parser.set_defaults(msys_directory='')
+    parser.add_option('-s', '--sources', action='store',
+                      dest='sources',
+                      help="Paths to search for library source directories"
+                           " as a semicolon ';' separated list: defaults to %s"
+                           % (';'.join(hunt_paths),))
     parser.add_option('-p', '--prefix', action='store',
                       dest='prefix',
-                      help="Destination directory of the build: defaults to MSYS %s)"
+                      help="Destination directory of the build: defaults to MSYS %s"
                            % (default_prefix_mp,))
     parser.set_defaults(prefix='')
     parser.add_option('--help-args', action='store_true', dest='arg_help',
     """Set the environment variables used by the scripts"""
     
     environ = msys.environ
+
     msys_root_wp = msys.msys_root
     prefix_wp = options.prefix
     if not prefix_wp:
     else:
         prefix_mp = default_prefix_mp
         prefix_wp = msys.msys_to_windows(prefix_mp)
+    include_mp = prefix_mp + '/include'
+    lib_mp = prefix_mp + '/lib'
+    subsystem = ''
+    if not options.subsystem_noforce:
+        subsystem = '-mwindows'
+    msvcrt_mp = ''
+    resources_mp = ''
+    if options.msvcrt_version == 71:
+        # Hide the msvcrt.dll import libraries with those for msvcr71.dll.
+        # Their subdirectory is in the same directory as the SDL library.
+        msvcrt_mp = lib_mp + '/msvcr71'
+    elif options.msvcrt_version == 90:
+        # Hide the msvcrt.dll import libraries with those for msvcr90.dll.
+        # Their subdirectory is in the same directory as the SDL library.
+        msvcrt_mp = lib_mp + '/msvcr90'
+        resources_mp = msvcrt_mp + '/resources.o'
+
     environ['PREFIX'] = prefix_mp
+    environ.pop('INCLUDE', None)  # INCLUDE causes problems with MIXER.
+    environ['CPPFLAGS'] = merge_strings(as_macro_define('__MSVCRT_VERSION__',
+                                                       '0x0%02i0' % (options.msvcrt_version,)),
+                                        as_preprocessor_header_path(include_mp),
+                                        environ.get('CPPFLAGS', ''),
+                                        sep=' ')
+    # Need to make the resources object file an explicit linker option to
+    # bypass libtool (freetype).
+    environ['LDFLAGS'] = merge_strings(as_linker_lib_path(msvcrt_mp),
+                                       environ.get('LDFLAGS', ''),
+                                       as_linker_lib_path(lib_mp),
+                                       as_linker_option(resources_mp),
+                                       subsystem,
+                                       sep=' ')
+
     environ['BDCONF'] = as_flag(options.configure and
                                 not options.clean_only)
     environ['BDCOMP'] = as_flag(options.compile and
                                  options.strip and
                                  not options.clean_only)
     environ['BDCLEAN'] = as_flag(options.clean or options.clean_only)
-    environ.pop('INCLUDE', None)  # INCLUDE causes problems with MIXER.
-    lib_mp = prefix_mp + '/lib'
-    msvcr71_mp = ''
-    if options.msvcr71:
-        # Hide the msvcrt.dll import libraries with those for msvcr71.dll.
-        # Their subdirectory is in the same directory as the SDL library.
-        msvcr71_mp = lib_mp + '/msvcr71'
-        environ['DBMSVCR71'] = msvcr71_mp
-    subsystem = ''
-    if not options.subsystem_noforce:
-        subsystem = '-mwindows'
-    environ['LDFLAGS'] = merge_strings(environ.get('LDFLAGS', ''),
-                                       as_linker_lib_path(lib_mp),
-                                       as_linker_lib_path(msvcr71_mp),
-                                       subsystem,
-                                       sep=' ')
-
-    # For dependency headers.
-    include_wp = prefix_wp + '/include'
-    environ['CPATH'] = merge_strings(include_wp, environ.get('CPATH', ''),
-                                     sep=';')
+    environ['BDRESOURCES'] = resources_mp
+    environ['BDMSVCRT_VERSION'] = '%i' % (options.msvcrt_version,)
+    environ['BDMSVCRT'] = msvcrt_mp
 
 class ChooseError(Exception):
     """Failer to select dependencies"""
                 msg = "Internal error: unknown library type %s" % (lib,)
             print_("  %-10s: %s" % (d.name, msg))
     
-def main(dependencies, msvcr71_preparation, msys_preparation):
+def main(dependencies, msvcr71_preparation, msvcr90_preparation, msys_preparation):
     """Build the dependencies according to the command line options."""
 
     options, args = command_line()
             print_("No libraries specified.")
         elif options.build_all:
             print_("All libraries excluded")
-    if options.msvcr71:
+    if options.msvcrt_version == 71 and not options.clean_only:
         chosen_deps.insert(0, msvcr71_preparation)
         print_("Linking to msvcr71.dll.")
+    elif options.msvcrt_version == 90 and not options.clean_only:
+        chosen_deps.insert(0, msvcr90_preparation)
     else:
-        print_("Linking to MinGW default C runtime library.")
-    if chosen_deps:
+        print_("Linking to C runtime library msvcrt.dll.")
+    if chosen_deps and not options.clean_only:
         chosen_deps.insert(0, msys_preparation)
     try:
         m = msys.Msys(options.msys_directory)
     start_time = None
     return_code = 1
     set_environment_variables(m, options)
-    print_("Destination directory:",
-           m.msys_to_windows(m.environ['PREFIX']).replace('/', os.sep))
+    if not options.clean_only:
+        print_("Destination directory:",
+               m.msys_to_windows(m.environ['PREFIX']).replace('/', os.sep))
     print_("common CPPFLAGS:", m.environ.get('CPPFLAGS', ''))
     print_("common CFLAGS:", m.environ.get('CFLAGS', ''))
     print_("common LDFLAGS:", m.environ.get('LDFLAGS', ''))
+    sources = hunt_paths
+    if options.sources:
+        sources = options.sources.split(';')
+    print_("library source directories search paths: %s" % (';'.join(sources),))
     try:
-        configure(chosen_deps)
+        configure(chosen_deps, sources)
     except BuildError:
         print_("Build aborted:", geterror())
     else:
-        print_("\n=== Starting build ===")
+        if options.clean_only:
+            print_("\n=== Performing clean ===")
+        else:
+            print_("\n=== Starting build ===")
         start_time = time.time()  # For file timestamp checks.
         try:
             build(chosen_deps, m)
         else:
             # A successful build!
             return_code = 0
-    summary(dependencies, m, start_time, chosen_deps)
+    if not options.clean_only:
+        summary(dependencies, m, start_time, chosen_deps)
 
     # MinGW configure file for setup.py (optional).
     try:
 # represent configure, compile, install and clean respectively. When '1' the
 # corresponding action is performed. When '0' it is skipped. The installation
 # directory is given by PREFIX. The script needs to prepend it to PATH. The
-# source code root directory is DBWD. A script will cd to it before doing
-# starting the build. Various gcc flags are in CPATH, CPPFLAGS, CFLAGS and
-# LDFLAGS.
+# script's HOME directory is the source code root directory. The msvcrt version
+# is given as BDMSVCRT_VERSION. BDMSVCRT is where to place a shadow libraries
+# which hide the normal MinGW C runtime export libraries. Various gcc flags are
+# in CPPFLAGS, CFLAGS, and LDFLAGS. INCLUDE is undefined.
 #
 # None of these scripts end with an "exit". Exit, possibly, leads to Msys
 # freezing on some versions of Windows (98).
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
   # Remove NONAMELESSUNION from directx.h headers.
     BDDXHDR=
   done
 
-  # If this comes from SVN it has no configure script
+  # If this comes from the repository it has no configure script
   if [ ! -f "./configure" ]; then
     ./autogen.sh
   fi
   # Prevent libtool deadlocks (maybe).
-  ./configure --disable-libtool-lock --prefix="$PREFIX" LDFLAGS="$LDFLAGS"
+  ./configure --disable-libtool-lock --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
   
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
 if [ x$BDINST == x1 ]; then
   make install
   # Make SDL_config_win32.h available for prebuilt and MSVC
-  cp -f "$BDWD/include/SDL_config_win32.h" "$PREFIX/include/SDL"
+  cp -f "$HOME/include/SDL_config_win32.h" "$PREFIX/include/SDL"
 fi
 
 if [ x$BDSTRIP == x1 ]; then
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
   cp -fp win32/Makefile.gcc .
 fi
 
 if [ x$BDCOMP == x1 ]; then
-  # Build with the import library renamed, using asm code, our CFLAGS
-  # and LDFLAGS.
-  make IMPLIB=libz.dll.a CFLAGS="$CFLAGS" LOC="-DASMV $LDFLAGS" \
-    OBJA=match.o -fMakefile.gcc
+  # Build with the import library renamed, using asm code, our CPPFLAGS,
+  # CFLAGS, and LDFLAGS (passed in as LOC).
+  make IMPLIB=libz.dll.a OBJA=match.o -fMakefile.gcc
+       CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LOC="-DASMV $LDFLAGS"
 fi
 
 if [ x$BDINST == x1 ]; then
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
-  ./configure --prefix="$PREFIX" LDFLAGS="$LDFLAGS"
+  ./configure --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
   
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' builds/unix/config.log`" != x ]; then
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
-  ./configure --prefix="$PREFIX" LDFLAGS="$LDFLAGS"
+  # If this comes from the repository it has no configure script
+  if [ ! -f "./configure" ]; then
+    ./autogen.sh
+  fi
+
+  ./configure --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
   
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
   make clean
 fi
 """),
-    Dependency('PNG', ['l*png*[1-9][1-9.]*'], ['libpng14.dll'], """
+    Dependency('PNG', ['l*png*[1-9][1-9.]*'], ['libpng16-16.dll'], """
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
-  # Use the provided MinGW makefile.
-  cp -fp scripts/Makefile.mingw .
+  ./configure --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
+  
+  # check for MSYS permission errors
+  if [ x"`grep 'Permission denied' config.log`" != x ]; then
+      echo '**** MSYS problems; build aborted.'
+      exit 1
+  fi
 fi
 
 if [ x$BDCOMP == x1 ]; then
-  make -fMakefile.mingw prefix="$PREFIX" \
-       MINGW_CCFLAGS="-I$PREFIX/include $CFLAGS" MINGW_LDFLAGS="$LDFLAGS"
+  make
 fi
 
 if [ x$BDINST == x1 ]; then
-  make install -fMakefile.mingw prefix="$PREFIX"
+  make install
 fi
 
 if [ x$BDSTRIP == x1 ]; then
-  strip --strip-all "$PREFIX/bin/libpng14.dll"
+  strip --strip-all "$PREFIX/bin/libpng16-16.dll"
 fi
 
 if [ x$BDCLEAN == x1 ]; then
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
   # This will only build a static library.
-  ./configure --prefix="$PREFIX" LDFLAGS="$LDFLAGS"
+  ./configure --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
   
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
   make clean
 fi
 """),
-    Dependency('TIFF', ['tiff-[3-9].*'], ['libtiff-3.dll'], """
+    Dependency('TIFF', ['tiff-[3-9].*'], ['libtiff-5.dll'], """
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
+
+# Only build the library; the tools can be built, but do not install
+# for msvcr90.dll because of a strange linker error.
+bd_subdirs="port libtiff"
+
 
 if [ x$BDCONF == x1 ]; then
-  ./configure --disable-cxx --prefix="$PREFIX" LDFLAGS="$LDFLAGS"
+  ./configure --disable-cxx --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
   
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
 fi
 
 if [ x$BDCOMP == x1 ]; then
-  make
+  make SUBDIRS="$bd_subdirs"
 fi
 
 if [ x$BDINST == x1 ]; then
-  make install
+  make install SUBDIRS="$bd_subdirs"
 fi
 
 if [ x$BDSTRIP == x1 ]; then
-  strip --strip-all "$PREFIX/bin/libtiff-3.dll"
+  strip --strip-all "$PREFIX/bin/libtiff-5.dll"
 fi
 
 if [ x$BDCLEAN == x1 ]; then
   set +e
-  make clean
-  rm -f libtiff/libtiff.dll.a
-  rm -f libtiff/libtiff.dll
+  make clean SUBDIRS="$bd_subdirs"
+  rm -f libtiff.dll.a
+  rm -f libtiff.dll
 fi
 """),
     Dependency('IMAGE', ['SDL_image-[1-9].*'], ['SDL_image.dll'], """
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
-  # Disable dynamic loading of image libraries as that uses the wrong DLL
-  # search path. --disable-libtool-lock: Prevent libtool deadlocks (maybe).
+  # If this comes from the repository it has no configure script
+  if [ ! -f "./configure" ]; then
+    ./autogen.sh
+  fi
+
+  # configure searches for the JPEG dll. Unfortunately it uses the wrong file
+  # name. Correct this.
+  mv configure configure~
+  sed -e 's|jpeg\.dll|libjpeg-*.dll|' configure~ >configure
+  
+  # Add the destination bin directory to the library search path so
+  # configure can find its precious DLL files.
+  export LDFLAGS="$LDFLAGS -L$PREFIX/bin"
+  
+  # Add path to PNG headers
+  CPPFLAGS="$CPPFLAGS `$PREFIX/bin/libpng-config --I_opts`"
+  
+  # Disable dynamic loading of image libraries as it uses the wrong DLL
+  # search path: does not check in the same directory.
+  #  --disable-libtool-lock: Prevent libtool deadlocks (maybe).
   ./configure --disable-jpg-shared --disable-png-shared --disable-tif-shared \
-              --disable-libtool-lock \
-              --prefix="$PREFIX" LDFLAGS="$LDFLAGS"
+              --disable-libtool-lock --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
   
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
 """),
     Dependency('SMPEG', ['smpeg-[0-9].*', 'smpeg'], ['smpeg.dll'], """
 
+if (( $BDMSVCRT_VERSION != 60 )); then
+    echo The smpeg build has been disabled\\.
+    exit 0
+fi
+
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
   # This comes straight from SVN so has no configure script
     ./autogen.sh
   fi
 
-  # Don't need the toys.
-  ./configure --disable-gtk-player --disable-opengl-player \
-              --prefix="$PREFIX" \
-              LDFLAGS="-static-libstdc++ -static-libgcc $LDFLAGS"
-  
+  # Don't need the toys. Disable dynamic linking of libgcc and libstdc++
+  ./configure --disable-gtk-player --disable-opengl-player --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
+              
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
       echo '**** MSYS problems; build aborted.'
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
-  ./configure --prefix="$PREFIX" LDFLAGS="$LDFLAGS"
+  ./configure --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
   
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
-  ./configure --prefix="$PREFIX" LDFLAGS="$LDFLAGS" LIBS='-logg'
-  
+  ./configure --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" LIBS='-logg'
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
       echo '**** MSYS problems; build aborted.'
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
   # Add __MINGW32__ to SIZE_T_MAX declaration test in alloc.h header.
 
   # Will only install a static library, but that is all that is needed.
   ./configure --disable-shared --disable-ogg --disable-cpplibs \
-    --disable-doxygen-docs --prefix="$PREFIX" LDFLAGS="$LDFLAGS"
+    --disable-doxygen-docs --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
   
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
-  cat > win32/Makefile.static.mingw << 'THE_END'
-# MinGW Makefile adapted from template for use under win32
-#
-# libmikmod subdirectory
-
-# Your compiler here
-CC=gcc
-# Compiler flags
-CPPFLAGS_MIKMOD=-c -DWIN32 -DDRV_DS -DDRV_WIN -DHAVE_FCNTL_H -DHAVE_MALLOC_H -DHAVE_LIMITS_H $(CPPFLAGS)
-COMPILE=$(CC) $(CPPFLAGS_MIKMOD) -I../include -I.. -I../win32 $(CFLAGS)
-
-.SUFFIXES:
-.SUFFIXES: .o .c
-
-LIBNAME=libmikmod.a
-
-LIBS=$(LIBNAME)
-
-DRIVER_OBJ=drv_ds.o drv_win.o
-
-OBJ=$(DRIVER_OBJ) \\
-    drv_nos.o drv_raw.o drv_stdout.o drv_wav.o \\
-    load_669.o load_amf.o load_dsm.o load_far.o load_gdm.o load_it.o  \\
-    load_imf.o load_m15.o load_med.o load_mod.o load_mtm.o load_okt.o \\
-    load_s3m.o load_stm.o load_stx.o load_ult.o load_uni.o load_xm.o \\
-    mmalloc.o mmerror.o mmio.o \\
-    mdriver.o mdreg.o mloader.o mlreg.o mlutil.o mplayer.o munitrk.o mwav.o \\
-    npertab.o sloader.o virtch.o virtch2.o virtch_common.o
-
-all:            $(LIBS)
-
-clean:
-\tfor f in $(LIBS) ; do rm -f $f; done
-\trm -f *.o
-
-distclean:
-\trm -f ../include/mikmod.h
-
-install:
-\tcp -fp libmikmod.a "$(PREFIX)/lib"
-\tcp -fp ../include/mikmod.h "$(PREFIX)/include"
-\tcp -fp ../libmikmod-config "$(PREFIX)/bin"
-
-$(LIBNAME):     $(OBJ)
-\tar -r $(LIBNAME) *.o
-\tranlib $(LIBNAME)
-
-../include/mikmod.h ../win32/mikmod_build.h:\tmikmod_build.h
-\tcp -f mikmod_build.h ../win32/mikmod_build.h
-\tcp -f mikmod_build.h ../include/mikmod.h
-
-drv_ds.o:       ../drivers/drv_ds.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../drivers/drv_ds.c
-drv_nos.o:      ../drivers/drv_nos.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../drivers/drv_nos.c
-drv_raw.o:      ../drivers/drv_raw.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../drivers/drv_raw.c
-drv_stdout.o:   ../drivers/drv_stdout.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../drivers/drv_stdout.c
-drv_wav.o:      ../drivers/drv_wav.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../drivers/drv_wav.c
-drv_win.o:       ../drivers/drv_win.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../drivers/drv_win.c
-load_669.o:     ../loaders/load_669.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_669.c
-load_amf.o:     ../loaders/load_amf.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_amf.c
-load_dsm.o:     ../loaders/load_dsm.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_dsm.c
-load_far.o:     ../loaders/load_far.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_far.c
-load_gdm.o:     ../loaders/load_gdm.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_gdm.c
-load_it.o:      ../loaders/load_it.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_it.c
-load_imf.o:     ../loaders/load_imf.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_imf.c
-load_m15.o:     ../loaders/load_m15.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_m15.c
-load_med.o:     ../loaders/load_med.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_med.c
-load_mod.o:     ../loaders/load_mod.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_mod.c
-load_mtm.o:     ../loaders/load_mtm.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_mtm.c
-load_okt.o:     ../loaders/load_okt.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_okt.c
-load_s3m.o:     ../loaders/load_s3m.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_s3m.c
-load_stm.o:     ../loaders/load_stm.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_stm.c
-load_stx.o:     ../loaders/load_stx.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_stx.c
-load_ult.o:     ../loaders/load_ult.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_ult.c
-load_uni.o:     ../loaders/load_uni.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_uni.c
-load_xm.o:      ../loaders/load_xm.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../loaders/load_xm.c
-mmalloc.o:      ../mmio/mmalloc.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../mmio/mmalloc.c
-mmerror.o:      ../mmio/mmerror.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../mmio/mmerror.c
-mmio.o:         ../mmio/mmio.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../mmio/mmio.c
-mdriver.o:      ../playercode/mdriver.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/mdriver.c
-mdreg.o:        ../playercode/mdreg.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/mdreg.c
-mloader.o:      ../playercode/mloader.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/mloader.c
-mlreg.o:        ../playercode/mlreg.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/mlreg.c
-mlutil.o:       ../playercode/mlutil.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/mlutil.c
-mplayer.o:      ../playercode/mplayer.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/mplayer.c
-munitrk.o:      ../playercode/munitrk.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/munitrk.c
-mwav.o:         ../playercode/mwav.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/mwav.c
-npertab.o:      ../playercode/npertab.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/npertab.c
-sloader.o:      ../playercode/sloader.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/sloader.c
-virtch.o:       ../playercode/virtch.c ../playercode/virtch_common.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/virtch.c
-virtch2.o:      ../playercode/virtch2.c ../playercode/virtch_common.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/virtch2.c
-virtch_common.o:        ../playercode/virtch_common.c \\
-\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
-\t$(COMPILE) -o $@ ../playercode/virtch_common.c
-THE_END
 
   function mikmod_getver
   {
       /^LIBMIKMOD_MAJOR_VERSION *= *[0-9]+/ { major = getnum($0); next}
       /^LIBMIKMOD_MINOR_VERSION *= *[0-9]+/ { minor = getnum($0); next}
       /^LIBMIKMOD_MICRO_VERSION *= *[0-9]+/ { micro = getnum($0); next}
-      END { printf "%s.%s.%s", major, minor, micro }' \
+      END { printf "%s %s %s", major, minor, micro }' \
       $1
     }
 
-  mikmod_version=`mikmod_getver configure.in`
+  export mikmod_version=(`mikmod_getver configure.in`)
   sed -e "s~@prefix@~$PREFIX~g" \
       -e "s~@exec_prefix@~$PREFIX~g" \
-      -e "s~@LIBMIKMOD_VERSION@~$mikmod_version~g" \
+      -e "s~@LIBMIKMOD_VERSION@~${mikmod_version[0]}.${mikmod_version[1]}.${mikmod_version[2]}~g" \
       -e "s~@REENTRANT@~-D_REENTRANT~g" \
       -e "s~@LIB_LDADD@~~g" \
       -e "s~@LIBRARY_LIB@~-lpthread~g" \
-  libmikmod-config.in >libmikmod-config
+      libmikmod-config.in >libmikmod-config
+
+  # Enviroment variable expansion is used in writing the makefile...
+  cat > win32/Makefile.static.mingw << THE_END
+# MinGW Makefile adapted from template for use under win32
+#
+# libmikmod subdirectory
+
+# Your compiler here
+CC=gcc
+# Compiler flags
+CPPFLAGS_MIKMOD=-c -DWIN32 -DDRV_DS -DDRV_WIN -DHAVE_FCNTL_H -DHAVE_MALLOC_H -DHAVE_LIMITS_H \\$(CPPFLAGS)
+COMPILE=\\$(CC) \\$(CPPFLAGS_MIKMOD) -I../include -I.. -I../win32 \\$(CFLAGS)
+
+.SUFFIXES:
+.SUFFIXES: .o .c
+
+LIBNAME=libmikmod.a
+
+LIBS=\\$(LIBNAME)
+
+DRIVER_OBJ=drv_ds.o drv_win.o
+
+OBJ=\\$(DRIVER_OBJ) \\
+    drv_nos.o drv_raw.o drv_stdout.o drv_wav.o \\
+    load_669.o load_amf.o load_dsm.o load_far.o load_gdm.o load_it.o  \\
+    load_imf.o load_m15.o load_med.o load_mod.o load_mtm.o load_okt.o \\
+    load_s3m.o load_stm.o load_stx.o load_ult.o load_uni.o load_xm.o \\
+    mmalloc.o mmerror.o mmio.o \\
+    mdriver.o mdreg.o mloader.o mlreg.o mlutil.o mplayer.o munitrk.o mwav.o \\
+    npertab.o sloader.o virtch.o virtch2.o virtch_common.o
+
+all:            \\$(LIBS)
+
+clean:
+\tfor f in \\$(LIBS) ; do rm -f $f; done
+\trm -f *.o
+\trm -f mikmod_build.h
+
+distclean:
+\trm -f ../include/mikmod.h
+
+install:
+\tcp -fp libmikmod.a "\\$(PREFIX)/lib"
+\tcp -fp ../include/mikmod.h "\\$(PREFIX)/include"
+\tcp -fp ../libmikmod-config "\\$(PREFIX)/bin"
+
+\\$(LIBNAME):     \\$(OBJ)
+\tar -r \\$(LIBNAME) *.o
+\tranlib \\$(LIBNAME)
+
+../include/mikmod.h ../win32/mikmod_build.h:\t../include/mikmod.h.in
+\tsed -e "s~@LIBMIKMOD_MAJOR_VERSION@~${mikmod_version[0]}~" \\
+\t    -e "s~@LIBMIKMOD_MINOR_VERSION@~${mikmod_version[1]}~" \\
+\t    -e "s~@LIBMIKMOD_MICRO_VERSION@~${mikmod_version[2]}~" \\
+\t    -e "s~@DOES_NOT_HAVE_SIGNED@~~" \\
+\t    ../include/mikmod.h.in >../win32/mikmod_build.h
+\tcp -f ../win32/mikmod_build.h ../include/mikmod.h
+
+drv_ds.o:       ../drivers/drv_ds.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../drivers/drv_ds.c
+drv_nos.o:      ../drivers/drv_nos.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../drivers/drv_nos.c
+drv_raw.o:      ../drivers/drv_raw.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../drivers/drv_raw.c
+drv_stdout.o:   ../drivers/drv_stdout.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../drivers/drv_stdout.c
+drv_wav.o:      ../drivers/drv_wav.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../drivers/drv_wav.c
+drv_win.o:       ../drivers/drv_win.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../drivers/drv_win.c
+load_669.o:     ../loaders/load_669.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_669.c
+load_amf.o:     ../loaders/load_amf.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_amf.c
+load_dsm.o:     ../loaders/load_dsm.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_dsm.c
+load_far.o:     ../loaders/load_far.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_far.c
+load_gdm.o:     ../loaders/load_gdm.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_gdm.c
+load_it.o:      ../loaders/load_it.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_it.c
+load_imf.o:     ../loaders/load_imf.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_imf.c
+load_m15.o:     ../loaders/load_m15.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_m15.c
+load_med.o:     ../loaders/load_med.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_med.c
+load_mod.o:     ../loaders/load_mod.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_mod.c
+load_mtm.o:     ../loaders/load_mtm.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_mtm.c
+load_okt.o:     ../loaders/load_okt.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_okt.c
+load_s3m.o:     ../loaders/load_s3m.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_s3m.c
+load_stm.o:     ../loaders/load_stm.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_stm.c
+load_stx.o:     ../loaders/load_stx.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_stx.c
+load_ult.o:     ../loaders/load_ult.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_ult.c
+load_uni.o:     ../loaders/load_uni.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_uni.c
+load_xm.o:      ../loaders/load_xm.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../loaders/load_xm.c
+mmalloc.o:      ../mmio/mmalloc.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../mmio/mmalloc.c
+mmerror.o:      ../mmio/mmerror.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../mmio/mmerror.c
+mmio.o:         ../mmio/mmio.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../mmio/mmio.c
+mdriver.o:      ../playercode/mdriver.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/mdriver.c
+mdreg.o:        ../playercode/mdreg.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/mdreg.c
+mloader.o:      ../playercode/mloader.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/mloader.c
+mlreg.o:        ../playercode/mlreg.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/mlreg.c
+mlutil.o:       ../playercode/mlutil.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/mlutil.c
+mplayer.o:      ../playercode/mplayer.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/mplayer.c
+munitrk.o:      ../playercode/munitrk.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/munitrk.c
+mwav.o:         ../playercode/mwav.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/mwav.c
+npertab.o:      ../playercode/npertab.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/npertab.c
+sloader.o:      ../playercode/sloader.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/sloader.c
+virtch.o:       ../playercode/virtch.c ../playercode/virtch_common.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/virtch.c
+virtch2.o:      ../playercode/virtch2.c ../playercode/virtch_common.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/virtch2.c
+virtch_common.o:        ../playercode/virtch_common.c \\
+\t                ../win32/mikmod_build.h ../include/mikmod_internals.h
+\t\\$(COMPILE) -o \\$@ ../playercode/virtch_common.c
+THE_END
+
+    unset -v mikmod_version
 fi
 
 if [ x$BDCOMP == x1 ]; then
   cd win32
-  make LDFLAGS="$LDFLAGS" -fMakefile.static.mingw
+  make -fMakefile.static.mingw \
+       CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
+
   cd ..
 fi
 
 if [ x$BDINST == x1 ]; then
   cd win32
-  make install PREFIX="$PREFIX" -fMakefile.static.mingw
+  make install -fMakefile.static.mingw PREFIX="$PREFIX"
   cd ..
 fi
 
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 mikmod_dependencies='-ldsound'
 flac_dependencies='-lWs2_32'
     ./autogen.sh
   fi
 
+  # For msvcr90.dll linkage, remap SDL_strdup and SDL_vsnprintf calls.
+  if (( $BDMSVCRT_VERSION == 90 )); then
+    export CPPFLAGS="$CPPFLAGS -DSDL_strdup=_strdup -DSDL_vsnprintf=_vsnprintf"
+  fi
+  
   # No dynamic loading of dependent libraries. Use LIBS so FLAC test
   # builds (unfortunately LIBS is not passed on to Makefile).
   export LIBS="$mikmod_dependencies $flac_dependencies"
   ./configure --disable-music-ogg-shared --disable-music-mp3-shared \
-    --disable-music-mod-shared --disable-music-flac-shared \
-    --disable-libtool-lock --prefix="$PREFIX" LDFLAGS="$LDFLAGS"
+              --disable-music-mod-shared --disable-music-flac-shared \
+              --disable-music-fluidsynth-midi \
+              --disable-libtool-lock --prefix="$PREFIX" \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
   
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
   # Fix up some g++ 4.5.0 issues in the source code.
 fi
 
 if [ x$BDCOMP == x1 ]; then
-  make LDFLAGS="$LDFLAGS"
+  make CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
 fi
 
 if [ x$BDINST == x1 ]; then
 
 set -e
 export PATH="$PREFIX/bin:$PATH"
-cd "$BDWD"
 
 if [ x$BDCONF == x1 ]; then
   # Don't want the pthreads dll, which links to msvcrt.dll.
   ./configure --enable-shared --enable-memalign-hack \
               --disable-pthreads --prefix="$PREFIX" \
-              --enable-runtime-cpudetect
-              
+              --enable-runtime-cpudetect \
+              CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
+
   # check for MSYS permission errors
   if [ x"`grep 'Permission denied' config.log`" != x ]; then
       echo '**** MSYS problems; build aborted.'
 mkdir -p "$PREFIX/doc"
 mkdir -p "$PREFIX/man"
 mkdir -p "$PREFIX/share"
-
-# Have libtool link against static stdc++ and gcc libraries. Use hacked .la files.
-# This works when the destination directory comes early in the library search path.
-if [ ! -f "$PREFIX/lib/null.dll.a" ]; then
-  dest_lib="$PREFIX/lib"
-  dlltool -D null.dll -l "$PREFIX/lib/null.dll.a"
-  cp -fp /mingw/lib/gcc/mingw32/4.5.0/libstdc++.a "$dest_lib/libstdc++_pg.a"
-  sed -e "s~^\\(library_names='\\)[^']\\+~\\1null.dll.a~" \
-      -e "s~^\\(dependency_libs='\\)[^']\\+~\\1 -lstdc++_pg -lgcc_eh~" \
-      -e "s~^\\(libdir='\\)[^']\\+~\\1$PREFIX/lib~" \
-      /mingw/lib/gcc/mingw32/4.5.0/libstdc++.la >"$dest_lib/libstdc++.la"
-  sed -e "s~^\\(old_library='\\)[^']\\+~\\1libgcc.a~" \
-      -e "s~^\\(dependency_libs='\\)[^']\\+~\\1 -lgcc~" \
-      "$dest_lib/libstdc++.la" >"$dest_lib/libgcc_s.la"
-fi
 """)
     
 msvcr71_prep = Preparation('msvcr71.dll linkage', r"""
 #
 #   msvcr71.dll support
 #
-if [ ! -f "$DBMSVCR71/libmoldname.a" ]; then
-  echo "Making directory $DBMSVCR71 for msvcr71.dll linking."
-  mkdir -p "$DBMSVCR71"
-  cp -fp /mingw/lib/libmoldname71.a "$DBMSVCR71/libmoldname.a"
-  cp -fp /mingw/lib/libmoldname71d.a "$DBMSVCR71/libmoldnamed.a"
-  cp -fp /mingw/lib/libmsvcr71.a "$DBMSVCR71/libmsvcrt.a"
-  cp -fp /mingw/lib/libmsvcr71d.a "$DBMSVCR71/libmsvcrtd.a"
+if [ ! -f "$BDMSVCRT/libmoldname.a" ]; then
+  echo "Making directory $BDMSVCRT for msvcr71.dll linking."
+  mkdir -p "$BDMSVCRT"
+  cp -fp /mingw/lib/libmoldname71.a "$BDMSVCRT/libmoldname.a"
+  cp -fp /mingw/lib/libmoldname71d.a "$BDMSVCRT/libmoldnamed.a"
+  cp -fp /mingw/lib/libmsvcr71.a "$BDMSVCRT/libmsvcrt.a"
+  cp -fp /mingw/lib/libmsvcr71d.a "$BDMSVCRT/libmsvcrtd.a"
+fi
+""")
+
+msvcr90_prep = Preparation('msvcr90.dll linkage', r"""
+
+set -e
+
+#
+#   msvcr90.dll support
+#
+if [ ! -f "$BDMSVCRT/libmoldname.a" ]; then
+  echo "Making directory $BDMSVCRT for msvcr90.dll linking."
+  mkdir -p "$BDMSVCRT"
+  cd "$BDMSVCRT"
+  # Need libmsvcr90.a as libmoldname links to it.
+  cp -fp /mingw/lib/libmsvcr90.a .
+  cp -fp libmsvcr90.a libmsvcrt.a
+  cp -fp /mingw/lib/libmsvcr90d.a .
+  cp -fp libmsvcr90d.a libmsvcrtd.a
+
+  # Will be creating extra files; this will simplify cleanup
+  mkdir -p tmp
+  cd tmp
+
+  # The manifest resource
+  cat > manifest.xml << 'THE_END'
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
+    </dependentAssembly>
+  </dependency>
+</assembly>
+THE_END
+
+  cat > manifest.rc << 'THE_END'
+#include <winuser.h>
+1 RT_MANIFEST manifest.xml
+THE_END
+
+  windres -o "$BDRESOURCES" manifest.rc
+
+  # Update libmoldname for msvcr90.dll
+  #
+  # _fstab inlined in MSVC 9.0. Replace the fstab entry with a wrapper
+  # function.
+  #
+  # This is quick and dirty surgery on a MinGW 4.6.1 libmoldname90.a copy.  
+
+  # Provide the fstat function required by TIFF.
+  cat > fstat.c << 'THE_END'
+/* Stub function for fstat.
+ * This is an inlined function in Visual C 2008 so is missing from msvcr90.dll
+ */
+#include <sys/stat.h>
+
+_CRTIMP int __cdecl __MINGW_NOTHROW fstat(int fd, struct stat *buffer)
+{
+    return _fstat(fd, (struct _stat *)buffer);
+}
+THE_END
+
+  # When compiling, make sure __MSVCRT_VERSION__ is set for msvcr90.dll,
+  # otherwise will have undefined symbols.
+  cp /mingw/lib/libmoldname90.a libmoldname.a
+  ar d libmoldname.a dyoks00032.o
+  gcc -c -O2 -D__MSVCRT_VERSION__=0x0900 fstat.c
+  ar rc libmoldname.a fstat.o
+  ranlib libmoldname.a
+  mv -f libmoldname.a "$BDMSVCRT"
+  cp /mingw/lib/libmoldname90d.a libmoldnamed.a
+  ar d libmoldnamed.a dsxks00032.o
+  gcc -c -g -D__MSVCRT_VERSION__=0x0900 fstat.c
+  ar rc libmoldnamed.a fstat.o
+  ranlib libmoldnamed.a
+  mv -f libmoldnamed.a "$BDMSVCRT"
+
+  # Cleanup
+  cd ..
+  rm -Rf ./tmp
 fi
 """)
 
 """)
 
 if __name__ == '__main__':
-    sys.exit(main(dependencies, msvcr71_prep, msys_prep))
+    sys.exit(main(dependencies, msvcr71_prep, msvcr90_prep, msys_prep))

prebuilt-template/Setup_Win.in

-# Pygame 1.9.0 Windows dependency macros.
+# Pygame 1.9.2 Windows dependency macros.
 SDL = -Iprebuilt/include -Iprebuilt/include/SDL -Lprebuilt/lib -lSDL
 FONT = -lSDL_ttf
 IMAGE = -lSDL_image
 AVFORMAT = -Iprebuilt/include -lavformat -lavcodec -lavutil
 SWSCALE = -Iprebuilt/include -lswscale -lavutil
 # Ensure make_prebuilt.py includes the ffmpeg headers.
-COPYHDRS_AVFORMAT = -lavformat -Iprebuilt/include/libavformat
-COPYHDRS_SWCALE = -lswscale -Iprebuilt/include/libswscale
-COPYHDRS_AVCODEC = -lavcodec -Iprebuilt/include/libavcodec
-COPYHDRS_AVUTIL = -lavutil -Iprebuilt/include/libavutil
+#COPYHDRS_AVFORMAT = -lavformat -Iprebuilt/include/libavformat
+#COPYHDRS_SWCALE = -lswscale -Iprebuilt/include/libswscale
+#COPYHDRS_AVCODEC = -lavcodec -Iprebuilt/include/libavcodec
+#COPYHDRS_AVUTIL = -lavutil -Iprebuilt/include/libavutil
 # Ensure make_prebuilt.py includes the freetype2 headers.
 COPYHDRS_FREETYPE = -lfreetype -Iprebuilt/include/freetype2/freetype -Iprebuilt/include/freetype2/freetype/config
 # The DLL's
 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-3.dll
-COPYLIB_png -lz -Lprebuilt/lib/libpng14.dll
+COPYLIB_tiff -ljpeg -lz -Lprebuilt/lib/libtiff-5.dll
+COPYLIB_png -lz -Lprebuilt/lib/libpng16-16.dll
 COPYLIB_jpeg -Lprebuilt/lib/libjpeg-8.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
 COPYLIB_portmidi -Lprebuilt/lib/portmidi.dll
-COPYLIB_avformat -lavcodec -lavutil -Lprebuilt/lib/avformat-52.dll
-COPYLIB_swscale -lavutil -Lprebuilt/lib/swscale-0.dll
-COPYLIB_avcodec -lavutil -Lprebuilt/lib/avcodec-52.dll
-COPYLIB_avutil -Lprebuilt/lib/avutil-50.dll