Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
8.2KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_prog_help2man.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_PROG_HELP2MAN([program list], [man directory prefix], [binary prefix])
  8. #
  9. # DESCRIPTION
  10. #
  11. # AX_PROG_HELP2MAN is a macro designed to facilitate usage of help2man. It
  12. # may take three optional arguments:
  13. #
  14. # 1. <program list>: comma-separated m4 list of input programs
  15. #
  16. # Specifies the list of input programs which shall be used to produce man
  17. # pages using help2man. If no value is specified, the macro assumes that
  18. # the sole target will be named $(PACKAGE_NAME). Thus, the two following
  19. # lines are equivalent:
  20. #
  21. # AX_PROG_HELP2MAN
  22. # AX_PROG_HELP2MAN([\$(PACKAGE_NAME)])
  23. #
  24. # 2. <man directory prefix>: directory prefix of the man pages directory
  25. #
  26. # Sets AX_HELP2MAN_PREFIX_MANS to <man directory prefix>. Defaults to
  27. # 'doc/man/man1' if no value is provided. Note that
  28. # AX_HELP2MAN_PREFIX_MANS will always be a subdirectory of the build
  29. # directory.
  30. #
  31. # 3. <binary prefix>:
  32. #
  33. # Sets AX_HELP2MAN_PREFIX_BIN to <binary prefix>. Defaults to
  34. # '$(top_builddir)' if no value is provided. The two following lines are
  35. # equivalent:
  36. #
  37. # AX_PROG_HELP2MAN([subdir/program1, subdir/program2])
  38. # AX_PROG_HELP2MAN([program1, program2], [], [\$(top_builddir)/subdir])
  39. #
  40. # The macro:
  41. #
  42. # - checks that help2man is available on the system.
  43. #
  44. # - provides the configure option --disable-help2man.
  45. #
  46. # - sets the output variable ax_help2man_MANS to the list of man pages
  47. # that shall be generated.
  48. #
  49. # - sets the automake conditional HAVE_HELP2MAN
  50. #
  51. # - sets the substitution variable AX_HELP2MAN_RULES to the required make
  52. # rules, targets and recipes.
  53. #
  54. # Further detail on the macro can be found after the minimal working
  55. # example. Here is a minimal working example:
  56. #
  57. # # configure.ac:
  58. # AX_PROG_HELP2MAN
  59. #
  60. # # Makefile.am:
  61. # if HAVE_HELP2MAN
  62. # man1_MANS = $(ax_help2man_MANS)
  63. # @AX_HELP2MAN_RULES@
  64. # endif
  65. #
  66. # This minimal working example shall work under the following assumptions:
  67. #
  68. # 1. the aforementioned binary has the same name as the project
  69. #
  70. # 2. the project produces a single binary at the root of the build
  71. # directory
  72. #
  73. # 3. the man page shall be generated into the doc/man/man1 directory
  74. #
  75. # Note that adding ax_help2man_MANS to man1_MANS is not needed if the man
  76. # page generation is not mandatory.
  77. #
  78. # The AX_HELP2MAN_RULES substitution variable shall contain:
  79. #
  80. # - a recipe to create, if necessary, the destination directory.
  81. #
  82. # - a generic rule to produce the manpages.
  83. #
  84. # This rule targets the contents of the variable ax_help2man_MANS and its
  85. # recipe shall be akin to the following:
  86. #
  87. # $(HELP2MAN) -l -N --output="$@" --name="$(shell basename $<)" "$(shell dirname $<)/$(shell basename $<)"
  88. #
  89. # Errors from this rule are ignored.
  90. #
  91. # - rules for each input program and target man page.
  92. #
  93. # For each input program, a rule akin to the following shall be available:
  94. #
  95. # $(AX_HELP2MAN_PREFIX_MANS)/program.1: $(AX_HELP2MAN_PREFIX_BIN)/path/to/program
  96. #
  97. # The macro assumes that all man pages shall be generated into the same
  98. # directory (AX_HELP2MAN_PREFIX_MANS) and that all input programs can be
  99. # found in the same directory (AX_HELP2MAN_PREFIX_BIN). If a subset of the
  100. # inputs or outputs have different paths (for instance one of the inputs
  101. # is a script available in $(top_srcdir) whereas the other inputs are
  102. # programs compiled at build time), it can be customized in the
  103. # Makefile.am: the target man page must be added to ax_help2man_MANS, so
  104. # that it becomes a target of the generic rule for man pages and a rule
  105. # must be added to specify its prerequisite:
  106. #
  107. # ax_help2man_MANS += path/to/output/man/page.1
  108. # path/to/output/man/page.1: path/to/input/program.1
  109. #
  110. # Here is a full example for a project where binaries 'program1' and
  111. # 'program2' are compiled at build time whereas 'script' is available in
  112. # the source tree:
  113. #
  114. # # configure.ac:
  115. # AX_PROG_HELP2MAN([program1, program2])
  116. #
  117. # # Makefile.am:
  118. # if HAVE_HELP2MAN
  119. # man1_MANS = $(ax_help2man_MANS)
  120. # @AX_HELP2MAN_RULES@
  121. # ax_help2man_MANS += $(AX_HELP2MAN_PREFIX_MANS)/script.1
  122. # $(AX_HELP2MAN_PREFIX_MANS)/script.1: $(top_srcdir)/script
  123. # endif
  124. #
  125. # Note that this macro should not be called more than once.
  126. #
  127. # LICENSE
  128. #
  129. # Copyright (c) 2017 Harenome Ranaivoarivony-Razanajato <ranaivoarivony-razanajato@hareno.me>
  130. #
  131. # This program is free software; you can redistribute it and/or modify it
  132. # under the terms of the GNU General Public License as published by the
  133. # Free Software Foundation; either version 3 of the License, or (at your
  134. # option) any later version.
  135. #
  136. # This program is distributed in the hope that it will be useful, but
  137. # WITHOUT ANY WARRANTY; without even the implied warranty of
  138. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  139. # Public License for more details.
  140. #
  141. # Under Section 7 of GPL version 3, you are granted additional permissions
  142. # described in the Autoconf Configure Script Exception, version 3.0, as
  143. # published by the Free Software Foundation.
  144. #
  145. # You should have received a copy of the GNU General Public License along
  146. # with this program. If not, see <https://www.gnu.org/licenses/>.
  147. #serial 2
  148. AC_DEFUN_ONCE([AX_PROG_HELP2MAN],
  149. [
  150. dnl The make rules use 'AM_V_P' and 'AM_V_at' which may not be known.
  151. m4_pattern_allow(AM_V_P)
  152. m4_pattern_allow(AM_V_at)
  153. dnl Provide an option for the configure script, and check whether help2man
  154. dnl is available and whether the user wants to use it.
  155. AC_ARG_ENABLE(help2man,
  156. [AS_HELP_STRING([--disable-help2man], [Disable help2man man generation])])
  157. AC_PATH_PROG(HELP2MAN, help2man, false)
  158. AS_IF([test "x$enable_help2man" = "xno"], [HELP2MAN="false"])
  159. AM_CONDITIONAL([HAVE_HELP2MAN], [test "x$HELP2MAN" != "xfalse"])
  160. dnl Default to 'doc' and $(top_builddir) if no prefixes were provided
  161. AC_SUBST(AX_HELP2MAN_PREFIX_MANS, "\$(top_builddir)/m4_ifblank([$2], [doc/man/man1], [$2])")
  162. AC_SUBST(AX_HELP2MAN_PREFIX_BIN, "m4_ifblank([$3], [\$(top_builddir)], [$3])")
  163. ax_help2man_targets_text=""
  164. m4_ifblank([$1],
  165. dnl if no executable path was specified, default to $(PACKAGE_NAME)
  166. [
  167. ax_help2man_mans_list='$(AX_HELP2MAN_PREFIX_MANS)/$(PACKAGE_NAME).1'
  168. ax_help2man_targets_text='$(AX_HELP2MAN_PREFIX_MANS)/$(PACKAGE_NAME).1: $(AX_HELP2MAN_PREFIX_BIN)/$(PACKAGE_NAME)'
  169. ],
  170. dnl else, (if executable path(s) were specified), create rules for each target
  171. [
  172. m4_foreach(target, [$1],
  173. [
  174. ax_help2man_target="target"
  175. ax_help2man_target_name=$(basename "${ax_help2man_target}")
  176. ax_help2man_mans_list="${ax_help2man_mans_list} "'$(AX_HELP2MAN_PREFIX_MANS)/'"${ax_help2man_target_name}"'.1'
  177. ax_help2man_targets_text="${ax_help2man_targets_text}
  178. "'$(AX_HELP2MAN_PREFIX_MANS)/'"${ax_help2man_target_name}"'.1: $(AX_HELP2MAN_PREFIX_BIN)/'"${ax_help2man_target}"
  179. ])
  180. ])
  181. dnl Reminder for $ax_help2man_rules_text:
  182. dnl Do not insert spaces here, make rules require tabs for indentation!
  183. dnl
  184. dnl $(shell dirname $<)/$(shell basename $<) instead of merely $<:
  185. dnl if the make rule prerequisite
  186. dnl (i.e the input program for help2man) is at the root of the directory, the
  187. dnl prerequisite text will only contain the name of the file. However,
  188. dnl help2man needs the leading './'... Fortunately, dirname returns '.' if its
  189. dnl input does not contain slashes!
  190. ax_help2man_rules_text='
  191. # Rule to create the directory for man 1 pages
  192. $(AX_HELP2MAN_PREFIX_MANS):
  193. $(AM_V_at)$(MKDIR_P) @S|@@
  194. # Generic rule to create manpages using help2man
  195. $(ax_help2man_MANS): | $(AX_HELP2MAN_PREFIX_MANS)
  196. @if ! $(AM_V_P); then printf " %-8s %s\n" "HELP2MAN" "@S|@@"; fi
  197. $(AM_V_at)-$(HELP2MAN) -l -N --output="@S|@@" --name="$(shell basename $<)" "$(shell dirname $<)/$(shell basename $<)"
  198. # Targets
  199. '"${ax_help2man_targets_text}"
  200. AC_SUBST([ax_help2man_MANS], ["${ax_help2man_mans_list}"])
  201. AC_SUBST([AX_HELP2MAN_RULES], ["${ax_help2man_rules_text}"])
  202. AM_SUBST_NOTMAKE([AX_HELP2MAN_RULES])
  203. ])