#****************************************************************************
# PAKCS: The Portland Aachen Kiel Curry System:
# =============================================
#****************************************************************************
# A prototype implementation of the functional logic language Curry
# developed by
#
# Sergio Antoy, Bernd Brassel, Martin Engelke, Michael Hanus, Klaus Hoeppner,
# Johannes Koj, Philipp Niederau, Ramin Sadre, Frank Steiner
#
# (contact: mh@informatik.uni-kiel.de)
#****************************************************************************

# Logfile for make:
MAKELOG=make.log

#
# Install all components of PAKCS
#
.PHONY: all
all: config
	@rm -f ${MAKELOG}
	@echo "Make started at `date`" > ${MAKELOG}
	${MAKE} install 2>&1 | tee -a ${MAKELOG}
	@echo "Make finished at `date`" >> ${MAKELOG}
	@echo "Make process logged in file ${MAKELOG}"

#
# Install all components of PAKCS
#
.PHONY: install
install:
	# install the mcc front-end if necessary:
	@if [ -f mccparser/Makefile ] ; then cd mccparser && ${MAKE} ; fi
	# install the front-end if necessary:
	cd bin && rm -f parsecurry && ln -s .pakcs_wrapper parsecurry
	# pre-compile all libraries:
	@cd lib && ${MAKE} fcy
	# install the Curry2Prolog compiler as a saved system:
	rm -f bin/pakcs bin/curry2prolog
	@if [ -r bin/sicstusprolog -o -r bin/swiprolog ] ; then cd curry2prolog && ${MAKE} ; fi
	# compile all libraries:
	@cd lib && ${MAKE} acy
	# prepare for separate compilation by compiling all librariers to Prolog code:
	@if [ -r bin/pakcs ] ; then cd lib && ${MAKE} pl ; fi
	# compile the Curry Port Name Server demon:
	@if [ -r bin/pakcs ] ; then cd cpns && ${MAKE} ; fi
	# compile the event handler demon for dynamic web pages:
	@if [ -r bin/pakcs ] ; then cd www && ${MAKE} ; fi
	# compile the tools for Curry2Prolog:
	@if [ -r bin/pakcs ] ; then cd tools && ${MAKE} ; fi
	# compile documentation, if necessary:
	@if [ -d docs/src ] ; then cd docs/src && ${MAKE} install ; fi
	chmod -R go+rX .

# Configure installation w.r.t. variables in bin/.pakcs_variables:
.PHONY: config
config:
	@./update-pakcsrc
	@./configure-pakcs

#
# Create documentation for system libraries:
#
.PHONY: libdoc
libdoc:
	@if [ ! -r bin/currydoc ] ; then \
	  echo "Cannot create library documentation: currydoc not available!" ; exit 1 ; fi
	@rm -f ${MAKELOG}
	@echo "Make libdoc started at `date`" > ${MAKELOG}
	@cd lib && ${MAKE} doc 2>&1 | tee -a ../${MAKELOG}
	@echo "Make libdoc finished at `date`" >> ${MAKELOG}
	@echo "Make libdoc process logged in file ${MAKELOG}"

# Install the TasteCurry interpreter (if you wish, however, its use is not
# recommended since it is no longer supported):
.PHONY: tastecurry
tastecurry: config
	rm -f bin/tastecurry
	@if [ ! -r bin/sicstusprolog ] ; then \
	  echo "Cannot install tastecurry: no SICStus Prolog defined!" ; exit 1 ; fi
	cd tastecurry && ${MAKE}
	cd lib && ${MAKE} fl

# Install the Curry->Java compiler (if you wish, however, its use is not
# recommended since it is no longer supported):
.PHONY: curry2java
curry2java: config tastecurry
	if [ -d tc2java/curry ] ; then cd tc2java/curry && ${MAKE} ; fi
	cd bin && rm -f curry2java && ln -s .pakcs_wrapper curry2java

# Clean the system files, i.e., remove the installed PAKCS components
.PHONY: clean
clean:
	rm -f ${MAKELOG}
	${MAKE} cleantools
	cd lib && ${MAKE} clean
	cd examples && ../bin/cleancurry -r
	if [ -d docs/src ] ; then cd docs/src && ${MAKE} clean ; fi
	cd bin && rm -f sicstusprolog swiprolog

# Clean the generated PAKCS tools
.PHONY: cleantools
cleantools:
	cd curry2prolog && ${MAKE} clean
	cd tastecurry && ${MAKE} clean
	cd tools && ${MAKE} clean
	cd cpns && ${MAKE} clean
	cd www && ${MAKE} clean
	if [ -d parser/src/curry ] ; then cd parser/src/curry && ${MAKE} clean ; fi
	if [ -d tc2java/curry ] ; then cd tc2java/curry && ${MAKE} clean ; fi
	cd bin && rm -f curry2java curry2prolog pakcs parsecurry tastecurry

#################################################################################
