Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 187194
Collapse All | Expand All

(-)autogen.sh (+422 lines)
Line 0 Link Here
1
#!/bin/sh
2
# Run this to generate all the initial makefiles, etc.
3
4
#name of package
5
PKG_NAME=${PKG_NAME:-nautilus-python}
6
srcdir=${srcdir:-.}
7
ACLOCAL_FLAGS="-I m4 $ACLOCAL_FLAGS"
8
9
# default version requirements ...
10
REQUIRED_AUTOCONF_VERSION=${REQUIRED_AUTOCONF_VERSION:-2.53}
11
REQUIRED_AUTOMAKE_VERSION=${REQUIRED_AUTOMAKE_VERSION:-1.7}
12
REQUIRED_LIBTOOL_VERSION=${REQUIRED_LIBTOOL_VERSION:-1.4.3}
13
REQUIRED_GETTEXT_VERSION=${REQUIRED_GETTEXT_VERSION:-0.10.40}
14
REQUIRED_GLIB_GETTEXT_VERSION=${REQUIRED_GLIB_GETTEXT_VERSION:-2.2.0}
15
REQUIRED_INTLTOOL_VERSION=${REQUIRED_INTLTOOL_VERSION:-0.25}
16
REQUIRED_PKG_CONFIG_VERSION=${REQUIRED_PKG_CONFIG_VERSION:-0.14.0}
17
REQUIRED_GTK_DOC_VERSION=${REQUIRED_GTK_DOC_VERSION:-1.0}
18
REQUIRED_DOC_COMMON_VERSION=${REQUIRED_DOC_COMMON_VERSION:-2.3.0}
19
20
# a list of required m4 macros.  Package can set an initial value
21
REQUIRED_M4MACROS=${REQUIRED_M4MACROS:-}
22
FORBIDDEN_M4MACROS=${FORBIDDEN_M4MACROS:-}
23
24
# Not all echo versions allow -n, so we check what is possible. This test is
25
# based on the one in autoconf.
26
case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
27
  *c*,-n*) ECHO_N= ;;
28
  *c*,*  ) ECHO_N=-n ;;
29
  *)       ECHO_N= ;;
30
esac
31
32
# if GNOME2_DIR or GNOME2_PATH is set, modify ACLOCAL_FLAGS ...
33
# NOTE: GNOME2_DIR is deprecated (as of Jan 2004), but is left here for
34
# backwards-compatibility. You should be using GNOME2_PATH, since that is also
35
# understood by libraries such as libgnome.
36
if [ -n "$GNOME2_DIR" ]; then
37
    echo "Using GNOME2_DIR is deprecated in gnome-common."
38
    echo "Please use GNOME2_PATH instead (for compatibility with other GNOME pieces)."
39
    ACLOCAL_FLAGS="-I $GNOME2_DIR/share/aclocal $ACLOCAL_FLAGS"
40
    LD_LIBRARY_PATH="$GNOME2_DIR/lib:$LD_LIBRARY_PATH"
41
    PATH="$GNOME2_DIR/bin:$PATH"
42
    export PATH
43
    export LD_LIBRARY_PATH
44
else
45
    if [ -n "$GNOME2_PATH" ]; then
46
        ACLOCAL_FLAGS="-I $GNOME2_PATH/share/aclocal $ACLOCAL_FLAGS"
47
        LD_LIBRARY_PATH="$GNOME2_PATH/lib:$LD_LIBRARY_PATH"
48
        PATH="$GNOME2_PATH/bin:$PATH"
49
        export PATH
50
        export LD_LIBRARY_PATH
51
    fi
52
fi
53
54
# some terminal codes ...
55
boldface="`tput bold 2>/dev/null`"
56
normal="`tput sgr0 2>/dev/null`"
57
printbold() {
58
    echo $ECHO_N "$boldface"
59
    echo "$@"
60
    echo $ECHO_N "$normal"
61
}    
62
printerr() {
63
    echo "$@" >&2
64
}
65
66
# Usage:
67
#     compare_versions MIN_VERSION ACTUAL_VERSION
68
# returns true if ACTUAL_VERSION >= MIN_VERSION
69
compare_versions() {
70
    ch_min_version=$1
71
    ch_actual_version=$2
72
    ch_status=0
73
    IFS="${IFS=         }"; ch_save_IFS="$IFS"; IFS="."
74
    set $ch_actual_version
75
    for ch_min in $ch_min_version; do
76
        ch_cur=`echo $1 | sed 's/[^0-9].*$//'`; shift # remove letter suffixes
77
        if [ -z "$ch_min" ]; then break; fi
78
        if [ -z "$ch_cur" ]; then ch_status=1; break; fi
79
        if [ $ch_cur -gt $ch_min ]; then break; fi
80
        if [ $ch_cur -lt $ch_min ]; then ch_status=1; break; fi
81
    done
82
    IFS="$ch_save_IFS"
83
    return $ch_status
84
}
85
86
# Usage:
87
#     version_check PACKAGE VARIABLE CHECKPROGS MIN_VERSION SOURCE
88
# checks to see if the package is available
89
version_check() {
90
    vc_package=$1
91
    vc_variable=$2
92
    vc_checkprogs=$3
93
    vc_min_version=$4
94
    vc_source=$5
95
    vc_status=1
96
97
    vc_checkprog=`eval echo "\\$$vc_variable"`
98
    if [ -n "$vc_checkprog" ]; then
99
	printbold "using $vc_checkprog for $vc_package"
100
	return 0
101
    fi
102
103
    printbold "checking for $vc_package >= $vc_min_version..."
104
    for vc_checkprog in $vc_checkprogs; do
105
	echo $ECHO_N "  testing $vc_checkprog... "
106
	if $vc_checkprog --version < /dev/null > /dev/null 2>&1; then
107
	    vc_actual_version=`$vc_checkprog --version | head -n 1 | \
108
                               sed 's/^.*[ 	]\([0-9.]*[a-z]*\).*$/\1/'`
109
	    if compare_versions $vc_min_version $vc_actual_version; then
110
		echo "found $vc_actual_version"
111
		# set variable
112
		eval "$vc_variable=$vc_checkprog"
113
		vc_status=0
114
		break
115
	    else
116
		echo "too old (found version $vc_actual_version)"
117
	    fi
118
	else
119
	    echo "not found."
120
	fi
121
    done
122
    if [ "$vc_status" != 0 ]; then
123
	printerr "***Error***: You must have $vc_package >= $vc_min_version installed"
124
	printerr "  to build $PKG_NAME.  Download the appropriate package for"
125
	printerr "  from your distribution or get the source tarball at"
126
        printerr "    $vc_source"
127
	printerr
128
    fi
129
    return $vc_status
130
}
131
132
# Usage:
133
#     require_m4macro filename.m4
134
# adds filename.m4 to the list of required macros
135
require_m4macro() {
136
    case "$REQUIRED_M4MACROS" in
137
	$1\ * | *\ $1\ * | *\ $1) ;;
138
	*) REQUIRED_M4MACROS="$REQUIRED_M4MACROS $1" ;;
139
    esac
140
}
141
142
forbid_m4macro() {
143
    case "$FORBIDDEN_M4MACROS" in
144
	$1\ * | *\ $1\ * | *\ $1) ;;
145
	*) FORBIDDEN_M4MACROS="$FORBIDDEN_M4MACROS $1" ;;
146
    esac
147
}
148
149
# Usage:
150
#     check_m4macros
151
# Checks that all the requested macro files are in the aclocal macro path
152
# Uses REQUIRED_M4MACROS and ACLOCAL variables.
153
check_m4macros() {
154
    # construct list of macro directories
155
    cm_macrodirs="`$ACLOCAL --print-ac-dir`"
156
    set - $ACLOCAL_FLAGS
157
    while [ $# -gt 0 ]; do
158
	if [ "$1" = "-I" ]; then
159
	    cm_macrodirs="$cm_macrodirs $2"
160
	    shift
161
	fi
162
	shift
163
    done
164
165
    cm_status=0
166
    if [ -n "$REQUIRED_M4MACROS" ]; then
167
	printbold "Checking for required M4 macros..."
168
	# check that each macro file is in one of the macro dirs
169
	for cm_macro in $REQUIRED_M4MACROS; do
170
	    cm_macrofound=false
171
	    for cm_dir in $cm_macrodirs; do
172
		if [ -f "$cm_dir/$cm_macro" ]; then
173
		    cm_macrofound=true
174
		    break
175
		fi
176
		# The macro dir in Cygwin environments may contain a file
177
		# called dirlist containing other directories to look in.
178
		if [ -f "$cm_dir/dirlist" ]; then
179
		    for cm_otherdir in `cat $cm_dir/dirlist`; do
180
			if [ -f "$cm_otherdir/$cm_macro" ]; then
181
			    cm_macrofound=true
182
		            break
183
			fi
184
		    done
185
		fi
186
	    done
187
	    if $cm_macrofound; then
188
		:
189
	    else
190
		printerr "  $cm_macro not found"
191
		cm_status=1
192
	    fi
193
	done
194
    fi
195
    if [ -n "$FORBIDDEN_M4MACROS" ]; then
196
	printbold "Checking for forbidden M4 macros..."
197
	# check that each macro file is in one of the macro dirs
198
	for cm_macro in $FORBIDDEN_M4MACROS; do
199
	    cm_macrofound=false
200
	    for cm_dir in $cm_macrodirs; do
201
		if [ -f "$cm_dir/$cm_macro" ]; then
202
		    cm_macrofound=true
203
		    break
204
		fi
205
	    done
206
	    if $cm_macrofound; then
207
		printerr "  $cm_macro found (should be cleared from macros dir)"
208
		cm_status=1
209
	    fi
210
	done
211
    fi
212
    if [ "$cm_status" != 0 ]; then
213
	printerr "***Error***: some autoconf macros required to build $PKG_NAME"
214
	printerr "  were not found in your aclocal path, or some forbidden"
215
	printerr "  macros were found.  Perhaps you need to adjust your"
216
	printerr "  ACLOCAL_PATH?"
217
	printerr
218
    fi
219
    return $cm_status
220
}
221
222
# try to catch the case where the macros2/ directory hasn't been cleared out.
223
forbid_m4macro gnome-cxx-check.m4
224
225
want_libtool=false
226
want_gettext=false
227
want_glib_gettext=false
228
want_intltool=false
229
want_pkg_config=false
230
want_gtk_doc=false
231
232
configure_files="`find $srcdir -name '{arch}' -prune -o -name configure.ac -print -o -name configure.in -print`"
233
for configure_ac in $configure_files; do
234
    if grep "^A[CM]_PROG_LIBTOOL" $configure_ac >/dev/null; then
235
	want_libtool=true
236
    fi
237
    if grep "^AM_GNU_GETTEXT" $configure_ac >/dev/null; then
238
	want_gettext=true
239
    fi
240
    if grep "^AM_GLIB_GNU_GETTEXT" $configure_ac >/dev/null; then
241
	want_glib_gettext=true
242
    fi
243
    if grep "^AC_PROG_INTLTOOL" $configure_ac >/dev/null; then
244
	want_intltool=true
245
    fi
246
    if grep "^PKG_CHECK_MODULES" $configure_ac >/dev/null; then
247
	want_pkg_config=true
248
    fi
249
    if grep "^GTK_DOC_CHECK" $configure_ac >/dev/null; then
250
	want_gtk_doc=true
251
    fi
252
done
253
254
DIE=0
255
256
#tell Mandrake autoconf wrapper we want autoconf 2.5x, not 2.13
257
WANT_AUTOCONF_2_5=1
258
export WANT_AUTOCONF_2_5
259
version_check autoconf AUTOCONF 'autoconf2.50 autoconf autoconf-2.53' $REQUIRED_AUTOCONF_VERSION \
260
    "http://ftp.gnu.org/pub/gnu/autoconf/autoconf-$REQUIRED_AUTOCONF_VERSION.tar.gz" || DIE=1
261
AUTOHEADER=`echo $AUTOCONF | sed s/autoconf/autoheader/`
262
263
case $REQUIRED_AUTOMAKE_VERSION in
264
    1.4*) automake_progs="automake-1.4" ;;
265
    1.5*) automake_progs="automake-1.5 automake-1.6 automake-1.7 automake-1.8" ;;
266
    1.6*) automake_progs="automake-1.6 automake-1.7 automake-1.8" ;;
267
    1.7*) automake_progs="automake-1.7 automake-1.8" ;;
268
    1.8*) automake_progs="automake-1.8" ;;
269
esac
270
version_check automake AUTOMAKE "$automake_progs" $REQUIRED_AUTOMAKE_VERSION \
271
    "http://ftp.gnu.org/pub/gnu/automake/automake-$REQUIRED_AUTOMAKE_VERSION.tar.gz" || DIE=1
272
ACLOCAL=`echo $AUTOMAKE | sed s/automake/aclocal/`
273
274
# We need to do this for the craaaaaaazy mkinstalldirs usage of glib-gettext
275
AUTOMAKE_VERSION=`echo $AUTOMAKE | sed s/automake-//`
276
ACLOCAL_DIR=`$ACLOCAL --print-ac-dir`
277
AUTOMAKE_DIR=`echo $ACLOCAL_DIR | sed s/aclocal/automake-$AUTOMAKE_VERSION/`
278
279
if $want_libtool; then
280
    version_check libtool LIBTOOLIZE libtoolize $REQUIRED_LIBTOOL_VERSION \
281
        "http://ftp.gnu.org/pub/gnu/libtool/libtool-$REQUIRED_LIBTOOL_VERSION.tar.gz" || DIE=1
282
    require_m4macro libtool.m4
283
fi
284
285
if $want_gettext; then
286
    version_check gettext GETTEXTIZE gettextize $REQUIRED_GETTEXT_VERSION \
287
        "http://ftp.gnu.org/pub/gnu/gettext/gettext-$REQUIRED_GETTEXT_VERSION.tar.gz" || DIE=1
288
    require_m4macro gettext.m4
289
fi
290
291
if $want_glib_gettext; then
292
    version_check glib-gettext GLIB_GETTEXTIZE glib-gettextize $REQUIRED_GLIB_GETTEXT_VERSION \
293
        "ftp://ftp.gtk.org/pub/gtk/v2.2/glib-$REQUIRED_GLIB_GETTEXT_VERSION.tar.gz" || DIE=1
294
    require_m4macro glib-gettext.m4
295
fi
296
297
if $want_intltool; then
298
    version_check intltool INTLTOOLIZE intltoolize $REQUIRED_INTLTOOL_VERSION \
299
        "http://ftp.gnome.org/pub/GNOME/sources/intltool/" || DIE=1
300
    require_m4macro intltool.m4
301
fi
302
303
if $want_pkg_config; then
304
    version_check pkg-config PKG_CONFIG pkg-config $REQUIRED_PKG_CONFIG_VERSION \
305
        "'http://www.freedesktop.org/software/pkgconfig/releases/pkgconfig-$REQUIRED_PKG_CONFIG_VERSION.tar.gz" || DIE=1
306
    require_m4macro pkg.m4
307
fi
308
309
if $want_gtk_doc; then
310
    version_check gtk-doc GTKDOCIZE gtkdocize $REQUIRED_GTK_DOC_VERSION \
311
        "http://ftp.gnome.org/pub/GNOME/sources/gtk-doc/" || DIE=1
312
    require_m4macro gtk-doc.m4
313
fi
314
315
if [ "x$USE_COMMON_DOC_BUILD" = "xyes" ]; then
316
    version_check gnome-common DOC_COMMON gnome-doc-common \
317
        $REQUIRED_DOC_COMMON_VERSION " " || DIE=1
318
fi
319
320
check_m4macros || DIE=1
321
322
if [ "$DIE" -eq 1 ]; then
323
  exit 1
324
fi
325
326
if test -z "$*"; then
327
  printerr "**Warning**: I am going to run \`configure' with no arguments."
328
  printerr "If you wish to pass any to it, please specify them on the"
329
  printerr \`$0\'" command line."
330
  printerr
331
fi
332
333
topdir=`pwd`
334
for configure_ac in $configure_files; do 
335
    dirname=`dirname $configure_ac`
336
    basename=`basename $configure_ac`
337
    if test -f $dirname/NO-AUTO-GEN; then
338
	echo skipping $dirname -- flagged as no auto-gen
339
    else
340
	printbold "Processing $configure_ac"
341
	cd $dirname
342
343
        # Note that the order these tools are called should match what
344
        # autoconf's "autoupdate" package does.  See bug 138584 for
345
        # details.
346
347
        # programs that might install new macros get run before aclocal
348
	if grep "^A[CM]_PROG_LIBTOOL" $basename >/dev/null; then
349
	    printbold "Running $LIBTOOLIZE..."
350
	    $LIBTOOLIZE --force || exit 1
351
	fi
352
353
	if grep "^AM_GLIB_GNU_GETTEXT" $basename >/dev/null; then
354
	    printbold "Running $GLIB_GETTEXTIZE... Ignore non-fatal messages."
355
	    echo "no" | $GLIB_GETTEXTIZE --force --copy || exit 1
356
	    # This is to copy in mkinstalldirs for glib-gettext
357
	    if [ -x $AUTOMAKE_DIR/mkinstalldirs ]; then
358
		echo "  copying mkinstalldirs... "
359
		cp -f $AUTOMAKE_DIR/mkinstalldirs $dirname
360
	    fi
361
	elif grep "^AM_GNU_GETTEXT" $basename >/dev/null; then
362
	   if grep "^AM_GNU_GETTEXT_VERSION" $basename > /dev/null; then
363
	   	printbold "Running autopoint..."
364
		autopoint --force || exit 1
365
	   else
366
	    	printbold "Running $GETTEXTIZE... Ignore non-fatal messages."
367
	    	echo "no" | $GETTEXTIZE --force --copy || exit 1
368
	   fi
369
	fi
370
371
	if grep "^AC_PROG_INTLTOOL" $basename >/dev/null; then
372
	    printbold "Running $INTLTOOLIZE..."
373
	    $INTLTOOLIZE --force --automake || exit 1
374
	fi
375
	if grep "^GTK_DOC_CHECK" $basename >/dev/null; then
376
	    printbold "Running $GTKDOCIZE..."
377
	    $GTKDOCIZE || exit 1
378
	fi
379
380
	if [ "x$USE_COMMON_DOC_BUILD" = "xyes" ]; then
381
	    printbold "Running gnome-doc-common..."
382
	    gnome-doc-common --copy || exit 1
383
	fi
384
385
        # Now run aclocal to pull in any additional macros needed
386
	aclocalinclude="$ACLOCAL_FLAGS"
387
	printbold "Running $ACLOCAL..."
388
	$ACLOCAL $aclocalinclude || exit 1
389
390
	if grep "GNOME_AUTOGEN_OBSOLETE" aclocal.m4 >/dev/null; then
391
	    printerr "*** obsolete gnome macros were used in $configure_ac"
392
	fi
393
394
	# Now that all the macros are sorted, run autoconf and autoheader ...
395
	printbold "Running $AUTOCONF..."
396
	$AUTOCONF || exit 1
397
	if grep "^A[CM]_CONFIG_HEADER" $basename >/dev/null; then
398
	    printbold "Running $AUTOHEADER..."
399
	    $AUTOHEADER || exit 1
400
	    # this prevents automake from thinking config.h.in is out of
401
	    # date, since autoheader doesn't touch the file if it doesn't
402
	    # change.
403
	    test -f config.h.in && touch config.h.in
404
	fi
405
406
	# Finally, run automake to create the makefiles ...
407
	printbold "Running $AUTOMAKE..."
408
	$AUTOMAKE --gnu --add-missing || exit 1
409
410
	cd "$topdir"
411
    fi
412
done
413
414
conf_flags="--enable-maintainer-mode"
415
416
if test x$NOCONFIGURE = x; then
417
    printbold Running $srcdir/configure $conf_flags "$@" ...
418
    $srcdir/configure $conf_flags "$@" \
419
	&& echo Now type \`make\' to compile $PKG_NAME || exit 1
420
else
421
    echo Skipping configure process.
422
fi
(-)m4/python.m4 (+83 lines)
Line 0 Link Here
1
## this one is commonly used with AM_PATH_PYTHONDIR ...
2
dnl AM_CHECK_PYMOD(MODNAME [,SYMBOL [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]]])
3
dnl Check if a module containing a given symbol is visible to python.
4
AC_DEFUN(AM_CHECK_PYMOD,
5
[AC_REQUIRE([AM_PATH_PYTHON])
6
py_mod_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'`
7
AC_MSG_CHECKING(for ifelse([$2],[],,[$2 in ])python module $1)
8
AC_CACHE_VAL(py_cv_mod_$py_mod_var, [
9
ifelse([$2],[], [prog="
10
import sys
11
try:
12
        import $1
13
except ImportError:
14
        sys.exit(1)
15
except:
16
        sys.exit(0)
17
sys.exit(0)"], [prog="
18
import $1
19
$1.$2"])
20
if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
21
  then
22
    eval "py_cv_mod_$py_mod_var=yes"
23
  else
24
    eval "py_cv_mod_$py_mod_var=no"
25
  fi
26
])
27
py_val=`eval "echo \`echo '$py_cv_mod_'$py_mod_var\`"`
28
if test "x$py_val" != xno; then
29
  AC_MSG_RESULT(yes)
30
  ifelse([$3], [],, [$3
31
])dnl
32
else
33
  AC_MSG_RESULT(no)
34
  ifelse([$4], [],, [$4
35
])dnl
36
fi
37
])
38
39
dnl a macro to check for ability to create python extensions
40
dnl  AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
41
dnl function also defines PYTHON_INCLUDES
42
AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
43
[AC_REQUIRE([AM_PATH_PYTHON])
44
AC_MSG_CHECKING(for headers required to compile python extensions)
45
dnl deduce PYTHON_INCLUDES
46
py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
47
py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
48
PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
49
if test "$py_prefix" != "$py_exec_prefix"; then
50
  PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
51
fi
52
AC_SUBST(PYTHON_INCLUDES)
53
dnl check if the headers exist:
54
save_CPPFLAGS="$CPPFLAGS"
55
CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
56
AC_TRY_CPP([#include <Python.h>],dnl
57
[AC_MSG_RESULT(found)
58
$1],dnl
59
[AC_MSG_RESULT(not found)
60
$2])
61
CPPFLAGS="$save_CPPFLAGS"
62
])
63
64
dnl a macro to check for ability to embed python
65
dnl  AM_CHECK_PYTHON_LIBS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
66
dnl function also defines PYTHON_LIBS
67
AC_DEFUN([AM_CHECK_PYTHON_LIBS],
68
[AC_REQUIRE([AM_CHECK_PYTHON_HEADERS])
69
AC_MSG_CHECKING(for libraries required to embed python)
70
dnl deduce PYTHON_LIBS
71
py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
72
PYTHON_LIBS="-L${py_prefix}/lib -lpython${PYTHON_VERSION}"
73
PYTHON_LIB_LOC="${py_prefix}/lib" 
74
AC_SUBST(PYTHON_LIBS)
75
AC_SUBST(PYTHON_LIB_LOC)
76
dnl check if the headers exist:
77
save_LIBS="$LIBS"
78
LIBS="$LIBS $PYTHON_LIBS"
79
AC_TRY_LINK_FUNC(Py_Initialize, dnl
80
         [LIBS="$save_LIBS"; AC_MSG_RESULT(yes); $1], dnl
81
         [LIBS="$save_LIBS"; AC_MSG_RESULT(no); $2])
82
83
])
(-)configure.in (-1 / +1 lines)
Lines 80-86 Link Here
80
		  if test -f $PY_PREFIX/include/python$PY_VERSION/Python.h; then
80
		  if test -f $PY_PREFIX/include/python$PY_VERSION/Python.h; then
81
			  AC_MSG_RESULT(yes)
81
			  AC_MSG_RESULT(yes)
82
			  PY_LIBS="python$PY_VERSION"
82
			  PY_LIBS="python$PY_VERSION"
83
			  PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
83
			  PY_LIB_LOC="$PY_EXEC_PREFIX/lib"
84
			  PY_CFLAGS="-I$PY_PREFIX/include/python$PY_VERSION"
84
			  PY_CFLAGS="-I$PY_PREFIX/include/python$PY_VERSION"
85
			  PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config/Makefile"
85
			  PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config/Makefile"
86
			  PY_LOCALMODLIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
86
			  PY_LOCALMODLIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
(-)ChangeLog (+39 lines)
Lines 1-3 Link Here
1
2006-02-19  Gustavo J. A. M. Carneiro  <gjc@gnome.org>
2
3
	* configure.in: Fix PY_LIB_LOC to point to $PY_EXEC_PREFIX/lib,
4
	which is where a normal (i.e. not distribution patched) python
5
	installation puts the shared library.
6
7
	* src/nautilus-python.c (nautilus_python_init_python): Use
8
	PY_LIB_LOC here to open the correct python library (for cases of
9
	prefix != /usr).
10
11
	* src/Makefile.am (PYTHON_LIBS): Use PY_LIB_LOC here.
12
13
	* configure.in: Remove -L from $PY_LIB_LOC.
14
15
	* src/nautilus-python.c (np_init_pygobject): Add a missing
16
	PyErr_Print(); for the case when _PyGObbject_API is not found.
17
	(np_init_pygtk): idem.
18
19
2006-02-18  Gustavo J. A. M. Carneiro  <gjc@gnome.org>
20
21
	* src/nautilus-python.c (np_init_pygnomevfs): Copy-paste of
22
	init_pygnomevfs from pygnomevfs.h, but changing error handling to
23
	avoid Py_FatalError, so we don't crash nautilus if gnomevfs module
24
	is missing.
25
	(np_init_pygnomevfs): Convert macro to inline function, make it
26
	return TRUE/FALSE on success/failure.  Update rest of code to
27
	reflect these changes.
28
	(np_init_pygtk): idem.
29
	(np_init_pygobject): idem.
30
	(nautilus_python_init_python): Call np_init_pygnomevfs instead of
31
	init_pygnomevfs.
32
33
	* src/nautilus-python.h: Moved np_init_pygobject and
34
	np_init_pygtk to src/nautilus-python.c.
35
36
	* src/nautilus-python.c: Refactor to initialize nautilus-python on
37
	demand: python/pygtk/pygnomevfs are not initialized if no python
38
	extension is actually found.
39
1
=== 0.4.3 ===
40
=== 0.4.3 ===
2
2006-02-15  Gustavo J. A. M. Carneiro  <gjc@gnome.org>
41
2006-02-15  Gustavo J. A. M. Carneiro  <gjc@gnome.org>
3
42
(-)src/nautilus-python.c (-23 / +122 lines)
Lines 37-46 Link Here
37
static const guint nautilus_python_ndebug_keys = sizeof (nautilus_python_debug_keys) / sizeof (GDebugKey);
37
static const guint nautilus_python_ndebug_keys = sizeof (nautilus_python_debug_keys) / sizeof (GDebugKey);
38
NautilusPythonDebug nautilus_python_debug;
38
NautilusPythonDebug nautilus_python_debug;
39
39
40
static gboolean nautilus_python_init_python(void);
41
40
static GArray *all_types = NULL;
42
static GArray *all_types = NULL;
41
43
42
#define ENTRY_POINT "nautilus_extension_types"
43
44
45
static inline gboolean np_init_pygobject(void)
46
{
47
    PyObject *gobject = PyImport_ImportModule("gobject");
48
    if (gobject != NULL) {
49
        PyObject *mdict = PyModule_GetDict(gobject);
50
        PyObject *cobject = PyDict_GetItemString(mdict, "_PyGObject_API");
51
        if (PyCObject_Check(cobject))
52
            _PyGObject_API = (struct _PyGObject_Functions *)PyCObject_AsVoidPtr(cobject);
53
        else {
54
            PyErr_SetString(PyExc_RuntimeError,
55
                            "could not find _PyGObject_API object");
56
			PyErr_Print();
57
			return FALSE;
58
        }
59
    } else {
60
        PyErr_Print();
61
        g_warning("could not import gobject");
62
        return FALSE;
63
    }
64
	return TRUE;
65
}
66
67
static inline gboolean np_init_pygtk(void)
68
{
69
    PyObject *pygtk = PyImport_ImportModule("gtk._gtk");
70
    if (pygtk != NULL) {
71
		PyObject *module_dict = PyModule_GetDict(pygtk);
72
		PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API");
73
		if (PyCObject_Check(cobject))
74
			_PyGtk_API = (struct _PyGtk_FunctionStruct*)
75
				PyCObject_AsVoidPtr(cobject);
76
		else {
77
            PyErr_SetString(PyExc_RuntimeError,
78
                            "could not find _PyGtk_API object");
79
			PyErr_Print();
80
			return FALSE;
81
        }
82
    } else {
83
        PyErr_Print();
84
        g_warning("could not import gtk._gtk");
85
        return FALSE;
86
    }
87
	return TRUE;
88
}
89
90
static inline gboolean np_init_pygnomevfs(void)
91
{
92
    PyObject *module = PyImport_ImportModule("gnomevfs");
93
    if (module != NULL) {
94
        PyObject *mdict = PyModule_GetDict(module);
95
        PyObject *cobject = PyDict_GetItemString(mdict, "_PyGnomeVFS_API");
96
        if (PyCObject_Check(cobject))
97
            _PyGnomeVFS_API = (struct _PyGnomeVFS_Functions *)PyCObject_AsVoidPtr(cobject);
98
        else {
99
	         g_warning("could not find _PyGnomeVFS_API object in the gnomevfs module");
100
			 return FALSE;
101
        }
102
    } else {
103
        PyErr_Print();
104
        g_warning("could not import gnomevfs");
105
		return FALSE;
106
    }
107
	return TRUE;
108
}
109
110
44
static void
111
static void
45
nautilus_python_load_file(GTypeModule *type_module, const gchar *filename)
112
nautilus_python_load_file(GTypeModule *type_module, const gchar *filename)
46
{
113
{
Lines 88-94 Link Here
88
{
155
{
89
	GDir *dir;
156
	GDir *dir;
90
	const char *name;
157
	const char *name;
91
	PyObject *sys_path, *py_path;
158
	gboolean initialized = FALSE;
92
159
93
	debug_enter_args("dirname=%s", dirname);
160
	debug_enter_args("dirname=%s", dirname);
94
	
161
	
Lines 96-106 Link Here
96
	if (!dir)
163
	if (!dir)
97
		return;
164
		return;
98
165
99
	  /* sys.path.insert(0, dirname) */
100
	sys_path = PySys_GetObject("path");
101
	py_path = PyString_FromString(dirname);
102
	PyList_Insert(sys_path, 0, py_path);
103
	Py_DECREF(py_path);
104
			
166
			
105
	while ((name = g_dir_read_name(dir))) {
167
	while ((name = g_dir_read_name(dir))) {
106
		if (g_str_has_suffix(name, ".py")) {
168
		if (g_str_has_suffix(name, ".py")) {
Lines 110-157 Link Here
110
			len = strlen(name) - 3;
172
			len = strlen(name) - 3;
111
			modulename = g_new0(char, len + 1 );
173
			modulename = g_new0(char, len + 1 );
112
			strncpy(modulename, name, len);
174
			strncpy(modulename, name, len);
175
176
			if (!initialized) {
177
				PyObject *sys_path, *py_path;
178
				  /* n-p python part is initialized on demand (or not
179
				   * at all if no extensions are found) */
180
				if (!nautilus_python_init_python()) {
181
					g_warning("nautilus_python_init_python failed");
182
					goto exit;
183
				}
184
				  /* sys.path.insert(0, dirname) */
185
				sys_path = PySys_GetObject("path");
186
				py_path = PyString_FromString(dirname);
187
				PyList_Insert(sys_path, 0, py_path);
188
				Py_DECREF(py_path);
189
			}
113
			nautilus_python_load_file(module, modulename);
190
			nautilus_python_load_file(module, modulename);
114
		}
191
		}
115
	}
192
	}
193
exit:
116
	g_dir_close(dir);
194
	g_dir_close(dir);
117
}
195
}
118
196
119
gboolean
197
static gboolean
120
nautilus_python_init_python (gchar **user_extensions_dir)
198
nautilus_python_init_python (void)
121
{
199
{
122
	PyObject *pygtk, *mdict, *require;
200
	PyObject *pygtk, *mdict, *require;
123
	PyObject *sys_path, *tmp, *nautilus, *gtk, *pygtk_version, *pygtk_required_version;
201
	PyObject *sys_path, *tmp, *nautilus, *gtk, *pygtk_version, *pygtk_required_version;
124
	GModule *libpython;
202
	GModule *libpython;
125
	char *home_dir;
126
	char *argv[] = { "nautilus", NULL };
203
	char *argv[] = { "nautilus", NULL };
127
204
128
	if (Py_IsInitialized())
205
	if (Py_IsInitialized())
129
		return TRUE;
206
		return TRUE;
130
207
131
	libpython = g_module_open("libpython" PYTHON_VERSION "." G_MODULE_SUFFIX, 0);
208
  	debug("g_module_open " PY_LIB_LOC "/libpython" PYTHON_VERSION "." G_MODULE_SUFFIX);
209
	libpython = g_module_open(PY_LIB_LOC "/libpython" PYTHON_VERSION "." G_MODULE_SUFFIX, 0);
132
	if (!libpython)
210
	if (!libpython)
133
		g_warning("g_module_open libpython failed: %s", g_module_error());
211
		g_warning("g_module_open libpython failed: %s", g_module_error());
134
212
	debug("Py_Initialize");
135
	Py_Initialize();
213
	Py_Initialize();
214
	if (PyErr_Occurred()) {
215
		PyErr_Print();
216
		return FALSE;
217
	}
218
	
219
	debug("PySys_SetArgv");
136
	PySys_SetArgv(1, argv);
220
	PySys_SetArgv(1, argv);
221
	if (PyErr_Occurred()) {
222
		PyErr_Print();
223
		return FALSE;
224
	}
137
225
138
	/* pygtk.require("2.0") */
226
	/* pygtk.require("2.0") */
227
	debug("pygtk.require(\"2.0\")");
139
	pygtk = PyImport_ImportModule("pygtk");
228
	pygtk = PyImport_ImportModule("pygtk");
229
	if (!pygtk) {
230
		PyErr_Print();
231
		return FALSE;
232
	}
140
	mdict = PyModule_GetDict(pygtk);
233
	mdict = PyModule_GetDict(pygtk);
141
	require = PyDict_GetItemString(mdict, "require");
234
	require = PyDict_GetItemString(mdict, "require");
142
	PyObject_CallObject(require, Py_BuildValue("(S)", PyString_FromString("2.0")));
235
	PyObject_CallObject(require, Py_BuildValue("(S)", PyString_FromString("2.0")));
236
	if (PyErr_Occurred()) {
237
		PyErr_Print();
238
		return FALSE;
239
	}
143
240
144
	/* import gobject */
241
	/* import gobject */
145
  	debug("init_pygobject");
242
  	debug("init_pygobject");
146
	np_init_pygobject();
243
	if (!np_init_pygobject()) {
147
244
		g_warning("pygobject initialization failed");
245
		return FALSE;
246
	}
148
	/* import gtk */
247
	/* import gtk */
149
	debug("init_pygtk");
248
	debug("init_pygtk");
150
	np_init_pygtk();
249
	if (!np_init_pygtk()) {
151
250
		g_warning("pygtk initialization failed");
251
		return FALSE;
252
	}
152
	/* import gnomevfs */
253
	/* import gnomevfs */
153
	debug("init_gnomevfs");
254
	debug("init_gnomevfs");
154
	init_pygnomevfs();
255
	if (!np_init_pygnomevfs())
256
		return FALSE;
155
257
156
	/* gobject.threads_init() */
258
	/* gobject.threads_init() */
157
    debug("pyg_enable_threads");
259
    debug("pyg_enable_threads");
Lines 175-183 Link Here
175
	/* sys.path.insert(., ...) */
277
	/* sys.path.insert(., ...) */
176
	debug("sys.path.insert(0, ...)");
278
	debug("sys.path.insert(0, ...)");
177
	sys_path = PySys_GetObject("path");
279
	sys_path = PySys_GetObject("path");
178
	home_dir = g_strdup_printf("%s/.nautilus/python-extensions/",
179
							   g_get_home_dir());
180
	*user_extensions_dir = home_dir;
181
	PyList_Insert(sys_path, 0,
280
	PyList_Insert(sys_path, 0,
182
				  (tmp = PyString_FromString(NAUTILUS_LIBDIR "/nautilus-python")));
281
				  (tmp = PyString_FromString(NAUTILUS_LIBDIR "/nautilus-python")));
183
	Py_DECREF(tmp);
282
	Py_DECREF(tmp);
Lines 232-241 Link Here
232
331
233
	all_types = g_array_new(FALSE, FALSE, sizeof(GType));
332
	all_types = g_array_new(FALSE, FALSE, sizeof(GType));
234
333
235
	if (!nautilus_python_init_python(&user_extensions_dir))
236
		return;
237
		
238
	nautilus_python_load_dir(module, NAUTILUS_LIBDIR "/nautilus/extensions-1.0/python");
334
	nautilus_python_load_dir(module, NAUTILUS_LIBDIR "/nautilus/extensions-1.0/python");
335
	user_extensions_dir = g_strdup_printf("%s/.nautilus/python-extensions/",
336
										  g_get_home_dir());
239
	nautilus_python_load_dir(module, user_extensions_dir);
337
	nautilus_python_load_dir(module, user_extensions_dir);
240
	g_free(user_extensions_dir);
338
	g_free(user_extensions_dir);
241
}
339
}
Lines 253-258 Link Here
253
351
254
	debug("Shutting down nautilus-python extension.");
352
	debug("Shutting down nautilus-python extension.");
255
#endif
353
#endif
354
	g_array_free(all_types, TRUE);
256
}
355
}
257
356
258
void 
357
void 
(-)src/Makefile.am (-3 / +4 lines)
Lines 7-17 Link Here
7
	$(DISABLE_DEPRECATED_CFLAGS)			\
7
	$(DISABLE_DEPRECATED_CFLAGS)			\
8
	$(NAUTILUS_PYTHON_CFLAGS)			\
8
	$(NAUTILUS_PYTHON_CFLAGS)			\
9
	-DPYTHON_VERSION=\"$(PYTHON_VERSION)\"		\
9
	-DPYTHON_VERSION=\"$(PYTHON_VERSION)\"		\
10
	-DPY_LIB_LOC="\"$(PY_LIB_LOC)\""		\
10
	$(PY_CFLAGS)
11
	$(PY_CFLAGS)
11
12
12
PYTHON_LIBS = 			\
13
PYTHON_LIBS =					\
13
	-l$(PY_LIBS)		\
14
	-L$(PY_LIB_LOC) -l$(PY_LIBS)		\
14
	$(PY_OTHER_LIBS)	\
15
	$(PY_OTHER_LIBS)			\
15
	$(PY_EXTRA_LIBS)
16
	$(PY_EXTRA_LIBS)
16
17
17
nautilus_extensiondir=$(NAUTILUS_LIBDIR)/nautilus/extensions-1.0
18
nautilus_extensiondir=$(NAUTILUS_LIBDIR)/nautilus/extensions-1.0
(-)src/nautilus-python.h (-39 lines)
Lines 39-84 Link Here
39
#define debug_enter_args(x, y) { if (nautilus_python_debug & NAUTILUS_PYTHON_DEBUG_MISC) \
39
#define debug_enter_args(x, y) { if (nautilus_python_debug & NAUTILUS_PYTHON_DEBUG_MISC) \
40
                                     g_printf("%s: entered " x "\n", __FUNCTION__, y); }
40
                                     g_printf("%s: entered " x "\n", __FUNCTION__, y); }
41
41
42
/* Macros from PyGTK, changed to return FALSE instead of nothing */
43
#define np_init_pygobject() { \
44
    PyObject *gobject = PyImport_ImportModule("gobject"); \
45
    if (gobject != NULL) { \
46
        PyObject *mdict = PyModule_GetDict(gobject); \
47
        PyObject *cobject = PyDict_GetItemString(mdict, "_PyGObject_API"); \
48
        if (PyCObject_Check(cobject)) \
49
            _PyGObject_API = (struct _PyGObject_Functions *)PyCObject_AsVoidPtr(cobject); \
50
        else { \
51
            PyErr_SetString(PyExc_RuntimeError, \
52
                            "could not find _PyGObject_API object"); \
53
	    return FALSE; \
54
        } \
55
    } else { \
56
        PyErr_Print(); \
57
        g_warning("could not import gobject"); \
58
        return FALSE; \
59
    } \
60
}
61
42
62
#define np_init_pygtk() { \
63
    PyObject *pygtk = PyImport_ImportModule("gtk._gtk"); \
64
    if (pygtk != NULL) { \
65
	PyObject *module_dict = PyModule_GetDict(pygtk); \
66
	PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API"); \
67
	if (PyCObject_Check(cobject)) \
68
	    _PyGtk_API = (struct _PyGtk_FunctionStruct*) \
69
		PyCObject_AsVoidPtr(cobject); \
70
	else { \
71
            PyErr_SetString(PyExc_RuntimeError, \
72
                            "could not find _PyGtk_API object"); \
73
	    return FALSE; \
74
        } \
75
    } else { \
76
        PyErr_Print(); \
77
        g_warning("could not import gtk._gtk"); \
78
        return FALSE; \
79
    } \
80
}
81
82
PyTypeObject *_PyNautilusColumn_Type;
43
PyTypeObject *_PyNautilusColumn_Type;
83
#define PyNautilusColumn_Type (*_PyNautilusColumn_Type)
44
#define PyNautilusColumn_Type (*_PyNautilusColumn_Type)
84
45

Return to bug 187194