wscript 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2006-2012 (ita)
  4. # the following two variables are used by the target "waf dist"
  5. VERSION='0.0.1'
  6. APPNAME='cc_test'
  7. # if you want to cross-compile, use a different command line:
  8. # CC=mingw-gcc AR=mingw-ar waf configure build
  9. top = '.'
  10. from waflib import Configure, Logs, Utils
  11. #Configure.autoconfig = True # True/False/'clobber'
  12. def options(opt):
  13. opt.load('compiler_c gnu_dirs')
  14. def configure(conf):
  15. conf.load('compiler_c gnu_dirs')
  16. # compile and link in the default mode, which is c++ if present
  17. conf.check(fragment='int main() { return 0; }\n')
  18. # just compile in c mode, and do not link
  19. conf.check(fragment='int main() { return 0; }\n', features='c')
  20. try:
  21. conf.check(fragment="int main() { return 0; }\n", execute=True) # 1
  22. except conf.errors.WafError:
  23. Logs.warn('You are probably using a cross-compiler (disabling specific configuration tests)')
  24. conf.check_library(test_exec=False)
  25. else:
  26. conf.check(fragment="""#include<stdio.h>\nint main(){fprintf(stderr, "mu"); printf("%d", 22);return 0;}\n""", execute=True, define_name='HAVE_MU')
  27. conf.check_library(test_exec=True)
  28. conf.check(lib='m', cflags='-Wall', defines=['var=foo', 'x=y'], uselib_store='M', mandatory=False)
  29. conf.check_large_file(mandatory=False)
  30. conf.check_inline()
  31. endianness = conf.check_endianness()
  32. conf.define_cond("BIG_ENDIAN", endianness == "big")
  33. def test_build(ctx):
  34. ctx(rule='echo hello', shell=True, always=True)
  35. # Configuration tests may even be re-used:
  36. #ctx.in_msg = True # suppress console outputs
  37. #ctx.check_large_file(mandatory=False)
  38. conf.multicheck(
  39. # list of conf.check() arguments
  40. {'header_name':'stdio.h', 'msg':'... stdio', 'uselib_store': 'STDIO'},
  41. {'header_name':'xyztabcd.h', 'msg':'... optional xyztabcd.h', 'mandatory': False},
  42. {'header_name':'stdlib.h', 'msg':'... stdlib', 'okmsg': 'aye', 'errmsg': 'nope'},
  43. {'func': test_build, 'msg':'... testing an arbitrary build function', 'okmsg':'ok'},
  44. # parallelism control with after_tests/before_tests
  45. {'header_name':'malloc.h', 'msg':'... malloc', 'uselib_store':'MALLOC', 'id':'malloc_t', 'mandatory':False},
  46. {'header_name':'unistd.h', 'msg':'... unistd', 'uselib_store':'UNISTD', 'before_tests':['malloc_t'], 'mandatory':False},
  47. msg = 'Checking for headers in parallel',
  48. #mandatory = False, # set to False to make all tests non-mandatory
  49. #run_all_tests = False # set to False to stop at the first error
  50. )
  51. conf.check(header_name='stdio.h', auto_add_header_name=True)
  52. #conf.check(header_name='unistd.h')
  53. conf.check(fragment='int main() {return 0;}\n')
  54. conf.write_config_header('config.h')
  55. # exclude system libraries, force a particular folder (see strictlib below)
  56. #conf.check(features='c cprogram strictlib', lib = 'gif', libpath = ['/opt/lib'])
  57. def build(bld):
  58. bld.env.DEFINES=['WAF=1']
  59. bld.recurse('program stlib shlib')
  60. #bld.install_files('/tmp/foo', 'wscript')
  61. #bld.env.PREFIX='/tmp/foo'
  62. bld.install_files('${PREFIX}/', 'program/a.h program/main.c', relative_trick=False)
  63. bld.install_as('${PREFIX}/gnigni.txt', 'wscript')
  64. bld.symlink_as('${PREFIX}/libfoo.so', 'wscript')
  65. p = Utils.subst_vars('${PREFIX}/gnigni.txt', bld.env)
  66. bld.symlink_as('${PREFIX}/share/gnigni-abs.txt', p, relative_trick=False)
  67. bld.symlink_as('${PREFIX}/share/gnigni-rel.txt', p, relative_trick=True)
  68. bld.env.FOO =['m', 'ncurses']
  69. bld.env.ST = '-L%s'
  70. bld.env.A = 'aye'
  71. bld.env.B = 'doh'
  72. bld.env.SRCA = ['aaa']
  73. bld(rule='echo ${ST:FOO} ${ST:SRC} ${A}${B} ${ST:SRCA} ${ST:SRC[0].abspath()}',
  74. always=True, source='wscript', shell=1, name='Shell')
  75. if not Utils.is_win32:
  76. bld(rule='echo ${ST:FOO} ${ST:SRC} ${A}${B} ${ST:SRCA} ${ST:SRC[0].abspath()}',
  77. always=True, source='wscript', shell=0,
  78. stdout=None, stderr=None, # disable synchronized outputs on this rule
  79. cls_keyword=lambda x:'Trying again', name='NoShell')
  80. # illustrate how to add a command 'foo' and to execute things in it
  81. if bld.cmd == 'foo':
  82. def bar(bld):
  83. print('myprogram exit status is',
  84. bld.exec_command(bld.get_tgen_by_name('myprogram').link_task.outputs[0].abspath()))
  85. bld.add_post_fun(bar)
  86. #bld(rule='echo ${SRC} ${tsk.generator.newsize}', newsize='256x256', source='wscript')
  87. # command examples
  88. from waflib.Build import BuildContext
  89. class foo_class(BuildContext):
  90. cmd = 'foo'
  91. from waflib.Context import Context
  92. class package_class(Context):
  93. """just a test, try calling 'waf package' """
  94. cmd = 'package'
  95. fun = 'package'
  96. def package(ctx):
  97. print('just a test', ctx.path.ant_glob('wscript'))
  98. # and a task generator method example
  99. from waflib import TaskGen
  100. @TaskGen.feature('strictlib')
  101. def check_lib_in_libpath(self):
  102. #For use in a configuration check: raise an exception
  103. #if the library file does not exist in the folders pointed by 'libpath'
  104. pths = self.to_list(getattr(self, 'libpath', []))
  105. if pths:
  106. for l in self.to_list(Utils.to_list(getattr(self, 'lib', []))):
  107. for x in pths:
  108. names = Utils.listdir(x)
  109. lname = self.env.cshlib_PATTERN % l
  110. if lname in names:
  111. break
  112. else:
  113. self.bld.fatal('wrong path for the library %s' % l)