1rule FHaikuPackageGrist package 2{ 3 local grist = [ Match "<(.*)>" : $(package:G) ] ; 4 return hpkg_$(grist:E="")-$(package:G=) ; 5} 6 7 8rule HaikuPackage package 9{ 10 local grist = [ FHaikuPackageGrist $(package) ] ; 11 12 HAIKU_CONTAINER_GRIST on $(package) = $(grist) ; 13 HAIKU_INCLUDE_IN_CONTAINER_VAR on $(package) = HAIKU_INCLUDE_IN_PACKAGES ; 14 HAIKU_INSTALL_TARGETS_VAR on $(package) 15 = $(grist)_HAIKU_PACKAGE_INSTALL_TARGETS ; 16 HAIKU_CONTAINER_SYSTEM_DIR_TOKENS on $(package) = ; 17 18 HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE = $(package) ; 19 20 if $(HAIKU_PACKAGES_UPDATE_ONLY) { 21 HAIKU_CONTAINER_UPDATE_ONLY on $(package) = 1 ; 22 HAIKU_CONTAINER_INHERIT_UPDATE_VARIABLE on $(package) 23 = HAIKU_INCLUDE_IN_IMAGE ; 24 } else if $(HAIKU_UPDATE_ALL_PACKAGES) { 25 HAIKU_INCLUDE_IN_IMAGE on $(package) = 1 ; 26 } 27 28 HAIKU_CONTAINER_ALWAYS_CREATE_DIRECTORIES on $(package) = 1 ; 29 30 # If HAIKU_DONT_REBUILD_PACKAGES is defined, don't rebuild an existing 31 # package. 32 if $(HAIKU_DONT_REBUILD_PACKAGES) { 33 local file = [ Glob $(HAIKU_PACKAGES_DIR_$(HAIKU_PACKAGING_ARCH)) 34 : $(package:BS) ] ; 35 if $(file) { 36 HAIKU_DONT_REBUILD_PACKAGE on $(package) = 1 ; 37 } 38 } 39} 40 41 42rule PreprocessPackageInfo source : directory : architecture 43 : secondaryArchitecture 44{ 45 source = $(source:G=package-info-source) ; 46 SEARCH on $(source) += 47 [ FDirName $(HAIKU_PACKAGE_INFOS_DIR) $(architecture) ] 48 [ FDirName $(HAIKU_PACKAGE_INFOS_DIR) any ] 49 [ FDirName $(HAIKU_PACKAGE_INFOS_DIR) generic ] 50 ; 51 52 local target = $(source:BSG=package-info)-package-info ; 53 MakeLocate $(target) : $(directory) ; 54 55 PreprocessPackageOrRepositoryInfo $(target) : $(source) : $(architecture) 56 : $(secondaryArchitecture) : useCPP ; 57 58 # Update requires in the package info. 59 if $(HAIKU_BUILD_TYPE) != bootstrap { 60 local updateRequiresFiles = 61 <build>update_package_requires 62 [ on <repository>HaikuPorts return $(HAIKU_REPOSITORY_CACHE_FILE) ] 63 ; 64 Depends $(target) : $(updateRequiresFiles) ; 65 UpdatePackageInfoRequires $(target) : $(updateRequiresFiles) ; 66 } 67 68 return $(target) ; 69} 70 71 72actions UpdatePackageInfoRequires 73{ 74 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 75 "$(2[1])" "$(1)" "$(2[2])" 76} 77 78 79rule PreprocessPackageOrRepositoryInfo target : source : architecture 80 : secondaryArchitecture : flags 81{ 82 # PreprocessPackageOrRepositoryInfo <target> : <source> : <architecture> 83 # : [ <secondaryArchitecture> ] [ : <flags> ] ; 84 # Preprocesses the package or repository info template file <source> by 85 # performing several placeholder substitutions and optionally filtering it 86 # through the C preprocessor. 87 # 88 # <target> - The generated preprocessed file. 89 # <source> - The package or repository info template file. 90 # <architecture> - The primary packaging architecture. 91 # <secondaryArchitecture> - If given, the secondary packaging architecture 92 # the package targets. Otherwise the primary architecture is targeted. 93 # <flags>: 94 # useCPP - Filter the source file through the C preprocessor after the 95 # placeholder substitutions have been performed. 96 97 local defines = HAIKU_PACKAGING_ARCH=$(architecture) 98 HAIKU_$(HAIKU_BUILD_TYPE:U)_BUILD ; 99 local sedReplacements = %HAIKU_PACKAGING_ARCH%,$(architecture) ; 100 if $(secondaryArchitecture) { 101 defines += HAIKU_SECONDARY_PACKAGING_ARCH=$(secondaryArchitecture) ; 102 sedReplacements 103 += %HAIKU_SECONDARY_PACKAGING_ARCH%,$(secondaryArchitecture) ; 104 sedReplacements += 105 %HAIKU_SECONDARY_PACKAGING_ARCH_SUFFIX%,_$(secondaryArchitecture) ; 106 } else { 107 sedReplacements 108 += %HAIKU_SECONDARY_PACKAGING_ARCH_SUFFIX%, ; 109 } 110 111 local revisionFile = [ DetermineEffectiveHaikuRevision ] ; 112 Depends $(target) : $(source) $(revisionFile) ; 113 114 if useCPP in $(flags) { 115 PREPROCESSOR on $(target) 116 = "|" $(HOST_CC) -E -w [ FDefines $(defines) ] - ; 117 } else { 118 PREPROCESSOR on $(target) = ; 119 } 120 121 HAIKU_SED_REPLACEMENTS on $(target) = "-e s,$(sedReplacements),g" ; 122 123 PreprocessPackageOrRepositoryInfo1 $(target) : $(source) $(revisionFile) ; 124} 125 126 127actions PreprocessPackageOrRepositoryInfo1 128{ 129 revision=`cat $(2[2])` 130 version=$(HAIKU_VERSION)_${revision} 131 sed $(HAIKU_SED_REPLACEMENTS) \ 132 -e s,%HAIKU_VERSION%,${version}-1, \ 133 -e s,%HAIKU_VERSION_NO_REVISION%,${version}, $(2[1]) \ 134 $(PREPROCESSOR) > $(1) 135} 136 137 138rule BuildHaikuPackage package : packageInfo 139{ 140 local architecture = $(HAIKU_PACKAGING_ARCH) ; 141 local secondaryArchitecture ; 142 if $(TARGET_PACKAGING_ARCH) != $(architecture) { 143 secondaryArchitecture = $(TARGET_PACKAGING_ARCH) ; 144 } 145 146 MakeLocate $(package) : $(HAIKU_PACKAGES_DIR_$(architecture)) ; 147 148 # Don't rebuild an existing package, if requested. 149 if [ on $(package) return $(HAIKU_DONT_REBUILD_PACKAGE) ] { 150 NoUpdate $(package) ; 151 BuildHaikuPackageDummy $(package) ; 152 return ; 153 } 154 155 local grist = [ FHaikuPackageGrist $(package) ] ; 156 157 local tempDir = [ FDirName 158 $(HAIKU_PACKAGES_BUILD_DIR_$(architecture)) $(HAIKU_BUILD_TYPE) $(grist) 159 ] ; 160 local scriptDir = [ FDirName $(tempDir) scripts ] ; 161 162 # build the package info and locate the package 163 packageInfo = [ PreprocessPackageInfo $(packageInfo) : $(tempDir) 164 : $(architecture) : $(secondaryArchitecture) ] ; 165 Depends $(package) : $(packageInfo) ; 166 167 # prepare the script that initializes the shell variables 168 local initVariablesScript = <$(grist)>haiku.package-init-vars ; 169 MakeLocate $(initVariablesScript) : $(scriptDir) ; 170 Always $(initVariablesScript) ; 171 172 local script = $(initVariablesScript) ; 173 AddVariableToScript $(script) : sourceDir : $(HAIKU_TOP) ; 174 AddVariableToScript $(script) : outputDir : $(HAIKU_OUTPUT_DIR) ; 175 AddVariableToScript $(script) : tmpDir : $(tempDir) ; 176 AddVariableToScript $(script) : addBuildCompatibilityLibDir 177 : $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ; 178 AddVariableToScript $(script) : compressionLevel 179 : [ on $(package) return $(HAIKU_PACKAGE_COMPRESSION_LEVEL) ] ; 180 AddVariableToScript $(script) : updateOnly 181 : [ on $(package) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] ; 182 AddVariableToScript $(script) : cc : $(TARGET_CC_$(architecture)) ; 183 AddTargetVariableToScript $(script) : <build>addattr ; 184 AddTargetVariableToScript $(script) : <build>copyattr ; 185 AddTargetVariableToScript $(script) : <mimedb>mime_db : mimeDB ; 186 AddTargetVariableToScript $(script) : <build>mimeset ; 187 AddTargetVariableToScript $(script) : <build>package ; 188 AddTargetVariableToScript $(script) : <build>rc ; 189 AddTargetVariableToScript $(script) : <build>resattr ; 190 AddTargetVariableToScript $(script) : <build>unzip ; 191 if $(HOST_RM_ATTRS_TARGET) { 192 AddTargetVariableToScript $(script) : $(HOST_RM_ATTRS_TARGET) 193 : rmAttrs ; 194 } else { 195 AddVariableToScript $(script) : rmAttrs : rm ; 196 } 197 198 # create the other scripts 199 local makeDirsScript = <$(grist)>haiku.package-make-dirs ; 200 local copyFilesScript = <$(grist)>haiku.package-copy-files ; 201 local extractFilesScript = <$(grist)>haiku.package-extract-files ; 202 203 MakeLocate $(makeDirsScript) $(copyFilesScript) $(extractFilesScript) 204 : $(scriptDir) ; 205 206 CreateContainerMakeDirectoriesScript $(package) : $(makeDirsScript) ; 207 CreateContainerCopyFilesScript $(package) : $(copyFilesScript) ; 208 CreateContainerExtractFilesScript $(package) : $(extractFilesScript) ; 209 210 local scripts = $(initVariablesScript) $(makeDirsScript) 211 $(copyFilesScript) $(extractFilesScript) ; 212 213 # call the build actions 214 local mainScript = build_haiku_package ; 215 SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ; 216 217 Depends $(package) : $(mainScript) $(scripts) ; 218 BuildHaikuPackage1 $(package) : $(mainScript) $(packageInfo) $(scripts) ; 219} 220 221 222actions BuildHaikuPackage1 223{ 224 $(2[1]) "$(1)" "$(2[2])" $(2[3-]) 225} 226 227 228actions BuildHaikuPackageDummy 229{ 230 # do nothing 231} 232 233 234rule FDontRebuildCurrentPackage 235{ 236 on $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 237 return $(HAIKU_DONT_REBUILD_PACKAGE) ; 238} 239 240 241rule AddDirectoryToPackage directoryTokens : attributeFiles 242{ 243 if ! [ FDontRebuildCurrentPackage ] { 244 return [ AddDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 245 : $(directoryTokens) : $(attributeFiles) ] ; 246 } 247} 248 249 250rule AddFilesToPackage directory : targets : destName 251{ 252 if ! [ FDontRebuildCurrentPackage ] { 253 AddFilesToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 254 : $(directory) : $(targets) : $(destName) ; 255 } 256} 257 258 259rule AddSymlinkToPackage directoryTokens : linkTarget : linkName 260{ 261 if ! [ FDontRebuildCurrentPackage ] { 262 linkTarget = $(linkTarget:J=/) ; 263 264 AddSymlinkToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 265 : $(directoryTokens) : $(linkTarget) : $(linkName) ; 266 } 267} 268 269 270rule CopyDirectoryToPackage directoryTokens : sourceDirectory 271 : targetDirectoryName : excludePatterns : flags 272{ 273 if ! [ FDontRebuildCurrentPackage ] { 274 CopyDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 275 : $(directoryTokens) : $(sourceDirectory) : $(targetDirectoryName) 276 : $(excludePatterns) : $(flags) ; 277 } 278} 279 280 281rule AddHeaderDirectoryToPackage dirTokens : dirName : flags 282{ 283 if ! [ FDontRebuildCurrentPackage ] { 284 AddHeaderDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 285 : $(dirTokens) : $(dirName) : $(flags) ; 286 } 287} 288 289 290rule AddWifiFirmwareToPackage driver : subDirToExtract : archive 291 : extract 292{ 293 if ! [ FDontRebuildCurrentPackage ] { 294 AddWifiFirmwareToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 295 : $(driver) : $(subDirToExtract) : $(archive) : $(extract) ; 296 } 297} 298 299 300rule ExtractArchiveToPackage dirTokens : archiveFile : flags : extractedSubDir 301{ 302 if ! [ FDontRebuildCurrentPackage ] { 303 ExtractArchiveToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 304 : $(dirTokens) : $(archiveFile) : $(flags) : $(extractedSubDir) ; 305 } 306} 307 308 309rule AddDriversToPackage relativeDirectoryTokens : targets 310{ 311 if ! [ FDontRebuildCurrentPackage ] { 312 AddDriversToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 313 : $(relativeDirectoryTokens) : $(targets) ; 314 } 315} 316 317 318rule AddNewDriversToPackage relativeDirectoryTokens : targets 319{ 320 if ! [ FDontRebuildCurrentPackage ] { 321 AddNewDriversToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 322 : $(relativeDirectoryTokens) : $(targets) ; 323 } 324} 325 326 327rule AddBootModuleSymlinksToPackage targets 328{ 329 if ! [ FDontRebuildCurrentPackage ] { 330 AddBootModuleSymlinksToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 331 : $(targets) ; 332 } 333} 334 335 336rule AddLibrariesToPackage directory : libs 337{ 338 if ! [ FDontRebuildCurrentPackage ] { 339 AddLibrariesToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) 340 : $(directory) : $(libs) ; 341 } 342} 343 344 345# default value for the package compression level 346HAIKU_PACKAGE_COMPRESSION_LEVEL ?= 9 ; 347