include Makefile.setup

srcdist=mrgprogs.src
bindist=mrgprogs.bin
srctar=${srcdist}.tar.gz
srczip=${srcdist}.zip
bintar=${bindist}.tar.gz
binzip=${bindist}.zip
webdir=../web/camelot
webprogs=${webdir}/programs
version_file=${webdir}/version.php
#localbindir ?= $(MRGLOCALBINDIR)

.PHONY: distrib local clean


default:
	@echo "Type \"make dist\" to create distribution files and export them to the MRG webpage."
	@echo "Type \"make local\" to compile camelot, gf and gdf and copy them to $(localbindir)."

dist: src bin rpm
	cvs commit -m "Automated update of Camelot distribution" ${webdir}
	rm -rf ${srcdist} ${bindist}

src:
	rm -rf ${srcdist}
	cvs checkout -d ${srcdist} ProgDist
	cp misc/dist.README ${srcdist}/README
	cp misc/dist.INSTALL ${srcdist}/INSTALL
	find ${srcdist} -name CVS -prune -exec rm -rf {} \;
	tar czf ${srctar} ${srcdist}
	zip -r  ${srczip} ${srcdist}
	cp ${srctar} ${srczip} ${webprogs}
	rm -rf ${srctar} ${srczip}

# Maybe we should have a top-level makefile in the source distribution ?

# Careful: bin requires that ${srcdist} is already checked out

bin:
	rm -rf ${bindist}
	mkdir ${bindist}
	cd ${srcdist}/Camelot/src && make standalone &&  cp camelot Camelotlib.class ${PWD}/${bindist}
	cp -r ${srcdist}/Camelot/examples ${PWD}/${bindist}
	cd ${srcdist}/Grail/gdf/src &&  make standalone &&  cp gdf ${PWD}/${bindist}
	cd ${srcdist}/Grail/gf/src && make standalone && cp gf ${PWD}/${bindist}
	cd ${srcdist}/LFD_inference && make && cp lfd_infer ${PWD}/${bindist}
	echo "<!-- Camelot compiler version for inclusion in index.php -->" > ${version_file}
	${bindist}/camelot --version | sed 's/Camelot compiler //' >> ${version_file}
	tar czf ${bintar} ${bindist}
	zip -r ${binzip} ${bindist}
	cp ${bintar} ${binzip} ${webprogs}
	rm -rf ${bintar} ${binzip}

rpm:
	@echo "WARNING: don't know how to make rpms yet"


# Create standalone versions of the programs and copy them 
# to the DICE mrg filespace
local:
	cd Camelot/src; make standalone; cp camelot Camelotlib.class ${localbindir}
	cd Grail/gdf/src; make standalone; chmod a+rx gdf; cp gdf ${localbindir}
	cd Grail/gf/src; make standalone; chmod a+rx gf; cp gf ${localbindir}
	cd LFD_inference; make ; chmod a+rx lfd_infer; cp lfd_infer ${localbindir}
	cd ${localbindir}; chmod a+r Camelotlib.class; chmod a+rx camelot gf gdf

clean:
	rm -rf ${srcdist} ${srctar} ${srczip} ${bintar} ${binzip}
	cd sml-jvm; make clean
	cd Camelot/src; make clean
	cd Grail/gf/src; make clean
	cd Grail/gdf/src; make clean
	cd LFD_inference; make clean

