python-autoconf.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. # coding: utf-8
  2. #
  3. #
  4. # Python module to detect python settings to build and install python
  5. # embedded interpreter and any external modules
  6. #
  7. #
  8. # Copyright (C) 1994-2018 Altair Engineering, Inc.
  9. # For more information, contact Altair at www.altair.com.
  10. #
  11. # This file is part of the PBS Professional ("PBS Pro") software.
  12. #
  13. # Open Source License Information:
  14. #
  15. # PBS Pro is free software. You can redistribute it and/or modify it under the
  16. # terms of the GNU Affero General Public License as published by the Free
  17. # Software Foundation, either version 3 of the License, or (at your option) any
  18. # later version.
  19. #
  20. # PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
  21. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  22. # FOR A PARTICULAR PURPOSE.
  23. # See the GNU Affero General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU Affero General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. #
  28. # Commercial License Information:
  29. #
  30. # For a copy of the commercial license terms and conditions,
  31. # go to: (http://www.pbspro.com/UserArea/agreement.html)
  32. # or contact the Altair Legal Department.
  33. #
  34. # Altair’s dual-license business model allows companies, individuals, and
  35. # organizations to create proprietary derivative works of PBS Pro and
  36. # distribute them - whether embedded or bundled with other software -
  37. # under a commercial license agreement.
  38. #
  39. # Use of Altair’s trademarks, including but not limited to "PBS™",
  40. # "PBS Professional®", and "PBS Pro™" and Altair’s logos is subject to Altair's
  41. # trademark licensing policies.
  42. #
  43. # NOTE:
  44. # - requires the distutils, os and sys packages to be installed.
  45. _REQUIRED_VERSION_MIN = '2.6.0'
  46. _REQUIRED_VERSION_MAX = '2.7.99'
  47. import sys
  48. import os
  49. if sys.version < _REQUIRED_VERSION_MIN or sys.version > _REQUIRED_VERSION_MAX:
  50. print "requires python version >= %s" % (_REQUIRED_VERSION,)
  51. raise SystemExit,2
  52. from optparse import OptionParser
  53. from distutils import sysconfig
  54. get_py_config_var = sysconfig.get_config_var
  55. py_version = get_py_config_var('VERSION')
  56. if py_version is None:
  57. py_version = sys.version[:3]
  58. py_stdlibdir = get_py_config_var('LIBDIR')
  59. # the actual LIBDIR in case install path got moved
  60. if py_stdlibdir:
  61. py_stdlibdir_real = "%s/%s" % (sysconfig.PREFIX, py_stdlibdir.split(os.sep)[-1])
  62. else:
  63. py_stdlibdir_real = "%s/lib" % (sysconfig.PREFIX,)
  64. py_lib_configdir = get_py_config_var('LIBPL')
  65. if py_lib_configdir:
  66. py_lib_configdir=py_lib_configdir.replace(py_stdlibdir,py_stdlibdir_real)
  67. def get_includes():
  68. """get compiled pythons include directories"""
  69. rv = ["-I%s" % (sysconfig.get_python_inc(plat_specific=1),), "-I%s" % (sysconfig.get_python_inc(),)]
  70. return " ".join(rv)
  71. #:: get_includes()
  72. def get_cflags():
  73. """get compiler flags"""
  74. rv = ""
  75. cflags = get_py_config_var('CFLAGS')
  76. if cflags:
  77. rv = " ".join(cflags.split())
  78. #: TODO you could remove some options?
  79. return rv
  80. #:: get_cflags()
  81. def get_libs():
  82. """get libraries to link with"""
  83. rv = ""
  84. tmp_list = []
  85. if py_lib_configdir:
  86. tmp_list.append('-L%s' % (py_lib_configdir,))
  87. tmp_list.append("-lpython%s" % (py_version,))
  88. libs = get_py_config_var('LIBS')
  89. if libs:
  90. tmp_list.extend(libs.split())
  91. syslibs = get_py_config_var('SYSLIBS')
  92. if syslibs:
  93. tmp_list.extend(syslibs.split())
  94. if tmp_list:
  95. rv = " ".join(tmp_list)
  96. return rv
  97. #:: get_libs()
  98. def get_ldflags():
  99. """get linker flags for the compiled python"""
  100. rv = ""
  101. tmp_list = []
  102. #: this is needed so that symbols are not removed from the static library
  103. #: when shared modules need to be loaded
  104. py_link_for_shared = get_py_config_var('LINKFORSHARED')
  105. if py_lib_configdir:
  106. py_link_for_shared = py_link_for_shared.replace("Modules",
  107. py_lib_configdir);
  108. if py_link_for_shared:
  109. tmp_list.append(py_link_for_shared)
  110. if tmp_list:
  111. rv = " ".join(tmp_list)
  112. return rv
  113. #:: get_ldflagss()
  114. def get_stdlibdir():
  115. """The installed pythons library directory"""
  116. rv = ""
  117. tmp_list = []
  118. if py_stdlibdir_real:
  119. tmp_list.append(py_stdlibdir_real)
  120. if tmp_list:
  121. rv = " ".join(tmp_list)
  122. return rv
  123. #:: get_stdlibdir()
  124. def setupOptions():
  125. usage = "usage: %prog [options]"
  126. parser = OptionParser(usage=usage)
  127. parser.add_option("--includes", action="store_true", dest="includes",
  128. help="get header file includes for python installation")
  129. parser.add_option("--cflags", action="store_true", dest="cflags",
  130. help="get Compiler flags")
  131. parser.add_option("--libs", action="store_true", dest="libs",
  132. help="get additional libraries to be linked with")
  133. parser.add_option("--ldflags",action="store_true", dest="ldflags",
  134. help="get library flags")
  135. parser.add_option("--stdlibdir",action="store_true", dest="stdlibdir",
  136. help="get installed python's libdir")
  137. parser.add_option("--py-version",action="store_true", dest="py_version",
  138. help="get version string to determine the installed python standard modules dir")
  139. parser.add_option("--stdlibmoddir",action="store_true", dest="stdlibmoddir",
  140. help="get installed python's standard modules libdir")
  141. parser.add_option("--stdlibmodshareddir",action="store_true", dest="stdlibmodshareddir",
  142. help="get installed python's standard modules *shared* libdir")
  143. return parser.parse_args()
  144. #:: seetupOptions()
  145. def Main():
  146. (options, args) = setupOptions()
  147. if options.ldflags:
  148. print get_ldflags()
  149. elif options.libs:
  150. print get_libs()
  151. elif options.cflags:
  152. print get_cflags()
  153. elif options.includes:
  154. print get_includes()
  155. elif options.stdlibdir:
  156. print get_stdlibdir()
  157. elif options.py_version:
  158. print py_version
  159. elif options.stdlibmoddir:
  160. print \
  161. get_py_config_var('DESTLIB').replace(py_stdlibdir,py_stdlibdir_real)
  162. elif options.stdlibmodshareddir:
  163. print \
  164. get_py_config_var('DESTSHARED').replace(py_stdlibdir,py_stdlibdir_real)
  165. #:: Main()
  166. if __name__ == '__main__':
  167. Main()