]> git.ipfire.org Git - thirdparty/man-pages.git/blob - share/mk/build/examples/src.mk
share/mk/: Reorganize build system
[thirdparty/man-pages.git] / share / mk / build / examples / src.mk
1 # Copyright 2021-2024, Alejandro Colomar <alx@kernel.org>
2 # SPDX-License-Identifier: LGPL-3.0-only WITH LGPL-3.0-linking-exception
3
4
5 ifndef MAKEFILE_BUILD_EX_SRC_INCLUDED
6 MAKEFILE_BUILD_EX_SRC_INCLUDED := 1
7
8
9 include $(MAKEFILEDIR)/build/_.mk
10 include $(MAKEFILEDIR)/configure/build-depends/findutils.mk
11 include $(MAKEFILEDIR)/configure/build-depends/grep.mk
12 include $(MAKEFILEDIR)/configure/build-depends/mandoc.mk
13 include $(MAKEFILEDIR)/configure/build-depends/sed.mk
14 include $(MAKEFILEDIR)/configure/directory_variables.mk
15 include $(MAKEFILEDIR)/src.mk
16
17
18 _UNITS_ex_src := \
19 $(patsubst $(MANDIR)/%, $(_MANDIR)/%, \
20 $(shell \
21 $(FIND) $(MANDIR)/* -type f \
22 | $(GREP) '$(MANEXT)' \
23 | $(XARGS) $(GREP) -H '^\.\\" SRC BEGIN ' \
24 | $(SED) 's,:\.\\" SRC BEGIN (,.d/,' \
25 | $(SED) 's/)//' \
26 | $(SORTMAN) \
27 | $(SED) 's,:,\\:,g' \
28 ) \
29 )
30 _UNITS_ex_h := $(filter %.h,$(_UNITS_ex_src))
31 _UNITS_ex_c := $(filter %.c,$(_UNITS_ex_src))
32
33
34 $(_UNITS_ex_src): $$(patsubst $(_MANDIR)/%.d,$(MANDIR)/%,$$(@D)) $(MK) | $$(@D)/
35 $(_UNITS_ex_c): $$(filter $$(@D)/%.h,$(_UNITS_ex_h))
36 $(_UNITS_ex_src):
37 $(info SED $@)
38 <$< \
39 $(SED) -n \
40 -e '/^\.TH/,/^\.SH/{/^\.SH/!p}' \
41 -e '/^\.SH EXAMPLES/p' \
42 -e "/^\... SRC BEGIN ($(@F))$$/,/^\... SRC END$$/p" \
43 | $(MANDOC) -Tutf8 \
44 | $(SED) '/^[^ ]/d' \
45 | $(SED) 's/^ //' \
46 >$@
47
48
49 .PHONY: build-ex-src
50 build-ex-src: $(_UNITS_ex_src);
51
52
53 endif # include guard