1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4#   BAREOS(R) - Backup Archiving REcovery Open Sourced
5#
6#   Copyright (C) 2020-2020 Bareos GmbH & Co. KG
7#
8#   This program is Free Software; you can redistribute it and/or
9#   modify it under the terms of version three of the GNU Affero General Public
10#   License as published by the Free Software Foundation, which is
11#   listed in the file LICENSE.
12#
13#   This program is distributed in the hope that it will be useful, but
14#   WITHOUT ANY WARRANTY; without even the implied warranty of
15#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16#   Affero General Public License for more details.
17#
18#   You should have received a copy of the GNU Affero General Public License
19#   along with this program; if not, write to the Free Software
20#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21#   02110-1301, USA.
22
23#  This program extracts the build configuration from the python interpreter.
24#  The output is consumed by cmake where appropriate variables are set.
25#  This is required to build python modules without setuptools.
26
27import sys
28
29try:
30    import sysconfig
31except:
32    import distutils.sysconfig as sysconfig
33
34for var in ("CC", "BLDSHARED"):
35    value = sysconfig.get_config_var(var)
36    print(
37        'message(STATUS "Python{0}_{1}\ is\  {2}")'.format(
38            sys.version_info[0], var, value
39        )
40    )
41    print('set(Python{0}_{1} "{2}")'.format(sys.version_info[0], var, value))
42
43    # if nothing comes after the compile command, the flags are empty
44    try:
45        value = value.split(" ", 1)[1]
46    except:
47        value = ""
48    # as these vars contain the compiler itself, we remove the first word and return it as _FLAGS
49    print(
50        'message(STATUS "Python{0}_{1}_FLAGS\ is\  {2}")'.format(
51            sys.version_info[0], var, value
52        )
53    )
54    print('set(Python{0}_{1}_FLAGS "{2}")'.format(sys.version_info[0], var, value))
55
56for var in ("CFLAGS", "CCSHARED", "INCLUDEPY", "LDFLAGS"):
57    value = sysconfig.get_config_var(var)
58    print(
59        'message(STATUS "Python{0}_{1}\ is\  {2}")'.format(
60            sys.version_info[0], var, value
61        )
62    )
63    print('set(Python{0}_{1} "{2}")'.format(sys.version_info[0], var, value))
64
65for var in ("EXT_SUFFIX",):
66    value = sysconfig.get_config_var(var)
67    if value is None:
68        value = ""
69    print(
70        'message(STATUS "Python{0}_{1}\ is\  {2}")'.format(
71            sys.version_info[0], var, value
72        )
73    )
74    print('set(Python{0}_{1} "{2}")'.format(sys.version_info[0], var, value))
75