doc: update Vala documentation
[automake.git] / t / python-vars.sh
blob5855c5ff6c23d408ee704ed58a54f7dbaead265f
1 #! /bin/sh
2 # Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # Check that AM_PATH_PYTHON correctly sets all the output variables
18 # advertised in the manual, both with the GNU prefix values and the
19 # Python sys.* prefix values.
21 required=python
22 . test-init.sh
24 # In case the user's config.site defines pythondir or pyexecdir.
25 CONFIG_SITE=/dev/null; export CONFIG_SITE
27 # Update the definition below if the documentation changes. The values
28 # of the 'pythondir' and 'pyexecdir' variables vary among different
29 # python installations, so we need more relaxed and ad-hoc checks for
30 # them. Also, more proper "functional" checks on them should be done in
31 # the 'python-virtualenv.sh' test.
33 # This version identification is duplicated in python.m4 (and the manual).
34 PYTHON_VERSION=$($PYTHON -c 'import sys; print ("%u.%u" % sys.version_info[:2])') || exit 1
35 PYTHON_PLATFORM=$($PYTHON -c 'import sys; print (sys.platform)') || exit 1
36 PYTHON_EXEC_PREFIX=$($PYTHON -c 'import sys; print (sys.exec_prefix)') || exit 1
37 PYTHON_PREFIX=$($PYTHON -c 'import sys; print (sys.prefix)') || exit 1
38 pkgpythondir="\${pythondir}/$me"
39 pkgpyexecdir="\${pyexecdir}/$me"
41 pyvars='PYTHON_VERSION PYTHON_PLATFORM PYTHON_PREFIX PYTHON_EXEC_PREFIX
42 pkgpythondir pkgpyexecdir'
44 cat >> configure.ac << 'END'
45 AC_CONFIG_FILES([vars-got pythondir pyexecdir])
46 AM_PATH_PYTHON
47 AC_OUTPUT
48 END
50 cat > my.py << 'END'
51 def my():
52 return 1
53 END
55 cat > Makefile.am << 'END'
57 python_PYTHON = my.py
59 EXTRA_DIST = vars-exp
61 check-local: test-in test-am
62 .PHONY: test-in test-am
64 test-in:
65 @echo "> doing test-in"
66 @echo ">> contents of pythondir:"
67 cat pythondir
68 case `cat pythondir` in '$${PYTHON_PREFIX}'/*);; *) exit 1;; esac
69 @echo ">> contents of pyexecdir:"
70 cat pyexecdir
71 case `cat pyexecdir` in '$${PYTHON_EXEC_PREFIX}'/*);; *) exit 1;; esac
72 @echo ">> contents of vars-exp:"
73 cat $(srcdir)/vars-exp
74 @echo ">> contents of vars-got:"
75 cat $(builddir)/vars-got
76 diff $(srcdir)/vars-exp $(builddir)/vars-got
78 ## Note: this target's rules will be extended in the "for" loop below.
79 test-am:
80 @echo "> doing test-am"
81 case '$(pythondir)' in '$(PYTHON_PREFIX)'/*);; *) exit 1;; esac
82 case '$(pyexecdir)' in '$(PYTHON_EXEC_PREFIX)'/*);; *) exit 1;; esac
83 END
85 echo @pythondir@ > pythondir.in
86 echo @pyexecdir@ > pyexecdir.in
88 # This depends on whether we're doing GNU or Python values, per arg.
89 setup_vars_file ()
91 vartype=$1
92 : > vars-exp
93 : > vars-got.in
95 for var in $pyvars; do
96 if test x"$vartype" = xgnu; then
97 # when not using Python sys.* values, PYTHON_*PREFIX will vary;
98 # the computed value will be (something like) "/usr",
99 # but the expected value will be "${prefix}".
100 if test x"$var" = xPYTHON_PREFIX \
101 || test x"$var" = xPYTHON_EXEC_PREFIX; then
102 continue
105 eval val=\$$var
106 echo "var=$val #$var" >> vars-exp
107 echo "var=@$var@ #$var" >> vars-got.in
108 echo "${tab}test x'\$($var)' = x'$val' || test \"\$NO_CHECK_PYTHON_PREFIX\"" >> Makefile.am
109 done
112 setup_vars_file gnu
114 $ACLOCAL
115 $AUTOMAKE --add-missing
117 # some debugging output.
118 for var in pythondir pyexecdir $pyvars; do
119 grep "^$var *=" Makefile.in
120 done
122 $AUTOCONF
124 # Do GNU values.
125 ./configure PYTHON="$PYTHON"
126 $MAKE test-in test-am
127 run_make distcheck
129 # Do Python values.
130 setup_vars_file python
131 instdir=$(pwd)/inst
132 ./configure PYTHON="$PYTHON" --with-python-sys-prefix --prefix="$instdir"
133 $MAKE test-in test-am
135 # This tries to install to $PYTHON_PREFIX, which may not be writable.
136 # Override it to something safe, but then of course we have to skip
137 # checking that it is what we originally set it to.
138 run_make distcheck \
139 PYTHON_PREFIX="$instdir" \
140 NO_CHECK_PYTHON_PREFIX=1 \
141 AM_DISTCHECK_CONFIGURE_FLAGS=--with-python-sys-prefix