forked from SUSE/doc-sle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
293 lines (229 loc) · 13.3 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#
# Copyright (c) 2014 Rick Salevsky <rsalevsky@suse.de>
# Copyright (c) 2016 Stefan Knorr <sknorr@suse.de>
# Copyright (c) 2017 Guo Yunhe
# Copyright (c) 2018 Alessio Adamo <alessio@alessioadamo.com>
#
# How to use this makefile:
# * After updating the XML: $ make po
# * When creating output: $ make all
# * To specify to type of output: $ make pdf | text | single-html
# * To specify the books to build: $ make BOOKS_TO_TRANSLATE="book1 book2 book3" (default="DC-SLED-all DC-SLES-all DC-opensuse-all")
# * To specify the langs to build: $ make LANGS="lang_code1 lang_code2 lang_code3" (default: langs with at least 60% translation)
# * To clean up: $ make clean
# * For in depth cleanup: $ make cleanall (performs same cleaning actions of target 'clean' and in addition removes .pot
# files and obsolete files)
# * To remove just obsolete files: $ make clean_obsolete
.PHONY: all po pot translate validate pdf text single-html clean_po_temp clean_mo clean_pot clean clean_obsolete cleanall
# Make sure that 'doc-sle' project and 'doc-sle-translations' subproject are
# on the same branch
MAIN_PROJECT_BRANCH := $(shell git branch | grep \* | sed 's@ @@; s@\*@@')
SUBPROJECT_BRANCH := $(shell cd locale && git checkout $(MAIN_PROJECT_BRANCH) &>/dev/null; git branch | grep \* | sed 's@ @@; s@\*@@')
ifneq ($(MAIN_PROJECT_BRANCH),$(SUBPROJECT_BRANCH))
$(error Main project branch is '$(MAIN_PROJECT_BRANCH)' while subproject branch is '$(SUBPROJECT_BRANCH)'. Failed to check out branch '$(MAIN_PROJECT_BRANCH)' in subproject)
endif
# The list of available languages is retrieved by searching for subdirs with
# pattern lang/po and removing the '/po' suffix
FULL_LANG_LIST := $(patsubst locale/%/po,%,$(wildcard locale/*/po))
# The list of available books is retrieved by searching for pattern DC-*
FULL_BOOK_LIST := $(wildcard DC-*)
# The list of source files is represented by all '.xml' files in xml/ dir
# except schemas.xml which does not contain translatable strings
FULL_XML_LIST := $(filter-out xml/schemas.xml,$(wildcard xml/*.xml))
# The list of entities is represented by all '.ent' files in xml/ dir
FULL_ENT_LIST := $(wildcard xml/*.ent)
# The list of images is represented by all files under 'images/src/*' dirs
FULL_IMAGE_LIST := $(wildcard images/src/*/*)
# The PO domain list is generated by taking the basename of the source files
# and removing the dir part
FULL_DOMAIN_LIST := $(basename $(notdir $(FULL_XML_LIST)))
# The list of POT files is generated by attaching the 'locale/50-pot/' prefix and the
# '.pot' suffix to each domain
FULL_POT_LIST := $(foreach DOMAIN,$(FULL_DOMAIN_LIST),locale/50-pot/$(DOMAIN).pot)
# The list of PO files is generated as follows. First, for each available language
# it is generated a pattern like 'locale/[lang_code]/po/_DOMAIN_NAME_.lang.po', then the placeholder
# _DOMAIN_NAME_ is substituted with each available domain to get a pattern like
# 'locale/[lang_code]/po/domain.lang.po'
FULL_PO_LIST := $(foreach DOMAIN,$(FULL_DOMAIN_LIST),$(subst _DOMAIN_NAME_,$(DOMAIN),$(foreach LANG,$(FULL_LANG_LIST),locale/$(LANG)/po/_DOMAIN_NAME_.$(LANG).po)))
# The list of MO files is generated by substituting the extension .po with .mo in
# FULL_PO_LIST
FULL_MO_LIST := $(patsubst %.po,%.mo,$(FULL_PO_LIST))
# If not specified, the default books to be translated are DC-SLED-all, DC-SLES-all,
# DC-opensuse-all
ifndef BOOKS_TO_TRANSLATE
BOOKS_TO_TRANSLATE := DC-SLED-all DC-SLES-all DC-opensuse-all
endif
# The variable 'SELECTED_SOURCES" is necessary only for targets that are related to the translation of
# the XMLs. It relies on the 'xml-selector' script which in turn relies on the command 'daps list-srcfiles'.
# Since this operation is time consuming, it is performed # only for a subset of targets (specifically 'mo',
# 'translate', 'validate', 'pdf', 'single-html', 'text'). See variable 'CHECK_IF_TO_BE_TRANSLATED'.
CHECK_IF_TO_BE_TRANSLATED := $(filter all mo translate validate pdf single-html text,$(MAKECMDGOALS))
ifdef CHECK_IF_TO_BE_TRANSLATED
# Determine the sources necessary to build selected books
SELECTED_SOURCES := $(shell 50-tools/xml-selector $(BOOKS_TO_TRANSLATE) | tee /dev/tty | sed '1d; s@XML sources of .*: @@; /^$$/d' | tr ' ' '\n' | sort -u)
endif
# These are the xml files required for the selected books stored in the
# variable "BOOKS_TO_TRANSLATE"
SELECTED_XML_FILES := $(filter %.xml,$(SELECTED_SOURCES))
# These are the ent files required for the selected books stored in the
# variable "BOOKS_TO_TRANSLATE"
SELECTED_ENT_FILES := $(filter %.ent,$(SELECTED_SOURCES))
# These are the PO domain list required for the translation of selected books stored in the
# variable "BOOKS_TO_TRANSLATE"
SELECTED_DOMAIN_LIST := $(basename $(notdir $(SELECTED_XML_FILES)))
ifndef LANGS
# If LANGS is not defined within the command line, for output use only those files that are at least 60% translated.
# This check is made through the script 'po-selector'. However, since this operation is time consuming, it is performed
# only for a subset of targets. See variable 'CHECK_IF_TO_BE_TRANSLATED'.
ifdef CHECK_IF_TO_BE_TRANSLATED
# TO DO: rework the po-selector script so that 60% translation is not calculated on the single PO, but overall.
LANGS := $(shell 50-tools/po-selector $(SELECTED_DOMAIN_LIST) | tee /dev/tty | sort -u)
# If no language is suitable, print an error message and quit.
ifeq ($(strip $(LANGS)),)
$(error No language passed selection! Eventually, force one or more languages by passing LANG="lang_code1 lang_code2 ..." on the command line.)
endif
endif
endif
# TO DO: check if LANGSEN is still necessary (legacy from release-notes project)
LANGSEN := $(LANGS) en
# The list of MO files necessary for the translation of the selected sources is generated as follows.
# For each selected language, the file name is built by adding the suffix '.lang.mo' to the list of
# selected domains, then it is added the prefix 'locale/[lang_code]/po/' as dir name.
SELECTED_MO_FILES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/po/,$(addsuffix .$(LANG).mo,$(SELECTED_DOMAIN_LIST))))
# The list of destination DC-, XML and ENT files is made by prefixing 'locale/[lang_code]/'
XML_DEST_FILES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/,$(SELECTED_XML_FILES)))
ENT_DEST_FILES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/,$(SELECTED_ENT_FILES)))
SCHEMAS_XML_DEST_FILES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/xml/,schemas.xml))
DC_DEST_FILES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/,$(BOOKS_TO_TRANSLATE)))
# TO DO: select only necessary images via 'daps list-srcfiles'
IMAGE_DEST_FILES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/,$(FULL_IMAGE_LIST)))
# The XML sources to be translated to create the requested output are retrieved by parsing the output of
# daps list-srcfiles, however when a book depends on — let's say — MAIN.*.xml (e.g. DC-SLES-tuning), validation
# and output generation fail because daps requires all XML files listed in the <xi:include href="file_name.xml"/>
# tags. To be on the safe side, create a symlink for all unselected sources prior to validation.
# The list of unselected sources is obtained by filtering out the selected sources from the full list.
# To that it is prepended each selected lang dir.
# TO DO: check whether to obtain 100% output translation it is necessary to have also the additional files
# translated
UNSELECTED_XML_SOURCES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/,$(filter-out $(SELECTED_XML_FILES),$(FULL_XML_LIST))))
UNSELECTED_ENT_SOURCES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/,$(filter-out $(SELECTED_ENT_FILES),$(FULL_ENT_LIST))))
# Functions to retrieve the path and file name of pdf/single html/text output
# TO DO: check why daps seems to ignore that xml files are translated into languages other than English
WHICH_PDF = $(shell 50-tools/output-retriever --dc-name $1 --pdf-name)
WHICH_HTML = $(shell 50-tools/output-retriever --dc-name $1 --html-name)
WHICH_TEXT = $(shell 50-tools/output-retriever --dc-name $1 --text-name)
# List of output files depending on selected languages and books to translate
PDF_FILES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/,$(foreach BOOK,$(BOOKS_TO_TRANSLATE), $(call WHICH_PDF,$(BOOK)))))
SINGLE_HTML_FILES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/,$(foreach BOOK,$(BOOKS_TO_TRANSLATE), $(call WHICH_HTML,$(BOOK)))))
TEXT_FILES := $(foreach LANG,$(LANGS),$(addprefix locale/$(LANG)/,$(foreach BOOK,$(BOOKS_TO_TRANSLATE), $(call WHICH_TEXT,$(BOOK)))))
# Find out all obsolete files.
# The current full POT file list was generated from current XML files. Obsolete POT file list is generated by filtering out
# the current full POT file list from the content of 'locale/50-pot/' dir
OBSOLETE_POT_LIST := $(filter-out $(FULL_POT_LIST), $(wildcard locale/50-pot/*.pot))
# The current full PO file list was generated from current POT files. Obsolete PO file list is generated by filtering out
# the current full PO file list from the content of 'locale/[lang_code]/po/' dirs
OBSOLETE_PO_LIST := $(filter-out $(FULL_PO_LIST), $(wildcard locale/*/po/*.po))
# The current full image file list is generated by prefixing the lang code to 'FULL_IMAGE_LIST'. Obsolete image file list
# is generated by filtering out the current full image file list from the content of 'locale/[lang_code]/images/src/*/' dirs
OBSOLETE_IMAGE_LIST := $(filter-out $(foreach LANG,$(FULL_LANG_LIST),$(addprefix locale/$(LANG)/,$(FULL_IMAGE_LIST))), $(wildcard locale/*/images/src/*/*))
OBSOLETE_FILE_LIST := $(OBSOLETE_POT_LIST) $(OBSOLETE_PO_LIST) $(OBSOLETE_IMAGE_LIST)
# TO DO: check if VERSION is still necessary (legacy from release-notes project)
ifndef VERSION
VERSION := unreleased
endif
# TO DO: check if DATE is still necessary (legacy from release-notes project)
ifndef DATE
DATE := $(shell date +%Y-%0m-%0d)
endif
DAPS_COMMAND_BASIC = daps -vv
DAPS_COMMAND = $(DAPS_COMMAND_BASIC) -d
ITSTOOL = itstool -i 50-tools/suse.its
all: pdf single-html text
pot: $(FULL_POT_LIST)
locale/50-pot/%.pot: xml/%.xml
$(ITSTOOL) -o $@ $<
po: $(FULL_PO_LIST)
define update_po
locale/$(1)/po/%.$(1).po: locale/50-pot/%.pot
if [ -r $$@ ]; then \
msgmerge --previous --update $$@ $$<; \
else \
msginit -o $$@ -i $$< --no-translator -l $(1); \
fi
endef
$(foreach LANG,$(FULL_LANG_LIST),$(eval $(call update_po,$(LANG))))
mo: $(SELECTED_MO_FILES)
%.mo: %.po
msgfmt $< -o $@
translate: $(XML_DEST_FILES) $(SCHEMAS_XML_DEST_FILES) $(ENT_DEST_FILES) $(UNSELECTED_XML_SOURCES) $(UNSELECTED_ENT_SOURCES) $(DC_DEST_FILES) $(IMAGE_DEST_FILES)
define translate_xml
$$(XML_DEST_FILES): locale/$(1)/xml/%.xml: locale/$(1)/po/%.$(1).mo xml/%.xml
if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
$$(ITSTOOL) -l $(1) -m $$< -o $$(@D) $$(filter %.xml,$$^)
daps-xmlformat -i $$@
locale/%/xml/schemas.xml: xml/schemas.xml
if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
ln -s ../../../$$< $$@
$$(ENT_DEST_FILES): locale/$(1)/xml/%.ent: xml/%.ent
if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
ln -s ../../../$$< $$@
ifneq ($$(strip $$(UNSELECTED_XML_SOURCES)),)
$$(UNSELECTED_XML_SOURCES): locale/$(1)/xml/%.xml: xml/%.xml
if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
ln -s ../../../$$< $$@
endif
ifneq ($$(strip $$(UNSELECTED_ENT_SOURCES)),)
$$(UNSELECTED_ENT_SOURCES): locale/$(1)/xml/%.ent: xml/%.ent
if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
ln -s ../../../$$< $$@
endif
$$(DC_DEST_FILES): locale/$(1)/%: %
cp $$< $$(@D)
$$(IMAGE_DEST_FILES): locale/$(1)/%: %
if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
if [ ! -L $$@ -a ! -f $$@ ]; then ln -s ../../../../../$$< $$@; fi
endef
$(foreach LANG,$(LANGS),$(eval $(call translate_xml,$(LANG))))
validate: translate
@for DC_FILE in $(DC_DEST_FILES); do \
echo -n "$$DC_FILE: "; \
daps -d $$DC_FILE validate; \
done
# TO DO: Handle 'en' output.
pdf: validate $(PDF_FILES)
define generate_pdf
$(2): $(1)
$$(DAPS_COMMAND) $$< pdf
endef
$(foreach LANG,$(LANGS),$(foreach BOOK, $(BOOKS_TO_TRANSLATE),$(eval $(call generate_pdf,$(BOOK),$(addprefix locale/$(LANG)/,$(call WHICH_PDF,$(BOOK)))))))
single-html: validate $(SINGLE_HTML_FILES)
define generate_html
$(2): $(1)
$$(DAPS_COMMAND) $$< html --single
# TO DO: check if the following arguments are still necessary
# --stringparam "homepage='https://www.opensuse.org'"
endef
$(foreach LANG,$(LANGS),$(foreach BOOK, $(BOOKS_TO_TRANSLATE),$(eval $(call generate_html,$(BOOK),$(addprefix locale/$(LANG)/,$(call WHICH_HTML,$(BOOK)))))))
text: validate $(TEXT_FILES)
define generate_text
$(2): $(1)
$$(DAPS_COMMAND) $$< text
endef
$(foreach LANG,$(LANGS),$(foreach BOOK, $(BOOKS_TO_TRANSLATE),$(eval $(call generate_text,$(BOOK),$(addprefix locale/$(LANG)/,$(call WHICH_TEXT,$(BOOK)))))))
clean_po_temp:
rm -rf $(foreach LANG,$(FULL_LANG_LIST),$(addprefix locale/$(LANG),/po/*.po~))
clean_mo:
rm -rf $(FULL_MO_LIST)
clean_pot:
rm -rf $(FULL_POT_LIST)
clean: clean_po_temp clean_mo
rm -rf $(foreach LANG,$(FULL_LANG_LIST),$(addprefix locale/$(LANG),/xml/))
rm -rf $(foreach LANG,$(FULL_LANG_LIST),$(addprefix locale/$(LANG)/,$(FULL_BOOK_LIST)))
rm -rf $(foreach LANG,$(FULL_LANG_LIST),$(addprefix locale/$(LANG),/build/))
rm -rf build/
clean_obsolete:
@if [ " $(strip $(OBSOLETE_FILE_LIST))" == " " ]; then \
echo "No obsolete files detected!"; \
else rm -rf $(OBSOLETE_FILE_LIST) && echo "Removed: $(OBSOLETE_FILE_LIST)"; \
fi
cleanall: clean clean_pot clean_obsolete