xref: /haiku/build/jam/PackageRules (revision 4bd0c1066b227cec4b79883bdef697c7a27f2e90)
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	for feature in $(HAIKU_BUILD_FEATURES) {
111		local featureSplit = [ FSplitString $(feature) : ":" ] ;
112		defines += HAIKU_BUILD_FEATURE_$(featureSplit:UJ=_)_ENABLED ;
113	}
114
115	local revisionFile = [ DetermineEffectiveHaikuRevision ] ;
116	Depends $(target) : $(source) $(revisionFile) ;
117
118	if useCPP in $(flags) {
119		PREPROCESSOR on $(target)
120			= "|" $(HOST_CC) -E -w [ FDefines $(defines) ] - ;
121	} else {
122		PREPROCESSOR on $(target) = ;
123	}
124
125	HAIKU_SED_REPLACEMENTS on $(target) = "-e s,$(sedReplacements),g" ;
126
127	PreprocessPackageOrRepositoryInfo1 $(target) : $(source) $(revisionFile) ;
128}
129
130
131actions PreprocessPackageOrRepositoryInfo1
132{
133	revision=`cat $(2[2])`
134	version=$(HAIKU_VERSION)_${revision}
135	sed $(HAIKU_SED_REPLACEMENTS) \
136			-e s,%HAIKU_VERSION%,${version}-1, \
137			-e s,%HAIKU_VERSION_NO_REVISION%,${version}, $(2[1]) \
138		$(PREPROCESSOR) > $(1)
139}
140
141
142rule BuildHaikuPackage package : packageInfo
143{
144	local architecture = $(HAIKU_PACKAGING_ARCH) ;
145	local secondaryArchitecture ;
146	if $(TARGET_PACKAGING_ARCH) != $(architecture) {
147		secondaryArchitecture = $(TARGET_PACKAGING_ARCH) ;
148	}
149
150	MakeLocate $(package) : $(HAIKU_PACKAGES_DIR_$(architecture)) ;
151
152	# Don't rebuild an existing package, if requested.
153	if [ on $(package) return $(HAIKU_DONT_REBUILD_PACKAGE) ] {
154		NoUpdate $(package) ;
155		BuildHaikuPackageDummy $(package) ;
156		return ;
157	}
158
159	local grist = [ FHaikuPackageGrist $(package) ] ;
160
161	local tempDir = [ FDirName
162		$(HAIKU_PACKAGES_BUILD_DIR_$(architecture)) $(HAIKU_BUILD_TYPE) $(grist)
163	] ;
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	Depends $(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