#
# $Id: Makefile,v 2.10 1999/01/09 22:48:34 diego Exp $
#
# Top level makefile for the Odyssey compiler.
#
# Subdirectories to build. Order is important! Directories at the top of
# the list are needed before their successors can be built.
#
SUB0		= Scripts Debug
SUB1		= FindPar FixPgen
SUB2		= String UtilLib ParLib CSSAMELib OptLib
SUB3		= OCC GenPar ShowCCFG
SUBDIRS		= $(SUB0) $(SUB1) $(SUB2) $(SUB3)
SRCDIR		= src

ROOT		= $(ODYSSEY)
ODYSSEY_BACKUP	= $(HOME)/Backup
ODYSSEY_DISTRIB = $(HOME)/pub/Odyssey

include $(ROOT)/Makefile.defs

default: help

help: title
	@echo "Available targets are:" ;\
	echo "" ;\
	echo "backup         - Creates a backup in "'$$ODYSSEY_BACKUP.' ;\
	echo "[p]build       - Compiles every module." ;\
	echo "clean          - Removes objects, libraries and executables." ;\
	echo "clobber        - Uninstalls objects, libraries and executables from "'$$ODYSSEY.' ;\
	echo "depend         - Builds dependency information for every module." ;\
	echo "distrib        - Copies the whole distribution to "'$$ODYSSEY_DISTRIB.' ;\
	echo "[p]fromscratch - Clobbers and installs everything." ;\
	echo "ftp            - Creates a tar file out of the "'$$ODYSSEY_DISTRIB'" directory." ;\
	echo "[p]install     - Installs libraries and executables in "'$$ODYSSEY.' ;\
	echo "install-headers- Installs exportable headers from every directory." ;\
	echo "[p]rebuild     - Cleans and builds modules." ;\
	echo "" ;\
	echo "NOTE: The optional 'p' at the start of some rules is to compile with Purify." ;\
	echo "" ;\
	echo "The following environment variables should be defined:" ;\
	echo "" ;\
	echo "ODYSSEY:          Pointing to Odyssey's root directory." ;\
	echo "ODYSSEY_ARCH:     Architecture. Same values used by SUIF." ;\
	echo "ODYSSEY_COMPILER: Compiler to use. Same values used by SUIF." ;\
	echo "" ;\
	echo "Defaults are:" ;\
	echo "ODYSSEY:          $$ODYSSEY" ;\
	echo "ODYSSEY_ARCH:     $$ODYSSEY_ARCH" ;\
	echo "ODYSSEY_COMPILER: $$ODYSSEY_COMPILER" ;\
	echo "" ;\
	echo "" ;\
	echo "" ;\
	echo "Other variables defined in Makefile:" ;\
	echo "" ;\
	echo "ODYSSEY_BACKUP:	$$ODYSSEY_BACKUP" ;\
	echo "ODYSSEY_DISTRIB:	$$ODYSSEY_DISTRIB" ;\
	echo "" ;\

title:
	@echo "" ;\
	echo "-------------------------------------------------------------------------------" ;\
	echo "Odyssey Compiler v$(VERSION)" ;\
	echo "-------------------------------------------------------------------------------" ;\
	echo "" ;\


build rebuild clean clobber depend install install-headers tags: title checkdirs
	@for dir in $(SUBDIRS); do \
		echo "###----------------------------------------------------------------------------"; \
		echo "### `date`: $@ing $(SRCDIR)/$$dir"; \
		echo "###----------------------------------------------------------------------------"; \
		(cd $(SRCDIR)/$$dir; $(MAKE) --no-print-directory $@); \
		echo "" ; \
		echo "" ; \
	done

pbuild:
	$(MAKE) PURIFY=purify build

pfromscratch:
	$(MAKE) PURIFY=purify fromscratch

pinstall:
	$(MAKE) PURIFY=purify install

prebuild:
	$(MAKE) PURIFY=purify rebuild

ci: title
	cvs ci

#
# fromscratch cannot make depend before install because most header files
# are not installed yet. In any case, depend is not needed because we start
# from a clobbered state anyway.
#
fromscratch: clobber install-headers install depend tags

distrib: install
	$(ROOT)/src/Scripts/create-odyssey-distrib ${ODYSSEY_DISTRIB}

ftp:
	$(ROOT)/src/Scripts/create-odyssey-ftp ${ODYSSEY_DISTRIB}

backup bak: clobber
	$(ROOT)/src/Scripts/odyssey-backup ${ODYSSEY_BACKUP}

checkdirs: $(BINDIR) $(LIBDIR) $(INCDIR) $(MANDIR)

$(BINDIR) $(LIBDIR) $(INCDIR) $(MANDIR):
	@echo Creating directory '$@'
	@mkdir -p $@
