* COPYING, lib/COPYING: Update to GPLv3. All uses changed.
[platform/upstream/automake.git] / tests / pr401c.test
1 #! /bin/sh
2 # Copyright (C) 2005, 2006, 2007  Free Software Foundation, Inc.
3 #
4 # This file is part of GNU Automake.
5 #
6 # GNU Automake is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
9 # any later version.
10 #
11 # GNU Automake is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Automake; see the file COPYING.  If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 # Boston, MA 02110-1301, USA.
20
21 # Check support for AC_CONFIG_LIBOBJ_DIR vs ALLOCA.
22 # (pr401.test and pr401b.test do the same for LIBOBJS and LTLIBOBJS)
23
24 required=gcc
25 . ./defs || exit 1
26
27 set -e
28
29 mkdir lib src
30
31 ac_cv_func_alloca_works=no
32 export  ac_cv_func_alloca_works
33
34 cat >lib/alloca.c <<'EOF'
35 char *
36 feep ()
37 {
38   return "feep";
39 }
40 EOF
41
42 cat >src/main.c <<'EOF'
43 #include <stdio.h>
44
45 extern char *feep ();
46
47 int
48 main (int argc, char **argv)
49 {
50   puts (feep ());
51   return 0;
52 }
53 EOF
54
55 cat >>configure.in << 'EOF'
56 ## These lines are activated for later tests
57 #: AC_CONFIG_LIBOBJ_DIR([lib])
58 AC_PROG_CC
59 #x AM_PROG_CC_C_O
60 AC_PROG_RANLIB
61 AC_FUNC_ALLOCA
62 AC_CONFIG_FILES([lib/Makefile src/Makefile])
63 AC_OUTPUT
64 EOF
65
66 ## ----------------------------------------- ##
67 ## First a test of traditional ALLOCA usage. ##
68 ## ----------------------------------------- ##
69
70 cat >Makefile.am <<'EOF'
71 SUBDIRS = lib src
72 EOF
73
74 cat >lib/Makefile.am <<'EOF'
75 noinst_LIBRARIES = libfeep.a
76 libfeep_a_SOURCES =
77 libfeep_a_LIBADD = $(ALLOCA)
78 EOF
79
80 cat >src/Makefile.am <<'EOF'
81 check_PROGRAMS = main
82 main_LDADD = ../lib/libfeep.a
83
84 TESTS = main
85 EOF
86
87 $ACLOCAL
88 $AUTOCONF
89 $AUTOMAKE
90 ./configure
91 $MAKE distcheck
92
93
94 ## ------------------------------------------ ##
95 ## Traditional LIBOBJS with LIBOBJDIR set.    ##
96 ## ------------------------------------------ ##
97
98 # Invocation of AC_CONFIG_LIBOBJ_DIR may be necessary for reasons
99 # unrelated to Automake or Makefile.am layout.
100
101 sed 's/#: //' configure.in >configure.int
102 mv -f configure.int configure.in
103
104 $ACLOCAL
105 $AUTOCONF
106 $AUTOMAKE
107 ./configure
108 test ! -d lib/lib
109 $MAKE distcheck
110
111 ## -------------------------------------------- ##
112 ## Error message with usage in wrong directory. ##
113 ## -------------------------------------------- ##
114
115 mv -f src/Makefile.am src/t
116 sed 's/LDADD = .*/LDADD = @ALLOCA@/' src/t > src/Makefile.am
117 AUTOMAKE_fails
118 grep 'cannot be used outside.*lib' stderr
119 mv -f src/t src/Makefile.am
120
121
122 ## ------------------------------------------- ##
123 ## Test using ALLOCA from a sibling directory. ##
124 ## ------------------------------------------- ##
125
126 sed 's/#x //; s/lib\/Makefile //' configure.in >configure.int
127 mv -f configure.int configure.in
128
129 cat >Makefile.am <<'EOF'
130 SUBDIRS = src
131 EOF
132
133 cat > src/Makefile.am <<'EOF'
134 AUTOMAKE_OPTIONS = subdir-objects
135
136 noinst_LIBRARIES = libfeep.a
137 libfeep_a_SOURCES =
138 libfeep_a_LIBADD = $(ALLOCA) $(LIBOBJS) # Add LIBOBJS for fun
139
140 check_PROGRAMS = main
141 main_LDADD = libfeep.a
142
143 TESTS = main
144 EOF
145
146 $ACLOCAL
147 $AUTOCONF
148 $AUTOMAKE --add-missing
149 ./configure
150 $MAKE
151 test ! -d src/lib
152 test ! -d 'src/$(top_builddir)'
153 $MAKE check
154 $MAKE distclean
155
156
157 ## ---------------------------------------- ##
158 ## Test using ALLOCA from parent directory. ##
159 ## ---------------------------------------- ##
160
161 sed 's/^.*src\/Makefile.*$//' configure.in >configure.int
162 mv -f configure.int configure.in
163
164 cat >Makefile.am <<'EOF'
165 AUTOMAKE_OPTIONS = subdir-objects
166
167 noinst_LIBRARIES = lib/libfeep.a
168 lib_libfeep_a_SOURCES =
169 lib_libfeep_a_LIBADD = $(ALLOCA)
170
171 check_PROGRAMS = src/main
172 src_main_SOURCES = src/main.c
173 src_main_LDADD = lib/libfeep.a
174
175 TESTS = src/main
176
177 check-local:
178         test -f src/main.$(OBJEXT)
179         test -f lib/alloca.$(OBJEXT)
180         test ! -f src/$(DEPDIR)/alloca.Po
181 EOF
182
183 $ACLOCAL
184 $AUTOCONF
185 $AUTOMAKE
186 ./configure
187 $MAKE distcheck