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