maint: Update HACKING
[automake.git] / t / subobj-objname-clash.sh
blob7da9868c8a0d99daeae3b7fa2aea4b80a55cc73b
1 #! /bin/sh
2 # Copyright (C) 1996-2017 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 # Make sure that object names don't clash when using subdir-objects.
18 # The check is done for clashing programs, clashing libraries and
19 # a program that clashes with a library
21 . test-init.sh
23 mkdir src
25 cat >> configure.ac << 'END'
26 AC_PROG_CC
27 AC_PROG_RANLIB
28 AC_OUTPUT
29 END
31 cat > Makefile.am << 'END'
32 AUTOMAKE_OPTIONS = subdir-objects foreign
33 noinst_PROGRAMS =
34 noinst_LIBRARIES =
36 # CLASHING PROGRAMS
37 noinst_PROGRAMS += foo src/foo
38 foo_SOURCES = src/foo.c src/main.c
39 foo_CPPFLAGS = -DVAL=0
40 src_foo_CPPFLAGS = -DVAL=1
41 src_foo_SOURCES = src/foo.c src/main.c
43 # CLASHING LIBS
44 noinst_PROGRAMS += bar src/bar
45 noinst_LIBRARIES += libbar.a src/libbar.a
46 bar_SOURCES = src/main.c
47 bar_LDADD = libbar.a
48 src_bar_SOURCES = src/main.c
49 src_bar_LDADD = src/libbar.a
50 libbar_a_SOURCES = src/foo.c
51 libbar_a_CPPFLAGS = -DVAL=0
52 src_libbar_a_SOURCES = src/foo.c
53 src_libbar_a_CPPFLAGS = -DVAL=1
55 # CLASHING PROGRAM + LIB
56 noinst_PROGRAMS += libzap_a src/zap
57 noinst_LIBRARIES += src/libzap.a
58 libzap_a_SOURCES = src/main.c src/foo.c
59 libzap_a_CPPFLAGS = -DVAL=2
60 src_zap_SOURCES = src/main.c
61 src_zap_LDADD = src/libzap.a
62 src_libzap_a_SOURCES = src/foo.c
63 src_libzap_a_CPPFLAGS = -DVAL=3
65 # NON-CLASHING
66 noinst_PROGRAMS += src/foo-uniq
67 src_foo_uniq_SOURCES = src/main.c src/foo.c
68 src_foo_uniq_CPPFLAGS = -DVAL=4
69 END
71 cat > src/foo.c << 'END'
72 int
73 foo ()
75 return VAL;
77 END
79 cat > src/main.c << 'END'
80 int foo (void);
82 int
83 main ()
85 return foo ();
87 END
89 $ACLOCAL
90 $AUTOCONF
91 $AUTOMAKE --add-missing
93 ./configure
94 $MAKE
95 set +e
96 ./foo || fail_ "./foo should return 0"
97 ./src/foo; test $? = 1 || fail_ "./src/foo should return 1"
98 ./bar || fail_ "./bar should return 0"
99 ./src/bar; test $? = 1 || fail_ "./src/bar should return 1"
100 ./libzap_a; test $? = 2 || fail_ "./libfoo_a should return 2"
101 ./src/zap; test $? = 3 || fail_ "./src/prog_libfoo should return 3"
102 ./src/foo-uniq; test $? = 4 || fail_ "./foo_uniq should return 4"
103 set -e
104 $MAKE clean