#; Adapted from makefile for IHS library, which was created by Bishop Brock.

#; This file is free software; you can redistribute it and/or modify
#; it under the terms of the GNU General Public License as published by
#; the Free Software Foundation; either version 2 of the License, or
#; (at your option) any later version.

#; This book is distributed in the hope that it will be useful,
#; but WITHOUT ANY WARRANTY; without even the implied warranty of
#; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#; GNU General Public License for more details.

#; You should have received a copy of the GNU General Public License
#; along with this book; if not, write to the Free Software
#; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# Edit the following as necessary.  The setting below reflects an
# assumption regarding where this makefile will be executed.
ACL2 = time nice acl2
SHELL = bash --noprofile --norc

INHIBIT = (assign inhibit-output-lst (list (quote prove) (quote proof-tree) (quote warning) (quote observation)))

#  If you define this to be a list of book names (without .lisp or any other
#  suffixes) then you can do `make all' and `make dependencies'.

BOOKS = $(patsubst %.lisp, %, $(wildcard *.lisp))

# We should really check that following is not empty.
TOP_BOOKS = $(patsubst %.lisp, %.cert, $(wildcard *.lisp))

#  This tells make to expect `suffix rules' for these file suffixes.

.SUFFIXES: .cert .lisp .date

#  This rule tells how to get <book>.cert from <book>.lisp, either by running
#  Acl2 on the <book>.acl2 file (if it exists) or using the default command
#  to certify at ground zero.

.lisp.cert:
	echo "Making $*.cert on `date`"
	date > $*.date
	if \
	  [ -f $*.acl2 ] ; \
	then \
	  $(ACL2) < $*.acl2 > $*.out ; \
	else \
	  echo ':q (ACL2::LP) (ld `($(INHIBIT) (certify-book! "$*" 0)))' | $(ACL2) > $*.out ; \
	fi
	ls -al $*.cert

#  This rule checks to insure that the make was successful, where success
#  means that the <book>.cert file was created.

.date: 
	echo 'The make for the book $*.lisp seems to have failed.'
	rm $*.date
	false

all:
	make -s -f Makefile $(TOP_BOOKS) INHIBIT='$(INHIBIT)'

#  This rule prints make dependency commands to the screen.  For best
#  results run as `make -s dependencies'.

dependencies: 
	for book in $(BOOKS) ; \
	do \
	(echo "" ;  echo "$$book.cert: $$book.lisp" ; \
	egrep '^[^;]*\((include-book|INCLUDE-BOOK)[ \t]*\".*\"' \
	`if [ -f $$book.acl2 ]; then echo "$$book.acl2"; fi` $$book.lisp) | \
	sed "s/[^\"]*\"/$$book.cert: /" | sed 's/".*/.cert/' ;\
	done

clean:
	rm -f *.cert
	rm -f *.o
	rm -f *.fasl
	rm -f *.sbin
	rm -f *.lbin
	rm -f *.pfsl
	rm -f *.bin
	rm -f *.sparcf
	rm -f *.axpf
	rm -f *.out
	rm -f *.date
	rm -f *.log
	rm -f workxxx
