###############################################################################
# Makefile for HOL Light                                                      #
#                                                                             #
# Simple "make" just builds the camlp4 syntax extension "pa_j.cmo", which is  #
# necessary to load the HOL Light core into the OCaml toplevel.               #
#                                                                             #
# The later options such as "make hol" create standalone images, but only     #
# work under Linux when the "ckpt" checkpointing program is installed.        #
#                                                                             #
# See the README file for more detailed information about the build process.  #
#                                                                             #
# Thanks to Carl Witty for 3.07 and 3.08 ports of pa_j.ml and this process.   #
###############################################################################

# Installation directory for standalone binaries. Set here to the user's
# binary directory. You may want to change it to something like /usr/local/bin

BINDIR=${HOME}/bin

# This is the list of source files in the HOL Light core

HOLSRC=sys.ml lib.ml type.ml term.ml thm.ml basics.ml nets.ml           \
       preterm.ml parser.ml printer.ml equal.ml bool.ml drule.ml        \
       tactics.ml itab.ml simp.ml theorems.ml ind-defs.ml class.ml      \
       trivia.ml canon.ml meson.ml quot.ml recursion.ml pair.ml         \
       num.ml arith.ml wf.ml calc_num.ml normalizer.ml grobner.ml       \
       ind-types.ml list.ml realax.ml calc_int.ml realarith.ml          \
       real.ml calc_rat.ml int.ml sets.ml iter.ml cart.ml define.ml     \
       help.ml database.ml

# Build the camlp4 syntax extension file

pa_j.cmo: sources pa_j.ml; ocamlc -c -pp "camlp4r pa_extend.cmo q_MLast.cmo" -I +camlp4 pa_j.ml

# Copy over and modify the sources

sources:; cp ../../*.ml .; \
          cp -f ../diffs/*.ml .; \
          java -jar ../tools/nametheorems.jar *.ml; \
          rm *.ml.old

# Choose the source for the camlp4 syntax extension based on OCaml version
# If this doesn't work, pick the one for (or closest to) the major version
# of OCaml you're using.

pa_j.ml: pa_j_3.04.ml pa_j_3.06.ml pa_j_3.07+2.ml pa_j_3.08.ml pa_j_3.08.1.ml pa_j_3.08.2.ml; cp pa_j_`ocamlc -version`.ml pa_j.ml

# Build a standalone hol image called "hol" (needs Linux and ckpt program)

hol: pa_j.cmo ${HOLSRC};                                                \
     if test `uname` = Linux; then                                       \
     echo -e '#use "make.ml";;\nself_destruct "";;' | ckpt -a SIGUSR1 -n hol.snapshot ocaml;\
     mv hol.snapshot hol;                                               \
     else                                                               \
     echo '******************************************************';     \
     echo 'FAILURE: Image build assumes Linux and ckpt program';        \
     echo '******************************************************';     \
     fi

# Build an image with multivatiate calculus preloaded.

hol.multivariate: ./hol                                                 \
     Multivariate/misc.ml Multivariate/vectors.ml                       \
     Multivariate/topology.ml Multivariate/convex.ml                    \
     Multivariate/dimension.ml Multivariate/analysis.ml;                \
     echo -e 'loadt "Multivariate/make.ml";;\nself_destruct "Preloaded with multivariate analysis";;' | ./hol; mv hol.snapshot hol.multivariate;


# Build an image with analysis and SOS procedure preloaded

hol.sosa: ./hol                                                         \
     Examples/analysis.ml Examples/transc.ml Examples/sos.ml;           \
     echo -e 'loadt "Examples/analysis.ml";;\nloadt "Examples/transc.ml";;\nloadt "Examples/sos.ml";;\nself_destruct "Preloaded with analysis and SOS";;' | ./hol; mv hol.snapshot hol.sosa;

# Build an image with cardinal arithmetic preloaded

hol.card: ./hol Examples/card.ml;                                       \
          echo -e 'loadt "Examples/card.ml";;\nself_destruct "Preloaded with cardinal arithmetic";;' | ./hol; mv hol.snapshot hol.card;

# Build all those

all: hol hol.multivariate hol.sosa hol.card;

# Build binaries and copy them to binary directory

install: hol hol.multivariate hol.sosa hol.card; cp hol hol.multivariate hol.sosa hol.card ${BINDIR}

# Clean up all generated files

clean:; rm -f *.ml *.ml.old pa_j.cmi pa_j.cmo hol hol.multivariate hol.sosa hol.card
