# 
# The LOOP Project
# 
# The LOOP Team, Dresden University and Nijmegen University
# 
# Copyright (C) 2002
# 
# 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 in file COPYING in this or one of the
# parent directories for more details.
# 
# Created 23.1.02 by Hendrik
# 
# Time-stamp: <Monday 8 October 01 17:58:00 tews@ithif51>
# 
# Top level Makefile
# 
# $Id: Makefile,v 1.4 2002/01/24 10:27:40 tews Exp $
# 


######################################################################
#
# CONFIGURE SECTION
#
######################################################################


# Directory for executables. 
# This is where ccslc (and optionally ccslc.opt) will be installed
BINDIR=/usr/local/bin

# Library director.
# This is where the PVS fixedpoints library will be installed.
LIBDIR=/usr/local/lib/ccsl

# In case the optimised compilers ocamlc.opt and ocamlopt.opt are 
# available on your system, you can use them. 
# Changing this variable is normally not necessary, unless you want
# to save 10 seconds during installation.
USEOPT=no
# Uncomment the next line if you want to use the opt versions.
#USEOPT=yes


######################################################################
#
# END OF CONFIGURE SECTION
#
######################################################################

# There should be no need to change anything below.

# OCAMLDIR holds the directory where the ocaml executables can be found
# In all normal circumstances these executables are found via the 
# the search path and OCAMLDIR should stay empty.
OCAMLDIR=
#
# If the executables are not in the search path, then set the variable 
# like
#OCAMLDIR=/usr/local/ocaml-2.04/bin


# insert -g here for compiling with debugging support
export COMPFLAGS=


#append a slash to OCAMLDIR
OCAMLDIR1=$(subst //,/,$(if $(OCAMLDIR),$(OCAMLDIR)/,))

# names of the ocaml binaries

export OCAMLLEX=$(OCAMLDIR1)ocamllex
export OCAMLYACC=$(OCAMLDIR1)ocamlyacc
export OCAMLCP=$(OCAMLDIR1)ocamlcp
export OCAMLDEP=$(OCAMLDIR1)ocamldep
export OCAMLMKTOP=$(OCAMLDIR1)ocamlmktop

ifeq ($(USEOPT),no)
  export OCAMLC=$(OCAMLDIR1)ocamlc
  export OCAMLOPT=$(OCAMLDIR1)ocamlopt
else
  export OCAMLC=$(OCAMLDIR1)ocamlc.opt
  export OCAMLOPT=$(OCAMLDIR1)ocamlopt.opt
endif


PVSLIBDIR=$(LIBDIR)/pvs


all: configure-pvslib
	$(MAKE) -C Keywords -e
	$(MAKE) -C Common -e
	$(MAKE) -C Ccsl -e ccslc

opt: configure-pvslib
	$(MAKE) -C Common -e native
	$(MAKE) -C Ccsl -e ccslc.opt


configure-pvslib:
	sed -e '/let fixedpointlib = ref/ s+ref .*+ref "$(PVSLIBDIR)"+' \
		Common/global.ml > Common/global.ml.tmp
	mv Common/global.ml.tmp Common/global.ml


install:
	mkdir -p $(BINDIR)
	mkdir -p $(PVSLIBDIR)
	cp Ccsl/ccslc $(BINDIR)
	cp Ccsl/ccslc.opt $(BINDIR)
	for f in Lib/Pvs/* ; do \
		cp $$f $(PVSLIBDIR); \
	done


uninstall:
	rm $(BINDIR)/ccsl
	rm $(BINDIR)/ccslc.opt
	rmdir $(BINDIR)
	for f in Lib/Pvs/* ; do \
		rm $(PVSLIBDIR)/$$f; \
	done
	rmdir $(PVSLIBDIR)


depend:
	for f in Keywords Common Ccsl ; do \
		touch $$f/.depend; \
	done
	$(MAKE) -C Keywords depend
	$(MAKE) -C Ccsl depend

clean:
	$(MAKE) -C Common cleanall
	$(MAKE) -C Doc clean


.PHONY: all configure-pvslib clean

