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