Salome HOME
New version of hack_libtool utility to workaround problems on some Linux configurations
[modules/kernel.git] / salome_adm / unix / config_files / pyembed.m4
1 dnl  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 dnl
3 dnl  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 dnl  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 dnl
6 dnl  This library is free software; you can redistribute it and/or
7 dnl  modify it under the terms of the GNU Lesser General Public
8 dnl  License as published by the Free Software Foundation; either
9 dnl  version 2.1 of the License.
10 dnl
11 dnl  This library is distributed in the hope that it will be useful,
12 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 dnl  Lesser General Public License for more details.
15 dnl
16 dnl  You should have received a copy of the GNU Lesser General Public
17 dnl  License along with this library; if not, write to the Free Software
18 dnl  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 dnl
20 dnl  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 dnl
22
23 dnl This macro defines the PYTHON_EMBED_{CFLAGS,LDFLAGS,LIBS} substitutions
24 dnl that should be used when embedding the python interpreter into a program.
25 dnl AM_INIT_PYTHON_EMBED
26 dnl
27 AC_DEFUN([AM_INIT_PYTHON_EMBED],
28 [AC_REQUIRE([AM_PATH_PYTHON])
29 AC_REQUIRE([AM_INIT_PYEXEC_MOD])
30
31 AC_MSG_CHECKING(for flags used to embed python interpreter)
32 changequote(,)dnl
33 py_makefile="`$PYTHON -c '
34 import sys
35 print \"%s/lib/python%s/config/Makefile\"%(sys.exec_prefix, sys.version[:3])'`"
36 changequote([,])dnl
37 if test ! -f "$py_makefile"; then
38    AC_MSG_ERROR([*** Couldn't find the python config makefile.  Maybe you are
39 *** missing the development portion of the python installation])
40 fi
41
42 changequote(,)dnl
43 py_lib="`$PYTHON -c '
44 import sys
45 ver = sys.version[:3]
46 pre = sys.exec_prefix
47 print \"-L%s/lib/python%s/config\" % (pre, ver),
48 if ver == \"1.4\":
49         print \"-lPython -lObjects -lParser\"
50 else:
51         print \"-lpython\" + ver
52
53 changequote([,])dnl
54
55 py_ldflags=`sed -n -e 's/^LDFLAGS=\(.*\)/\1/p' $py_makefile`
56 py_linkforshared=`sed -n -e 's/^LINKFORSHARED=\(.*\)/\1/p' $py_makefile`
57
58 PYTHON_EMBED_LDFLAGS="$py_ldflags $py_linkforshared"
59
60 py_localmodlibs=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $py_makefile`
61 py_basemodlibs=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $py_makefile`
62 py_other_libs=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $py_makefile`
63
64 PYTHON_EMBED_LIBS="$py_lib $py_localmodlibs $py_basemodlibs $py_other_libs"
65
66 PYTHON_EMBED_CFLAGS="$PYTHON_INCLUDES"
67
68 AC_MSG_RESULT(done)
69
70 AC_SUBST(PYTHON_EMBED_CFLAGS)
71 AC_SUBST(PYTHON_EMBED_LDFLAGS)
72 AC_SUBST(PYTHON_EMBED_LIBS)
73 ])
74
75 dnl creates a config.c file, which holds the builtin module initialisation
76 dnl table for python.  The first argument should be the output filename.
77 dnl The second argument gives the names of all the modules you want to build
78 dnl into the executable.
79 dnl AM_PYTHON_CREATE_CONFIG_C(CONFIG_C, MODULE ...)
80 AC_DEFUN([AM_PYTHON_CREATE_CONFIG_C],
81 [AC_REQUIRE([AM_INIT_PYTHON_EMBED])
82 AC_MSG_CHECKING(for config.c.in)
83 changequote(,)dnl
84 py_config_in="`$PYTHON -c '
85 import sys
86 print \"%s/lib/python%s/config/config.c.in\"%(sys.exec_prefix, sys.version[:3])'`"
87 changequote([,])dnl
88 if test ! -f "$py_config_in"; then
89    AC_MSG_ERROR([*** Couldn't find the config.c.in file.  Maybe you are
90 *** missing the development portion of the python installation])
91 fi
92
93 py_cnf_decls=""
94 py_cnf_inits=""
95 py_nl='\
96 '
97 for mod in . $2; do
98   if test "$mod" != .; then
99     py_cnf_decls="${py_cnf_decls}extern void init$mod();$py_nl"
100     py_cnf_inits="${py_cnf_inits}  {\"$mod\", init$mod},$py_nl"
101   fi
102 done
103 sed -e "
104   /MARKER 1/i$py_nl$py_cnf_decls
105   /MARKER 2/i$py_nl$py_cnf_inits
106 " $py_config_in > $1
107 AC_MSG_RESULT(created $1)
108 ])
109
110 s page was automatically generated Contact Matt Wilson with any comments
111 the LXR engine written by Arne     or questions about LXR on gnome.org.
112 rg Gleditsch and Per Kristian      Do not contact Matt Wilson concerning
113 rmshus.                            any software on this site.