#################### LISTING ONE #################### #!/usr/bin/perl -w use strict; $|++; use Template; use Getopt::Long; GetOptions( 'preprocess' => \ (my $preprocess), 'force!' => \ (my $force = 0), ) or die "see code for usage\n"; my $t = Template->new ({ RELATIVE => 1, PRE_PROCESS => $preprocess, INCLUDE_PATH => ['.'], TAG_STYLE => 'star', }); my %seen; while (<>) { next if $seen{$_}++; my($outname, $inname) = split; my @instat = stat($inname) or print(" - $inname (can't stat)\n"), next; unless ($force) { my @outstat = stat($outname); @outstat and $outstat[9] > $instat[9] and print(" - $inname (not newer)\n"), next; } $t->process($inname, {env => \%ENV}, $outname) or print(" ! ", $t->error(), "\n"), next; print(" + $inname => $outname\n"); chown $instat[4], $instat[5], $outname or warn "Cannot chown @instat[4,5] $outname: $!"; chmod $instat[2], $outname or warn "Cannot chmod $instat[2] $outname: $!"; } #################### LISTING TWO #################### ### mandatory SHELL = /bin/sh .SUFFIXES: ### ensure FINAL ifndef RECURSED MAKECMDGOALS ?= install $(MAKECMDGOALS): @$(MAKE) --no-print-directory RECURSED=1 $(MAKECMDGOALS) FINAL else # endif is at end of file ### external configuration variables (from env or make-line) export PREFIX ?= /web/stonehenge export INSTALLPREFIX ?= $(PREFIX) export APACHE_PREFIX ?= /opt/apache/1.3.23 export SERVERNAME ?= www.stonehenge.com export LISTEN_AT ?= www.stonehenge.com:80 ### internal variables (should require no change) I = $(INSTALLPREFIX) TEMPLATER = ./run-template ### macros get_installs_from_subdir = $(patsubst %,$I/%,$(patsubst %.tmpl,%,$(shell find $1 -type f ! -name '*~' -print))) ### subdirectories ## etc install: install-etc install_etc_files := $(call get_installs_from_subdir, etc) install-etc: $(install_etc_files) ## htdocs install: install-htdocs install_htdocs_files := $(call get_installs_from_subdir, htdocs) install-htdocs: $(install_htdocs_files) ## sbin install: install-sbin install_sbin_files := $(call get_installs_from_subdir, sbin) install-sbin: $(install_sbin_files) ## var install: install-var install_var_files := $(call get_installs_from_subdir, var) install-var: $(install_var_files) ### pattern rules $I/%: % mkdir -p $(dir $@) cp $< $@ $I/%: %.tmpl $(TEMPLATER) GNUmakefile @echo want: $< '=>' $@ @echo $@ $< >>$(TEMPLATER).in ### handle FINAL step FINAL: $(TEMPLATER).out $(TEMPLATER).out: $(TEMPLATER).in $(TEMPLATER) --force $< -@cp /dev/null $< -@touch $@ $(TEMPLATER).in:; touch $@ endif # matches ifdef/else at top of file