.SUFFIXES:
.SUFFIXES: .rd .rb .html

RD2HTML=rd2 -r rd/rd2html-lib --with-css=style.css --html-charset=EUC-JP \
 -r rt/rt2html-lib \
 --with-part=RT:rt --out-code=euc --with-part=HTML:html

.rd.html:
	$(RD2HTML) $< > $@

.rb.html:
	$(RD2HTML) $< > $@

HTMS=index.html nusdas.html nusdir.html nusschema.html nusdump.html

all: script ext

script: here lower

here: $(HTMS)

lower:
	@cd nusdas; $(MAKE)
	@cd nwpl; $(MAKE)

ext:
	@cd nwplraw; test -f Makefile || ruby extconf.rb; $(MAKE)

$(HTMS): Makefile

nwpl/nwptime.html: nwpl/nwptime.rb
	$(RD2HTML) $< > $@

nwpl/csvfile.html: nwpl/csvfile.rb
	$(RD2HTML) $< > $@

clean:
	-rm -f $(HTMS)

prefix=$(buildroot)/usr
BINDIR=$(prefix)/bin
LIBDIR=$(prefix)/lib/ruby/1.6
DOCDIR=$(prefix)/doc/ruby-nusdas

CP  = install -m 0644
XCP = install -m 0755

install: install-script install-ext

install-ext:
	cd nwplraw; $(MAKE) install

install-script:
	test -d $(LIBDIR) || mkdir -p $(LIBDIR)
	test -d $(DOCDIR) || mkdir -p $(DOCDIR)
	$(CP) nusdas.rb $(LIBDIR)/
	$(CP) *.html $(DOCDIR)/
	:
	test -d $(LIBDIR)/nusdas || mkdir -p $(LIBDIR)/nusdas
	test -d $(DOCDIR)/nusdas || mkdir -p $(DOCDIR)/nusdas
	$(CP) nusdas/*.rb $(LIBDIR)/nusdas/
	$(CP) nusdas/*.html $(DOCDIR)/nusdas/
	:
	test -d $(LIBDIR)/nwpl || mkdir -p $(LIBDIR)/nwpl
	test -d $(DOCDIR)/nwpl || mkdir -p $(DOCDIR)/nwpl
	$(CP) nwpl/*.rb $(LIBDIR)/nwpl/
	$(CP) nwpl/*.html $(DOCDIR)/nwpl/
	:
	test -d $(BINDIR) || mkdir -p $(BINDIR)
	$(XCP) nusdir.rb $(BINDIR)/nusdir
	$(XCP) nusdump.rb $(BINDIR)/nusdump
	$(XCP) nusschema.rb $(BINDIR)/nusschema
