diff options
-rw-r--r-- | backends.py | 3 | ||||
-rw-r--r-- | build.py | 32 | ||||
-rw-r--r-- | ninjabackend.py | 7 |
3 files changed, 37 insertions, 5 deletions
diff --git a/backends.py b/backends.py index 30a8aa3..1aecadd 100644 --- a/backends.py +++ b/backends.py @@ -13,7 +13,7 @@ # limitations under the License. import mparser -import os, sys, re, pickle +import os, re, pickle import build from coredata import MesonException @@ -320,6 +320,7 @@ class Backend(): commands = [] commands += compiler.get_always_flags() commands += self.build.get_global_flags(compiler) + commands += self.build.get_external_args(compiler) commands += target.get_extra_args(compiler.get_language()) if self.environment.coredata.buildtype != 'plain': commands += compiler.get_debug_flags() @@ -33,6 +33,8 @@ class Build: self.compilers = [] self.cross_compilers = [] self.global_args = {} + self.external_args = {} # These are set from "the outside" with e.g. mesonconf + self.external_link_args = {} self.tests = [] self.headers = [] self.man = [] @@ -51,12 +53,32 @@ class Build: return False def add_compiler(self, compiler): - if self.static_linker is None and compiler.get_language() != 'java'\ - and compiler.get_language() != 'vala': + lang = compiler.get_language() + if self.static_linker is None and lang != 'java'\ + and lang != 'vala': self.static_linker = self.environment.detect_static_linker(compiler) if self.has_language(compiler.get_language()): return self.compilers.append(compiler) + self.get_flags_from_envvars(compiler) + + def get_flags_from_envvars(self, compiler): + lang = compiler.get_language() + if lang == 'c': + compile_flags = os.environ.get('CFLAGS', '').split() + compile_flags += os.environ.get('CPPFLAGS', '').split() + link_flags = compile_flags + os.environ.get('LDFLAGS', '').split() + elif lang == 'cpp': + compile_flags = os.environ.get('CXXFLAGS', '').split() + compile_flags += os.environ.get('CPPFLAGS', '').split() + link_flags = compile_flags + os.environ.get('LDFLAGS', '').split() + else: + compile_flags = [] + link_flags = [] + if len(compile_flags) > 0: + self.external_args[lang] = compile_flags + if len(link_flags) > 0: + self.external_link_args[lang] = link_flags def add_cross_compiler(self, compiler): if len(self.cross_compilers) == 0: @@ -90,6 +112,12 @@ class Build: def get_global_flags(self, compiler): return self.global_args.get(compiler.get_language(), []) + def get_external_args(self, compiler): + return self.external_args.get(compiler.get_language(), []) + + def get_external_link_args(self, compiler): + return self.external_link_args.get(compiler.get_language(), []) + class IncludeDirs(): def __init__(self, curdir, dirs, kwargs): self.curdir = curdir diff --git a/ninjabackend.py b/ninjabackend.py index ad06486..5a6418f 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -816,6 +816,8 @@ class NinjaBackend(backends.Backend): commands = [] commands += linker.get_linker_always_flags() commands += linker.get_buildtype_linker_flags(self.environment.coredata.buildtype) + if not(isinstance(target, build.StaticLibrary)): + commands += self.build.get_external_link_args(linker) if isinstance(target, build.Executable): commands += linker.get_std_exe_link_flags() elif isinstance(target, build.SharedLibrary): @@ -830,8 +832,9 @@ class NinjaBackend(backends.Backend): commands += self.build_target_link_arguments(linker, dependencies) commands += target.link_flags # External deps must be last because target link libraries may depend on them. - for dep in target.get_external_deps(): - commands += dep.get_link_flags() + if not(isinstance(target, build.StaticLibrary)): + for dep in target.get_external_deps(): + commands += dep.get_link_flags() commands += linker.build_rpath_args(self.environment.get_build_dir(), target.get_rpaths()) if self.environment.coredata.coverage: commands += linker.get_coverage_link_flags() |