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