diff Makefile @ 1:55281f14dc9b

Add README file and manpage
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Fri, 03 Feb 2017 16:11:58 +0100
parents a7e41e1a79c8
children 4269feba381e
line wrap: on
line diff
--- a/Makefile	Thu Jan 19 22:39:51 2017 +0100
+++ b/Makefile	Fri Feb 03 16:11:58 2017 +0100
@@ -44,10 +44,34 @@
 PAX :=		pax
 GZIP :=		gzip
 SED :=		sed
+XSLTPROC :=	xsltproc
+DOCBOOK5_MANPAGES_STYLESHEET =	http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl
+DOCBOOK5_MANPAGES_FLAGS =	--stringparam man.authors.section.enabled 0 \
+				--stringparam man.copyright.section.enabled 0
+
+define generate-manpage-rule =
+$(addsuffix .%,$(basename $1)): $(addsuffix .%.xml,$(basename $(firstword $1))) docbook-update-source-data.xsl
+	$$(XSLTPROC) \
+	    --xinclude \
+	    --stringparam package $$(PACKAGE) \
+	    --stringparam version $$(VERSION) \
+	    docbook-update-source-data.xsl $$< | \
+	    $$(XSLTPROC) \
+	    --xinclude \
+	    --output $(firstword $1) \
+	    $$(DOCBOOK5_MANPAGES_FLAGS) \
+	    $$(DOCBOOK5_MANPAGES_STYLESHEET) \
+	    -
+	for alias in $(wordlist 2,$(words $1),$1); do \
+	    ln -sf $(notdir $(firstword $1)) $$$$alias; \
+	done
+endef
 
 DESTDIR ?=
 prefix ?=	/usr/local
 bindir ?=	$(prefix)/bin
+datadir ?=	$(prefix)/share
+mandir ?=	$(datadir)/man
 
 OS_NAME :=	$(shell uname -s)
 OS_RELEASE :=	$(shell uname -r)
@@ -101,11 +125,13 @@
 	tok.o \
 	util.o
 
+MANPAGES = pwm.1
+
 .DEFAULT_TARGET = all
 
 .PHONY: all clean clobber dist install
 
-all: $(PACKAGE)
+all: $(PACKAGE) $(MANPAGES)
 
 XCPPFLAGS =	-DPACKAGE=\"$(PACKAGE)\" \
 		-DVERSION=\"$(VERSION)\"
@@ -146,15 +172,26 @@
 $(PACKAGE): $(OBJS)
 	$(LINK.o) $^ $(LDLIBS) -o $@
 
+$(eval $(call generate-manpage-rule,$(MANPAGES)))
+
 %.o: %.c
 	$(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
 	$(COMPILE.c) -o $@ $<
 
 install:
 	$(INSTALL.exec) $(PACKAGE) "$(DESTDIR)$(bindir)/$(PACKAGE)"
+	for manpage in $(MANPAGES); do \
+	    if [ -L $${manpage} ]; then \
+	        $(INSTALL.link) $${manpage} \
+	            "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
+	    else \
+	        $(INSTALL.data) $${manpage} \
+	            "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
+	    fi \
+	done
 
 clean:
-	rm -f $(PACKAGE) $(OBJS)
+	rm -f $(PACKAGE) $(OBJS) $(MANPAGES)
 
 clobber: clean
 	rm -f $(patsubst %.o,%.d,$(OBJS))