]>
Commit | Line | Data |
---|---|---|
84d8375a AS |
1 | #!/bin/sh |
2 | # | |
17a004aa | 3 | # Copyright (C) 2004-2024 ZNC, see the NOTICE file for details. |
84d8375a AS |
4 | # |
5 | # Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | # you may not use this file except in compliance with the License. | |
7 | # You may obtain a copy of the License at | |
8 | # | |
9 | # http://www.apache.org/licenses/LICENSE-2.0 | |
10 | # | |
11 | # Unless required by applicable law or agreed to in writing, software | |
12 | # distributed under the License is distributed on an "AS IS" BASIS, | |
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | # See the License for the specific language governing permissions and | |
15 | # limitations under the License. | |
16 | # | |
17 | ||
18 | # http://stackoverflow.com/questions/18993438/shebang-env-preferred-python-version | |
19 | # http://stackoverflow.com/questions/12070516/conditional-shebang-line-for-different-versions-of-python | |
20 | """:" | |
21 | which python3 >/dev/null 2>&1 && exec python3 "$0" "$@" | |
22 | which python >/dev/null 2>&1 && exec python "$0" "$@" | |
23 | which python2 >/dev/null 2>&1 && exec python2 "$0" "$@" | |
24 | echo "Error: configure wrapper requires python" | |
25 | exec echo "Either install python, or use cmake directly" | |
26 | ":""" | |
27 | ||
28 | import argparse | |
29 | import os | |
4202b3ac | 30 | import shutil |
84d8375a AS |
31 | import subprocess |
32 | import sys | |
33 | import re | |
34 | ||
35 | extra_args = [os.path.dirname(sys.argv[0])] | |
36 | parser = argparse.ArgumentParser() | |
37 | ||
38 | def gnu_install_dir(name, cmake=None): | |
39 | if cmake is None: | |
40 | cmake = name.upper() | |
41 | parser.add_argument('--' + name, action='append', metavar=cmake, | |
42 | dest='cm_args', | |
43 | type=lambda s: '-DCMAKE_INSTALL_{}={}'.format(cmake, s)) | |
44 | ||
45 | gnu_install_dir('prefix') | |
46 | gnu_install_dir('bindir') | |
47 | gnu_install_dir('sbindir') | |
48 | gnu_install_dir('libexecdir') | |
49 | gnu_install_dir('sysconfdir') | |
50 | gnu_install_dir('sharedstatedir') | |
51 | gnu_install_dir('localstatedir') | |
52 | gnu_install_dir('libdir') | |
53 | gnu_install_dir('includedir') | |
54 | gnu_install_dir('oldincludedir') | |
55 | gnu_install_dir('datarootdir') | |
56 | gnu_install_dir('datadir') | |
57 | gnu_install_dir('infodir') | |
58 | gnu_install_dir('localedir') | |
59 | gnu_install_dir('mandir') | |
60 | gnu_install_dir('docdir') | |
61 | ||
62 | ||
63 | group = parser.add_mutually_exclusive_group() | |
64 | group.add_argument('--enable-debug', action='store_const', dest='build_type', | |
65 | const='Debug', default='Release') | |
66 | group.add_argument('--disable-debug', action='store_const', dest='build_type', | |
67 | const='Release', default='Release') | |
68 | ||
69 | def tristate(name, cmake=None): | |
70 | if cmake is None: | |
71 | cmake = name.upper() | |
72 | group = parser.add_mutually_exclusive_group() | |
73 | group.add_argument('--enable-' + name, action='append_const', | |
74 | dest='cm_args', const='-DWANT_{}=YES'.format(cmake)) | |
75 | group.add_argument('--disable-' + name, action='append_const', | |
76 | dest='cm_args', const='-DWANT_{}=NO'.format(cmake)) | |
77 | ||
78 | tristate('ipv6') | |
79 | tristate('openssl') | |
80 | tristate('zlib') | |
81 | tristate('perl') | |
82 | tristate('swig') | |
83 | tristate('cyrus') | |
84 | tristate('charset', 'ICU') | |
85 | tristate('tcl') | |
86 | tristate('i18n') | |
a1a254be | 87 | tristate('argon') |
84d8375a AS |
88 | |
89 | class HandlePython(argparse.Action): | |
90 | def __call__(self, parser, namespace, values, option_string=None): | |
91 | extra_args.append('-DWANT_PYTHON=YES') | |
92 | if values is not None: | |
93 | extra_args.append('-DWANT_PYTHON_VERSION=' + values) | |
94 | ||
95 | group = parser.add_mutually_exclusive_group() | |
96 | group.add_argument('--enable-python', action=HandlePython, nargs='?', | |
97 | metavar='PYTHON_VERSION') | |
98 | group.add_argument('--disable-python', action='append_const', dest='cm_args', | |
99 | const='-DWANT_PYTHON=NO') | |
100 | ||
101 | parser.add_argument('--with-gtest', action='store', dest='gtest') | |
102 | parser.add_argument('--with-gmock', action='store', dest='gmock') | |
103 | ||
104 | class HandleSystemd(argparse.Action): | |
105 | def __call__(self, parser, namespace, values, option_string=None): | |
106 | extra_args.append('-DWANT_SYSTEMD=YES') | |
107 | if values is not None: | |
108 | extra_args.append('-DWANT_SYSTEMD_DIR=' + values) | |
109 | ||
110 | parser.add_argument('--with-systemdsystemunitdir', action=HandleSystemd, | |
111 | nargs='?', metavar='UNITDIR') | |
112 | ||
113 | def env_type(s): | |
114 | name, value = s.split('=', 1) | |
115 | return (name, value) | |
116 | ||
117 | parser.add_argument('env', nargs='*', type=env_type, metavar='ENV_VAR=VALUE') | |
118 | ||
119 | args = parser.parse_args() | |
120 | ||
4202b3ac AS |
121 | if not shutil.which('cmake'): |
122 | print('CMake is required to proceed. Please install it via package manager,\n' | |
123 | 'or download the binary from https://cmake.org/') | |
124 | sys.exit(1) | |
125 | ||
84d8375a AS |
126 | cm_args = args.cm_args or [] |
127 | ||
128 | for env_key, env_value in args.env: | |
129 | os.environ[env_key] = env_value | |
130 | if args.gtest: | |
131 | os.environ['GTEST_ROOT'] = args.gtest | |
132 | if args.gmock: | |
133 | os.environ['GMOCK_ROOT'] = args.gmock | |
134 | ||
135 | if os.environ.get('CXX') is not None: | |
136 | extra_args.append('-DCMAKE_CXX_COMPILER=' + os.environ['CXX']) | |
137 | ||
138 | try: | |
139 | os.remove('CMakeCache.txt') | |
140 | except OSError: | |
141 | pass | |
142 | subprocess.check_call(['cmake', '-DCMAKE_BUILD_TYPE=' + args.build_type] | |
143 | + cm_args + extra_args) |