Let user know about how to build after configure is done
[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 from common import git
11 from common import Colors
12
13
14 PROJECTNAME = "GStreamer 'all'"
15
16 ROOTDIR = os.path.abspath(os.path.dirname(__file__))
17
18
19 def get_meson():
20     meson = os.path.join(ROOTDIR, 'meson', 'meson.py')
21     if os.path.exists(meson):
22         return meson
23
24     return accept_command(["meson.py", "meson"])
25
26
27 def accept_command(commands):
28     """Checks if @command --version works."""
29     for command in commands:
30         try:
31             subprocess.check_output([command, "--version"])
32             return command
33         except FileNotFoundError:
34             pass
35
36     return None
37
38
39 def get_configs(meson):
40      return ['-D', 'werror=true']
41
42
43 def configure_meson(args, options):
44     """Configures meson and generate the Makefile."""
45     meson = get_meson()
46     if not meson:
47         print("Install mesonbuild to build %s: http://mesonbuild.com/\n"
48               "You can simply install it with:\n"
49               "    $ sudo pip3 install meson" % PROJECTNAME)
50         exit(1)
51
52     ninja = accept_command(["ninja", "ninja-build"])
53     if not ninja:
54         print("Install ninja-build to build %s: https://ninja-build.org/"
55               % PROJECTNAME)
56         exit(1)
57
58     build_dir = os.path.join(ROOTDIR, "build")
59     shutil.rmtree(build_dir, True)
60     os.mkdir(build_dir)
61
62     try:
63         subprocess.check_call([sys.executable, meson, "../"] + args, cwd=build_dir)
64         subprocess.check_call([sys.executable, os.path.join(ROOTDIR, 'meson', 'mesonconf.py')]
65                               + get_configs(meson), cwd=build_dir)
66         print("You can now build GStreamer and its various subprojects running:\n"
67             " $ ninja -C %s" % build_dir)
68     except subprocess.CalledProcessError as e:
69         print("EXIT meson return %s" % e.returncode)
70         exit(1)
71
72
73 if __name__ == "__main__":
74     parser = argparse.ArgumentParser(description='Process some integers.')
75     parser.add_argument("--no-reconfigure", action='store_true',
76                         default=False, help='Avoid removing the build dir'
77                        ' if not necessary.')
78     options, args = parser.parse_known_args()
79     if options.no_reconfigure:
80         if os.path.exists(
81                 ROOTDIR + "/build/build.ninja") and os.path.exists(
82                     ROOTDIR + "/Makefile"):
83             print("Not reconfiguring")
84             exit(0)
85
86     configure_meson(args, options)