Determine and use the proper linker based on input source languages.

pull/15/head
Jussi Pakkanen 11 years ago
parent 8ef713843f
commit 17b5920aa8
  1. 31
      backends.py
  2. 4
      build.py

@ -166,10 +166,13 @@ class Backend():
obj_list.append(self.generate_single_compile(target, outfile, src, True)) obj_list.append(self.generate_single_compile(target, outfile, src, True))
else: else:
header_deps.append(src) header_deps.append(src)
src_list = []
for src in gen_src_deps: for src in gen_src_deps:
src_list.append(src)
obj_list.append(self.generate_single_compile(target, outfile, src, True)) obj_list.append(self.generate_single_compile(target, outfile, src, True))
for src in target.get_sources(): for src in target.get_sources():
if not self.environment.is_header(src): if not self.environment.is_header(src):
src_list.append(src)
obj_list.append(self.generate_single_compile(target, outfile, src, False, header_deps)) obj_list.append(self.generate_single_compile(target, outfile, src, False, header_deps))
for obj in target.get_objects(): for obj in target.get_objects():
if isinstance(obj, str): if isinstance(obj, str):
@ -179,10 +182,32 @@ class Backend():
obj_list += self.determine_ext_objs(obj) obj_list += self.determine_ext_objs(obj)
else: else:
raise MesonException('Unknown data type in object list.') raise MesonException('Unknown data type in object list.')
elem = self.generate_link(target, outfile, outname, obj_list) linker = self.determine_linker(target, src_list)
elem = self.generate_link(target, outfile, outname, obj_list, linker)
self.generate_shlib_aliases(target, self.get_target_dir(target), outfile, elem) self.generate_shlib_aliases(target, self.get_target_dir(target), outfile, elem)
self.processed_targets[name] = True self.processed_targets[name] = True
def determine_linker(self, target, src):
if isinstance(target, build.StaticLibrary):
return self.build.static_linker
if len(self.build.compilers) == 1:
return self.build.compilers[0]
# Currently a bit naive. C++ must
# be linked with a C++ compiler, but
# otherwise we don't care. This will
# become trickier if and when Fortran
# and the like become supported.
cpp = None
for c in self.build.compilers:
if c.get_language() == 'cpp':
cpp = c
break
if cpp is not None:
for s in src:
if c.can_compile(s):
return cpp
return self.build.compilers[0]
def determine_ext_objs(self, extobj): def determine_ext_objs(self, extobj):
result = [] result = []
targetdir = self.get_target_private_dir(extobj.target) targetdir = self.get_target_private_dir(extobj.target)
@ -859,12 +884,10 @@ class NinjaBackend(Backend):
elem.add_item('CROSS', '--cross-host=' + self.environment.cross_info['name']) elem.add_item('CROSS', '--cross-host=' + self.environment.cross_info['name'])
elem.write(outfile) elem.write(outfile)
def generate_link(self, target, outfile, outname, obj_list): def generate_link(self, target, outfile, outname, obj_list, linker):
if isinstance(target, build.StaticLibrary): if isinstance(target, build.StaticLibrary):
linker = self.build.static_linker
linker_base = 'STATIC' linker_base = 'STATIC'
else: else:
linker = self.build.compilers[0]
linker_base = linker.get_language() # Fixme. linker_base = linker.get_language() # Fixme.
if isinstance(target, build.SharedLibrary): if isinstance(target, build.SharedLibrary):
self.generate_shsym(outfile, target) self.generate_shsym(outfile, target)

@ -350,12 +350,12 @@ class Generator():
if hasattr(args[0], 'held_object'): if hasattr(args[0], 'held_object'):
exe = args[0].held_object exe = args[0].held_object
if not isinstance(exe, Executable):
raise InvalidArguments('First generator argument must be an executable.')
elif hasattr(args[0], 'ep'): elif hasattr(args[0], 'ep'):
exe = args[0].ep exe = args[0].ep
else: else:
raise InvalidArguments('First generator argument must be an executable object.') raise InvalidArguments('First generator argument must be an executable object.')
if not isinstance(exe, Executable):
raise InvalidArguments('First generator argument must be an executable.')
self.exe = exe self.exe = exe
self.process_kwargs(kwargs) self.process_kwargs(kwargs)

Loading…
Cancel
Save