1 | #!/usr/bin/python
|
---|
2 |
|
---|
3 | """
|
---|
4 | Copyright (C) 2009-2022 Oracle and/or its affiliates.
|
---|
5 |
|
---|
6 | This file is part of VirtualBox base platform packages, as
|
---|
7 | available from https://www.virtualbox.org.
|
---|
8 |
|
---|
9 | This program is free software; you can redistribute it and/or
|
---|
10 | modify it under the terms of the GNU General Public License
|
---|
11 | as published by the Free Software Foundation, in version 3 of the
|
---|
12 | License.
|
---|
13 |
|
---|
14 | This program is distributed in the hope that it will be useful, but
|
---|
15 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
17 | General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU General Public License
|
---|
20 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
21 |
|
---|
22 | SPDX-License-Identifier: GPL-3.0-only
|
---|
23 | """
|
---|
24 |
|
---|
25 | from __future__ import print_function
|
---|
26 | import os,sys
|
---|
27 | from distutils.version import StrictVersion
|
---|
28 |
|
---|
29 | versions = ["2.6", "2.7", "3.1", "3.2", "3.2m", "3.3", "3.3m", "3.4", "3.4m", "3.5", "3.5m", "3.6", "3.6m", "3.7", "3.7m", "3.8", "3.8m", "3.9", "3.9m", "3.10", "3.10m", "3.11", "3.11m" ]
|
---|
30 | prefixes = ["/usr", "/usr/local", "/opt", "/opt/local"]
|
---|
31 | known = {}
|
---|
32 |
|
---|
33 | def checkPair(p, v, dllpre, dllsuff, bitness_magic):
|
---|
34 | incdir = os.path.join(p, "include", "python"+v)
|
---|
35 | incfile = os.path.join(incdir, "Python.h")
|
---|
36 | if not os.path.isfile(incfile):
|
---|
37 | return None
|
---|
38 |
|
---|
39 | lib = os.path.join(p, "lib/i386-linux-gnu", dllpre+"python"+v+dllsuff)
|
---|
40 | if not os.path.isfile(lib):
|
---|
41 | lib = os.path.join(p, "lib", dllpre+"python"+v+dllsuff)
|
---|
42 | if not os.path.isfile(lib):
|
---|
43 | lib = None
|
---|
44 |
|
---|
45 | if bitness_magic == 1:
|
---|
46 | lib64 = os.path.join(p, "lib", "64", dllpre+"python"+v+dllsuff)
|
---|
47 | if not os.path.isfile(lib64):
|
---|
48 | lib64 = None
|
---|
49 | elif bitness_magic == 2:
|
---|
50 | lib64 = os.path.join(p, "lib/x86_64-linux-gnu", dllpre+"python"+v+dllsuff)
|
---|
51 | if not os.path.isfile(lib64):
|
---|
52 | lib64 = os.path.join(p, "lib64", dllpre+"python"+v+dllsuff)
|
---|
53 | if not os.path.isfile(lib64):
|
---|
54 | lib64 = os.path.join(p, "lib", dllpre+"python"+v+dllsuff)
|
---|
55 | if not os.path.isfile(lib64):
|
---|
56 | lib64 = None
|
---|
57 | else:
|
---|
58 | lib64 = None
|
---|
59 |
|
---|
60 | if lib is None and lib64 is None:
|
---|
61 | return None
|
---|
62 | else:
|
---|
63 | return [incdir, lib, lib64]
|
---|
64 |
|
---|
65 | def print_vars(vers, known, sep, bitness_magic):
|
---|
66 | print("VBOX_PYTHON%s_INC=%s%s" %(vers, known[0], sep))
|
---|
67 | if bitness_magic > 0:
|
---|
68 | if known[2]:
|
---|
69 | print("VBOX_PYTHON%s_LIB=%s%s" %(vers, known[2], sep))
|
---|
70 | if known[1]:
|
---|
71 | print("VBOX_PYTHON%s_LIB_X86=%s%s" %(vers, known[1], sep))
|
---|
72 | else:
|
---|
73 | print("VBOX_PYTHON%s_LIB=%s%s" %(vers, known[1], sep))
|
---|
74 |
|
---|
75 |
|
---|
76 | def main(argv):
|
---|
77 | global prefixes
|
---|
78 | global versions
|
---|
79 |
|
---|
80 | dllpre = "lib"
|
---|
81 | dllsuff = ".so"
|
---|
82 | bitness_magic = 0
|
---|
83 |
|
---|
84 | if len(argv) > 1:
|
---|
85 | target = argv[1]
|
---|
86 | else:
|
---|
87 | target = sys.platform
|
---|
88 |
|
---|
89 | if len(argv) > 2:
|
---|
90 | arch = argv[2]
|
---|
91 | else:
|
---|
92 | arch = "unknown"
|
---|
93 |
|
---|
94 | if len(argv) > 3:
|
---|
95 | multi = int(argv[3])
|
---|
96 | else:
|
---|
97 | multi = 1
|
---|
98 |
|
---|
99 | if multi == 0:
|
---|
100 | prefixes = ["/usr"]
|
---|
101 | versions = [str(sys.version_info[0])+'.'+str(sys.version_info[1]),
|
---|
102 | str(sys.version_info[0])+'.'+str(sys.version_info[1])+'m']
|
---|
103 |
|
---|
104 | if target == 'darwin':
|
---|
105 | ## @todo Pick up the locations from VBOX_PATH_MACOSX_SDK_10_*.
|
---|
106 | prefixes = ['/Developer/SDKs/MacOSX10.4u.sdk/usr',
|
---|
107 | '/Developer/SDKs/MacOSX10.5.sdk/usr',
|
---|
108 | '/Developer/SDKs/MacOSX10.6.sdk/usr',
|
---|
109 | '/Developer/SDKs/MacOSX10.7.sdk/usr']
|
---|
110 | dllsuff = '.dylib'
|
---|
111 |
|
---|
112 | if target == 'solaris' and arch == 'amd64':
|
---|
113 | bitness_magic = 1
|
---|
114 |
|
---|
115 | if target == 'linux' and arch == 'amd64':
|
---|
116 | bitness_magic = 2
|
---|
117 |
|
---|
118 | for v in versions:
|
---|
119 | if v.endswith("m"):
|
---|
120 | realversion = v[:-1]
|
---|
121 | else:
|
---|
122 | realversion = v
|
---|
123 | if StrictVersion(realversion) < StrictVersion('2.6'):
|
---|
124 | continue
|
---|
125 | for p in prefixes:
|
---|
126 | c = checkPair(p, v, dllpre, dllsuff, bitness_magic)
|
---|
127 | if c is not None:
|
---|
128 | known[v] = c
|
---|
129 | break
|
---|
130 | keys = list(known.keys())
|
---|
131 | # we want default to be the lowest versioned Python
|
---|
132 | keys.sort()
|
---|
133 | d = None
|
---|
134 | # We need separator other than newline, to sneak through $(shell)
|
---|
135 | sep = "|"
|
---|
136 | for k in keys:
|
---|
137 | if d is None:
|
---|
138 | d = k
|
---|
139 | vers = k.replace('.', '').upper()
|
---|
140 | print_vars(vers, known[k], sep, bitness_magic)
|
---|
141 | if d is not None:
|
---|
142 | print_vars("DEF", known[d], sep, bitness_magic)
|
---|
143 | else:
|
---|
144 | print(argv[0] + ": No Python development package found!", file=sys.stderr)
|
---|
145 |
|
---|
146 | if __name__ == '__main__':
|
---|
147 | main(sys.argv)
|
---|