2 # Copyright (c) 2007,2008,2009 Zmanda, Inc. All Rights Reserved.
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.
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
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
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
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).
26 # Files which support it are syntax-checked when the user invokes 'make check',
27 # unless the Makefile.am defines SKIP_CHECKS.
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.
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.
40 # To emulate EXTRA_DIST for scripts, use SCRIPTS_EXTRA_DIST, e.g.,
41 # SCRIPTS_SHELL = $(selected_scripts)
42 # SCRIPTS_EXTRA_DIST = $(all_scripts)
46 # include $(top_srcdir)/config/automake/vars.am
47 # include $(top_srcdir)/config/automake/scripts.am
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
55 # with the corresponding files in the repository:
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
62 # To add extra flags to the perl checks (e.g., to add new -I flags), set
65 # Implementation note:
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
73 %: %.pl $(top_builddir)/config.status
74 $(top_builddir)/config.status --file=$@:$<
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; \
82 echo "skipping syntax check of $@ because perl packages are not compiled yet"; \
86 %.pl: %.pl.in $(top_builddir)/config.status
87 $(top_builddir)/config.status --file=$@:$<
89 %.pm: %.pm.in $(top_builddir)/config.status
90 $(top_builddir)/config.status --file=$@:$<
93 %: %.sh $(top_builddir)/config.status
94 $(top_builddir)/config.status --file=$@:$<
97 %.sh: %.sh.in $(top_builddir)/config.status
98 $(top_builddir)/config.status --file=$@:$<
101 %: %.awk $(top_builddir)/config.status
102 $(top_builddir)/config.status --file=$@:$<
105 %.awk: %.awk.in $(top_builddir)/config.status
106 $(top_builddir)/config.status --file=$@:$<
108 # config.status leaves config.log files around
109 CLEANFILES += config.log
111 # and we'll need to clean up our generated files for distclean
112 DISTCLEANFILES += $(SCRIPTS_SHELL) $(SCRIPTS_PERL) $(SCRIPTS_AWK) $(SCRIPTS_INCLUDE)
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; \
128 check-local: check-perl
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"; \
141 echo "$$shobj syntax error"; \
146 echo "No 'bash' available -- cannot syntax-check shell scripts"; \
150 check-local: check-shell
153 # make sure that the sources for all shell and perl scripts get included
154 # in the distribution
156 @SCRIPTS_PERL="$(SCRIPTS_PERL) $(SCRIPTS_EXTRA_DIST)"; \
157 SCRIPTS_SHELL="$(SCRIPTS_SHELL) $(SCRIPTS_EXTRA_DIST)"; \
158 SCRIPTS_AWK="$(SCRIPTS_AWK) $(SCRIPTS_EXTRA_DIST)"; \
160 for script in $$SCRIPTS_PERL; do \
161 test -f $(srcdir)/$${script}.pl && \
162 SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.pl"; \
164 for script in $$SCRIPTS_SHELL; do \
165 test -f $(srcdir)/$${script}.sh && \
166 SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.sh"; \
168 for script in $$SCRIPTS_AWK; do \
169 test -f $(srcdir)/$${script}.awk && \
170 SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.awk"; \
172 for script in $$SCRIPTS_SHELL $$SCRIPTS_PERL $$SCRIPTS_AWK; do \
173 test -f $(srcdir)/$${script}.in && \
174 SCRIPTS_DIST="$$SCRIPTS_DIST $${script}.in"; \
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; \
181 test -f "$(distdir)/$${script}" && continue; \
182 echo "distributing $${script}"; \
183 cp -p "$(srcdir)/$${script}" "$(distdir)/$${script}" || exit 1; \
186 dist-hook: dist-scripts