[gtk-doc/win-no-msys: 7/8] WIP: Support MSVC compilers...
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-doc/win-no-msys: 7/8] WIP: Support MSVC compilers...
- Date: Wed, 15 Apr 2020 04:05:38 +0000 (UTC)
commit d6cd374568fc44ca1cae9af9a518e52b3ada2c19
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Wed Apr 15 12:03:53 2020 +0800
WIP: Support MSVC compilers...
gtkdoc-scangobj.in | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
gtkdoc/scangobj.py | 7 +++++-
2 files changed, 78 insertions(+), 2 deletions(-)
---
diff --git a/gtkdoc-scangobj.in b/gtkdoc-scangobj.in
index 7660c70..5149e67 100755
--- a/gtkdoc-scangobj.in
+++ b/gtkdoc-scangobj.in
@@ -21,9 +21,15 @@
#
import argparse
+import distutils
import os
import sys
+from distutils import ccompiler
+from distutils.cygwinccompiler import Mingw32CCompiler
+from distutils.msvccompiler import MSVCCompiler
+from distutils.sysconfig import customize_compiler
+
try:
import gtkdoc_uninstalled
except ModuleNotFoundError:
@@ -31,7 +37,69 @@ except ModuleNotFoundError:
from gtkdoc import common, config, scangobj
+def check_is_msvc():
+ compiler = None
+ is_msvc = False
+ if os.name == 'nt':
+ # The compiler used here on Windows may well not be
+ # the same compiler that was used to build Python,
+ # as the official Python binaries are built with
+ # Visual Studio
+ compiler_name = os.environ.get('CC')
+ if compiler_name is None:
+ if os.environ.get('MSYSTEM') == 'MINGW32' or os.environ.get('MSYSTEM') == 'MINGW64':
+ compiler_name = 'mingw32'
+ else:
+ compiler_name = distutils.ccompiler.get_default_compiler()
+
+ if compiler_name != 'msvc' and \
+ compiler_name != 'mingw32' and \
+ compiler_name != 'clang' and \
+ compiler_name != 'clang-cl':
+ raise SystemExit('Specified Compiler \'%s\' is unsupported.' % compiler_name)
+ else:
+ # XXX: Is it common practice to use a non-Unix compiler
+ # class instance on non-Windows on platforms g-i supports?
+ compiler_name = distutils.ccompiler.get_default_compiler()
+
+ # Now, create the distutils ccompiler instance based on the info we have.
+ if compiler_name == 'msvc':
+ # For MSVC, we need to create a instance of a subclass of distutil's
+ # MSVC9Compiler class, as it does not provide a preprocess()
+ # implementation
+ compiler = distutils.msvccompiler.MSVCCompiler()
+ else:
+ compiler = distutils.ccompiler.new_compiler(compiler=compiler_name)
+ customize_compiler(compiler)
+
+ # customize_compiler() from distutils only does customization
+ # for 'unix' compiler type. Also, avoid linking to msvcrxx.dll
+ # for MinGW builds as the dumper binary does not link to the
+ # Python DLL, but link to msvcrt.dll if necessary.
+ if isinstance(compiler, Mingw32CCompiler):
+ if compiler.dll_libraries != ['msvcrt']:
+ self.compiler.dll_libraries = []
+# if self.compiler.preprocessor is None:
+# self.compiler.preprocessor = self.compiler.compiler + ['-E']
+
+ if isinstance(compiler, distutils.msvccompiler.MSVCCompiler):
+ # We trick distutils to believe that we are (always) using a
+ # compiler supplied by a Windows SDK, so that we avoid launching
+ # a new build environment to detect the compiler that is used to
+ # build Python itself, which is not desirable, so that we use the
+ # compiler commands (and env) as-is.
+ os.environ['DISTUTILS_USE_SDK'] = '1'
+ if 'MSSdk' not in os.environ:
+ if 'WindowsSDKDir' in os.environ:
+ os.environ['MSSdk'] = os.environ.get('WindowsSDKDir')
+ elif os.environ.get('VCInstallDir'):
+ os.environ['MSSdk'] = os.environ.get('VCInstallDir')
+ is_msvc = True
+
+ return is_msvc
+
if __name__ == '__main__':
+ is_msvc = check_is_msvc()
parser = argparse.ArgumentParser(
description='gtkdoc-rebase version %s - introspect g-objects' % config.version)
parser.add_argument('--version', action='version', version=config.version)
@@ -66,7 +134,10 @@ if __name__ == '__main__':
options.ldflags = ' '.join(options.ldflags)
if not options.cc:
- options.cc = os.environ.get('CC', 'gcc')
+ if is_msvc:
+ options.cc = os.environ.get('CC', 'cl')
+ else:
+ options.cc = os.environ.get('CC', 'gcc')
if not options.ld:
options.ld = os.environ.get('LD', options.cc)
if not options.cflags:
diff --git a/gtkdoc/scangobj.py b/gtkdoc/scangobj.py
index 7434ec1..74145d4 100644
--- a/gtkdoc/scangobj.py
+++ b/gtkdoc/scangobj.py
@@ -1288,7 +1288,12 @@ def run(options):
if 'libtool' in options.cc:
o_file = options.module + '-scan.lo'
else:
- o_file = options.module + '-scan.o'
+ obj_ext = None
+ if options.cc == 'cl':
+ obj_ext = '.obj'
+ else:
+ obj_ext = '.o'
+ o_file = options.module + '-scan' + obj_ext
x_file = options.module + '-scan' + config.exeext
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]