LocaleRules revision ef9994ee
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	$(CC) -E $(CCDEFS) -DB_COLLECTING_CATKEYS $(HDRS) "$(2[2-)" > "$(1)".pre | true
77	$(2[1]) $(HAIKU_CATALOG_REGEXP) -s $(HAIKU_CATALOG_SIGNATURE) \
78		-w -o "$(1)" "$(1)".pre
79}
80
81rule LinkApplicationCatalog target : sources : signature : language
82{
83	# Link catalog entries from given catkey file into output compiled catalog
84	# file. Compiled catalog file will then be copied into the image, but only
85	# if the fingerprint matches the one from the untranslated catalog for the
86	# same file.
87
88	local subdir = [ on $(signature) return $(HAIKU_CATALOGS_SUBDIR) ] ;
89	MakeLocate $(target) : [ FDirName $(HAIKU_CATALOGS_OBJECT_DIR) $(subdir) ] ;
90	Depends $(target) : $(sources) <build>linkcatkeys ;
91	LocalClean clean : $(target) ;
92
93	HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ;
94	HAIKU_CATALOG_LANGUAGE on $(target) = $(language) ;
95	LinkApplicationCatalog1 $(target) : <build>linkcatkeys $(sources) ;
96}
97
98actions LinkApplicationCatalog1
99{
100	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
101	$(2[1]) "$(2[2-])" -l $(HAIKU_CATALOG_LANGUAGE) \
102		-s $(HAIKU_CATALOG_SIGNATURE) -o "$(1)"
103}
104
105rule DoCatalogs target : signature : sources : sourceLanguage : regexp
106{
107	# DoCatalogs <target> : <signature> : <sources> [ : <sourceLanguage> ]
108	#	[ : <regexp> ]
109	#
110	# Extracts the catkeys from a target's source files, generates the
111	# default catalog from them, and also generates catalogs for all
112	# translations.
113	#
114	# target:			The target.
115	# signature: 		Application MIME signature (must match the one
116	#					declared in the sourcecode).
117	# sources: 			List of cpp files where to search keys.
118	# sourceLanguage	Short name of the language of used for the strings in
119	#					the sources. Optional: default is "en".
120	# regexp            The regular expression used to parse the files.
121	#                   Optional: default is matching be_catalog->GetString
122
123	local subdir ;
124	if [ on $(SUBDIR) return $(HAIKU_MULTIPLE_LOCALIZED_TARGETS) ] {
125		subdir = $(SUBDIR_TOKENS[2-]) $(target) ;
126	} else {
127		subdir = $(SUBDIR_TOKENS[2-]) ;
128	}
129
130	HAIKU_CATALOGS_SUBDIR on $(signature) = $(subdir) ;
131
132	local generatedCatalog
133		= $(sourceLanguage:G=$(signature):E=en:S=.catalog) ;
134	MakeLocate $(generatedCatalog)
135		: [ FDirName $(HAIKU_CATALOGS_OBJECT_DIR) $(subdir) ] ;
136
137	# generate catkeys file from sources
138	ExtractCatalogEntries $(generatedCatalog:S=.catkeys)
139		: [ FGristFiles $(sources) ] : $(signature) : $(regexp) ;
140
141	# find translations
142	local translationsDir
143		= [ FDirName $(HAIKU_TOP) data catalogs $(subdir) ] ;
144	local translations = [ Glob $(translationsDir) : *.catkeys ] ;
145	translations = [ FGristFiles $(translations:BS) ] ;
146	SEARCH on $(translations) += $(translationsDir) ;
147
148	# generate catalogs from all catkeys files
149	local catkeysFiles = $(generatedCatalog:S=.catkeys) $(translations) ;
150	for catkeysFile in $(catkeysFiles) {
151		LinkApplicationCatalog $(catkeysFile:S=.catalog) : $(catkeysFile)
152			: $(signature) : $(catkeysFile:B) ;
153	}
154
155	HAIKU_CATALOG_FILES on $(target) = $(catkeysFiles:S=.catalog) ;
156	HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ;
157
158	# For the pseudo-target LocalizedTargets
159	HAIKU_LOCALIZED_TARGETS += $(target) ;
160
161	# For the pseudo-target catalogs
162	HAIKU_LOCALE_CATALOGS += $(catkeysFiles:S=.catalog) ;
163
164	# For the pseudo-target catkeys
165	HAIKU_LOCALE_OUTPUT_CATKEYS += $(generatedCatalog:S=.catkeys) ;
166}
167
168rule AddCatalogEntryAttribute target
169{
170	# AddCatalogEntryAttribute <target> : <attribute value> ;
171	#
172	# <attribute value> should be of the form
173	#	"x-vnd.Haiku-App:context:string"
174
175	CATALOG_ENTRY on $(target) = "$(2)" ;
176
177	Depends $(target) : <build>addattr ;
178
179	AddCatalogEntryAttribute1 $(target)
180		: <build>addattr ;
181}
182
183actions AddCatalogEntryAttribute1
184{
185	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
186	"$(2)" -t string "SYS:NAME" "$(CATALOG_ENTRY)" "$(1)"
187}
188