tests: Let 'ltorder.sh' run successfully with Guix dynamic loader
[automake.git] / t / pr401c.sh
blob59f6aaa15677fb6e3b29d728f20c62161d4285c1
1 #! /bin/sh
2 # Copyright (C) 2005-2018 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 <https://www.gnu.org/licenses/>.
17 # Check support for AC_CONFIG_LIBOBJ_DIR vs ALLOCA.
18 # (pr401.sh and pr401b.sh do the same for LIBOBJS and LTLIBOBJS)
20 required=cc
21 . test-init.sh
23 mkdir lib src
25 ac_cv_func_alloca_works=no; export ac_cv_func_alloca_works
27 cat >lib/alloca.c <<'EOF'
28 const char *feep (void)
30 return "feep";
32 EOF
34 cat >src/main.c <<'EOF'
35 #include <stdio.h>
37 extern const char *feep (void);
39 int main (void)
41 puts (feep ());
42 return 0;
44 EOF
46 cat >>configure.ac << 'EOF'
47 ## These lines are activated for later tests.
48 #: AC_CONFIG_LIBOBJ_DIR([lib])
49 AC_PROG_CC
50 AM_PROG_AR
51 AC_PROG_RANLIB
52 AC_FUNC_ALLOCA
53 AC_CONFIG_FILES([lib/Makefile src/Makefile])
54 AM_CONDITIONAL([CROSS_COMPILING], [test $cross_compiling = yes])
55 AC_OUTPUT
56 EOF
58 ## ----------------------------------------- ##
59 ## First a test of traditional ALLOCA usage. ##
60 ## ----------------------------------------- ##
62 cat >Makefile.am <<'EOF'
63 SUBDIRS = lib src
64 EOF
66 cat >lib/Makefile.am <<'EOF'
67 noinst_LIBRARIES = libfeep.a
68 libfeep_a_SOURCES =
69 libfeep_a_LIBADD = $(ALLOCA)
70 EOF
72 cat >src/Makefile.am <<'EOF'
73 check_PROGRAMS = main
74 main_LDADD = ../lib/libfeep.a
76 if !CROSS_COMPILING
77 TESTS = main
78 endif
79 EOF
81 cp "$am_scriptdir/ar-lib" . || fatal_ "fetching auxiliary script 'ar-lib'"
83 $ACLOCAL
84 $AUTOCONF
85 $AUTOMAKE -a
86 ./configure
87 $MAKE distcheck
90 ## --------------------------------------- ##
91 ## Traditional ALLOCA with LIBOBJDIR set. ##
92 ## --------------------------------------- ##
94 # Invocation of AC_CONFIG_LIBOBJ_DIR may be necessary for reasons
95 # unrelated to Automake or Makefile.am layout.
97 sed 's/#: //' configure.ac >configure.tmp
98 mv -f configure.tmp configure.ac
100 $ACLOCAL
101 $AUTOCONF
102 $AUTOMAKE
103 ./configure
104 test ! -e lib/lib
105 $MAKE distcheck
107 ## -------------------------------------------- ##
108 ## Error message with usage in wrong directory. ##
109 ## -------------------------------------------- ##
111 mv -f src/Makefile.am src/t
112 sed 's/LDADD = .*/LDADD = @ALLOCA@/' src/t > src/Makefile.am
113 AUTOMAKE_fails
114 grep 'cannot be used outside.*lib' stderr
115 mv -f src/t src/Makefile.am
118 ## ------------------------------------------- ##
119 ## Test using ALLOCA from a sibling directory. ##
120 ## ------------------------------------------- ##
122 sed 's/lib\/Makefile //' configure.ac >configure.tmp
123 mv -f configure.tmp configure.ac
125 cat >Makefile.am <<'EOF'
126 SUBDIRS = src
129 cat > src/Makefile.am <<'EOF'
130 AUTOMAKE_OPTIONS = subdir-objects
132 noinst_LIBRARIES = libfeep.a
133 libfeep_a_SOURCES =
134 libfeep_a_LIBADD = $(ALLOCA) $(LIBOBJS) # Add LIBOBJS for fun.
136 check_PROGRAMS = main
137 main_LDADD = libfeep.a
139 if !CROSS_COMPILING
140 TESTS = main
141 endif
144 $ACLOCAL
145 $AUTOCONF
146 $AUTOMAKE --add-missing
147 ./configure
148 $MAKE
149 test ! -e src/lib
150 test ! -e 'src/$(top_builddir)'
151 $MAKE check
152 $MAKE distclean
155 ## ---------------------------------------- ##
156 ## Test using ALLOCA from parent directory. ##
157 ## ---------------------------------------- ##
159 sed 's/^.*src\/Makefile.*$//' configure.ac >configure.tmp
160 mv -f configure.tmp configure.ac
162 cat >Makefile.am <<'EOF'
163 AUTOMAKE_OPTIONS = subdir-objects
165 noinst_LIBRARIES = lib/libfeep.a
166 lib_libfeep_a_SOURCES =
167 lib_libfeep_a_LIBADD = $(ALLOCA)
169 check_PROGRAMS = src/main
170 src_main_SOURCES = src/main.c
171 src_main_LDADD = lib/libfeep.a
173 if !CROSS_COMPILING
174 TESTS = src/main
175 endif
177 check-local:
178 test -f src/main.$(OBJEXT)
179 test -f lib/alloca.$(OBJEXT)
180 test ! -f src/$(DEPDIR)/alloca.Po
183 $ACLOCAL
184 $AUTOCONF
185 $AUTOMAKE
186 ./configure
187 $MAKE distcheck