# -*- mode: Makefile; -*-

# cert.pl build system
# Copyright (C) 2008-2014 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/
#
# License: (An MIT/X11-style license)
#
#   Permission is hereby granted, free of charge, to any person obtaining a
#   copy of this software and associated documentation files (the "Software"),
#   to deal in the Software without restriction, including without limitation
#   the rights to use, copy, modify, merge, publish, distribute, sublicense,
#   and/or sell copies of the Software, and to permit persons to whom the
#   Software is furnished to do so, subject to the following conditions:
#
#   The above copyright notice and this permission notice shall be included in
#   all copies or substantial portions of the Software.
#
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#   DEALINGS IN THE SOFTWARE.
#
# 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 history)))

# 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)/build/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".

%.cert : %.lisp
# Bug fix 2015-07-11: Previously we were using "$*" here.  That caused problems
# for file names like foo$bar.lisp, because the command we would give to the
# shell would look like make_cert_help.pl "foo$bar.lisp", and the $bar would
# then be subject to shell expansion.  Putting it in single quotes should help
# to defend against this, although it of course won't work for file names with
# single quotes.
	@$(MAKE_CERT_PL) '$*' \
                         $(if $(findstring 1,$(pcert)),"complete","certify") \
                         $(if $(findstring 1,$(pcert)),"no_acl2x",$(if $(findstring 1,$(acl2x)),"yes","no")) \
                         $^

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

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

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