55the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
66cygwin in no-cygwin mode).
77"""
8-
98from __future__ import annotations
109
1110import copy
@@ -45,6 +44,7 @@ class Compiler(unix.Compiler):
4544 """Handles the Cygwin port of the GNU C compiler to Windows."""
4645
4746 compiler_type = 'cygwin'
47+ src_extensions = unix .Compiler .src_extensions + [".mc" ]
4848 obj_extension = ".o"
4949 static_lib_extension = ".a"
5050 shared_lib_extension = ".dll.a"
@@ -105,16 +105,30 @@ def gcc_version(self):
105105 with suppress_known_deprecation ():
106106 return LooseVersion ("11.2.0" )
107107
108- def _compile (self , obj , src , ext , cc_args , extra_postargs , pp_opts ):
109- """Compiles the source by spawning GCC and windres if needed."""
110- if ext in ('.rc' , '.res' ):
111- # gcc needs '.res' and '.rc' compiled to object files !!!
112- try :
108+ def _compile (
109+ self ,
110+ obj : str | os .PathLike [str ],
111+ src : str | os .PathLike [str ],
112+ ext : str ,
113+ cc_args : list [str ],
114+ extra_postargs : list [str ],
115+ pp_opts ,
116+ ) -> None :
117+ """Compiles the source by spawning GCC and windres, and/or windmc if needed."""
118+ try :
119+ if ext == '.mc' :
120+ h_dir = os .path .dirname (src )
121+ rc_dir = os .path .dirname (obj )
122+ # first compile .mc to .rc and .h file
123+ self .spawn (['windmc' , '-h' , h_dir , '-r' , rc_dir , src ])
124+ # then compile .rc to .res file
125+ src = os .path .join (
126+ rc_dir , os .path .splitext (os .path .basename (src ))[0 ] + '.rc'
127+ )
128+ if ext in ('.rc' , '.res' , '.mc' ):
129+ # gcc needs '.res' and '.rc' compiled to object files !!!
113130 self .spawn (["windres" , "-i" , src , "-o" , obj ])
114- except DistutilsExecError as msg :
115- raise CompileError (msg )
116- else : # for other files use the C-compiler
117- try :
131+ else : # for other files use the C-compiler
118132 if self .detect_language (src ) == 'c++' :
119133 self .spawn (
120134 self .compiler_so_cxx
@@ -126,8 +140,8 @@ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
126140 self .spawn (
127141 self .compiler_so + cc_args + [src , '-o' , obj ] + extra_postargs
128142 )
129- except DistutilsExecError as msg :
130- raise CompileError (msg )
143+ except DistutilsExecError as msg :
144+ raise CompileError (msg )
131145
132146 def link (
133147 self ,
@@ -238,7 +252,7 @@ def out_extensions(self):
238252 """
239253 return {
240254 ** super ().out_extensions ,
241- ** {ext : ext + self .obj_extension for ext in ('.res' , '.rc' )},
255+ ** {ext : ext + self .obj_extension for ext in ('.res' , '.rc' , '.mc' )},
242256 }
243257
244258
0 commit comments