129df49e63ae81313c23f4f3e2ea9756f8aeff27
[debian/amanda] / config / automake / scripts.am
1 # vim:ft=automake
2 # Copyright (c) 2005 Zmanda, Inc.  All Rights Reserved.
3
4 # This library is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU Lesser General Public License version 2.1 as 
6 # published by the Free Software Foundation.
7
8 # This library is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
11 # License for more details.
12
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this library; if not, write to the Free Software Foundation,
15 # Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA.
16
17 # Contact information: Zmanda Inc., 505 N Mathlida Ave, Suite 120
18 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19
20 # SYNOPSIS:
21 #
22 # Automake magic to handle the various tasks of building scripts.  Scripts can
23 # be built down to extensionless executables (e.g., foo.pl -> foo), or to 
24 # files with the usual extension (foo-lib.sh.in -> foo.sh).
25 #
26 # Files which support it are syntax-checked when the user invokes 'make check'.
27 #
28 # All *target* filenames must be listed in SCRIPTS_SHELL, SCRIPTS_PERL, and 
29 # SCRIPTS_AWK to support 'make check', 'make dist', and 'make distclean'.
30 #
31 # USAGE:
32 #
33 #   include $(top_srcdir)/config/automake/vars.am
34 #   include $(top_srcdir)/config/automake/scripts.am
35 #   ...
36 #   SCRIPTS_PERL = fooscript barscript perl-lib.pl perlmod.pm
37 #   SCRIPTS_SHELL = shell1 shell2 sh-lib.sh
38 #   SCRIPTS_AWK = talk balk chalk awk-lib.awk
39 #
40 # with the corresponding files in the repository:
41 #
42 #   fooscript.pl barscript.pl perl-lib.pl.in perlmod.pm.in
43 #   shell1.sh shell2.sh sh-lib.sh.in
44 #   talk.awk balk.awk chalk.awk awk-lib.awk.in
45 #
46 # by default, all shell and perl scripts are syntax checked.  If this is
47 # a problem (for example, perl scripts depending on Amanda extension 
48 # modules), then assign to CHECK_{PERL,SHELL} the list of files you wish
49 # to be checked (which can be empty).
50 #
51 # To add extra flags to the perl checks (e.g., to add new -I flags), set
52 # CHECK_PERL_FLAGS.
53
54 # Implementation note:
55 #
56 # This file uses config.status to substitute @foo@ in those scripts while
57 # converting them. It also adds the executable bits (a+x) to extensionless
58 # files.  The substitution works even though the files are not listed in 
59 # configure.in
60
61 # Perl
62 %: %.pl $(top_builddir)/config.status
63         $(top_builddir)/config.status --file=$@:$<
64         chmod a+x $@
65
66 %.pl: %.pl.in $(top_builddir)/config.status
67         $(top_builddir)/config.status --file=$@:$<
68
69 %.pm: %.pm.in $(top_builddir)/config.status
70         $(top_builddir)/config.status --file=$@:$<
71
72 # Shell
73 %: %.sh $(top_builddir)/config.status
74         $(top_builddir)/config.status --file=$@:$<
75         chmod a+x $@
76
77 %.sh: %.sh.in $(top_builddir)/config.status
78         $(top_builddir)/config.status --file=$@:$<
79
80 # Awk
81 %: %.awk $(top_builddir)/config.status
82         $(top_builddir)/config.status --file=$@:$<
83         chmod a+x $@
84
85 %.awk: %.awk.in $(top_builddir)/config.status
86         $(top_builddir)/config.status --file=$@:$<
87
88 # config.status leaves config.log files around
89 CLEANFILES += config.log
90
91 # and we'll need to clean up our generated files for distclean
92 DISTCLEANFILES += $(SCRIPTS_SHELL) $(SCRIPTS_PERL) $(SCRIPTS_AWK)
93
94 # syntax-check perl scripts on 'make check'
95 check-perl: $(CHECK_PERL)
96         @CHECK_PERL="$(CHECK_PERL)"; \
97         if test -n "$(PERL)"; then \
98                 for perlobj in $$CHECK_PERL; do \
99                         $(PERL) $(CHECK_PERL_FLAGS) -c -w -T $$perlobj || exit 1; \
100                 done; \
101         fi
102 check-local: check-perl
103
104 # syntax-check shell scripts on 'make check'
105 CHECK_SHELL = $(SCRIPTS_SHELL)
106 check-shell: $(CHECK_SHELL)
107         @CHECK_SHELL="$(CHECK_SHELL)"; \
108         if test -n "$$CHECK_SHELL"; then \
109                 if test -n "$(BASH)"; then \
110                         for shobj in $$CHECK_SHELL; do \
111                                 if $(BASH) -n $$shobj; then \
112                                         echo "$$shobj syntax OK"; \
113                                 else \
114                                         echo "$$shobj syntax error"; \
115                                         exit 1; \
116                                 fi; \
117                         done; \
118                 else \
119                         echo "No 'bash' available -- cannot syntax-check shell scripts"; \
120                 fi; \
121         fi
122 check-local: check-shell
123
124 # make sure that the sources for all shell and perl scripts get included
125 # in the distribution
126 dist-scripts:
127         SCRIPTS_PERL="$(SCRIPTS_PERL)"; SCRIPTS_SHELL="$(SCRIPTS_SHELL)"; SCRIPTS_AWK="$(SCRIPTS_AWK)"; \
128         for script in $$SCRIPTS_PERL; do \
129                 test -f $(srcdir)/$${script}.pl && { cp -p $(srcdir)/$${script}.pl $(distdir)/ || exit 1; } \
130         done; \
131         for script in $$SCRIPTS_SHELL; do \
132                 test -f $(srcdir)/$${script}.sh && { cp -p $(srcdir)/$${script}.sh $(distdir)/ || exit 1; } \
133         done; \
134         for script in $$SCRIPTS_AWK; do \
135                 test -f $(srcdir)/$${script}.awk && { cp -p $(srcdir)/$${script}.awk $(distdir)/ || exit 1; } \
136         done; \
137         for script in $$SCRIPTS_SHELL $$SCRIPTS_PERL $$SCRIPTS_AWK; do \
138                 test -f $(srcdir)/$${script}.in && { cp -p $(srcdir)/$${script}.in $(distdir)/ || exit 1; } \
139         done; \
140         true
141 dist-hook: dist-scripts