# Makefile to generate a collection distribution archive in .plt
# format, along with utilities to test the current code in DrScheme,
# and some links to doc/Makefile.

# Copyright (C) 2004  Sylvain Beucler
# Copyright (C) 2004  Julien Charles
# Copyright (C) 2004  Pierre Chtel
# Copyright (C) 2004  Cyril Rodas

# This file is part of SpcialK

# SpcialK 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, or (at your option)
# any later version.

# SpcialK 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
# along with program; see the file COPYING. If not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

# $Header: /cvs/ter/specialk/Makefile,v 1.28 2004/06/15 22:22:07 sylvain Exp $

.PHONY: clean doc veryclean link install plt snapshot upload_plt upload_snapshot

all: plt

# Name of the PLT collection
COLLECTION=specialk


# CVS Repository containing module 'specialk'
CVSROOT=/cvs/ter

# Files or directories included in the collection
FILES=doc/doc.txt src/* demos

# DrScheme version
PLT_VERSION=$(shell mzscheme --version | sed "s/.*version \([^,]\+\).*/\1/")


# These settings can be overwritten in a developer-specific
# 'properties' files, which is in the .cvsignore so it is not part of
# the CVS repository
# UNUSED at the moment
-include settings.mk



snapshot upload_snapshot upload_plt upload_pdf: DATE=$(shell date)# +"%Y%m%d")
snapshot plt: DIR=$(COLLECTION)#-$(shell date +"%Y%m%d")

# --replace so one can overwrite an old version
# (Beware: do not install such a .plt when you are working on SpcialK!!!)
# No --all-users, because the user should choose that when using setup-plt
# To install the resulting package: setup-plt [--all-users] specialk.plt
plt: COLLECTS="$(shell mzscheme -emv '(display (car (current-library-collection-paths)))')"
plt: #save_collect prepare_dir $(COLLECTION).plt (: $(FILES)) restore_collect
	-mv $(COLLECTS) $(COLLECTS).temp
	mkdir -p $(COLLECTS)/$(COLLECTION)
	mkdir $(DIR)
	rm -rf $(DIR)
	cvs -d$(CVSROOT) export -d $(DIR) -r HEAD $(COLLECTION)
	cd $(DIR); for i in $(FILES); do cp -a $$i $(COLLECTS)/$(COLLECTION); done
	rm -rf $(DIR)
	mzc --replace --collection-plt $(COLLECTION).plt $(COLLECTION)
	rm -rf $(COLLECTS)
	-mv $(COLLECTS).temp $(COLLECTS)

snapshot:
	mkdir $(DIR)
	cvs -d$(CVSROOT) export -d $(DIR) -r HEAD $(COLLECTION)
	echo "$(DATE)" > $(DIR)/TIMESTAMP
	tar czf $(DIR).tar.gz $(DIR)
	rm -rf $(DIR)

upload_snapshot: snapshot
	curl -F filepath=@specialk.tar.gz -n deptinfo.unice.fr/cgi-bin/twiki/bin/upload/Minfo/PagePersoSylvainBeucler -F filecomment="Sources, doc, exemples, Makefile's<br>[$(DATE)]"

upload_plt: plt
	curl -F filepath=@specialk.plt -n deptinfo.unice.fr/cgi-bin/twiki/bin/upload/Minfo/PagePersoSylvainBeucler -F filecomment="Installateur<br>[$(DATE)]"

upload_pdf:
	cd doc && make specialk.pdf && make specialk-fr.pdf
	curl -F filepath=@doc/specialk.pdf -n deptinfo.unice.fr/cgi-bin/twiki/bin/upload/Minfo/PagePersoSylvainBeucler -F filecomment="English documentation<br>[$(DATE)]"
	curl -F filepath=@doc/specialk-fr.pdf -n deptinfo.unice.fr/cgi-bin/twiki/bin/upload/Minfo/PagePersoSylvainBeucler -F filecomment="Documentation franaise<br>[$(DATE)]"

upload_doc_plt:
	cd doc && make specialk-doc.plt && make specialk-fr-doc.plt
	curl -F filepath=@doc/specialk-fr-doc.plt -n deptinfo.unice.fr/cgi-bin/twiki/bin/upload/Minfo/PagePersoSylvainBeucler -F filecomment="Documentation franaise<br>[$(DATE)]"
	curl -F filepath=@doc/specialk-doc.plt -n deptinfo.unice.fr/cgi-bin/twiki/bin/upload/Minfo/PagePersoSylvainBeucler -F filecomment="English documentation<br>[$(DATE)]"


doc:
	cd doc && make $(COLLECTION)-doc.plt && mv $(COLLECTION)-doc.plt ..

# Create a symbolic link in the .plt-scheme user directory that will
# point here so this directory is recognised as a collection by
# DrScheme
link:
	-mkdir -p $$HOME/.plt-scheme/$(PLT_VERSION)/collects
	rm -f $$HOME/.plt-scheme/$(PLT_VERSION)/collects/$(COLLECTION)
	ln -s `pwd`/src $$HOME/.plt-scheme/$(PLT_VERSION)/collects/$(COLLECTION)

# Install collection in ~/.plt-scheme/<version>/collects
install: plt
	setup-plt $(COLLECTION).plt


clean:
	-find -type f -name "*~" -print0 | xargs -0 rm
	cd doc; make clean

veryclean: clean
	-rm -f $(COLLECTION).plt
	-rm -f $(COLLECTION)-doc.plt
	-rm -f $(COLLECTION)*.tar.gz
	-rm -fr src/compiled
	cd doc; make veryclean
