include Makefile.defs

all: nmstl/callback NMSTL src/*.cc
	$(MAKE) -C src
	$(MAKE) -C SRC
	$(MAKE) -C test
	$(MAKE) -C example
	$(MAKE) -C EXAMPLE
	$(MAKE) -C java

install: all docs
	mkdir -p $(rootdir)$(libdir)
	install src/libnmstl.so.0 SRC/libNMSTL.so.0 $(rootdir)$(libdir)
	ln -sf libnmstl.so.0 $(rootdir)$(libdir)/libnmstl.so
	ln -sf libNMSTL.so.0 $(rootdir)$(libdir)/libNMSTL.so
	mkdir -p $(rootdir)$(includedir)/nmstl $(rootdir)$(includedir)/NMSTL
	install `ls -d nmstl/[a-z]*[a-z] | grep -v CVS` $(rootdir)$(includedir)/nmstl
	install `ls -d NMSTL/[a-z]*[a-z] | grep -v CVS` $(rootdir)$(includedir)/NMSTL
	mkdir -p $(rootdir)$(bindir)
	install bin/wtf $(rootdir)$(bindir)
	mkdir -p $(rootdir)$(docdir)/$(PACKAGE)-$(VERSION)
	install README LICENSE $(rootdir)$(docdir)/$(PACKAGE)-$(VERSION)
	cd doc ; tar cf - html | ( cd $(rootdir)$(docdir)/$(PACKAGE)-$(VERSION) ; tar xfv - )

distdir = $(PACKAGE)-$(VERSION)

docs: nmstl/callback NMSTL
	$(MAKE) -C doc

nmstl/callback: gencallback.pm
	perl gencallback.pm > nmstl/callback

NMSTL: nmstl/callback genuc.pm nmstl/*[a-z] example/[a-z]*.cc src/*.cc
	rm -rf NMSTL SRC EXAMPLE
	perl genuc.pm
	perl -pe 's/nmstl/NMSTL/g' src/Makefile > SRC/Makefile
	perl -pe 's/nmstl/NMSTL/g' example/Makefile > EXAMPLE/Makefile

testdist:
	cd $(PACKAGE)-$(VERSION) && ./configure && $(MAKE)

distfiles:
	rm -rf DISTFILES tmpbuild
	mkdir tmpbuild
	cp -R CVS tmpbuild
	cd tmpbuild && cvs update -dP | grep '^U ' | cut -c3- > ../DISTFILES1
	( echo configure; echo nmstl.spec ; echo doc/html; echo nmstl/callback ) >> DISTFILES1
	perl -ne 'chomp; print "$$_\n" if s~^(nmstl/|src/|example/)~uc $$1~e && -e $$_' DISTFILES1 > DISTFILES2
	rm -rf tmpbuild
	cat DISTFILES1 DISTFILES2 | sort > DISTFILES
	rm DISTFILES1 DISTFILES2

dist: nmstl/callback NMSTL docs
	-rm -rf $(distdir) $(distdir).tar.gz
	mkdir $(distdir)
	chmod 755 $(distdir)
	cat DISTFILES | xargs tar cf - | ( cd $(distdir) ; tar xf - )
	tar cfv - $(distdir) | gzip -c > $(distdir).tar.gz

publish:
	scp $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)-*.rpm \
		nmstl.sourceforge.net:/home/groups/n/nm/nmstl/htdocs/releases
	ssh nmstl.sourceforge.net /home/groups/n/nm/nmstl/htdocs/releases/release $(PACKAGE)-$(VERSION)
	ncftpput upload.sourceforge.net incoming $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)-*.rpm bin/wtf

rpm:
	rpmbuild -ta $(PACKAGE)-$(VERSION).tar.gz
	cp /usr/src/redhat/SRPMS/$(PACKAGE)-$(VERSION)-* .
	cp /usr/src/redhat/RPMS/*/$(PACKAGE)-$(VERSION)-* .

clean:
	find . -name 'core*' -exec rm {} \;
	rm -f nmstl/callback
	rm -rf NMSTL SRC EXAMPLE
	$(MAKE) -C src clean
	$(MAKE) -C test clean
	$(MAKE) -C example clean
	$(MAKE) -C java clean
	$(MAKE) -C doc clean
