### webdir.make -- makefile template for website directories # $Id: webdir.make,v 1.1 2007-12-01 23:53:12 steve Exp $ # COPYRIGHT 1998, HyperSpace Express ######################################################################## # # This makefile contains rules for making subdirectories in websites, # and for transferring files to a remote website. SRCDIR contains the # relative path to the top directory to be transferred, and DOTDOT is # relative to SRCDIR. Replaces subdir.make in this case. # # === SRCDIR is really a local proxy for DOCUMENT_ROOT # === don't need TOPDIR; MF_DIR can be relative to SRCDIR # ######################################################################## ### Usage: # TOPDIR=../../... # parent of Config/makefiles # SRCDIR=../... # top directory to be uploaded # DOTDOT= # MYNAME= # MF_DIR=$(TOPDIR)/Config/makefiles # include $(MF_DIR)/file.make # (up to this point it's standard boilerplate) # include $(MF_DIR)/webdir.make ### ### WURM.cf: Web Upload Recursive Makefile configuration file: # Must define HOST and DSTDIR, at least. # HOST may take the form username@host; it's used by ssh/rsh/etc # include $(SRCDIR)/WURM.cf $(SRCDIR)/WURM.cf: @echo 'WURM.cf in $$(SRCDIR) ($(SRCDIR)) needs to define:' @echo ' HOST=' @echo ' DSTDIR=' ### Note that a directory may contain a WURMfile, which is used instead # of the Makefile for "make put" and possibly other web-specific # targets. This allows an imported subtree to retain its original # Makefile. # === need to hack setup and put to pass down additional info. # === MYPATH should start at .=SRCDIR; ftp should cd to $(DSTDIR)/$(MYPATH) === ifeq ($(strip $(MYPATH)),) MYPATH=$(DOTDOT)/$(MYNAME) endif DSTPATH=$(DSTDIR)/$(DOTDOT)/$(MYNAME) ### Commands: PROCESS = process ### Rules: # # Can make .html files from corresponding .xh files. # Use XH_HTML to specify them all. # ifndef TAGSET TAGSET=xhtml endif .SUFFIXES: .html .xh .xh.html: $(PROCESS) -t $(TAGSET) $< > $@ { grep -s $@ .cvsignore ; } || echo $@ >> .cvsignore XH_FILES= $(wildcard *.xh) XH_HTML= $(XH_FILES:.xh=.html) ### Targets: # ls get a listing (ls -CF) of the remote directory # ls-r # put.log transfer modified files in this directory to the website. # put recursive transfer # all build executables, etc. # doc build documentation # clean remove trash # setup initialize Makefile and other essential files ### # Note: we're not propagating HOSTS, DSTDIR, command names, # or anything else that we can get from $SRCDIR/WURM.cf # Note: the upload code now *requires* rsync and ssh. There is no good way # to parametrize the way we perform operations on the remote site. For # a taste of what we'd be up against, see the "ftput" target, below. ls: @echo '# ls $(HOST):$(DSTPATH)' @ssh $(HOST) ls -CF $(DSTPATH) ls-l: @echo '# ls -l $(HOST):$(DSTPATH)' @ssh $(HOST) ls -l $(DSTPATH) # mkdir.log: First see if we need to make the remote directory. mkdir.log: @echo making remote directory -ssh $(HOST) mkdir $(DSTPATH) echo `date` mkdir $(DSTPATH) > mkdir.log put:: mkdir.log # put.log: This is the one that does most of the work. # Note that as a side effect we make put.bak, which is the list # of the most recent files so we can retry the command if it fails. put.log:: $(FILES) $(IMAGES) rsync -a -u -v -e ssh $? $(HOST):$(DSTPATH)/ echo `date`: $? >> put.log echo $? > put.bak # put uses the -u flag to rsync to keep from clobbering remote files # that have been changed on the server. # put: put:: put.log retry: scp `cat put.bak` $(HOST):$(DSTPATH) # === obsolete FTP put. ftput:: $(FILES) $(IMAGES) @echo cd $(DOTDOT) > put @[ "$(MYNAME)x" = "x" ] || echo mkdir $(MYNAME) >> put @[ "$(MYNAME)x" = "x" ] || echo cd $(MYNAME) >> put @echo binary >> put for f in $? ; do echo put $$f >> put ; done @echo bye >> put [ "$(HOST)x" = "x" ] || $(FTP) $(HOST) < put > put.log ftpretry: $(FTP) $(HOST) < put fake: echo faked >> put.log fake-r: echo faked >> put.log @@for p in $(SUBDIRS) xxx; do ( if test -f $$p/Makefile; \ then cd $$p; $(MAKE) fake-r; fi); \ done ### Recursion: ifdef SUBDIRS # rec_defs: Variable definitions required for recursive makes. # We have to propagate them in the command because if we # didn't, the sub-make would inherit from the parent process. # There are two cases we need to handle: $(TOPDIR) is defined as a # ../... path, in which case $(MF_DIR) is also relative, or # $(TOPDIR) is undefined and $(MF_DIR) is absolute. ifdef TOPDIR rec_defs = TOPDIR=../$(TOPDIR) SRCDIR=../$(SRCDIR) \ DOTDOT=$(MYPATH) MYNAME=$$p MYPATH=$(MYPATH)/$$p \ VPATH=$(VPATH)/$$p else rec_defs = SRCDIR=../$(SRCDIR) \ DOTDOT=$(MYPATH) MYNAME=$$p MYPATH=$(MYPATH)/$$p \ VPATH=$(VPATH)/$$p endif # You'd think we could simply define $(rec_make) and $(rec_wurm) as # the entire command, including $(MAKE), but that screws up the weird # way make handles -n. That could be fixed with the "+" prefix. rec_wurm = if test -f $$p/WURMfile; then cd $$p; rec_make = elif test -f $$p/Makefile; then cd $$p; rec_sync = elif test -d $$p; then # (was in rec_sync) rsync -a -u -v -C -e ssh $$p/ $(HOST):$(DSTPATH)/$$p/; # Recursive rsync from $(SRC)/ to $(DST), used to recursively upload a # subdirectory that doesn't have a Makefile or WURMfile. rec-sync: rsync -a -u -v -C -e ssh $(SRC)/ $(DST) # === should use $(RRSYNC) for the recursive case, and $(RSYNC) otherwise # We only need to check for WURMfile on "put" -- other make targets # require a Makefile, for pretty obvious reasons. # If we run across a subdir with neither a WURMfile nor a Makefile, # we make put by rsync'ing the whole subdir (rec_sync). We do this # by running "make rec-sync" so that "make -n" works. # # The use of -C is arguable, but makes sense in most cases: # the CVS directory, at least, won't make sense on the server. # To change this behavior, simply make a WURMfile. # # === have to make sure we *don't* rsync if "make -n" -- probably # requires two separate recursion rules for put # # === rsync sometimes wants --delete and perhaps other optional args. # === should probably have a suitable definition # === need to redefine $(rec_make) to not execute if we're running from # === a WURMfile -- otherwise it will break on subdirs that have a Makefile # === but not a WURMfile. Do it later, since nobody's doing that yet. # === easy if WURMfile "include"s wurm.make instead of webdir.make all:: @@for p in $(SUBDIRS) xxx; do ( \ if test -f $$p/Makefile; then cd $$p; $(MAKE) $(rec_defs) $@; \ fi ); \ done doc:: @@for p in $(SUBDIRS) xxx; do ( \ if test -f $$p/Makefile; then cd $$p; $(MAKE) $(rec_defs) $@; \ fi); \ done put:: @@for p in $(SUBDIRS) xxx; do ( \ $(rec_wurm) $(MAKE) -f WURMfile $(rec_defs) $@; \ $(rec_make) $(MAKE) $(rec_defs) $@; \ $(rec_sync) $(MAKE) SRC=$$p DST=$(HOST):$(DSTPATH)/$$p/ rec-sync;\ fi); \ done clean:: @@for p in $(SUBDIRS) xxx; do ( \ if test -f $$p/Makefile; then cd $$p; $(MAKE) $(rec_defs) $@; \ fi); \ done ### Setup: setup:: @@for p in $(SUBDIRS) xxx; do ( if test -d $$p; \ then echo 'setting up ' $$p; \ test -f $$p/Makefile || (cd $$p; \ make -f ../Makefile $(rec_defs) Makefile); \ (cd $$p; $(MAKE) $(rec_defs) setup || true); \ fi); done endif # === could skip this, since we no longer construct "put" setup:: .cvsignore @echo .cvsignore set up in $(MYNAME) .cvsignore: @echo put > .cvsignore ifdef TOPDIR setup_TOPDIR = echo 'TOPDIR=$(TOPDIR)' >> Makefile setup_MF_DIR = echo 'MF_DIR=$$(TOPDIR)/Config/makefiles' >> Makefile else setup_TOPDIR = echo 'TOPDIR is not defined: not propagated' setup_MF_DIR = echo 'MF_DIR=$(MF_DIR)' >> Makefile endif Makefile: @echo '### Makefile for' $(MYPATH) > Makefile @echo '# $$'Id'$$' >> Makefile @echo '# COPYRIGHT 1999, HyperSpace Express' >> Makefile @echo '' >> Makefile @$(setup_TOPDIR) @echo 'MYNAME=$(MYNAME)' >> Makefile @echo 'DOTDOT=$(DOTDOT)' >> Makefile @echo 'SRCDIR=$(SRCDIR)' >> Makefile @echo '' >> Makefile @echo "FILES= \\" >> Makefile @echo ' $$(wildcard *.html)' >> Makefile @echo '' >> Makefile @$(setup_MF_DIR) @echo 'include $$(MF_DIR)/file.make' >> Makefile -grep '^include ' ../Makefile \ | grep -v file.make | grep -v subdir.make >> Makefile @echo ' ' >> Makefile @echo "$(MYPATH)/Makefile set up. Edit as needed." ### make check: locate files that may have problems. check:: @egrep -n "\\