Skip to content

Commit 1808e12

Browse files
Avasamraedrizqie
andcommitted
Add support for windmc compiling routine
Co-Authored-By: Raed Rizqie <raed.rizqie@gmail.com>
1 parent a1c0ebc commit 1808e12

2 files changed

Lines changed: 38 additions & 17 deletions

File tree

distutils/compilers/C/base.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class Compiler:
9797
# Subclasses that rely on the standard filename generation methods
9898
# implemented below should override these; see the comment near
9999
# those methods ('object_filenames()' et. al.) for details:
100-
src_extensions: ClassVar[list[str] | None] = None
100+
src_extensions: ClassVar[list[str]] = []
101101
obj_extension: ClassVar[str | None] = None
102102
static_lib_extension: ClassVar[str | None] = None
103103
shared_lib_extension: ClassVar[str | None] = None
@@ -371,7 +371,7 @@ def _setup_compile(
371371
outdir: str | None,
372372
macros: list[_Macro] | None,
373373
incdirs: list[str] | tuple[str, ...] | None,
374-
sources,
374+
sources: Sequence[str | os.PathLike[str]],
375375
depends,
376376
extra,
377377
):
@@ -387,7 +387,7 @@ def _setup_compile(
387387

388388
pp_opts = gen_preprocess_options(macros, incdirs)
389389

390-
build = {}
390+
build: dict[str, tuple[str | os.PathLike[str], str]] = {}
391391
for i in range(len(sources)):
392392
src = sources[i]
393393
obj = objects[i]
@@ -531,7 +531,14 @@ def _need_link(self, objects, output_file):
531531
newer = newer_group(objects, output_file)
532532
return newer
533533

534-
def detect_language(self, sources: str | list[str]) -> str | None:
534+
def detect_language(
535+
self,
536+
sources: str
537+
| os.PathLike[str]
538+
| list[str]
539+
| list[os.PathLike[str]]
540+
| list[str | os.PathLike[str]],
541+
) -> str | None:
535542
"""Detect the language of a given file, or list of files. Uses
536543
language_map, and language_order to do the job.
537544
"""

distutils/compilers/C/cygwin.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
66
cygwin in no-cygwin mode).
77
"""
8-
98
from __future__ import annotations
109

1110
import 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

Comments
 (0)