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
10$(eval $(call gb_CustomTarget_CustomTarget,helpcontent2/help3xsl))
11
12# HACK!!
13html_TREE_MODULES := swriter scalc simpress sdraw sdatabase smath schart sbasic shared
14html_TEXT_MODULES := $(html_TREE_MODULES)
15html_BMARK_MODULES := swriter:WRITER scalc:CALC simpress:IMPRESS sdraw:DRAW sdatabase:BASE smath:MATH schart:CHART sbasic:BASIC shared:SHARED
16
17$(eval $(call gb_CustomTarget_register_targets,helpcontent2/help3xsl,\
18	hid2file.js \
19	languages.js \
20	$(foreach lang,$(gb_HELP_LANGS),\
21		$(lang)/bookmarks.js \
22		$(lang)/contents.js \
23		$(lang)/html.text \
24		$(foreach module,$(html_TREE_MODULES),$(module)/$(lang)/contents.part) \
25		$(foreach module,$(html_BMARK_MODULES),$(firstword $(subst :, ,$(module)))/$(lang)/bookmarks.part) \
26		$(foreach module,$(html_TEXT_MODULES),filelists/html-help/$(module)/$(lang).filelist) \
27		$(lang)/langnames.js \
28		$(if $(HELP_OMINDEX_PAGE),$(lang)/xap_tpl) \
29		$(lang)/noscript.html \
30	) \
31))
32
33# In the below recipe, the file $@.good is used to communicate failure of xsltproc in the pipeline
34# (similar to Bash's `set -o pipefail`; the final `rm $@.good` will fail, and fail the whole
35# command, if the xsltproc invocation failed):
36$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/hid2file.js : \
37		$(SRCDIR)/helpcontent2/help3xsl/generate_hid2file.xsl \
38		$(call gb_ExternalExecutable_get_dependencies,xsltproc) \
39		$(foreach module,$(html_TEXT_MODULES),$(call gb_AllLangHelp_get_helpfiles_target,$(module))) \
40		$(SRCDIR)/helpcontent2/CustomTarget_html.mk
41	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),XSL,1)
42	$(call gb_Helper_abbreviate_dirs,\
43		( \
44			echo 'var hid2fileMap = {' \
45			&& RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),100,$(foreach module,$(html_TEXT_MODULES),$(addprefix $(SRCDIR)/,$(gb_AllLangHelp_$(module)_HELPFILES)))) \
46			&& <"$$RESPONSEFILE" $(if $(filter WNT,$(OS)),tr -d '\r' | env -i PATH="$$PATH") xargs -n 1 printf '%s\n' \
47			| while read xhp; do \
48				rm -f $@.good && \
49				{ $(call gb_ExternalExecutable_get_command,xsltproc) $< $$xhp && touch $@.good; } \
50				| $(gb_AWK) 'NF' \
51				&& rm $@.good || exit \
52			; done \
53			&& rm "$$RESPONSEFILE" \
54			&& echo '};' \
55		) > $@ \
56	)
57
58
59# Xapian localized templates
60ifeq ($(HELP_OMINDEX_PAGE),TRUE)
61
62define html_gen_xaptpl_dep
63$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/xap_tpl : \
64	$(if $(filter en-US,$(1)),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$(1)))/helpcontent2/source/text/shared/help/browserhelp.xhp
65
66endef
67
68$(eval $(foreach lang,$(gb_HELP_LANGS),$(call html_gen_xaptpl_dep,$(lang))))
69
70$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/xap_tpl : \
71		$(SRCDIR)/helpcontent2/help3xsl/xap_templ_query.xsl \
72		$(call gb_ExternalExecutable_get_dependencies,xsltproc) \
73		$(SRCDIR)/helpcontent2/CustomTarget_html.mk
74	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),XAT,1)
75	$(call gb_Helper_abbreviate_dirs,\
76		$(call gb_ExternalExecutable_get_command,xsltproc) \
77		--stringparam lang $* \
78		--stringparam productname "$(PRODUCTNAME)" \
79		--stringparam productversion "$(PRODUCTVERSION)" \
80		-o $@ \
81		$(SRCDIR)/helpcontent2/help3xsl/xap_templ_query.xsl \
82		$(if $(filter en-US,$*),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$*))/helpcontent2/source/text/shared/help/browserhelp.xhp \
83	)
84
85endif
86
87# Create noscript.html, when browser has no javascript enabled
88
89define html_gen_noscript_dep
90$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/noscript.html : \
91	$(if $(filter en-US,$(1)),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$(1)))/helpcontent2/source/text/shared/help/browserhelp.xhp
92
93endef
94
95$(eval $(foreach lang,$(gb_HELP_LANGS),$(call html_gen_noscript_dep,$(lang))))
96
97$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/noscript.html : \
98		$(SRCDIR)/helpcontent2/help3xsl/noscript.xsl \
99		$(SRCDIR)/helpcontent2/help3xsl/brand.xsl \
100		$(call gb_ExternalExecutable_get_dependencies,xsltproc) \
101		$(SRCDIR)/helpcontent2/CustomTarget_html.mk
102	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),NJS,1)
103	$(call gb_Helper_abbreviate_dirs,\
104		$(call gb_ExternalExecutable_get_command,xsltproc) \
105		--stringparam lang $* \
106		--stringparam productname "$(PRODUCTNAME)" \
107		--stringparam productversion "$(PRODUCTVERSION)" \
108		-o $@ \
109		$(SRCDIR)/helpcontent2/help3xsl/noscript.xsl \
110		$(if $(filter en-US,$*),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$*))/helpcontent2/source/text/shared/help/browserhelp.xhp \
111	)
112
113
114# set of installed languages - has to be language independent
115$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/languages.js : \
116		$(SRCDIR)/helpcontent2/CustomTarget_html.mk
117	( \
118		printf 'var languagesSet = new Set([' ; \
119		for lang in $(ALL_LANGS) ; do printf '%s' "'$$lang', " ; done | sed 's/, $$//' ; \
120		printf ']);\n' \
121	) > $@
122
123
124define html_gen_langnames_js_dep
125$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/langnames.js : \
126	$(if $(filter en-US,$(1)),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$(1)))/helpcontent2/source/text/shared/help/browserhelp.xhp
127
128endef
129
130$(eval $(foreach lang,$(gb_HELP_LANGS),$(call html_gen_langnames_js_dep,$(lang))))
131
132# names of the languages - has to be translated, ie. per language
133$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/langnames.js : \
134		$(SRCDIR)/helpcontent2/CustomTarget_html.mk
135	( \
136		echo 'var languageNames = {' ; \
137		grep '<paragraph[^>]*id="lang_' $(if $(filter en-US,$*),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$*))/helpcontent2/source/text/shared/help/browserhelp.xhp | \
138			sed -e 's/^.*<variable id="\([^"]*\)"[^>]*>\([^<]*\)<.*$$/"\1": "\2",/' ; \
139		echo '};' \
140	) > $@
141
142define html_gen_contents_html_dep
143$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/contents.part : $(call gb_HelpTarget__get_treefile,$(1),$(3))
144$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/contents.part : TREE_FILE := $(call gb_HelpTarget__get_treefile,$(1),$(3))
145$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/contents.part : LANGUAGE := $(2)
146$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/contents.part : MODULE := $(lastword $(subst :, ,$(filter $(module):%, $(html_BMARK_MODULES))))
147
148endef
149
150define html_gen_contents_dep
151$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/contents.js : \
152	$(foreach module,$(html_TREE_MODULES),\
153		$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(module)/$(1)/contents.part)
154$(foreach module,$(html_TREE_MODULES),$(call html_gen_contents_html_dep,$(module)/$(1),$(1),helpcontent2/source/auxiliary/$(module)))
155
156endef
157
158$(eval $(foreach lang,$(gb_HELP_LANGS),$(call html_gen_contents_dep,$(lang))))
159
160$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/contents.js :
161	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),CAT,2)
162	$(call gb_Helper_abbreviate_dirs,\
163		( \
164			echo "document.getElementById(\"Contents\").innerHTML='\\" \
165			&& cat $(filter %.part,$^) | $(gb_AWK) 'NF' \
166			&& echo "';" \
167		) > $@ \
168	)
169
170$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/contents.part : \
171		$(SRCDIR)/helpcontent2/help3xsl/get_tree.xsl \
172		$(SRCDIR)/helpcontent2/help3xsl/brand.xsl \
173		$(call gb_ExternalExecutable_get_dependencies,xsltproc)
174	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),XSL,1)
175	$(call gb_Helper_abbreviate_dirs,\
176		$(call gb_ExternalExecutable_get_command,xsltproc) \
177			--stringparam lang $(LANGUAGE) \
178			--stringparam local $(if $(HELP_ONLINE),'no','yes') \
179			--stringparam module $(MODULE) \
180			--stringparam productname "$(PRODUCTNAME)" \
181			--stringparam productversion "$(PRODUCTVERSION)" \
182			-o $@ \
183			$(SRCDIR)/helpcontent2/help3xsl/get_tree.xsl \
184			$(TREE_FILE) \
185	)
186
187# link txt file for icon replacement table - tdf#128519
188# copy online_transform.xsl to workdir and build links.txt.xsl
189$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl/online_transform.xsl) : \
190		$(SRCDIR)/helpcontent2/help3xsl/online_transform.xsl
191	cp $(SRCDIR)/helpcontent2/help3xsl/online_transform.xsl $@
192
193$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl/links.txt.xsl) : \
194		$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl/online_transform.xsl) \
195		$(SRCDIR)/icon-themes/colibre/links.txt \
196		$(SRCDIR)/helpcontent2/helpers/make_icon_link.txt.py \
197		$(call gb_ExternalExecutable_get_dependencies,python)
198	$(call gb_ExternalExecutable_get_command,python) $(SRCDIR)/helpcontent2/helpers/make_icon_link.txt.py $(SRCDIR)/icon-themes/colibre/links.txt $@
199
200define html_gen_html_dep
201$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/html.text : \
202		$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl/links.txt.xsl) \
203	$(foreach module,$(html_TEXT_MODULES), \
204		$(if $(filter en-US,$(1)), \
205			$(call gb_AllLangHelp_get_helpfiles_target,$(module)), \
206			$(call gb_HelpTranslateTarget_get_target,$(module)/$(1))))
207
208endef
209
210$(eval $(foreach lang,$(gb_HELP_LANGS),$(call html_gen_html_dep,$(lang))))
211
212$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/html.text : \
213		$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl/links.txt.xsl) \
214		$(call gb_ExternalExecutable_get_dependencies,xsltproc)
215	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),XSL,1)
216	$(call gb_Helper_abbreviate_dirs,\
217		cd $(if $(filter en-US,$*),$(SRCDIR),$(call gb_HelpTranslatePartTarget_get_workdir,$*))/helpcontent2/source \
218		&& rm -rf $(dir $@)text \
219		&& RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),100,$(foreach module,$(html_TEXT_MODULES),$(patsubst helpcontent2/source/%,%,$(gb_AllLangHelp_$(module)_HELPFILES)))) \
220		&& <"$$RESPONSEFILE" $(if $(filter WNT,$(OS)),tr -d '\r' | env -i PATH="$$PATH") xargs -n 1 printf '%s\n' \
221		| while read xhp; do \
222			mkdir -p $$(dirname $(dir $@)$$xhp) && \
223			$(call gb_ExternalExecutable_get_command,xsltproc) \
224				--stringparam Language $* \
225				--stringparam local $(if $(HELP_ONLINE),'no','yes') \
226				--stringparam root $(if $(filter WNT,$(OS)),$$(cygpath -m `pwd`),`pwd`)/ \
227				--stringparam productname "$(PRODUCTNAME)" \
228				--stringparam productversion "$(PRODUCTVERSION)" \
229				--stringparam xapian $(if $(filter TRUE, $(HELP_OMINDEX_PAGE)),'yes','no') \
230				-o $(dir $@)$${xhp%.xhp}.html \
231				$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl/online_transform.xsl) \
232				$(if $(filter WNT,$(OS)),$$(cygpath -m `pwd`),`pwd`)/$$xhp \
233			|| exit \
234		; done \
235		&& rm "$$RESPONSEFILE" \
236		&& touch $@ \
237	)
238
239$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/bookmarks.js :
240	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),CAT,2)
241	$(call gb_Helper_abbreviate_dirs,\
242		( \
243			echo 'var bookmarks = [' \
244			&& cat $(filter %.part,$^) \
245			&& echo '];' \
246		) > $@ \
247	)
248
249define html__gen_bookmarks_lang_dep
250$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(2)/$(1)/bookmarks.part : \
251    $(if $(filter en-US,$(1)), \
252        $(call gb_AllLangHelp_get_helpfiles_target,$(firstword $(subst /, ,$(2)))), \
253        $(call gb_HelpTranslateTarget_get_target,$(firstword $(subst /, ,$(2)))/$(1)))
254
255endef
256
257define html__gen_bookmarks_lang_deps
258$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/bookmarks.js : \
259	$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(2)/$(1)/bookmarks.part
260$(call html__gen_bookmarks_lang_dep,$(1),$(2))
261$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(2)/$(1)/bookmarks.part : HELP_LANG := $(1)
262
263endef
264
265define html__gen_bookmarks_deps
266$(foreach lang,$(gb_HELP_LANGS),$(call html__gen_bookmarks_lang_deps,$(lang),$(1)))
267$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/%/bookmarks.part : APP := $(2)
268$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/$(1)/%/bookmarks.part : APPDIR := $(1)
269
270endef
271
272define html_gen_bookmarks_deps
273$(call html__gen_bookmarks_deps,$(firstword $(1)),$(lastword $(1)))
274
275endef
276
277$(eval $(foreach module,$(html_BMARK_MODULES),$(call html_gen_bookmarks_deps,$(subst :, ,$(module)))))
278
279# In the below recipe, the file $@.good is used to communicate failure of xsltproc in the pipeline
280# (similar to Bash's `set -o pipefail`; the final `rm $@.good` will fail, and fail the whole
281# command, if any xsltproc invocation failed):
282$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/%/bookmarks.part : \
283		$(SRCDIR)/helpcontent2/help3xsl/get_bookmark.xsl \
284		$(SRCDIR)/helpcontent2/help3xsl/brand.xsl \
285		$(call gb_ExternalExecutable_get_dependencies,xsltproc)
286	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),XSL,1)
287	$(call gb_Helper_abbreviate_dirs,\
288		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))) \
289		&& ( \
290			<"$$RESPONSEFILE" $(if $(filter WNT,$(OS)),tr -d '\r' | env -i PATH="$$PATH") xargs -n 1 printf '%s\n' \
291			| { rm -f $@.good && while read xhp; do \
292				$(call gb_ExternalExecutable_get_command,xsltproc) \
293					--stringparam app $(APP) \
294					--stringparam Language $(HELP_LANG) \
295					--stringparam local $(if $(HELP_ONLINE),'no','yes') \
296					--stringparam productname "$(PRODUCTNAME)" \
297					--stringparam productversion "$(PRODUCTVERSION)" \
298					$(SRCDIR)/helpcontent2/help3xsl/get_bookmark.xsl \
299					$$xhp \
300				|| exit \
301			; done && touch $@.good; } \
302			| sort -k3b -s \
303			| awk 'NF' \
304			&& rm $@.good \
305		) > $@ \
306		&& rm "$$RESPONSEFILE" \
307	)
308
309# The various gid_File_Help_*_Zip in scp2 that use EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG expect
310# $(module)/$(lang).filelist files containing lists of files (in instdir) for the corresponding
311# module/lang parts of help data.  As a hack, generate those from the existing HelpTarget file
312# lists, which specify the original .xhp files (in SRCDIR for en-US, translated for all other
313# langs).  For the shared module, also include the per-lang non .xhp/.html files from the
314# AllLangPackages helpcontent2_html_lang and helpcontent2_html_media_lang:
315
316# html__filelist,lang,module
317define html__filelist
318$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/filelists/html-help/$(2)/$(1).filelist: \
319        $(call gb_HelpTarget_get_filelist,$(2)/$(1)) \
320        $(if $(filter $(2),shared), \
321            $(call gb_Package_get_target,helpcontent2_html_lang_$(1)) \
322            $(call gb_Package_get_target,helpcontent2_html_media_lang_$(1)))
323	mkdir -p $$$$(dirname $$@)
324	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)) > $$@
325	$(if $(filter $(2),shared),cat $(call gb_Package_get_target,helpcontent2_html_lang_$(1)) $(call gb_Package_get_target,helpcontent2_html_media_lang_$(1)) >> $$@,:)
326
327endef
328
329$(eval $(foreach lang,$(gb_HELP_LANGS),$(foreach module,$(html_TEXT_MODULES),$(call html__filelist,$(lang),$(module)))))
330
331# vim: set noet sw=4 ts=4:
332