64edbc67fab90328d1375be5fd7a22f2806754d4
[debian/amanda] / config / automake / scripts.am
1 # vim:ft=automake
2 # Copyright (c) 2007,2008,2009 Zmanda, Inc.  All Rights Reserved.
3 #
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
7 #
8 # This program 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 General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
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 # unless the Makefile.am defines SKIP_CHECKS.
28 #
29 # All *target* filenames must be listed in SCRIPTS_SHELL, SCRIPTS_PERL, and
30 # SCRIPTS_AWK to support 'make dist', and 'make distclean'. No files which are
31 # not substituted by config.status should be included in SCRIPTS_PERL,
32 # SCRIPTS_SHELL, or SCRIPTS_AWK.  If non-generated files are listed for
33 # installation, then Automake will figure out that they should be distributed;
34 # otherwise, include them in EXTRA_DIST.
35 #
36 # All SCRIPTS_SHELL and SCRIPTS_PERL are syntax-checked on 'make check'.  There is
37 # a fix in place to run these syntax checks against the perl modules in the build
38 # tree, rather than against the (potentially old) installed perl modules.
39 #
40 # To emulate EXTRA_DIST for scripts, use SCRIPTS_EXTRA_DIST, e.g.,
41 #   SCRIPTS_SHELL = $(selected_scripts)
42 #   SCRIPTS_EXTRA_DIST = $(all_scripts)
43 #
44 # USAGE:
45 #
46 #   include $(top_srcdir)/config/automake/vars.am
47 #   include $(top_srcdir)/config/automake/scripts.am
48 #   ...
49 #   SCRIPTS_PERL = fooscript barscript perl-lib.pl perlmod.pm
50 #   SCRIPTS_SHELL = shell1 shell2 sh-lib.sh
51 #   SCRIPTS_AWK = talk balk chalk awk-lib.awk
52 #   sbin_SCRIPTS = not-subbed
53 #   SCRIPTS_EXTRA_DIST = util-script
54 #
55 # with the corresponding files in the repository:
56 #
57 #   fooscript.pl barscript.pl perl-lib.pl.in perlmod.pm.in
58 #   shell1.sh shell2.sh sh-lib.sh.in
59 #   talk.awk balk.awk chalk.awk awk-lib.awk.in
60 #   not-subbed util-script.pl
61 #
62 # To add extra flags to the perl checks (e.g., to add new -I flags), set
63 # CHECK_PERL_FLAGS.
64
65 # Implementation note:
66 #
67 # This file uses config.status to substitute @foo@ in those scripts while
68 # converting them. It also adds the executable bits (a+x) to extensionless
69 # files.  The substitution works even though the files are not listed in 
70 # configure.in
71
72 # Perl
73 %: %.pl $(top_builddir)/config.status
74         $(top_builddir)/config.status --file=$@:$<
75         chmod a+x $@
76 if CHECK_SCRIPTS_AT_BUILD
77         @if test -f $(top_builddir)/perl/.libs/libCmdline.so -o -f $(top_builddir)/perl/libCmdline.so; then \
78                 sed "s,^use lib ['\"]$(amperldir)['\"],# use lib '$(amperldir)' # nouselib," < $@ > $@.nouselib; \
79                 $(PERL) $(CHECK_PERL_FLAGS) -I$(top_builddir)/perl -I$(top_builddir)/perl/.libs -I$(top_srcdir)/perl -c -w $@.nouselib || exit 1; \
80                 rm $@.nouselib; \
81         fi
82 endif
83
84 %.pl: %.pl.in $(top_builddir)/config.status
85         $(top_builddir)/config.status --file=$@:$<
86
87 %.pm: %.pm.in $(top_builddir)/config.status
88         $(top_builddir)/config.status --file=$@:$<
89
90 # Shell
91 %: %.sh $(top_builddir)/config.status
92         $(top_builddir)/config.status --file=$@:$<
93         chmod a+x $@
94
95 %.sh: %.sh.in $(top_builddir)/config.status
96         $(top_builddir)/config.status --file=$@:$<
97
98 # Awk
99 %: %.awk $(top_builddir)/config.status
100         $(top_builddir)/config.status --file=$@:$<
101         chmod a+x $@
102
103 %.awk: %.awk.in $(top_builddir)/config.status
104         $(top_builddir)/config.status --file=$@:$<
105
106 # config.status leaves config.log files around
107 CLEANFILES += config.log
108
109 # and we'll need to clean up our generated files for distclean
110 DISTCLEANFILES += $(SCRIPTS_SHELL) $(SCRIPTS_PERL) $(SCRIPTS_AWK) $(SCRIPTS_INCLUDE)
111
112 # syntax-check perl scripts on 'make check'
113 check-perl: $(SCRIPTS_PERL)
114         @SCRIPTS_PERL="$(SCRIPTS_PERL)"; \
115         if test x"$(SKIP_CHECKS)" = x"" && \
116             test -f $(top_builddir)/perl/.libs/libCmdline.so -o -f $(top_builddir)/perl/libCmdline.so; then \
117             if test -n "$(PERL)"; then \
118                     for perlobj in $$SCRIPTS_PERL; do \
119                             sed "s,^use lib ['\"]$(amperldir)['\"],# use lib '$(amperldir)' # nouselib," < $$perlobj > $$perlobj.nouselib; \
120                             $(PERL) $(CHECK_PERL_FLAGS) -I$(top_builddir)/perl -I$(top_builddir)/perl/.libs -I$(top_srcdir)/perl -c -w $$perlobj.nouselib || exit 1; \
121                             rm $$perlobj.nouselib; \
122                     done; \
123             fi \
124         fi
125 check-local: check-perl
126
127 # syntax-check perl scripts on 'make installcheck'
128 installcheck-perl: $(SCRIPTS_PERL)
129         @SCRIPTS_PERL="$(SCRIPTS_PERL)"; \
130         if test x"$(SKIP_CHECKS)" = x"" && \
131             test -n "$(PERL)"; then \
132                 for perlobj in $$SCRIPTS_PERL; do \
133                         $(PERL) $(CHECK_PERL_FLAGS) -c -w $$perlobj || exit 1; \
134                 done; \
135         fi
136 installcheck-local: installcheck-perl
137
138 # syntax-check shell scripts on 'make check'
139 check-shell: $(SCRIPTS_SHELL)
140         @SCRIPTS_SHELL="$(SCRIPTS_SHELL)"; \
141         if test x"$(SKIP_CHECKS)" = x"" && \
142             test -n "$$SCRIPTS_SHELL"; then \
143                 if test -n "$(BASH)"; then \
144                         for shobj in $$SCRIPTS_SHELL; do \
145                                 if $(BASH) -n $$shobj; then \
146                                         echo "$$shobj syntax OK"; \
147                                 else \
148                                         echo "$$shobj syntax error"; \
149                                         exit 1; \
150                                 fi; \
151                         done; \
152                 else \
153                         echo "No 'bash' available -- cannot syntax-check shell scripts"; \
154                 fi; \
155         fi
156 check-local: check-shell
157
158 # make sure that the sources for all shell and perl scripts get included
159 # in the distribution
160 dist-scripts:
161         @SCRIPTS_PERL="$(SCRIPTS_PERL) $(SCRIPTS_EXTRA_DIST)"; \
162         SCRIPTS_SHELL="$(SCRIPTS_SHELL) $(SCRIPTS_EXTRA_DIST)"; \
163         SCRIPTS_AWK="$(SCRIPTS_AWK) $(SCRIPTS_EXTRA_DIST)"; \
164         SCRIPTS_DIST=; \
165         for script in $$SCRIPTS_PERL; do \
166                 test -f $(srcdir)/$${script}.pl && \
167                         SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.pl"; \
168         done; \
169         for script in $$SCRIPTS_SHELL; do \
170                 test -f $(srcdir)/$${script}.sh && \
171                         SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.sh"; \
172         done; \
173         for script in $$SCRIPTS_AWK; do \
174                 test -f $(srcdir)/$${script}.awk && \
175                         SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.awk"; \
176         done; \
177         for script in $$SCRIPTS_SHELL $$SCRIPTS_PERL $$SCRIPTS_AWK; do \
178                 test -f $(srcdir)/$${script}.in && \
179                         SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.in"; \
180         done; \
181         for script in $$SCRIPTS_DIST; do \
182                 dir=`dirname $${script}`; \
183                 if test -n "$$dir" && test ! -d "$(distdir)/$$dir"; then \
184                         mkdir -p "$(distdir)/$$dir" || exit 1; \
185                 fi; \
186                 test -f "$(distdir)/$${script}" && continue; \
187                 echo "distributing $${script}"; \
188                 cp -p "$(srcdir)/$${script}" "$(distdir)/$${script}" || exit 1; \
189         done; \
190         true
191 dist-hook: dist-scripts