Fix from Jack Jansen for the Mac and the Metrowerks compiler, posted
to the Distutils-SIG and archived at
http://mail.python.org/pipermail/distutils-sig/2000-November/001755.html
diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py
index b10ee67..53901b3 100644
--- a/Lib/distutils/ccompiler.py
+++ b/Lib/distutils/ccompiler.py
@@ -838,6 +838,7 @@
 # that platform.
 default_compiler = { 'posix': 'unix',
                      'nt': 'msvc',
+                     'mac': 'mwerks',
                    }
 
 # Map compiler types to (module_name, class_name) pairs -- ie. where to
@@ -853,6 +854,8 @@
                                "Mingw32 port of GNU C Compiler for Win32"),
                    'bcpp':    ('bcppcompiler', 'BCPPCompiler',
                                "Borland C++ Compiler"),
+                   'mwerks':  ('mwerkscompiler', 'MWerksCompiler',
+                               "MetroWerks CodeWarrior"),
                  }
 
 def show_compilers():
diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py
index fe728c3..41d5dbb 100644
--- a/Lib/distutils/dist.py
+++ b/Lib/distutils/dist.py
@@ -172,12 +172,6 @@
         # operations, we just check the 'have_run' dictionary and carry on.
         # It's only safe to query 'have_run' for a command class that has
         # been instantiated -- a false value will be inserted when the
-        if sys.platform == 'mac':
-            import EasyDialogs
-            cmdlist = self.get_command_list()
-            self.script_args = EasyDialogs.GetArgv(
-                self.global_options + self.display_options, cmdlist)
-
         # command object is created, and replaced with a true value when
         # the command is successfully run.  Thus it's probably best to use
         # '.get()' rather than a straight lookup.
@@ -375,6 +369,16 @@
         execute commands (currently, this only happens if user asks for
         help).
         """
+        #
+        # We now have enough information to show the Macintosh dialog that allows
+        # the user to interactively specify the "command line".
+        #
+        if sys.platform == 'mac':
+            import EasyDialogs
+            cmdlist = self.get_command_list()
+            self.script_args = EasyDialogs.GetArgv(
+                self.global_options + self.display_options, cmdlist)
+ 
         # We have to parse the command line a bit at a time -- global
         # options, then the first command, then its options, and so on --
         # because each command will be handled by a different class, and
diff --git a/Lib/distutils/mwerkscompiler.py b/Lib/distutils/mwerkscompiler.py
new file mode 100644
index 0000000..2edc825
--- /dev/null
+++ b/Lib/distutils/mwerkscompiler.py
@@ -0,0 +1,203 @@
+"""distutils.mwerkscompiler
+
+Contains MWerksCompiler, an implementation of the abstract CCompiler class
+for MetroWerks CodeWarrior on the Macintosh. Needs work to support CW on
+Windows."""
+
+import sys, os, string
+from types import *
+from distutils.errors import \
+     DistutilsExecError, DistutilsPlatformError, \
+     CompileError, LibError, LinkError
+from distutils.ccompiler import \
+     CCompiler, gen_preprocess_options, gen_lib_options
+import distutils.util
+import distutils.dir_util
+import mkcwproject
+
+class MWerksCompiler (CCompiler) :
+    """Concrete class that implements an interface to Microsoft Visual C++,
+       as defined by the CCompiler abstract class."""
+
+    compiler_type = 'mwerks'
+
+    # Just set this so CCompiler's constructor doesn't barf.  We currently
+    # don't use the 'set_executables()' bureaucracy provided by CCompiler,
+    # as it really isn't necessary for this sort of single-compiler class.
+    # Would be nice to have a consistent interface with UnixCCompiler,
+    # though, so it's worth thinking about.
+    executables = {}
+
+    # Private class data (need to distinguish C from C++ source for compiler)
+    _c_extensions = ['.c']
+    _cpp_extensions = ['.cc', '.cpp', '.cxx']
+    _rc_extensions = ['.r']
+    _exp_extension = '.exp'
+
+    # Needed for the filename generation methods provided by the
+    # base class, CCompiler.
+    src_extensions = (_c_extensions + _cpp_extensions +
+                      _rc_extensions)
+    res_extension = '.rsrc'
+    obj_extension = '.obj' # Not used, really
+    static_lib_extension = '.lib'
+    shared_lib_extension = '.slb'
+    static_lib_format = shared_lib_format = '%s%s'
+    exe_extension = ''
+
+
+    def __init__ (self,
+                  verbose=0,
+                  dry_run=0,
+                  force=0):
+
+        CCompiler.__init__ (self, verbose, dry_run, force)
+        
+        
+    def compile (self,
+                 sources,
+                 output_dir=None,
+                 macros=None,
+                 include_dirs=None,
+                 debug=0,
+                 extra_preargs=None,
+                 extra_postargs=None):
+         self.__sources = sources
+         self.__macros = macros
+         self.__include_dirs = include_dirs
+         # Don't need extra_preargs and extra_postargs for CW
+         
+    def link (self,
+              target_desc,
+              objects,
+              output_filename,
+              output_dir=None,
+              libraries=None,
+              library_dirs=None,
+              runtime_library_dirs=None,
+              export_symbols=None,
+              debug=0,
+              extra_preargs=None,
+              extra_postargs=None,
+              build_temp=None):
+        # First examine a couple of options for things that aren't implemented yet
+        if not target_desc in (self.SHARED_LIBRARY, self.SHARED_OBJECT):
+            raise DistutilsPlatformError, 'Can only make SHARED_LIBRARY or SHARED_OBJECT targets on the Mac'
+        if runtime_library_dirs:
+            raise DistutilsPlatformError, 'Runtime library dirs not implemented yet'
+        if extra_preargs or extra_postargs:
+            raise DistutilsPlatformError, 'Runtime library dirs not implemented yet'
+        if len(export_symbols) != 1:
+            raise DistutilsPlatformError, 'Need exactly one export symbol'
+        # Next there are various things for which we need absolute pathnames.
+        # This is because we (usually) create the project in a subdirectory of
+        # where we are now, and keeping the paths relative is too much work right
+        # now.
+        sources = map(self._filename_to_abs, self.__sources)
+        include_dirs = map(self._filename_to_abs, self.__include_dirs)
+        if objects:
+            objects = map(self._filename_to_abs, objects)
+        else:
+            objects = []
+        if build_temp:
+            build_temp = self._filename_to_abs(build_temp)
+        else:
+            build_temp = os.curdir()
+        if output_dir:
+            output_filename = os.path.join(output_dir, output_filename)
+        # The output filename needs special handling: splitting it into dir and
+        # filename part. Actually I'm not sure this is really needed, but it
+        # can't hurt.
+        output_filename = self._filename_to_abs(output_filename)
+        output_dir, output_filename = os.path.split(output_filename)
+        # Now we need the short names of a couple of things for putting them
+        # into the project.
+        if output_filename[-8:] == '.ppc.slb':
+            basename = output_filename[:-8]
+        else:
+            basename = os.path.strip(output_filename)[0]
+        projectname = basename + '.mcp'
+        targetname = basename
+        xmlname = basename + '.xml'
+        exportname = basename + '.mcp.exp'
+        prefixname = 'mwerks_%s_config.h'%basename
+        # Create the directories we need
+        distutils.dir_util.mkpath(build_temp, self.verbose, self.dry_run)
+        distutils.dir_util.mkpath(output_dir, self.verbose, self.dry_run)
+        # And on to filling in the parameters for the project builder
+        settings = {}
+        settings['mac_exportname'] = exportname
+        settings['mac_outputdir'] = output_dir
+        settings['mac_dllname'] = output_filename
+        settings['mac_targetname'] = targetname
+        settings['sysprefix'] = sys.prefix
+        settings['mac_sysprefixtype'] = 'Absolute'
+        sourcefilenames = []
+        sourcefiledirs = []
+        for filename in sources + objects:
+            dirname, filename = os.path.split(filename)
+            sourcefilenames.append(filename)
+            if not dirname in sourcefiledirs:
+                sourcefiledirs.append(dirname)
+        settings['sources'] = sourcefilenames
+        settings['extrasearchdirs'] = sourcefiledirs + include_dirs + library_dirs
+        if self.dry_run:
+            print 'CALLING LINKER IN', os.getcwd()
+            for key, value in settings.items():
+                print '%20.20s %s'%(key, value)
+            return
+        # Build the export file
+        exportfilename = os.path.join(build_temp, exportname)
+        if self.verbose:
+            print '\tCreate export file', exportfilename
+        fp = open(exportfilename, 'w')
+        fp.write('%s\n'%export_symbols[0])
+        fp.close()
+        # Generate the prefix file, if needed, and put it in the settings
+        if self.__macros:
+            prefixfilename = os.path.join(os.getcwd(), os.path.join(build_temp, prefixname))
+            fp = open(prefixfilename, 'w')
+            fp.write('#include "mwerks_plugin_config.h"\n')
+            for name, value in self.__macros:
+                if value is None:
+                    fp.write('#define %s\n'%name)
+                else:
+                    fp.write('#define %s "%s"\n'%(name, value))
+            fp.close()
+            settings['prefixname'] = prefixname
+
+        # Build the XML file. We need the full pathname (only lateron, really)
+        # because we pass this pathname to CodeWarrior in an AppleEvent, and CW
+        # doesn't have a clue about our working directory.
+        xmlfilename = os.path.join(os.getcwd(), os.path.join(build_temp, xmlname))
+        if self.verbose:
+            print '\tCreate XML file', xmlfilename
+        xmlbuilder = mkcwproject.cwxmlgen.ProjectBuilder(settings)
+        xmlbuilder.generate()
+        xmldata = settings['tmp_projectxmldata']
+        fp = open(xmlfilename, 'w')
+        fp.write(xmldata)
+        fp.close()
+        # Generate the project. Again a full pathname.
+        projectfilename = os.path.join(os.getcwd(), os.path.join(build_temp, projectname))
+        if self.verbose:
+            print '\tCreate project file', projectfilename
+        mkcwproject.makeproject(xmlfilename, projectfilename)
+        # And build it
+        if self.verbose:
+            print '\tBuild project'
+        mkcwproject.buildproject(projectfilename)
+        
+    def _filename_to_abs(self, filename):
+        # Some filenames seem to be unix-like. Convert to Mac names.
+##        if '/' in filename and ':' in filename:
+##           raise DistutilsPlatformError, 'Filename may be Unix or Mac style: %s'%filename
+##        if '/' in filename:
+##           filename = macurl2path(filename)
+        filename = distutils.util.convert_path(filename)
+        if not os.path.isabs(filename):
+           curdir = os.getcwd()
+           filename = os.path.join(curdir, filename)
+        return filename
+        
+