pandora_python3_devel.m4 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. dnl -*- mode: m4; c-basic-offset: 2; indent-tabs-mode: nil; -*-
  2. dnl vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  3. dnl
  4. dnl pandora-build: A pedantic build system
  5. dnl
  6. dnl Copyright (C) 2009 Sun Microsystems, Inc.
  7. dnl Copyright (C) 2008 Sebastian Huber <sebastian-huber@web.de>
  8. dnl Copyright (C) 2008 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
  9. dnl Copyright (C) 2008 Rafael Laboissiere <rafael@laboissiere.net>
  10. dnl Copyright (C) 2008 Andrew Collier <colliera@ukzn.ac.za>
  11. dnl Copyright (C) 2008 Matteo Settenvini <matteo@member.fsf.org>
  12. dnl Copyright (C) 2008 Horst Knorr <hk_classes@knoda.org>
  13. dnl
  14. dnl This program is free software: you can redistribute it and/or modify it
  15. dnl under the terms of the GNU General Public License as published by the
  16. dnl Free Software Foundation, either version 3 of the License, or (at your
  17. dnl option) any later version.
  18. dnl
  19. dnl This program is distributed in the hope that it will be useful, but
  20. dnl WITHOUT ANY WARRANTY; without even the implied warranty of
  21. dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  22. dnl Public License for more details.
  23. dnl
  24. dnl You should have received a copy of the GNU General Public License along
  25. dnl with this program. If not, see <http://www.gnu.org/licenses/>.
  26. dnl
  27. dnl As a special exception, the respective Autoconf Macro's copyright owner
  28. dnl gives unlimited permission to copy, distribute and modify the configure
  29. dnl scripts that are the output of Autoconf when processing the Macro. You
  30. dnl need not follow the terms of the GNU General Public License when using
  31. dnl or distributing such scripts, even though portions of the text of the
  32. dnl Macro appear in them. The GNU General Public License (GPL) does govern
  33. dnl all other use of the material that constitutes the Autoconf Macro.
  34. dnl
  35. dnl This special exception to the GPL applies to versions of the Autoconf
  36. dnl Macro released by the Autoconf Macro Archive. When you make and
  37. dnl distribute a modified version of the Autoconf Macro, you may extend this
  38. dnl special exception to the GPL to apply to your modified version as well.
  39. dnl SYNOPSIS
  40. dnl
  41. dnl PANDORA_PYTHON3_DEVEL([version])
  42. dnl
  43. dnl DESCRIPTION
  44. dnl
  45. dnl Note: Defines as a precious variable "PYTHON3_VERSION". Don't override it
  46. dnl in your configure.ac.
  47. dnl
  48. dnl This macro checks for Python and tries to get the include path to
  49. dnl 'Python.h'. It provides the $(PYTHON3_CPPFLAGS) and $(PYTHON3_LDFLAGS)
  50. dnl output variables. It also exports $(PYTHON3_EXTRA_LIBS) and
  51. dnl $(PYTHON3_EXTRA_LDFLAGS) for embedding Python in your code.
  52. dnl
  53. dnl You can search for some particular version of Python by passing a
  54. dnl parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". Please
  55. dnl note that you *have* to pass also an operator along with the version to
  56. dnl match, and pay special attention to the single quotes surrounding the
  57. dnl version number. Don't use "PYTHON3_VERSION" for this: that environment
  58. dnl variable is declared as precious and thus reserved for the end-user.
  59. dnl
  60. dnl LAST MODIFICATION
  61. dnl
  62. dnl 2009-08-23
  63. AC_DEFUN([PANDORA_PYTHON3_DEVEL],[
  64. #
  65. # Allow the use of a (user set) custom python version
  66. #
  67. AC_ARG_VAR([PYTHON3_VERSION],[The installed Python
  68. version to use, for example '3.0'. This string
  69. will be appended to the Python interpreter
  70. canonical name.])
  71. AS_IF([test -z "$PYTHON3"],[
  72. AC_PATH_PROG([PYTHON3],[python[$PYTHON3_VERSION]])
  73. ])
  74. AS_IF([test -z "$PYTHON3"],[
  75. PANDORA_MSG_ERROR([Cannot find python$PYTHON3_VERSION in your system path])
  76. PYTHON3_VERSION=""
  77. ])
  78. #
  79. # if the macro parameter ``version'' is set, honour it
  80. #
  81. if test -n "$1"; then
  82. AC_MSG_CHECKING([for a version of Python $1])
  83. ac_supports_python3_ver=`$PYTHON3 -c "import sys, string; \
  84. ver = string.split(sys.version)[[0]]; \
  85. print(ver $1)"`
  86. if test "$ac_supports_python3_ver" = "True"; then
  87. AC_MSG_RESULT([yes])
  88. else
  89. AC_MSG_RESULT([no])
  90. PANDORA_MSG_ERROR([this package requires Python $1.
  91. If you have it installed, but it isn't the default Python
  92. interpreter in your system path, please pass the PYTHON3_VERSION
  93. variable to configure. See ``configure --help'' for reference.
  94. ])
  95. PYTHON_VERSION=""
  96. fi
  97. fi
  98. #
  99. # Check if you have distutils, else fail
  100. #
  101. AC_MSG_CHECKING([for Python3 distutils package])
  102. ac_python3_distutils_result=`$PYTHON3 -c "import distutils" 2>&1`
  103. if test -z "$ac_python3_distutils_result"; then
  104. AC_MSG_RESULT([yes])
  105. else
  106. AC_MSG_RESULT([no])
  107. PANDORA_MSG_ERROR([cannot import Python3 module "distutils".
  108. Please check your Python3 installation. The error was:
  109. $ac_python3_distutils_result])
  110. PYTHON3_VERSION=""
  111. fi
  112. #
  113. # Check for Python include path
  114. #
  115. AC_MSG_CHECKING([for Python3 include path])
  116. if test -z "$PYTHON3_CPPFLAGS"; then
  117. python3_path=`$PYTHON3 -c "import distutils.sysconfig; \
  118. print(distutils.sysconfig.get_python_inc());"`
  119. if test -n "${python3_path}"; then
  120. python3_path="-I$python3_path"
  121. fi
  122. PYTHON3_CPPFLAGS=$python3_path
  123. fi
  124. AC_MSG_RESULT([$PYTHON3_CPPFLAGS])
  125. AC_SUBST([PYTHON3_CPPFLAGS])
  126. #
  127. # Check for Python library path
  128. #
  129. AC_MSG_CHECKING([for Python3 library path])
  130. if test -z "$PYTHON3_LDFLAGS"; then
  131. # (makes two attempts to ensure we've got a version number
  132. # from the interpreter)
  133. py3_version=`$PYTHON3 -c "from distutils.sysconfig import *; \
  134. print(' '.join(get_config_vars('VERSION')))"`
  135. if test "$py3_version" == "[None]"; then
  136. if test -n "$PYTHON3_VERSION"; then
  137. py3_version=$PYTHON3_VERSION
  138. else
  139. py3_version=`$PYTHON3 -c "import sys; \
  140. print(sys.version[[:3]])"`
  141. fi
  142. fi
  143. PYTHON3_LDFLAGS=`$PYTHON3 -c "from distutils.sysconfig import *; \
  144. print('-L' + get_python_lib(0,1), \
  145. '-lpython');"`$py3_version
  146. fi
  147. AC_MSG_RESULT([$PYTHON3_LDFLAGS])
  148. AC_SUBST([PYTHON3_LDFLAGS])
  149. #
  150. # Check for site packages
  151. #
  152. AC_MSG_CHECKING([for Python3 site-packages path])
  153. if test -z "$PYTHON3_SITE_PKG"; then
  154. PYTHON3_SITE_PKG=`$PYTHON3 -c "import distutils.sysconfig; \
  155. print(distutils.sysconfig.get_python_lib(0,0));"`
  156. fi
  157. AC_MSG_RESULT([$PYTHON3_SITE_PKG])
  158. AC_SUBST([PYTHON3_SITE_PKG])
  159. #
  160. # libraries which must be linked in when embedding
  161. #
  162. AC_MSG_CHECKING(for Python3 embedding libraries)
  163. if test -z "$PYTHON3_EMBED_LIBS"; then
  164. PYTHON3_EMBED_LIBS=`$PYTHON3 -c "import distutils.sysconfig; \
  165. conf = distutils.sysconfig.get_config_var; \
  166. print(conf('LOCALMODLIBS'), conf('LIBS'))"`
  167. fi
  168. AC_MSG_RESULT([$PYTHON3_EMBED_LIBS])
  169. AC_SUBST(PYTHON3_EMBED_LIBS)
  170. #
  171. # linking flags needed when embedding
  172. #
  173. AC_MSG_CHECKING(for Python3 embedding linking flags)
  174. if test -z "$PYTHON3_EMBED_LDFLAGS"; then
  175. PYTHON3_EMBED_LDFLAGS=`$PYTHON3 -c "import distutils.sysconfig; \
  176. conf = distutils.sysconfig.get_config_var; \
  177. print(conf('LINKFORSHARED'))"`
  178. fi
  179. AC_MSG_RESULT([$PYTHON3_EMBED_LDFLAGS])
  180. AC_SUBST(PYTHON3_EMBED_LDFLAGS)
  181. #
  182. # final check to see if everything compiles alright
  183. #
  184. AC_MSG_CHECKING([for Python3 development environment consistency])
  185. AC_LANG_PUSH([C])
  186. # save current global flags
  187. ac_save_LIBS="$LIBS"
  188. ac_save_CPPFLAGS="$CPPFLAGS"
  189. LIBS="$ac_save_LIBS $PYTHON3_LDFLAGS"
  190. CPPFLAGS="$ac_save_CPPFLAGS $PYTHON3_CPPFLAGS"
  191. AC_TRY_LINK([
  192. #include <Python.h>
  193. ],[
  194. Py_Initialize();
  195. ],[python3exists=yes],[python3exists=no])
  196. AC_MSG_RESULT([$python3exists])
  197. if test ! "$python3exists" = "yes"; then
  198. AC_MSG_WARN([
  199. Could not link test program to Python3.
  200. Maybe the main Python3 library has been installed in some non-standard
  201. library path. If so, pass it to configure, via the LDFLAGS environment
  202. variable.
  203. Example: ./configure LDFLAGS="-L/usr/non-standard-path/python3/lib"
  204. ============================================================================
  205. ERROR!
  206. You probably have to install the development version of the Python3 package
  207. for your distribution. The exact name of this package varies among them.
  208. ============================================================================
  209. ])
  210. PYTHON3_VERSION=""
  211. fi
  212. AC_LANG_POP
  213. # turn back to default flags
  214. CPPFLAGS="$ac_save_CPPFLAGS"
  215. LIBS="$ac_save_LIBS"
  216. #
  217. # all done!
  218. #
  219. ])