Merge branch 'maint'
[platform/upstream/automake.git] / t / dist-auxdir-many-subdirs.sh
1 #! /bin/sh
2 # Copyright (C) 2011-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 # It should be legitimate for many subdir Makefiles to require the
18 # same config-aux files.
19
20 am_create_testdir=empty
21 required=cc
22 . ./defs || exit 1
23
24 count=0
25 ocwd=$(pwd) || fatal_ "cannot get current working directory"
26
27 # Usage: do_check [--add-missing] [CONFIG-AUXDIR-PATH=.]
28 do_check ()
29 {
30   case $1 in
31     -a|--add-missing) add_missing=yes; shift;;
32     *) add_missing=no;;
33   esac
34   auxdir=${1-.}
35
36   count=$(($count + 1))
37   mkdir T$count.d
38   cd T$count.d
39
40   distdir=$me-$count
41   unindent > configure.ac << END
42     AC_INIT([$me], [$count])
43     AC_CONFIG_AUX_DIR([$auxdir])
44     AM_INIT_AUTOMAKE
45     AC_PROG_CC
46     # We don't want to require python or emcas in this test, so
47     # the tricks below.
48     AM_PATH_PYTHON([2.2], [], [:])
49     EMACS=no; AM_PATH_LISPDIR
50     AC_CONFIG_FILES([Makefile])
51 END
52
53   unindent > Makefile.stub <<'END'
54     ## For depcomp.
55     bin_PROGRAMS = foo
56     foo_SOURCES = foo.c
57     ## For py-compile.
58     python_PYTHON = bar.py
59     ## For elisp-comp.
60     lisp_LISP = baz.el
61     ## For test-driver.
62     TESTS =
63 END
64
65   required_files='
66     install-sh
67     missing
68     depcomp
69     py-compile
70     elisp-comp
71     test-driver
72   '
73
74   echo "SUBDIRS =" > Makefile.am
75
76   suffixes='0 1 2 3 4 5 6 7 8 9'
77
78   for x in $suffixes; do
79     mkdir sub$x
80     echo "SUBDIRS += sub$x" >> Makefile.am
81     echo "AC_CONFIG_FILES([sub$x/Makefile])" >> configure.ac
82     cp Makefile.stub sub$x/Makefile.am
83     echo 'int main (void) { return 0; }' > sub$x/foo.c
84     touch sub$x/bar.py sub$x/baz.el
85   done
86   echo AC_OUTPUT >> configure.ac
87
88   $ACLOCAL
89   $AUTOCONF
90
91   "$am_scriptdir"/install-sh -d $auxdir \
92     || fatal_ "creating directory '$auxdir' with install-sh"
93   if test $add_missing = yes; then
94     $AUTOMAKE -a --copy
95     for f in $required_files; do
96       test -f $auxdir/$f
97       # To ensure that if a auxiliary file is required and distributed
98       # by many Makefiles, the "dist" rule won't try to copy it multiple
99       # times in $(distdir).
100       chmod a-w $auxdir/$f
101     done
102   else
103     for f in $required_files; do
104       cp "$am_scriptdir"/$f $auxdir/$f \
105         || fatal_ "faild to fetch auxiliary script '$f'"
106       # See comments above.
107       chmod a-w $auxdir/$f
108     done
109     $AUTOMAKE
110   fi
111
112   for vpath in : false; do
113     if $vpath; then
114       mkdir build
115       cd build
116       srcdir=..
117     else
118       srcdir=.
119     fi
120     $srcdir/configure
121     $MAKE distdir
122     find $distdir # For debugging.
123     for f in $required_files; do
124       test -f $distdir/$auxdir/$f
125     done
126     cd $srcdir
127   done
128
129   cd "$ocwd" || fatal_ "cannot chdir back to '$ocwd'"
130 }
131
132 do_check .
133 do_check --add-missing .
134 do_check build-aux
135 do_check --add-missing build-aux
136 do_check a/b/c
137 do_check --add-missing a/b/c
138
139 :