-VERSION=0.1
-YEAR=2018
+VERSION=1.1.1
+YEAR=2020
BUILD_DATE:=$(shell date '+%Y-%m-%d')
BUILD_COMMIT:=$(shell if git rev-parse >/dev/null 2>/dev/null ; then git describe --always --tags ; else echo '<unknown>' ; fi)
+DESTDIR=
+PREFIX=/usr/local
+BINDIR=$(PREFIX)/bin
+MANDIR=$(PREFIX)/share/man
+
CXXFLAGS=-O2 -Wall -Wextra -Wno-parentheses -std=gnu++11 -g
-all: paperjam
+all: paperjam paperjam.1 paperjam.1.html
MODULES=paperjam pdf-tools parse cmds pdf
OBJS=$(addsuffix .o, $(MODULES))
paperjam.o: CXXFLAGS += -DVERSION='"$(VERSION)"' -DYEAR='"$(YEAR)"' -DBUILD_DATE='"$(BUILD_DATE)"' -DBUILD_COMMIT='"$(BUILD_COMMIT)"'
+paperjam.1: paperjam.1.txt
+ a2x -f manpage $<
+
+# The dependency on paperjam.1 is there to serialize both calls of asciidoc,
+# which does not name temporary files safely.
+paperjam.1.html: paperjam.1.txt paperjam.1
+ a2x -f xhtml -D . $<
+
clean:
rm -f *.o
rm -f paperjam
-
-.PHONY: all clean
+ rm -f paperjam.1 paperjam.1.html docbook-xsl.css
+ rm -f *.tar.gz
+
+install: all
+ install -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1
+ install -s paperjam $(DESTDIR)$(BINDIR)/
+ install -m 644 paperjam.1 $(DESTDIR)$(MANDIR)/man1/
+
+release:
+ git tag v$(VERSION)
+ git push --tags
+ git archive --format=tar --prefix=paperjam-$(VERSION)/ HEAD | gzip >paperjam-$(VERSION).tar.gz
+ rsync paperjam-$(VERSION).tar.gz jw:/home/ftp/pub/mj/linux/
+ rsync paperjam.1.html jw:web/static/sw/paperjam/
+ ssh jw 'cd web && bin/release-prog paperjam $(VERSION)'
+
+.PHONY: all clean release