1#!/usr/bin/env python3
2
3import os, sys, shutil, subprocess
4
5global_options = ['--werror']
6
7flavors = {
8    'debug': {
9        'options': [
10            '-Dtest=true',
11            '-Ddocumentation=enabled',
12        ],
13    },
14
15    'release': {
16        'options': [
17            '--buildtype', 'release',
18            '-Db_ndebug=true',
19            '-Db_lto=true',
20            '-Dtest=true',
21            '-Ddocumentation=disabled',
22        ],
23    },
24
25    'mini': {
26        'options': [
27            '--buildtype', 'release',
28            '-Db_ndebug=true',
29            '-Db_lto=true',
30            '-Diconv=disabled',
31            '-Ddocumentation=disabled',
32        ],
33    },
34
35    'musl': {
36        'options': [
37            '--buildtype', 'minsize',
38            '--default-library', 'static',
39            '-Db_ndebug=true',
40            '-Db_lto=true',
41            '-Ddocumentation=disabled',
42        ],
43        'env': {
44            'CC': 'musl-gcc',
45        },
46    },
47
48    'win32': {
49        'arch': 'i686-w64-mingw32',
50        'options': [
51            '-Ddocumentation=disabled',
52        ]
53    },
54
55    'win64': {
56        'arch': 'x86_64-w64-mingw32',
57        'options': [
58            '-Ddocumentation=disabled',
59        ]
60    },
61}
62
63project_name = 'mpc'
64source_root = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]) or '.', '..'))
65output_path = os.path.join(source_root, 'output')
66prefix_root = '/usr/local/stow'
67
68for name, data in flavors.items():
69    print(name)
70    build_root = os.path.join(output_path, name)
71
72    env = os.environ.copy()
73    if 'env' in data:
74        env.update(data['env'])
75
76    cmdline = [
77        'meson', source_root, build_root,
78    ] + global_options
79
80    if 'options' in data:
81        cmdline.extend(data['options'])
82
83    prefix = os.path.join(prefix_root, project_name + '-' + name)
84
85    if 'arch' in data:
86        prefix = os.path.join(prefix, data['arch'])
87        cmdline += ('--cross-file', os.path.join(source_root, 'build', name, 'cross-file.txt'))
88
89    cmdline += ('--prefix', prefix)
90
91    try:
92        shutil.rmtree(build_root)
93    except:
94        pass
95
96    subprocess.check_call(cmdline, env=env)
97