PackageRules revision 495b360b
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	local defines = HAIKU_PACKAGING_ARCH=$(architecture) ;
54	local sedReplacements = %HAIKU_PACKAGING_ARCH%,$(architecture) ;
55	if $(HAIKU_BOOTSTRAP_BUILD) {
56		defines += HAIKU_BOOTSTRAP_BUILD ;
57		target = $(target)-bootstrap ;
58	}
59	if $(secondaryArchitecture) {
60		defines += HAIKU_SECONDARY_PACKAGING_ARCH=$(secondaryArchitecture) ;
61		sedReplacements
62			+= %HAIKU_SECONDARY_PACKAGING_ARCH%,$(secondaryArchitecture) ;
63		sedReplacements +=
64			%HAIKU_SECONDARY_PACKAGING_ARCH_SUFFIX%,_$(secondaryArchitecture) ;
65	} else {
66		sedReplacements
67			+= %HAIKU_SECONDARY_PACKAGING_ARCH_SUFFIX%, ;
68	}
69
70	local revisionFile = [ DetermineHaikuRevision ] ;
71	local updateRequiresFiles ;
72	local haikuPortsRepositoryFile ;
73	if ! $(HAIKU_BOOTSTRAP_BUILD) {
74		updateRequiresFiles =
75			<build>update_package_requires
76			[ on <repository>HaikuPorts return $(HAIKU_REPOSITORY_CACHE_FILE) ]
77			;
78	}
79
80	MakeLocate $(target) : $(directory) ;
81	Depends $(target) : $(source) $(revisionFile) $(updateRequiresFiles) ;
82
83	CCDEFS on $(target) = [ FDefines $(defines) ] ;
84	HAIKU_SED_REPLACEMENTS on $(target) = "-e s,$(sedReplacements),g" ;
85
86	PreprocessPackageInfo1 $(target) : $(source) $(revisionFile)
87		$(updateRequiresFiles) ;
88
89	return $(target) ;
90}
91
92
93actions PreprocessPackageInfo1
94{
95	revision=`sed -n 's,^\(hrev[0-9]*\).*,\1,p' $(2[2])`
96	sed $(HAIKU_SED_REPLACEMENTS) \
97			-e s,%HAIKU_VERSION%,$(HAIKU_VERSION)_${revision:-0}-1, < $(2[1]) \
98		| $(HOST_CC) -E -w $(CCDEFS) - -o $(1)
99
100	if [ -n "$(2[4]:E)" ]; then
101		$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
102		"$(2[3])" "$(1)" "$(2[4])" || exit 1
103	fi
104}
105
106
107rule BuildHaikuPackage package : packageInfo
108{
109	local architecture = $(HAIKU_PACKAGING_ARCH) ;
110	local secondaryArchitecture ;
111	if $(TARGET_PACKAGING_ARCH) != $(architecture) {
112		secondaryArchitecture = $(TARGET_PACKAGING_ARCH) ;
113	}
114
115	MakeLocate $(package) : $(HAIKU_PACKAGES_DIR_$(architecture)) ;
116
117	# Don't rebuild an existing package, if requested.
118	if [ on $(package) return $(HAIKU_DONT_REBUILD_PACKAGE) ] {
119		NoUpdate $(package) ;
120		BuildHaikuPackageDummy $(package) ;
121		return ;
122	}
123
124	local grist = [ FHaikuPackageGrist $(package) ] ;
125
126	local tempDir
127		= [ FDirName $(HAIKU_PACKAGES_BUILD_DIR_$(architecture)) $(grist) ] ;
128	local scriptDir = [ FDirName $(tempDir) scripts ] ;
129
130	#  build the package info and locate the package
131	packageInfo = [ PreprocessPackageInfo $(packageInfo) : $(tempDir)
132		: $(architecture) : $(secondaryArchitecture) ] ;
133	Depends $(package) : $(packageInfo) ;
134
135	# prepare the script that initializes the shell variables
136	local initVariablesScript = <$(grist)>haiku.package-init-vars ;
137	MakeLocate $(initVariablesScript) : $(scriptDir) ;
138	Always $(initVariablesScript) ;
139
140	local script = $(initVariablesScript) ;
141	AddVariableToScript $(script) : sourceDir : $(HAIKU_TOP) ;
142	AddVariableToScript $(script) : outputDir : $(HAIKU_OUTPUT_DIR) ;
143	AddVariableToScript $(script) : tmpDir : $(tempDir) ;
144	AddVariableToScript $(script) : addBuildCompatibilityLibDir
145		: $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ;
146	AddVariableToScript $(script) : compressionLevel
147		: [ on $(package) return $(HAIKU_PACKAGE_COMPRESSION_LEVEL) ] ;
148	AddVariableToScript $(script) : updateOnly
149		: [ on $(package) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] ;
150	AddVariableToScript $(script) : cc : $(TARGET_CC_$(architecture)) ;
151	AddTargetVariableToScript $(script) : <build>addattr ;
152	AddTargetVariableToScript $(script) : <build>copyattr ;
153	AddTargetVariableToScript $(script) : <mimedb>mime_db : mimeDB ;
154	AddTargetVariableToScript $(script) : <build>mimeset ;
155	AddTargetVariableToScript $(script) : <build>package ;
156	AddTargetVariableToScript $(script) : <build>rc ;
157	AddTargetVariableToScript $(script) : <build>resattr ;
158	AddTargetVariableToScript $(script) : <build>unzip ;
159	if $(HOST_RM_ATTRS_TARGET) {
160		AddTargetVariableToScript $(script) : $(HOST_RM_ATTRS_TARGET)
161			: rmAttrs ;
162	} else {
163		AddVariableToScript $(script) : rmAttrs : rm ;
164	}
165
166	# create the other scripts
167	local makeDirsScript = <$(grist)>haiku.package-make-dirs ;
168	local copyFilesScript = <$(grist)>haiku.package-copy-files ;
169	local extractFilesScript = <$(grist)>haiku.package-extract-files ;
170
171	MakeLocate $(makeDirsScript) $(copyFilesScript) $(extractFilesScript)
172		: $(scriptDir) ;
173
174	CreateContainerMakeDirectoriesScript $(package) : $(makeDirsScript) ;
175	CreateContainerCopyFilesScript $(package) : $(copyFilesScript) ;
176	CreateContainerExtractFilesScript $(package) : $(extractFilesScript) ;
177
178	local scripts = $(initVariablesScript) $(makeDirsScript)
179		$(copyFilesScript) $(extractFilesScript) ;
180
181	# call the build actions
182	local mainScript = build_haiku_package ;
183	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
184
185	LocalDepends $(package) : $(mainScript) $(scripts) ;
186	BuildHaikuPackage1 $(package) : $(mainScript) $(packageInfo) $(scripts) ;
187}
188
189
190actions BuildHaikuPackage1
191{
192	$(2[1]) "$(1)" "$(2[2])" $(2[3-])
193}
194
195
196actions BuildHaikuPackageDummy
197{
198	# do nothing
199}
200
201
202rule FDontRebuildCurrentPackage
203{
204	on $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
205		return $(HAIKU_DONT_REBUILD_PACKAGE) ;
206}
207
208
209rule AddDirectoryToPackage directoryTokens : attributeFiles
210{
211	if ! [ FDontRebuildCurrentPackage ] {
212		return [ AddDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
213			: $(directoryTokens) : $(attributeFiles) ] ;
214	}
215}
216
217
218rule AddFilesToPackage directory : targets : destName
219{
220	if ! [ FDontRebuildCurrentPackage ] {
221		AddFilesToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
222			: $(directory) : $(targets) : $(destName) ;
223	}
224}
225
226
227rule AddSymlinkToPackage directoryTokens : linkTarget : linkName
228{
229	if ! [ FDontRebuildCurrentPackage ] {
230		linkTarget = $(linkTarget:J=/) ;
231
232		AddSymlinkToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
233			: $(directoryTokens) : $(linkTarget) : $(linkName) ;
234	}
235}
236
237
238rule CopyDirectoryToPackage directoryTokens : sourceDirectory
239	: targetDirectoryName : excludePatterns : flags
240{
241	if ! [ FDontRebuildCurrentPackage ] {
242		CopyDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
243			: $(directoryTokens) : $(sourceDirectory) : $(targetDirectoryName)
244			: $(excludePatterns) : $(flags) ;
245	}
246}
247
248
249rule AddHeaderDirectoryToPackage dirTokens : dirName : flags
250{
251	if ! [ FDontRebuildCurrentPackage ] {
252		AddHeaderDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
253			: $(dirTokens) : $(dirName) : $(flags) ;
254	}
255}
256
257
258rule AddWifiFirmwareToPackage driver : subDirToExtract : archive
259	: extract
260{
261	if ! [ FDontRebuildCurrentPackage ] {
262		AddWifiFirmwareToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
263			: $(driver) : $(subDirToExtract) : $(archive) : $(extract) ;
264	}
265}
266
267
268rule ExtractArchiveToPackage dirTokens : archiveFile : flags : extractedSubDir
269{
270	if ! [ FDontRebuildCurrentPackage ] {
271		ExtractArchiveToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
272			: $(dirTokens) : $(archiveFile) : $(flags) : $(extractedSubDir) ;
273	}
274}
275
276
277rule AddDriversToPackage relativeDirectoryTokens : targets
278{
279	if ! [ FDontRebuildCurrentPackage ] {
280		AddDriversToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
281			: $(relativeDirectoryTokens) : $(targets) ;
282	}
283}
284
285
286rule AddNewDriversToPackage relativeDirectoryTokens : targets
287{
288	if ! [ FDontRebuildCurrentPackage ] {
289		AddNewDriversToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
290			: $(relativeDirectoryTokens) : $(targets) ;
291	}
292}
293
294
295rule AddBootModuleSymlinksToPackage targets
296{
297	if ! [ FDontRebuildCurrentPackage ] {
298		AddBootModuleSymlinksToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
299			: $(targets) ;
300	}
301}
302
303
304rule AddLibrariesToPackage directory : libs
305{
306	if ! [ FDontRebuildCurrentPackage ] {
307		AddLibrariesToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
308			: $(directory) : $(libs) ;
309	}
310}
311
312
313# default value for the package compression level
314HAIKU_PACKAGE_COMPRESSION_LEVEL ?= 9 ;
315