# -----------------------------------------------------------------------------
#  (C) Altran Praxis Limited
# -----------------------------------------------------------------------------
# 
#  The SPARK toolset is free software; you can redistribute it and/or modify it
#  under terms of the GNU General Public License as published by the Free
#  Software Foundation; either version 3, or (at your option) any later
#  version. The SPARK toolset 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 distributed with the SPARK toolset; see file
#  COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy of
#  the license.
# 
# =============================================================================

################################################################################
# PURPOSE
#-------------------------------------------------------------------------------
# Makefile for the entire Spark Toolset source distribution
# Build the SPARK Toolset on NT, Solaris, Linux or MacOS X
################################################################################

################################################################################
# BUILD CONFIGURATION
################################################################################

################################################################################
# DETERMINE HOST INFORMATION
################################################################################

# Determine which platform this Makefile is being run on.
TARGET := $(shell uname -s)
GCC_TARGET:=$(shell gcc -dumpmachine)

# Canonicalize the target string.
ifeq ($(findstring CYGWIN_NT,${TARGET}),CYGWIN_NT)
   TARGET:=Windows
endif

################################################################################
# PLATFORM SPECIFIC CONFIGURATION
################################################################################

BUILD_VICTOR:=false

# Windows.
ifeq (${TARGET},Windows)
    EXEEXTN:=.exe
    ifeq (${GCC_TARGET},i686-pc-mingw32)
        BUILD_VICTOR:=true
    endif
endif

# Sun.
ifeq (${TARGET},SunOS)
    EXEEXTN:=
endif

# Linux.
ifeq (${TARGET},Linux)
    EXEEXTN:=
    BUILD_VICTOR:=true
endif

# Darwin (Mac OS X).
ifeq (${TARGET},Darwin)
    EXEEXTN:=
endif

################################################################################
# TARGETS
################################################################################

# Build all of the tools, copy them to bin, and clean up.
all: makeall copyall cleanall

################################################################################
# BUILDS
################################################################################

makeall:
	make -C sparklalr
	make -C examiner
	make -C simplifier
	make -C wraputility
	make -C checker
	make -C pogs
	make -C sparkformat
	make -C sparkmake
	make -C sparksimp
	make -C victor
	make -C victor_wrapper

copyall: copywindowsfiles
	cp ./examiner/spark${EXEEXTN}           ./bin/
	cp ./simplifier/spadesimp${EXEEXTN}     ./bin/
	cp ./simplifier/zombiescope${EXEEXTN}   ./bin/
	cp ./wraputility/wrap_utility${EXEEXTN} ./bin/
	cp ./checker/checker${EXEEXTN}          ./bin/
	cp ./pogs/pogs${EXEEXTN}                ./bin/
	cp ./sparkformat/sparkformat${EXEEXTN}  ./bin/
	cp ./sparkmake/sparkmake${EXEEXTN}      ./bin/
	cp ./sparksimp/sparksimp${EXEEXTN}      ./bin/
	cp ./victor_wrapper/victor${EXEEXTN}    ./bin/
ifeq (${BUILD_VICTOR},true)
	cp ./victor/alt-ergo/alt-ergo.opt       ./bin/alt-ergo${EXEEXTN}
	cp ./victor/vct/bin/vct${EXEEXTN}       ./bin/
	cp ./victor/alt-ergo/smt_prelude.mlw    ./share/spark/
endif
	cp ./victor/vct/run/prelude.fdl         ./share/spark/
	cp ./victor/vct/run/prelude.rul         ./share/spark/
	cp ./victor/vct/run/divmod.rul          ./share/spark/

ifeq (${TARGET},Windows)
copywindowsfiles:
	# Copy manifests for SICStus tools.
	cp ./simplifier/spadesimp${EXEEXTN}.manifest   ./bin/
	cp ./simplifier/zombiescope${EXEEXTN}.manifest ./bin/
	cp ./checker/checker${EXEEXTN}.manifest        ./bin/
	# Copy the required DLLs into bin.
	cp ./dlls/*                                    ./bin/

else
copywindowsfiles:
endif

cleanall:
	make -C sparklalr      clean
	make -C examiner       clean
	make -C simplifier     clean
	make -C wraputility    clean
	make -C checker        clean
	make -C pogs           clean
	make -C sparkformat    clean
	make -C sparkmake      clean
	make -C sparksimp      clean
	make -C victor         clean
	make -C victor_wrapper clean

reallycleanall:
	rm -f ./bin/*
	rm -f ./share/spark/*
	make -C sparklalr      reallyclean
	make -C examiner       reallyclean
	make -C simplifier     reallyclean
	make -C wraputility    reallyclean
	make -C checker        reallyclean
	make -C pogs           reallyclean
	make -C sparkformat    reallyclean
	make -C sparkmake      reallyclean
	make -C sparksimp      reallyclean
	make -C victor         clean
	make -C victor_wrapper reallyclean

analyseall:
	-make -C sparklalr      examine
	-make -C examiner       examine
	-make -C simplifier     spxref
	-make -C wraputility    examine
	-make -C checker        spxref
	-make -C pogs           examine
	-make -C sparkformat    examine
	-make -C sparkmake      examine
	-make -C victor_wrapper examine

analyseallplain:
	-make -C sparklalr      examine
	-make -C examiner       examine
	-make -C simplifier     spxrefplain
	-make -C wraputility    examine
	-make -C checker        spxrefplain
	-make -C pogs           examine
	-make -C sparkformat    examine
	-make -C sparkmake      examine
	-make -C victor_wrapper examine

# Regenerate the reference results.
# (May be used to capture analysis of the current code base).
generaterereference: analyseallplain
	cp ./sparklalr/vcg/sparklalr.rep      ./analyse/referenceanalysis/sparklalr.rep
	cp ./examiner/vcg/mainunits95.rep     ./analyse/referenceanalysis/examiner.rep
	cp ./simplifier/spxref_undefined.txt  ./analyse/referenceanalysis/simplifier_spxref_undefined.txt
	cp ./wraputility/vcg/wrap_utility.rep ./analyse/referenceanalysis/wrap_utility.rep
	cp ./checker/spxref_undefined.txt     ./analyse/referenceanalysis/checker_spxref_undefined.txt
	cp ./pogs/vcg/pogs.rep                ./analyse/referenceanalysis/pogs.rep
	cp ./sparkformat/vcg/sparkformat.rep  ./analyse/referenceanalysis/sparkformat.rep
	cp ./sparkmake/vcg/sparkmake.rep      ./analyse/referenceanalysis/sparkmake.rep
	cp ./victor_wrapper/vcg/victor.rep    ./analyse/referenceanalysis/victor.rep

################################################################################
# END-OF-FILE
