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