waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

wscript (4263B)


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