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