CustomTarget_html.mk 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
  2. #
  3. # This file is part of the LibreOffice project.
  4. #
  5. # This Source Code Form is subject to the terms of the Mozilla Public
  6. # License, v. 2.0. If a copy of the MPL was not distributed with this
  7. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. #
  9. $(eval $(call gb_CustomTarget_CustomTarget,helpcontent2/help3xsl))
  10. # HACK!!
  11. html_TREE_MODULES := sbasic scalc schart shared simpress smath swriter sdraw
  12. html_TEXT_MODULES := $(html_TREE_MODULES) sdatabase
  13. html_BMARK_MODULES := swriter:WRITER scalc:CALC simpress:IMPRESS sdraw:DRAW shared/explorer/database:BASE smath:MATH schart:CHART sbasic:BASIC shared:SHARED
  14. $(eval $(call gb_CustomTarget_register_targets,helpcontent2/help3xsl,\
  15. hid2file.js \
  16. languages.js \
  17. $(foreach lang,$(gb_HELP_LANGS),\
  18. $(lang)/bookmarks.js \
  19. $(lang)/contents.js \
  20. $(lang)/html.text \
  21. $(lang)/langnames.js \
  22. $(foreach module,$(html_TREE_MODULES),$(module)/$(lang)/contents.part) \
  23. $(foreach module,$(html_BMARK_MODULES),$(firstword $(subst :, ,$(module)))/$(lang)/bookmarks.part) \
  24. $(foreach module,$(html_TEXT_MODULES),filelists/html-help/$(module)/$(lang).filelist) \
  25. ) \
  26. ))
  27. # In the below recipe, the file $@.good is used to communicate failure of xsltproc in the pipeline
  28. # (similar to Bash's `set -o pipefail`; the final `rm $@.good` will fail, and fail the whole
  29. # command, if the xsltproc invocation failed):
  30. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/hid2file.js : \
  31. $(SRCDIR)/helpcontent2/help3xsl/generate_hid2file.xsl \
  32. $(call gb_ExternalExecutable_get_dependencies,xsltproc) \
  33. $(foreach module,$(html_TEXT_MODULES),$(call gb_AllLangHelp_get_helpfiles_target,$(module))) \
  34. $(SRCDIR)/helpcontent2/CustomTarget_html.mk
  35. $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),XSL,1)
  36. $(call gb_Helper_abbreviate_dirs,\
  37. ( \
  38. echo 'var hid2fileMap = {' \
  39. && RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),100,$(foreach module,$(html_TEXT_MODULES),$(addprefix $(SRCDIR)/,$(gb_AllLangHelp_$(module)_HELPFILES)))) \
  40. && <"$$RESPONSEFILE" $(if $(filter WNT,$(OS)),tr -d '\r' | env -i PATH="$$PATH") xargs -n 1 printf '%s\n' \
  41. | while read xhp; do \
  42. rm -f $@.good && \
  43. { $(call gb_ExternalExecutable_get_command,xsltproc) $< $$xhp && touch $@.good; } \
  44. | $(gb_AWK) 'NF' \
  45. && rm $@.good || exit \
  46. ; done \
  47. && rm "$$RESPONSEFILE" \
  48. && echo '};' \
  49. ) > $@ \
  50. )
  51. # set of installed languages - has to be language independent
  52. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/languages.js : \
  53. $(SRCDIR)/helpcontent2/CustomTarget_html.mk
  54. ( \
  55. printf 'var languagesSet = new Set([' ; \
  56. for lang in $(gb_HELP_LANGS) ; do printf '%s' "'$$lang', " ; done | sed 's/, $$//' ; \
  57. printf ']);\n' \
  58. ) > $@
  59. define html_gen_langnames_js_dep
  60. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/langnames.js : \
  61. $(if $(filter en-US,$(1)),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$(1)))/helpcontent2/source/text/shared/help/browserhelp.xhp
  62. endef
  63. $(eval $(foreach lang,$(gb_HELP_LANGS),$(call html_gen_langnames_js_dep,$(lang))))
  64. # names of the languages - has to be translated, ie. per language
  65. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/langnames.js : \
  66. $(SRCDIR)/helpcontent2/CustomTarget_html.mk
  67. ( \
  68. echo 'var languageNames = {' ; \
  69. grep '<paragraph[^>]*id="lang_' $(if $(filter en-US,$*),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$*))/helpcontent2/source/text/shared/help/browserhelp.xhp | \
  70. sed -e 's/^.*<variable id="\([^"]*\)"[^>]*>\([^<]*\)<.*$$/"\1": "\2",/' ; \
  71. echo '};' \
  72. ) > $@
  73. define html_gen_contents_html_dep
  74. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/contents.part : $(call gb_HelpTarget__get_treefile,$(1),$(3))
  75. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/contents.part : TREE_FILE := $(call gb_HelpTarget__get_treefile,$(1),$(3))
  76. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/contents.part : LANGUAGE := $(2)
  77. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/contents.part : MODULE := $(lastword $(subst :, ,$(filter $(module):%, $(html_BMARK_MODULES))))
  78. endef
  79. define html_gen_contents_dep
  80. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/contents.js : \
  81. $(foreach module,$(html_TREE_MODULES),\
  82. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(module)/$(1)/contents.part)
  83. $(foreach module,$(html_TREE_MODULES),$(call html_gen_contents_html_dep,$(module)/$(1),$(1),helpcontent2/source/auxiliary/$(module)))
  84. endef
  85. $(eval $(foreach lang,$(gb_HELP_LANGS),$(call html_gen_contents_dep,$(lang))))
  86. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/contents.js :
  87. $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),CAT,2)
  88. $(call gb_Helper_abbreviate_dirs,\
  89. ( \
  90. echo "document.getElementById(\"Contents\").innerHTML='\\" \
  91. && cat $(filter %.part,$^) | $(gb_AWK) 'NF' \
  92. && echo "';" \
  93. ) > $@ \
  94. )
  95. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/contents.part : \
  96. $(SRCDIR)/helpcontent2/help3xsl/get_tree.xsl \
  97. $(call gb_ExternalExecutable_get_dependencies,xsltproc)
  98. $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),XSL,1)
  99. $(call gb_Helper_abbreviate_dirs,\
  100. $(call gb_ExternalExecutable_get_command,xsltproc) \
  101. --stringparam lang $(LANGUAGE) \
  102. --stringparam local $(if $(HELP_ONLINE),'no','yes') \
  103. --stringparam module $(MODULE) \
  104. --stringparam productname "$(PRODUCTNAME)" \
  105. --stringparam productversion "$(PRODUCTVERSION)" \
  106. -o $@ \
  107. $(SRCDIR)/helpcontent2/help3xsl/get_tree.xsl \
  108. $(TREE_FILE) \
  109. )
  110. define html_gen_html_dep
  111. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/html.text : \
  112. $(foreach module,$(html_TEXT_MODULES), \
  113. $(if $(filter en-US,$(1)), \
  114. $(call gb_AllLangHelp_get_helpfiles_target,$(module)), \
  115. $(call gb_HelpTranslateTarget_get_target,$(module)/$(1))))
  116. endef
  117. $(eval $(foreach lang,$(gb_HELP_LANGS),$(call html_gen_html_dep,$(lang))))
  118. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/html.text : \
  119. $(SRCDIR)/helpcontent2/help3xsl/online_transform.xsl \
  120. $(call gb_ExternalExecutable_get_dependencies,xsltproc)
  121. $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),XSL,1)
  122. $(call gb_Helper_abbreviate_dirs,\
  123. cd $(if $(filter en-US,$*),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$*))/helpcontent2/source \
  124. && rm -rf $(dir $@)text \
  125. && RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),100,$(foreach module,$(html_TEXT_MODULES),$(patsubst helpcontent2/source/%,%,$(gb_AllLangHelp_$(module)_HELPFILES)))) \
  126. && <"$$RESPONSEFILE" $(if $(filter WNT,$(OS)),tr -d '\r' | env -i PATH="$$PATH") xargs -n 1 printf '%s\n' \
  127. | while read xhp; do \
  128. mkdir -p $$(dirname $(dir $@)$$xhp) && \
  129. $(call gb_ExternalExecutable_get_command,xsltproc) \
  130. --stringparam Language $* \
  131. --stringparam local $(if $(HELP_ONLINE),'no','yes') \
  132. --stringparam root $(if $(filter WNT,$(OS)),$$(cygpath -m `pwd`),`pwd`)/ \
  133. --stringparam productname "$(PRODUCTNAME)" \
  134. --stringparam productversion "$(PRODUCTVERSION)" \
  135. -o $(dir $@)$${xhp%.xhp}.html \
  136. $(SRCDIR)/helpcontent2/help3xsl/online_transform.xsl \
  137. $(if $(filter WNT,$(OS)),$$(cygpath -m `pwd`),`pwd`)/$$xhp \
  138. || exit \
  139. ; done \
  140. && rm "$$RESPONSEFILE" \
  141. && touch $@ \
  142. )
  143. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/bookmarks.js :
  144. $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),CAT,2)
  145. $(call gb_Helper_abbreviate_dirs,\
  146. ( \
  147. echo 'var bookmarks = [' \
  148. && cat $(filter %.part,$^) \
  149. && echo '];' \
  150. ) > $@ \
  151. )
  152. define html__gen_bookmarks_lang_dep
  153. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(2)/$(1)/bookmarks.part : \
  154. $(if $(filter en-US,$(1)), \
  155. $(call gb_AllLangHelp_get_helpfiles_target,$(firstword $(subst /, ,$(2)))), \
  156. $(call gb_HelpTranslateTarget_get_target,$(firstword $(subst /, ,$(2)))/$(1)))
  157. endef
  158. define html__gen_bookmarks_lang_deps
  159. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/bookmarks.js : \
  160. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(2)/$(1)/bookmarks.part
  161. $(call html__gen_bookmarks_lang_dep,$(1),$(2))
  162. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(2)/$(1)/bookmarks.part : HELP_LANG := $(1)
  163. endef
  164. define html__gen_bookmarks_deps
  165. $(foreach lang,$(gb_HELP_LANGS),$(call html__gen_bookmarks_lang_deps,$(lang),$(1)))
  166. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/%/bookmarks.part : APP := $(2)
  167. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/%/bookmarks.part : APPDIR := $(1)
  168. endef
  169. define html_gen_bookmarks_deps
  170. $(call html__gen_bookmarks_deps,$(firstword $(1)),$(lastword $(1)))
  171. endef
  172. $(eval $(foreach module,$(html_BMARK_MODULES),$(call html_gen_bookmarks_deps,$(subst :, ,$(module)))))
  173. # In the below recipe, the file $@.good is used to communicate failure of xsltproc in the pipeline
  174. # (similar to Bash's `set -o pipefail`; the final `rm $@.good` will fail, and fail the whole
  175. # command, if any xsltproc invocation failed):
  176. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/bookmarks.part : \
  177. $(SRCDIR)/helpcontent2/help3xsl/get_bookmark.xsl \
  178. $(call gb_ExternalExecutable_get_dependencies,xsltproc)
  179. $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),XSL,1)
  180. $(call gb_Helper_abbreviate_dirs,\
  181. RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),100,$(addprefix $(if $(filter en-US,$(HELP_LANG)),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$(HELP_LANG)))/,$(gb_AllLangHelp_$(APPDIR)_BOOKMARK_HELPFILES))) \
  182. && ( \
  183. <"$$RESPONSEFILE" $(if $(filter WNT,$(OS)),tr -d '\r' | env -i PATH="$$PATH") xargs -n 1 printf '%s\n' \
  184. | { rm -f $@.good && while read xhp; do \
  185. $(call gb_ExternalExecutable_get_command,xsltproc) \
  186. --stringparam app $(APP) \
  187. --stringparam Language $(HELP_LANG) \
  188. --stringparam local $(if $(HELP_ONLINE),'no','yes') \
  189. --stringparam productname "$(PRODUCTNAME)" \
  190. --stringparam productversion "$(PRODUCTVERSION)" \
  191. $(SRCDIR)/helpcontent2/help3xsl/get_bookmark.xsl \
  192. $$xhp \
  193. || exit \
  194. ; done && touch $@.good; } \
  195. | sort -k3b -t\> -s \
  196. | awk 'NF' \
  197. && rm $@.good \
  198. ) > $@ \
  199. && rm "$$RESPONSEFILE" \
  200. )
  201. # The various gid_File_Help_*_Zip in scp2 that use EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG expect
  202. # $(module)/$(lang).filelist files containing lists of files (in instdir) for the corresponding
  203. # module/lang parts of help data. As a hack, generate those from the existing HelpTarget file
  204. # lists, which specify the original .xhp files (in SRCDIR for en-US, translated for all other
  205. # langs). For the shared module, also include the per-lang non .xhp/.html files from the
  206. # AllLangPackages helpcontent2_html_lang and helpcontent2_html_media_lang:
  207. # html__filelist,lang,module
  208. define html__filelist
  209. $(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/filelists/html-help/$(2)/$(1).filelist: \
  210. $(call gb_HelpTarget_get_filelist,$(2)/$(1)) \
  211. $(if $(filter $(2),shared), \
  212. $(call gb_Package_get_target,helpcontent2_html_lang_$(1)) \
  213. $(call gb_Package_get_target,helpcontent2_html_media_lang_$(1)))
  214. mkdir -p $$$$(dirname $$@)
  215. sed -e 's|$(if $(filter $(1),en-US),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$(1)))/helpcontent2/source/|$(INSTROOT)/$(LIBO_SHARE_HELP_FOLDER)/$(1)/|g' -e 's|.xhp|.html|g' $(call gb_HelpTarget_get_filelist,$(2)/$(1)) > $$@
  216. $(if $(filter $(2),shared),cat $(call gb_Package_get_target,helpcontent2_html_lang_$(1)) $(call gb_Package_get_target,helpcontent2_html_media_lang_$(1)) >> $$@,:)
  217. endef
  218. $(eval $(foreach lang,$(gb_HELP_LANGS),$(foreach module,$(html_TEXT_MODULES),$(call html__filelist,$(lang),$(module)))))
  219. # vim: set noet sw=4 ts=4: