PROJ=sbo-maintainer-tools

# note to self: after changing this, "make version" to update all 4 scripts.
VERSION=0.9.8

PREFIX=/usr/local
DESTDIR=

SHAREDIR=$(PREFIX)/share
TESTDIR=$(SHAREDIR)/$(PROJ)/sbopkglint.d
BINDIR=$(PREFIX)/bin
MANDIR=$(PREFIX)/man
MAN1DIR=$(MANDIR)/man1
DOCDIR=$(PREFIX)/doc/$(PROJ)-$(VERSION)

DOCS=README QUICKSTART TODO pre-commit-sbolint NEWS
SCRIPTS=sbopkglint sbolint sbofixinfo sbodl explodepkg.sbopkglint

all:
	@echo "Use 'make install PREFIX=<path>' to install $(PROJ)."

install: man
	install -d -m0755 \
		$(DESTDIR)$(TESTDIR) \
		$(DESTDIR)$(SHAREDIR)/$(PROJ) \
		$(DESTDIR)$(BINDIR) \
		$(DESTDIR)$(MAN1DIR) \
		$(DESTDIR)$(DOCDIR)
	install -m0755 $(SCRIPTS) $(DESTDIR)$(BINDIR)/
	sed -i 's,@PREFIX@,$(PREFIX),' $(DESTDIR)$(BINDIR)/sbopkglint
	sed -i 's,@PREFIX@,$(PREFIX),' $(DESTDIR)$(BINDIR)/sbolint
	install -m0644 sbopkglint.d/* $(DESTDIR)$(TESTDIR)/
	install -m0644 pkglist.txt $(DESTDIR)$(SHAREDIR)/$(PROJ)
	install -m0644 $(DOCS) $(DESTDIR)$(DOCDIR)/
	gzip -9c < sbolint.1 > $(DESTDIR)$(MAN1DIR)/sbolint.1.gz
	gzip -9c < sbopkglint.1 > $(DESTDIR)$(MAN1DIR)/sbopkglint.1.gz
	gzip -9c < sbofixinfo.1 > $(DESTDIR)$(MAN1DIR)/sbofixinfo.1.gz
	gzip -9c < sbodl.1 > $(DESTDIR)$(MAN1DIR)/sbodl.1.gz

clean:
	rm -f sbopkglint.1 sbolint.1 sbofixinfo.1 sbodl.1

man: sbopkglint.1 sbolint.1 sbofixinfo.1 sbodl.1

sbolint.1: sbolint
	./sbolint --man > sbolint.1

sbopkglint.1: sbopkglint
	./sbopkglint --man > sbopkglint.1

sbofixinfo.1: sbofixinfo
	./sbofixinfo --man > sbofixinfo.1

sbodl.1: sbodl
	./sbodl --man > sbodl.1

version:
	sh update-version.sh $(VERSION)

# this requires VERSION in this Makefile to be set to the latest git tag.
release: clean
	git archive -o $(PROJ)-$(VERSION).tar.gz --prefix=$(PROJ)-$(VERSION)/ $(VERSION)

.PHONY: all install clean version release
