wscript 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2010 (ita)
  4. VERSION='0.0.1'
  5. APPNAME='cc_test'
  6. top = '.'
  7. out = 'build'
  8. """
  9. General variant system
  10. Call for example:
  11. $ waf configure build_debug build_release clean_debug clean_release
  12. The builds will end in different build folders
  13. note how "bld.variant" is used to detect the current variant
  14. See also playground/remote/wscript for a more specific example
  15. """
  16. def configure(conf):
  17. conf.setenv('debug')
  18. conf.load('compiler_c')
  19. conf.define("A", 1)
  20. conf.define("B", 1.1)
  21. conf.define("C", "1.1e19", quote=False)
  22. # the configuration file must be written in each variant
  23. conf.write_config_header('debug/config.h', remove=False)
  24. conf.setenv('release', env=conf.env.derive()) # start with a copy instead of a new env
  25. conf.env.CFLAGS = ['-O2']
  26. conf.options.prefix = '/opt' # warning: this changes the options globally
  27. conf.load('compiler_c')
  28. conf.define('E', 1)
  29. conf.write_config_header('release/config.h')
  30. def build(bld):
  31. # cleaning from the top-level directory might remove
  32. # the file 'config.h' from the variants, so we
  33. # are forcing the use of *debug or *release commands
  34. #
  35. # the config set 'debug' is loaded automatically when the 'debug' variant is used
  36. if not bld.variant:
  37. bld.fatal('Call "waf build_debug" or "waf build_release", and read the comments in the wscript file!')
  38. # the includes='.' add the build directory path to the command arguments
  39. # (look at the -I flags by using waf -v)
  40. bld.program(source='main.c', target='app', includes='.')
  41. # To use multiple compilers at once, either:
  42. #
  43. # * use a particular environment from the configuration:
  44. # bld.env = bld.all_envs['debug']
  45. # bld.program(source='main.c', target='app2', includes='.')
  46. # * add an 'env' parameter to a particular task generator:
  47. # bld.program(..., env=bld.all_envs['release'].derive())
  48. def options(opt):
  49. opt.load('compiler_c')
  50. def init(ctx):
  51. from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
  52. for x in 'debug release'.split():
  53. for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
  54. name = y.__name__.replace('Context','').lower()
  55. class tmp(y):
  56. cmd = name + '_' + x
  57. variant = x
  58. ## if you work on "debug" 99% of the time, here is how to re-enable "waf build":
  59. #for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
  60. # class tmp(y):
  61. # variant = 'debug'
  62. # you may also set 'win32/debug' instead of 'debug'
  63. # the commands will be "build_win32/debug" or "build_win32/release"
  64. # in this case you may want to modify Options.commands in this "init" function
  65. # calling "waf buildall" will run "waf build_debug build_release"
  66. def buildall(ctx):
  67. import waflib.Options
  68. for x in ('build_debug', 'build_release'):
  69. waflib.Options.commands.insert(0, x)
  70. # --------------------------
  71. # or, if you want to memorize the default variant and just type "waf",
  72. #
  73. #def options(opt):
  74. # opt.load('compiler_c')
  75. #def init(ctx):
  76. # from waflib import ConfigSet, Options
  77. # env = ConfigSet.ConfigSet()
  78. # try:
  79. # env.load('build/c4che/foo.txt')
  80. # except:
  81. # the_variant = 'debug'
  82. # else:
  83. # the_variant = env.the_variant or debug
  84. #
  85. # if getattr(Options.options, 'the_variant', ''):
  86. # if Options.options.the_variant != the_variant:
  87. # the_variant = env.the_variant = Options.options.the_variant
  88. # env.store('build/c4che/foo.txt')
  89. #
  90. # for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
  91. # class tmp(y):
  92. # variant = the_variant
  93. # --------------------------
  94. # Or, if you like to have a command-line flag
  95. # - add ctx.load('variant') to options and init functions
  96. # - add --variant=<name of the variant> to the command line
  97. #def options(ctx):
  98. # ctx.add_option('--variant', action='store', default='', help='set the variant name')
  99. #def init(ctx):
  100. # from waflib.Options import options
  101. # from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
  102. # from waflib.Configure import ConfigurationContext
  103. # for y in (BuildContext, CleanContext, InstallContext, UninstallContext, ConfigurationContext):
  104. # name = y.__name__.replace('Context','').lower()
  105. # class tmp(y):
  106. # cmd = name
  107. # variant = options.variant
  108. #