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