#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#  makefile
#
#  Bishop Brock
#  Computational Logic, Inc.
#  1717 West 6th Street, Suite 290
#  Austin, TX 78703
#  brock@cli.com
#
#  Modified by Jun Sawada,   May 1997.
#  This make file has been tested with ACL2 V1-9 based on GCL 2.2 and
#  Allegro 4.3.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#  The ACL2 macro defines how to run Acl2.  The default command below prints
#  runtime statistics for the certification, and runs it `nice' in an attempt
#  to lessen interference with interactive jobs.  We normally inhibit
#  most output during certification to speed the proofs.

ACL2 = time nice acl2
ACL2_LIB = /p/src/formal-methods/acl2-v1-9-new/books

#  Use a different extension for different Common Lisps:
# AKCL, GCL:  o
# Lucid (sparc) sbin
# Allegro fasl
# lispworks fasl
EXT=o

INHIBIT =
#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 = ihs-init ihs-theories math-lemmas quotient-remainder-lemmas \
        logops-definitions logops-lemmas ihs

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

.SUFFIXES: .cert .lisp  .${EXT} .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' > workxxx ; \
	  echo '(lp)' >> workxxx ; \
	  echo '(ld `($(INHIBIT) (certify-book! "$*" 0)))' >> workxxx  ; \
	  $(ACL2) < workxxx > $*.out ; \
	fi
	ls -al $*.cert $*.${EXT}
	make -s -f makefile $*.${EXT}

#  This rule checks to insure that the make was succesful, where success
#  means that the <book>.${EXT} file was created.

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

#  This rule certifies every book in BOOKS.  If the dependencies are set up
#  correctly then the order of the books in BOOKS won't matter.

all:
	echo '(value :q)' > workxxx
	echo '(with-open-file (str "workyyy" :direction :output) (format str "~a" acl2::*compiled-file-extension*))' >> workxxx
	${ACL2} < workxxx
	rm -f workxxx
	for book in $(BOOKS) ;\
	do \
	make -s -f makefile $$book.cert INHIBIT='$(INHIBIT)' ACL2_LIB='$(ACL2_LIB)' EXT=`cat workyyy` ;\
	done
	rm -f workyyy

ihs-absolute-paths.cert: 
	echo '(in-package "ACL2")' > $*.lisp
	echo '(defmacro acl2-book-dir () ' >> $*.lisp
	echo \"${ACL2_LIB}\"\) >> $*.lisp
	cat $*.body >> $*.lisp
	echo ':q' > workxxx
	echo '(lp)' >> workxxx
	echo '(ld `($(INHIBIT) (certify-book! "$*" 0)))' >> workxxx
	$(ACL2) < workxxx > $*.out ; 

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

#
clean:
	rm -f *.o *.fasl *.cert *.out *.date workxxx workyyy ihs-absolute-paths.lisp gazonk*

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

#  Put dependencies (from `make -s dependencies', or other sources) below.


ihs-init.cert: ihs-init.lisp
ihs-init.cert: $(ACL2_LIB)/public/utilities.cert
ihs-init.cert: ihs-absolute-paths.cert

ihs-theories.cert: ihs-theories.lisp
ihs-theories.cert: ihs-init.cert

math-lemmas.cert: math-lemmas.lisp
math-lemmas.cert: ihs-absolute-paths.cert
math-lemmas.cert: $(ACL2_LIB)/arithmetic/top.cert
math-lemmas.cert: ihs-init.cert

quotient-remainder-lemmas.cert: quotient-remainder-lemmas.lisp
quotient-remainder-lemmas.cert: ihs-init.cert
quotient-remainder-lemmas.cert: ihs-theories.cert
quotient-remainder-lemmas.cert: math-lemmas.cert

logops-definitions.cert: logops-definitions.lisp
logops-definitions.cert: ihs-init.cert
logops-definitions.cert: ihs-theories.cert
logops-definitions.cert: math-lemmas.cert
logops-definitions.cert: quotient-remainder-lemmas.cert

logops-lemmas.cert: logops-lemmas.lisp
logops-lemmas.cert: ihs-init.cert
logops-lemmas.cert: ihs-theories.cert
logops-lemmas.cert: math-lemmas.cert
logops-lemmas.cert: quotient-remainder-lemmas.cert
logops-lemmas.cert: logops-definitions.cert

ihs.cert: ihs.lisp
ihs.cert: ihs-absolute-paths.cert
ihs.cert: ihs-init.cert
ihs.cert: ihs-theories.cert
ihs.cert: logops-definitions.cert
ihs.cert: math-lemmas.cert
ihs.cert: quotient-remainder-lemmas.cert
ihs.cert: logops-lemmas.cert

array1.cert: array1.lisp

fm9001.cert: fm9001.lisp
fm9001.cert: ihs-absolute-paths.cert
fm9001.cert: array1.cert
fm9001.cert: ihs.cert