From 52ed7fd8f84b052604b6a8e404d8d990a9d277ed Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 30 Aug 2013 22:51:14 +0300 Subject: [PATCH] Can build both cross and native binaries at the same time. --- backends.py | 46 ++++++++++++++++------- cross/ubuntu-armhf.txt | 3 ++ cross/ubuntu-mingw.txt | 3 ++ test cases/common/29 pipeline/meson.build | 4 +- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/backends.py b/backends.py index f0c765033..69b46e29f 100644 --- a/backends.py +++ b/backends.py @@ -515,18 +515,23 @@ class NinjaBackend(Backend): outfile.write(description) def generate_dynamic_link_rules(self, outfile): - for compiler in self.build.compilers: - langname = compiler.get_language() - rule = 'rule %s_LINKER\n' % langname - command = ' command = %s %s $FLAGS %s $in $LINK_FLAGS $aliasing\n' % \ - (execute_wrapper, - ' '.join(compiler.get_linker_exelist()),\ - ' '.join(compiler.get_linker_output_flags('$out'))) - description = ' description = Linking target $out' - outfile.write(rule) - outfile.write(command) - outfile.write(description) - outfile.write('\n') + ctypes = [(self.build.compilers, False), (self.build.cross_compilers, True)] + for (complist, is_cross) in ctypes: + for compiler in complist: + langname = compiler.get_language() + crstr = '' + if is_cross: + crstr = '_CROSS' + rule = 'rule %s%s_LINKER\n' % (langname, crstr) + command = ' command = %s %s $FLAGS %s $in $LINK_FLAGS $aliasing\n' % \ + (execute_wrapper, + ' '.join(compiler.get_linker_exelist()),\ + ' '.join(compiler.get_linker_output_flags('$out'))) + description = ' description = Linking target $out' + outfile.write(rule) + outfile.write(command) + outfile.write(description) + outfile.write('\n') scriptdir = self.environment.get_script_dir() outfile.write('\n') symrule = 'rule SHSYM\n' @@ -608,6 +613,13 @@ class NinjaBackend(Backend): for genlist in target.get_generated_sources(): generator = genlist.get_generator() exe = generator.get_exe() + if self.environment.is_cross_build() and \ + isinstance(exe, interpreter.BuildTarget) and exe.is_cross: + if 'exe_wrapper' not in self.environment.cross_info: + s = 'Can not use target %s as a generator because it is cross-built\n' + s += 'and no exe wrapper is defined. You might want to set it to native instead.' + s = s % exe.name + raise MesonException(s) infilelist = genlist.get_infilelist() outfilelist = genlist.get_outfilelist() if isinstance(exe, interpreter.BuildTarget): @@ -675,7 +687,10 @@ class NinjaBackend(Backend): commands.append(barg) commands.append(sarg) commands += self.get_pch_include_args(compiler, target) - compiler_name = '%s_COMPILER' % compiler.get_language() + crstr = '' + if target.is_cross: + crstr = '_CROSS' + compiler_name = '%s%s_COMPILER' % (compiler.get_language(), crstr) element = NinjaBuildElement(rel_obj, compiler_name, rel_src) for d in header_deps: @@ -755,7 +770,10 @@ class NinjaBackend(Backend): linker_base = linker.get_language() # Fixme. if isinstance(target, interpreter.SharedLibrary): self.generate_shsym(outfile, target) - linker_rule = linker_base + '_LINKER' + crstr = '' + if target.is_cross: + crstr = '_CROSS' + linker_rule = linker_base + crstr + '_LINKER' commands = [] if isinstance(target, interpreter.Executable): commands += linker.get_std_exe_link_flags() diff --git a/cross/ubuntu-armhf.txt b/cross/ubuntu-armhf.txt index 57c8e2a7f..b46851957 100644 --- a/cross/ubuntu-armhf.txt +++ b/cross/ubuntu-armhf.txt @@ -1,6 +1,9 @@ name = 'linux' c = '/usr/bin/arm-linux-gnueabihf-gcc' cpp = '/usr/bin/arm-linux-gnueabihf-g++' +ar = '/usr/arm-linux-gnueabihf/bin/ar' +strip = '/usr/i586-mingw32msvc/bin/strip' + root = '/usr/arm-linux-gnueabihf' pkg_config = '/usr/bin/arm-linux-gnueabihf-pkg-config' diff --git a/cross/ubuntu-mingw.txt b/cross/ubuntu-mingw.txt index bb5303f15..66b279f22 100644 --- a/cross/ubuntu-mingw.txt +++ b/cross/ubuntu-mingw.txt @@ -2,4 +2,7 @@ name = 'windows' exe_wrapper = 'wine' # A command used to run generated executables. c = '/usr/bin/i586-mingw32msvc-gcc' cpp = '/usr/bin/i586-mingw32msvc-g++' +ar = '/usr/i586-mingw32msvc/bin/ar' +strip = '/usr/i586-mingw32msvc/bin/strip' + root = '/usr/i586-mingw32msvc' diff --git a/test cases/common/29 pipeline/meson.build b/test cases/common/29 pipeline/meson.build index 151b9d2b8..813c209e9 100644 --- a/test cases/common/29 pipeline/meson.build +++ b/test cases/common/29 pipeline/meson.build @@ -1,6 +1,8 @@ project('pipeline test', 'c') -e1 = executable('srcgen', 'srcgen.c') +# We need to run this executable locally so build it with +# the host compiler. +e1 = executable('srcgen', 'srcgen.c', native : true) gen = generator(e1, \ outputs : '@BASENAME@.c', # Line continuation inside arguments should work without needing a "\".