From 01b43e5f0ada65370e19e2dbeac0773f4177ac73 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 11 Aug 2016 16:09:47 +0530 Subject: [PATCH] Print the CFLAGS/LDFLAGS/etc inherited from the environment People can forget it and then wonder what's wrong. Just explicitly print it. --- mesonbuild/environment.py | 61 ++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 404ed3ee1..4ee739341 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -13,7 +13,9 @@ # limitations under the License. import os, re, subprocess, platform -from . import coredata, mesonlib +from . import coredata +from . import mesonlib +from . import mlog from .compilers import * import configparser @@ -700,29 +702,40 @@ class Environment(): def get_args_from_envvars(lang): - if lang == 'c': - compile_args = os.environ.get('CFLAGS', '').split() - link_args = compile_args + os.environ.get('LDFLAGS', '').split() - compile_args += os.environ.get('CPPFLAGS', '').split() - elif lang == 'cpp': - compile_args = os.environ.get('CXXFLAGS', '').split() - link_args = compile_args + os.environ.get('LDFLAGS', '').split() - compile_args += os.environ.get('CPPFLAGS', '').split() - elif lang == 'objc': - compile_args = os.environ.get('OBJCFLAGS', '').split() - link_args = compile_args + os.environ.get('LDFLAGS', '').split() - compile_args += os.environ.get('CPPFLAGS', '').split() - elif lang == 'objcpp': - compile_args = os.environ.get('OBJCXXFLAGS', '').split() - link_args = compile_args + os.environ.get('LDFLAGS', '').split() - compile_args += os.environ.get('CPPFLAGS', '').split() - elif lang == 'fortran': - compile_args = os.environ.get('FFLAGS', '').split() - link_args = compile_args + os.environ.get('LDFLAGS', '').split() - else: - compile_args = [] - link_args = [] - return (compile_args, link_args) + """ + @lang: Language to fetch environment flags for + + 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)) + + if lang not in ('c', 'cpp', 'objc', 'objcpp', 'fortran'): + return ([], []) + + # Compile flags + cflags_mapping = {'c': 'CFLAGS', 'cpp': 'CXXFLAGS', + 'objc': 'OBJCFLAGS', 'objcpp': 'OBJCXXFLAGS', + 'fortran': 'FFLAGS'} + compile_flags = os.environ.get(cflags_mapping[lang], '') + log_var(cflags_mapping[lang], compile_flags) + compile_flags = compile_flags.split() + + # Link flags (same for all languages) + link_flags = os.environ.get('LDFLAGS', '') + log_var('LDFLAGS', link_flags) + link_flags = link_flags.split() + + # Pre-processof rlags (not for fortran) + preproc_flags = '' + if lang in ('c', 'cpp', 'objc', 'objcpp'): + preproc_flags = os.environ.get('CPPFLAGS', '') + log_var('CPPFLAGS', preproc_flags) + preproc_flags = preproc_flags.split() + + return (compile_flags + preproc_flags, link_flags + compile_flags) class CrossBuildInfo(): def __init__(self, filename):