ZIP = /cygdrive/c/progra~1/winzip/winzip32

SUBDIRS = OnBoard \
	  OnBoardC \
	  SrcEdit \
	  Sherpa \
	  Documentation \
	  Samples

VER     = 242
DISTNAME= OnBSuite$(VER)
DISTDIR = $(DISTNAME)/

BINS    = $(DISTDIR)*.prc \
	  $(DISTDIR)*.pdb 

READMES = $(DISTDIR)COPYING.txt \
	  $(DISTDIR)README.txt \
	  $(DISTDIR)SrcEdit_KeyboardSupport.txt

DOCS    = $(DISTDIR)Samples \
	  $(DISTDIR)Headers \
	  $(DISTDIR)Documentation

.PHONY: all
all: subdirs

.PHONY: subdirs $(SUBDIRS)
subdirs: $(SUBDIRS)

$(SUBDIRS):
	$(MAKE) $(TARGET) -C $@

clean: TARGET=clean
clean: subdirs
	-rm -f *~

# These are the things we need to make for a distribution
dist: source-zip source-tar binary-zip binary-tar

# target to clear out any temp dirs left around from a "make dist"
clean-dist:
	-rm -rf ../$(DISTDIR)
	-rm -rf $(DISTDIR)
	-rm -f $(DISTNAME)_src.zip \
	   $(DISTNAME)_src.tgz \
	   $(DISTNAME).zip \
	   $(DISTNAME).tgz

# Clean out temp files, CVS directories etc
# ie, clean up directories ready for a distribution
#
# (This is a dummy target, just calls _dist-clean in the copied directory)
.PHONY: dist-clean
dist-clean: $(DISTDIR)
	$(MAKE) _dist-clean -C $(DISTDIR)
	-rm -f $(BINS) \
	    OnBoardHeaderV40.pdb \
	    SrcEdit_KeyboardSupport.txt

# This does the real work...
.PHONY: dist-clean
_dist-clean: TARGET=dist-clean
_dist-clean: subdirs
	-rm -f syncmail \
		roger.txt \
		checkoutlist \
		$(DISTNAME)_src.tgz \
		$(DISTNAME)_src.zip \
		$(DISTNAME).tgz \
		$(DISTNAME).zip \
	rm -rf `find . -name CVS`
	-rm -f *~

# Make a copy of the directory in order to do a distribution
$(DISTDIR): 
	mkdir ../$(DISTDIR)
	cp -R * ../$(DISTDIR)
	mv ../$(DISTDIR) .

source-zip: dist-clean
	$(ZIP) -min -a -r -p $(DISTNAME)_src.zip $(DISTDIR)*

source-tar: dist-clean
	tar cvzf $(DISTNAME)_src.tgz $(DISTDIR)

# dummy target: just call "make _prcs" in the copied directory
prcs: $(DISTDIR)
	$(MAKE) _prcs -C $(DISTDIR)

# ensure all prcs are up to date, and copy into root directory
_prcs: all
	cp SrcEdit/Src/SrcEdit.prc .
	cp OnBoard/Src/OnBoard.prc .
	cp OnBoardC/Src/OnBoardC.prc .
	cp Headers/OnBoardHeaderV40.pdb .
	cp SrcEdit/SrcEdit_KeyboardSupport.txt .

binary-zip: prcs
# Have to split these up, because of the weird way winzip recurses
	$(ZIP) -min -a -p $(DISTNAME).zip $(BINS) $(READMES)
	$(ZIP) -min -a -r -p $(DISTNAME).zip $(DOCS)

binary-tar: prcs
	tar cvzf $(DISTNAME).tgz $(BINS) $(DOCS) $(READMES)
