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