0421503f7c932ba65b6b10c39c0ffb647a40c619
[obnox/samba/samba-obnox.git] / buildtools / wafadmin / Tools / compiler_cc.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # Matthias Jahn jahn dôt matthias ât freenet dôt de, 2007 (pmarat)
4
5 import os, sys, imp, types, ccroot
6 import optparse
7 import Utils, Configure, Options
8 from Logs import debug
9
10 c_compiler = {
11         'win32':  ['msvc', 'gcc'],
12         'cygwin': ['gcc'],
13         'darwin': ['gcc'],
14         'aix':    ['xlc', 'gcc'],
15         'linux':  ['gcc', 'icc', 'suncc'],
16         'sunos':  ['gcc', 'suncc'],
17         'irix':   ['gcc'],
18         'hpux':   ['gcc'],
19         'gnu':    ['gcc'],
20         'default': ['gcc']
21 }
22
23 def __list_possible_compiler(platform):
24         try:
25                 return c_compiler[platform]
26         except KeyError:
27                 return c_compiler["default"]
28
29 def detect(conf):
30         """
31         for each compiler for the platform, try to configure the compiler
32         in theory the tools should raise a configuration error if the compiler
33         pretends to be something it is not (setting CC=icc and trying to configure gcc)
34         """
35         try: test_for_compiler = Options.options.check_c_compiler
36         except AttributeError: conf.fatal("Add set_options(opt): opt.tool_options('compiler_cc')")
37         orig = conf.env
38         for compiler in test_for_compiler.split():
39                 conf.env = orig.copy()
40                 try:
41                         conf.check_tool(compiler)
42                 except Configure.ConfigurationError, e:
43                         debug('compiler_cc: %r' % e)
44                 else:
45                         if conf.env['CC']:
46                                 orig.table = conf.env.get_merged_dict()
47                                 conf.env = orig
48                                 conf.check_message(compiler, '', True)
49                                 conf.env['COMPILER_CC'] = compiler
50                                 break
51                         conf.check_message(compiler, '', False)
52                         break
53         else:
54                 conf.fatal('could not configure a c compiler!')
55
56 def set_options(opt):
57         build_platform = Utils.unversioned_sys_platform()
58         possible_compiler_list = __list_possible_compiler(build_platform)
59         test_for_compiler = ' '.join(possible_compiler_list)
60         cc_compiler_opts = opt.add_option_group("C Compiler Options")
61         cc_compiler_opts.add_option('--check-c-compiler', default="%s" % test_for_compiler,
62                 help='On this platform (%s) the following C-Compiler will be checked by default: "%s"' % (build_platform, test_for_compiler),
63                 dest="check_c_compiler")
64
65         for c_compiler in test_for_compiler.split():
66                 opt.tool_options('%s' % c_compiler, option_group=cc_compiler_opts)
67