configure: Let user know when exit on meson error
[platform/upstream/gstreamer.git] / configure
1 #!/usr/bin/env python3
2 """Script for generating the Makefiles."""
3
4 import argparse
5 import os
6 import sys
7 import shutil
8 import subprocess
9
10
11 PROJECTNAME = "GStreamer 'all'"
12
13 ROOTDIR = os.path.abspath(os.path.dirname(__file__))
14 MAKEFILE_TMPL = """all:
15 %(tab)scd %(build_dir)s && %(ninja)s -k 100; %(ninja)s
16
17 install:
18 %(tab)scd %(build_dir)s && DESTDIR="${DESTDIR}" %(ninja)s install
19
20 check:
21 %(tab)scd %(build_dir)s && %(ninja)s test
22
23 uninstalled:
24 %(tab)scd %(build_dir)s && %(ninja)s uninstalled
25
26 clean:
27 %(tab)srm -Rf %(build_dir)s
28 %(tab)srm Makefile
29 """
30
31
32 def accept_command(commands):
33     """Checks if @command --version works."""
34     for command in commands:
35         try:
36             subprocess.check_output([command, "--version"])
37             return command
38         except FileNotFoundError:
39             pass
40
41     return None
42
43
44 def get_configs(meson):
45      meson_version = subprocess.check_output([meson, '--version']).decode().strip()
46      if meson_version <= '0.33.0':
47          print("Disabling the introspection as support for the introspection with subproject was introduced in 0.34")
48          return ['-Dgstreamer:disable_introspection=true',
49                  '-Dgst-editing-services:disable_introspection=true',
50                  '-Dgst-devtools:disable_introspection=true']
51
52      return []
53
54
55 def configure_meson(args):
56     """Configures meson and generate the Makefile."""
57     meson = accept_command(["meson", "meson.py"])
58     if not meson:
59         print("Install mesonbuild to build %s: http://mesonbuild.com/\n"
60               "You can simply install it with:\n"
61               "    $ sudo pip3 install meson" % PROJECTNAME)
62         exit(1)
63
64     ninja = accept_command(["ninja", "ninja-build"])
65     if not ninja:
66         print("Install ninja-build to build %s: https://ninja-build.org/"
67               % PROJECTNAME)
68         exit(1)
69
70     build_dir = os.path.join(ROOTDIR, "build")
71     shutil.rmtree(build_dir, True)
72     os.mkdir(build_dir)
73     os.chdir(build_dir)
74
75     try:
76         subprocess.check_call([meson, "../"] + args + get_configs(meson))
77     except subprocess.CalledProcessError as e:
78         print("EXIT meson return %s" % e.returncode)
79         exit(1)
80
81     with open(os.path.join(ROOTDIR, "Makefile"), "w") as makefile:
82         makefile.write(MAKEFILE_TMPL %
83                        {"build_dir": build_dir,
84                         "ninja": ninja,
85                         "tab": "        "})
86
87 if __name__ == "__main__":
88     parser = argparse.ArgumentParser(description='Process some integers.')
89     parser.add_argument("--no-reconfigure", action='store_true',
90                         default=False, help='Avoid removing the build dir'
91                        ' if not necessary.')
92     options, args = parser.parse_known_args()
93     if options.no_reconfigure:
94         if os.path.exists(
95                 ROOTDIR + "/build/build.ninja") and os.path.exists(
96                     ROOTDIR + "/Makefile"):
97             print("Not reconfiguring")
98             exit(0)
99
100     configure_meson(args)