### subdir.make -- makefile template for subdirectories # $Id: subdir.make,v 1.5 2007-05-10 15:55:21 steve Exp $ # COPYRIGHT 1997, HyperSpace Express # This file is free software licenced under LGPL v2.0 or later. ######################################################################## # # This makefile contains rules for making subdirectories. # ######################################################################## ### Usage: # TOPDIR=../../.... # DOTDOT= # MYNAME= # MF_DIR=$(TOPDIR)/Config/makefiles # include $(MF_DIR)/file.make # (up to this point it's standard boilerplate) # SUBDIRS = x y z # include $(MF_DIR)/subdir.make ### MYPATH=$(DOTDOT)/$(MYNAME) ### Targets: # all build executables, etc. # doc build documentation # clean remove trash # setup initialize Makefile and other essential files ### # This file contains the code necessary for recursion on the targets # in file.make. Note the use of zzz and existance tests to handle the # common case where either $(SUBDIRS) is empty or a Makefile is missing. # variable definitions required for subdirectories in a recursive make recursion_defs= TOPDIR=../$(TOPDIR) DOTDOT=$(MYPATH) MYNAME=$$p \ MYPATH=$(MYPATH)/$$p VPATH=$(VPATH)/$$p # === not at all clear that VPATH is necessary or even desirable. all:: for p in $(SUBDIRS) zzz; do ( if test -f $$p/Makefile; \ then cd $$p; $(MAKE) $(recursion_defs) all; fi ); \ done doc:: @@for p in $(SUBDIRS) zzz; do ( cd $$p; if test -f Makefile; \ then $(MAKE) $(recursion_defs) doc; fi); \ done clean:: @@for p in `ls -d $(SUBDIRS)` zzz; do ( cd $$p; if test -f Makefile; \ then $(MAKE) $(recursion_defs) clean; fi); \ done # Note that we don't do the zzz trick with setup. If $(SUBDIRS) is empty # there's no point in doing this, and an error is the right thing. setup:: @@for p in $(SUBDIRS); do \ echo 'setting up ' $$p; \ test -d $$p || mkdir $$p; \ test -f $$p/Makefile || (cd $$p; \ make -f ../Makefile $(recursion_defs) Makefile); \ if test -f $$p/Imakefile; then \ (cd $$p; xmkmf -a); \ elif grep -s setup: $$p/Makefile; then \ (cd $$p; $(MAKE) $(recursion_defs) setup || true); \ fi; \ done Makefile: @echo '### Makefile for' $(MYPATH) > Makefile @echo '# $$'Id'$$' >> Makefile @echo '# COPYRIGHT 1999, HyperSpace Express' >> Makefile @echo ' ' >> Makefile @echo 'TOPDIR=$(TOPDIR)' >> Makefile @echo 'MYNAME=$(MYNAME)' >> Makefile @echo 'DOTDOT=$(DOTDOT)' >> Makefile @echo ' ' >> Makefile @echo 'MF_DIR=$$(TOPDIR)/Config/makefiles' >> Makefile @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."