#  -*- Fundamental -*- 

# ACL2 Version 1.8

# Copyright (C) 1989-95 Computational Logic, Inc. (CLI).  All rights reserved.

# Use of this software constitutes agreement with the terms of ACL2
# license agreement, found in the file LICENSE.

# At CLInc the various Lisp images located using meta-x info and going to the
# node Lisp Implementations Available at CLI.

#  Example invocations for users:

#   make             ; Build saved_acl2 from scratch.  Same as make small.
#   make small       ; Build saved_acl2 from scratch.
#   make large       ; Build large-saved_acl2 from scratch.
#   make both        ; Build both large and small images from scratch.
#   make LISP=cl PREFIX=allegro-
#   make LISP=lisp PREFIX=lucid-
#   make LISP=lispworks PREFIX=lispworks-
#                    ; Same as make, except that image is named
#                    ; allegro-saved_acl2 and the image is built on top of
#                    ; a Common Lisp executable called cl (similarly for the
#                    ; other two examples).
#   make TAGS        ; Create tags table, handy for viewing sources with emacs.
#   make certify-books
#                    ; Certify all the example books using current acl2 command
#                    ; (Implementors might wish to use certify-books-test 
#                    ; below).
#   make certify-books PREFIX=xxx- EXT=wfasl
#                    ; Same as make certify-books, but use xxx-saved_acl2,
#                    ; where the Lisp underlying xxx-saved_acl2 uses the
#                    ; extension .wfasl for compiled files.  (The default value
#                    ; of EXT is .o, which is correct for GCL and AKCL.  If
#                    ; PREFIX is unspecified, then saved_acl2 is used.)  NOTE:
#                    ; PREFIX may only be used to specify a pathname relative
#                    ; to the directory of this makefile.
#   make clean-books ; Remove certificate files, object files, log files,
#                    ; debris, ..., created by `make certify-books'.

###############################################################################

#  NOTE:  Users need not read below this line.  Neither should installers of
#  ACL2 at sites other than CLI.  We have no reason to believe that the make
#  commands illustrated below will work at sites other than CLI.  Indeed, we
#  have reasons to believe they will not!  A typical problem is that we refer
#  to a file or directory that exists at CLI but that is not created when our
#  installation instructions are followed at other sites.

#  Example invocations for CLI implementors:

#   WARNING:  Implementors should NOT use `make large'.  Let's call all our
#   images saved_acl2, except perhaps for prefixes indicating for example the
#   underlying Lisp used in building the image.

#   NOTE:  make small and make large both completely recompile, initialize and
#   save.  Consider some of the "fast" and "very-fast" options below if only
#   part of the system needs to be rebuilt.

#   make big-test
#                  ; Build the large image from scratch, make the DOC files in
#                  ; EMACS (TexInfo), HTML, and TEX, build the small image,
#                  ; certify all the books, prove through axioms.lisp.
#                  ; Typical invocations:

#   make big-test >& make-big-test.log&
#   make big-test LISP=cl PREFIX=cl- >& make-cl-big-test.log&

#   make test

#                  ; Build the system from scratch, certify all books, and
#                  ; prove through axioms.lisp.  Consider "make test DOC" if
#                  ; running late at night (so that you don't smash someone's
#                  ; documentation).

#   make very-fast init 
#                  ; Build the system, recompiling as little as possible
#                  ; (perhaps don't even recompile TMP1.lisp).

#   make distribution
#                  ; Build the system for distribution via ftp.

#   make fast init ; Compile as needed, initialize, build full-size saved_acl2
#   make fast-small init-small
#                  ; Compile as needed, initialize, build small saved_acl2.
#   make very-fast-small init-small
#                  ; As above, only compiling files with out of date objects.

#   make full      ; A complete recompilation whether needed or not.
#   make full init ; Completely recompile, initialize and save.
#   make full-meter init  ; Completely recompile with meters, init and save.
#   make init      ; Just build full-size saved_acl2.
#   make small     ; Completely recompile and then build small saved_acl2 image.
#   make check-sum ; Call only after ACL2 is completely compiled.
#   make full LISP=lucid PREFIX=lucid-  ; makes acl2 in Lucid
#   make full LISP=cl PREFIX=allegro- ; makes acl2 in allegro
#   make full LISP=lispworks PREFIX=lispworks- ; makes acl2 in lispworks
#   make copy DIR=targetdir  ; copies all of acl2 to targetdir.  Don't use ~ notation.
#   make DOC       ; Build html and emacs info files
#   make clean-doc ; Remove debris created by make DOC
#   make red       ; Just build full-size saved_acl2, but do so without pass 2
#   make proofs    ; Assuming sources are compiled, initialize without skipping
#                  ; proofs during pass 2.  Does not save an image.  Uses same
#                  ; flags used to build full-size image.
#   make certify-books-test
#                  ; Certify all the example books using
#                  ; `pwd`/${PREFIX}saved_acl2, e.g., 
#                  ; /slocal/src/acl2/v1-8/saved_acl2.  This is different
#                  ; from certify-books because that command uses whatever
#                  ; acl2 is invoked by the shell command acl2.

#  Metering:  If the currently compiled version is unmetered and you wish
#  it metered, the fastest thing to do is to (push :acl2-metering *features*)
#  and then yank in and recompile just those definitions that mention
#  acl2-metering.  However, if you would like to install metering as part
#  of a system-wide recompilation, you must use the full-meter option below,
#  rather than the fast-meter option.  If, while running a fully metered
#  system you wish to do what would otherwise be a make fast but you want
#  to preserve the metering, use the fast-meter option.  If you want to
#  get rid of the metering in the compiled code, do make full.

LISP = gcl
DIR = /tmp
PREFIX = ""

sources = axioms.lisp basis.lisp type-set-a.lisp type-set-b.lisp\
          translate.lisp rewrite.lisp simplify.lisp bdd.lisp\
          other-processes.lisp induct.lisp prove.lisp\
          proof-checker-a.lisp history-management.lisp defuns.lisp defthm.lisp\
          other-events.lisp ld.lisp proof-checker-b.lisp interface-raw.lisp\
          defpkgs.lisp

small:	full-small init-small-pass1 init-small

fast:   check
	date
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::quick-compile-acl2 nil nil)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

fast-small:   check
	date
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::quick-compile-acl2 nil t)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

check:  
	date
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::check-suitability-for-acl2)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

compile-ok:  
	date
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::note-compile-ok)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

very-fast:   check
	date
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::quick-compile-acl2 t nil)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

very-fast-small:   check
	date
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::quick-compile-acl2 t t)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

fast-meter:   check
	date
	rm -f workxxx
	echo '(load "init.lsp") (push :acl2-metering *features*)' > workxxx
	echo '(acl2::quick-compile-acl2 nil nil)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

check-sum:
	date
	rm -f workxxx
	echo '(load "init.lsp") (acl2)' > workxxx
	echo '(acl2::make-check-sum-file)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

full:   TAGS check
	rm -f workxxx
	rm -f acl2-fns.o acl2-fns.lbin acl2-fns.sbin acl2-fns.fasl acl2-fns.wfasl
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::compile-acl2 nil)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

full-small:   TAGS check
	rm -f workxxx
	rm -f acl2-fns.o acl2-fns.lbin acl2-fns.sbin acl2-fns.fasl acl2-fns.wfasl
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::compile-acl2 t)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

full-meter:  check
	date
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::make-tags)' >> workxxx
	echo '(push :acl2-metering *features*)' >> workxxx
	echo '(acl2::compile-acl2 nil)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

copy:
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::copy-acl2 "${DIR}")' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

TAGS:   acl2.lisp acl2-check.lisp acl2-fns.lisp acl2-init.lisp ${sources}
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::make-tags)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx
	
init:
# Note:  If you believe that compilation is up-to-date, do
# make compile-ok init
# rather than
# make init.
	rm -f workxxx
	echo -n "" >> ${PREFIX}osaved_acl2
	rm -f ${PREFIX}osaved_acl2
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::save-acl2' "'(acl2::initialize-acl2 (quote acl2::include-book) acl2::*acl2-pass-2-files* nil))" >> workxxx
	${LISP} < workxxx
	echo -n "" >> ${PREFIX}saved_acl2
	mv -f ${PREFIX}saved_acl2 ${PREFIX}osaved_acl2
	mv -f nsaved_acl2 ${PREFIX}saved_acl2
	rm -f workxxx
	rm -fr saved
	mkdir saved
	cp *.lisp saved
	rm -f workxxx

proofs: compile-ok
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::load-acl2 nil)' >> workxxx
# Don't bother building TMP1.* files.
	echo '(setq acl2::*compiled-*1*-fns* t)' >> workxxx
	echo '(acl2::initialize-acl2 nil acl2::*acl2-pass-2-files* nil)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

DOC:
	rm -f workxxx
	PREFIX=$(PREFIX) ; export PREFIX ; doc/create-acl2-html
	PREFIX=$(PREFIX) ; export PREFIX ; doc/create-acl2-texinfo
	rm -f workxxx

TEXINFO:
	rm -f workxxx
	PREFIX=$(PREFIX) ; export PREFIX ; doc/create-acl2-texinfo
	rm -f workxxx

HTML:
	rm -f workxxx
	PREFIX=$(PREFIX) ; export PREFIX ; doc/create-acl2-html
	rm -f workxxx

clean:
# Does not remove TAGS
	rm -f *.o *#* *.c *.h *.data gazonk.* workxxx \
	  *.lbin *.sbin *.fasl *.wfasl *.fn acl2-status.txt *.log TMP* saved/*
	rm -f *~ */*~ */*/*~ */*/*/*~

red:    compile-ok
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::save-acl2' "'(acl2::initialize-acl2 nil nil nil))" >> workxxx
	${LISP} < workxxx
	echo -n "" >> red-${PREFIX}saved_acl2
	mv -f red-${PREFIX}saved_acl2 red-${PREFIX}osaved_acl2
	mv -f nsaved_acl2 red-${PREFIX}saved_acl2
	rm -f workxxx
	rm -fr saved
	mkdir saved
	cp *.lisp saved

init-small:
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::save-acl2' "'(acl2::initialize-acl2 (quote acl2::include-book) acl2::*acl2-pass-2-files* t))" >> workxxx
	${LISP} < workxxx
	echo -n "" >> ${PREFIX}saved_acl2
	mv -f ${PREFIX}saved_acl2 ${PREFIX}osaved_acl2
	mv -f nsaved_acl2 ${PREFIX}saved_acl2
	rm -f workxxx
	rm -fr saved
	mkdir saved
	cp *.lisp saved
	rm -f workxxx

init-small-pass1:
	rm -f workxxx
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::load-acl2 t)' >> workxxx
	echo '(acl2::initialize-acl2 (quote acl2::include-book) acl2::*acl2-pass-2-files* t t)' >> workxxx
	${LISP} < workxxx
	rm -f workxxx

# CAREFUL!  Do not use large unless you want the image renamed to large-....
large: full init move-large

move-large:
	mv ${PREFIX}saved_acl2 large-${PREFIX}saved_acl2

# It's important to make the large image first, in order to trust the small one.
both:   large small

certify-books:
	ACL2=acl2 ; cd books ; rm -f public/*.cert ; make ACL2=$$ACL2

certify-books-test:
	ACL2=`pwd`/${PREFIX}saved_acl2 ; cd books ; touch placeholder.log ; mv *.log ../saved; rm -f public/*.cert ; make ACL2=$$ACL2

clean-doc:
	cd doc ; rm -f *.o *~* *#* TAGS *.c *.h *.data gazonk.* workxxx \
	  *.lbin *.sbin *.fasl *.wfasl *.fn *.cert
	rm -f doc/EMACS/acl2-doc-emacs.texinfo
	rm -f doc/EMACS/saved/*
	rm -f doc/LEMACS/acl2-doc-lemacs.texinfo
	rm -f doc/LEMACS/saved/*
	rm -f doc/HTML/saved/*
	rm -f doc/TEX/saved/*
	cd doc/TEX ; rm -f acl2-book.aux acl2-book.cp acl2-book.cps \
	  acl2-book.fn acl2-book.ky acl2-book.log acl2-book.pg acl2-book.tex \
	  acl2-book.toc acl2-book.tp acl2-book.vr
	cd doc/TEX ; gzip acl2-book.ps
	cd doc/TEX ; gzip acl2-book.dvi

clean-books:
	cd books ; rm -f *.log *~ */*.cert */*.out */*.date */*.o */*~ \
	  */*.lbin */*.sbin */*.fasl */*.wfasl */*.fn */*.log

# Note that we have hardwired in the directory name below.  We don't expect
# anyone other than CLI implementors to use this target.  Be sure to edit
# the pathname for future versions after v1-8.
distribution:
	rm -f workxxx
	rm -f workyyy
	echo '(load "init.lsp")' > workxxx
	echo '(acl2::copy-distribution "workyyy" "/slocal/src/acl2/v1-8")' >> workxxx
	${LISP} < workxxx
# The following command causes an error (which is good) if check-distribution
# fails.
	chmod 777 workyyy
	echo "Making distribution directory."
	workyyy
	echo "Done.  Now creating tar file."
	cd ../acl2-sources ; make tar

# This following should be executed inside the acl2-sources directory.
# You probably need to be the owner of all files in order for the chmod
# commands to work, but perhaps not.
tar:
	rm -f acl2.tar.Z acl2.tar
	rm -f SUM
# We want the extracted tar files to have permission for everyone to write,
# so that when they use -p with tar they get that permission.
# But we don't want the tar file itself to have that permission.  We may as
# well protect all the other files too from writing by CLI people other than
# those in the acl2 group, even though these files aren't the ones transferred
# to the ftp server.  Those come from the tar file, and we will extract them
# without the -p option so that the ftp files will not be world-writable.
	cd .. ; chmod -R g+w acl2-sources ; chmod -R o+w acl2-sources ; tar cvf /tmp/acl2.tar acl2-sources ; chmod -R o-w acl2-sources
	mv /tmp/acl2.tar .
	compress acl2.tar
	sum acl2.tar.Z > SUM
	rm -f workxxx
	rm -f workyyy

# Consider "make test DOC" if running late at night.
test: full init certify-books-test proofs

big-test: full init DOC move-large small certify-books-test proofs
