# -*- mode: Makefile; -*-

# cert.pl build system
# Copyright (C) 2008-2011 Centaur Technology
#
# Contact:
#   Centaur Technology Formal Verification Group
#   7600-C N. Capital of Texas Highway, Suite 300, Austin, TX 78731, USA.
#   http://www.centtech.com/
#
# This program 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 program 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 program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
#
# Original authors: Sol Swords <sswords@centtech.com>
#                   Jared Davis <jared@centtech.com>
#
# NOTE: This file is not part of the standard ACL2 books build process; it is
# part of an experimental build system.  The ACL2 developers do not maintain
# this file.


# make_cert -- this file can be included in a GNU Makefile (with SHELL set to
# bash) to provide a rule for certifying ACL2 books.

# BOZO do we still need this?
SHELL := $(shell which bash)

# Default ACL2 to whatever 'acl2' is in the path
export ACL2 ?= acl2

# If this is non-empty, we'll print various debugging messages.
export ACL2_BOOKS_DEBUG ?=

# If this is non-empty, we'll execute the ON_FAILURE_CMD whenever anything
# fails.  For instance, you could email yourself or something.
export ON_FAILURE_CMD ?=

# If this is non-empty, we'll create .time files that can be used by
# critpath.pl
export TIME_CERT ?=

# Typically you want to inhibit most proof output during certification, since
# this can greatly reduce the size of .out files.
export INHIBIT ?= (set-inhibit-output-lst (list (quote prove) \
                                         (quote proof-tree) \
                                         (quote warning) \
                                         (quote observation) \
                                         (quote event) \
                                         (quote expansion)))

# Modeline for .out files.  We like to have the .out files open in auto-revert
# mode, for those cases where you are watching the file as it is being
# certified.
export OUTFILE_HEADER ?= "-*- Mode: auto-revert -*-"

# Max number of seconds to wait for files to appear before giving up.  Don't be
# scared by this!  Ordinarily we don't even have to wait at all.  But if the
# exit status of ACL2 indicates that the certification succeeded without the
# .cert file having appeared, we'll start polling in one-second intervals to
# see if the file shows up.
export MAX_NFS_LAG ?= 10

# Avoid loading customization file unless environment variable is already set.
export ACL2_CUSTOMIZATION ?= NONE

# STARTJOB can be set in the environment to be some other command than the shell,
# which should take the syntax "startjob -c 'shell command'".  For example, this
# could be a queueing command to submit the job to a cluster.
export STARTJOB ?= $(SHELL)

# MAKE_CERT_PL must point to wherever make_cert_help.pl lives.
export MAKE_CERT_PL ?= $(ACL2_SYSTEM_BOOKS)/make_cert_help.pl


# A cert file is made using the two-pass scheme iff the .acl2x file is
# one of its dependencies.  Simpler and hopefully more reliable than
# the previous scheme.  This pattern rule doesn't need to have the
# .acl2x as a dependency because that dependency is generated by
# cert.pl independently, for files containing the phrase
# "two-pass certification".

ifneq ($(ACL2_PCERT),)

%.cert : %.lisp
	@$(MAKE_CERT_PL) "$*" "complete" "no_acl2x" $^
	@echo "Done $*.cert"

%.pcert1 :
	@$(MAKE_CERT_PL) "$*" $(if $(findstring 1,$(pcert)),"convert","pcertifyplus") \
                          $(if $(findstring 1,$(acl2x)),"yes","no") $^
	@echo "Done $*.pcert1"

%.pcert0 : %.lisp
	@$(MAKE_CERT_PL) "$*" "pcertify" $(if $(findstring 1,$(acl2x)),"yes","no") $^
	@echo "Done $*.pcert0"

%.acl2x : %.lisp
	@$(MAKE_CERT_PL) "$*" $(if $(findstring 1,$(acl2xskip)),"acl2xskip","acl2x") "yes" $^

else

%.cert : %.lisp
	@$(MAKE_CERT_PL) "$*" "certify" $(if $(findstring 1,$(acl2x)),"yes","no") $^

%.acl2x : %.lisp
	@$(MAKE_CERT_PL) "$*" $(if $(findstring 1,$(acl2xskip)),"acl2xskip","acl2x") "yes" $^

endif

