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