Debian Codegraph @

engine/man/Makefile

raw
1 prefix = /usr/local
2 mandir = $(prefix)/man
3 INSTALL = install
4 INSTALL_DATA = ${INSTALL} -m 644
5
6 # By default, the man pages are generated using a copy of go-md2man built from
7 # the vendored sources in this directory. This behavior can be overridden by
8 # setting the GO_MD2MAN variable to the name/path of an existing go-md2man
9 # binary.
10 GO_MD2MAN ?= .build/go-md2man
11
12 ALL_PAGES := $(wildcard *.*.md)
13
14 # Determine which manual sections we are generating pages for
15 # by isolating the last part of the filename before the extension
16 # and eliminating duplicates.
17 man_section = $(lastword $(subst ., ,$(1)))
18 sections := $(sort $(foreach page,$(ALL_PAGES:.md=),$(call man_section,$(page))))
19
20 # Dynamically generate pattern rules for each manual section
21 # so make knows how to build a target like man8/dockerd.8.
22 define MANPAGE_template
23 man$(1)/%.$(1): %.$(1).md $(if $(findstring file,$(origin GO_MD2MAN)),$(GO_MD2MAN)) | man$(1)
24 $(GO_MD2MAN) -in $$< -out $$@
25 endef
26 $(foreach sec,$(sections),$(eval $(call MANPAGE_template,$(sec))))
27
28 # Default target: build all man pages.
29 all: $(foreach page,$(ALL_PAGES:.md=),man$(call man_section,$(page))/$(page))
30
31 # Target for creating the man{1..8} directories as needed.
32 .PRECIOUS: man%
33 man%:
34 -mkdir $@
35
36 .PHONY: install
37 install: all
38 @set -ex; \
39 for sec in $(sections); do \
40 $(INSTALL) -d $(DESTDIR)$(mandir)/man$$sec && \
41 $(INSTALL_DATA) man$$sec/* $(DESTDIR)$(mandir)/man$$sec; \
42 done
43
44 .build/go-md2man: go.mod go.sum
45 GO111MODULE=auto go build -o $@ github.com/cpuguy83/go-md2man/v2
46
47 .PHONY: clean
48 clean:
49 rm -r man* .build