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