summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2014-08-04 10:44:21 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2014-08-06 09:31:59 +0200
commit212374149f7c957ea25ea12404f92c625fdc211a (patch)
tree3438e2ef3a6735ebcb37e1d88d3ea77ac5133203
parentc8cf864bfff3e56c45f129e9d825cb41d54a647e (diff)
downloadmpv-212374149f7c957ea25ea12404f92c625fdc211a.tar.bz2
mpv-212374149f7c957ea25ea12404f92c625fdc211a.tar.xz
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.
-rw-r--r--waftools/generators/headers.py8
-rw-r--r--wscript27
2 files changed, 35 insertions, 0 deletions
diff --git a/waftools/generators/headers.py b/waftools/generators/headers.py
index b38fcb88f4..bd28befd99 100644
--- a/waftools/generators/headers.py
+++ b/waftools/generators/headers.py
@@ -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):
diff --git a/wscript b/wscript
index ee1ece5744..e0d71235e5 100644
--- a/wscript
+++ b/wscript
@@ -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)