1#! /bin/sh
2# Copyright (C) 2008-2021 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 <https://www.gnu.org/licenses/>.
16
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.
22#
23# Further, the install rule should honor failures of the install program.
24
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.
28
29. test-init.sh
30
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.
35
36limit=2500
37subdir=long_subdir_name_with_many_characters
38nfiles=81
39list=$(seq_ 1 $nfiles)
40
41oPATH=$PATH; export oPATH
42nPATH=$(pwd)/x-bin$PATH_SEPARATOR$PATH; export nPATH
43
44mkdir x-bin
45
46sed "s|@limit@|$limit|g" >x-bin/my-install <<'END'
47#! /bin/sh
48limit=@limit@
49PATH=$oPATH; export PATH
50if test -z "$orig_INSTALL"; then
51  echo "$0: \$orig_INSTALL variable not set" >&2
52  exit 1
53fi
54len=`expr "$orig_INSTALL $*" : ".*" 2>/dev/null || echo $limit`
55if test $len -ge $limit; then
56  echo "$0: safe command line limit of $limit characters exceeded" >&2
57  exit 1
58fi
59exec $orig_INSTALL "$@"
60exit 1
61END
62
63# Creative quoting in the next line to please maintainer-check.
64sed "s|@limit@|$limit|g" >x-bin/'rm' <<'END'
65#! /bin/sh
66limit=@limit@
67PATH=$oPATH; export PATH
68RM='rm -f'
69len=`expr "$RM $*" : ".*" 2>/dev/null || echo $limit`
70if test $len -ge $limit; then
71  echo "$0: safe command line limit of $limit characters exceeded" >&2
72  exit 1
73fi
74exec $RM "$@"
75exit 1
76END
77
78# Creative quoting in the next line to please maintainer-check.
79chmod +x x-bin/'rm' x-bin/my-install
80
81cat >setenv.in <<'END'
82orig_INSTALL='@INSTALL@'
83# In case we've falled back on the install-sh script (seen e.g.,
84# on AIX 7.1), we need to make sure we use its absolute path,
85# as we don't know from which directory we'll be run.
86case "$orig_INSTALL" in
87   /*) ;;
88  */*) orig_INSTALL=$(pwd)/$orig_INSTALL;;
89esac
90export orig_INSTALL
91END
92
93cat >>configure.ac <<END
94AC_CONFIG_FILES([setenv.sh:setenv.in])
95AC_CONFIG_FILES([$subdir/Makefile])
96AC_OUTPUT
97END
98
99cat >Makefile.am <<END
100SUBDIRS = $subdir
101END
102
103mkdir $subdir
104cd $subdir
105
106cat >Makefile.am <<'END'
107bin_SCRIPTS =
108nobase_bin_SCRIPTS =
109data_DATA =
110nobase_data_DATA =
111include_HEADERS =
112nobase_include_HEADERS =
113END
114
115for n in $list; do
116  unindent >>Makefile.am <<END
117    bin_SCRIPTS += script$n
118    nobase_bin_SCRIPTS += nscript$n
119    data_DATA += data$n
120    nobase_data_DATA += ndata$n
121    include_HEADERS += header$n.h
122    nobase_include_HEADERS += nheader$n.h
123END
124  echo >script$n
125  echo >nscript$n
126  echo >data$n
127  echo >ndata$n
128  echo >header$n.h
129  echo >nheader$n.h
130done
131
132cd ..
133$ACLOCAL
134$AUTOCONF
135$AUTOMAKE --add-missing
136
137instdir=$(pwd)/inst
138mkdir build
139cd build
140../configure --prefix="$instdir"
141. ./setenv.sh
142test -n "$orig_INSTALL"
143$MAKE
144# Try whether native install (or install-sh) works.
145$MAKE install
146test -f "$instdir/bin/script1"
147# Multiple uninstall should work, too.
148$MAKE uninstall
149$MAKE uninstall
150test $(find "$instdir" -type f -print | wc -l) -eq 0
151
152# Try whether we don't exceed the low limit.
153PATH=$nPATH; export PATH
154run_make INSTALL=my-install install
155test -f "$instdir/bin/script1"
156run_make INSTALL=my-install uninstall
157test $(find "$instdir" -type f -print | wc -l) -eq 0
158PATH=$oPATH; export PATH
159
160cd $subdir
161srcdir=../../$subdir
162
163# Ensure 'make install' fails when 'install' fails.
164
165# We cheat here, for efficiency, knowing the internal rule names.
166# For correctness, one should '$MAKE install' here always, or at
167# least use install-exec or install-data.
168
169for file in script3 script$nfiles
170do
171  chmod a-r $srcdir/$file
172  test ! -r $srcdir/$file || skip_ "cannot drop file read permissions"
173  $MAKE install-binSCRIPTS && exit 1
174  chmod u+r $srcdir/$file
175done
176
177for file in nscript3 nscript$nfiles
178do
179  chmod a-r $srcdir/$file
180  $MAKE install-nobase_binSCRIPTS && exit 1
181  chmod u+r $srcdir/$file
182done
183
184for file in data3 data$nfiles
185do
186  chmod a-r $srcdir/$file
187  $MAKE install-dataDATA && exit 1
188  chmod u+r $srcdir/$file
189done
190
191for file in ndata3 ndata$nfiles
192do
193  chmod a-r $srcdir/$file
194  $MAKE install-nobase_dataDATA && exit 1
195  chmod u+r $srcdir/$file
196done
197
198for file in header3.h header$nfiles.h
199do
200  chmod a-r $srcdir/$file
201  $MAKE install-includeHEADERS && exit 1
202  chmod u+r $srcdir/$file
203done
204
205for file in nheader3.h nheader$nfiles.h
206do
207  chmod a-r $srcdir/$file
208  $MAKE install-nobase_includeHEADERS && exit 1
209  chmod u+r $srcdir/$file
210done
211
212:
213