summaryrefslogtreecommitdiffstats
path: root/share/mk/build
diff options
context:
space:
mode:
Diffstat (limited to 'share/mk/build')
-rw-r--r--share/mk/build/_.mk52
-rw-r--r--share/mk/build/catman.mk89
-rw-r--r--share/mk/build/groff.mk39
-rw-r--r--share/mk/build/html.mk42
-rw-r--r--share/mk/build/pdf.mk68
-rw-r--r--share/mk/build/pre.mk47
-rw-r--r--share/mk/build/ps.mk68
-rw-r--r--share/mk/build/src.mk117
8 files changed, 522 insertions, 0 deletions
diff --git a/share/mk/build/_.mk b/share/mk/build/_.mk
new file mode 100644
index 0000000..bdce760
--- /dev/null
+++ b/share/mk/build/_.mk
@@ -0,0 +1,52 @@
+########################################################################
+# Copyright 2021-2023, Alejandro Colomar <alx@kernel.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+########################################################################
+
+
+ifndef MAKEFILE_BUILD_INCLUDED
+MAKEFILE_BUILD_INCLUDED := 1
+
+
+include $(MAKEFILEDIR)/cmd.mk
+include $(MAKEFILEDIR)/src.mk
+
+
+builddir := .tmp
+
+SYSCONFDIR := $(srcdir)/etc
+
+_MANDIR := $(builddir)/man
+
+
+MKDIR := mkdir -p
+RM := rm
+
+
+NONSO_MAN := $(shell $(FIND) $(MANDIR)/* -type f \
+ | $(GREP) '$(MANEXT)' \
+ | $(XARGS) $(GREP) -l '^\.TH ' \
+ | $(SORT) \
+ | $(SED) 's,:,\\:,g')
+NONSO_MDOC := $(shell $(FIND) $(MANDIR)/* -type f \
+ | $(GREP) '$(MANEXT)' \
+ | $(XARGS) $(GREP) -l '^\.Dt ' \
+ | $(SORT) \
+ | $(SED) 's,:,\\:,g')
+
+
+$(builddir)/%/:
+ +$(info MKDIR $@)
+ +$(MKDIR) $@
+
+
+.PHONY: build
+build: build-catman build-html build-pdf build-ps build-src;
+
+.PHONY: clean
+clean:
+ $(info RM -rf $(builddir))
+ $(RM) -rf $(builddir)
+
+
+endif # include guard
diff --git a/share/mk/build/catman.mk b/share/mk/build/catman.mk
new file mode 100644
index 0000000..7b8766e
--- /dev/null
+++ b/share/mk/build/catman.mk
@@ -0,0 +1,89 @@
+########################################################################
+# Copyright 2021-2023, Alejandro Colomar <alx@kernel.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+########################################################################
+
+
+ifndef MAKEFILE_BUILD_CATMAN_INCLUDED
+MAKEFILE_BUILD_CATMAN_INCLUDED := 1
+
+
+include $(MAKEFILEDIR)/build/_.mk
+include $(MAKEFILEDIR)/build/groff.mk
+include $(MAKEFILEDIR)/cmd.mk
+include $(MAKEFILEDIR)/src.mk
+
+
+groff_man_ignore_grep := $(DATAROOTDIR)/lint/groff/man.ignore.grep
+
+MANWIDTH ?= 80
+TROFF_CHECKSTYLE_LVL := 3
+NROFF_LINE_LENGTH := $(shell $(EXPR) $(MANWIDTH) - 2)
+NROFF_OUT_DEVICE := $(shell $(LOCALE) charmap \
+ | $(GREP) -i 'utf-*8' >/dev/null \
+ && $(ECHO) utf8 \
+ || $(ECHO) ascii)
+
+DEFAULT_NROFFFLAGS := \
+ -T$(NROFF_OUT_DEVICE) \
+ -rLL=$(NROFF_LINE_LENGTH)n \
+ -rCHECKSTYLE=$(TROFF_CHECKSTYLE_LVL) \
+ -ww
+EXTRA_NROFFFLAGS :=
+NROFFFLAGS := $(DEFAULT_NROFFFLAGS) $(EXTRA_NROFFFLAGS)
+
+DEFAULT_GROTTYFLAGS := -c
+EXTRA_GROTTYFLAGS :=
+GROTTYFLAGS := $(DEFAULT_GROTTYFLAGS) $(EXTRA_GROTTYFLAGS)
+GROTTY := grotty
+
+
+_CATMAN_troff := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.cat.troff,$(NONSO_MAN) $(NONSO_MDOC))
+_CATMAN_MAN_set := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.cat.set,$(NONSO_MAN))
+_CATMAN_MDOC_set:= $(patsubst $(MANDIR)/%,$(_MANDIR)/%.cat.set,$(NONSO_MDOC))
+_CATMAN := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.cat,$(NONSO_MAN) $(NONSO_MDOC))
+
+
+$(_CATMAN_troff): %.cat.troff: %.eqn | $$(@D)/
+ $(info EQN $@)
+ ! ($(EQN) -T$(NROFF_OUT_DEVICE) $(EQNFLAGS) <$< 2>&1 >$@) \
+ | $(GREP) ^ >&2
+
+$(_CATMAN_MAN_set): %.cat.set: %.cat.troff $(groff_man_ignore_grep) | $$(@D)/
+ $(info TROFF $@)
+ ! ($(TROFF) $(TROFFFLAGS_MAN) $(NROFFFLAGS) <$< 2>&1 >$@ \
+ | $(GREP) -v -f '$(groff_man_ignore_grep)' \
+ ||:; \
+ ) \
+ | $(GREP) ^ >&2
+
+$(_CATMAN_MDOC_set): %.cat.set: %.cat.troff | $$(@D)/
+ $(info TROFF $@)
+ ! ($(TROFF) $(TROFFFLAGS_MDOC) $(NROFFFLAGS) <$< 2>&1 >$@) \
+ | $(GREP) ^ >&2
+
+$(_CATMAN): %.cat: %.cat.set | $$(@D)/
+ $(info GROTTY $@)
+ $(GROTTY) $(GROTTYFLAGS) <$< >$@
+
+
+.PHONY: build-catman-eqn
+build-catman-eqn: $(_CATMAN_troff);
+
+.PHONY: build-catman-troff-man
+build-catman-troff-man: $(_CATMAN_MAN_set);
+
+.PHONY: build-catman-troff-mdoc
+build-catman-troff-mdoc: $(_CATMAN_MDOC_set);
+
+.PHONY: build-catman-troff
+build-catman-troff: build-catman-troff-man build-catman-troff-mdoc;
+
+.PHONY: build-catman-grotty
+build-catman-grotty: $(_CATMAN);
+
+.PHONY: build-catman
+build-catman: build-catman-grotty;
+
+
+endif # include guard
diff --git a/share/mk/build/groff.mk b/share/mk/build/groff.mk
new file mode 100644
index 0000000..2a5a3de
--- /dev/null
+++ b/share/mk/build/groff.mk
@@ -0,0 +1,39 @@
+########################################################################
+# Copyright 2021-2023, Alejandro Colomar <alx@kernel.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+########################################################################
+
+
+ifndef MAKEFILE_BUILD_GROFF_INCLUDED
+MAKEFILE_BUILD_GROFF_INCLUDED := 1
+
+
+include $(MAKEFILEDIR)/build/_.mk
+include $(MAKEFILEDIR)/cmd.mk
+include $(MAKEFILEDIR)/src.mk
+
+
+DEFAULT_EQNFLAGS :=
+EXTRA_EQNFLAGS :=
+EQNFLAGS := $(DEFAULT_EQNFLAGS) $(EXTRA_EQNFLAGS)
+EQN := eqn
+
+DEFAULT_TROFFFLAGS := -wbreak
+EXTRA_TROFFFLAGS :=
+TROFFFLAGS := $(DEFAULT_TROFFFLAGS) $(EXTRA_TROFFFLAGS)
+TROFF := troff
+
+DEFAULT_TROFFFLAGS_MAN := \
+ $(TROFFFLAGS) \
+ -man
+EXTRA_TROFFFLAGS_MAN :=
+TROFFFLAGS_MAN := $(DEFAULT_TROFFFLAGS_MAN) $(EXTRA_TROFFFLAGS_MAN)
+
+DEFAULT_TROFFFLAGS_MDOC := \
+ $(TROFFFLAGS) \
+ -mdoc
+EXTRA_TROFFFLAGS_MDOC :=
+TROFFFLAGS_MDOC := $(DEFAULT_TROFFFLAGS_MDOC) $(EXTRA_TROFFFLAGS_MDOC)
+
+
+endif # include guard
diff --git a/share/mk/build/html.mk b/share/mk/build/html.mk
new file mode 100644
index 0000000..084654d
--- /dev/null
+++ b/share/mk/build/html.mk
@@ -0,0 +1,42 @@
+########################################################################
+# Copyright 2021-2022, Alejandro Colomar <alx@kernel.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+########################################################################
+
+
+ifndef MAKEFILE_BUILD_HTML_INCLUDED
+MAKEFILE_BUILD_HTML_INCLUDED := 1
+
+
+include $(MAKEFILEDIR)/build/_.mk
+include $(MAKEFILEDIR)/cmd.mk
+include $(MAKEFILEDIR)/src.mk
+
+
+htmlext := .html
+_HTMLDIR := $(builddir)/html
+
+
+DEFAULT_MAN2HTMLFLAGS :=
+EXTRA_MAN2HTMLFLAGS :=
+MAN2HTMLFLAGS := $(DEFAULT_MAN2HTMLFLAGS) $(EXTRA_MAN2HTMLFLAGS)
+MAN2HTML := man2html
+
+
+_HTMLPAGES := $(patsubst $(MANDIR)/%,$(_HTMLDIR)/%$(htmlext),$(MANPAGES))
+
+
+# Use with
+# make MAN2HTMLFLAGS=whatever html
+# The sed removes the lines "Content-type: text/html\n\n"
+$(_HTMLPAGES): $(_HTMLDIR)/%$(htmlext): $(MANDIR)/% | $$(@D)/
+ $(info MAN2HTML $@)
+ $(MAN2HTML) $(MAN2HTMLFLAGS) $< \
+ | $(SED) -e 1,2d >$@
+
+
+.PHONY: build-html html
+build-html html: $(_HTMLPAGES);
+
+
+endif # include guard
diff --git a/share/mk/build/pdf.mk b/share/mk/build/pdf.mk
new file mode 100644
index 0000000..380c6c6
--- /dev/null
+++ b/share/mk/build/pdf.mk
@@ -0,0 +1,68 @@
+########################################################################
+# Copyright 2023, Alejandro Colomar <alx@kernel.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+########################################################################
+
+
+ifndef MAKEFILE_BUILD_PDF_INCLUDED
+MAKEFILE_BUILD_PDF_INCLUDED := 1
+
+
+include $(MAKEFILEDIR)/build/_.mk
+include $(MAKEFILEDIR)/build/groff.mk
+include $(MAKEFILEDIR)/cmd.mk
+include $(MAKEFILEDIR)/src.mk
+
+
+DEFAULT_GROPDFFLAGS :=
+EXTRA_GROPDFFLAGS :=
+GROPDFFLAGS := $(DEFAULT_GROPDFFLAGS) $(EXTRA_GROPDFFLAGS)
+GROPDF := gropdf
+
+
+_PDFMAN_troff := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.pdf.troff,$(NONSO_MAN) $(NONSO_MDOC))
+_PDFMAN_MAN_set := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.pdf.set,$(NONSO_MAN))
+_PDFMAN_MDOC_set:= $(patsubst $(MANDIR)/%,$(_MANDIR)/%.pdf.set,$(NONSO_MDOC))
+_PDFMAN := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.pdf,$(NONSO_MAN) $(NONSO_MDOC))
+
+
+$(_PDFMAN_troff): %.pdf.troff: %.eqn | $$(@D)/
+ $(info EQN $@)
+ ! ($(EQN) -Tpdf $(EQNFLAGS) <$< 2>&1 >$@) \
+ | $(GREP) ^ >&2
+
+$(_PDFMAN_MAN_set): %.pdf.set: %.pdf.troff | $$(@D)/
+ $(info TROFF $@)
+ ! ($(TROFF) -Tpdf $(TROFFFLAGS_MAN) <$< 2>&1 >$@) \
+ | $(GREP) ^ >&2
+
+$(_PDFMAN_MDOC_set): %.pdf.set: %.pdf.troff | $$(@D)/
+ $(info TROFF $@)
+ ! ($(TROFF) -Tpdf $(TROFFFLAGS_MDOC) <$< 2>&1 >$@) \
+ | $(GREP) ^ >&2
+
+$(_PDFMAN): %.pdf: %.pdf.set | $$(@D)/
+ $(info GROPDF $@)
+ $(GROPDF) $(GROPDFFLAGS) <$< >$@
+
+
+.PHONY: build-pdf-eqn
+build-pdf-eqn: $(_PDFMAN_troff);
+
+.PHONY: build-pdf-troff-man
+build-pdf-troff-man: $(_PDFMAN_MAN_set);
+
+.PHONY: build-pdf-troff-mdoc
+build-pdf-troff-mdoc: $(_PDFMAN_MDOC_set);
+
+.PHONY: build-pdf-troff
+build-pdf-troff: build-pdf-troff-man build-pdf-troff-mdoc;
+
+.PHONY: build-pdf-gropdf
+build-pdf-gropdf: $(_PDFMAN);
+
+.PHONY: build-pdf
+build-pdf: build-pdf-gropdf;
+
+
+endif # include guard
diff --git a/share/mk/build/pre.mk b/share/mk/build/pre.mk
new file mode 100644
index 0000000..4c458fa
--- /dev/null
+++ b/share/mk/build/pre.mk
@@ -0,0 +1,47 @@
+########################################################################
+# Copyright 2021-2023, Alejandro Colomar <alx@kernel.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+########################################################################
+
+
+ifndef MAKEFILE_BUILD_PRE_INCLUDED
+MAKEFILE_BUILD_PRE_INCLUDED := 1
+
+
+include $(MAKEFILEDIR)/build/_.mk
+include $(MAKEFILEDIR)/cmd.mk
+include $(MAKEFILEDIR)/src.mk
+
+
+DEFAULT_PRECONVFLAGS :=
+EXTRA_PRECONVFLAGS :=
+PRECONVFLAGS := $(DEFAULT_PRECONVFLAGS) $(EXTRA_PRECONVFLAGS)
+PRECONV := preconv
+
+TBL := tbl
+
+
+_MAN_tbl := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.tbl,$(NONSO_MAN) $(NONSO_MDOC))
+_MAN_eqn := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.eqn,$(NONSO_MAN) $(NONSO_MDOC))
+
+
+$(_MAN_tbl): $(_MANDIR)/%.tbl: $(MANDIR)/% | $$(@D)/
+ $(info PRECONV $@)
+ $(PRECONV) $(PRECONVFLAGS) $< >$@
+
+$(_MAN_eqn): %.eqn: %.tbl | $$(@D)/
+ $(info TBL $@)
+ $(TBL) <$< >$@
+
+
+.PHONY: build-pre-preconv
+build-pre-preconv: $(_MAN_tbl);
+
+.PHONY: build-pre-tbl
+build-pre-tbl: $(_MAN_eqn);
+
+.PHONY: build-pre
+build-pre: build-pre-tbl;
+
+
+endif # include guard
diff --git a/share/mk/build/ps.mk b/share/mk/build/ps.mk
new file mode 100644
index 0000000..5b29dc1
--- /dev/null
+++ b/share/mk/build/ps.mk
@@ -0,0 +1,68 @@
+########################################################################
+# Copyright 2023, Alejandro Colomar <alx@kernel.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+########################################################################
+
+
+ifndef MAKEFILE_BUILD_PS_INCLUDED
+MAKEFILE_BUILD_PS_INCLUDED := 1
+
+
+include $(MAKEFILEDIR)/build/_.mk
+include $(MAKEFILEDIR)/build/groff.mk
+include $(MAKEFILEDIR)/cmd.mk
+include $(MAKEFILEDIR)/src.mk
+
+
+DEFAULT_GROPSFLAGS :=
+EXTRA_GROPSFLAGS :=
+GROPSFLAGS := $(DEFAULT_GROPSFLAGS) $(EXTRA_GROPSFLAGS)
+GROPS := grops
+
+
+_PSMAN_troff := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.ps.troff,$(NONSO_MAN) $(NONSO_MDOC))
+_PSMAN_MAN_set := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.ps.set,$(NONSO_MAN))
+_PSMAN_MDOC_set:= $(patsubst $(MANDIR)/%,$(_MANDIR)/%.ps.set,$(NONSO_MDOC))
+_PSMAN := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.ps,$(NONSO_MAN) $(NONSO_MDOC))
+
+
+$(_PSMAN_troff): %.ps.troff: %.eqn | $$(@D)/
+ $(info EQN $@)
+ ! ($(EQN) -Tps $(EQNFLAGS) <$< 2>&1 >$@) \
+ | $(GREP) ^ >&2
+
+$(_PSMAN_MAN_set): %.ps.set: %.ps.troff | $$(@D)/
+ $(info TROFF $@)
+ ! ($(TROFF) -Tps $(TROFFFLAGS_MAN) <$< 2>&1 >$@) \
+ | $(GREP) ^ >&2
+
+$(_PSMAN_MDOC_set): %.ps.set: %.ps.troff | $$(@D)/
+ $(info TROFF $@)
+ ! ($(TROFF) -Tps $(TROFFFLAGS_MDOC) <$< 2>&1 >$@) \
+ | $(GREP) ^ >&2
+
+$(_PSMAN): %.ps: %.ps.set | $$(@D)/
+ $(info GROPS $@)
+ $(GROPS) $(GROPSFLAGS) <$< >$@
+
+
+.PHONY: build-ps-eqn
+build-ps-eqn: $(_PSMAN_troff);
+
+.PHONY: build-ps-troff-man
+build-ps-troff-man: $(_PSMAN_MAN_set);
+
+.PHONY: build-ps-troff-mdoc
+build-ps-troff-mdoc: $(_PSMAN_MDOC_set);
+
+.PHONY: build-ps-troff
+build-ps-troff: build-ps-troff-man build-ps-troff-mdoc;
+
+.PHONY: build-ps-grops
+build-ps-grops: $(_PSMAN);
+
+.PHONY: build-ps
+build-ps: build-ps-grops;
+
+
+endif # include guard
diff --git a/share/mk/build/src.mk b/share/mk/build/src.mk
new file mode 100644
index 0000000..365c256
--- /dev/null
+++ b/share/mk/build/src.mk
@@ -0,0 +1,117 @@
+########################################################################
+# Copyright 2021-2023, Alejandro Colomar <alx@kernel.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+########################################################################
+
+
+ifndef MAKEFILE_BUILD_SRC_INCLUDED
+MAKEFILE_BUILD_SRC_INCLUDED := 1
+
+
+include $(MAKEFILEDIR)/build/_.mk
+include $(MAKEFILEDIR)/cmd.mk
+include $(MAKEFILEDIR)/src.mk
+include $(MAKEFILEDIR)/verbose.mk
+
+
+PKGCONF_LIBS := libbsd-overlay
+
+
+DEFAULT_CPPFLAGS := $(shell $(PKGCONF) --cflags $(PKGCONF_LIBS) $(HIDE_ERR))
+EXTRA_CPPFLAGS :=
+CPPFLAGS := $(DEFAULT_CPPFLAGS) $(EXTRA_CPPFLAGS)
+
+DEFAULT_CFLAGS := \
+ -std=gnu17 \
+ -Wall \
+ -Wextra \
+ -Wstrict-prototypes \
+ -Wdeclaration-after-statement \
+ -Werror \
+ -Wno-error=unused-parameter \
+ -Wno-error=sign-compare \
+ -Wno-error=format \
+ -Wno-error=uninitialized
+ #-Wno-error=declaration-after-statement
+EXTRA_CFLAGS :=
+CFLAGS := $(DEFAULT_CFLAGS) $(EXTRA_CFLAGS)
+
+DEFAULT_LDFLAGS := \
+ -Wl,--as-needed \
+ -Wl,--no-allow-shlib-undefined \
+ -Wl,--no-copy-dt-needed-entries \
+ -Wl,--no-undefined \
+ $(shell $(PKGCONF) --libs-only-L $(PKGCONF_LIBS) $(HIDE_ERR)) \
+ $(shell $(PKGCONF) --libs-only-other $(PKGCONF_LIBS) $(HIDE_ERR))
+EXTRA_LDFLAGS :=
+LDFLAGS := $(DEFAULT_LDFLAGS) $(EXTRA_LDFLAGS)
+
+DEFAULT_LDLIBS := \
+ -lc \
+ $(shell $(PKGCONF) --libs-only-l $(PKGCONF_LIBS) $(HIDE_ERR))
+EXTRA_LDLIBS :=
+LDLIBS := $(DEFAULT_LDLIBS) $(EXTRA_LDLIBS)
+
+
+CC := cc
+LD := $(CC) $(CFLAGS)
+
+
+_SRCPAGEDIRS := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.d/,$(NONSO_MAN))
+
+_UNITS_src_src := $(patsubst $(MANDIR)/%,$(_MANDIR)/%,$(shell \
+ $(FIND) $(MANDIR)/* -type f \
+ | $(GREP) '$(MANEXT)' \
+ | $(XARGS) $(GREP) -H '^\.\\" SRC BEGIN ' \
+ | $(SED) 's,:\.\\" SRC BEGIN (,.d/,' \
+ | $(SED) 's/)//' \
+ | $(SORT) \
+ | $(SED) 's,:,\\:,g'))
+_UNITS_src_h := $(filter %.h,$(_UNITS_src_src))
+_UNITS_src_c := $(filter %.c,$(_UNITS_src_src))
+_UNITS_src_o := $(patsubst %.c,%.o,$(_UNITS_src_c))
+_UNITS_src_bin := $(patsubst %.c,%,$(_UNITS_src_c))
+
+
+$(_SRCPAGEDIRS): $(_MANDIR)/%.d/: $(MANDIR)/%
+ +$(info MKDIR $@)
+ +$(MKDIR) $@
+ +touch $@
+
+$(_UNITS_src_src): $$(patsubst $(_MANDIR)/%.d,$(MANDIR)/%,$$(@D)) | $$(@D)/
+$(_UNITS_src_c): $$(filter $$(@D)/%.h,$(_UNITS_src_h))
+$(_UNITS_src_src):
+ $(info SED $@)
+ <$< \
+ $(SED) -n \
+ -e '/^\.TH/,/^\.SH/{/^\.SH/!p}' \
+ -e '/^\.SH EXAMPLES/p' \
+ -e "/^\... SRC BEGIN ($(@F))$$/,/^\... SRC END$$/p" \
+ | $(MANDOC) -Tutf8 \
+ | $(SED) '/^[^ ]/d' \
+ | $(SED) 's/^ //' \
+ >$@
+
+$(_UNITS_src_o): %.o: %.c
+ $(info CC $@)
+ $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
+
+$(_UNITS_src_bin): %: %.o
+ $(info LD $@)
+ $(LD) $(LDFLAGS) -o $@ $< $(LDLIBS)
+
+
+.PHONY: build-src-c
+build-src-c: $(_UNITS_src_c);
+
+.PHONY: build-src-cc
+build-src-cc: $(_UNITS_src_o);
+
+.PHONY: build-src-ld
+build-src-ld: $(_UNITS_src_bin);
+
+.PHONY: build-src
+build-src: build-src-ld
+
+
+endif # include guard