5bac2803b79c85d911b4527507a76c57e7db4baa
[platform/upstream/automake.git] / t / python-vars.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
3 #
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.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Check that AM_PATH_PYTHON correctly sets all the output variables
18 # advertised in the manual.
19
20 required=python
21 . ./defs || exit 1
22
23 # In case the user's config.site defines pythondir or pyexecdir.
24 CONFIG_SITE=/dev/null; export CONFIG_SITE
25
26 PYTHON=python
27
28 # Update the definition below if the documentation changes.
29 # Note that the value of the 'pythondir' and 'pyexecdir' variables can
30 # vary among different python installations, so we need more relaxed
31 # and ad-hoc checks for them.  Also, more proper "functional" checks
32 # on them should be done in the 'python-virtualenv.sh' test.
33 PYTHON_VERSION=$($PYTHON -c 'import sys; print(sys.version[:3])') || exit 1
34 PYTHON_PLATFORM=$($PYTHON -c 'import sys; print(sys.platform)') || exit 1
35 PYTHON_EXEC_PREFIX='${exec_prefix}'
36 PYTHON_PREFIX='${prefix}'
37 pkgpythondir="\${pythondir}/$me"
38 pkgpyexecdir="\${pyexecdir}/$me"
39
40 pyvars='PYTHON_VERSION PYTHON_PLATFORM PYTHON_PREFIX PYTHON_EXEC_PREFIX
41         pkgpythondir pkgpyexecdir'
42
43 cat >> configure.ac << 'END'
44 AC_CONFIG_FILES([vars-got pythondir pyexecdir])
45 AM_PATH_PYTHON
46 AC_OUTPUT
47 END
48
49 cat > my.py << 'END'
50 def my():
51     return 1
52 END
53
54 cat > Makefile.am << 'END'
55
56 python_PYTHON = my.py
57
58 EXTRA_DIST = vars-exp
59
60 check-local: test-in test-am
61 .PHONY: test-in test-am
62
63 test-in:
64         cat pythondir
65         case `cat pythondir` in '$${prefix}'/*);; *) exit 1;; esac
66         cat pyexecdir
67         case `cat pyexecdir` in '$${exec_prefix}'/*);; *) exit 1;; esac
68         cat $(srcdir)/vars-exp
69         cat $(builddir)/vars-got
70         diff $(srcdir)/vars-exp $(builddir)/vars-got
71
72 ## Note: this target's rules will be extended in the "for" loop below.
73 test-am:
74         case '$(pythondir)' in '$(prefix)'/*);; *) exit 1;; esac
75         case '$(pyexecdir)' in '$(exec_prefix)'/*);; *) exit 1;; esac
76 END
77
78 echo @pythondir@ > pythondir.in
79 echo @pyexecdir@ > pyexecdir.in
80
81 : > vars-exp
82 : > vars-got.in
83
84 for var in $pyvars; do
85   eval val=\$$var
86   echo "var=$val" >> vars-exp
87   echo "var=@$var@" >> vars-got.in
88   echo "${tab}test x'\$($var)' = x'$val'" >> Makefile.am
89 done
90
91 cat Makefile.am
92 cat vars-got.in
93
94 $ACLOCAL
95 $AUTOMAKE --add-missing
96
97 for var in pythondir pyexecdir $pyvars; do
98   grep "^$var *=" Makefile.in
99 done
100
101 $AUTOCONF
102 ./configure PYTHON="$PYTHON"
103
104 $MAKE test-in test-am
105 $MAKE distcheck
106
107 :