annotate make/common/ProcessMarkdown.gmk @ 2615:9c70f25ca307

8180472: Pandoc should generate html5 from markdown Reviewed-by: erikj
author ihse
date Wed, 17 May 2017 12:42:58 +0200
parents 481bd01358a9
children
rev   line source
ihse@2590 1 # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
ihse@2590 2 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ihse@2590 3 #
ihse@2590 4 # This code is free software; you can redistribute it and/or modify it
ihse@2590 5 # under the terms of the GNU General Public License version 2 only, as
ihse@2590 6 # published by the Free Software Foundation. Oracle designates this
ihse@2590 7 # particular file as subject to the "Classpath" exception as provided
ihse@2590 8 # by Oracle in the LICENSE file that accompanied this code.
ihse@2590 9 #
ihse@2590 10 # This code is distributed in the hope that it will be useful, but WITHOUT
ihse@2590 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ihse@2590 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ihse@2590 13 # version 2 for more details (a copy is included in the LICENSE file that
ihse@2590 14 # accompanied this code).
ihse@2590 15 #
ihse@2590 16 # You should have received a copy of the GNU General Public License version
ihse@2590 17 # 2 along with this work; if not, write to the Free Software Foundation,
ihse@2590 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ihse@2590 19 #
ihse@2590 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ihse@2590 21 # or visit www.oracle.com if you need additional information or have any
ihse@2590 22 # questions.
ihse@2590 23 #
ihse@2590 24
ihse@2590 25 ifeq (,$(_MAKEBASE_GMK))
ihse@2590 26 $(error You must include MakeBase.gmk prior to including ProcessMarkdown.gmk)
ihse@2590 27 endif
ihse@2590 28
ihse@2590 29 # Helper function for SetupProcessMarkdown
ihse@2590 30 # $1: The $1 from SetupProcessMarkdown
ihse@2590 31 # $2: The name of the current source file, relative to $1_SRC
ihse@2590 32 define ProcessMarkdown
ihse@2590 33 $1_$2_OUTPUT_FILE := $$($1_DEST)/$$(basename $2).html
ihse@2590 34 $1_$2_TARGET_DIR := $$(dir $$($1_$2_OUTPUT_FILE))
ihse@2590 35 ifneq ($$($1_CSS), )
ihse@2590 36 ifneq ($$(findstring http:/, $$($1_CSS)), )
ihse@2590 37 $1_$2_CSS_OPTION := --css '$$($1_CSS)'
ihse@2590 38 else
ihse@2615 39 $1_$2_CSS := $$(strip $$(call RelativePath, $$($1_CSS), $$($1_$2_TARGET_DIR)))
ihse@2590 40 $1_$2_CSS_OPTION := --css '$$($1_$2_CSS)'
ihse@2590 41 endif
ihse@2590 42 endif
ihse@2590 43 $1_$2_OPTIONS = $$(shell $$(GREP) _pandoc-options_: $$($1_SRC)/$2 | $$(CUT) -d : -f 2-)
ihse@2590 44 $1_$2_MARKER := $$(subst /,_,$1_$2)
ihse@2590 45
ihse@2590 46 $1_$2_VARDEPS := $$($1_OPTIONS) $$($1_CSS)
ihse@2590 47 $1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \
ihse@2590 48 $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps)
ihse@2590 49
ihse@2590 50 $$($1_$2_OUTPUT_FILE): $$($1_SRC)/$2 $$($1_$2_VARDEPS_FILE)
ihse@2590 51 $$(call LogInfo, Converting $2 to html)
ihse@2590 52 $$(call MakeDir, $$($1_$2_TARGET_DIR) $$(SUPPORT_OUTPUTDIR)/markdown)
ihse@2590 53 $$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \
ihse@2615 54 $$(PANDOC) $$($1_OPTIONS) -f markdown -t html5 --standalone \
ihse@2590 55 $$($1_$2_CSS_OPTION) $$($1_$2_OPTIONS) '$$<' -o '$$@')
ihse@2590 56 ifneq ($$(findstring $$(LOG_LEVEL), debug trace),)
ihse@2590 57 TOO_LONG_LINES=`$$(GREP) -E -e '^.{80}.+$$$$' $$<` || true ; \
ihse@2590 58 if [ "x$$$$TOO_LONG_LINES" != x ]; then \
ihse@2590 59 $$(ECHO) "Warning: Unsuitable markdown in $$<:" ; \
ihse@2590 60 $$(ECHO) "The following lines are longer than 80 characters:" ; \
ihse@2590 61 $$(GREP) -E -n -e '^.{80}.+$$$$' $$< || true ; \
ihse@2590 62 fi
ihse@2590 63 endif
ihse@2590 64
ihse@2590 65 $1 += $$($1_$2_OUTPUT_FILE)
ihse@2590 66 endef
ihse@2590 67
ihse@2590 68 ################################################################################
ihse@2590 69 # Setup make rules for converting a markdown file to html.
ihse@2590 70 #
ihse@2590 71 # Parameter 1 is the name of the rule. This name is used as variable prefix,
ihse@2590 72 # and the targets generated are listed in a variable by that name.
ihse@2590 73 #
ihse@2590 74 # Remaining parameters are named arguments. These include:
ihse@2590 75 # SRC : Source root dir (defaults to dir of first file)
ihse@2590 76 # DEST : Dest root dir
ihse@2590 77 # FILES : List of files to copy with absolute paths, or path relative to SRC.
ihse@2590 78 # Must be in SRC.
ihse@2590 79 # OPTIONS : Additional options to pandoc
ihse@2590 80 #
ihse@2590 81 SetupProcessMarkdown = $(NamedParamsMacroTemplate)
ihse@2590 82 define SetupProcessMarkdownBody
ihse@2590 83 ifeq ($$($1_FILES), )
ihse@2590 84 $$(error FILES is missing in SetupProcessMarkdown $1)
ihse@2590 85 endif
ihse@2590 86
ihse@2590 87 ifeq ($$($1_DEST), )
ihse@2590 88 $$(error DEST is missing in SetupProcessMarkdown $1)
ihse@2590 89 endif
ihse@2590 90
ihse@2590 91 # Default SRC to the dir of the first file.
ihse@2590 92 ifeq ($$($1_SRC), )
ihse@2590 93 $1_SRC := $$(dir $$(firstword $$($1_FILES)))
ihse@2590 94 endif
ihse@2590 95
ihse@2590 96 # Remove any trailing slash from SRC and DEST
ihse@2590 97 $1_SRC := $$(patsubst %/,%,$$($1_SRC))
ihse@2590 98 $1_DEST := $$(patsubst %/,%,$$($1_DEST))
ihse@2590 99
ihse@2590 100 $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \
ihse@2590 101 $$(eval $$(call ProcessMarkdown,$1,$$f)) \
ihse@2590 102 )
ihse@2590 103 endef