tests: never source test-defs.sh directly, source test-lib.sh instead
[automake.git] / t / instmany.sh
blob369e23a9eca1074a485dd6f4d70bf6b471bcb61e
1 #! /bin/sh
2 # Copyright (C) 2008-2012 Free Software Foundation, Inc.
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.
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.
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/>.
17 # Installing many files should not exceed the command line length limit.
18 # Here, the main issue is that we may prepend '$(srcdir)/' to each file,
19 # which may cause much longer command lines. The list of files must
20 # anyway remain below the limit, otherwise 'make' won't be able to even
21 # fork the command.
23 # Further, the install rule should honor failures of the install program.
25 # Python is done in the sister test.
26 # For texinfos, we expand names using $(srcdir) in the first place.
27 # Let's hope nobody uses many texinfos.
29 . ./defs || exit 1
31 # In order to have a useful test on modern systems (which have a high
32 # limit, if any), use a fake install program that errors out for more
33 # than 2K characters in a command line. The POSIX limit is 4096, but
34 # that may include space taken up by the environment.
36 limit=2500
37 subdir=long_subdir_name_with_many_characters
38 nfiles=81
39 list=$(seq_ 1 $nfiles)
41 sed "s|@limit@|$limit|g" >myinstall.in <<'END'
42 #! /bin/sh
43 # Fake install script. This doesn't really install
44 # (the INSTALL path below would be wrong outside this directory).
45 limit=@limit@
46 INSTALL='@INSTALL@'
47 len=`expr "$INSTALL $*" : ".*" 2>/dev/null || echo $limit`
48 if test $len -ge $limit; then
49 echo "$0: safe command line limit of $limit characters exceeded" >&2
50 exit 1
52 exit 0
53 END
55 # Creative quoting in the next line to please maintainer-check.
56 sed "s|@limit@|$limit|g" >'rm' <<'END'
57 #! /bin/sh
58 limit=@limit@
59 PATH=$save_PATH
60 export PATH
61 RM='rm -f'
62 len=`expr "$RM $*" : ".*" 2>/dev/null || echo $limit`
63 if test $len -ge $limit; then
64 echo "$0: safe command line limit of $limit characters exceeded" >&2
65 exit 1
67 exec $RM "$@"
68 exit 1
69 END
71 chmod +x rm
73 cat >>configure.ac <<END
74 AC_CONFIG_FILES([myinstall], [chmod +x ./myinstall])
75 AC_CONFIG_FILES([$subdir/Makefile])
76 AC_OUTPUT
77 END
79 cat >Makefile.am <<END
80 SUBDIRS = $subdir
81 END
83 mkdir $subdir
84 cd $subdir
86 cat >Makefile.am <<'END'
87 bin_SCRIPTS =
88 nobase_bin_SCRIPTS =
89 data_DATA =
90 nobase_data_DATA =
91 include_HEADERS =
92 nobase_include_HEADERS =
93 END
95 for n in $list; do
96 unindent >>Makefile.am <<END
97 bin_SCRIPTS += script$n
98 nobase_bin_SCRIPTS += nscript$n
99 data_DATA += data$n
100 nobase_data_DATA += ndata$n
101 include_HEADERS += header$n.h
102 nobase_include_HEADERS += nheader$n.h
104 echo >script$n
105 echo >nscript$n
106 echo >data$n
107 echo >ndata$n
108 echo >header$n.h
109 echo >nheader$n.h
110 done
112 cd ..
113 $ACLOCAL
114 $AUTOCONF
115 $AUTOMAKE --add-missing
117 instdir=$(pwd)/inst
118 mkdir build
119 cd build
120 ../configure --prefix="$instdir"
121 $MAKE
122 # Try whether native install (or install-sh) works.
123 $MAKE install
124 # Multiple uninstall should work, too.
125 $MAKE uninstall
126 $MAKE uninstall
127 test $(find "$instdir" -type f -print | wc -l) -eq 0
129 # Try whether we don't exceed the low limit.
130 INSTALL='$(SHELL) $(top_builddir)/myinstall' $MAKE -e install
131 env save_PATH="$PATH" PATH="$(pwd)/..$PATH_SEPARATOR$PATH" $MAKE uninstall
133 cd $subdir
134 srcdir=../../$subdir
136 # Ensure 'make install' fails when 'install' fails.
138 # We cheat here, for efficiency, knowing the internal rule names.
139 # For correctness, one should '$MAKE install' here always, or at
140 # least use install-exec or install-data.
142 for file in script3 script$nfiles
144 chmod a-r $srcdir/$file
145 test ! -r $srcdir/$file || skip_ "cannot drop file read permissions"
146 $MAKE install-binSCRIPTS && exit 1
147 chmod u+r $srcdir/$file
148 done
150 for file in nscript3 nscript$nfiles
152 chmod a-r $srcdir/$file
153 $MAKE install-nobase_binSCRIPTS && exit 1
154 chmod u+r $srcdir/$file
155 done
157 for file in data3 data$nfiles
159 chmod a-r $srcdir/$file
160 $MAKE install-dataDATA && exit 1
161 chmod u+r $srcdir/$file
162 done
164 for file in ndata3 ndata$nfiles
166 chmod a-r $srcdir/$file
167 $MAKE install-nobase_dataDATA && exit 1
168 chmod u+r $srcdir/$file
169 done
171 for file in header3.h header$nfiles.h
173 chmod a-r $srcdir/$file
174 $MAKE install-includeHEADERS && exit 1
175 chmod u+r $srcdir/$file
176 done
178 for file in nheader3.h nheader$nfiles.h
180 chmod a-r $srcdir/$file
181 $MAKE install-nobase_includeHEADERS && exit 1
182 chmod u+r $srcdir/$file
183 done