relativize.tap 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. # Test Automake-provided internal make macro $(am__relativize).
  17. am_create_testdir=empty
  18. . test-init.sh
  19. plan_ later
  20. mkdir uber uber/top
  21. cd uber/top
  22. : > install-sh
  23. : > missing
  24. cat >> configure.ac <<END
  25. AC_INIT([$me], [1.0])
  26. AM_INIT_AUTOMAKE
  27. AC_CONFIG_FILES([Makefile])
  28. AC_OUTPUT
  29. END
  30. cat > Makefile.am << 'END'
  31. # The 'am__relitivize' definition is only brought in when
  32. # SUBDIRS are defined.
  33. SUBDIRS = .
  34. .PHONY: test
  35. test:
  36. @$(am__relativize); echo "result: '$$reldir'"; set -x; \
  37. case $${reldir:-.} in "$$exp"|"$$exp/.") ;; *) exit 1;; esac
  38. END
  39. $ACLOCAL && $AUTOMAKE && $AUTOCONF && ./configure || fatal_ "setup failure"
  40. rel_ ()
  41. {
  42. case $1 in -x) directive=TODO; shift;; *) directive=;; esac
  43. test $# -eq 4 && test x"$3" = x"=" || fatal_ "rel_: incorrect usage"
  44. command_ok_ "$1/{$4} = $2" -D "$directive" \
  45. env dir1=$1 dir2=$2 exp=$4 $MAKE test
  46. }
  47. # am__relativize
  48. # ~~~~~~~~~~~~~~
  49. # Computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
  50. # Input:
  51. # - DIR1 relative pathname, relative to the current directory
  52. # - DIR2 relative pathname, relative to the current directory
  53. # Output:
  54. # - reldir relative pathname of DIR2, relative to DIR1
  55. rel_ . . = .
  56. rel_ . .. = ..
  57. rel_ .. . = top
  58. for d in x long-longer a/b 1/2/3/4/5; do
  59. rel_ $d $d = .
  60. for d2 in . .. x r/s/t; do
  61. rel_ $d $d/$d2 = $d2
  62. done
  63. done
  64. rel_ one two = ../two
  65. rel_ a b/c = ../b/c
  66. rel_ a/b . = ../..
  67. rel_ a/b foo = ../../foo
  68. rel_ a/b foo/bar = ../../foo/bar
  69. rel_ a/b a/c = ../c
  70. rel_ a/b a/c/d = ../c/d
  71. rel_ foo/bar/baz foo/bar/qux/zap = ../qux/zap
  72. rel_ ../foo . = ../top
  73. rel_ ../.. . = uber/top
  74. rel_ ../../foo . = ../uber/top
  75. rel_ ../../x ok = ../uber/top/ok
  76. rel_ ../../x bo/ba = ../uber/top/bo/ba
  77. rel_ ../../x ../ok2 = ../uber/top/../ok2
  78. rel_ ../a/b/c/d/e . = ../../../../../top
  79. :