1# BeOS specific rules 2 3rule AddFileDataAttribute target : attrName : attrType : dataFile 4{ 5 # AddFileAttribute <target> : <attrName> : <attrType> : <dataFile> ; 6 # Adds a single attribute to a file, retrieving the attribute data from 7 # a separate file. 8 # <target>: The file to which the attribute shall be added. 9 # <attrName>: The name of the attribute. 10 # <attrType>: Attribute type as supported by addattr (string, int, etc.) 11 # <dataFile>: The data to be written to the attribute will be read from 12 # that file. 13 # Note that this is supposed to be a build target, not a path 14 # name - if you need to add a data file in a different path, 15 # you have to locate it first. 16 # 17 18 # We need to create a temporary file in which we store the attribute name 19 # and type. Otherwise we wouldn't have these data available in the 20 # addattr actions. 21 local id = [ NextID ] ; 22 local attrMetaFile 23 = [ FGristFiles $(target:G=)-attr-$(attrName)-$(attrType)-$(id) ] ; 24 25 ATTRIBUTE_NAME on $(attrMetaFile) = $(attrName) ; 26 ATTRIBUTE_TYPE on $(attrMetaFile) = $(attrType) ; 27 MakeLocateArch $(attrMetaFile) ; 28 CreateAttributeMetaFile $(attrMetaFile) ; 29 30 Depends $(target) : <build>addattr $(attrMetaFile) $(dataFile) ; 31 AddFileDataAttribute1 $(target) 32 : <build>addattr $(attrMetaFile) $(dataFile) ; 33} 34 35actions CreateAttributeMetaFile 36{ 37 echo "-t $(ATTRIBUTE_TYPE)" "$(ATTRIBUTE_NAME)" > "$(1)" 38} 39 40actions AddFileDataAttribute1 41{ 42 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 43 $(2[1]) -f $(2[3]) `cat $(2[2])` $(1) 44} 45 46rule AddStringDataResource 47{ 48 # AddStringDataResource <target> : <resourceID> : <dataString> 49 # Adds a single resource to the resources of an executable/library. 50 # <target>: The executable/library. 51 # <resourceID>: A resource ID string as understood by xres (type:id[:name]). 52 # <dataString>: The string <dataString> will be written to the resource. 53 # Defaults to "". 54 # 55 local target = $(1) ; 56 local resourceID = $(2) ; 57 local dataString = $(3:E="") ; 58 59 # the resource file 60 local resources 61 = [ FGristFiles $(target:B)-added-string-data-resources.rsrc ] ; 62 63 # add the resource file to the target, if not yet done 64 if ! [ on $(resources) return $(RESOURCES_ADDED) ] { 65 RESOURCES_ADDED on $(resources) = true ; 66 MakeLocateArch $(resources) ; 67 Depends $(resources) : <build>xres ; 68 AddStringDataResource1 $(resources) : <build>xres ; 69 AddResources $(target) : $(resources) ; 70 } 71 72 RESOURCE_STRINGS on $(resources) 73 += "-a "$(resourceID)" -s \""$(dataString)"\"" ; 74} 75 76actions together AddStringDataResource1 77{ 78 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 79 $(2[1]) -o "$(1)" $(RESOURCE_STRINGS) 80} 81 82rule AddFileDataResource 83{ 84 # AddFileDataResource <target> : <resourceID> : [ <dataFile> ] 85 # Adds a single resource to the resources of an executable/library. 86 # <target>: The executable/library. 87 # <resourceID>: A resource ID string as understood by xres (type:id[:name]). 88 # <dataFile>: The data to be written into the resource will be read from 89 # that file. 90 # Note that this is supposed to be a build target, not a path 91 # name - if you need to add a data file in a different path, you 92 # have to locate it first. 93 # 94 local target = $(1) ; 95 local resourceID = $(2) ; 96 local dataFile = $(3) ; 97 98 # the resource file 99 local resources 100 = <added-resources>file-data-$(resourceID)-$(dataFile).rsrc ; 101 102 # add it to the resources of the given target 103 AddResources $(target) : $(resources) ; 104 105 # if the rule for creating the resource file has not been invoked yet, do it 106 if ! [ on $(resources) return $(RESOURCES_DEFINED) ] { 107 RESOURCES_DEFINED on $(resources) = true ; 108 RESOURCE_ID on $(resources) = $(resourceID) ; 109 MakeLocateArch $(resources) ; 110 111 Depends $(resources) : <build>xres $(dataFile) ; 112 AddFileDataResource1 $(resources) : <build>xres $(dataFile) ; 113 } 114} 115 116actions AddFileDataResource1 117{ 118 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 119 $(2[1]) -o "$(1)" -a "$(RESOURCE_ID)" "$(2[2])" ; 120} 121 122rule XRes 123{ 124 # XRes <target> : <resource files> 125 if $(2) 126 { 127 Depends $(1) : <build>xres $(2) ; 128 XRes1 $(1) : <build>xres $(2) ; 129 } 130} 131 132actions XRes1 133{ 134 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 135 $(2[1]) -o "$(1)" "$(2[2-])" ; 136} 137 138rule SetVersion 139{ 140 # SetVersion <target> 141 142 Depends $(1) : <build>setversion ; 143 SetVersion1 $(1) : <build>setversion ; 144} 145 146actions SetVersion1 147{ 148 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 149 $(2[1]) "$(1)" -system $(HAIKU_BUILD_VERSION) -short "$(HAIKU_BUILD_DESCRIPTION)" ; 150} 151 152rule SetType 153{ 154 # SetType <target> 155 156 Depends $(1) : <build>settype ; 157 SetType1 $(1) : <build>settype ; 158} 159 160actions SetType1 161{ 162 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 163 $(2[1]) -t $(TARGET_EXECUTABLE_MIME_TYPE) "$(1)" ; 164} 165 166rule MimeSet 167{ 168 # MimeSet <target> 169 170 Depends $(1) : <build>mimeset ; 171 MimeSet1 $(1) : <build>mimeset ; 172} 173 174actions MimeSet1 175{ 176 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 177 $(2[1]) -f "$(1)" ; 178} 179 180rule ResComp 181{ 182 # ResComp <resource file> : <rdef file> ; 183 # 184 # <resource file> and <rdef file> must be gristed. 185 186 # get compiler and defines for the platform 187 local cc ; 188 local defines ; 189 local localIncludesOption ; 190 191 on $(1) { # use on $(1) variable values 192 defines = $(DEFINES) ; 193 194 if $(PLATFORM) = host { 195 defines += $(HOST_DEFINES) ; 196 cc = $(HOST_CC) ; 197 localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; 198 } else { 199 defines += $(TARGET_DEFINES) ; 200 cc = $(TARGET_CC) ; 201 localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ; 202 } 203 } 204 205 DEFINES on $(1) = $(defines) ; 206 CCDEFS on $(1) = [ FDefines $(defines) ] ; 207 HDRS on $(1) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) 208 : $(localIncludesOption) ] ; 209 RCHDRS on $(1) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) 210 : "-I " ] ; 211 CC on $(1) = $(cc) ; 212 213 # set up other vars 214 SEARCH on $(2) += $(SEARCH_SOURCE) ; 215 MakeLocateArch $(1) ; 216 Depends $(1) : $(2) <build>rc ; 217 LocalClean clean : $(1) ; 218 ResComp1 $(1) : <build>rc $(2) ; 219} 220 221# Note: We pipe the input files into the preprocessor, since *.rdef files are 222# considered linker scripts, and thus we can use preprocessor features. 223actions ResComp1 224{ 225 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 226 cat "$(2[2-])" | $(CC) -E $(CCDEFS) $(HDRS) - | egrep -v '^#' | $(2[1]) $(RCHDRS) --auto-names -o "$(1)" - 227} 228 229rule ResAttr attributeFile : _resourceFiles : deleteAttributeFile 230{ 231 # ResAttr <attribute file> : <resource files> [ : <delete file> ] ; 232 # 233 # <attribute file> and <resource files> must be gristed. 234 # <resource files> can also be .rdef files -- they will be compiled first in 235 # this case. 236 # <clear file> is a boolean that specifies wether or not the target file 237 # should be removed before writing. Defaults to true. 238 239 local resourceFiles ; 240 local resourceFile ; 241 deleteAttributeFile ?= true ; 242 deleteAttributeFile1 on $(1) = $(deleteAttributeFile) ; 243 244 for resourceFile in $(_resourceFiles) { 245 # if the specified resource file is an .rdef file, we compile it first 246 if $(resourceFile:S) = ".rdef" { 247 local rdefFile = $(resourceFile) ; 248 resourceFile = $(rdefFile:S=.rsrc) ; 249 ResComp $(resourceFile) : $(rdefFile) ; 250 } else { 251 SEARCH on $(resourceFile) += $(SEARCH_SOURCE) ; 252 } 253 254 resourceFiles += $(resourceFile) ; 255 } 256 257 MakeLocateArch $(attributeFile) ; 258 Depends $(attributeFile) : $(resourceFiles) <build>resattr ; 259 LocalClean clean : $(attributeFile) ; 260 ResAttr1 $(attributeFile) : <build>resattr $(resourceFiles) ; 261} 262 263actions ResAttr1 264{ 265 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 266 if [ \\"$(deleteAttributeFile1)\\" = "true" ]; then 267 $(RM) $(1) 268 fi 269 $(2[1]) -O -o "$(1)" "$(2[2-])" 270} 271 272# Localization rules 273 274# Extract catalog entries from the sourcefile and put the output textfile in 275# target. This output file is then used to create the binary catalog with 276# linkcatkeys. 277rule ExtractCatalogEntries target : source : signature 278{ 279 # get compiler and defines for the platform 280 local headers ; 281 local sysHeaders ; 282 local cc ; 283 local defines ; 284 local localIncludesOption ; 285 local systemIncludesOption ; 286 287 on $(target) { # use on $(target) variable values 288 headers = $(HAIKU_CONFIG_HEADERS) $(SEARCH_SOURCE) $(SUBDIRHDRS) 289 $(HDRS) ; 290 sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ; 291 defines = $(DEFINES) ; 292 293 if $(PLATFORM) = host { 294 sysHeaders += $(HOST_HDRS) ; 295 defines += $(HOST_DEFINES) ; 296 297 if $(USES_BE_API) { 298 sysHeaders += $(HOST_BE_API_HEADERS) ; 299 } 300 301 defines += $(HOST_DEFINES) ; 302 cc = $(HOST_CC) ; 303 localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; 304 systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ; 305 } else { 306 sysHeaders += $(TARGET_HDRS) ; 307 defines += $(TARGET_DEFINES) ; 308 defines += $(TARGET_DEFINES) ; 309 cc = $(TARGET_CC) ; 310 localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ; 311 systemIncludesOption = $(TARGET_SYSTEM_INCLUDES_OPTION) ; 312 } 313 } 314 315 DEFINES on $(target) = $(defines) ; 316 CCDEFS on $(target) = [ FDefines $(defines) ] ; 317 HDRS on $(target) = [ FIncludes $(headers) : $(localIncludesOption) ] 318 $(includesSeparator) 319 [ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ; 320 CC on $(target) = $(cc) ; 321 322 LOCALE_KIT_SIGNATURE on $(target) = $(signature) ; 323 324 SEARCH on $(source) += $(SEARCH_SOURCE) ; 325 326 MakeLocatePlatform $(target) ; 327 Depends $(target) : $(source) <build>collectcatkeys ; 328 LocalClean clean : $(target) ; 329 ExtractCatalogEntries1 $(target) : <build>collectcatkeys $(source) ; 330} 331 332actions ExtractCatalogEntries1 333{ 334 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 335 cat "$(2[2-])" | $(CC) -E $(CCDEFS) $(HDRS) - > "$(1)".pre 336 $(2[1]) -s $(LOCALE_KIT_SIGNATURE) -w -o "$(1)" "$(1)".pre 337} 338 339# Link catalog entries from given catkey file into output compiled catalog file. 340# Compiled catalog file will then be copied into the image, but only if the 341# fingerprint matches the one from the untranslated catalog for the same file. 342rule LinkApplicationCatalog target : sources : signature : language 343{ 344 MakeLocateArch $(target) ; 345 LOCALE_KIT_SIGNATURE on $(target) = $(signature) ; 346 Depends $(target) : $(sources) <build>linkcatkeys ; 347 LocalClean clean : $(target) ; 348 LinkApplicationCatalog1 $(target) 349 : <build>linkcatkeys $(language) $(sources) ; 350} 351 352actions LinkApplicationCatalog1 353{ 354 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 355 $(2[1]) "$(2[3-])" -l $(2[2]:B) -v -s $(LOCALE_KIT_SIGNATURE) -o "$(1)" 356} 357 358# General rules to invoke from jamfiles and that do (almost) everything related 359# to localization 360rule DoCatalogs appName # Application name 361 : signature # Application MIME signature (must match the one 362 # declared in the sourcecode) 363 : sources # List of cpp files where to search keys 364 : generatedCatalog # Name of the generated catalog (most probably 365 # english.catalog) 366 : translatedCatalogs # List of available translations 367{ 368 genCat = [ FGristFiles $(generatedCatalog) ] ; 369 trans = [ FGristFiles $(translatedCatalogs) ] ; 370 srcs = [ FGristFiles $(sources) ] ; 371 SEARCH on $(trans) += [ FDirName $(HAIKU_TOP) data catalogs $(SUBDIR_TOKENS[2-]) ] ; 372 373 ExtractCatalogEntries $(genCat:S=.catkeys) : $(srcs) : $(signature) ; 374 375 LinkApplicationCatalog $(genCat) : $(genCat:S=.catkeys) 376 : $(signature) : $(genCat:B) ; 377 378 for catalog in $(trans) 379 { 380 LinkApplicationCatalog $(catalog:S=.catalog) : $(catalog) 381 : $(signature) : $(catalog:B) ; 382 } 383 384 AddFilesToHaikuImage system data locale catalogs $(signature) : 385 $(genCat) $(trans:S=.catalog) ; 386} 387