tests: improve 'pkg-config' requirement
[automake.git] / t / pkg-config-macros.sh
blob06a65e35e25d4950c2604c7b7c66ba9c62c5a8d3
1 #! /bin/sh
2 # Copyright (C) 2012 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 <http://www.gnu.org/licenses/>.
17 # Try to find the pkg-config '.m4' files and make them easily accessed
18 # to the test cases requiring them.
20 . ./defs || exit 1
22 echo "# Automatically generated by $me." > get.sh
23 echo : >> get.sh
25 if ver=$(pkg-config --version) && test -n "$ver"; then
26 echo "printf 'pkg-config version: %s\\n' '$ver'" >> get.sh
27 else
28 echo "skip_all_ \"'pkg-config' not available\"" >> get.sh
31 cat > configure.ac <<'END'
32 AC_INIT([pkg], [1.0])
33 PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
34 END
36 have_pkg_config_macros ()
38 $AUTOCONF && ! $FGREP PKG_CHECK_MODULES configure
41 if have_pkg_config_macros; then
42 # The pkg-config macros are already available, nothing to do.
43 exit 0
46 # Usual locations where pkg.m4 *might* be installed.
47 XT_ACLOCAL_PATH=/usr/local/share/aclocal:/usr/share/aclocal
49 # Find the location of the pkg-config executable.
50 oIFS=$IFS dir=
51 for d in $PATH; do
52 IFS=$oIFS
53 if test -f $dir/pkg-config || test -f $dir/pkg-config.exe; then
54 dir=$d
55 break
57 done
58 IFS=$oIFS
60 # Now try to use the location of the pkg-config executable to guess
61 # where the corresponding pkg.m4 might be installed.
62 if test -n "$dir"; then
63 # Only support standard installation layouts.
64 XT_ACLOCAL_PATH=${dir%/bin}/share/alocal:$XT_ACLOCAL_PATH
67 XT_ACLOCAL_PATH=$XT_ACLOCAL_PATH${ACLOCAL_PATH+":$ACLOCAL_PATH"}
69 # Try once again to fetch the pkg-config macros.
70 mkdir m4
71 ACLOCAL_PATH=$XT_ACLOCAL_PATH $ACLOCAL --install -I m4
72 if test -f m4/pkg.m4 && have_pkg_config_macros; then
73 echo "ACLOCAL_PATH='$(pwd)/m4':\$ACLOCAL_PATH" >> get.sh
74 echo "export ACLOCAL_PATH" >> get.sh
75 echo "sed 20q '$(pwd)/m4/pkg.m4' # For debugging." >> get.sh
76 else
77 echo "skip_all_ \"pkg-config m4 macros not found\"" >> get.sh
80 ACLOCAL_PATH=; unset ACLOCAL_PATH
81 . ./get.sh
83 $ACLOCAL --force -I m4 || cat >> get.sh <<'END'
84 # We need to use '-Wno-syntax', since we do not want our test suite
85 # to fail merely because some third-party '.m4' file is underquoted.
86 ACLOCAL="$ACLOCAL -Wno-syntax"
87 END
89 # The pkg-config m4 file(s) we might fetched will be copied in the
90 # 'm4' subdirectory of the test directory are going to be needed by
91 # other tests, so we must not remove the test directory.
92 keep_testdirs=yes