1 # Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
  2 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  3 #
  4 # This code is free software; you can redistribute it and/or modify it
  5 # under the terms of the GNU General Public License version 2 only, as
  6 # published by the Free Software Foundation.  Oracle designates this
  7 # particular file as subject to the "Classpath" exception as provided
  8 # by Oracle in the LICENSE file that accompanied this code.
  9 #
 10 # This code is distributed in the hope that it will be useful, but WITHOUT
 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13 # version 2 for more details (a copy is included in the LICENSE file that
 14 # accompanied this code).
 15 #
 16 # You should have received a copy of the GNU General Public License version
 17 # 2 along with this work; if not, write to the Free Software Foundation,
 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19 #
 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21 # or visit www.oracle.com if you need additional information or have any
 22 # questions.
 23 #
 24 
 25 default: all
 26 
 27 include $(SPEC)
 28 include MakeBase.gmk
 29 include Execute.gmk
 30 include Modules.gmk
 31 include ModuleTools.gmk
 32 include ProcessMarkdown.gmk
 33 include ToolsJdk.gmk
 34 include ZipArchive.gmk
 35 include TextFileProcessing.gmk
 36 
 37 # This is needed to properly setup DOCS_MODULES.
 38 $(eval $(call ReadImportMetaData))
 39 
 40 ################################################################################
 41 # Hook to include the corresponding custom file, if present.
 42 $(eval $(call IncludeCustomExtension, Docs.gmk))
 43 
 44 ################################################################################
 45 # This file generates all documentation for OpenJDK.
 46 #
 47 # We will generate API documentation for two different selections of the source
 48 # code: "Java SE", which contains just the modules covered by the top-level
 49 # module java.se and "JDK", which covers all of Java SE and also all
 50 # other available modules that should be documented, including imported modules,
 51 # if any.
 52 #
 53 # We will also generate separate, free-standing specifications from either
 54 # markdown or existing html files.
 55 #
 56 
 57 ################################################################################
 58 # Javadoc settings
 59 
 60 # On top of the sources that was used to compile the JDK, we need some
 61 # extra java.rmi sources that are used just for javadoc.
 62 MODULES_SOURCE_PATH := $(call PathList, $(call GetModuleSrcPath) \
 63     $(SUPPORT_OUTPUTDIR)/rmic/* $(TOPDIR)/src/*/share/doc/stub)
 64 
 65 # URLs
 66 JAVADOC_BASE_URL := https://docs.oracle.com/pls/topic/lookup?ctx=javase$(VERSION_NUMBER)&id=homepage
 67 BUG_SUBMIT_URL := https://bugreport.java.com/bugreport/
 68 COPYRIGHT_URL := legal/copyright.html
 69 LICENSE_URL := https://www.oracle.com/technetwork/java/javase/terms/license/java$(VERSION_NUMBER)speclicense.html
 70 REDISTRIBUTION_URL := https://www.oracle.com/technetwork/java/redist-137594.html
 71 
 72 # In order to get a specific ordering it's necessary to specify the total
 73 # ordering of tags as the tags are otherwise ordered in order of definition.
 74 JAVADOC_TAGS := \
 75     -tag beaninfo:X \
 76     -tag revised:X \
 77     -tag since.unbundled:X \
 78     -tag spec:X \
 79     -tag specdefault:X \
 80     -tag Note:X \
 81     -tag ToDo:X \
 82     -tag 'apiNote:a:API Note:' \
 83     -tag 'implSpec:a:Implementation Requirements:' \
 84     -tag 'implNote:a:Implementation Note:' \
 85     -tag param \
 86     -tag return \
 87     -tag throws \
 88     -taglet build.tools.taglet.JSpec\$$JLS \
 89     -taglet build.tools.taglet.JSpec\$$JVMS \
 90     -taglet build.tools.taglet.ModuleGraph \
 91     -taglet build.tools.taglet.ToolGuide \
 92     -tag since \
 93     -tag serialData \
 94     -tag factory \
 95     -tag see \
 96     -taglet build.tools.taglet.ExtLink \
 97     -taglet build.tools.taglet.Incubating \
 98     -taglet build.tools.taglet.Preview \
 99     -tagletpath $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes \
100     $(CUSTOM_JAVADOC_TAGS) \
101     #
102 
103 # The reference tags must stay stable to allow for comparisons across the
104 # development cycle. If JAVADOC_TAGS needs to change, make sure that
105 # REFERENCE_TAGS remains unchanged, by copying and hardcoding, if necessary.
106 REFERENCE_TAGS := $(JAVADOC_TAGS)
107 
108 # Which doclint checks to ignore
109 JAVADOC_DISABLED_DOCLINT := accessibility html missing syntax reference
110 
111 # The initial set of options for javadoc
112 JAVADOC_OPTIONS := -use -keywords -notimestamp \
113     -serialwarn -encoding ISO-8859-1 -docencoding UTF-8 -breakiterator \
114     -splitIndex --system none -javafx --expand-requires transitive \
115     --override-methods=summary
116 
117 # The reference options must stay stable to allow for comparisons across the
118 # development cycle.
119 REFERENCE_OPTIONS := -XDignore.symbol.file=true -use -keywords -notimestamp \
120     -serialwarn -encoding ISO-8859-1 -breakiterator -splitIndex --system none \
121     -html5 -javafx --expand-requires transitive
122 
123 # Should we add DRAFT stamps to the generated javadoc?
124 ifeq ($(VERSION_IS_GA), true)
125   IS_DRAFT := false
126 else
127   IS_DRAFT := true
128 endif
129 
130 ################################################################################
131 # General text snippets
132 
133 FULL_COMPANY_NAME := Oracle and/or its affiliates
134 COMPANY_ADDRESS := 500 Oracle Parkway, Redwood Shores, CA 94065 USA
135 
136 JAVA_PLATFORM := Java Platform
137 
138 ifeq ($(IS_DRAFT), true)
139   DRAFT_MARKER_STR := <br><strong>DRAFT $(VERSION_STRING)</strong>
140   ifeq ($(VERSION_BUILD), 0)
141     DRAFT_MARKER_TITLE := $(SPACE)[ad-hoc build]
142   else
143     DRAFT_MARKER_TITLE := $(SPACE)[build $(VERSION_BUILD)]
144   endif
145   DRAFT_TEXT := This specification is not final and is subject to change. \
146       Use is subject to <a href="$(LICENSE_URL)">license terms</a>.
147 
148   # Workaround stylesheet bug
149   HEADER_STYLE := style="margin-top: 9px;"
150 else
151   HEADER_STYLE := style="margin-top: 14px;"
152 endif
153 
154 # $1 - Relative prefix to COPYRIGHT_URL
155 COPYRIGHT_BOTTOM = \
156     <a href="$(strip $1)$(COPYRIGHT_URL)">Copyright</a> \
157     &copy; 1993, $(COPYRIGHT_YEAR), $(FULL_COMPANY_NAME), \
158     $(COMPANY_ADDRESS).<br>All rights reserved. \
159     Use is subject to <a href="$(LICENSE_URL)">license terms</a> and the \
160     <a href="$(REDISTRIBUTION_URL)">documentation redistribution policy</a>. \
161     $(DRAFT_MARKER_STR) <!-- Version $(VERSION_STRING) -->
162 
163 JAVADOC_BOTTOM := \
164     <a href="$(BUG_SUBMIT_URL)">Report a bug or suggest an enhancement</a><br> \
165     For further API reference and developer documentation see the \
166     <a href="$(JAVADOC_BASE_URL)" target="_blank">Java SE \
167     Documentation</a>, which contains more detailed, \
168     developer-targeted descriptions with conceptual overviews, definitions \
169     of terms, workarounds, and working code examples.<br> \
170     Java is a trademark or registered trademark of $(FULL_COMPANY_NAME) in \
171     the US and other countries.<br> \
172     $(call COPYRIGHT_BOTTOM, {@docroot}/../)
173 
174 JAVADOC_TOP := \
175     <div style="padding: 6px; text-align: center; font-size: 80%; \
176     font-family: DejaVu Sans, Arial, Helvetica, sans-serif; \
177     font-weight: normal;">$(DRAFT_TEXT)</div>
178 
179 ################################################################################
180 # JDK javadoc titles/text snippets
181 
182 JDK_SHORT_NAME := Java SE $(VERSION_SPECIFICATION) &amp; JDK $(VERSION_SPECIFICATION)
183 JDK_LONG_NAME := Java<sup>&reg;</sup> Platform, Standard Edition \
184     &amp;&nbsp;Java&nbsp;Development&nbsp;Kit
185 
186 ################################################################################
187 # Java SE javadoc titles/text snippets
188 
189 JAVASE_SHORT_NAME := Java SE $(VERSION_SPECIFICATION)
190 JAVASE_LONG_NAME := Java<sup>&reg;</sup> Platform, Standard Edition
191 
192 ################################################################################
193 # Functions
194 
195 # Helper function for creating a svg file from a dot file generated by the
196 # GenGraphs tool.
197 # param 1: SetupJavadocGeneration namespace ($1)
198 # param 2: module name
199 #
200 define setup_gengraph_dot_to_svg
201   $1_$2_DOT_SRC :=  $$($1_GENGRAPHS_DIR)/$2.dot
202   $1_$2_SVG_TARGET := $$($1_TARGET_DIR)/$2/module-graph.svg
203 
204     # For each module needing a graph, create a svg file from the dot file
205     # generated by the GenGraphs tool and store it in the target dir.
206     $$(eval $$(call SetupExecute, gengraphs_svg_$1_$2, \
207         INFO := Running dot for module graphs for $2, \
208         DEPS := $$(gengraphs_$1_TARGET), \
209         OUTPUT_FILE := $$($1_$2_SVG_TARGET), \
210         SUPPORT_DIR := $$($1_GENGRAPHS_DIR), \
211         COMMAND := $$(DOT) -Tsvg -o $$($1_$2_SVG_TARGET) $$($1_$2_DOT_SRC), \
212     ))
213 
214   $1_MODULEGRAPH_TARGETS += $$($1_$2_SVG_TARGET)
215 endef
216 
217 # Helper function to create the overview.html file to use with the -overview
218 # javadoc option.
219 # Returns the filename as $1_OVERVIEW.
220 #
221 # param 1: SetupJavadocGeneration namespace ($1)
222 define create_overview_file
223   $1_OVERVIEW_TEXT := \
224       <!DOCTYPE html> \
225       <html><head></head><body> \
226       #
227   ifneq ($$($1_GROUPS),)
228     $1_OVERVIEW_TEXT += \
229       <p>This document is divided into \
230       $$(subst 2,two,$$(subst 3,three,$$(words $$($1_GROUPS)))) sections:</p> \
231       <blockquote><dl> \
232       #
233     $1_OVERVIEW_TEXT += $$(foreach g, $$($1_GROUPS), \
234         <dt style="margin-top: 8px;">$$($$g_GROUP_NAME)</dt> \
235         <dd style="margin-top: 8px;">$$($$g_GROUP_DESCRIPTION)</dd> \
236     )
237     $1_OVERVIEW_TEXT += \
238         </dl></blockquote> \
239         #
240   endif
241   $1_OVERVIEW_TEXT += \
242       </body></html> \
243       #
244 
245   $1_OVERVIEW := $$(SUPPORT_OUTPUTDIR)/docs/$1-overview.html
246 
247   $1_OVERVIEW_VARDEPS_FILE := $$(call DependOnVariable, $1_OVERVIEW_TEXT, \
248       $$($1_OVERVIEW).vardeps)
249 
250   $$($1_OVERVIEW): $$($1_OVERVIEW_VARDEPS_FILE)
251 	$$(call LogInfo, Creating overview.html for $1)
252 	$$(call MakeDir, $$(@D))
253 	$$(PRINTF) > $$@ '$$($1_OVERVIEW_TEXT)'
254 endef
255 
256 ################################################################################
257 # Setup make rules to create an API documentation collection, using javadoc and
258 # other tools if needed.
259 #
260 # Parameter 1 is the name of the rule. This name is used as variable prefix.
261 # Targets generated are returned as $1_JAVADOC_TARGETS and
262 # $1_MODULEGRAPH_TARGETS. Note that the index.html file will work as a "touch
263 # file" for all the magnitude of files that are generated by javadoc.
264 #
265 # Remaining parameters are named arguments. These include:
266 #   MODULES - Modules to generate javadoc for
267 #   GROUPS - Name of the groups to divide the modules into, if any
268 #   SHORT_NAME - The short name of this documentation collection
269 #   LONG_NAME - The long name of this documentation collection
270 #   TARGET_DIR - Where to store the output
271 #
272 SetupApiDocsGeneration = $(NamedParamsMacroTemplate)
273 define SetupApiDocsGenerationBody
274 
275   # Figure out all modules, both specified and transitive indirect exports, that
276   # will be processed by javadoc.
277   $1_INDIRECT_EXPORTS := $$(call FindTransitiveIndirectDepsForModules, $$($1_MODULES))
278   $1_ALL_MODULES := $$(sort $$($1_MODULES) $$($1_INDIRECT_EXPORTS))
279 
280   $1_JAVA_ARGS := -Dextlink.spec.version=$$(VERSION_SPECIFICATION) \
281 	-Djspec.version=$$(VERSION_SPECIFICATION)
282 
283   ifeq ($$(ENABLE_FULL_DOCS), true)
284     # Tell the ModuleGraph taglet to generate html links to soon-to-be-created
285     # svg files with module graphs.
286     $1_JAVA_ARGS += -DenableModuleGraph=true
287   endif
288 
289   # Start with basic options and tags
290   ifeq ($$($1_OPTIONS), )
291     $1_OPTIONS := $$(JAVADOC_OPTIONS)
292   endif
293   ifeq ($$($1_TAGS), )
294     $1_TAGS := $$(JAVADOC_TAGS)
295   endif
296   $1_OPTIONS += $$($1_TAGS)
297 
298   $1_OPTIONS += --module-source-path $$(MODULES_SOURCE_PATH)
299   $1_OPTIONS += --module $$(call CommaList, $$($1_MODULES))
300 
301   # Create a string like "-Xdoclint:all,-syntax,-html,..."
302   $1_OPTIONS += -Xdoclint:all,$$(call CommaList, $$(addprefix -, \
303       $$(JAVADOC_DISABLED_DOCLINT)))
304 
305   $1_DOC_TITLE := $$($1_LONG_NAME)<br>Version $$(VERSION_SPECIFICATION) API \
306       Specification
307   $1_WINDOW_TITLE := $$(subst &amp;,&,$$($1_SHORT_NAME))$$(DRAFT_MARKER_TITLE)
308   $1_HEADER_TITLE := <div $$(HEADER_STYLE)><strong>$$($1_SHORT_NAME)</strong> \
309       $$(DRAFT_MARKER_STR)</div>
310 
311   $1_OPTIONS += -doctitle '$$($1_DOC_TITLE)'
312   $1_OPTIONS += -windowtitle '$$($1_WINDOW_TITLE)'
313   $1_OPTIONS += -header '$$($1_HEADER_TITLE)'
314   $1_OPTIONS += -bottom '$$(JAVADOC_BOTTOM)'
315   ifeq ($$(IS_DRAFT), true)
316     $1_OPTIONS += -top '$$(JAVADOC_TOP)'
317   endif
318 
319   # Do not store debug level options in VARDEPS.
320   ifneq ($$(LOG_LEVEL), trace)
321     $1_LOG_OPTION += -quiet
322   else
323     $1_LOG_OPTION += -verbose
324   endif
325 
326   # Generate the overview.html file. This will return the filename in
327   # $1_OVERVIEW.
328   $$(eval $$(call create_overview_file,$1))
329   $1_OPTIONS += -overview $$($1_OVERVIEW)
330 
331   $$(foreach g, $$($1_GROUPS), \
332     $$(eval $1_OPTIONS += -group "$$($$g_GROUP_NAME)" "$$($$g_GROUP_MODULES)") \
333   )
334 
335   ifeq ($$($1_JAVADOC_CMD), )
336     $1_JAVADOC_CMD := $$(JAVA) -Djava.awt.headless=true $$($1_JAVA_ARGS) \
337         $$(NEW_JAVADOC)
338   else
339     $1_OPTIONS += $$(addprefix -J, $$($1_JAVA_ARGS))
340   endif
341 
342   $1_VARDEPS := $$($1_JAVA_ARGS) $$($1_OPTIONS) $$(MODULES_SOURCE_PATH) \
343       $$($1_ALL_MODULES) $$($1_JAVADOC_CMD)
344   $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
345       $$(SUPPORT_OUTPUTDIR)/docs/$1.vardeps)
346 
347   # Get a list of all files in all the source dirs for all included modules
348   $1_SOURCE_DEPS := $$(call FindFiles, $$(wildcard $$(foreach module, \
349       $$($1_ALL_MODULES), $$(call FindModuleSrcDirs, $$(module)))))
350 
351   $$(eval $$(call SetupExecute, javadoc_$1, \
352       WARN := Generating $1 javadoc for $$(words $$($1_ALL_MODULES)) modules, \
353       INFO := Javadoc modules: $$($1_ALL_MODULES), \
354       DEPS := $$(BUILD_TOOLS_JDK) $$($1_VARDEPS_FILE) $$($1_SOURCE_DEPS) \
355           $$($1_OVERVIEW), \
356       OUTPUT_DIR := $$($1_TARGET_DIR), \
357       SUPPORT_DIR := $$(SUPPORT_OUTPUTDIR)/docs, \
358       COMMAND := $$($1_JAVADOC_CMD) -d $$($1_TARGET_DIR) $$($1_OPTIONS) \
359           $$($1_LOG_OPTION), \
360   ))
361 
362   $1_JAVADOC_TARGETS := $$(javadoc_$1_TARGET)
363 
364   ifeq ($$(ENABLE_FULL_DOCS), true)
365     # We have asked ModuleGraph to generate links to svg files. Now we must
366     # produce the svg files.
367 
368     # Locate which modules has the @moduleGraph tag in their module-info.java
369     $1_MODULES_NEEDING_GRAPH := $$(strip $$(foreach m, $$($1_ALL_MODULES), \
370       $$(if $$(shell $$(GREP) -e @moduleGraph \
371           $$(wildcard $$(addsuffix /module-info.java, \
372           $$(call FindModuleSrcDirs, $$m)))), \
373         $$m) \
374     ))
375 
376     # First we run the GenGraph tool. It will query the module structure of the
377     # running JVM and output .dot files for all existing modules.
378     GENGRAPHS_PROPS := \
379         $$(TOPDIR)/make/jdk/src/classes/build/tools/jigsaw/javadoc-graphs.properties
380 
381     $1_GENGRAPHS_DIR := $$(SUPPORT_OUTPUTDIR)/docs/$1-gengraphs
382 
383     $$(eval $$(call SetupExecute, gengraphs_$1, \
384         INFO := Running gengraphs for $1 documentation, \
385         DEPS := $$(BUILD_JIGSAW_TOOLS) $$(GENGRAPHS_PROPS), \
386         OUTPUT_DIR := $$($1_GENGRAPHS_DIR), \
387         COMMAND := $$(TOOL_GENGRAPHS) --spec --output $$($1_GENGRAPHS_DIR) \
388             --dot-attributes $$(GENGRAPHS_PROPS), \
389     ))
390 
391     # For each module needing a graph, create a svg file from the dot file
392     # generated by the GenGraphs tool and store it in the target dir.
393     # They will depend on gengraphs_$1_TARGET, and will be added to $1.
394     $$(foreach m, $$($1_MODULES_NEEDING_GRAPH), \
395       $$(eval $$(call setup_gengraph_dot_to_svg,$1,$$m)) \
396     )
397   endif
398 endef
399 
400 ################################################################################
401 # Setup generation of the JDK API documentation (javadoc + modulegraph)
402 
403 # Define the groups of the JDK API documentation
404 JavaSE_GROUP_NAME := Java SE
405 JavaSE_GROUP_MODULES := $(call ColonList, $(sort java.se \
406     $(call FindTransitiveIndirectDepsForModules, java.se)))
407 JavaSE_GROUP_DESCRIPTION := \
408     The Java Platform, Standard Edition (Java SE) APIs define the core Java \
409     platform for general-purpose computing. These APIs are in modules whose \
410     names start with {@code java}. \
411     #
412 JDK_GROUPS += JavaSE
413 
414 JDK_GROUP_NAME := JDK
415 JDK_GROUP_MODULES := jdk.*
416 JDK_GROUP_DESCRIPTION := \
417     The Java Development Kit (JDK) APIs are specific to the JDK and will not \
418     necessarily be available in all implementations of the Java SE Platform. \
419     These APIs are in modules whose names start with {@code jdk}. \
420     #
421 JDK_GROUPS += JDK
422 
423 # If we are importing JavaFX, we need a JavaFX group. In an ideal world, this
424 # would have been abstracted away to a more proper generic handling of imported
425 # modules.
426 ifneq ($(findstring javafx., $(IMPORTED_MODULES)), )
427   JavaFX_GROUP_NAME := JavaFX
428   JavaFX_GROUP_MODULES := javafx.*
429   JavaFX_GROUP_DESCRIPTION := \
430       The JavaFX APIs define a set of user-interface controls, graphics, \
431       media, and web packages for developing rich client applications. These \
432       APIs are in modules whose names start with {@code javafx}. \
433       #
434   JDK_GROUPS += JavaFX
435 endif
436 
437 # All modules to have docs generated by docs-jdk-api target
438 JDK_MODULES := $(sort $(filter-out $(MODULES_FILTER), $(DOCS_MODULES)))
439 
440 $(eval $(call SetupApiDocsGeneration, JDK_API, \
441     MODULES := $(JDK_MODULES), \
442     GROUPS := $(JDK_GROUPS), \
443     SHORT_NAME := $(JDK_SHORT_NAME), \
444     LONG_NAME := $(JDK_LONG_NAME), \
445     TARGET_DIR := $(DOCS_OUTPUTDIR)/api, \
446 ))
447 
448 # Targets generated are returned in JDK_API_JAVADOC_TARGETS and
449 # JDK_API_MODULEGRAPH_TARGETS.
450 
451 ################################################################################
452 # Setup generation of the Java SE API documentation (javadoc + modulegraph)
453 
454 # The Java SE module scope is just java.se and its transitive indirect
455 # exports.
456 JAVASE_MODULES := java.se
457 
458 $(eval $(call SetupApiDocsGeneration, JAVASE_API, \
459     MODULES := $(JAVASE_MODULES), \
460     SHORT_NAME := $(JAVASE_SHORT_NAME), \
461     LONG_NAME := $(JAVASE_LONG_NAME), \
462     TARGET_DIR := $(IMAGES_OUTPUTDIR)/javase-docs/api, \
463 ))
464 
465 # Targets generated are returned in JAVASE_API_JAVADOC_TARGETS and
466 # JAVASE_API_MODULEGRAPH_TARGETS.
467 
468 ################################################################################
469 # Setup generation of the reference Java SE API documentation (javadoc + modulegraph)
470 
471 # The reference javadoc is just the same as javase, but using the BootJDK javadoc
472 # and a stable set of javadoc options.  Typically it is used for generating
473 # diffs between the reference javadoc and a javadoc bundle of a specific build
474 # generated in the same way.
475 
476 $(eval $(call SetupApiDocsGeneration, REFERENCE_API, \
477     MODULES := $(JAVASE_MODULES), \
478     SHORT_NAME := $(JAVASE_SHORT_NAME), \
479     LONG_NAME := $(JAVASE_LONG_NAME), \
480     TARGET_DIR := $(IMAGES_OUTPUTDIR)/reference-docs/api, \
481     JAVADOC_CMD := $(JAVADOC), \
482     OPTIONS := $(REFERENCE_OPTIONS), \
483     TAGS := $(REFERENCE_TAGS), \
484 ))
485 
486 # Targets generated are returned in REFERENCE_API_JAVADOC_TARGETS and
487 # REFERENCE_API_MODULEGRAPH_TARGETS.
488 
489 ################################################################################
490 
491 # Use this variable to control which spec files are included in the output.
492 # Format: space-delimited list of names, including at most one '%' as a
493 # wildcard. Spec source files match if their filename or any enclosing folder
494 # name matches one of the items in SPEC_FILTER.
495 SPEC_FILTER := %
496 
497 ApplySpecFilter = \
498     $(strip $(foreach file, $(1), \
499         $(eval searchkeys := $(subst /, ,$(subst $(WORKSPACE_ROOT),,$(file)))) \
500         $(if $(filter $(SPEC_FILTER), $(searchkeys)), \
501             $(file) \
502         ) \
503     ))
504 
505 # Copy the global resources, including the top-level redirect index.html
506 GLOBAL_SPECS_RESOURCES_DIR := $(TOPDIR)/make/data/docs-resources
507 $(eval $(call SetupCopyFiles, COPY_GLOBAL_RESOURCES, \
508     SRC := $(GLOBAL_SPECS_RESOURCES_DIR), \
509     FILES := $(call ApplySpecFilter, $(call FindFiles, $(GLOBAL_SPECS_RESOURCES_DIR))), \
510     DEST := $(DOCS_OUTPUTDIR), \
511 ))
512 JDK_INDEX_TARGETS += $(COPY_GLOBAL_RESOURCES)
513 
514 # Copy the legal notices distributed with the docs bundle
515 $(eval $(call SetupCopyFiles, COPY_DOCS_LEGAL_NOTICES, \
516     SRC := $(TOPDIR)/src/jdk.javadoc/share/legal, \
517     FILES := $(call ApplySpecFilter, $(wildcard $(TOPDIR)/src/jdk.javadoc/share/legal/*)), \
518     DEST := $(DOCS_OUTPUTDIR)/legal, \
519 ))
520 JDK_INDEX_TARGETS += $(COPY_DOCS_LEGAL_NOTICES)
521 
522 ################################################################################
523 # Copy JDK specs files
524 
525 # For all non html/md files in $module/share/specs directories, copy them
526 # unmodified
527 
528 ALL_MODULES := $(call FindAllModules)
529 COPY_SPEC_FILTER := %.gif %.jpg %.mib %.css
530 
531 $(foreach m, $(ALL_MODULES), \
532   $(eval SPECS_$m := $(call FindModuleSpecsDirs, $m)) \
533   $(foreach d, $(SPECS_$m), \
534     $(if $(call ApplySpecFilter, $(filter $(COPY_SPEC_FILTER), $(call FindFiles, $d))), \
535       $(eval $(call SetupCopyFiles, COPY_$m, \
536           SRC := $d, \
537           FILES := $(call ApplySpecFilter, $(filter $(COPY_SPEC_FILTER), $(call FindFiles, $d))), \
538           DEST := $(DOCS_OUTPUTDIR)/specs/, \
539       )) \
540       $(eval JDK_SPECS_TARGETS += $(COPY_$m)) \
541     ) \
542   ) \
543 )
544 
545 # Create copyright footer variables. We need different variables for different
546 # relative paths to the copyright.html file. The number 0-2 below represent how
547 # many extra directory levels down below the specs dir the specs html file is
548 # located.
549 SPECS_BOTTOM = <footer class="legal-footer"><hr/>$(COPYRIGHT_BOTTOM)</footer>
550 # The legal dir is one ../ below the specs dir, so start with one ../.
551 specs_bottom_rel_path := ../
552 $(foreach n, 0 1 2, \
553   $(eval SPECS_BOTTOM_$n := $(call SPECS_BOTTOM,$(specs_bottom_rel_path))) \
554   $(eval specs_bottom_rel_path := $(specs_bottom_rel_path)../) \
555 )
556 
557 SPECS_TOP := $(if $(filter true, $(IS_DRAFT)), <header class="draft-header">$(DRAFT_TEXT)</header>)
558 
559 # For all html files in $module/share/specs directories, copy and add the
560 # copyright footer.
561 
562 $(foreach m, $(ALL_MODULES), \
563   $(eval SPECS_$m := $(call FindModuleSpecsDirs, $m)) \
564   $(foreach d, $(SPECS_$m), \
565     $(foreach f, $(call ApplySpecFilter, $(filter %.html, $(call FindFiles, $d))), \
566       $(eval $m_$f_NOF_SUBDIRS := $(words $(subst /, $(SPACE), $(subst $d, , $(dir $f))))) \
567       $(eval $m_$f_NAME := PROCESS_HTML_$m_$(strip $(call RelativePath, $f, $(TOPDIR)))) \
568       $(eval $(call SetupTextFileProcessing, $($m_$f_NAME), \
569           SOURCE_FILES := $f, \
570           SOURCE_BASE_DIR := $d, \
571           OUTPUT_DIR := $(DOCS_OUTPUTDIR)/specs/, \
572           REPLACEMENTS := \
573               <body> => <body>$(SPECS_TOP) ; \
574               </body> => $(SPECS_BOTTOM_$($m_$f_NOF_SUBDIRS))</body>, \
575       )) \
576       $(eval JDK_SPECS_TARGETS += $($($m_$f_NAME))) \
577     ) \
578   ) \
579 )
580 
581 ifeq ($(ENABLE_PANDOC), true)
582   # For all markdown files in $module/share/specs directories, convert them to
583   # html, if we have pandoc (otherwise we'll just skip this).
584 
585   GLOBAL_SPECS_DEFAULT_CSS_FILE := $(DOCS_OUTPUTDIR)/resources/jdk-default.css
586 
587   $(foreach m, $(ALL_MODULES), \
588     $(eval SPECS_$m := $(call FindModuleSpecsDirs, $m)) \
589     $(foreach d, $(SPECS_$m), \
590       $(foreach f, $(call ApplySpecFilter, $(filter %.md, $(call FindFiles, $d))), \
591         $(eval $m_$f_NOF_SUBDIRS := $(words $(subst /, $(SPACE), $(subst $d, , $(dir $f))))) \
592         $(eval $m_$f_NAME := SPECS_TO_HTML_$m_$(strip $(call RelativePath, $f, $(TOPDIR)))) \
593         $(eval $(call SetupProcessMarkdown, $($m_$f_NAME), \
594             SRC := $d, \
595             FILES := $f, \
596             DEST := $(DOCS_OUTPUTDIR)/specs/, \
597             CSS := $(GLOBAL_SPECS_DEFAULT_CSS_FILE), \
598             OPTIONS := -V include-before='$(SPECS_TOP)' -V include-after='$(SPECS_BOTTOM_$($m_$f_NOF_SUBDIRS))', \
599             REPLACEMENTS := \
600 		@@VERSION_SPECIFICATION@@ => $(VERSION_SPECIFICATION) ; \
601 		@@VERSION_STRING@@ => $(VERSION_STRING), \
602             POST_PROCESS := $(TOOL_FIXUPPANDOC), \
603         )) \
604         $(eval JDK_SPECS_TARGETS += $($($m_$f_NAME))) \
605       ) \
606     ) \
607   )
608 
609   # For all markdown files in $module/share/man directories, convert them to
610   # html.
611 
612   # Create dynamic man pages from markdown using pandoc. We need
613   # PANDOC_HTML_MANPAGE_FILTER, a wrapper around
614   # PANDOC_HTML_MANPAGE_FILTER_JAVASCRIPT. This is created by buildtools-jdk.
615 
616   # We should also depend on the source javascript filter
617   PANDOC_HTML_MANPAGE_FILTER_JAVASCRIPT := \
618       $(TOPDIR)/make/scripts/pandoc-html-manpage-filter.js
619 
620   $(foreach m, $(ALL_MODULES), \
621     $(eval MAN_$m := $(call FindModuleManDirs, $m)) \
622     $(foreach d, $(MAN_$m), \
623       $(foreach f, $(call ApplySpecFilter, $(filter %.md, $(call FindFiles, $d))), \
624         $(eval $m_$f_NAME := MAN_TO_HTML_$m_$(strip $(call RelativePath, $f, $(TOPDIR)))) \
625         $(eval $(call SetupProcessMarkdown, $($m_$f_NAME), \
626             SRC := $d, \
627             FILES := $f, \
628             DEST := $(DOCS_OUTPUTDIR)/specs/man, \
629             FILTER := $(PANDOC_HTML_MANPAGE_FILTER), \
630             CSS := $(GLOBAL_SPECS_DEFAULT_CSS_FILE), \
631             REPLACEMENTS := \
632 		@@COPYRIGHT_YEAR@@ => $(COPYRIGHT_YEAR) ; \
633 		@@VERSION_SHORT@@ => $(VERSION_SHORT) ; \
634 		@@VERSION_SPECIFICATION@@ => $(VERSION_SPECIFICATION), \
635             OPTIONS := --toc -V include-before='$(SPECS_TOP)' -V include-after='$(SPECS_BOTTOM_1)', \
636             POST_PROCESS := $(TOOL_FIXUPPANDOC), \
637             EXTRA_DEPS := $(PANDOC_HTML_MANPAGE_FILTER) \
638                 $(PANDOC_HTML_MANPAGE_FILTER_JAVASCRIPT), \
639         )) \
640         $(eval JDK_SPECS_TARGETS += $($($m_$f_NAME))) \
641       ) \
642     ) \
643   )
644 
645   # The html generated from markdown also needs the css file
646   JDK_SPECS_TARGETS += $(COPY_GLOBAL_RESOURCES)
647 endif
648 
649 # Special treatment for generated documentation
650 
651 JDWP_PROTOCOL := $(SUPPORT_OUTPUTDIR)/gensrc/jdk.jdi/jdwp-protocol.html
652 ifneq ($(call ApplySpecFilter, $(JDWP_PROTOCOL)), )
653   $(eval $(call SetupTextFileProcessing, PROCESS_JDWP_PROTOCOL, \
654       SOURCE_FILES := $(JDWP_PROTOCOL), \
655       OUTPUT_DIR := $(DOCS_OUTPUTDIR)/specs/jdwp, \
656       REPLACEMENTS := \
657           <body> => <body>$(SPECS_TOP) ; \
658           </body> => $(SPECS_BOTTOM_1)</body>, \
659   ))
660   JDK_SPECS_TARGETS += $(PROCESS_JDWP_PROTOCOL)
661 endif
662 
663 # Get jvmti.html from the main jvm variant (all variants' jvmti.html are identical).
664 JVMTI_HTML ?= $(HOTSPOT_OUTPUTDIR)/variant-$(JVM_VARIANT_MAIN)/gensrc/jvmtifiles/jvmti.html
665 ifneq ($(call ApplySpecFilter, $(JVMTI_HTML)), )
666   $(eval $(call SetupTextFileProcessing, PROCESS_JVMTI_HTML, \
667       SOURCE_FILES := $(JVMTI_HTML), \
668       OUTPUT_DIR := $(DOCS_OUTPUTDIR)/specs/, \
669       REPLACEMENTS := \
670           <body> => <body>$(SPECS_TOP) ; \
671           </body> => $(SPECS_BOTTOM_0)</body>, \
672   ))
673   JDK_SPECS_TARGETS += $(PROCESS_JVMTI_HTML)
674 endif
675 
676 ################################################################################
677 # Optional target which bundles all generated javadocs into a zip archive.
678 
679 JAVADOC_ZIP_NAME := jdk-$(VERSION_STRING)-docs.zip
680 JAVADOC_ZIP_FILE := $(OUTPUTDIR)/bundles/$(JAVADOC_ZIP_NAME)
681 
682 $(eval $(call SetupZipArchive, BUILD_JAVADOC_ZIP, \
683     SRC := $(DOCS_OUTPUTDIR), \
684     ZIP := $(JAVADOC_ZIP_FILE), \
685     EXTRA_DEPS := $(JDK_API_JAVADOC_TARGETS) $(JDK_API_MODULEGRAPH_TARGETS) \
686         $(JDK_SPECS_TARGETS), \
687 ))
688 
689 ZIP_TARGETS += $(BUILD_JAVADOC_ZIP)
690 
691 ################################################################################
692 # Hook to include the corresponding custom file, if present.
693 $(eval $(call IncludeCustomExtension, Docs-post.gmk))
694 
695 ################################################################################
696 # Bundles all generated specs into a zip archive, skipping javadocs.
697 
698 SPECS_ZIP_NAME := jdk-$(VERSION_STRING)-specs.zip
699 SPECS_ZIP_FILE := $(OUTPUTDIR)/bundles/$(SPECS_ZIP_NAME)
700 
701 $(eval $(call SetupZipArchive, BUILD_SPECS_ZIP, \
702     SRC := $(DOCS_OUTPUTDIR), \
703     ZIP := $(SPECS_ZIP_FILE), \
704     EXTRA_DEPS := $(JDK_SPECS_TARGETS), \
705 ))
706 
707 SPECS_ZIP_TARGETS += $(BUILD_SPECS_ZIP)
708 
709 ################################################################################
710 
711 docs-jdk-api-javadoc: $(JDK_API_JAVADOC_TARGETS) $(JDK_API_CUSTOM_TARGETS)
712 
713 docs-jdk-api-modulegraph: $(JDK_API_MODULEGRAPH_TARGETS)
714 
715 docs-javase-api-javadoc: $(JAVASE_API_JAVADOC_TARGETS) $(JAVASE_API_CUSTOM_TARGETS)
716 
717 docs-javase-api-modulegraph: $(JAVASE_API_MODULEGRAPH_TARGETS)
718 
719 docs-reference-api-javadoc: $(REFERENCE_API_JAVADOC_TARGETS) $(REFERENCE_API_CUSTOM_TARGETS)
720 
721 docs-reference-api-modulegraph: $(REFERENCE_API_MODULEGRAPH_TARGETS)
722 
723 docs-jdk-specs: $(JDK_SPECS_TARGETS)
724 
725 docs-jdk-index: $(JDK_INDEX_TARGETS)
726 
727 docs-zip: $(ZIP_TARGETS)
728 
729 docs-specs-zip: $(SPECS_ZIP_TARGETS)
730 
731 all: docs-jdk-api-javadoc docs-jdk-api-modulegraph docs-javase-api-javadoc \
732     docs-javase-api-modulegraph docs-reference-api-javadoc \
733     docs-reference-api-modulegraph docs-jdk-specs docs-jdk-index docs-zip \
734     docs-specs-zip
735 
736 .PHONY: default all docs-jdk-api-javadoc docs-jdk-api-modulegraph \
737     docs-javase-api-javadoc docs-javase-api-modulegraph \
738     docs-reference-api-javadoc docs-reference-api-modulegraph docs-jdk-specs \
739     docs-jdk-index docs-zip docs-specs-zip