diff --git a/waflib/Tools/compiler_c.py b/waflib/Tools/compiler_c.py index 73db5f00..548f0a68 100644 --- a/waflib/Tools/compiler_c.py +++ b/waflib/Tools/compiler_c.py @@ -15,11 +15,12 @@ Try to detect a C compiler from the list of supported compilers (gcc, msvc, etc) The compilers are associated to platforms in :py:attr:`waflib.Tools.compiler_c.c_compiler`. To register a new C compiler named *cfoo* (assuming the tool ``waflib/extras/cfoo.py`` exists), use:: + from waflib.Tools.compiler_c import c_compiler + c_compiler['win32'] = ['cfoo', 'msvc', 'gcc'] + def options(opt): opt.load('compiler_c') def configure(cnf): - from waflib.Tools.compiler_c import c_compiler - c_compiler['win32'] = ['cfoo', 'msvc', 'gcc'] cnf.load('compiler_c') def build(bld): bld.program(source='main.c', target='app') @@ -54,11 +55,16 @@ Dict mapping the platform names to Waf tools finding specific C compilers:: c_compiler['linux'] = ['gcc', 'icc', 'suncc'] """ +def default_compilers(): + build_platform = Utils.unversioned_sys_platform() + possible_compiler_list = c_compiler.get(build_platform, c_compiler['default']) + return ' '.join(possible_compiler_list) + def configure(conf): """ Try to find a suitable C compiler or raise a :py:class:`waflib.Errors.ConfigurationError`. """ - try: test_for_compiler = conf.options.check_c_compiler + try: test_for_compiler = conf.options.check_c_compiler or default_compilers() except AttributeError: conf.fatal("Add options(opt): opt.load('compiler_c')") for compiler in re.split('[ ,]+', test_for_compiler): @@ -85,15 +91,13 @@ def options(opt): $ waf configure --check-c-compiler=gcc """ + test_for_compiler = default_compilers() opt.load_special_tools('c_*.py', ban=['c_dumbpreproc.py']) - global c_compiler - build_platform = Utils.unversioned_sys_platform() - possible_compiler_list = c_compiler.get(build_platform, c_compiler['default']) - test_for_compiler = ' '.join(possible_compiler_list) cc_compiler_opts = opt.add_option_group('Configuration options') - cc_compiler_opts.add_option('--check-c-compiler', default=test_for_compiler, + cc_compiler_opts.add_option('--check-c-compiler', default=None, help='list of C compilers to try [%s]' % test_for_compiler, dest="check_c_compiler") + for x in test_for_compiler.split(): opt.load('%s' % x) diff --git a/waflib/Tools/compiler_cxx.py b/waflib/Tools/compiler_cxx.py index f809a24a..db94c0ef 100644 --- a/waflib/Tools/compiler_cxx.py +++ b/waflib/Tools/compiler_cxx.py @@ -15,11 +15,12 @@ Try to detect a C++ compiler from the list of supported compilers (g++, msvc, et The compilers are associated to platforms in :py:attr:`waflib.Tools.compiler_cxx.cxx_compiler`. To register a new C++ compiler named *cfoo* (assuming the tool ``waflib/extras/cfoo.py`` exists), use:: + from waflib.Tools.compiler_cxx import cxx_compiler + cxx_compiler['win32'] = ['cfoo', 'msvc', 'gcc'] + def options(opt): opt.load('compiler_cxx') def configure(cnf): - from waflib.Tools.compiler_cxx import cxx_compiler - cxx_compiler['win32'] = ['cfoo', 'msvc', 'gcc'] cnf.load('compiler_cxx') def build(bld): bld.program(source='main.c', target='app') @@ -55,12 +56,16 @@ Dict mapping the platform names to Waf tools finding specific C++ compilers:: cxx_compiler['linux'] = ['gxx', 'icpc', 'suncxx'] """ +def default_compilers(): + build_platform = Utils.unversioned_sys_platform() + possible_compiler_list = cxx_compiler.get(build_platform, cxx_compiler['default']) + return ' '.join(possible_compiler_list) def configure(conf): """ Try to find a suitable C++ compiler or raise a :py:class:`waflib.Errors.ConfigurationError`. """ - try: test_for_compiler = conf.options.check_cxx_compiler + try: test_for_compiler = conf.options.check_cxx_compiler or default_compilers() except AttributeError: conf.fatal("Add options(opt): opt.load('compiler_cxx')") for compiler in re.split('[ ,]+', test_for_compiler): @@ -87,13 +92,10 @@ def options(opt): $ waf configure --check-cxx-compiler=gxx """ + test_for_compiler = default_compilers() opt.load_special_tools('cxx_*.py') - global cxx_compiler - build_platform = Utils.unversioned_sys_platform() - possible_compiler_list = cxx_compiler.get(build_platform, cxx_compiler['default']) - test_for_compiler = ' '.join(possible_compiler_list) cxx_compiler_opts = opt.add_option_group('Configuration options') - cxx_compiler_opts.add_option('--check-cxx-compiler', default=test_for_compiler, + cxx_compiler_opts.add_option('--check-cxx-compiler', default=None, help='list of C++ compilers to try [%s]' % test_for_compiler, dest="check_cxx_compiler") diff --git a/waflib/Tools/compiler_d.py b/waflib/Tools/compiler_d.py index e9bf9c52..8b07c7da 100644 --- a/waflib/Tools/compiler_d.py +++ b/waflib/Tools/compiler_d.py @@ -33,11 +33,19 @@ Dict mapping the platform names to lists of names of D compilers to try, in orde d_compiler['default'] = ['gdc', 'dmd', 'ldc2'] """ +def default_compilers(): + build_platform = Utils.unversioned_sys_platform() + possible_compiler_list = d_compiler.get(build_platform, d_compiler['default']) + return ' '.join(possible_compiler_list) + def configure(conf): """ Try to find a suitable D compiler or raise a :py:class:`waflib.Errors.ConfigurationError`. """ - for compiler in re.split('[ ,]+', conf.options.dcheck): + try: test_for_compiler = conf.options.check_d_compiler or default_compilers() + except AttributeError: conf.fatal("Add options(opt): opt.load('compiler_d')") + + for compiler in re.split('[ ,]+', test_for_compiler): conf.env.stash() conf.start_msg('Checking for %r (D compiler)' % compiler) try: @@ -61,12 +69,11 @@ def options(opt): $ waf configure --check-d-compiler=dmd """ - build_platform = Utils.unversioned_sys_platform() - possible_compiler_list = d_compiler.get(build_platform, d_compiler['default']) - test_for_compiler = ' '.join(possible_compiler_list) + test_for_compiler = default_compilers() d_compiler_opts = opt.add_option_group('Configuration options') - d_compiler_opts.add_option('--check-d-compiler', default=test_for_compiler, action='store', - help='list of D compilers to try [%s]' % test_for_compiler, dest='dcheck') - for d_compiler in ('gdc', 'dmd', 'ldc2'): - opt.load('%s' % d_compiler) + d_compiler_opts.add_option('--check-d-compiler', default=None, + help='list of D compilers to try [%s]' % test_for_compiler, dest='check_d_compiler') + + for x in test_for_compiler.split(): + opt.load('%s' % x) diff --git a/waflib/Tools/compiler_fc.py b/waflib/Tools/compiler_fc.py index a9754d9d..5643f5e0 100644 --- a/waflib/Tools/compiler_fc.py +++ b/waflib/Tools/compiler_fc.py @@ -20,11 +20,16 @@ Dict mapping the platform names to lists of names of Fortran compilers to try, i c_compiler['linux'] = ['gfortran', 'g95', 'ifort'] """ +def default_compilers(): + build_platform = Utils.unversioned_sys_platform() + possible_compiler_list = fc_compiler.get(build_platform, fc_compiler['default']) + return ' '.join(possible_compiler_list) + def configure(conf): """ Try to find a suitable Fortran compiler or raise a :py:class:`waflib.Errors.ConfigurationError`. """ - try: test_for_compiler = conf.options.check_fc + try: test_for_compiler = conf.options.check_fortran_compiler or default_compilers() except AttributeError: conf.fatal("Add options(opt): opt.load('compiler_fc')") for compiler in re.split('[ ,]+', test_for_compiler): conf.env.stash() @@ -50,16 +55,13 @@ def options(opt): $ waf configure --check-fortran-compiler=ifort """ + test_for_compiler = default_compilers() opt.load_special_tools('fc_*.py') - build_platform = Utils.unversioned_sys_platform() - possible_compiler_list = fc_compiler.get(build_platform, fc_compiler['default']) - test_for_compiler = ' '.join(possible_compiler_list) fortran_compiler_opts = opt.add_option_group('Configuration options') - fortran_compiler_opts.add_option('--check-fortran-compiler', - default=test_for_compiler, + fortran_compiler_opts.add_option('--check-fortran-compiler', default=None, help='list of Fortran compiler to try [%s]' % test_for_compiler, - dest="check_fc") + dest="check_fortran_compiler") - for compiler in test_for_compiler.split(): - opt.load('%s' % compiler) + for x in test_for_compiler.split(): + opt.load('%s' % x)