File: python.m4

package info (click to toggle)
owfs 3.2p3+dfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,688 kB
  • sloc: ansic: 65,085; pascal: 5,957; tcl: 2,688; makefile: 1,357; python: 1,114; sh: 891; cs: 623; php: 600; perl: 587; java: 404; ruby: 289; cpp: 105; asm: 102; xml: 53
file content (230 lines) | stat: -rw-r--r-- 7,452 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#------------------------------------------------------------------------
# SC_PATH_PYTHONCONFIG --
#
#
# Arguments:
#	none
#
# Results:
#
#	Adds the following arguments to configure:
#		--with-pythonconfig=...
#		--with-python=...
#
#	Defines the following vars:
#
#------------------------------------------------------------------------

AC_DEFUN([SC_PATH_PYTHON],
    [AC_PREREQ(2.57)dnl

#----------------------------------------------------------------
# Look for Python
#----------------------------------------------------------------

PYCFLAGS=
PYLDFLAGS=
PYLIB=
PYVERSION=
PYSITEDIR=

AC_ARG_WITH(python, [  --with-python           Set location of Python executable],[ PYBIN="$withval"], [PYBIN=yes])
AC_ARG_WITH(pythonconfig, [  --with-pythonconfig        Set location of python-config executable],[ PYTHONCONFIGBIN="$withval"], [PYTHONCONFIGBIN=yes])

if test "x$PYTHONCONFIGBIN" = xyes; then
       AC_CHECK_PROGS(PYTHONCONFIG, python-config python2.7-config python2.5-config python2.4-config python2.3-config)
else
      PYTHONCONFIG="$PYTHONCONFIGBIN"
fi

# First, check for "--without-python" or "--with-python=no".
if test x"${PYBIN}" = xno -o x"${with_alllang}" = xno ; then 
AC_MSG_NOTICE([Disabling Python])
else
# First figure out the name of the Python executable

if test "x$PYBIN" = xyes; then
AC_CHECK_PROGS(PYTHON, python python2.7 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5 python1.4 python)
else
PYTHON="$PYBIN"
fi


if test ! -z "$PYTHONCONFIG"; then

# python-config available.
   AC_MSG_CHECKING(for Python cflags)
   PYTHONCFLAGS="`$PYTHONCONFIG --cflags 2>/dev/null`"
   if test -z "$PYTHONCFLAGS"; then
	AC_MSG_RESULT(not found)
   else
	AC_MSG_RESULT($PYTHONCFLAGS)
   fi
   PYCFLAGS=$PYTHONCFLAGS

   AC_MSG_CHECKING(for Python ldflags)
   PYTHONLDFLAGS="`$PYTHONCONFIG --ldflags 2>/dev/null`"
   if test -z "$PYTHONLDFLAGS"; then
	AC_MSG_RESULT(not found)
   else
   	AC_MSG_RESULT($PYTHONLDFLAGS)
   fi
   PYLDFLAGS=$PYTHONLDFLAGS

   AC_MSG_CHECKING(for Python libs)
   PYTHONLIBS="`$PYTHONCONFIG --libs 2>/dev/null`"
   if test -z "$PYTHONLIBS"; then
	AC_MSG_RESULT(not found)
   else
   	AC_MSG_RESULT($PYTHONLIBS)
   fi
   PYLIB="$PYTHONLIBS"

   # Need to do this hack since autoconf replaces __file__ with the name of the configure file
   filehack="file__"
   PYVERSION=`($PYTHON -c "import string,operator,os.path; print operator.getitem(os.path.split(operator.getitem(os.path.split(string.__$filehack),0)),1)")`
   AC_MSG_RESULT($PYVERSION)

   AC_MSG_CHECKING(for Python exec-prefix)
   PYTHONEPREFIX="`$PYTHONCONFIG --exec-prefix 2>/dev/null`"
   if test -z "$PYTHONEPREFIX"; then
     AC_MSG_RESULT(not found)
   else
     AC_MSG_RESULT($PYTHONEPREFIX)
   fi
   PYEPREFIX="$PYTHONEPREFIX"

   AC_MSG_CHECKING(for Python site-dir)
   #This seem to be the site-packages dir where files are installed.
   PYSITEDIR=`($PYTHON -c "from distutils.sysconfig import get_python_lib; print get_python_lib(plat_specific=1)") 2>/dev/null`
   if test -z "$PYSITEDIR"; then
     # I'm not really sure if it should be installed at /usr/lib64...
     if test -d "$PYEPREFIX/lib$LIBPOSTFIX/$PYVERSION/site-packages"; then
       PYSITEDIR="$PYEPREFIX/lib$LIBPOSTFIX/$PYVERSION/site-packages"
     else
       if test -d "$PYEPREFIX/lib/$PYVERSION/site-packages"; then
         PYSITEDIR="$PYEPREFIX/lib/$PYVERSION/site-packages"
       fi
     fi
   fi
   AC_MSG_RESULT($PYSITEDIR)

else

# python-config not available.
if test -n "$PYTHON"; then
    AC_MSG_CHECKING(for Python prefix)
    PYPREFIX=`($PYTHON -c "import sys; print sys.prefix") 2>/dev/null`
    AC_MSG_RESULT($PYPREFIX)
    AC_MSG_CHECKING(for Python exec-prefix)
    PYEPREFIX=`($PYTHON -c "import sys; print sys.exec_prefix") 2>/dev/null`
    AC_MSG_RESULT($PYEPREFIX)


    # Note: I could not think of a standard way to get the version string from different versions.
    # This trick pulls it out of the file location for a standard library file.

    AC_MSG_CHECKING(for Python version)

    # Need to do this hack since autoconf replaces __file__ with the name of the configure file
    filehack="file__"
    PYVERSION=`($PYTHON -c "import string,operator,os.path; print operator.getitem(os.path.split(operator.getitem(os.path.split(string.__$filehack),0)),1)")`
    AC_MSG_RESULT($PYVERSION)

    # Find the directory for libraries this is necessary to deal with
    # platforms that can have apps built for multiple archs: e.g. x86_64
    AC_MSG_CHECKING(for Python lib dir)
    PYLIBDIR=`($PYTHON -c "import sys; print sys.lib") 2>/dev/null`
    if test -z "$PYLIBDIR"; then
      # older versions don't have sys.lib  so the best we can do is assume lib
      #PYLIBDIR="lib$LIBPOSTFIX"

      if test -r $PYPREFIX/include/$PYVERSION/Python.h; then
        if test -d "$PYEPREFIX/lib$LIBPOSTFIX/$PYVERSION/config"; then
	  PYLIBDIR="lib$LIBPOSTFIX"
        else
	  if test -d "$PYEPREFIX/lib/$PYVERSION/config"; then
	    # for some reason a 64bit system could have libs installed at lib
	    PYLIBDIR="lib"
	  else
	    # I doubt this will work
	    PYLIBDIR="lib$LIBPOSTFIX"
	  fi
        fi
      else
	# probably very old installation...
	PYLIBDIR="lib"
      fi
    fi
    AC_MSG_RESULT($PYLIBDIR)

    AC_MSG_CHECKING(for Python site-dir)
    PYSITEDIR=`($PYTHON -c "from distutils.sysconfig import get_python_lib; print get_python_lib(plat_specific=1)") 2>/dev/null`
    if test -z "$PYSITEDIR"; then
      # I'm not really sure if it should be installed at /usr/lib64...
      if test -d "$PYEPREFIX/lib$LIBPOSTFIX/$PYVERSION/site-packages"; then
        PYSITEDIR="$PYEPREFIX/lib$LIBPOSTFIX/$PYVERSION/site-packages"
      else
        if test -d "$PYEPREFIX/lib/$PYVERSION/site-packages"; then
          PYSITEDIR="$PYEPREFIX/lib/$PYVERSION/site-packages"
        fi
      fi
    fi
    AC_MSG_RESULT($PYSITEDIR)

   
    # Set the include directory

    AC_MSG_CHECKING(for Python header files)
    if test -r $PYPREFIX/include/$PYVERSION/Python.h; then
        PYCFLAGS="-I$PYPREFIX/include/$PYVERSION -I$PYEPREFIX/$PYLIBDIR/$PYVERSION/config"
    fi
    if test -z "$PYCFLAGS"; then
        if test -r $PYPREFIX/include/Py/Python.h; then
            PYCFLAGS="-I$PYPREFIX/include/Py -I$PYEPREFIX/$PYLIBDIR/python/lib"
        fi
    fi
    AC_MSG_RESULT($PYCFLAGS)

    # Set the library directory blindly.   This probably won't work with older versions
    AC_MSG_CHECKING(for Python library)
    dirs="$PYVERSION/config $PYVERSION/$PYLIBDIR python/$PYLIBDIR"
    for i in $dirs; do
        if test -d $PYEPREFIX/$PYLIBDIR/$i; then
           PYLIB="$PYEPREFIX/$PYLIBDIR/$i"
           break
        fi
    done
    if test -z "$PYLIB"; then
        AC_MSG_RESULT(Not found)
    else
        AC_MSG_RESULT($PYLIB)
    fi

    AC_MSG_CHECKING(for Python LDFLAGS)
    # Check for really old versions
    if test -r $PYLIB/libPython.a; then
         PYLINK="-lModules -lPython -lObjects -lParser"
    else
	if test ! -r $PYLIB/lib$PYVERSION.so -a -r $PYLIB/lib$PYVERSION.a ; then
		# python2.2 on FC1 need this
		PYLINK="$PYLIB/lib$PYVERSION.a"
	else
		PYLINK="-l$PYVERSION"
	fi
    fi
    PYLDFLAGS="$PYLINK"
    AC_MSG_RESULT($PYLDFLAGS)
fi
fi

# Cygwin (Windows) needs the library for dynamic linking
case $host in
*-*-cygwin* | *-*-mingw*) PYTHONDYNAMICLINKING="-L$PYLIB $PYLINK"
         DEFS="-DUSE_DL_IMPORT $DEFS" PYCFLAGS="$PYCFLAGS"
         ;;
*)PYTHONDYNAMICLINKING="";;
esac
fi

])