xref: /haiku/build/jam/PackageRules (revision 4796acbc8c8fa3a5325a27722746b999009988d1)
1#-------------------------------------------------------------------------------
2# Packages for OBOS alpha/beta testers
3#-------------------------------------------------------------------------------
4
5rule Copy
6{
7	if $(2) {
8		SEARCH on $(2) += $(SEARCH_SOURCE) ;
9		Depends $(1) : <build>copyattr $(2) ;
10		Copy1 $(1) : <build>copyattr $(2) ;
11	}
12}
13
14actions Copy1
15{
16	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
17	"$(2[1])" -d "$(2[2-])" "$(1)"
18}
19
20rule Packages
21{
22	local packagenames = $(1) ;
23	local packagefiles = $(2) ;
24	local path = $(3) ;
25	for name in $(packagenames) {
26		Package $(name) : $(packagefiles) : $(path) ;
27    }
28}
29
30rule FPackageConfigSubPath
31{
32	# FPackageConfigSubPath <packagename>
33	#
34	local packagename = $(1) ;
35
36	local configSubPath ;
37	on $(packagename) {
38		if $(PLATFORM) = host {
39			configSubPath = $(HOST_PLATFORM) $(HOST_ARCH) ;
40		} else {
41			configSubPath = $(TARGET_PLATFORM) $(TARGET_ARCH) ;
42		}
43
44		if $(DEBUG) = 0 {
45			configSubPath += release ;
46		} else {
47			configSubPath += debug_$(DEBUG) ;
48		}
49	}
50
51	return $(configSubPath) ;
52}
53
54rule Package
55{
56	local packagename = $(1) ;
57    local packagefiles = $(2) ;
58	local path = $(3) ;
59
60	local configSubPath = [ FPackageConfigSubPath $(packagename) ] ;
61	local packagezip = $(packagename:S=.zip:G=_packages) ;
62	local targetDir = [ FDirName $(HAIKU_PACKAGE_DIR) $(configSubPath) ] ;
63	local packagedir = [ FDirName $(targetDir) $(packagename) ] ;
64
65    local installscript = install.sh ;
66	local packageinstallscript = $(installscript:G=_packages!$(packagename)) ;
67    local installzip = install.zip ;
68	local packageinstallzip = $(installzip:G=_packages!$(packagename)) ;
69
70    local packageobjectdir = [ FDirName $(HAIKU_PACKAGE_OBJECT_DIR)
71		$(configSubPath) $(packagename) ] ;
72	local packagefiledir =  [ FDirName $(packageobjectdir) $(path) ] ;
73    local packagefileinstallzip
74    	= $(installzip:G=_package_objects!$(packagename)) ;
75
76	# add the files to the install.zip
77	local packagefilegrist = [ FGrist _package_files $(packagename) $(path) ] ;
78    for file in $(packagefiles) {
79		if $(path[0]) = "boot" {
80			local packagefile = $(file:G=$(packagefilegrist)) ;
81			MakeLocate $(packagefile) : $(packagefiledir) ;
82			Copy $(packagefile) : $(file) ;
83			Clean cleanPackages : $(packagefile) ;
84			PackageInstallZip $(packagefileinstallzip) : $(packagefile) ;
85		} else {
86			local packagefile = $(file:G=_packages!$(packagename)) ;
87			MakeLocate $(packagefile) : $(packagedir) ;
88			Copy $(packagefile) : [ FGristFiles $(file) ] ;
89			Clean cleanPackages : $(packagefile) ;
90			Depends $(packagezip) : $(packagefile) ;
91		}
92	}
93
94	# general setup for this package -- only on first invocation
95	if ! $(_setup_$(packagename)) {
96		_setup_$(packagename) = true ;
97
98		NotFile $(packagename) ;
99		LocalDepends packages : $(packagename) ;
100
101		MakeLocate $(packagezip) : $(targetDir) ;
102		MakeLocate $(packageinstallscript) : $(packagedir) ;
103		MakeLocate $(packageinstallzip) : $(packagedir) ;
104		MakeLocate $(packagefileinstallzip) : $(packageobjectdir) ;
105
106		PackageInstallScript $(packageinstallscript) : $(packagedir) ;
107		LinkInstallZip $(packageinstallzip) : $(packagefileinstallzip) ;
108		Depends $(packagename) : $(packagezip) ;
109		PackageZip $(packagezip) : $(packagedir)
110			: $(packageinstallscript) $(packageinstallzip) ;
111	}
112
113}
114
115rule PackageSymLink
116{
117	# PackageSymLink <packageName> : <symlink path components>
118	#	: <symlink target>
119	#
120	local packagename = $(1) ;
121	local symlinkPath = $(2) ;
122	local symlinkTarget = $(3) ;
123
124	local configSubPath = [ FPackageConfigSubPath $(packagename) ] ;
125
126	local symlinkDir = [ FReverse $(symlinkPath) ] ;
127	local symlink = $(symlinkDir[1]) ;
128	symlinkDir = [ FReverse $(symlinkDir[2-]) ] ;
129	local symlinkGrist = [ FGrist _package $(packagename) $(symlinkDir) ] ;
130	symlink = $(symlink:G=$(symlinkGrist)) ;
131
132	if $(symlinkDir[1]) = boot {
133	    local installzip = install.zip ;
134	    local packagefileinstallzip
135    		= $(installzip:G=_package_objects!$(packagename)) ;
136
137		local packageobjectdir = [ FDirName $(HAIKU_PACKAGE_OBJECT_DIR)
138			$(configSubPath) $(packagename) ] ;
139		symlinkDir = [ FDirName $(packageobjectdir) $(symlinkDir) ] ;
140
141		PackageInstallZip $(packagefileinstallzip) : $(symlink) ;
142
143	} else {
144		local packagezip = $(packagename:S=.zip:G=_packages) ;
145
146		local packagedir = [ FDirName $(HAIKU_PACKAGE_DIR) $(configSubPath)
147			$(packagename) ] ;
148		symlinkDir = [ FDirName $(packagedir) $(symlinkDir) ] ;
149
150		Depends $(packagezip) : $(symlink) ;
151	}
152
153	MakeLocate $(symlink) : $(symlinkDir) ;
154	SymLink $(symlink) : $(symlinkTarget) : false ;
155	Clean cleanPackages : $(symlink) ;
156}
157
158rule PackageDriverSymLink
159{
160	# PackageDriverSymLink <packageName> : <devRelativeSymlinkComponents> ;
161	# <packageName>: Package name.
162	# <devRelativeSymlinkComponents>: Path components relative to the
163	#     /boot/home/config/add-ons/kernel/drivers/dev directory, e.g.
164	#     "graphics mga.driver" (no quotation, of course).
165	#
166	local packageName = $(1) ;
167	local symlinkComponents = $(2) ;
168
169	# construct the symlink contents
170	local symlinkPath = [ FReverse $(symlinkComponents) ] ;
171	symlinkPath = bin $(symlinkPath[1]) ;
172
173	for i in $(symlinkComponents) {
174		symlinkPath = $(DOTDOT) $(symlinkPath) ;
175	}
176
177	PackageSymLink $(packageName)
178		: boot home config add-ons kernel drivers dev $(symlinkComponents)
179		: [ FDirName $(symlinkPath) ] ;
180}
181
182rule PackageZip
183{
184	local dir = $(2:G=dir) ;
185	Depends $(1) : $(dir) $(3) ;
186	Clean cleanPackages : $(1) ;
187	PackageZip1 $(1) : $(dir) ;
188}
189
190actions together PackageZip1 {
191	cd "$(2:P)" ;
192	zip -rq "$(1:BS)" "$(2:BS)" ;
193}
194
195rule PackageInstallScript
196{
197	MakeLocate $(1) : $(2) ;
198	Clean cleanPackages : $(1) ;
199	PackageInstallScript1 $(1) : $(2:G=dir) ;
200}
201
202actions together PackageInstallScript1
203{
204echo '#!/bin/sh
205base=`dirname "$0"`
206cd "$base"
207if [ -n "$TTY" ]
208then
209    unzip -d / install.zip
210else
211    response=`alert "Would you like to automatically overwrite existing files, or receive a prompt?" "Overwrite" "Prompt"`
212    if [ $response == "Overwrite" ]
213    then
214        unzip -od / install.zip
215        alert "Finished installing" "Thanks"
216    else
217        if [ -e /boot/beos/apps/Terminal ]
218        then
219            terminal=/boot/beos/apps/Terminal
220        else
221            terminal=`query Terminal | head -1`
222        fi
223        $terminal -t "installer" /bin/sh "$0"
224    fi
225fi' > "$(1)" ;
226	chmod 755 "$(1)" ;
227}
228
229rule PackageInstallZip
230{
231	Depends $(1) : $(2) ;
232	Clean cleanPackages : $(1) ;
233}
234
235actions together PackageInstallZip
236{
237	cd "$(1:P)" ;
238	zip -rqy "$(1:BS)" boot ;
239}
240
241rule LinkInstallZip
242{
243	Depends $(1) : $(2) ;
244	Clean cleanPackages : $(1) ;
245}
246
247actions together LinkInstallZip
248{
249	ln -sf "`pwd`/$(2)" "$(1)" ;
250}
251
252
253# TODO: The stuff above should be moved (Copy) or removed (the rest).
254
255
256#pragma mark - Haiku Packages
257
258
259rule FHaikuPackageGrist package
260{
261	local grist = [ Match "<(.*)>" : $(package:G) ] ;
262	return hpkg_$(grist:E="")_$(package:G=) ;
263}
264
265
266rule HaikuPackage package
267{
268	local grist = [ FHaikuPackageGrist $(package) ] ;
269
270	HAIKU_CONTAINER_GRIST on $(package) = $(grist) ;
271	HAIKU_INCLUDE_IN_CONTAINER_VAR on $(package)
272		= $(grist)_HAIKU_INCLUDE_IN_PACKAGE ;
273	HAIKU_INSTALL_TARGETS_VAR on $(package)
274		= $(grist)_HAIKU_PACKAGE_INSTALL_TARGETS ;
275	HAIKU_CONTAINER_SYSTEM_DIR_TOKENS on $(package) = ;
276
277	HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE = $(package) ;
278}
279
280
281rule BuildHaikuPackage package : packageInfo
282{
283	local grist = [ FHaikuPackageGrist $(package) ] ;
284
285	local tempDir = [ FDirName $(HAIKU_PACKAGES_BUILD_DIR) $(grist) ] ;
286	local scriptDir = [ FDirName $(tempDir) scripts ] ;
287
288	# locate the package and package info
289	MakeLocate $(package) : $(HAIKU_PACKAGES_DIR) ;
290	SEARCH on $(packageInfo) += $(HAIKU_PACKAGE_INFOS_DIR) ;
291	LocalDepends $(package) : $(packageInfo) ;
292
293	# prepare the script that initializes the shell variables
294	local initVariablesScript = <$(grist)>haiku.package-init-vars ;
295	MakeLocate $(initVariablesScript) : $(scriptDir) ;
296	Always $(initVariablesScript) ;
297
298	local script = $(initVariablesScript) ;
299	AddVariableToScript $(script) : sourceDir : $(HAIKU_TOP) ;
300	AddVariableToScript $(script) : outputDir : $(HAIKU_OUTPUT_DIR) ;
301	AddVariableToScript $(script) : tmpDir : $(tempDir) ;
302	AddVariableToScript $(script) : addBuildCompatibilityLibDir
303		: $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ;
304	AddTargetVariableToScript $(script) : <build>addattr ;
305	AddTargetVariableToScript $(script) : <build>copyattr ;
306	AddTargetVariableToScript $(script) : <build>package ;
307	AddTargetVariableToScript $(script) : <build>rc ;
308	AddTargetVariableToScript $(script) : <build>resattr ;
309	AddTargetVariableToScript $(script) : <build>unzip ;
310	if $(HOST_RM_ATTRS_TARGET) {
311		AddTargetVariableToScript $(script) : $(HOST_RM_ATTRS_TARGET)
312			: rmAttrs ;
313	} else {
314		AddVariableToScript $(script) : rmAttrs : rm ;
315	}
316
317	# create the other scripts
318	local makeDirsScript = <$(grist)>haiku.package-make-dirs ;
319	local copyFilesScript = <$(grist)>haiku.package-copy-files ;
320
321	MakeLocate $(makeDirsScript) $(copyFilesScript) : $(scriptDir) ;
322
323	CreateContainerMakeDirectoriesScript $(package) : $(makeDirsScript) ;
324	CreateContainerCopyFilesScript $(package) : $(copyFilesScript) ;
325
326	local scripts = $(initVariablesScript) $(makeDirsScript)
327		$(copyFilesScript) ;
328
329	# call the build actions
330	local mainScript = build_haiku_package ;
331	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
332
333	LocalDepends $(package) : $(mainScript) $(scripts) ;
334	BuildHaikuPackage1 $(package) : $(mainScript) $(packageInfo) $(scripts) ;
335}
336
337
338actions BuildHaikuPackage1
339{
340	$(2[1]) "$(1)" "$(2[2])" $(2[3-])
341}
342
343
344rule AddDirectoryToPackage directoryTokens : attributeFiles
345{
346	return [ AddDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
347		: $(directoryTokens) : $(attributeFiles) ] ;
348}
349
350
351rule AddFilesToPackage directory : targets : destName
352{
353	AddFilesToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) : $(directory)
354		: $(targets) : $(destName) ;
355}
356
357
358rule AddSymlinkToPackage directoryTokens : linkTarget : linkName
359{
360	linkTarget = $(linkTarget:J=/) ;
361
362	AddSymlinkToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
363		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
364}
365
366
367rule CopyDirectoryToPackage directoryTokens : sourceDirectory
368	: targetDirectoryName : excludePatterns : alwaysUpdate
369{
370	CopyDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
371		: $(directoryTokens) : $(sourceDirectory) : $(targetDirectoryName)
372		: $(excludePatterns) : $(alwaysUpdate) ;
373}
374
375
376rule AddHeaderDirectoryToPackage dirTokens : dirName : alwaysUpdate
377{
378	AddHeaderDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
379		: $(dirTokens) : $(dirName) : $(alwaysUpdate) ;
380}
381
382
383rule AddWifiFirmwareToPackage driver : subDirToExtract : archive
384	: extract
385{
386	AddWifiFirmwareToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
387		: $(driver) : $(subDirToExtract) : $(archive) : $(extract) ;
388}
389
390
391rule ExtractArchiveToPackage dirTokens : archiveFile : alwaysUpdate
392	: extractedSubDir
393{
394	# TODO: Update support?
395	ExtractArchiveToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
396		: $(dirTokens) : $(archiveFile) : $(extractedSubDir) ;
397}
398
399
400rule AddDriversToPackage relativeDirectoryTokens : targets
401{
402	AddDriversToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
403		: $(relativeDirectoryTokens) : $(targets) ;
404}
405
406
407rule AddNewDriversToPackage relativeDirectoryTokens : targets
408{
409	AddNewDriversToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
410		: $(relativeDirectoryTokens) : $(targets) ;
411}
412
413
414rule AddBootModuleSymlinksToPackage targets
415{
416	AddBootModuleSymlinksToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
417		: $(targets) ;
418}
419
420
421rule AddLibrariesToPackage directory : libs
422{
423	AddLibrariesToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
424		: $(directory) : $(libs) ;
425}
426