summaryrefslogtreecommitdiff
path: root/giscanner/ccompiler.py
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2014-08-25 11:28:41 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2015-07-30 11:01:18 +0800
commit7ce646db1cb0842db2089df671b17081f82f2b0a (patch)
tree242f7ced19a0beb389f1df8f0fe3c2d7078c69cb /giscanner/ccompiler.py
parentad8fc51441b331c7db573201dd283a423081c042 (diff)
downloadgobject-introspection-7ce646db1cb0842db2089df671b17081f82f2b0a.tar.gz
dumper.py: Use Distutils to Build Dumper Program
Add compiler() and link() functions in ccompiler.py to call distutil.ccompiler's compile() and link() functions, so that we can in turn call them from dumper.py to build the dumper program. As distutils don't get along well with libtool libraries (ie .la files), we can deduce the libraries to link from using the file name .la file and include $(builddir)/.libs in the linking stage. For MSVC builds, we need to ignore mt.exe failing to find a .exe.manifest file as Visual Studio 2010+ do not generate such files during linking, and it is done by distutils as Python 2.7.x is built with Visual Studio 2008, which do generate such manifest files during the build. https://bugzilla.gnome.org/show_bug.cgi?id=728313
Diffstat (limited to 'giscanner/ccompiler.py')
-rw-r--r--giscanner/ccompiler.py133
1 files changed, 103 insertions, 30 deletions
diff --git a/giscanner/ccompiler.py b/giscanner/ccompiler.py
index f9105fe7..da56c60a 100644
--- a/giscanner/ccompiler.py
+++ b/giscanner/ccompiler.py
@@ -106,54 +106,76 @@ class CCompiler(object):
self._cflags_no_deprecation_warnings = "-Wno-deprecated-declarations"
- def get_internal_link_flags(self, args, libtool, libraries, libpaths):
+ def get_internal_link_flags(self, libtool, libraries, libpaths):
# An "internal" link is where the library to be introspected
# is being built in the current directory.
+ internal_link_args = []
# Search the current directory first
- # (This flag is not supported nor needed for Visual C++)
- if not self.check_is_msvc():
- args.append('-L.')
+ self.compiler.add_library_dir('.')
- # https://bugzilla.gnome.org/show_bug.cgi?id=625195
+ if self.check_is_msvc():
+ for library in libraries:
+ # MSVC Builds don't use libtool, so no .la libraries,
+ # so just add the library directly.
+ self.compiler.add_library(library)
+ for libpath in libpaths:
+ self.compiler.add_library_dir(libpath)
+
+ else:
if not libtool:
- args.append('-Wl,-rpath=.')
- args.append('-Wl,--no-as-needed')
+ # https://bugzilla.gnome.org/show_bug.cgi?id=625195
+ internal_link_args.append('-Wl,-rpath=.')
- for library in libraries:
- if self.check_is_msvc():
- args.append(library + '.lib')
- else:
+ # Ensure libraries are always linked as we are going to use ldd to work
+ # out their names later
+ internal_link_args.append('-Wl,--no-as-needed')
+
+ for library in libraries:
if library.endswith(".la"): # explicitly specified libtool library
- args.append(library)
+ self.compiler.add_library_dir('.libs')
+ if os.name != 'nt':
+ self.compiler.add_runtime_library_dir('.libs')
+ if (library.startswith('lib')):
+ self.compiler.add_library(library[len('lib'):library.rfind('.la')])
+ else:
+ self.compiler.add_library(library[:library.rfind('.la')])
else:
- args.append('-l' + library)
-
- for library_path in libpaths:
- # Not used/needed on Visual C++, and -Wl,-rpath options
- # will cause grief
- if not self.check_is_msvc():
- args.append('-L' + library_path)
- if os.path.isabs(library_path):
+ self.compiler.add_library(library)
+
+ for libpath in libpaths:
+ self.compiler.add_library_dir(libpath)
+
+ # Not used/needed on Windows, add_runtime_library_dir()
+ # will cause grief on Windows
+ if os.name != 'nt':
+ self.compiler.add_runtime_library_dir(libpath)
+ if os.path.isabs(libpath):
if libtool:
- args.append('-rpath')
- args.append(library_path)
+ internal_link_args.append('-rpath')
+ internal_link_args.append(libpath)
else:
- args.append('-Wl,-rpath=' + library_path)
+ internal_link_args.append('-Wl,-rpath=' + libpath)
+
+ return internal_link_args
- def get_external_link_flags(self, args, libraries):
+ def get_external_link_flags(self, libraries):
# An "external" link is where the library to be introspected
# is installed on the system; this case is used for the scanning
# of GLib in gobject-introspection itself.
+ external_link_args = []
+
for library in libraries:
- if self.check_is_msvc():
- args.append(library + '.lib')
- else:
- if library.endswith(".la"): # explicitly specified libtool library
- args.append(library)
+ if library.endswith(".la"): # explicitly specified libtool library
+ if (library.startswith('lib')):
+ self.compiler.add_library(library[len('lib'):library.rfind('.la')])
else:
- args.append('-l' + library)
+ self.compiler.add_library(library[:library.rfind('.la')])
+ else:
+ self.compiler.add_library(library)
+
+ return external_link_args
def preprocess(self, source, output, cpp_options):
extra_postargs = ['-C']
@@ -180,6 +202,57 @@ class CCompiler(object):
include_dirs=include_dirs,
extra_postargs=extra_postargs)
+ def compile(self, pkg_config_cflags, cpp_includes, source, init_sections, quiet):
+ extra_postargs = []
+ includes = []
+ cpp_options = None
+ source_str = ''.join(source)
+ tmpdir_idx = source_str.rfind(os.sep, 0, source_str.rfind(os.sep))
+ (include_paths, macros, extra_args) = \
+ self._set_cpp_options(pkg_config_cflags)
+
+ for include in cpp_includes:
+ includes.append(include)
+
+ # Do not add -Wall when using init code as we do not include any
+ # header of the library being introspected
+ if self.compiler_cmd == 'gcc' and not init_sections:
+ extra_postargs.append('-Wall')
+ extra_postargs.append(self._cflags_no_deprecation_warnings)
+
+ includes.extend(include_paths)
+ extra_postargs.extend(extra_args)
+
+ return self.compiler.compile(sources=source,
+ macros=macros,
+ include_dirs=includes,
+ extra_postargs=extra_postargs,
+ output_dir=source_str[tmpdir_idx + 1:
+ source_str.rfind(os.sep)])
+
+ def link(self, output, objects, lib_args, libtool, quiet):
+ extra_preargs = []
+ extra_postargs = []
+ library_dirs = []
+ libraries = []
+ output_str = ''.join(output)
+ output_dir = output_str[:output_str.rfind(os.sep)]
+
+ if libtool:
+ if os.name == 'nt':
+ extra_postargs.append('-Wl,--export-all-symbols')
+ else:
+ extra_postargs.append('-export-dynamic')
+
+ for arg in lib_args:
+ extra_postargs.append(arg)
+
+ self.compiler.link(target_desc=self.compiler.EXECUTABLE,
+ objects=objects,
+ output_filename=output,
+ extra_preargs=extra_preargs,
+ extra_postargs=extra_postargs)
+
def resolve_windows_libs(self, libraries, options):
args = []
libsearch = []