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