xref: /haiku/build/jam/LocaleRules (revision 8d2bf6953e851d431fc67de1bc970c40afa79e9f)
1# Localization rules
2
3# Extract catalog entries from the sourcefile and put the output textfile in
4# target. This output file is then used to create the binary catalog with
5# linkcatkeys.
6rule ExtractCatalogEntries target : sources : signature : regexp
7{
8	# get compiler and defines for the platform
9	local headers ;
10	local sysHeaders ;
11	local cc ;
12	local defines ;
13	local includesSeparator ;
14	local localIncludesOption ;
15	local systemIncludesOption ;
16
17	on $(target) { # use on $(target) variable values
18		defines = $(DEFINES) ;
19		headers = $(HAIKU_CONFIG_HEADERS) $(SEARCH_SOURCE) $(SUBDIRHDRS)
20			$(HDRS) ;
21		sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ;
22
23		if $(PLATFORM) = host {
24			sysHeaders += $(HOST_HDRS) ;
25			defines += $(HOST_DEFINES) ;
26			cc = $(HOST_CC) ;
27			if $(USES_BE_API) {
28				sysHeaders += $(HOST_BE_API_HEADERS) ;
29			}
30
31			includesSeparator = $(HOST_INCLUDES_SEPARATOR) ;
32			localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ;
33			systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ;
34		} else {
35			sysHeaders += $(TARGET_HDRS) ;
36			defines += $(TARGET_DEFINES) ;
37			cc = $(TARGET_CC) ;
38
39			includesSeparator = $(TARGET_INCLUDES_SEPARATOR) ;
40			localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ;
41			systemIncludesOption = $(TARGET_SYSTEM_INCLUDES_OPTION) ;
42		}
43	}
44
45	DEFINES on $(target) = $(defines) ;
46	CCDEFS on $(target) = [ FDefines $(defines) ] ;
47	HDRS on $(target) = [ FIncludes $(headers) : $(localIncludesOption) ]
48		$(includesSeparator)
49		[ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ;
50	CC on $(target) = $(cc) ;
51
52	HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ;
53	if $(regexp) = "" {
54		HAIKU_CATALOG_REGEXP on $(target) = ;
55	} else {
56		HAIKU_CATALOG_REGEXP on $(target) = -r $(regexp) ;
57	}
58
59	SEARCH on $(sources) += $(SEARCH_SOURCE) ;
60
61	local subdir = [ on $(signature) return $(HAIKU_CATALOGS_SUBDIR) ] ;
62	MakeLocate $(target) : [ FDirName $(HAIKU_CATALOGS_OBJECT_DIR) $(subdir) ] ;
63	Depends $(target) : $(sources) <build>collectcatkeys ;
64	LocalClean clean : $(target).pre ;
65	ExtractCatalogEntries1 $(target) : <build>collectcatkeys $(sources) ;
66}
67
68actions ExtractCatalogEntries1
69{
70	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
71	cat "$(2[2-])" \
72		| $(CC) -E $(CCDEFS) -DB_COLLECTING_CATKEYS $(HDRS) - > "$(1)".pre
73	$(2[1]) $(HAIKU_CATALOG_REGEXP) -s $(HAIKU_CATALOG_SIGNATURE) \
74		-w -o "$(1)" "$(1)".pre
75}
76
77rule LinkApplicationCatalog target : sources : signature : language
78{
79	# Link catalog entries from given catkey file into output compiled catalog
80	# file. Compiled catalog file will then be copied into the image, but only
81	# if the fingerprint matches the one from the untranslated catalog for the
82	# same file.
83
84	local subdir = [ on $(signature) return $(HAIKU_CATALOGS_SUBDIR) ] ;
85	MakeLocate $(target) : [ FDirName $(HAIKU_CATALOGS_OBJECT_DIR) $(subdir) ] ;
86	Depends $(target) : $(sources) <build>linkcatkeys ;
87	LocalClean clean : $(target) ;
88
89	HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ;
90	HAIKU_CATALOG_LANGUAGE on $(target) = $(language) ;
91	LinkApplicationCatalog1 $(target) : <build>linkcatkeys $(sources) ;
92}
93
94actions LinkApplicationCatalog1
95{
96	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
97	$(2[1]) "$(2[2-])" -l $(HAIKU_CATALOG_LANGUAGE) \
98		-s $(HAIKU_CATALOG_SIGNATURE) -o "$(1)"
99}
100
101rule DoCatalogs target : signature : sources : sourceLanguage : regexp
102{
103	# DoCatalogs <target> : <signature> : <sources> [ : <sourceLanguage> ]
104	#	[ : <regexp> ]
105	#
106	# Extracts the catkeys from a target's source files, generates the
107	# default catalog from them, and also generates catalogs for all
108	# translations.
109	#
110	# target:			The target.
111	# signature: 		Application MIME signature (must match the one
112	#					declared in the sourcecode).
113	# sources: 			List of cpp files where to search keys.
114	# sourceLanguage	Short name of the language of used for the strings in
115	#					the sources. Optional: default is "en".
116	# regexp            The regular expression used to parse the files.
117	#                   Optional: default is matching be_catalog->GetString
118
119	local subdir ;
120	if [ on $(SUBDIR) return $(HAIKU_MULTIPLE_LOCALIZED_TARGETS) ] {
121		subdir = $(SUBDIR_TOKENS[2-]) $(target) ;
122	} else {
123		subdir = $(SUBDIR_TOKENS[2-]) ;
124	}
125
126	HAIKU_CATALOGS_SUBDIR on $(signature) = $(subdir) ;
127
128	local generatedCatalog
129		= $(sourceLanguage:G=$(signature):E=en:S=.catalog) ;
130	MakeLocate $(generatedCatalog)
131		: [ FDirName $(HAIKU_CATALOGS_OBJECT_DIR) $(subdir) ] ;
132
133	# generate catkeys file from sources
134	ExtractCatalogEntries $(generatedCatalog:S=.catkeys)
135		: [ FGristFiles $(sources) ] : $(signature) : $(regexp) ;
136
137	# find translations
138	local translationsDir
139		= [ FDirName $(HAIKU_TOP) data catalogs $(subdir) ] ;
140	local translations = [ Glob $(translationsDir) : *.catkeys ] ;
141	translations = [ FGristFiles $(translations:BS) ] ;
142	SEARCH on $(translations) += $(translationsDir) ;
143
144	# generate catalogs from all catkeys files
145	local catkeysFiles = $(generatedCatalog:S=.catkeys) $(translations) ;
146	for catkeysFile in $(catkeysFiles) {
147		LinkApplicationCatalog $(catkeysFile:S=.catalog) : $(catkeysFile)
148			: $(signature) : $(catkeysFile:B) ;
149	}
150
151	HAIKU_CATALOG_FILES on $(target) = $(catkeysFiles:S=.catalog) ;
152	HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ;
153
154	# For the pseudo-target LocalizedTargets
155	HAIKU_LOCALIZED_TARGETS += $(target) ;
156
157	# For the pseudo-target catalogs
158	HAIKU_LOCALE_CATALOGS += $(catkeysFiles:S=.catalog) ;
159
160	# For the pseudo-target catkeys
161	HAIKU_LOCALE_OUTPUT_CATKEYS += $(generatedCatalog:S=.catkeys) ;
162}
163
164rule AddCatalogEntryAttribute target
165{
166	# AddCatalogEntryAttribute <target> : <attribute value> ;
167	#
168	# <attribute value> should be of the form
169	#	"x-vnd.Haiku-App:context:string"
170
171	CATALOG_ENTRY on $(target) = "$(2)" ;
172
173	Depends $(target) : <build>addattr ;
174
175	AddCatalogEntryAttribute1 $(target)
176		: <build>addattr ;
177}
178
179actions AddCatalogEntryAttribute1
180{
181	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
182	"$(2)" -t string "SYS:NAME" "$(CATALOG_ENTRY)" "$(1)"
183}
184