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