version/0.2
[shelmfish.git] / Makefile
blobb0c181806713547d5f9ae19305caccdfcfd96cfb
1 # Makefile for HelpMessage
2 # Copyright © 2012-2014 Géraud Meyer <graud@gmx.com>
4 # This file is free software; you can redistribute it and/or modify it under
5 # the terms of the GNU General Public License version 2 as published by the
6 # Free Software Foundation.
8 # This package is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 # details.
13 # You should have received a copy of the GNU General Public License along with
14 # this file. If not, see <http://www.gnu.org/licenses/>.
16 # This a GNU Makefile.
18 prefix ?= $(HOME)/.local
19 bindir ?= $(prefix)/bin
20 datarootdir ?= $(prefix)/share
21 docdir ?= $(datarootdir)/doc/$(PACKAGE_TARNAME)
22 mandir ?= $(datarootdir)/man
23 # DESTDIR = # distributors set this on the command line
25 empty :=
26 tab := $(empty) $(empty)
28 PACKAGE_NAME ?= HelpMessage
29 PACKAGE_TARNAME ?= helpmessage
31 # Get the version via git or from the VERSION file or from the project
32 # directory name.
33 VERSION = $(shell test -x version.sh && ./version.sh $(PACKAGE_TARNAME) \
34 || echo "unknown_version")
35 # Allow either to be overwritten by setting DIST_VERSION on the command line.
36 ifdef DIST_VERSION
37 VERSION = $(DIST_VERSION)
38 endif
39 PACKAGE_VERSION = $(VERSION)
41 # Remove the _g<SHA1> part from the $VERSION
42 RPM_VERSION = $(shell echo $(VERSION) | $(SED) -e 's/_g[0-9a-z]\+//')
44 PROGS =
45 SCRIPTS = helpm2pod helpm2man helpm2text helpmselect gitparseopt2helpm helpm4sh
46 TESTS =
47 HELPMDOC = $(HELPMSWITCH) $(HELPM4SHDOC)
48 HELPMSWITCH = helpm2pod
49 HELPM4SHDOC = helpm4sh gitparseopt2helpm helpmselect helpm2text helpm2man
50 HELPMESSAGE = helpmessage.5.helpm
51 TEXTDOC = $(HELPMDOC:%=%.1.txt) $(HELPMESSAGE:%.helpm=%.txt)
52 MANDOC = $(HELPMDOC:%=%.1) $(HELPMESSAGE:%.helpm=%)
53 HTMLDOC = $(HELPMDOC:%=%.1.html) $(HELPMESSAGE:%.helpm=%.html) README.html NEWS.html
54 RELEASEDOC = $(MANDOC) $(HTMLDOC)
55 ALLDOC = $(TEXTDOC) $(MANDOC) $(HTMLDOC)
57 TARNAME = $(PACKAGE_TARNAME)-$(RPM_VERSION)
59 RM ?= rm
60 CP ?= cp
61 MKDIR ?= mkdir
62 INSTALL ?= install
63 SED ?= sed
64 TAR ?= tar
65 TAR_FLAGS = --owner root --group root --mode a+rX,o-w --mtime .
66 MAKE ?= make
67 ASCIIDOC ?= asciidoc
68 ASCIIDOC_FLAGS = -apackagename="$(PACKAGE_NAME)" -aversion="$(VERSION)"
69 POD2MAN ?= pod2man
70 POD2MAN_FLAGS = --utf8 -c "HelpMessage Manuals" -r "$(PACKAGE_NAME) $(VERSION)"
71 POD2HTML ?= pod2html
72 POD2TEXT ?= pod2text
73 HELPM2POD ?= ./helpm2pod
74 HELPM4SH ?= ./helpm4sh
75 MD5SUM ?= md5sum
76 SHA512SUM ?= sha512sum
78 all: build
79 .help:
80 @echo "Available targets for $(PACKAGE_NAME) Makefile:"
81 @echo " .help all configure build clean doc doc-txt doc-helpm doc-man doc-html"
82 @echo " dist install install-doc install-doc-man install-doc-html"
83 @echo "Useful variables for $(PACKAGE_NAME) Makefile:"
84 @echo " prefix DESTDIR MAKE"
85 help: .help
86 .PHONY: .help help all build clean doc doc-txt doc-helpm doc-man doc-html \
87 dist install install-doc install-doc-man install-doc-html
89 build: $(PROGS) $(TESTS)
90 doc: $(ALLDOC)
91 doc-txt: $(TEXTDOC)
92 doc-helpm: $(HELPMDOC:%=%.1.helpm)
93 doc-pod: $(HELPMDOC:%=%.pod)
94 doc-man: $(MANDOC)
95 doc-html: $(HTMLDOC)
97 test: $(TESTS) $(HELPMDOC:%=%.pod) $(HELPMESSAGE:%.5.helpm=%.pod)
98 podchecker $(HELPMDOC:%=%.pod) $(HELPMESSAGE:%.5.helpm=%.pod)
100 install: build
101 $(MKDIR) -p $(DESTDIR)$(bindir)
102 set -e; for prog in $(PROGS) $(SCRIPTS); do \
103 $(INSTALL) -p -m 0755 "$$prog" "$(DESTDIR)$(bindir)/$$prog"; \
104 done
105 install-doc: install-doc-man install-doc-html
106 install-doc-man: doc-man
107 $(MKDIR) -p $(DESTDIR)$(mandir)/man1
108 set -e; for doc in $(MANDOC); do \
109 gzip -9 <"$$doc" >"$$doc".gz; \
110 $(INSTALL) -p -m 0644 "$$doc".gz "$(DESTDIR)$(mandir)/man1/"; \
111 $(RM) "$$doc".gz; \
112 done
113 install-doc-html: doc-html
114 $(MKDIR) -p $(DESTDIR)$(docdir)
115 set -e; for doc in $(HTMLDOC); do \
116 $(INSTALL) -p -m 0644 "$$doc" "$(DESTDIR)$(docdir)/"; \
117 done
119 clean:
120 $(RM) -r $(TARNAME)
121 $(RM) $(PACKAGE_TARNAME)-*.tar $(PACKAGE_TARNAME)-*.tar.gz \
122 $(PACKAGE_TARNAME)-*.tar.gz.md5 $(PACKAGE_TARNAME)-*.tar.gz.sha512
123 $(RM) $(PROGS) $(TESTS)
124 $(RM) *.xml pod2htm* $(HELPMDOC:%=%.1.helpm) \
125 $(HELPMDOC:%=%.pod) $(HELPMESSAGE:%.5.helpm=%.pod) *~ .*~
126 distclean: clean
127 $(RM) ChangeLog $(ALLDOC)
129 $(TARNAME).tar : ChangeLog
130 $(MKDIR) -p $(TARNAME)
131 echo $(VERSION) > $(TARNAME)/VERSION
132 $(CP) -p ChangeLog $(TARNAME)
133 git archive --format=tar --prefix=$(TARNAME)/ HEAD > $(TARNAME).tar
134 $(TAR) $(TAR_FLAGS) -rf $(TARNAME).tar $(TARNAME)
135 $(RM) -r $(TARNAME)
136 dist : $(TARNAME).tar.gz
137 $(TARNAME).tar.gz : $(TARNAME).tar $(RELEASEDOC)
138 $(MKDIR) $(TARNAME)
139 $(CP) -p -P $(RELEASEDOC) $(TARNAME)
140 $(TAR) $(TAR_FLAGS) -rf $(TARNAME).tar $(TARNAME)
141 $(RM) -r $(TARNAME)
142 gzip -f -9 $(TARNAME).tar
143 $(MD5SUM) $(TARNAME).tar.gz > $(TARNAME).tar.gz.md5
144 $(SHA512SUM) $(TARNAME).tar.gz > $(TARNAME).tar.gz.sha512
145 ChangeLog :
146 ( echo "# $@ for $(PACKAGE_NAME) - automatically generated from the VCS's history"; \
147 echo; \
148 ./gitchangelog.sh --tags --tag-pattern 'version\/[^\n]*' \
149 -- - --date-order --first-parent ) \
150 | $(SED) 's/^\[version/\f\[version/' \
151 > $@
153 README.html: README asciidoc.conf
154 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -a readme $<
155 NEWS.html: NEWS asciidoc.conf
156 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article $<
158 $(HELPM4SHDOC:%=%.1.helpm): %.1.helpm: %
159 $(HELPM4SH) helpm $< >$@
160 %.1.helpm: %
161 ./$< -h >$@
162 %.pod: %.5.helpm
163 $(HELPM2POD) - <$< >$@
164 %.pod: %.1.helpm
165 $(HELPM2POD) - <$< >$@
167 %.1: %.pod
168 $(POD2MAN) $(POD2MAN_FLAGS) --section 1 $< >$@
169 %.5: %.pod
170 $(POD2MAN) $(POD2MAN_FLAGS) --section 5 $< >$@
171 %.1.txt %.5.txt: %.pod
172 $(POD2TEXT) --utf8 $< >$@
173 %.1.html %.5.html: %.pod
174 $(POD2HTML) --noindex --title "$(shell printf "%s" "$(@:%.html=%)" | sed 's/\.\([0-9]\)$$/(\1)/' | tr a-z A-Z)" \
175 $< >$@