Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

519 lines
17KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_python_embed.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_PYTHON_DEFAULT
  8. # AX_PYTHON_ENABLE
  9. # AX_PYTHON_WITH
  10. # AX_PYTHON_PATH
  11. # AX_PYTHON_VERSION_ENSURE( [2.2] )
  12. # AX_PYTHON_CSPEC
  13. # AX_PYTHON_LSPEC
  14. #
  15. # DESCRIPTION
  16. #
  17. # This file provides autoconf support for those applications that want to
  18. # embed python. It supports all pythons >= 2.2 which is the first official
  19. # release containing distutils. Version 2.2 of python was released
  20. # December 21, 2001. Since it actually executes the python, cross platform
  21. # configuration will probably not work. Also, most of the platforms
  22. # supported are consistent until you look into Mac OS X. The python
  23. # included with it is installed as a framework which is a very different
  24. # environment to set up the normal tools such as gcc and libtool to deal
  25. # with. Therefore, once we establish which python that we are going to
  26. # use, we use its distutils to actually compile and link our modules or
  27. # applications.
  28. #
  29. # At this time, it does NOT support linking with Python statically. It
  30. # does support dynamic linking.
  31. #
  32. # This set of macros help define $PYTHON, $PYTHON_USE, $PYTHON_CSPEC and
  33. # $PYTHON_LSPEC. $PYTHON defines the full executable path for the Python
  34. # being linked to and is used within these macros to determine if that has
  35. # been specified or found. These macros do execute this python version so
  36. # it must be present on the system at configure time.
  37. #
  38. # $PYTHON_USE is an automake variable that defines whether Python support
  39. # should be included or not in your application. $PYTHON_CSPEC is a
  40. # variable that supplies additional CFLAGS for the compilation of the
  41. # application/shared library. $PYTHON_LSPEC is a variable that supplies
  42. # additional LDFLAGS for linking the application/shared library.
  43. #
  44. # The following is an example of how to set up for python usage within
  45. # your application in your configure.in:
  46. #
  47. # AX_PYTHON_DEFAULT( )
  48. # AX_PYTHON_ENABLE( ) # Optional
  49. # AX_PYTHON_WITH( ) # Optional
  50. # AX_PYTHON_PATH( ) # or AX_PYTHON_INSIST( )
  51. # # if $PYTHON is not defined, then the following do nothing.
  52. # AX_PYTHON_VERSION_ENSURE( [2.2] )
  53. # AX_PYTHON_CSPEC
  54. # AX_PYTHON_LSPEC
  55. #
  56. # The AX_PYTHON_DEFAULT sets the $PYTHON_USE to false. Thereby, excluding
  57. # it if it was optional.
  58. #
  59. # The AX_PYTHON_ENABLE looks for the optional configure parameters of
  60. # --enable-python/--disable-python and establishes the $PYTHON and
  61. # $PYTHON_USE variables accordingly.
  62. #
  63. # The AX_PYTHON_WITH looks for the optional configure parameters of
  64. # --with-python/--without-python and establishes the $PYTHON and
  65. # $PYTHON_USE variables accordingly.
  66. #
  67. # The AX_PYTHON_PATH looks for python assuming that none has been
  68. # previously found or defined and issues an error if it does not find it.
  69. # If it does find it, it establishes the $PYTHON and $PYTHON_USE variables
  70. # accordingly. AX_PYTHON_INSIST could be used here instead if you want to
  71. # insist that Python support be included using the --enable-python or
  72. # --with-python checks previously done.
  73. #
  74. # The AX_PYTHON_VERSION_ENSURE issues an error if the Python previously
  75. # found is not of version 2.2 or greater.
  76. #
  77. # Once that these macros have be run, we can use PYTHON_USE within the
  78. # makefile.am file to conditionally add the Python support such as:
  79. #
  80. # Makefile.am example showing optional inclusion of directories:
  81. #
  82. # if PYTHON_USE
  83. # plugins = plugins
  84. # src = src
  85. # else
  86. # plugins =
  87. # src =
  88. # endif
  89. #
  90. # SUBDIRS = . $(plugins) $(src)
  91. #
  92. # Makefile.am example showing optional shared library build:
  93. #
  94. # if PYTHON_USE
  95. # lib_LTLIBRARIES = libElemList.la
  96. # libElemList_la_SOURCES = libElemList.c
  97. # libElemList_la_CFLAGS = @PYTHON_CSPEC@
  98. # libElemList_la_LDFLAGS = @PYTHON_LSPEC@
  99. # endif
  100. #
  101. # Makefile.am example showing optional program build:
  102. #
  103. # if PYTHON_USE
  104. # bin_PROGRAMS = runFunc
  105. # runFunc_SOURCES = runFunc.c
  106. # runFunc_CFLAGS = @PYTHON_CSPEC@
  107. # runFunc_LDFLAGS = @PYTHON_LSPEC@
  108. # endif
  109. #
  110. # The above compiles the modules only if PYTHON_USE was specified as true.
  111. # Also, the else portion of the if was optional.
  112. #
  113. # LICENSE
  114. #
  115. # Copyright (c) 2008 Robert White <kranki@mac.com>
  116. # Copyright (c) 2008 Dustin J. Mitchell <dustin@cs.uchicago.edu>
  117. #
  118. # Copying and distribution of this file, with or without modification, are
  119. # permitted in any medium without royalty provided the copyright notice
  120. # and this notice are preserved. This file is offered as-is, without any
  121. # warranty.
  122. #serial 15
  123. # AX_PYTHON_DEFAULT( )
  124. # -----------------
  125. # Sets the default to not include Python support.
  126. AC_DEFUN([AX_PYTHON_DEFAULT],
  127. [
  128. ax_python_use=false
  129. AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true")
  130. ])
  131. # AX_PYTHON_ENABLE( [path] )
  132. # -----------------------------------------------------------------
  133. # Handles the various --enable-python commands.
  134. # Input:
  135. # $1 is the optional search path for the python executable if needed
  136. # Output:
  137. # PYTHON_USE (AM_CONDITIONAL) is true if python executable found
  138. # and --enable-python was requested; otherwise false.
  139. # $PYTHON contains the full executable path to python if PYTHON_ENABLE_USE
  140. # is true.
  141. #
  142. # Example:
  143. # AX_PYTHON_ENABLE( )
  144. # or
  145. # AX_PYTHON_ENABLE( "/usr/bin" )
  146. AC_DEFUN([AX_PYTHON_ENABLE],
  147. [
  148. AC_ARG_VAR([PYTHON],[Python Executable Path])
  149. # unless PYTHON was supplied to us (as a precious variable),
  150. # see if --enable-python[=PythonExecutablePath], --enable-python,
  151. # --disable-python or --enable-python=no was given.
  152. if test -z "$PYTHON"
  153. then
  154. AC_MSG_CHECKING(for --enable-python)
  155. AC_ARG_ENABLE(
  156. python,
  157. AS_HELP_STRING([--enable-python@<:@=PYTHON@:>@],
  158. [absolute path name of Python executable]
  159. ),
  160. [
  161. if test "$enableval" = "yes"
  162. then
  163. # "yes" was specified, but we don't have a path
  164. # for the executable.
  165. # So, let's search the PATH Environment Variable.
  166. AC_MSG_RESULT(yes)
  167. AC_PATH_PROG(
  168. [PYTHON],
  169. python,
  170. [],
  171. $1
  172. )
  173. if test -z "$PYTHON"
  174. then
  175. AC_MSG_ERROR(no path to python found)
  176. fi
  177. ax_python_use=true
  178. AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true")
  179. AX_PYTHON_PREFIX( )
  180. elif test "$enableval" = "no"
  181. then
  182. AC_MSG_RESULT(no)
  183. ax_python_use=false
  184. AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true")
  185. else
  186. # $enableval must be the executable path then.
  187. AC_SUBST([PYTHON], ["${enableval}"])
  188. AC_MSG_RESULT($withval)
  189. ax_python_use=true
  190. AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true")
  191. AX_PYTHON_PREFIX( )
  192. fi
  193. ],
  194. [
  195. # --with-python was not specified.
  196. AC_MSG_RESULT(no)
  197. ax_python_use=false
  198. AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true")
  199. ]
  200. )
  201. fi
  202. ])
  203. # AX_PYTHON_CSPEC( )
  204. # -----------------
  205. # Set up the c compiler options to compile Python
  206. # embedded programs/libraries in $PYTHON_CSPEC if
  207. # $PYTHON has been defined.
  208. AC_DEFUN([AX_PYTHON_CSPEC],
  209. [
  210. AC_ARG_VAR( [PYTHON], [Python Executable Path] )
  211. if test -n "$PYTHON"
  212. then
  213. ax_python_prefix=`${PYTHON} -c "import sys; print(sys.prefix)"`
  214. if test -z "$ax_python_prefix"
  215. then
  216. AC_MSG_ERROR([Python Prefix is not known])
  217. fi
  218. ax_python_execprefix=`${PYTHON} -c "import sys; print(sys.exec_prefix)"`
  219. ax_python_version=`$PYTHON -c "import sys; print(sys.version[[:3]])"`
  220. ax_python_includespec="-I${ax_python_prefix}/include/python${ax_python_version}"
  221. if test x"$python_prefix" != x"$python_execprefix"; then
  222. ax_python_execspec="-I${ax_python_execprefix}/include/python${ax_python_version}"
  223. ax_python_includespec="${ax_python_includespec} $ax_python_execspec"
  224. fi
  225. ax_python_ccshared=`${PYTHON} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('CFLAGSFORSHARED'))"`
  226. ax_python_cspec="${ax_python_ccshared} ${ax_python_includespec}"
  227. AC_SUBST([PYTHON_CSPEC], [${ax_python_cspec}])
  228. AC_MSG_NOTICE([PYTHON_CSPEC=${ax_python_cspec}])
  229. fi
  230. ])
  231. # AX_PYTHON_INSIST( )
  232. # -----------------
  233. # Look for Python and set the output variable 'PYTHON'
  234. # to 'python' if found, empty otherwise.
  235. AC_DEFUN([AX_PYTHON_INSIST],
  236. [
  237. AC_ARG_VAR( [PYTHON], [Python Executable Path] )
  238. if test -z "$PYTHON"
  239. then
  240. AC_MSG_ERROR([Python Executable not found])
  241. fi
  242. ])
  243. # AX_PYTHON_LSPEC( )
  244. # -----------------
  245. # Set up the linker options to link Python embedded
  246. # programs/libraries in $PYTHON_LSPEC if $PYTHON
  247. # has been defined.
  248. AC_DEFUN([AX_PYTHON_LSPEC],
  249. [
  250. AC_ARG_VAR( [PYTHON], [Python Executable Path] )
  251. if test -n "$PYTHON"
  252. then
  253. AX_PYTHON_RUN([
  254. import sys
  255. import distutils.sysconfig
  256. strUseFrameWork = "--enable-framework"
  257. dictConfig = distutils.sysconfig.get_config_vars( )
  258. strConfigArgs = dictConfig.get("CONFIG_ARGS")
  259. strLinkSpec = dictConfig.get('LDFLAGS')
  260. if -1 == strConfigArgs.find(strUseFrameWork):
  261. strLibPL = dictConfig.get("LIBPL")
  262. if strLibPL and (strLibPL != ""):
  263. strLinkSpec += " -L%s" % (strLibPL)
  264. strSys = dictConfig.get("SYSLIBS")
  265. if strSys and (strSys != ""):
  266. strLinkSpec += " %s" % (strSys)
  267. strSHL = dictConfig.get("SHLIBS")
  268. if strSHL and (strSHL != ""):
  269. strLinkSpec += " %s" % (strSHL)
  270. # Construct the Python Library Name.
  271. strTmplte = " -lpython%d.%d"
  272. if (sys.platform == "win32") or (sys.platform == "os2emx"):
  273. strTmplte = " -lpython%d%d"
  274. strWrk = strTmplte % ( (sys.hexversion >> 24),
  275. ((sys.hexversion >> 16) & 0xff))
  276. strLinkSpec += strWrk
  277. else:
  278. # This is not ideal since it changes the search path
  279. # for Frameworks which could have side-effects on
  280. # other included Frameworks. However, it is necessary
  281. # where someone has installed more than one frameworked
  282. # Python. Frameworks are really only used in MacOSX.
  283. strLibFW = dictConfig.get("PYTHONFRAMEWORKPREFIX")
  284. if strLibFW and (strLibFW != ""):
  285. strLinkSpec += " -F%s" % (strLibFW)
  286. strLinkSpec += " %s" % (dictConfig.get('LINKFORSHARED'))
  287. print(strLinkSpec)
  288. ])
  289. AC_SUBST([PYTHON_LSPEC], [${ax_python_output}])
  290. AC_MSG_NOTICE([PYTHON_LSPEC=${ax_python_output}])
  291. fi
  292. ])
  293. # AX_PYTHON_PATH( )
  294. # -----------------
  295. # Look for Python and set the output variable 'PYTHON'
  296. # to 'python' if found, empty otherwise.
  297. AC_DEFUN([AX_PYTHON_PATH],
  298. [
  299. AC_ARG_VAR( [PYTHON], [Python Executable Path] )
  300. AC_PATH_PROG( PYTHON, python, [], $1 )
  301. if test -z "$PYTHON"
  302. then
  303. AC_MSG_ERROR([Python Executable not found])
  304. else
  305. ax_python_use=true
  306. fi
  307. AM_CONDITIONAL(PYTHON_USE, test "$ax_python_use" = "true")
  308. ])
  309. # AX_PYTHON_PREFIX( )
  310. # -------------------
  311. # Use the values of $prefix and $exec_prefix for the corresponding
  312. # values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.
  313. AC_DEFUN([AX_PYTHON_PREFIX],
  314. [
  315. if test -z "$PYTHON"
  316. then
  317. AC_MSG_ERROR([Python Executable Path is not known])
  318. fi
  319. ax_python_prefix=`${PYTHON} -c "import sys; print(sys.prefix)"`
  320. ax_python_execprefix=`${PYTHON} -c "import sys; print(sys.exec_prefix)"`
  321. AC_SUBST([PYTHON_PREFIX], ["${ax_python_prefix}"])
  322. AC_SUBST([PYTHON_EXECPREFIX], ["${ax_python_execprefix}"])
  323. ])
  324. # AX_PYTHON_RUN( PYTHON_PROGRAM )
  325. # -----------------
  326. # Run a Python Test Program saving its output
  327. # in ax_python_output and its condition code
  328. # in ax_python_cc.
  329. AC_DEFUN([AX_PYTHON_RUN],
  330. [
  331. AC_ARG_VAR( [PYTHON], [Python Executable Path] )
  332. if test -z "$PYTHON"
  333. then
  334. AC_MSG_ERROR([Python Executable not found])
  335. else
  336. cat >conftest.py <<_ACEOF
  337. $1
  338. _ACEOF
  339. ax_python_output=`$PYTHON conftest.py`
  340. ax_python_cc=$?
  341. rm conftest.py
  342. if test -f "conftest.pyc"
  343. then
  344. rm conftest.pyc
  345. fi
  346. fi
  347. ])
  348. # AX_PYTHON_VERSION_CHECK( VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE] )
  349. # -----------------------------------------------------------------------------
  350. # Run ACTION-IF-TRUE if the Python interpreter has version >= VERSION.
  351. # Run ACTION-IF-FALSE otherwise.
  352. # This test uses sys.hexversion instead of the string equivalent (first
  353. # word of sys.version), in order to cope with versions such as 2.2c1.
  354. # hexversion has been introduced in Python 1.5.2; it's probably not
  355. # worth to support older versions (1.5.1 was released on October 31, 1998).
  356. AC_DEFUN([AX_PYTHON_VERSION_CHECK],
  357. [
  358. AC_ARG_VAR( [PYTHON], [Python Executable Path] )
  359. if test -n "$PYTHON"
  360. then
  361. AC_MSG_CHECKING([whether $PYTHON version >= $1])
  362. AX_PYTHON_RUN([
  363. import sys
  364. # split strings by '.' and convert to numeric. Append some zeros
  365. # because we need at least 4 digits for the hex conversion.
  366. # It accepts a string like "X[.Y[.Z]]" with X,Y,Z=digits
  367. # and [] means optional.
  368. minver = list(map(int, '$1'.split('.'))) + [[0, 0, 0]]
  369. minver[3] = 255
  370. minverhex = 0
  371. for i in range(0, 4): minverhex = (minverhex << 8) + minver[[i]]
  372. if sys.hexversion >= minverhex:
  373. sys.exit( 0 )
  374. else:
  375. sys.exit( 1 )
  376. ])
  377. if test $ax_python_cc -eq 0
  378. then
  379. $2
  380. m4_ifvaln(
  381. [$3],
  382. [else $3]
  383. )
  384. fi
  385. fi
  386. ])
  387. # AX_PYTHON_VERSION_ENSURE( VERSION )
  388. # -----------------
  389. # Insure that the Python Interpreter Version
  390. # is greater than or equal to the VERSION
  391. # parameter.
  392. AC_DEFUN([AX_PYTHON_VERSION_ENSURE],
  393. [
  394. AX_PYTHON_VERSION_CHECK(
  395. [$1],
  396. [AC_MSG_RESULT(yes)],
  397. [AC_MSG_ERROR(too old)]
  398. )
  399. ])
  400. # AX_PYTHON_WITH( [path] )
  401. # -----------------------------------------------------------------
  402. # Handles the various --with-python commands.
  403. # Input:
  404. # $1 is the optional search path for the python executable if needed
  405. # Output:
  406. # PYTHON_USE (AM_CONDITIONAL) is true if python executable found
  407. # and --with-python was requested; otherwise false.
  408. # $PYTHON contains the full executable path to python if PYTHON_USE
  409. # is true.
  410. #
  411. # Example:
  412. # AX_PYTHON_WITH( )
  413. # or
  414. # AX_PYTHON_WITH("/usr/bin")
  415. AC_DEFUN([AX_PYTHON_WITH],
  416. [
  417. AC_ARG_VAR([PYTHON],[Python Executable Path])
  418. # unless PYTHON was supplied to us (as a precious variable),
  419. # see if --with-python[=PythonExecutablePath], --with-python,
  420. # --without-python or --with-python=no was given.
  421. if test -z "$PYTHON"
  422. then
  423. AC_MSG_CHECKING(for --with-python)
  424. AC_ARG_WITH(
  425. python,
  426. AS_HELP_STRING([--with-python@<:@=PYTHON@:>@],
  427. [absolute path name of Python executable]
  428. ),
  429. [
  430. if test "$withval" = "yes"
  431. then
  432. # "yes" was specified, but we don't have a path
  433. # for the executable.
  434. # So, let's search the PATH Environment Variable.
  435. AC_MSG_RESULT(yes)
  436. AC_PATH_PROG(
  437. [PYTHON],
  438. python,
  439. [],
  440. $1
  441. )
  442. if test -z "$PYTHON"
  443. then
  444. AC_MSG_ERROR(no path to python found)
  445. fi
  446. ax_python_use=true
  447. AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true")
  448. AX_PYTHON_PREFIX( )
  449. elif test "$withval" = "no"
  450. then
  451. AC_MSG_RESULT(no)
  452. ax_python_use=false
  453. AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true")
  454. else
  455. # $withval must be the executable path then.
  456. AC_SUBST([PYTHON], ["${withval}"])
  457. AC_MSG_RESULT($withval)
  458. ax_python_use=true
  459. AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true")
  460. AX_PYTHON_PREFIX( )
  461. fi
  462. ],
  463. [
  464. # --with-python was not specified.
  465. AC_MSG_RESULT(no)
  466. ax_python_use=false
  467. AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true")
  468. ]
  469. )
  470. fi
  471. ])