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