diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2018-05-13 10:36:58 -0400 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-06-06 20:02:37 +0000 |
commit | fa72cd7173c0e2798d622052ae3fcee2ad947c0b (patch) | |
tree | fff491a3f72dee0cd11a8564621da986042da948 /mesonbuild/compilers/compilers.py | |
parent | 6eeea9dd546e881ef9eb38f61a0a7a96d67a77fc (diff) | |
download | meson-fa72cd7173c0e2798d622052ae3fcee2ad947c0b.zip meson-fa72cd7173c0e2798d622052ae3fcee2ad947c0b.tar.gz meson-fa72cd7173c0e2798d622052ae3fcee2ad947c0b.tar.bz2 |
Move get_args_from_envvars() from environment to compilers
Diffstat (limited to 'mesonbuild/compilers/compilers.py')
-rw-r--r-- | mesonbuild/compilers/compilers.py | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 6a310ba..7ac0753 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import contextlib, os.path, re, tempfile +import contextlib, os.path, re, tempfile, shlex import subprocess from ..linkers import StaticLinker @@ -57,6 +57,15 @@ clike_suffixes += ('h', 'll', 's') soregex = re.compile(r'.*\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$') +# Environment variables that each lang uses. +cflags_mapping = {'c': 'CFLAGS', + 'cpp': 'CXXFLAGS', + 'objc': 'OBJCFLAGS', + 'objcpp': 'OBJCXXFLAGS', + 'fortran': 'FFLAGS', + 'd': 'DFLAGS', + 'vala': 'VALAFLAGS'} + # All these are only for C-like languages; see `clike_langs` above. def sort_clike(lang): @@ -716,6 +725,48 @@ class Compiler: """ return [] + def get_args_from_envvars(self): + """ + Returns a tuple of (compile_flags, link_flags) for the specified language + from the inherited environment + """ + def log_var(var, val): + if val: + mlog.log('Appending {} from environment: {!r}'.format(var, val)) + + lang = self.get_language() + compiler_is_linker = False + if hasattr(self, 'get_linker_exelist'): + compiler_is_linker = (self.get_exelist() == self.get_linker_exelist()) + + if lang not in cflags_mapping: + return [], [], [] + + compile_flags = os.environ.get(cflags_mapping[lang], '') + log_var(cflags_mapping[lang], compile_flags) + compile_flags = shlex.split(compile_flags) + + # Link flags (same for all languages) + link_flags = os.environ.get('LDFLAGS', '') + log_var('LDFLAGS', link_flags) + link_flags = shlex.split(link_flags) + if compiler_is_linker: + # When the compiler is used as a wrapper around the linker (such as + # with GCC and Clang), the compile flags can be needed while linking + # too. This is also what Autotools does. However, we don't want to do + # this when the linker is stand-alone such as with MSVC C/C++, etc. + link_flags = compile_flags + link_flags + + # Pre-processor flags (not for fortran or D) + preproc_flags = '' + if lang in ('c', 'cpp', 'objc', 'objcpp'): + preproc_flags = os.environ.get('CPPFLAGS', '') + log_var('CPPFLAGS', preproc_flags) + preproc_flags = shlex.split(preproc_flags) + compile_flags += preproc_flags + + return preproc_flags, compile_flags, link_flags + def get_options(self): return {} # build afresh every time |