VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/python/gen_python_deps.py@ 99206

Last change on this file since 99206 was 99206, checked in by vboxsync, 20 months ago

xpcom18a4/python: Avoid distutils starting with python 3.10.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette