2 # Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
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.
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
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
18 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
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).
27 # Files which support it are syntax-checked when the user invokes 'make check',
28 # unless the Makefile.am defines SKIP_CHECKS.
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.
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.
41 # To emulate EXTRA_DIST for scripts, use SCRIPTS_EXTRA_DIST, e.g.,
42 # SCRIPTS_SHELL = $(selected_scripts)
43 # SCRIPTS_EXTRA_DIST = $(all_scripts)
47 # include $(top_srcdir)/config/automake/vars.am
48 # include $(top_srcdir)/config/automake/scripts.am
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
56 # with the corresponding files in the repository:
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
63 # To add extra flags to the perl checks (e.g., to add new -I flags), set
66 # Implementation note:
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
74 %: %.pl $(top_builddir)/config.status
75 $(top_builddir)/config.status --file=$@:$<
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; \
83 echo "skipping syntax check of $@ because perl packages are not compiled yet"; \
87 %.pl: %.pl.in $(top_builddir)/config.status
88 $(top_builddir)/config.status --file=$@:$<
90 %.pm: %.pm.in $(top_builddir)/config.status
91 $(top_builddir)/config.status --file=$@:$<
94 %: %.sh $(top_builddir)/config.status
95 $(top_builddir)/config.status --file=$@:$<
98 %.sh: %.sh.in $(top_builddir)/config.status
99 $(top_builddir)/config.status --file=$@:$<
102 %: %.awk $(top_builddir)/config.status
103 $(top_builddir)/config.status --file=$@:$<
106 %.awk: %.awk.in $(top_builddir)/config.status
107 $(top_builddir)/config.status --file=$@:$<
109 # config.status leaves config.log files around
110 CLEANFILES += config.log
112 # and we'll need to clean up our generated files for distclean
113 DISTCLEANFILES += $(SCRIPTS_SHELL) $(SCRIPTS_PERL) $(SCRIPTS_AWK) $(SCRIPTS_INCLUDE)
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; \
129 check-local: check-perl
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"; \
142 echo "$$shobj syntax error"; \
147 echo "No 'bash' available -- cannot syntax-check shell scripts"; \
151 check-local: check-shell
154 # make sure that the sources for all shell and perl scripts get included
155 # in the distribution
157 @SCRIPTS_PERL="$(SCRIPTS_PERL) $(SCRIPTS_EXTRA_DIST)"; \
158 SCRIPTS_SHELL="$(SCRIPTS_SHELL) $(SCRIPTS_EXTRA_DIST)"; \
159 SCRIPTS_AWK="$(SCRIPTS_AWK) $(SCRIPTS_EXTRA_DIST)"; \
161 for script in $$SCRIPTS_PERL; do \
162 test -f $(srcdir)/$${script}.pl && \
163 SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.pl"; \
165 for script in $$SCRIPTS_SHELL; do \
166 test -f $(srcdir)/$${script}.sh && \
167 SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.sh"; \
169 for script in $$SCRIPTS_AWK; do \
170 test -f $(srcdir)/$${script}.awk && \
171 SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.awk"; \
173 for script in $$SCRIPTS_SHELL $$SCRIPTS_PERL $$SCRIPTS_AWK; do \
174 test -f $(srcdir)/$${script}.in && \
175 SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.in"; \
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; \
182 test -f "$(distdir)/$${script}" && continue; \
183 echo "distributing $${script}"; \
184 cp -p "$(srcdir)/$${script}" "$(distdir)/$${script}" || exit 1; \
187 dist-hook: dist-scripts