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