Merge branch master into maint after 1.12 release
[platform/upstream/automake.git] / t / pr401c.sh
1 #! /bin/sh
2 # Copyright (C) 2005-2012 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 # Check support for AC_CONFIG_LIBOBJ_DIR vs ALLOCA.
18 # (pr401.test and pr401b.test do the same for LIBOBJS and LTLIBOBJS)
19
20 am_parallel_tests=no
21 required=cc
22 . ./defs || Exit 1
23
24 mkdir lib src
25
26 ac_cv_func_alloca_works=no
27 export  ac_cv_func_alloca_works
28
29 cat >lib/alloca.c <<'EOF'
30 const char *feep (void)
31 {
32   return "feep";
33 }
34 EOF
35
36 cat >src/main.c <<'EOF'
37 #include <stdio.h>
38
39 extern const char *feep (void);
40
41 int main (void)
42 {
43   puts (feep ());
44   return 0;
45 }
46 EOF
47
48 cat >>configure.ac << 'EOF'
49 ## These lines are activated for later tests.
50 #: AC_CONFIG_LIBOBJ_DIR([lib])
51 AC_PROG_CC
52 #x AM_PROG_CC_C_O
53 AM_PROG_AR
54 AC_PROG_RANLIB
55 AC_FUNC_ALLOCA
56 AC_CONFIG_FILES([lib/Makefile src/Makefile])
57 AM_CONDITIONAL([CROSS_COMPILING], [test $cross_compiling = yes])
58 AC_OUTPUT
59 EOF
60
61 ## ----------------------------------------- ##
62 ## First a test of traditional ALLOCA usage. ##
63 ## ----------------------------------------- ##
64
65 cat >Makefile.am <<'EOF'
66 SUBDIRS = lib src
67 EOF
68
69 cat >lib/Makefile.am <<'EOF'
70 noinst_LIBRARIES = libfeep.a
71 libfeep_a_SOURCES =
72 libfeep_a_LIBADD = $(ALLOCA)
73 EOF
74
75 cat >src/Makefile.am <<'EOF'
76 check_PROGRAMS = main
77 main_LDADD = ../lib/libfeep.a
78
79 if !CROSS_COMPILING
80 TESTS = main
81 endif
82 EOF
83
84 cp "$am_scriptdir/ar-lib" . || fatal_ "fetching auxiliary script 'ar-lib'"
85
86 $ACLOCAL
87 $AUTOCONF
88 $AUTOMAKE
89 ./configure
90 $MAKE distcheck
91
92
93 ## --------------------------------------- ##
94 ## Traditional ALLOCA with LIBOBJDIR set.  ##
95 ## --------------------------------------- ##
96
97 # Invocation of AC_CONFIG_LIBOBJ_DIR may be necessary for reasons
98 # unrelated to Automake or Makefile.am layout.
99
100 sed 's/#: //' configure.ac >configure.int
101 mv -f configure.int configure.ac
102
103 $ACLOCAL
104 $AUTOCONF
105 $AUTOMAKE
106 ./configure
107 test ! -d lib/lib
108 $MAKE distcheck
109
110 ## -------------------------------------------- ##
111 ## Error message with usage in wrong directory. ##
112 ## -------------------------------------------- ##
113
114 mv -f src/Makefile.am src/t
115 sed 's/LDADD = .*/LDADD = @ALLOCA@/' src/t > src/Makefile.am
116 AUTOMAKE_fails
117 grep 'cannot be used outside.*lib' stderr
118 mv -f src/t src/Makefile.am
119
120
121 ## ------------------------------------------- ##
122 ## Test using ALLOCA from a sibling directory. ##
123 ## ------------------------------------------- ##
124
125 sed 's/#x //; s/lib\/Makefile //' configure.ac >configure.int
126 mv -f configure.int configure.ac
127
128 cat >Makefile.am <<'EOF'
129 SUBDIRS = src
130 EOF
131
132 cat > src/Makefile.am <<'EOF'
133 AUTOMAKE_OPTIONS = subdir-objects
134
135 noinst_LIBRARIES = libfeep.a
136 libfeep_a_SOURCES =
137 libfeep_a_LIBADD = $(ALLOCA) $(LIBOBJS) # Add LIBOBJS for fun.
138
139 check_PROGRAMS = main
140 main_LDADD = libfeep.a
141
142 if !CROSS_COMPILING
143 TESTS = main
144 endif
145 EOF
146
147 $ACLOCAL
148 $AUTOCONF
149 $AUTOMAKE --add-missing
150 ./configure
151 $MAKE
152 test ! -d src/lib
153 test ! -d 'src/$(top_builddir)'
154 $MAKE check
155 $MAKE distclean
156
157
158 ## ---------------------------------------- ##
159 ## Test using ALLOCA from parent directory. ##
160 ## ---------------------------------------- ##
161
162 sed 's/^.*src\/Makefile.*$//' configure.ac >configure.int
163 mv -f configure.int configure.ac
164
165 cat >Makefile.am <<'EOF'
166 AUTOMAKE_OPTIONS = subdir-objects
167
168 noinst_LIBRARIES = lib/libfeep.a
169 lib_libfeep_a_SOURCES =
170 lib_libfeep_a_LIBADD = $(ALLOCA)
171
172 check_PROGRAMS = src/main
173 src_main_SOURCES = src/main.c
174 src_main_LDADD = lib/libfeep.a
175
176 if !CROSS_COMPILING
177 TESTS = src/main
178 endif
179
180 check-local:
181         test -f src/main.$(OBJEXT)
182         test -f lib/alloca.$(OBJEXT)
183         test ! -f src/$(DEPDIR)/alloca.Po
184 EOF
185
186 $ACLOCAL
187 $AUTOCONF
188 $AUTOMAKE
189 ./configure
190 $MAKE distcheck
191
192 :