Merge branch 'maint'
[platform/upstream/automake.git] / t / pkg-config-macros.sh
1 #! /bin/sh
2 # Copyright (C) 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 # Try to find the pkg-config '.m4' files and make them easily accessed
18 # to the test cases requiring them.
19
20 . test-init.sh
21
22 echo "# Automatically generated by $me." > get.sh
23 echo : >> get.sh
24
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
29 fi
30
31 cat > configure.ac <<'END'
32 AC_INIT([pkg], [1.0])
33 PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
34 END
35
36 have_pkg_config_macros ()
37 {
38   $AUTOCONF && ! $FGREP PKG_CHECK_MODULES configure
39 }
40
41 if have_pkg_config_macros; then
42   # The pkg-config macros are already available, nothing to do.
43   exit 0
44 fi
45
46 # Usual locations where pkg.m4 *might* be installed.
47 XT_ACLOCAL_PATH=/usr/local/share/aclocal:/usr/share/aclocal
48
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
56   fi
57 done
58 IFS=$oIFS
59
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
65 fi
66
67 XT_ACLOCAL_PATH=$XT_ACLOCAL_PATH${ACLOCAL_PATH+":$ACLOCAL_PATH"}
68
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
78 fi
79
80 ACLOCAL_PATH=; unset ACLOCAL_PATH
81 . ./get.sh
82
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
88
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
93
94 :