
ifeq ($(prefix),)
prefix:=`realpath ./install_tmp`
endif

PKG_NAME:=dbdoc
PKG_VERSION:=0.1.2

SUBDIRS:=scripts examples
XSLDIRS:=common docbook sql xhtml
XSLFILES:=\
	common/field.xsl \
	common/index.xsl \
	docbook/article.xsl \
	docbook/docbook2fo.xsl \
	docbook/msg.xml \
	docbook/param.xsl \
	sql/create_table.xsl \
	sql/drop_table.xsl \
	sql/index.xsl \
	sql/param.xsl \
	sql/common.xsl \
	sql/insert.xsl \
	sql/oracle.xml \
	sql/oracle8.xml \
	sql/postgresql.xml \
	xhtml/msg.xml \
	xhtml/param.xsl \
	xhtml/singlehtml.xsl
XSLDIRS:=common docbook sql xhtml
EXAMPLEFILES:=example1.dbdoc

DISTFILES:= \
	Makefile README \
	$(addprefix xsl/, $(XSLFILES)) \
	scripts/Makefile scripts/dbdoc.in \
	examples/Makefile $(addprefix examples/,$(EXAMPLEFILES))
DISTDIRS:=scripts xsl examples $(addprefix xsl/,$(XSLDIRS))

all:
	for dir in $(SUBDIRS); do \
		$(MAKE) -C $$dir prefix=$(prefix) all; \
	done

clean:
	for dir in $(SUBDIRS); do \
		$(MAKE) -C $$dir prefix=$(prefix) clean; \
	done

distclean: 
	for dir in $(SUBDIRS); do \
		$(MAKE) -C $$dir prefix=$(prefix) distclean; \
	done
	rm -rf dist-tmp

install:
	install -d $(prefix)
	for dir in $(SUBDIRS); do \
		$(MAKE) -C $$dir prefix=$(prefix) install; \
	done
	#
	install -d $(prefix)/share/dbdoc/xsl
	for dir in $(XSLDIRS); do install -d $(prefix)/share/dbdoc/xsl/$$dir; done
	for f in $(XSLFILES); do \
		install xsl/$$f $(prefix)/share/dbdoc/xsl/$$f; \
	done

dist:
	mkdir -p dist-tmp/$(PKG_NAME)-$(PKG_VERSION)
	for dir in $(DISTDIRS); do mkdir -p dist-tmp/$(PKG_NAME)-$(PKG_VERSION)/$$dir; done
	for f in $(DISTFILES); do cp -a $$f dist-tmp/$(PKG_NAME)-$(PKG_VERSION)/$$f; done
	tar czf $(PKG_NAME)-$(PKG_VERSION).tar.gz -C dist-tmp $(PKG_NAME)-$(PKG_VERSION)
	tar cjf $(PKG_NAME)-$(PKG_VERSION).tar.bz2 -C dist-tmp $(PKG_NAME)-$(PKG_VERSION)

ChangeLog:
	cvs2cl -w600 --fsf

.PHONY: ChangeLog all clean distclean dist
