SCons: cleaner determination of 32-bit/64-bit builds
[blender.git] / build_files / scons / config / Modules / FindPython.py
1 import os
2 import platform
3
4 def FindPython():
5     all_abi_flags = ['m', 'mu', '']
6
7     python = "/usr"
8     abi_flags = "m"  # Most common for linux distros
9     version = "3.3"
10
11     _arch = platform.uname()[4] + "-linux-gnu"
12
13     # Determine ABI flags used on this system
14     include = os.path.join(python, "include")
15     for cur_flags in all_abi_flags:
16         inc = os.path.join(include, "python" + version + cur_flags, "Python.h")
17         if os.path.exists(inc):
18             abi_flags = cur_flags
19             break
20
21     # Find config.h. In some distros, such as ubuntu 12.10 they are not in standard include dir.
22     incconf = os.path.join(include, _arch, "python" + version + cur_flags)
23     if not os.path.exists(os.path.join(incconf, "pyconfig.h")):
24         incconf = ''
25
26     # Determine whether python is in /usr/lib or /usr/lib64
27     lib32 = os.path.join(python, "lib", "python" + version, "sysconfig.py")
28     lib64 = os.path.join(python, "lib64", "python" + version, "sysconfig.py")
29     if os.path.exists(lib32):
30         libpath = "${BF_PYTHON}/lib"
31     elif os.path.exists(lib64):
32         libpath = "${BF_PYTHON}/lib64"
33     else:
34         # roll back to default value
35         libpath = "${BF_PYTHON}/lib"
36
37     libpath_arch = libpath
38     _libpath_arch = os.path.join(python, "lib", _arch)  # No lib64 stuff with recent deb-like distro afaik...
39     _libs = ["libpython" + version + abi_flags + ext for ext in (".so", ".a")]
40     for l in _libs:
41         if not os.path.exists(os.path.join(libpath, l)) and os.path.exists(os.path.join(_libpath_arch, l)):
42             libpath_arch = os.path.join(libpath, _arch)
43             break
44
45     return {"PYTHON": python,
46             "VERSION": version,
47             "LIBPATH": libpath,
48             "LIBPATH_ARCH": libpath_arch,
49             "ABI_FLAGS": abi_flags,
50             "CONFIG": incconf}