test: protect more yacc declarations against C vs. C++ linkage.
[automake.git] / t / pkg-config-macros.sh
blob95f38bf35b6f486d171a8bb98d975c25e6958597
1 #! /bin/sh
2 # Copyright (C) 2012-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 # Try to find the pkg-config '.m4' files and make them easily accessed
18 # to the test cases requiring them.
20 . test-init.sh
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 IFS=:
52 for d in $PATH; do
53 IFS=$oIFS
54 if test -f $d/pkg-config || test -f $d/pkg-config.exe; then
55 dir=$d
56 break
58 done
59 IFS=$oIFS
61 # Now try to use the location of the pkg-config executable to guess
62 # where the corresponding pkg.m4 might be installed.
63 if test -n "$dir"; then
64 # Only support standard installation layouts.
65 XT_ACLOCAL_PATH=${dir%/bin}/share/aclocal:$XT_ACLOCAL_PATH
68 XT_ACLOCAL_PATH=$XT_ACLOCAL_PATH${ACLOCAL_PATH+":$ACLOCAL_PATH"}
70 # Try once again to fetch the pkg-config macros.
71 mkdir m4
72 ACLOCAL_PATH=$XT_ACLOCAL_PATH $ACLOCAL -Wno-syntax --install -I m4
73 if test -f m4/pkg.m4 && have_pkg_config_macros; then
74 echo "ACLOCAL_PATH='$(pwd)/m4':\$ACLOCAL_PATH" >> get.sh
75 echo "export ACLOCAL_PATH" >> get.sh
76 echo "sed 20q '$(pwd)/m4/pkg.m4' # For debugging." >> get.sh
77 else
78 echo "skip_all_ \"pkg-config m4 macros not found\"" >> get.sh
81 unset ACLOCAL_PATH
82 . ./get.sh
84 $ACLOCAL --force -I m4 || cat >> get.sh <<'END'
85 # We need to use '-Wno-syntax', since we do not want our test suite
86 # to fail merely because some third-party '.m4' file is underquoted.
87 ACLOCAL="$ACLOCAL -Wno-syntax"
88 END
90 # The pkg-config m4 file(s) we might fetched will be copied in the
91 # 'm4' subdirectory of the test directory are going to be needed by
92 # other tests, so we must not remove the test directory.
93 keep_testdirs=yes