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.

229 lines
5.8KB

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2010 (ita)
  4. """
  5. Various configuration tests.
  6. """
  7. from waflib import Task
  8. from waflib.Configure import conf
  9. from waflib.TaskGen import feature, before_method, after_method
  10. LIB_CODE = '''
  11. #ifdef _MSC_VER
  12. #define testEXPORT __declspec(dllexport)
  13. #else
  14. #define testEXPORT
  15. #endif
  16. testEXPORT int lib_func(void) { return 9; }
  17. '''
  18. MAIN_CODE = '''
  19. #ifdef _MSC_VER
  20. #define testEXPORT __declspec(dllimport)
  21. #else
  22. #define testEXPORT
  23. #endif
  24. testEXPORT int lib_func(void);
  25. int main(int argc, char **argv) {
  26. (void)argc; (void)argv;
  27. return !(lib_func() == 9);
  28. }
  29. '''
  30. @feature('link_lib_test')
  31. @before_method('process_source')
  32. def link_lib_test_fun(self):
  33. """
  34. The configuration test :py:func:`waflib.Configure.run_build` declares a unique task generator,
  35. so we need to create other task generators from here to check if the linker is able to link libraries.
  36. """
  37. def write_test_file(task):
  38. task.outputs[0].write(task.generator.code)
  39. rpath = []
  40. if getattr(self, 'add_rpath', False):
  41. rpath = [self.bld.path.get_bld().abspath()]
  42. mode = self.mode
  43. m = '%s %s' % (mode, mode)
  44. ex = self.test_exec and 'test_exec' or ''
  45. bld = self.bld
  46. bld(rule=write_test_file, target='test.' + mode, code=LIB_CODE)
  47. bld(rule=write_test_file, target='main.' + mode, code=MAIN_CODE)
  48. bld(features='%sshlib' % m, source='test.' + mode, target='test')
  49. bld(features='%sprogram %s' % (m, ex), source='main.' + mode, target='app', use='test', rpath=rpath)
  50. @conf
  51. def check_library(self, mode=None, test_exec=True):
  52. """
  53. Check if libraries can be linked with the current linker. Uses :py:func:`waflib.Tools.c_tests.link_lib_test_fun`.
  54. :param mode: c or cxx or d
  55. :type mode: string
  56. """
  57. if not mode:
  58. mode = 'c'
  59. if self.env.CXX:
  60. mode = 'cxx'
  61. self.check(
  62. compile_filename = [],
  63. features = 'link_lib_test',
  64. msg = 'Checking for libraries',
  65. mode = mode,
  66. test_exec = test_exec,
  67. )
  68. ########################################################################################
  69. INLINE_CODE = '''
  70. typedef int foo_t;
  71. static %s foo_t static_foo () {return 0; }
  72. %s foo_t foo () {
  73. return 0;
  74. }
  75. '''
  76. INLINE_VALUES = ['inline', '__inline__', '__inline']
  77. @conf
  78. def check_inline(self, **kw):
  79. """
  80. Check for the right value for inline macro.
  81. Define INLINE_MACRO to 1 if the define is found.
  82. If the inline macro is not 'inline', add a define to the ``config.h`` (#define inline __inline__)
  83. :param define_name: define INLINE_MACRO by default to 1 if the macro is defined
  84. :type define_name: string
  85. :param features: by default *c* or *cxx* depending on the compiler present
  86. :type features: list of string
  87. """
  88. self.start_msg('Checking for inline')
  89. if not 'define_name' in kw:
  90. kw['define_name'] = 'INLINE_MACRO'
  91. if not 'features' in kw:
  92. if self.env.CXX:
  93. kw['features'] = ['cxx']
  94. else:
  95. kw['features'] = ['c']
  96. for x in INLINE_VALUES:
  97. kw['fragment'] = INLINE_CODE % (x, x)
  98. try:
  99. self.check(**kw)
  100. except self.errors.ConfigurationError:
  101. continue
  102. else:
  103. self.end_msg(x)
  104. if x != 'inline':
  105. self.define('inline', x, quote=False)
  106. return x
  107. self.fatal('could not use inline functions')
  108. ########################################################################################
  109. LARGE_FRAGMENT = '''#include <unistd.h>
  110. int main(int argc, char **argv) {
  111. (void)argc; (void)argv;
  112. return !(sizeof(off_t) >= 8);
  113. }
  114. '''
  115. @conf
  116. def check_large_file(self, **kw):
  117. """
  118. Check for large file support and define the macro HAVE_LARGEFILE
  119. The test is skipped on win32 systems (DEST_BINFMT == pe).
  120. :param define_name: define to set, by default *HAVE_LARGEFILE*
  121. :type define_name: string
  122. :param execute: execute the test (yes by default)
  123. :type execute: bool
  124. """
  125. if not 'define_name' in kw:
  126. kw['define_name'] = 'HAVE_LARGEFILE'
  127. if not 'execute' in kw:
  128. kw['execute'] = True
  129. if not 'features' in kw:
  130. if self.env.CXX:
  131. kw['features'] = ['cxx', 'cxxprogram']
  132. else:
  133. kw['features'] = ['c', 'cprogram']
  134. kw['fragment'] = LARGE_FRAGMENT
  135. kw['msg'] = 'Checking for large file support'
  136. ret = True
  137. try:
  138. if self.env.DEST_BINFMT != 'pe':
  139. ret = self.check(**kw)
  140. except self.errors.ConfigurationError:
  141. pass
  142. else:
  143. if ret:
  144. return True
  145. kw['msg'] = 'Checking for -D_FILE_OFFSET_BITS=64'
  146. kw['defines'] = ['_FILE_OFFSET_BITS=64']
  147. try:
  148. ret = self.check(**kw)
  149. except self.errors.ConfigurationError:
  150. pass
  151. else:
  152. self.define('_FILE_OFFSET_BITS', 64)
  153. return ret
  154. self.fatal('There is no support for large files')
  155. ########################################################################################
  156. ENDIAN_FRAGMENT = '''
  157. short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
  158. short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
  159. int use_ascii (int i) {
  160. return ascii_mm[i] + ascii_ii[i];
  161. }
  162. short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
  163. short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
  164. int use_ebcdic (int i) {
  165. return ebcdic_mm[i] + ebcdic_ii[i];
  166. }
  167. extern int foo;
  168. '''
  169. class grep_for_endianness(Task.Task):
  170. color = 'PINK'
  171. def run(self):
  172. txt = self.inputs[0].read(flags='rb').decode('iso8859-1')
  173. if txt.find('LiTTleEnDian') > -1:
  174. self.generator.tmp.append('little')
  175. elif txt.find('BIGenDianSyS') > -1:
  176. self.generator.tmp.append('big')
  177. else:
  178. return -1
  179. @feature('grep_for_endianness')
  180. @after_method('process_source')
  181. def grep_for_endianness_fun(self):
  182. """
  183. Used by the endiannes configuration test
  184. """
  185. self.create_task('grep_for_endianness', self.compiled_tasks[0].outputs[0])
  186. @conf
  187. def check_endianness(self):
  188. """
  189. Execute a configuration test to determine the endianness
  190. """
  191. tmp = []
  192. def check_msg(self):
  193. return tmp[0]
  194. self.check(fragment=ENDIAN_FRAGMENT, features='c grep_for_endianness', msg="Checking for endianness", define='ENDIANNESS', tmp=tmp, okmsg=check_msg)
  195. return tmp[0]