build: Generate man pages directly from ggo files.
[paraslash.git] / m4 / gengetopt / makefile
1 define ggo_opts
2 --output-dir=$(cmdline_dir) \
3 --set-version="$(GIT_VERSION)" \
4 --arg-struct-name=$(*F)_args_info \
5 --file-name=$(*F).cmdline \
6 --func-name=$(*F)_cmdline_parser \
7 --set-package="para_$(*F)"
8 endef
9
10 .PRECIOUS: $(cmdline_dir)/%.cmdline.c $(cmdline_dir)/%.cmdline.h $(ggo_dir)/%.ggo
11
12 $(cmdline_dir)/%.cmdline.h $(cmdline_dir)/%.cmdline.c: $(ggo_dir)/%.ggo | $(cmdline_dir)
13 @[ -z "$(Q)" ] || echo 'GGO $<'
14 $(Q) $(GENGETOPT) $(ggo_opts) < $<
15 ifeq ($(ggo_descriptions_declared),no)
16 echo 'extern const char *$(*F)_args_info_description;' >> $(cmdline_dir)/$(*F).cmdline.h
17 endif
18
19 $(m4depdir)/%.m4d: $(m4_ggo_dir)/%.m4 | $(m4depdir)
20 @[ -z "$(Q)" ] || echo 'M4D $<'
21 $(Q) m4 -I $(m4_ggo_dir) --debug=i $< 3>&1 1>/dev/null 2>&3 \
22 | awk '{if ($$0 ~ "^m4debug: input read from ") \
23 print "$(ggo_dir)/$(*F).ggo: " $$NF}' > $@
24
25 $(ggo_dir)/%.ggo: $(m4_ggo_dir)/%.m4 $(m4_ggo_dir)/header.m4 | $(ggo_dir)
26 @[ -z "$(Q)" ] || echo 'M4 $<'
27 $(Q) m4 -I $(m4_ggo_dir) $< > $@
28
29 $(help2man_dir)/para_%: $(ggo_dir)/%.ggo | $(help2man_dir)
30 @[ -z "$(Q)" ] || echo 'G2X $<'
31 $(Q) printf "#!/bin/sh\nif [ \"\$$1\" = '--version' ]; then \
32 $(GENGETOPT) $(ggo_opts) --show-version < $<; \
33 elif [ \"\$$1\" = '--help' ]; then \
34 $(GENGETOPT) $(ggo_opts) --show-detailed-help < $<; \
35 else \
36 exit 1; \
37 fi\n" > $@.tmp
38 $(Q) chmod 755 $@.tmp && mv $@.tmp $@