#
# Makefile for blazer-ja-proxy
#

RUBY=ruby
SETUP=setup.rb
VERSION=0.1.10
PKGNAME=blazer-ja-proxy
PKGVER=$(PKGNAME)-$(VERSION)
ardir=.

SFHOST=shell.sourceforge.jp
SFHOME=/home/groups/p/pa/palm-ja-proxy
SFWWW=$(SFHOST):$(SFHOME)/htdocs

# run test scripts
.PHONY: check
check: test

.PHONY: test
test:
	$(RUBY) test/run-test.rb

# wrappers for setup.rb
.PHONY: install .config
install:
	$(RUBY) $(SETUP) $@

.config: config
.PHONY: config
config:
	$(RUBY) $(SETUP) $@

.PHONY: setup
setup:
	$(RUBY) $(SETUP) $@

# make the web site
.PHONY: web
web: web/blazer-ja-proxy/.timestamp

web/blazer-ja-proxy/.timestamp: web/blazer-ja-proxy/README.html web/blazer-ja-proxy/ChangeLog.txt
	touch $@

web/blazer-ja-proxy/README.html: README.ja
	mkdir -p web/blazer-ja-proxy
	rd2 -r rd/rd2html-lib.rb \
		--out-code=euc \
		--html-charset=EUC-JP \
		--html-lang=ja_JP \
		--with-css='../orange.css' \
		--html-title='$(PKGVER) README' $< > $@

web/blazer-ja-proxy/ChangeLog.txt: ChangeLog
	mkdir -p web/blazer-ja-proxy
	cp $< $@

# upload the project web site
.PHONY: upload
upload: CVS/Root web
	@echo uploading
	rsync -e ssh -z -v --delete -L -C -r web/ `cat CVS/Root | cut -f3 -d: | cut -f1 -d@`@$(SFWWW)

# commit
.PHONY: commit
commit: CVS/Root
	log=`ruby -e 'print File.open("ChangeLog").read.split(/^$$/,2)[0]'`;\
	ver=`echo "$$log" | ruby -ne 'print if gsub!(/^- \\((\\d+\\.\\d+\\.\\d+)\\)/, "\\\\1")'`;\
	if [ -n "$$ver" ] && [ "$$ver" != "$(VERSION)" ]; then \
		echo '*** Version in ChangeLog does not match that in Makefile';\
		exit 1;\
	fi && \
	cvs commit -m "$$log" && \
	echo "$$log" &&\
	if [ -n "$$ver" ]; then cvs tag VER_`echo $(VERSION) | tr . _`; fi

# create a tarball
.PHONY: dist
dist: CVS/Root
	rm -rf tmp-dist; mkdir tmp-dist
	cd tmp-dist; cvs -d `cat ../CVS/Root` -Q export -r REL_`echo $(VERSION) | tr . _` -d $(PKGVER) $(PKGNAME)
	(cd tmp-dist; tar cf - $(PKGVER)) | gzip -c -9 > $(ardir)/$(PKGVER).tar.gz
	rm -rf tmp-dist

# test a release version
.PHONY: reltest
reltest: CVS/Root
	rm -rf tmp-reltest; mkdir tmp-reltest
	cd tmp-reltest; cvs -d `cat ../CVS/Root` -Q export -r REL_`echo $(VERSION) | tr . _` -d $(PKGVER) $(PKGNAME)
	make -C tmp-reltest/$(PKGVER) test && rm -rf tmp-reltest
	@echo '*** Make sure there is no files not added to the CVS repository.'

.PHONY: release
release: CVS/Root reltest dist
	!( cvs status -R 2>/dev/null | grep File: | grep -v Up-to-date )

