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