tests: less uses of "make -e"; avoid spurious failures in 'check-cc-no-c-o'
[platform/upstream/automake.git] / t / instmany-mans.sh
1 #! /bin/sh
2 # Copyright (C) 2008-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 # Installing many files should not exceed the command line length limit.
18
19 # This is the mans sister test of 'instmany.sh', see there for details.
20
21 . test-init.sh
22
23 # In order to have a useful test on modern systems (which have a high
24 # limit, if any), use a fake install program that errors out for more
25 # than 2K characters in a command line.  The POSIX limit is 4096, but
26 # that may include space taken up by the environment.
27
28 limit=2500
29 subdir=long_subdir_name_with_many_characters
30 nfiles=81
31 list=$(seq_ 1 $nfiles)
32
33 sed "s|@limit@|$limit|g" >myinstall.in <<'END'
34 #! /bin/sh
35 # Fake install script.  This doesn't really install
36 # (the INSTALL path below would be wrong outside this directory).
37 limit=@limit@
38 INSTALL='@INSTALL@'
39 len=`expr "$INSTALL $*" : ".*" 2>/dev/null || echo $limit`
40 if test $len -ge $limit; then
41   echo "$0: safe command line limit of $limit characters exceeded" >&2
42   exit 1
43 fi
44 exit 0
45 END
46
47 # Creative quoting in the next line to please maintainer-check.
48 sed "s|@limit@|$limit|g" >'rm' <<'END'
49 #! /bin/sh
50 limit=@limit@
51 PATH=$save_PATH
52 export PATH
53 RM='rm -f'
54 len=`expr "$RM $*" : ".*" 2>/dev/null || echo $limit`
55 if test $len -ge $limit; then
56   echo "$0: safe command line limit of $limit characters exceeded" >&2
57   exit 1
58 fi
59 exec $RM "$@"
60 exit 1
61 END
62
63 chmod +x rm
64
65 cat >>configure.ac <<END
66 AC_CONFIG_FILES([myinstall], [chmod +x ./myinstall])
67 AC_CONFIG_FILES([$subdir/Makefile])
68 AC_OUTPUT
69 END
70
71 cat >Makefile.am <<END
72 SUBDIRS = $subdir
73 END
74
75 mkdir $subdir
76 cd $subdir
77
78 cat >Makefile.am <<'END'
79 man_MANS =
80 man3_MANS =
81 notrans_man_MANS =
82 notrans_man3_MANS =
83 END
84
85 for n in $list; do
86   unindent >>Makefile.am <<END
87     man_MANS += page$n.1
88     man3_MANS += page$n.man
89     notrans_man_MANS += npage$n.1
90     notrans_man3_MANS += npage$n.man
91 END
92   echo >page$n.1
93   echo >page$n.man
94   echo >npage$n.1
95   echo >npage$n.man
96 done
97
98 cd ..
99 $ACLOCAL
100 $AUTOCONF
101 $AUTOMAKE --add-missing
102
103 instdir=$(pwd)/inst
104 mkdir build
105 cd build
106 ../configure --prefix="$instdir"
107 $MAKE
108 # Try whether native install (or install-sh) works.
109 $MAKE install
110 # Multiple uninstall should work, too.
111 $MAKE uninstall
112 $MAKE uninstall
113 test $(find "$instdir" -type f -print | wc -l) -eq 0
114
115 # Try whether we don't exceed the low limit.
116 INSTALL='$(SHELL) $(top_builddir)/myinstall' $MAKE -e install
117 env save_PATH="$PATH" PATH="$(pwd)/..$PATH_SEPARATOR$PATH" $MAKE uninstall
118
119 cd $subdir
120 srcdir=../../$subdir
121
122 # Ensure 'make install' fails when 'install' fails.
123
124 # We cheat here, for efficiency, knowing the internal rule names.
125 # For correctness, one should '$MAKE install' here always, or at
126 # least use install-exec or install-data.
127
128 for file in page3.1 page$nfiles.1 npage3.1 npage$nfiles.1; do
129   chmod a-r $srcdir/$file
130   test ! -r $srcdir/$file || skip_ "cannot drop file read permissions"
131   $MAKE install-man1 && exit 1
132   chmod u+r $srcdir/$file
133 done
134
135 for file in page3.man page$nfiles.man npage3.man npage$nfiles.man; do
136   chmod a-r $srcdir/$file
137   $MAKE install-man3 && exit 1
138   chmod u+r $srcdir/$file
139 done
140
141 :