gcc.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2006-2018 (ita)
  4. # Ralf Habacker, 2006 (rh)
  5. # Yinon Ehrlich, 2009
  6. """
  7. gcc/llvm detection.
  8. """
  9. from waflib.Tools import ccroot, ar
  10. from waflib.Configure import conf
  11. @conf
  12. def find_gcc(conf):
  13. """
  14. Find the program gcc, and if present, try to detect its version number
  15. """
  16. cc = conf.find_program(['gcc', 'cc'], var='CC')
  17. conf.get_cc_version(cc, gcc=True)
  18. conf.env.CC_NAME = 'gcc'
  19. @conf
  20. def gcc_common_flags(conf):
  21. """
  22. Common flags for gcc on nearly all platforms
  23. """
  24. v = conf.env
  25. v.CC_SRC_F = []
  26. v.CC_TGT_F = ['-c', '-o']
  27. if not v.LINK_CC:
  28. v.LINK_CC = v.CC
  29. v.CCLNK_SRC_F = []
  30. v.CCLNK_TGT_F = ['-o']
  31. v.CPPPATH_ST = '-I%s'
  32. v.DEFINES_ST = '-D%s'
  33. v.LIB_ST = '-l%s' # template for adding libs
  34. v.LIBPATH_ST = '-L%s' # template for adding libpaths
  35. v.STLIB_ST = '-l%s'
  36. v.STLIBPATH_ST = '-L%s'
  37. v.RPATH_ST = '-Wl,-rpath,%s'
  38. v.SONAME_ST = '-Wl,-h,%s'
  39. v.SHLIB_MARKER = '-Wl,-Bdynamic'
  40. v.STLIB_MARKER = '-Wl,-Bstatic'
  41. v.cprogram_PATTERN = '%s'
  42. v.CFLAGS_cshlib = ['-fPIC']
  43. v.LINKFLAGS_cshlib = ['-shared']
  44. v.cshlib_PATTERN = 'lib%s.so'
  45. v.LINKFLAGS_cstlib = ['-Wl,-Bstatic']
  46. v.cstlib_PATTERN = 'lib%s.a'
  47. v.LINKFLAGS_MACBUNDLE = ['-bundle', '-undefined', 'dynamic_lookup']
  48. v.CFLAGS_MACBUNDLE = ['-fPIC']
  49. v.macbundle_PATTERN = '%s.bundle'
  50. @conf
  51. def gcc_modifier_win32(conf):
  52. """Configuration flags for executing gcc on Windows"""
  53. v = conf.env
  54. v.cprogram_PATTERN = '%s.exe'
  55. v.cshlib_PATTERN = '%s.dll'
  56. v.implib_PATTERN = '%s.dll.a'
  57. v.IMPLIB_ST = '-Wl,--out-implib,%s'
  58. v.CFLAGS_cshlib = []
  59. # Auto-import is enabled by default even without this option,
  60. # but enabling it explicitly has the nice effect of suppressing the rather boring, debug-level messages
  61. # that the linker emits otherwise.
  62. import sys
  63. if sys.platform != "cygwin":
  64. # disabled on cygwin as it breaks build with arm cross compiler
  65. v.append_value('LINKFLAGS', ['-Wl,--enable-auto-import'])
  66. @conf
  67. def gcc_modifier_cygwin(conf):
  68. """Configuration flags for executing gcc on Cygwin"""
  69. gcc_modifier_win32(conf)
  70. v = conf.env
  71. v.cshlib_PATTERN = 'cyg%s.dll'
  72. v.append_value('LINKFLAGS_cshlib', ['-Wl,--enable-auto-image-base'])
  73. v.CFLAGS_cshlib = []
  74. @conf
  75. def gcc_modifier_darwin(conf):
  76. """Configuration flags for executing gcc on MacOS"""
  77. v = conf.env
  78. v.CFLAGS_cshlib = ['-fPIC']
  79. v.LINKFLAGS_cshlib = ['-dynamiclib']
  80. v.cshlib_PATTERN = 'lib%s.dylib'
  81. v.FRAMEWORKPATH_ST = '-F%s'
  82. v.FRAMEWORK_ST = ['-framework']
  83. v.ARCH_ST = ['-arch']
  84. v.LINKFLAGS_cstlib = []
  85. v.SHLIB_MARKER = []
  86. v.STLIB_MARKER = []
  87. v.SONAME_ST = []
  88. @conf
  89. def gcc_modifier_aix(conf):
  90. """Configuration flags for executing gcc on AIX"""
  91. v = conf.env
  92. v.LINKFLAGS_cprogram = ['-Wl,-brtl']
  93. v.LINKFLAGS_cshlib = ['-shared','-Wl,-brtl,-bexpfull']
  94. v.SHLIB_MARKER = []
  95. @conf
  96. def gcc_modifier_hpux(conf):
  97. v = conf.env
  98. v.SHLIB_MARKER = []
  99. v.STLIB_MARKER = []
  100. v.CFLAGS_cshlib = ['-fPIC','-DPIC']
  101. v.cshlib_PATTERN = 'lib%s.sl'
  102. @conf
  103. def gcc_modifier_openbsd(conf):
  104. conf.env.SONAME_ST = []
  105. @conf
  106. def gcc_modifier_osf1V(conf):
  107. v = conf.env
  108. v.SHLIB_MARKER = []
  109. v.STLIB_MARKER = []
  110. v.SONAME_ST = []
  111. @conf
  112. def gcc_modifier_platform(conf):
  113. """Execute platform-specific functions based on *gcc_modifier_+NAME*"""
  114. # * set configurations specific for a platform.
  115. # * the destination platform is detected automatically by looking at the macros the compiler predefines,
  116. # and if it's not recognised, it fallbacks to sys.platform.
  117. gcc_modifier_func = getattr(conf, 'gcc_modifier_' + conf.env.DEST_OS, None)
  118. if gcc_modifier_func:
  119. gcc_modifier_func()
  120. def configure(conf):
  121. """
  122. Configuration for gcc
  123. """
  124. conf.find_gcc()
  125. conf.find_ar()
  126. conf.gcc_common_flags()
  127. conf.gcc_modifier_platform()
  128. conf.cc_load_tools()
  129. conf.cc_add_flags()
  130. conf.link_add_flags()
  131. conf.check_gcc_o_space()