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