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