#This original file is stolen from Brock's IHS package.

# Set ACL2 to the acl2 executable in your system. Make sure that the version
# of Acl2 is V1-9. Our script file is not tested with other versions.
ACL2 = /usr/local/bin/acl2
# Set ACL2_BOOK_DIR to the directory containing the books coming with the
# Acl2 source code. If the source directory of ACL2 is $ACL2_PATH, the book
# directory is usually at $ACL2_PATH/books. Make sure they are certified.
ACL2_BOOK_DIR=/usr/local/src/acl2-v2.3/books

# COMPILE_FLAG to specify whether certifying process should compile
# books. "nil" means "do not compile". Otherwise, the certify command
# compiles the books.  When an .acl2 file is supplied to specify the way
# a book is certified, the .acl2 file overrides this flag.
COMPILE_FLAG=t

# Extension for the compiled object file names.
# For GCL, use "o"
# For Allegro, use "fasl".
EXT=fasl

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 = array1 b-ops-aux-def b-ops-aux basic-def MA2-def ISA-def trivia utils 

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

.SUFFIXES: .cert .lisp  .date $EXT


#  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
	(cd IHS ; make ACL2=$(ACL2) COMPILE_FLAG=$(COMPILE_FLAG) ACL2_LIB=${ACL2_BOOK_DIR} EXT=`cat workyyy` )
	for book in $(BOOKS) ;\
	do \
	make  -f makefile $$book.cert INHIBIT='$(INHIBIT)' EXT=`cat workyyy` ;\
	done 

tops: correctness.cert liveness.cert diagrams.cert 

outs: 
	for book in $(BOOKS) ;\
	do \
	make  -f makefile $$book.out  ;\
	done 

new_image: 
	${ACL2} < work_image.acl2

statistic:
	grep defthm $(BOOKS)

#  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`"
	rm -f $*.cert
	date > $*.date
	if  [ -f $*.acl2 ] ; \
	then \
	  $(ACL2) < $*.acl2 > $*.out ; \
	else \
	  echo ':q' > workxxx ; \
	  echo '(lp)' >> workxxx ; \
	  echo '(ld `($(INHIBIT) (certify-book! "$*" 0 $(COMPILE_FLAG))))' >> workxxx ; \
	  $(ACL2) < workxxx > $*.out ; \
	fi
	sleep 1
	ls -al $*.cert 


.lisp.out:
	rm -f $*.out
	echo ':q' > workxxx ; \
	echo '(lp)' >> workxxx ; \
	echo '(ld "$*.lisp" :ld-pre-eval-print t)' >> workxxx ; \
	$(ACL2) < workxxx > $*.out ; \


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

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


lean: 
	rm -f *.out *.date IHS/*.out IHS/*.date host-xpspec/*.out \

clean: 
	rm -f *.out *.date *.cert *.o *.fasl
	(cd IHS ; make clean)

#  This rule output the dependency file into ./.dependency.	

prepare:
	if [ "$(ACL2_BOOK_DIR)" = "" ] ; then \
	 echo ; \
	 echo Please set ACL2_BOOK_DIR to Acl2 book directory!  ; \
	 exit 1 ; \
	fi
	make dependencies
	(cd IHS ; rm ihs-absolute-paths.lisp ihs-absolute-paths.cert ; make ACL2_LIB=${ACL2_BOOK_DIR} ihs-absolute-paths.cert)

dependencies:
	rm -f .dependency ; \
	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/\" *\"/\//g' | \
	sed 's/".*/.cert/' >> .dependency ;\
	done


# Include dependency file
include .dependency

software.cert:  correctness.cert liveness.cert

