wscript 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. from waflib.Logs import pprint
  4. top = '.'
  5. out = 'build'
  6. def options(opt):
  7. opt.load('compiler_c')
  8. def configure(conf):
  9. conf.load('compiler_c')
  10. conf.failure = 0
  11. def disp(color, result):
  12. pprint(color, result)
  13. if color == 'RED':
  14. conf.failure=1
  15. def test(*funs):
  16. conf.env.stash()
  17. conf.in_msg = 1 # suppress outputs
  18. for f in funs:
  19. ret = f()
  20. if not ret:
  21. color = "GREEN"
  22. else:
  23. color = "RED"
  24. if ret:
  25. ret = '\t\t' + ret
  26. else:
  27. ret = ''
  28. disp(color, "%s%s" % (f.__doc__, ret))
  29. conf.env.revert()
  30. conf.in_msg = 0
  31. return None
  32. @test
  33. def fun1():
  34. "global_define=1 by default -> no DEFINES_X anywhere"
  35. conf.check_cfg(package='libpng')
  36. conf.check_cc(header_name='unistd.h')
  37. for x in conf.env:
  38. if x.startswith('DEFINES_') and x != 'DEFINES_ST':
  39. return 'conf.env.%s = %r' % (x, conf.env[x])
  40. @test
  41. def fun2():
  42. "global_define=1 -> no DEFINES_X anywhere"
  43. conf.check_cfg(package='libpng', global_define=1)
  44. conf.check_cc(header_name='unistd.h', global_define=1)
  45. for x in conf.env:
  46. if x.startswith('DEFINES_') and x != 'DEFINES_ST':
  47. return 'conf.env.%s = %r' % (x, conf.env[x])
  48. @test
  49. def fun3():
  50. "global_define=0 -> DEFINES=[]"
  51. conf.check_cfg(package='libpng', global_define=0)
  52. conf.check_cc(header_name='unistd.h', global_define=0)
  53. if conf.env.DEFINES:
  54. return 'conf.env.DEFINES = %r' % conf.env.DEFINES
  55. @test
  56. def fun4():
  57. "global_define=0 -> DEFINES_LIBPNG=['HAVE_LIBPNG=1']"
  58. conf.check_cfg(package='libpng', global_define=0)
  59. val = conf.env.DEFINES_LIBPNG
  60. if not isinstance(val, list) or not "HAVE_LIBPNG=1" in val:
  61. return 'conf.env.DEFINES_LIBPNG = %r' % val
  62. @test
  63. def fun5():
  64. "global_defines=0, uselib_store=UNISTD -> DEFINES_UNISTD=['HAVE_UNISTD_H=1']"
  65. conf.check_cc(header_name='unistd.h', uselib_store='UNISTD', global_define=0)
  66. val = conf.env.DEFINES_UNISTD
  67. if not isinstance(val, list) or not 'HAVE_UNISTD_H=1' in val:
  68. return 'conf.env.DEFINES_UNISTD = %r' % val
  69. @test
  70. def fun6():
  71. "global_defines=0, uselib_store=UNISTD, define_name=FOO -> DEFINES_UNISTD=['FOO=1']"
  72. conf.check_cc(header_name='unistd.h', uselib_store='UNISTD', global_define=0, define_name='FOO')
  73. val = conf.env.DEFINES_UNISTD
  74. if not isinstance(val, list) or not 'FOO=1' in val:
  75. return 'conf.env.DEFINES_UNISTD = %r' % val
  76. @test
  77. def fun7():
  78. "uselib_store=UNISTD -> HAVE_UNISTD=1"
  79. conf.check_cc(header_name='unistd.h', uselib_store='UNISTD')
  80. val = conf.env.HAVE_UNISTD
  81. if val != 1:
  82. return 'conf.env.HAVE_UNISTD = %r' % val
  83. @test
  84. def fun8():
  85. "global_defines=0, define_name=HAVE_FOO -> DEFINES_LIBPNG=['HAVE_FOO=1']"
  86. conf.check_cfg(package='libpng', global_define=0, define_name='HAVE_FOO')
  87. val = conf.env.DEFINES_LIBPNG
  88. if not isinstance(val, list) or not "HAVE_FOO=1" in val:
  89. return 'conf.env.DEFINES_LIBPNG = %r' % val
  90. @test
  91. def modversion1():
  92. "modversion=libpng -> DEFINES=['LIBPNG_VERSION=X']"
  93. conf.check_cfg(modversion='libpng')
  94. val = conf.env.DEFINES
  95. # automatic uppercase
  96. if not isinstance(val, list) or not val[0].startswith("LIBPNG_VERSION="):
  97. return 'conf.env.DEFINES = %r' % val
  98. @test
  99. def modversion2():
  100. "modversion=libpng, uselib_store=foo -> DEFINES=['FOO_VERSION=X']"
  101. conf.check_cfg(modversion='libpng', uselib_store='foo')
  102. val = conf.env.DEFINES
  103. # automatic uppercase
  104. if not isinstance(val, list) or not val[0].startswith("FOO_VERSION="):
  105. return 'conf.env.DEFINES = %r' % val
  106. @test
  107. def modversion3():
  108. "modversion=libpng, uselib_store=foo, define_name=bar -> DEFINES=['bar=X']"
  109. conf.check_cfg(modversion='libpng', uselib_store='foo', define_name='bar')
  110. val = conf.env.DEFINES
  111. if not isinstance(val, list) or not val[0].startswith("bar="):
  112. return 'conf.env.DEFINES = %r' % val
  113. @test
  114. def atleast_version1():
  115. "atleast_version=1.0, global_define=1 -> DEFINES=['HAVE_LIBPNG=1']"
  116. # same in waf 1.8 and 1.9
  117. conf.check_cfg(package='libpng', atleast_version='1.0', global_define=1, args='--libs --cflags')
  118. val = conf.env.DEFINES
  119. if not isinstance(val, list) or not 'HAVE_LIBPNG=1' in val:
  120. return 'conf.env.DEFINES = %r' % val
  121. if not conf.env.LIB_LIBPNG:
  122. return 'expected conf.env.LIB_LIBPNG to be defined :-/'
  123. @test
  124. def atleast_version2():
  125. "atleast_version=1.0, uselib_store=foo -> DEFINES=['HAVE_FOO=1']"
  126. conf.check_cfg(package='libpng', uselib_store='foo', atleast_version='1.0', args='--libs --cflags')
  127. val = conf.env.DEFINES
  128. if not isinstance(val, list) or not 'HAVE_FOO=1' in val:
  129. return 'conf.env.DEFINES = %r' % val
  130. if not conf.env.LIB_foo:
  131. return 'expected conf.env.LIB_foo to be defined :-/'
  132. if conf.failure:
  133. conf.fatal('One or several test failed, check the outputs above')