Imported Upstream version 3.2.0
[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 SYNTAX_CHECKS
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         else \
82                 echo "skipping syntax check of $@ because perl packages are not compiled yet"; \
83         fi
84 endif
85
86 %.pl: %.pl.in $(top_builddir)/config.status
87         $(top_builddir)/config.status --file=$@:$<
88
89 %.pm: %.pm.in $(top_builddir)/config.status
90         $(top_builddir)/config.status --file=$@:$<
91
92 # Shell
93 %: %.sh $(top_builddir)/config.status
94         $(top_builddir)/config.status --file=$@:$<
95         chmod a+x $@
96
97 %.sh: %.sh.in $(top_builddir)/config.status
98         $(top_builddir)/config.status --file=$@:$<
99
100 # Awk
101 %: %.awk $(top_builddir)/config.status
102         $(top_builddir)/config.status --file=$@:$<
103         chmod a+x $@
104
105 %.awk: %.awk.in $(top_builddir)/config.status
106         $(top_builddir)/config.status --file=$@:$<
107
108 # config.status leaves config.log files around
109 CLEANFILES += config.log
110
111 # and we'll need to clean up our generated files for distclean
112 DISTCLEANFILES += $(SCRIPTS_SHELL) $(SCRIPTS_PERL) $(SCRIPTS_AWK) $(SCRIPTS_INCLUDE)
113
114 # syntax-check perl scripts on an explicit 'make check', but only if
115 # SYNTAX_CHECKS are enabled, as this is sensitive to the presence of perl
116 # modules in the install tree, and can trip up unsuspecting users.
117 check-perl: $(SCRIPTS_PERL)
118         @SCRIPTS_PERL="$(SCRIPTS_PERL)"; \
119         if test x"$(SKIP_CHECKS)" = x"" && \
120             test -f $(top_builddir)/perl/.libs/libCmdline.so -o -f $(top_builddir)/perl/libCmdline.so; then \
121             for perlobj in $$SCRIPTS_PERL; do \
122                 sed "s,^use lib ['\"]$(amperldir)['\"],# use lib '$(amperldir)' # nouselib," < $$perlobj > $$perlobj.nouselib; \
123                 $(PERL) $(CHECK_PERL_FLAGS) -I$(top_builddir)/perl -I$(top_builddir)/perl/.libs -I$(top_srcdir)/perl -c -w $$perlobj.nouselib || exit 1; \
124                 rm $$perlobj.nouselib; \
125             done; \
126         fi
127 if SYNTAX_CHECKS
128 check-local: check-perl
129 endif
130
131 # syntax-check shell scripts on an explicit 'make check'
132 check-shell: $(SCRIPTS_SHELL)
133         @SCRIPTS_SHELL="$(SCRIPTS_SHELL)"; \
134         if test x"$(SKIP_CHECKS)" = x"" && \
135             test -n "$$SCRIPTS_SHELL"; then \
136                 if test -n "$(BASH)"; then \
137                         for shobj in $$SCRIPTS_SHELL; do \
138                                 if $(BASH) -n $$shobj; then \
139                                         echo "$$shobj syntax OK"; \
140                                 else \
141                                         echo "$$shobj syntax error"; \
142                                         exit 1; \
143                                 fi; \
144                         done; \
145                 else \
146                         echo "No 'bash' available -- cannot syntax-check shell scripts"; \
147                 fi; \
148         fi
149 if SYNTAX_CHECKS
150 check-local: check-shell
151 endif
152
153 # make sure that the sources for all shell and perl scripts get included
154 # in the distribution
155 dist-scripts:
156         @SCRIPTS_PERL="$(SCRIPTS_PERL) $(SCRIPTS_EXTRA_DIST)"; \
157         SCRIPTS_SHELL="$(SCRIPTS_SHELL) $(SCRIPTS_EXTRA_DIST)"; \
158         SCRIPTS_AWK="$(SCRIPTS_AWK) $(SCRIPTS_EXTRA_DIST)"; \
159         SCRIPTS_DIST=; \
160         for script in $$SCRIPTS_PERL; do \
161                 test -f $(srcdir)/$${script}.pl && \
162                         SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.pl"; \
163         done; \
164         for script in $$SCRIPTS_SHELL; do \
165                 test -f $(srcdir)/$${script}.sh && \
166                         SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.sh"; \
167         done; \
168         for script in $$SCRIPTS_AWK; do \
169                 test -f $(srcdir)/$${script}.awk && \
170                         SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.awk"; \
171         done; \
172         for script in $$SCRIPTS_SHELL $$SCRIPTS_PERL $$SCRIPTS_AWK; do \
173                 test -f $(srcdir)/$${script}.in && \
174                         SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.in"; \
175         done; \
176         for script in $$SCRIPTS_DIST; do \
177                 dir=`dirname $${script}`; \
178                 if test -n "$$dir" && test ! -d "$(distdir)/$$dir"; then \
179                         mkdir -p "$(distdir)/$$dir" || exit 1; \
180                 fi; \
181                 test -f "$(distdir)/$${script}" && continue; \
182                 echo "distributing $${script}"; \
183                 cp -p "$(srcdir)/$${script}" "$(distdir)/$${script}" || exit 1; \
184         done; \
185         true
186 dist-hook: dist-scripts