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