build: expose waf variants to the user

This allows the user to execute multiple configuration and build steps. It
can be used for several scenarios where you need different compiler flags.
This commit is contained in:
Stefano Pigozzi 2014-08-04 10:44:21 +02:00
parent c8cf864bff
commit 212374149f
2 changed files with 35 additions and 0 deletions

View File

@ -1,3 +1,9 @@
def __cp_to_variant__(ctx, variant, basename):
src = ctx.bldnode.search(basename).read()
node = ctx.bldnode.make_node("{0}/{1}".format(variant, basename))
node.parent.mkdir()
node.write(src)
def __get_version__(ctx):
import subprocess
process = subprocess.Popen(["sh", "./version.sh", "--print"],
@ -17,6 +23,7 @@ def __get_build_date__():
def __write_config_h__(ctx):
ctx.start_msg("Writing configuration header:")
ctx.write_config_header('config.h')
__cp_to_variant__(ctx, ctx.options.variant, 'config.h')
ctx.end_msg("config.h", "PINK")
def __write_version_h__(ctx):
@ -25,6 +32,7 @@ def __write_version_h__(ctx):
ctx.define("VERSION", ctx.env.VERSION)
ctx.define("BUILDDATE", __get_build_date__())
ctx.write_config_header("version.h")
__cp_to_variant__(ctx, ctx.options.variant, 'version.h')
ctx.end_msg("version.h", "PINK")
def __add_mplayer_defines__(ctx):

27
wscript
View File

@ -773,6 +773,10 @@ def options(opt):
help = 'directory for installing {0} [{1}]' \
.format(desc, default))
group.add_option('--variant',
default = '',
help = 'variant name for saving configuration and build results')
opt.parse_features('build and install options', build_options)
optional_features = main_dependencies + libav_dependencies
opt.parse_features('optional feaures', optional_features)
@ -798,6 +802,7 @@ def is_debug_build(ctx):
return getattr(ctx.options, 'enable_debug-build')
def configure(ctx):
ctx.resetenv(ctx.options.variant)
ctx.check_waf_version(mini='1.7.15')
target = os.environ.get('TARGET')
(cc, pkg_config, windres) = ('cc', 'pkg-config', 'windres')
@ -858,5 +863,27 @@ def configure(ctx):
ctx.store_dependencies_lists()
def build(ctx):
if ctx.options.variant not in ctx.all_envs:
from waflib import Errors
raise Errors.WafError(
'The project was not configured: run "waf --variant={0} configure" first!'
.format(ctx.options.variant))
ctx.unpack_dependencies_lists()
ctx.load('wscript_build')
def init(ctx):
from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
class tmp(y):
variant = ctx.options.variant
# This is needed because waf initializes the ConfigurationContext with
# an arbitrary setenv('') which would rewrite the previous configuration
# cache for the default variant if the configure step finishes.
# Ideally ConfigurationContext should just let us override this at class
# level like the other Context subclasses do with variant
from waflib.Configure import ConfigurationContext
class cctx(ConfigurationContext):
def resetenv(self, name):
self.all_envs = {}
self.setenv(name)