#  $Id: makefile 12359 2009-02-03 16:49:44Z Bill Ellis $
#-------------------------------------------------------------------------------
#  (C) Praxis High Integrity Systems 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)

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


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

# Windows.
ifeq (${TARGET},Windows)
    EXEEXTN:=.exe
endif

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

# Linux.
ifeq (${TARGET},Linux)
    EXEEXTN:=
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

copyall: copywindowsfiles
	cp ./examiner/spark${EXEEXTN}           ./bin/
	cp ./simplifier/spadesimp${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/

ifeq (${TARGET},Windows)
copywindowsfiles:
	# Copy manifests for SICStus tools.
	cp ./simplifier/spadesimp${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

reallycleanall:
	rm -f ./bin/*
	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

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

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

analysetest: analyseallplain
	cp ./sparklalr/spark.rep             ./analyse/generatedanalysis/sparklalr.rep
	cp ./examiner/spark.rep              ./analyse/generatedanalysis/examiner.rep
	cp ./simplifier/spxref_undefined.txt ./analyse/generatedanalysis/simplifier_spxref_undefined.txt
	cp ./wraputility/spark.rep           ./analyse/generatedanalysis/wraputility.rep
	cp ./checker/spxref_undefined.txt    ./analyse/generatedanalysis/checker_spxref_undefined.txt
	cp ./pogs/spark.rep                  ./analyse/generatedanalysis/pogs.rep
	cp ./sparkformat/spark.rep           ./analyse/generatedanalysis/sparkformat.rep
	cp ./sparkmake/spark.rep             ./analyse/generatedanalysis/sparkmake.rep
	-(diff -b -r ./analyse/referenceanalysis ./analyse/generatedanalysis && echo "Matched reference analysis results.") || echo "Did not match reference analysis results!"

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

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