# ./make/Makelibs -- top level makefile
#
# This makefile can be used to make the sibling ACL2 proof libraries.  We assume
# that all of the libraries are rooted at ../

.PHONY: all clean status diff update commit tag lsbooks deps just-libs



# The order of books in this listing is the order they will be built in.  You
# must ensure that the dependencies for each directory are listed before the
# directory occurs! (It isn't smart enough to figure it out on its own).

BOOKS = ../symbol-fns \
	../adviser \
	../super-ihs \
	../lists \
	../sets \
	../osets \
	../syntax \
	../bags \
	../alists \
	../paths \
	../records \
        ../defpun \
        ../pacc \
	../defstructure \
	../gacc \
        ../nu \
        ../pipe \
	../int178b \
	../proofs-common \
	../aamp7-separation \
        ../aamp-model



# Building All Of The Books
# You can use "make all" to build all of the books.  If you want to use an ACL2
# image other than the one in Makefile.top, you can add "ACL2=[ .../saved_acl2
# ]" to your Make command.  You can also use DEBUG=1 if you want to use debug
# mode on all of the Makefiles, but this is probably unwanted.

ifdef ACL2
	ACL2_ROOT = $(shell echo $(ACL2) | sed "s/\/[^/]*$$//")
	EXPORTS = DEBUG="$(DEBUG)" ACL2="$(ACL2)" ACL2_ROOT="$(ACL2_ROOT)"
else
	EXPORTS = DEBUG="$(DEBUG)"
endif


TIMELOG = $(shell pwd)/Time.log

all:
	@echo "" >> $(TIMELOG)
	@echo "Building on `date`" >> $(TIMELOG)
	@for book in $(BOOKS) ;\
	do \
		if [ -d $$book ] ;\
		then \
			echo "" ;\
			echo "Building $$book" ;\
			cd $$book; \
			export $(EXPORTS); \
			if [ -f /usr/bin/time ] ;\
			then \
				/usr/bin/time -ao $(TIMELOG) -f "%e Seconds for $$book" $(MAKE) -s all ;\
			else \
				$(MAKE) -s all ;\
			fi ;\
			if [ $$? -ne 0 ] ; \
			then \
				exit $$? ;\
			fi ;\
		else \
			echo "Skipping $$book (not a directory)" ;\
			echo "Skipping $$book (not a directory)" >> $(TIMELOG) ;\
		fi ;\
	done

# Cleaning All Of The Books
# You can use "make clean" to remove temporary files from all of the books.
# Note: This will wipe out all of your certified files, and you will have
# to rebuild everything!

clean:
	@echo ""
	@for book in $(BOOKS) ; \
	do \
		if [ -d $$book ] ; \
		then \
			echo "Cleaning $$book" ; \
			cd $$book; \
			export $(EXPORTS); \
			$(MAKE) -s clean ; \
			echo "" ;\
		else \
			echo "Skipping $$book (not a directory)" ;\
			echo "" ;\
		fi ;\
	done




# Checking CVS Status
# You can check the CVS status of all of your books by executing "make status".
# This will recursively descend into each directory and issue its own make
# status command.  You can also use "make diff" in order to see what changes
# have been made.

status:
	@echo "" ;\
        echo "Examining ." ;\
        cvs status 2>&1 | egrep "(File|aborted)" ;\
	for book in $(BOOKS) ; \
	do \
		if [ -d $$book ] ; \
		then \
			echo "" ;\
			echo "Examining $$book" ;\
			cd $$book; \
			cvs status 2>&1 | egrep "(File|aborted)" ;\
		else \
			echo "Skipping $$book (not a directory)" ;\
		fi ;\
	done ;\
	echo ""

diff:
	@echo "" ;\
	echo "Examining ." ;\
	cvs diff ;\
	for book in $(BOOKS) ;\
	do \
		if [ -d $$book ] ;\
		then \
			echo "" ;\
			echo "Examining $$book" ;\
			cd $$book ;\
			cvs diff ;\
		else \
			echo "Skipping $$book (not a directory)" ;\
		fi ;\
	done


# Updating from CVS Repository
# You can execute "make update" in order to perform a CVS update in each of the
# books directories, which will make sure your local files are fresh with
# respect to the CVS server.

update:
	@for book in $(BOOKS) ;\
	do \
		if [ -d $$book ] ; \
		then \
			echo "Updating $$book" ;\
			cd $$book; \
			cvs update -d 2>&1 | grep -v "^cvs update:" ;\
		else \
			echo "Skipping $$book (not a directory)" ;\
		fi ;\
	done



# Committing Changes to CVS
# You can execute "make commit" in order to commit your changes in each
# directory.  Note that you will need to provide MESSAGE="my commit message"
# for this command to be accepted.

commit:
	@if [ -n "$(MESSAGE)" ] ;\
	then \
		for book in $(BOOKS) ;\
		do \
			if [ -d $$book ] ; \
			then \
				echo "" ;\
				echo "Committing $$book" ;\
				cd $$book; cvs commit -m "$(MESSAGE)" ; \
			fi ;\
		done ;\
	else \
		echo "Refusing to commit without MESSAGE." ;\
		echo "Try adding 'MESSAGE="my message"' to your make command." ;\
	fi


tag: commit
	@if [ -n "$(TAGNAME)" ] ;\
	then \
		for book in $(BOOKS) ;\
		do \
			if [ -d $$book ] ;\
			then \
				echo "" ;\
				echo "Tagging $$book" ;\
				cd $$book; cvs -q tag "$(TAGNAME)" ;\
			fi ;\
		done ;\
	else \
		echo "Refusing to tag without TAGNAME." ;\
		echo "Try adding 'TAGNAME="name"' to your make command." ;\
	fi


# Support for OVERKILL system

BOOKSFILE = $(shell pwd)/.okill/BOOKS

lsbooks: 
	@for book in $(BOOKS) ;\
	do \
		if [ -d $$book ] ;\
		then \
			echo "Processing $$book" ;\
			cd $$book; make -s lsbooks >> $(BOOKSFILE) ;\
		fi ;\
	done

DIRSFILE = $(shell pwd)/.okill/DIRS

lsdirs:
	@for book in $(BOOKS) ;\
	do \
		if [ -d $$book ] ;\
		then \
			cd $$book; pwd -P >> $(DIRSFILE) ;\
		fi ;\
	done

deps: 
	@for book in $(BOOKS) ;\
	do \
		if [ -d $$book ] ;\
		then \
			echo "Processing $$book" ;\
			cd $$book; make deps NORECUR=1 ;\
		fi ;\
	done

just-libs: 
	@for book in $(BOOKS) ;\
	do \
		if [ -d $$book ] ;\
		then \
			echo -n "[$$book]: " ;\
			cd $$book; make -s just-libs ;\
		fi ;\
	done
