]>
Commit | Line | Data |
---|---|---|
e95f0ea6 | 1 | #!/bin/sh |
561a1805 AS |
2 | # |
3 | # Copyright (C) 2004-2016 ZNC, see the NOTICE file for details. | |
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 | ||
e95f0ea6 AS |
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 | ":""" | |
561a1805 AS |
27 | |
28 | import argparse | |
29 | import os | |
30 | import subprocess | |
31 | import sys | |
32 | import re | |
33 | ||
34 | extra_args = [os.path.dirname(sys.argv[0])] | |
35 | parser = argparse.ArgumentParser() | |
36 | ||
37 | def gnu_install_dir(name, cmake=None): | |
38 | if cmake is None: | |
39 | cmake = name.upper() | |
40 | parser.add_argument('--' + name, action='append', metavar=cmake, | |
41 | dest='cm_args', | |
42 | type=lambda s: '-DCMAKE_INSTALL_{}={}'.format(cmake, s)) | |
43 | ||
44 | gnu_install_dir('prefix') | |
45 | gnu_install_dir('bindir') | |
46 | gnu_install_dir('sbindir') | |
47 | gnu_install_dir('libexecdir') | |
48 | gnu_install_dir('sysconfdir') | |
49 | gnu_install_dir('sharedstatedir') | |
50 | gnu_install_dir('localstatedir') | |
51 | gnu_install_dir('libdir') | |
52 | gnu_install_dir('includedir') | |
53 | gnu_install_dir('oldincludedir') | |
54 | gnu_install_dir('datarootdir') | |
55 | gnu_install_dir('datadir') | |
56 | gnu_install_dir('infodir') | |
57 | gnu_install_dir('localedir') | |
58 | gnu_install_dir('mandir') | |
59 | gnu_install_dir('docdir') | |
60 | ||
61 | ||
62 | group = parser.add_mutually_exclusive_group() | |
63 | group.add_argument('--enable-debug', action='store_const', dest='build_type', | |
64 | const='Debug', default='Release') | |
65 | group.add_argument('--disable-debug', action='store_const', dest='build_type', | |
66 | const='Release', default='Release') | |
67 | ||
68 | def tristate(name, cmake=None): | |
69 | if cmake is None: | |
70 | cmake = name.upper() | |
71 | group = parser.add_mutually_exclusive_group() | |
72 | group.add_argument('--enable-' + name, action='append_const', | |
73 | dest='cm_args', const='-DWANT_{}=YES'.format(cmake)) | |
74 | group.add_argument('--disable-' + name, action='append_const', | |
75 | dest='cm_args', const='-DWANT_{}=NO'.format(cmake)) | |
76 | ||
77 | tristate('ipv6') | |
78 | tristate('openssl') | |
79 | tristate('zlib') | |
80 | tristate('perl') | |
81 | tristate('swig') | |
82 | tristate('cyrus') | |
83 | tristate('charset', 'ICU') | |
84 | tristate('tcl') | |
8eeeaf71 | 85 | tristate('i18n') |
561a1805 AS |
86 | |
87 | class HandlePython(argparse.Action): | |
88 | def __call__(self, parser, namespace, values, option_string=None): | |
89 | extra_args.append('-DWANT_PYTHON=YES') | |
90 | if values is not None: | |
fa79f69b | 91 | extra_args.append('-DWANT_PYTHON_VERSION=' + values) |
561a1805 AS |
92 | |
93 | group = parser.add_mutually_exclusive_group() | |
94 | group.add_argument('--enable-python', action=HandlePython, nargs='?', | |
95 | metavar='PYTHON_VERSION') | |
96 | group.add_argument('--disable-python', action='append_const', dest='cm_args', | |
97 | const='-DWANT_PYTHON=NO') | |
98 | ||
99 | parser.add_argument('--with-gtest', action='store', dest='gtest') | |
100 | parser.add_argument('--with-gmock', action='store', dest='gmock') | |
101 | ||
102 | class HandleSystemd(argparse.Action): | |
103 | def __call__(self, parser, namespace, values, option_string=None): | |
104 | extra_args.append('-DWANT_SYSTEMD=YES') | |
105 | if values is not None: | |
106 | extra_args.append('-DWANT_SYSTEMD_DIR=' + values) | |
107 | ||
108 | parser.add_argument('--with-systemdsystemunitdir', action=HandleSystemd, | |
109 | nargs='?', metavar='UNITDIR') | |
110 | ||
111 | def env_type(s): | |
112 | name, value = s.split('=', 1) | |
113 | return (name, value) | |
114 | ||
115 | parser.add_argument('env', nargs='*', type=env_type, metavar='ENV_VAR=VALUE') | |
116 | ||
117 | args = parser.parse_args() | |
118 | ||
119 | cm_args = args.cm_args or [] | |
120 | ||
121 | for env_key, env_value in args.env: | |
122 | os.environ[env_key] = env_value | |
123 | if args.gtest: | |
124 | os.environ['GTEST_ROOT'] = args.gtest | |
125 | if args.gmock: | |
126 | os.environ['GMOCK_ROOT'] = args.gmock | |
127 | ||
128 | if os.environ.get('CXX') is not None: | |
129 | extra_args.append('-DCMAKE_CXX_COMPILER=' + os.environ['CXX']) | |
130 | ||
131 | try: | |
132 | os.remove('CMakeCache.txt') | |
133 | except OSError: | |
134 | pass | |
135 | subprocess.check_call(['cmake', '-DCMAKE_BUILD_TYPE=' + args.build_type] | |
136 | + cm_args + extra_args) |