packaging: Bump to 1.14.1
[platform/upstream/automake.git] / t / cond39.sh
1 #!/bin/sh
2 # Copyright (C) 2008-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 # Build either as CONFIG_FILE or as PROGRAM.
18
19 required=cc
20 . test-init.sh
21
22 mkdir sub
23
24 cat >>configure.ac <<'END'
25 AC_PROG_CC
26 AM_CONDITIONAL([COND], [test "$COND" = true])
27 AM_COND_IF([COND], [],
28            [AC_CONFIG_FILES([prog1], [chmod 755 prog1])
29             AC_CONFIG_FILES([sub/prog2], [chmod 755 sub/prog2])])
30 AC_CONFIG_FILES([sub/Makefile])
31 AC_OUTPUT
32 END
33
34 cat >Makefile.am <<'END'
35 SUBDIRS = sub
36 if COND
37 bin_PROGRAMS = prog1
38 prog1_SOURCES = prog.c
39 else
40 bin_SCRIPTS = prog1
41 CLEANFILES = prog1
42 endif
43
44 sure-exist:
45         test -f prog1 || test -f prog1$(EXEEXT)
46         test -f sub/prog2 || test -f sub/prog2$(EXEEXT)
47
48 sure-not-exist:
49         test ! -f prog1 && test ! -f prog1$(EXEEXT)
50         test ! -f sub/prog2 && test ! -f sub/prog2$(EXEEXT)
51 END
52
53 cat >sub/Makefile.am <<'END'
54 if COND
55 bin_PROGRAMS = prog2
56 prog2_SOURCES = prog.c
57 else
58 bin_SCRIPTS = prog2
59 CLEANFILES = prog2
60 endif
61 END
62
63 cat >prog.c <<'END'
64 int main () { return 42; }
65 END
66
67 cat >prog1.in <<'END'
68 #! /bin/sh
69 bindir='@bindir@'
70 echo "hi, this is $0, and bindir is $bindir"
71 END
72
73 cp prog.c sub
74 cp prog1.in sub/prog2.in
75
76 $ACLOCAL
77 $AUTOCONF
78 $AUTOMAKE --add-missing
79
80 ./configure COND=true
81 run_make -E
82 grep 'overriding commands' stderr && exit 1
83 $MAKE sure-exist
84 ./prog1 && exit 1
85 ./sub/prog2 && exit 1
86 $MAKE clean
87 $MAKE sure-not-exist
88 $MAKE
89 $MAKE sure-exist
90 ./prog1 && exit 1
91 ./sub/prog2 && exit 1
92 $MAKE distclean
93
94 ./configure COND=false
95 run_make -E
96 grep 'overriding commands' stderr && exit 1
97 ./prog1
98 ./sub/prog2
99 $MAKE clean
100 $MAKE sure-not-exist
101 $MAKE
102 ./prog1
103 ./sub/prog2
104
105 :