#
# setup/Makefile
#

version     = 3.2.3
datadir     = $(HOME)/share
siteroot    = $(HOME)/var/www
ardir       = $(siteroot)/archive/setup
sitedocroot = $(siteroot)/tree

.PHONY: default asm doc text dist

default: asm

asm: setup.rb
setup.rb: asm.rb setup.rb.in base.rb compat.rb config.rb fileop.rb toplevel.rb
	ruby asm.rb setup.rb.in > $@

clean:
	rm -rf setup.rb NEWS.ja NEWS.en Usage_* doc.*

publish: setup.rb
	cp setup.rb $(datadir)

update:
	update-version --version=$(version) toplevel.rb

doc:
	rm -rf doc.ja; mkdir doc.ja
	rm -rf doc.en; mkdir doc.en
	compile-documents --ja --template=$(datadir)/template/manual.tmpl.ja --nocode=$(datadir)/NOCODE --refrdrc=$(datadir)/refrdrc.ja doc doc.ja
	compile-documents --en --template=$(datadir)/template/manual.tmpl.en --nocode=$(datadir)/NOCODE doc doc.en

text: Usage_ja.txt Usage_en.txt NEWS.ja NEWS.en

Usage_ja.txt: doc/usage.rd.m
	mldoc-split --lang=ja doc/usage.rd.m | crd2plain > $@
Usage_en.txt: doc/usage.rd.m
	mldoc-split --lang=en doc/usage.rd.m | crd2plain > $@

NEWS.ja: NEWS.m
	mldoc-split --lang=ja NEWS.m > $@
NEWS.en: NEWS.m
	mldoc-split --lang=en NEWS.m > $@

dist:
	rm -rf tmp; mkdir tmp
	cd tmp; cvs -Q export -r`echo V$(version) | tr . -` -d setup-$(version) setup
	cd tmp/setup-$(version); make asm doc text
	cd tmp/setup-$(version); rm -rf test web
	cd tmp; tar czf $(ardir)/setup-$(version).tar.gz setup-$(version)
	rm -rf tmp

site:
	erb web/setup.ja.rhtml | wrap-html --template=$(datadir)/template/basic.tmpl.ja | nkf -j > $(sitedocroot)/ja/prog/setup.html
	erb web/setup.en.rhtml | wrap-html --template=$(datadir)/template/basic.tmpl.en > $(sitedocroot)/en/setup.html
	mldoc-split --lang=ja NEWS.m | crd2html --ja > $(sitedocroot)/ja/man/setup/news.html
	mldoc-split --lang=en NEWS.m | crd2html --en > $(sitedocroot)/en/man/setup/news.html
	compile-documents --ja --template=$(datadir)/template/manual.tmpl.ja --nocode=$(datadir)/NOCODE --refrdrc=$(datadir)/refrdrc.ja doc $(sitedocroot)/ja/man/setup
	compile-documents --en --template=$(datadir)/template/manual.tmpl.en --nocode=$(datadir)/NOCODE doc $(sitedocroot)/en/man/setup
