make/launcher/LauncherCommon.gmk
branchihse-manpages-branch
changeset 57043 23d7457ca4c6
parent 57037 91a7d19da889
child 57045 9c7f4a3c4139
equal deleted inserted replaced
57042:c672ade1572d 57043:23d7457ca4c6
    24 #
    24 #
    25 
    25 
    26 include Modules.gmk
    26 include Modules.gmk
    27 include JdkNativeCompilation.gmk
    27 include JdkNativeCompilation.gmk
    28 include ProcessMarkdown.gmk
    28 include ProcessMarkdown.gmk
       
    29 include TextFileProcessing.gmk
    29 
    30 
    30 # Tell the compiler not to export any functions unless declared so in
    31 # Tell the compiler not to export any functions unless declared so in
    31 # the source code. On Windows, this is the default and cannot be changed.
    32 # the source code. On Windows, this is the default and cannot be changed.
    32 # On Mac, we have always exported all symbols, probably due to oversight
    33 # On Mac, we have always exported all symbols, probably due to oversight
    33 # and/or misunderstanding. To emulate this, don't hide any symbols
    34 # and/or misunderstanding. To emulate this, don't hide any symbols
   192   endif
   193   endif
   193 endef
   194 endef
   194 
   195 
   195 
   196 
   196 ################################################################################
   197 ################################################################################
   197 # Process/copy man pages. There should be a one-to-one relationship between
   198 # Create man pages for jmod to pick up. There should be a one-to-one
   198 # executables and man pages (even if this is not always the case), so piggyback
   199 # relationship between executables and man pages (even if this is not always
   199 # man page generation on the launcher compilation.
   200 # the case), so piggyback man page generation on the launcher compilation.
   200 
   201 
   201 ifeq ($(BUILD_MANPAGES), true)
   202 # Only build manpages on unix systems
       
   203 ifeq ($(TARGET_OS_TYPE), unix)
   202   MAN_$(MODULE) := $(call FindModuleManDirs, $(MODULE))
   204   MAN_$(MODULE) := $(call FindModuleManDirs, $(MODULE))
   203 
   205 
   204   $(foreach d, $(MAN_$(MODULE)), \
   206   MAN_FILES_MD := $(wildcard $(addsuffix /*.md, $(call FindModuleManDirs, $(MODULE)))
   205     $(if $(filter %.1, $(call CacheFind, $d)), \
   207   MAN_FILES_TROFF := $(wildcard $(addsuffix /*.1, $(call FindModuleManDirs, $(MODULE)))
   206       $(eval $(MODULE)_$d_NAME := COPY_MAN_$(MODULE)_$(strip $(call RelativePath, $d, $(TOPDIR)))) \
   208 
   207       $(eval $(call SetupCopyFiles, $($(MODULE)_$d_NAME), \
   209   ifneq ($(MAN_FILES_MD), )
   208           SRC := $d, \
   210     # If we got markdown files, ignore the troff files
   209           FILES := $(filter %.1, $(call CacheFind, $d)), \
   211     ifeq ($(PANDOC), )
   210           DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \
   212       $(info Warning: pandoc not found. Not generating man pages)
   211       )) \
   213     else
   212       $(eval MAN_PAGE_TARGETS += $($($(MODULE)_$d_NAME))) \
   214       # Create dynamic man pages from markdown using pandoc.
   213     ) \
   215       # We assume all man pages should reside in section 1.
   214   )
   216 
   215 
   217       PANDOC_FILTER := $(SUPPORT_OUTPUTDIR)/docs/pandoc-manpage-filter
   216   TARGETS += $(MAN_PAGE_TARGETS)
   218       PANDOC_FILTER_SETUP := $(SUPPORT_OUTPUTDIR)/docs/_pandoc_filter_setup.marker
   217 
   219       PANDOC_FILTER_JAVASCRIPT := $(TOPDIR)/make/scripts/pandoc-manpage-filter.js
   218 else
   220 
   219   # Create dynamic man pages from markdown
   221       # Create a usable instance of the wrapper script that calls the pandoc filter
   220 
   222       # (which is written in javascript).
   221   PANDOC_FILTER := $(SUPPORT_OUTPUTDIR)/docs/pandoc-manpage-filter
   223       $(eval $(call SetupTextFileProcessing, CREATE_PANDOC_FILTER, \
   222   PANDOC_FILTER_SETUP := $(SUPPORT_OUTPUTDIR)/docs/_pandoc_filter_setup.marker
   224           SOURCE_FILES := $(TOPDIR)/make/scripts/pandoc-manpage-filter.sh.template, \
   223   PANDOC_FILTER_JAVASCRIPT := $(TOPDIR)/make/scripts/pandoc-manpage-filter.js
   225           OUTPUT_FILE := $(PANDOC_FILTER), \
   224 
   226           REPLACEMENTS := \
   225   # Create a usable instance of the wrapper script that calls the pandoc filter
   227               @@BOOT_JDK@@ => $(BOOT_JDK) ; \
   226   # (which is written in javascript).
   228               @@TOPDIR@@ => $(TOPDIR) ; \
   227   $(eval $(call SetupTextFileProcessing, CREATE_PANDOC_FILTER, \
   229               @@JJS_FLAGS@@ => $(addprefix -J, $(JAVA_FLAGS_SMALL)), \
   228       SOURCE_FILES := $(TOPDIR)/make/scripts/pandoc-manpage-filter.sh.template, \
   230       ))
   229       OUTPUT_FILE := $(PANDOC_FILTER), \
   231 
   230       REPLACEMENTS := \
   232       # Created script must be made executable
   231           @@BOOT_JDK@@ => $(BOOT_JDK) ; \
   233       $(PANDOC_FILTER_SETUP): $(CREATE_PANDOC_FILTER)
   232           @@TOPDIR@@ => $(TOPDIR) ; \
   234 		$(CHMOD) a+rx $(PANDOC_FILTER)
   233           @@JJS_FLAGS@@ => $(addprefix -J, $(JAVA_FLAGS_SMALL)), \
   235 		$(TOUCH) $@
   234   ))
   236 
   235 
   237       # The norm in man pages is to display code literals as bold, but pandoc
   236   # Created script must be made executable
   238       # "correctly" converts these constructs (encoded in markdown using `...`
   237   $(PANDOC_FILTER_SETUP): $(CREATE_PANDOC_FILTER)
   239       # or ```...```) to \f[C]. Ideally, we should use the filter to encapsulate
   238 	$(CHMOD) a+rx $(PANDOC_FILTER)
   240       # the Code/CodeBlock in Strong. While this works for Code, pandoc cannot
   239 	$(TOUCH) $@
   241       # correctly render man page output for CodeBlock wrapped in Strong. So we
   240 
   242       # take the easy way out, and post-process the troff output, replacing
   241   # The norm in man pages is to display code literals as bold, but pandoc
   243       # \f[C] with \f[CB]. This has the added benefit of working correctly on
   242   # "correctly" converts these constructs (encoded in markdown using `...`
   244       # pandoc prior to version 2.0, which cannot properly produced nested
   243   # or ```...```) to \f[C]. Ideally, we should use the filter to encapsulate
   245       # formatting in man pages (see https://github.com/jgm/pandoc/issues/3568).
   244   # the Code/CodeBlock in Strong. While this works for Code, pandoc cannot
   246       #
   245   # correctly render man page output for CodeBlock wrapped in Strong. So we
   247       # As of pandoc 2.3, the termination of formatting is still broken
   246   # take the easy way out, and post-process the troff output, replacing
   248       # (see https://github.com/jgm/pandoc/issues/4973). We need to replace
   247   # \f[C] with \f[CB]. This has the added benefit of working correctly on
   249       # \f[] with \f[R].
   248   # pandoc prior to version 2.0, which cannot properly produced nested
   250       MAN_POST_PROCESS := $(SED) -e 's/\\f\[C\]/\\f\[CB\]/g' \
   249   # formatting in man pages (see https://github.com/jgm/pandoc/issues/3568).
   251           -e 's/\\f\[\]/\\f\[R\]/g'
   250   #
   252 
   251   # As of pandoc 2.3, the termination of formatting is still broken
   253       # Now generate the man pages from markdown using pandoc
   252   # (see https://github.com/jgm/pandoc/issues/4973). We need to replace
   254       MAN_$(MODULE) := $(call FindModuleManDirs, $(MODULE))
   253   # \f[] with \f[R].
   255 
   254   MAN_POST_PROCESS := $(SED) -e 's/\\f\[C\]/\\f\[CB\]/g' \
   256       $(foreach d, $(MAN_$(MODULE)), \
   255       -e 's/\\f\[\]/\\f\[R\]/g'
   257         $(if $(filter %.md, $(call CacheFind, $d)), \
   256 
   258           $(eval $(MODULE)_$d_NAME := MAN_TO_TROFF_$(MODULE)_$(strip $(call RelativePath, $d, $(TOPDIR)))) \
   257   # We assume all man pages should reside in section 1
   259           $(eval $(call SetupProcessMarkdown, $($(MODULE)_$d_NAME), \
   258 
   260               SRC := $d, \
   259   # Generate man pages from markdown
   261               FILES := $(filter %.md, $(call CacheFind, $d)), \
   260   MAN_$(MODULE) := $(call FindModuleManDirs, $(MODULE))
   262               DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \
   261 
   263               FORMAT := man, \
   262   $(foreach d, $(MAN_$(MODULE)), \
   264               EXTRA_DEPS := $(PANDOC_FILTER_SETUP) \
   263     $(if $(filter %.md, $(call CacheFind, $d)), \
   265                   $(PANDOC_FILTER_JAVASCRIPT), \
   264       $(eval $(MODULE)_$d_NAME := MAN_TO_TROFF_$(MODULE)_$(strip $(call RelativePath, $d, $(TOPDIR)))) \
   266               FILTER := $(PANDOC_FILTER), \
   265       $(eval $(call SetupProcessMarkdown, $($(MODULE)_$d_NAME), \
   267               POST_PROCESS := $(MAN_POST_PROCESS), \
   266           SRC := $d, \
   268               REPLACEMENTS := @@VERSION_SHORT@@ => $(VERSION_SHORT), \
   267           FILES := $(filter %.md, $(call CacheFind, $d)), \
   269           )) \
   268           DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \
   270           $(eval MAN_PAGE_TARGETS += $($($(MODULE)_$d_NAME))) \
   269           FORMAT := man, \
   271         ) \
   270           EXTRA_DEPS := $(PANDOC_FILTER_SETUP) \
   272       )
   271               $(PANDOC_FILTER_JAVASCRIPT), \
   273       TARGETS += $(MAN_PAGE_TARGETS)
   272           FILTER := $(PANDOC_FILTER), \
   274     endif
   273           POST_PROCESS := $(MAN_POST_PROCESS), \
   275   else
   274           REPLACEMENTS := @@VERSION_SHORT@@ => $(VERSION_SHORT), \
   276     # No markdown man pages present
   275       )) \
   277     ifeq ($(MAN_PAGES_ENABLED), true)
   276       $(eval MAN_PAGE_TARGETS += $($($(MODULE)_$d_NAME))) \
   278       # This is a mis-nomer. It really means "copy the pre-generated man pages".
   277     ) \
   279       $(eval $(call SetupCopyFiles, COPY_MAN_FILES,
   278   )
   280           DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1,
   279   TARGETS += $(MAN_PAGE_TARGETS)
   281           FILES := $(MAN_FILES_MD),
       
   282       ))
       
   283       TARGETS += $(COPY_MAN_FILES)
       
   284     endif
       
   285   endif
   280 endif
   286 endif