jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.2KB

  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. Try to detect a C compiler from the list of supported compilers (gcc, msvc, etc)::
  6. def options(opt):
  7. opt.load('compiler_c')
  8. def configure(cnf):
  9. cnf.load('compiler_c')
  10. def build(bld):
  11. bld.program(source='main.c', target='app')
  12. The compilers are associated to platforms in :py:attr:`waflib.Tools.compiler_c.c_compiler`. To register
  13. a new C compiler named *cfoo* (assuming the tool ``waflib/extras/cfoo.py`` exists), use::
  14. from waflib.Tools.compiler_c import c_compiler
  15. c_compiler['win32'] = ['cfoo', 'msvc', 'gcc']
  16. def options(opt):
  17. opt.load('compiler_c')
  18. def configure(cnf):
  19. cnf.load('compiler_c')
  20. def build(bld):
  21. bld.program(source='main.c', target='app')
  22. Not all compilers need to have a specific tool. For example, the clang compilers can be detected by the gcc tools when using::
  23. $ CC=clang waf configure
  24. """
  25. import re
  26. from waflib.Tools import ccroot
  27. from waflib import Utils
  28. from waflib.Logs import debug
  29. c_compiler = {
  30. 'win32': ['msvc', 'gcc', 'clang'],
  31. 'cygwin': ['gcc', 'clang'],
  32. 'darwin': ['clang', 'gcc'],
  33. 'aix': ['xlc', 'gcc', 'clang'],
  34. 'linux': ['gcc', 'clang', 'icc'],
  35. 'sunos': ['suncc', 'gcc'],
  36. 'irix': ['gcc', 'irixcc'],
  37. 'hpux': ['gcc'],
  38. 'osf1V': ['gcc'],
  39. 'gnu': ['gcc', 'clang'],
  40. 'java': ['gcc', 'msvc', 'clang', 'icc'],
  41. 'gnukfreebsd': ['gcc', 'clang'],
  42. 'default': ['clang', 'gcc'],
  43. }
  44. """
  45. Dict mapping platform names to Waf tools finding specific C compilers::
  46. from waflib.Tools.compiler_c import c_compiler
  47. c_compiler['linux'] = ['gcc', 'icc', 'suncc']
  48. """
  49. def default_compilers():
  50. build_platform = Utils.unversioned_sys_platform()
  51. possible_compiler_list = c_compiler.get(build_platform, c_compiler['default'])
  52. return ' '.join(possible_compiler_list)
  53. def configure(conf):
  54. """
  55. Detects a suitable C compiler
  56. :raises: :py:class:`waflib.Errors.ConfigurationError` when no suitable compiler is found
  57. """
  58. try:
  59. test_for_compiler = conf.options.check_c_compiler or default_compilers()
  60. except AttributeError:
  61. conf.fatal("Add options(opt): opt.load('compiler_c')")
  62. for compiler in re.split('[ ,]+', test_for_compiler):
  63. conf.env.stash()
  64. conf.start_msg('Checking for %r (C compiler)' % compiler)
  65. try:
  66. conf.load(compiler)
  67. except conf.errors.ConfigurationError as e:
  68. conf.env.revert()
  69. conf.end_msg(False)
  70. debug('compiler_c: %r', e)
  71. else:
  72. if conf.env.CC:
  73. conf.end_msg(conf.env.get_flat('CC'))
  74. conf.env.COMPILER_CC = compiler
  75. conf.env.commit()
  76. break
  77. conf.env.revert()
  78. conf.end_msg(False)
  79. else:
  80. conf.fatal('could not configure a C compiler!')
  81. def options(opt):
  82. """
  83. This is how to provide compiler preferences on the command-line::
  84. $ waf configure --check-c-compiler=gcc
  85. """
  86. test_for_compiler = default_compilers()
  87. opt.load_special_tools('c_*.py', ban=['c_dumbpreproc.py'])
  88. cc_compiler_opts = opt.add_option_group('Configuration options')
  89. cc_compiler_opts.add_option('--check-c-compiler', default=None,
  90. help='list of C compilers to try [%s]' % test_for_compiler,
  91. dest="check_c_compiler")
  92. for x in test_for_compiler.split():
  93. opt.load('%s' % x)