cb6d705b1df8cb11c1e72bcf137aaec478ad0c29
[debian/amanda] / config / automake / scripts.am
1 # vim:ft=automake
2 # Copyright (c) 2005-2008 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., 465 S Mathlida Ave, Suite 300
18 # Sunnyvale, CA 94086, 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'. No
30 # files which are not substituted by config.status should be included in
31 # SCRIPTS_PERL, SCRIPTS_SHELL, or SCRIPTS_AWK.  If non-generated files are listed
32 # for installation, then Automake will figure out that they should be distributed;
33 # otherwise, include them in EXTRA_DIST.
34 #
35 # USAGE:
36 #
37 #   include $(top_srcdir)/config/automake/vars.am
38 #   include $(top_srcdir)/config/automake/scripts.am
39 #   ...
40 #   SCRIPTS_PERL = fooscript barscript perl-lib.pl perlmod.pm
41 #   SCRIPTS_SHELL = shell1 shell2 sh-lib.sh
42 #   SCRIPTS_AWK = talk balk chalk awk-lib.awk
43 #   sbin_SCRIPTS = not-subbed
44 #   EXTRA_DIST = util-script.pl
45 #
46 # with the corresponding files in the repository:
47 #
48 #   fooscript.pl barscript.pl perl-lib.pl.in perlmod.pm.in
49 #   shell1.sh shell2.sh sh-lib.sh.in
50 #   talk.awk balk.awk chalk.awk awk-lib.awk.in
51 #   not-subbed util-script.pl
52 #
53 # by default, all shell and perl scripts are syntax checked.  If this is
54 # a problem (for example, perl scripts depending on Amanda extension 
55 # modules), then assign to CHECK_{PERL,SHELL} the list of files you wish
56 # to be checked (which can be empty).
57 #
58 # To add extra flags to the perl checks (e.g., to add new -I flags), set
59 # CHECK_PERL_FLAGS.
60
61 # Implementation note:
62 #
63 # This file uses config.status to substitute @foo@ in those scripts while
64 # converting them. It also adds the executable bits (a+x) to extensionless
65 # files.  The substitution works even though the files are not listed in 
66 # configure.in
67
68 # Perl
69 %: %.pl $(top_builddir)/config.status
70         $(top_builddir)/config.status --file=$@:$<
71         chmod a+x $@
72         @if test -f $(top_builddir)/perl/.libs/libCmdline.so -o -f $(top_builddir)/perl/libCmdline.so; then \
73                 grep -v '^use lib' $@ > $@.nouselib; \
74                 $(PERL) $(CHECK_PERL_FLAGS) -I$(top_builddir)/perl -I$(top_builddir)/perl/.libs -I$(top_srcdir)/perl -c -w -T $@.nouselib || exit 1; \
75                 rm $@.nouselib; \
76         fi
77
78 %.pl: %.pl.in $(top_builddir)/config.status
79         $(top_builddir)/config.status --file=$@:$<
80
81 %.pm: %.pm.in $(top_builddir)/config.status
82         $(top_builddir)/config.status --file=$@:$<
83
84 # Shell
85 %: %.sh $(top_builddir)/config.status
86         $(top_builddir)/config.status --file=$@:$<
87         chmod a+x $@
88
89 %.sh: %.sh.in $(top_builddir)/config.status
90         $(top_builddir)/config.status --file=$@:$<
91
92 # Awk
93 %: %.awk $(top_builddir)/config.status
94         $(top_builddir)/config.status --file=$@:$<
95         chmod a+x $@
96
97 %.awk: %.awk.in $(top_builddir)/config.status
98         $(top_builddir)/config.status --file=$@:$<
99
100 # config.status leaves config.log files around
101 CLEANFILES += config.log
102
103 # and we'll need to clean up our generated files for distclean
104 DISTCLEANFILES += $(SCRIPTS_SHELL) $(SCRIPTS_PERL) $(SCRIPTS_AWK) $(SCRIPTS_INCLUDE)
105
106 # syntax-check perl scripts on 'make check'
107 check-perl: $(CHECK_PERL)
108         @CHECK_PERL="$(CHECK_PERL)"; \
109         if test -f $(top_builddir)/perl/.libs/libCmdline.so -o -f $(top_builddir)/perl/libCmdline.so; then \
110                 if test -n "$(PERL)"; then \
111                         for perlobj in $$CHECK_PERL; do \
112                                 grep -v '^use lib' $$perlobj > $$perlobj.nouselib; \
113                                 $(PERL) $(CHECK_PERL_FLAGS) -I$(top_builddir)/perl -I$(top_builddir)/perl/.libs -I$(top_srcdir)/perl -c -w -T $$perlobj.nouselib || exit 1; \
114                                 rm $$perlobj.nouselib; \
115                         done; \
116                 fi \
117         fi
118 check-local: check-perl
119
120 # syntax-check perl scripts on 'make installcheck'
121 installcheck-perl: $(CHECK_PERL)
122         @CHECK_PERL="$(CHECK_PERL)"; \
123         if test -n "$(PERL)"; then \
124                 for perlobj in $$CHECK_PERL; do \
125                         $(PERL) $(CHECK_PERL_FLAGS) -c -w -T $$perlobj || exit 1; \
126                 done; \
127         fi
128 installcheck-local: installcheck-perl
129
130 # syntax-check shell scripts on 'make check'
131 CHECK_SHELL = $(SCRIPTS_SHELL)
132 check-shell: $(CHECK_SHELL)
133         @CHECK_SHELL="$(CHECK_SHELL)"; \
134         if test -n "$$CHECK_SHELL"; then \
135                 if test -n "$(BASH)"; then \
136                         for shobj in $$CHECK_SHELL; do \
137                                 if $(BASH) -n $$shobj; then \
138                                         echo "$$shobj syntax OK"; \
139                                 else \
140                                         echo "$$shobj syntax error"; \
141                                         exit 1; \
142                                 fi; \
143                         done; \
144                 else \
145                         echo "No 'bash' available -- cannot syntax-check shell scripts"; \
146                 fi; \
147         fi
148 check-local: check-shell
149
150 # make sure that the sources for all shell and perl scripts get included
151 # in the distribution
152 dist-scripts:
153         SCRIPTS_PERL="$(SCRIPTS_PERL)"; SCRIPTS_SHELL="$(SCRIPTS_SHELL)"; SCRIPTS_AWK="$(SCRIPTS_AWK)"; \
154         for script in $$SCRIPTS_PERL; do \
155                 test -f $(srcdir)/$${script}.pl && { cp -p $(srcdir)/$${script}.pl $(distdir)/ || exit 1; } \
156         done; \
157         for script in $$SCRIPTS_SHELL; do \
158                 test -f $(srcdir)/$${script}.sh && { cp -p $(srcdir)/$${script}.sh $(distdir)/ || exit 1; } \
159         done; \
160         for script in $$SCRIPTS_AWK; do \
161                 test -f $(srcdir)/$${script}.awk && { cp -p $(srcdir)/$${script}.awk $(distdir)/ || exit 1; } \
162         done; \
163         for script in $$SCRIPTS_SHELL $$SCRIPTS_PERL $$SCRIPTS_AWK; do \
164                 test -f $(srcdir)/$${script}.in && { cp -p $(srcdir)/$${script}.in $(distdir)/ || exit 1; } \
165         done; \
166         true
167 dist-hook: dist-scripts