xref: /haiku/build/jam/LocaleRules (revision 04a0e9c7b68cbe3a43d38e2bca8e860fd80936fb)
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_$(TARGET_PACKAGING_ARCH)) ;
36			defines += $(TARGET_DEFINES_$(TARGET_PACKAGING_ARCH))
37				$(TARGET_DEFINES) ;
38			cc = $(TARGET_CC_$(TARGET_PACKAGING_ARCH)) ;
39
40			includesSeparator
41				= $(TARGET_INCLUDES_SEPARATOR_$(TARGET_PACKAGING_ARCH)) ;
42			localIncludesOption
43				= $(TARGET_LOCAL_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
44			systemIncludesOption
45				= $(TARGET_SYSTEM_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
46		}
47	}
48
49	DEFINES on $(target) = $(defines) ;
50	CCDEFS on $(target) = [ FDefines $(defines) ] ;
51	HDRS on $(target) = [ FIncludes $(headers) : $(localIncludesOption) ]
52		$(includesSeparator)
53		[ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ;
54	CC on $(target) = $(cc) ;
55
56	HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ;
57	if $(regexp) = "" {
58		HAIKU_CATALOG_REGEXP on $(target) = ;
59	} else {
60		HAIKU_CATALOG_REGEXP on $(target) = -r $(regexp) ;
61	}
62
63	SEARCH on $(sources) += $(SEARCH_SOURCE) ;
64
65	local subdir = [ on $(signature) return $(HAIKU_CATALOGS_SUBDIR) ] ;
66	MakeLocate $(target) : [ FDirName $(HAIKU_CATALOGS_OBJECT_DIR) $(subdir) ] ;
67	Depends $(target) : $(sources) <build>collectcatkeys ;
68	LocalClean clean : $(target).pre ;
69	ExtractCatalogEntries1 $(target) : <build>collectcatkeys $(sources) ;
70}
71
72actions ExtractCatalogEntries1
73{
74	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
75	cat "$(2[2-])" \
76		| $(CC) -E $(CCDEFS) -DB_COLLECTING_CATKEYS $(HDRS) - > "$(1)".pre
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