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