Re: Exctracting source code from EXAMPLES

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Stephen,

On 3/21/22 01:02, Alejandro Colomar (man-pages) wrote:
> I like the idea of autogenerating and including a makefile, which allows
> listing the example programs in the process.  In my current makefile, I
> need to run make build-src before any further actions on those files,
> since I don't know them at the time of setting variables.
> 
> I may take some bits from here.

Well, I managed to get everything within the Makefile, with some complex
variable definition; no autogenerated makefiles, and no included
makefiles.  It makes the makefile a bit slow, however, by adding a fixed
initialization overhead:  `make clean` goes from 0.11 s to 1.96 s in my
computer.  2 s is not too much for complex operations, but it's a bit
nasty when you just want to clean, or you just changed one page.  But I
guess any solution will have a similar fixed overhead (or it will be
fast, but will require a separate step such as `make build-src`).

But the result is quite neat and simple, compared to other options:


+SRCPAGEDIRS:=$(patsubst $(MANDIR)/%,$(SRCDIR)/%.d,$(LINTPAGES))
+UNITS_c    := $(patsubst $(MANDIR)/%,$(SRCDIR)/%,$(shell \
+               find $(MANDIR)/man?/ -type f \
+               | grep '$(manext)$$' \
+               | while read m; do \
+                       <$$m \
+                       sed -n "s,^\.\\"'"'" SRC BEGIN
(\(.*.c\))$$,$$m.d\1,p";\
+               done))




+########################################################################
+# src
+
+$(SRCPAGEDIRS): $(SRCDIR)/%.d: $(MANDIR)/% | $$(@D)/.
+       $(info MKDIR    $@)
+       $(MKDIR) $@
+
+$(UNITS_c): $$(@D)
+       $(info SED      $@)
+       <$(patsubst $(SRCDIR)/%.d,$(MANDIR)/%,$<) \
+       sed -n \
+               -e '/^\.TH/,/^\.SH/{/^\.SH/!p}' \
+               -e '/^\.SH EXAMPLES/p' \
+               -e "/^\... SRC BEGIN ($(@F))$$/,/^\... SRC END$$/p" \
+       | $(MAN) -P cat -l - \
+       | sed '/^[^ ]/d' \
+       | sed 's/^       //' \
+       >$@ \
+       || exit $$?
+
+$(SRCDIRS): %/.: | $$(dir %). $(SRCDIR)/.
+
+.PHONY: build-src src
+build-src src: $(UNITS_c) | builddirs-src
+       @:
+
+.PHONY: builddirs-src
+builddirs-src: $(SRCDIRS)
+       @:
+
+


Those two biggie snippets embedded into the Makefile
are similar in essence to the 2 helper scripts you use.
The benefit of embedding them in the Makefile is that I have full
control of it, and can use variables directly from the Makefile.
Also less files :).
And even though it's slower,
I prefer it over having to run `make build-src` manually.


I've updated my 'lint' branch.

Cheers,

Alex

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux