diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-07-16 13:28:28 +0200 |
---|---|---|
committer | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-11-21 21:22:36 +0100 |
commit | 7e2edad8efea55e8df1faa695d1389ef4e326d7c (patch) | |
tree | f9662620b8ecaf50f6c67804dd0d99d00d85fe5b /waftools/checks/generic.py | |
parent | 0cb9227a73f03a6ecdf71e837c7c33c823b194b4 (diff) | |
download | mpv-7e2edad8efea55e8df1faa695d1389ef4e326d7c.tar.bz2 mpv-7e2edad8efea55e8df1faa695d1389ef4e326d7c.tar.xz |
switch the build system to waf
This commit adds a new build system based on waf. configure and Makefile
are deprecated effective immediately and someday in the future they will be
removed (they are still available by running ./old-configure).
You can find how the choice for waf came to be in `DOCS/waf-buildsystem.rst`.
TL;DR: we couldn't get the same level of abstraction and customization with
other build systems we tried (CMake and autotools).
For guidance on how to build the software now, take a look at README.md
and the cross compilation guide.
CREDITS:
This is a squash of ~250 commits. Some of them are not by me, so here is the
deserved attribution:
- @wm4 contributed some Windows fixes, renamed configure to old-configure
and contributed to the bootstrap script. Also, GNU/Linux testing.
- @lachs0r contributed some Windows fixes and the bootstrap script.
- @Nikoli contributed a lot of testing and discovered many bugs.
- @CrimsonVoid contributed changes to the bootstrap script.
Diffstat (limited to 'waftools/checks/generic.py')
-rw-r--r-- | waftools/checks/generic.py | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/waftools/checks/generic.py b/waftools/checks/generic.py new file mode 100644 index 0000000000..46813aed01 --- /dev/null +++ b/waftools/checks/generic.py @@ -0,0 +1,134 @@ +import os +from inflectors import DependencyInflector + +__all__ = [ + "check_pkg_config", "check_cc", "check_statement", "check_libs", + "check_headers", "compose_checks", "check_true", "any_version", + "load_fragment", "check_stub", "check_ctx_vars"] + +any_version = None + +def even(n): + return n % 2 == 0 + +def __define_options__(dependency_identifier): + return DependencyInflector(dependency_identifier).define_dict() + +def __merge_options__(dependency_identifier, *args): + options_accu = DependencyInflector(dependency_identifier).storage_dict() + options_accu['mandatory'] = False + [options_accu.update(arg) for arg in args if arg] + return options_accu + + +def check_libs(libs, function): + libs = [None] + libs + def fn(ctx, dependency_identifier): + for lib in libs: + kwargs = lib and {'lib': lib} or {} + if function(ctx, dependency_identifier, **kwargs): + return True + return False + return fn + +def check_statement(header, statement, **kw_ext): + def fn(ctx, dependency_identifier, **kw): + fragment = """ + #include <{0}> + int main(int argc, char **argv) + {{ {1}; return 0; }} """.format(header, statement) + opts = __merge_options__(dependency_identifier, + {'fragment':fragment}, + __define_options__(dependency_identifier), + kw_ext, kw) + return ctx.check_cc(**opts) + return fn + +def check_cc(**kw_ext): + def fn(ctx, dependency_identifier, **kw): + options = __merge_options__(dependency_identifier, + __define_options__(dependency_identifier), + kw_ext, kw) + return ctx.check_cc(**options) + return fn + +def check_pkg_config(*args, **kw_ext): + def fn(ctx, dependency_identifier, **kw): + argsl = list(args) + packages = [el for (i, el) in enumerate(args) if even(i)] + sargs = [i for i in args if i] # remove None + pkgc_args = ["--libs", "--cflags"] + if ctx.dependency_satisfied('static-build'): + pkgc_args += ["--static"] + + defaults = { + 'path': ctx.env.PKG_CONFIG, + 'package': " ".join(packages), + 'args': sargs + pkgc_args } + opts = __merge_options__(dependency_identifier, defaults, kw_ext, kw) + if ctx.check_cfg(**opts): + return True + else: + defkey = DependencyInflector(dependency_identifier).define_key() + ctx.undefine(defkey) + return False + return fn + +def check_headers(*headers): + def undef_others(ctx, headers, found): + not_found_hs = set(headers) - set([found]) + for not_found_h in not_found_hs: + defkey = DependencyInflector(not_found_h).define_key() + ctx.undefine(defkey) + + def fn(ctx, dependency_identifier): + for header in headers: + defaults = {'header_name': header, 'features': 'c cprogram'} + options = __merge_options__(dependency_identifier, defaults) + if ctx.check(**options): + undef_others(ctx, headers, header) + defkey = DependencyInflector(dependency_identifier).define_key() + ctx.define(defkey, 1) + return True + undef_others(ctx, headers, None) + return False + return fn + +def check_true(ctx, dependency_identifier): + defkey = DependencyInflector(dependency_identifier).define_key() + ctx.define(defkey, 1) + return True + +def check_ctx_vars(*variables): + def fn(ctx, dependency_identifier): + missing = [] + for variable in variables: + if variable not in ctx.env: + missing.append(variable) + + if any(missing): + ctx.add_optional_message(dependency_identifier, + 'missing {0}'.format(', '.join(missing))) + return False + else: + return True + + return fn + +def check_stub(ctx, dependency_identifier): + defkey = DependencyInflector(dependency_identifier).define_key() + ctx.undefine(defkey) + return False + +def compose_checks(*checks): + def fn(ctx, dependency_identifier): + return all([check(ctx, dependency_identifier) for check in checks]) + return fn + +def load_fragment(fragment): + file_path = os.path.join(os.path.dirname(__file__), '..', 'fragments', + fragment) + fp = open(file_path,"r") + fragment_code = fp.read() + fp.close() + return fragment_code |