pkg-config-macros.sh 2.8 KB

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