build:wafsamba: Remove unnecessary parameters to cmd_and_log
[samba.git] / third_party / waf / waflib / Tools / compiler_c.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
4
5 #!/usr/bin/env python
6 # encoding: utf-8
7 # Matthias Jahn jahn dôt matthias ât freenet dôt de, 2007 (pmarat)
8
9 """
10 Try to detect a C compiler from the list of supported compilers (gcc, msvc, etc)::
11
12         def options(opt):
13                 opt.load('compiler_c')
14         def configure(cnf):
15                 cnf.load('compiler_c')
16         def build(bld):
17                 bld.program(source='main.c', target='app')
18
19 The compilers are associated to platforms in :py:attr:`waflib.Tools.compiler_c.c_compiler`. To register
20 a new C compiler named *cfoo* (assuming the tool ``waflib/extras/cfoo.py`` exists), use::
21
22         from waflib.Tools.compiler_c import c_compiler
23         c_compiler['win32'] = ['cfoo', 'msvc', 'gcc']
24
25         def options(opt):
26                 opt.load('compiler_c')
27         def configure(cnf):
28                 cnf.load('compiler_c')
29         def build(bld):
30                 bld.program(source='main.c', target='app')
31
32 Not all compilers need to have a specific tool. For example, the clang compilers can be detected by the gcc tools when using::
33
34         $ CC=clang waf configure
35 """
36
37 import re
38 from waflib.Tools import ccroot
39 from waflib import Utils
40 from waflib.Logs import debug
41
42 c_compiler = {
43 'win32':  ['msvc', 'gcc', 'clang'],
44 'cygwin': ['gcc'],
45 'darwin': ['clang', 'gcc'],
46 'aix':    ['xlc', 'gcc', 'clang'],
47 'linux':  ['gcc', 'clang', 'icc'],
48 'sunos':  ['suncc', 'gcc'],
49 'irix':   ['gcc', 'irixcc'],
50 'hpux':   ['gcc'],
51 'osf1V':  ['gcc'],
52 'gnu':    ['gcc', 'clang'],
53 'java':   ['gcc', 'msvc', 'clang', 'icc'],
54 'default':['clang', 'gcc'],
55 }
56 """
57 Dict mapping platform names to Waf tools finding specific C compilers::
58
59         from waflib.Tools.compiler_c import c_compiler
60         c_compiler['linux'] = ['gcc', 'icc', 'suncc']
61 """
62
63 def default_compilers():
64         build_platform = Utils.unversioned_sys_platform()
65         possible_compiler_list = c_compiler.get(build_platform, c_compiler['default'])
66         return ' '.join(possible_compiler_list)
67
68 def configure(conf):
69         """
70         Detects a suitable C compiler
71
72         :raises: :py:class:`waflib.Errors.ConfigurationError` when no suitable compiler is found
73         """
74         try:
75                 test_for_compiler = conf.options.check_c_compiler or default_compilers()
76         except AttributeError:
77                 conf.fatal("Add options(opt): opt.load('compiler_c')")
78
79         for compiler in re.split('[ ,]+', test_for_compiler):
80                 conf.env.stash()
81                 conf.start_msg('Checking for %r (C compiler)' % compiler)
82                 try:
83                         conf.load(compiler)
84                 except conf.errors.ConfigurationError ,e:
85                         conf.env.revert()
86                         conf.end_msg(False)
87                         debug('compiler_c: %r', e)
88                 else:
89                         if conf.env.CC:
90                                 conf.end_msg(conf.env.get_flat('CC'))
91                                 conf.env.COMPILER_CC = compiler
92                                 conf.env.commit()
93                                 break
94                         conf.env.revert()
95                         conf.end_msg(False)
96         else:
97                 conf.fatal('could not configure a C compiler!')
98
99 def options(opt):
100         """
101         This is how to provide compiler preferences on the command-line::
102
103                 $ waf configure --check-c-compiler=gcc
104         """
105         test_for_compiler = default_compilers()
106         opt.load_special_tools('c_*.py', ban=['c_dumbpreproc.py'])
107         cc_compiler_opts = opt.add_option_group('Configuration options')
108         cc_compiler_opts.add_option('--check-c-compiler', default=None,
109                 help='list of C compilers to try [%s]' % test_for_compiler,
110                 dest="check_c_compiler")
111
112         for x in test_for_compiler.split():
113                 opt.load('%s' % x)