ImageRules revision d4954058b5bf012342b4ba68a52405ab11e4978a
1rule FSameTargetWithPrependedGrist
2{
3	# SameTargetWithPrependedGrist <target> : <grist to prepend> ;
4	#
5	local target = $(1) ;
6	local gristToPrepend = $(2) ;
7	local grist = $(target:G) ;
8
9	if $(grist) {
10		grist = $(gristToPrepend)!$(grist) ;
11	} else {
12		grist = $(gristToPrepend) ;
13	}
14	
15	return $(target:G=$(grist)) ;
16}
17
18rule InitScript
19{
20	# Note: The script must have been LOCATEd before.
21	local script = $(1) ;
22	local initScript
23		= [ FSameTargetWithPrependedGrist $(script) : init-script ] ;
24
25	if ! [ on $(script) return $(__is_initialized) ] {
26		__is_initialized on $(script) = true ;
27
28		MakeLocate $(initScript) : [ on $(script) return $(LOCATE) ] ;
29		Always $(initScript) ;
30		Depends $(script) : $(initScript) ;
31
32		InitScript1 $(initScript) ;
33	}
34
35	return $(initScript) ;
36}
37
38actions InitScript1
39{
40	$(RM) $(1)
41	echo -n > $(1)
42}
43
44rule AddVariableToScript script : variable : value
45{
46	# AddVariableToScript <script> : <variable> : <value> ;
47
48	# interpret an empty variable value as empty string
49	if ! $(value) {
50		value = "" ;
51	}
52
53	InitScript $(script) ;
54
55	VARIABLE_DEFS on $(script) += "echo $(variable)=\\\"$(value[1])\\\" >> " ;
56
57	# if the value is an array, add the other array elements
58	value = $(value[2-]) ;
59	while $(value) {
60		VARIABLE_DEFS on $(script)
61			+= "echo $(variable)=\\\" \\\$$(variable) $(value[1])\\\" >> " ;
62		value = $(value[2-]) ;
63	}
64
65	AddVariableToScript1 $(script) ;
66}
67
68actions together AddVariableToScript1
69{
70	$(VARIABLE_DEFS)$(1);
71}
72
73rule AddTargetVariableToScript
74{
75	# AddTargetVariableToScript <script> : <target> [ : <variable> ] ;
76	#
77	local script = $(1) ;
78	local target = $(2) ;
79	local variable = $(3:E=$(target:BS)) ;
80
81	InitScript $(script) ;
82
83	# That's not completely save, if one has more than on target with the
84	# same base name. A unique pseudo target would have to be introduced
85	# to do it more correctly.
86	VARIABLE_NAME($(target:BS)) on $(script) = $(variable) ;
87
88	Depends $(script) : $(target) ;
89	AddTargetVariableToScript1 $(script) : $(target) ;
90}
91
92actions AddTargetVariableToScript1
93{
94	echo "$(VARIABLE_NAME($(2:BS)))=\"$(2)\"" >> $(1)
95}
96
97
98#pragma mark -
99
100rule AddDirectoryToContainer container : directoryTokens
101{
102	# AddDirectoryToContainer <container> : <directoryTokens>
103
104	local containerGrist = [ on $(container) return $(HAIKU_CONTAINER_GRIST) ] ;
105	local directory = [ FDirName $(directoryTokens) ] ;
106	directory = $(directory:G=$(containerGrist)) ;
107
108	if ! [ on $(directory) return $(__is_on_image) ] {
109		HAIKU_INSTALL_DIRECTORIES on $(container) += $(directory) ;
110		__is_on_image on $(directory) = true ;
111		DIRECTORY_TOKENS on $(directory) = $(directoryTokens) ;
112		NotFile $(directory) ;
113	
114		# mark the parent dir as not to be created
115		local parent = [ FReverse $(directoryTokens) ] ;
116		parent = [ FReverse $(parent[2-]) ] ;
117		if $(parent) {
118			parent = [ FDirName $(parent) ] ;
119			parent = $(parent:G=$(containerGrist)) ;
120			DONT_CREATE on $(parent) = true ;
121		}
122	}
123
124	return $(directory) ;
125}
126
127rule FilterContainerUpdateTargets targets : filterVariable
128{
129	# FilterContainerUpdateTargets targets : filterVariable
130
131	local filteredTargets ;
132	local target ;
133	for target in $(targets) {
134		if [ on $(target) return $($(filterVariable)) ] {
135			filteredTargets += $(target) ;
136		}
137	}
138	return $(filteredTargets) ;
139}
140
141rule AddFilesToContainer container : directoryTokens : targets : destName
142{
143	# AddFilesToContainer <container> : <directoryTokens> : <targets>
144	#	[ : dest name ]
145	#
146	local directory = [ AddDirectoryToContainer $(container)
147		: $(directoryTokens) ] ;
148	local containerGrist = [ on $(container) return $(HAIKU_CONTAINER_GRIST) ] ;
149
150	# If the image shall only be updated, we filter out all targets not marked
151	# accordingly.
152	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
153		local filterVar
154			= [ on $(container) return $(HAIKU_INCLUDE_IN_CONTAINER_VAR) ] ;
155		if $(filterVar) {
156			targets = [ FilterContainerUpdateTargets $(targets)
157				: $(filterVar) ] ;
158		}
159	}
160
161	# We create a unique dummy target per target to install.
162	local installTargetsVar
163		= [ on $(container) return $(HAIKU_INSTALL_TARGETS_VAR) ] ;
164	local target ;
165	for target in $(targets) {
166		local name ;
167		if $(destName) {
168			name = $(destName) ;
169		} else {
170			name = $(target:G=:D=) ;
171		}
172
173		local destTarget = $(name:G=$(containerGrist)__$(directory:G=)) ;
174		TARGET on $(destTarget) = $(target) ;
175		INSTALL_DIR on $(destTarget) = $(directory) ;
176		$(installTargetsVar) on $(target) += $(destTarget) ;
177		TARGETS_TO_INSTALL on $(directory) += $(destTarget) ;
178	}
179}
180
181rule AddSymlinkToContainer container : directoryTokens : linkTarget : linkName
182{
183	# AddSymlinkToContainer <container> : <directory> : <link target>
184	#	[ : <link name> ] ;
185	#
186
187	# If the image shall only be updated, we don't add any symlinks.
188	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
189		return ;
190	}
191
192	local directory = [ AddDirectoryToContainer $(container)
193		: $(directoryTokens) ] ;
194
195	if ! $(linkName) {
196		local path = [ FReverse [ FSplitPath $(linkTarget) ] ] ;
197		linkName = $(path[1]) ;
198	}
199
200	local link = $(directory)/$(linkName) ;
201	SYMLINK_TARGET on $(link) = $(linkTarget) ;
202	SYMLINKS_TO_INSTALL on $(directory) += $(link) ;
203}
204
205rule CopyDirectoryToContainer container : directoryTokens : sourceDirectory
206	: targetDirectoryName : excludePatterns : alwaysUpdate
207{
208	# CopyDirectoryToContainer <container> : <directoryTokens>
209	#	: <sourceDirectory> : <targetDirectoryName> : <excludePatterns>
210	#	: <alwaysUpdate> ;
211	#
212
213	# If the image shall only be updated, we don't copy any directories
214	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ]
215			&& ! $(alwaysUpdate) {
216		return ;
217	}
218
219	if ! $(targetDirectoryName) {
220		local path = [ FReverse [ FSplitPath $(sourceDirectory) ] ] ;
221		targetDirectoryName = $(path[1]) ;
222	}
223
224	local directory = [ AddDirectoryToContainer $(container)
225		: $(directoryTokens) $(targetDirectoryName) ] ;
226
227	local targetDir = $(directory)/-/$(sourceDirectory) ;
228	EXCLUDE_PATTERNS on $(targetDir) = $(excludePatterns) ;
229	SOURCE_DIRECTORY on $(targetDir) = $(sourceDirectory) ;
230	TARGET_DIRECTORY on $(targetDir) = $(directory) ;
231	DIRECTORIES_TO_INSTALL on $(directory) += $(targetDir) ;
232}
233
234rule UnzipArchiveToContainer container : directoryTokens : zipFile
235{
236	# UnzipArchiveToContainer <container> : <directory> : <zipFile> ] ;
237	#
238
239	local directory = [ AddDirectoryToContainer $(container)
240		: $(directoryTokens) ] ;
241
242	ZIP_FILES_TO_INSTALL on $(directory) += $(zipFile) ;
243}
244
245rule AddDriversToContainer container : relativeDirectoryTokens : targets
246{
247	# AddDriversToContainer <container> : <relative directory> : <targets> ;
248	#
249	local directoryTokens = beos system add-ons kernel drivers dev
250		$(relativeDirectoryTokens) ;
251
252	AddFilesToContainer $(container) : beos system add-ons kernel drivers bin
253		: $(targets) ;
254
255	# If the image shall only be updated, we don't add any symlinks.
256	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
257		return ;
258	}
259
260	# get the relative symlink path prefix
261	local linkPrefix = ;
262	for i in $(relativeDirectoryTokens) {
263		linkPrefix += .. ;
264	}
265	linkPrefix += .. bin ;
266
267	# add the symlinks
268	local name ;
269	for name in $(targets:BS) {
270		AddSymlinkToContainer $(container) : $(directoryTokens)
271			: [ FDirName $(linkPrefix) $(name) ] : $(name) ;
272	}
273}
274
275rule AddDriverRegistrationToContainer container : relativeDirectoryTokens
276	: target : links
277{
278	# AddDriverRegistrationToContainer <container> : <directory>
279	#	: <link target> : <link names> ] ;
280	#
281	local directoryTokens = beos system add-ons kernel registration
282		$(relativeDirectoryTokens) ;
283
284	# get the relative symlink path prefix
285	local linkPrefix = ;
286	for i in $(relativeDirectoryTokens) {
287		linkPrefix += .. ;
288	}
289	linkPrefix += .. drivers bin ;
290
291	# add the symlink
292	AddSymlinkToContainer $(container) : $(directoryTokens)
293		: [ FDirName $(linkPrefix) $(target:BS) ] : $(links) ;
294}
295
296rule AddBootModuleSymlinksToContainer container : targets
297{
298	# AddBootModuleSymlinksToContainer <container> : <targets> ;
299	#
300
301	# If the image shall only be updated, we don't add any symlinks.
302	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
303		return ;
304	}
305
306	# add the symlinks
307	local installTargetsVar
308		= [ on $(container) return $(HAIKU_INSTALL_TARGETS_VAR) ] ;
309	local target ;
310	for target in $(targets) {
311		# Symlink to the first place where the target has been installed.
312		local destTarget = [ on $(target) return $($(installTargetsVar)[1]) ] ;
313		local installDir = [ on $(destTarget) return $(INSTALL_DIR) ] ;
314
315		if ! $(installDir) {
316			Echo "ERROR: AddBootModuleSymlinksToContainer: Can't create a "
317				"symlink to target" \"$(target)"\"." ;
318			Exit "ERROR: Add*ToContainer has not been invoked for it yet." ;
319		}
320
321		local name = $(target:BS) ;
322		local linkTarget = [ FDirName /boot $(installDir:G=) $(name) ] ; 
323
324		AddSymlinkToContainer $(container) : beos system add-ons kernel boot
325			: $(linkTarget) : $(name) ;
326	}
327}
328
329
330rule CreateContainerMakeDirectoriesScript container : script
331{
332	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
333	Always $(script) ;
334
335	local initScript = [ InitScript $(script) ] ;
336
337	local scriptBody
338		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
339	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
340	Depends $(scriptBody) : $(initScript) ;
341	Depends $(script) : $(scriptBody) ;
342
343	# collect the directories to create
344	local dirsToCreate ;
345	local directories = [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] ;
346	local dir ;
347	for dir in $(directories) {
348		if ! [ on $(dir) return $(DONT_CREATE) ] {
349			dirsToCreate += $(dir) ;
350		}
351	}
352
353	# If the image shall only be updated, we don't create directories.
354	if $(dirsToCreate)
355		&& ! [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
356		Depends $(scriptBody) : $(dirsToCreate) ;
357		CreateContainerMakeDirectoriesScript1 $(scriptBody) : $(dirsToCreate) ;
358
359		# For directories with attributes, we convert those the specified
360		# resource files to files with attributes and add commands to the script
361		# adding the attributes to the directories.
362		for dir in $(directories) {
363			local resourceFiles = [ on $(dir) return $(ATTRIBUTE_FILES) ] ;
364			if $(resourceFiles) {
365				local dirTokens = [ on $(dir) return $(DIRECTORY_TOKENS) ] ;
366	
367				# translate resources file to file with attributes
368				local attributeFile = $(script)-attributes-$(dirTokens:J=-) ;
369				ResAttr $(attributeFile) : $(resourceFiles) ;
370	
371				# use a unique dummy target for this file, on which we
372				# can define the TARGET_DIR variable
373				local dummyTarget = $(script)-attributes-dummy-$(dir:G=) ;
374				NotFile $(dummyTarget) ;
375				TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
376	
377				Depends $(dummyTarget) : $(initScript) $(attributeFile) ;
378				Depends $(script) : $(dummyTarget) ;
379	
380				AppendToContainerMakeDirectoriesScriptAttributes $(dummyTarget)
381					: $(initScript) $(attributeFile) ;
382			}
383		}
384	}
385}
386
387actions piecemeal CreateContainerMakeDirectoriesScript1
388{
389	echo \$mkdir -p "\"\${tPrefix}$(2:G=)\"" >> $(1)
390}
391
392actions AppendToContainerMakeDirectoriesScriptAttributes
393{
394	echo \$copyAttrs "\"\${sPrefix}$(2[2])\"" \
395		"\"\${tPrefix}$(TARGET_DIR)\"" >> $(2[1])
396}
397
398rule CreateContainerCopyFilesScript container : script
399{
400	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
401	Always $(script) ;
402
403	local initScript = [ InitScript $(script) ] ;
404
405	local scriptBody
406		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
407	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
408	Depends $(scriptBody) : $(initScript) ;
409	Depends $(script) : $(scriptBody) ;
410
411	local dir ;
412	for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] {
413		# filter the targets that shall be renamed; they have to be copied
414		# individually
415		local destTargets = [ on $(dir) return $(TARGETS_TO_INSTALL) ] ;
416		local remainingTargets ;
417		local destTarget ;
418		for destTarget in $(destTargets) {
419			local target = [ on $(destTarget) return $(TARGET) ] ;
420			local name = $(destTarget:BS) ;
421			if $(name) != $(target:BS) {
422				# use a unique dummy target for this file, on which we
423				# can define the TARGET_DIR variable
424				local dummyTarget = $(script)-dummy-$(dir:G=)-$(target) ;
425				NotFile $(dummyTarget) ;
426				TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
427				INSTALL_TARGET_NAME on $(dummyTarget) = $(name) ;
428	
429				Depends $(dummyTarget) : $(initScript) $(target) ;
430				Depends $(script) : $(dummyTarget) ;
431
432				AppendToContainerCopyFilesScriptSingleFile $(dummyTarget)
433					: $(initScript) $(target) ;
434			} else {
435				remainingTargets += $(target) ;
436			}
437		}
438		targets = $(remainingTargets) ;
439
440		if $(targets) {
441			# use a unique dummy target for this directory, on which we
442			# can define the TARGET_DIR variable
443			local dummyTarget = $(script)-dummy-$(dir:G=) ;
444			NotFile $(dummyTarget) ;
445			TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
446
447			Depends $(dummyTarget) : $(initScript) $(targets) ;
448			Depends $(script) : $(dummyTarget) ;
449
450			OUTPUT_SCRIPT on $(dummyTarget) = $(initScript) ;
451			AppendToContainerCopyFilesScript $(dummyTarget) : $(targets) ;
452		}
453	
454		local symlinks = [ on $(dir) return $(SYMLINKS_TO_INSTALL) ] ;
455		local symlink ;
456		for symlink in $(symlinks) {
457			NotFile $(symlink) ;
458
459			Depends $(script) : $(symlink) ;
460			Depends $(symlink) : $(initScript) ;
461
462			AddSymlinkToContainerCopyFilesScript $(symlink) : $(initScript) ;
463		}
464
465		local targetDirs = [ on $(dir) return $(DIRECTORIES_TO_INSTALL) ] ;
466		local targetDir ;
467		for targetDir in $(targetDirs) {
468			NotFile $(targetDir) ;
469
470			Depends $(script) : $(targetDir) ;
471			Depends $(targetDir) : $(initScript) ;
472
473			AddDirectoryToContainerCopyFilesScript $(targetDir) : $(initScript) ;
474		}
475	}
476}
477
478actions piecemeal AppendToContainerCopyFilesScript bind OUTPUT_SCRIPT
479{
480	echo \$cp "\"\${sPrefix}$(2)\"" "\"\${tPrefix}$(TARGET_DIR)\"" >> $(OUTPUT_SCRIPT)
481}
482
483actions AppendToContainerCopyFilesScriptSingleFile
484{
485	echo \$cp "\"\${sPrefix}$(2[2])\"" \
486		"\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" >> $(2[1])
487}
488
489actions AddSymlinkToContainerCopyFilesScript
490{
491	echo \$ln -sfn "\"$(SYMLINK_TARGET)\"" "\"\${tPrefix}$(1:G=)\"" >> $(2[1])
492}
493
494actions AddDirectoryToContainerCopyFilesScript
495{
496	echo \$cp -r $(EXCLUDE_PATTERNS) "\"\${sPrefix}$(SOURCE_DIRECTORY)/.\"" \
497		"\"\${tPrefix}$(TARGET_DIRECTORY:G=)\"" >> $(2[1])
498}
499
500
501rule CreateContainerUnzipFilesScript container : script
502{
503	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
504	Always $(script) ;
505
506	local initScript = [ InitScript $(script) ] ;
507
508	local scriptBody
509		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
510	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
511	Depends $(scriptBody) : $(initScript) ;
512	Depends $(script) : $(scriptBody) ;
513
514	local dir ;
515	for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] {
516		local zipFiles = [ on $(dir) return $(ZIP_FILES_TO_INSTALL) ] ;
517		local zipFile ;
518		for zipFile in $(zipFiles) {
519			# use a unique dummy target for this file, on which we
520			# can define the TARGET_DIR variable
521			local dummyTarget = $(script)-dummy-$(dir:G=)-$(zipFile) ;
522			NotFile $(dummyTarget) ;
523			TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
524
525			Depends $(dummyTarget) : $(initScript) $(zipFile) ;
526			Depends $(script) : $(dummyTarget) ;
527
528			AddUnzipFileToContainerUnzipFilesScript $(dummyTarget)
529				: $(initScript) $(zipFile) ;
530		}
531	}
532}
533
534actions AddUnzipFileToContainerUnzipFilesScript
535{
536	echo unzipFile "\"$(2[2])\"" "\"$(TARGET_DIR)\"" >> $(2[1])
537}
538
539
540#pragma mark - Haiku Image rules
541
542rule SetUpdateHaikuImageOnly flag
543{
544	HAIKU_CONTAINER_UPDATE_ONLY on $(HAIKU_IMAGE_CONTAINER_NAME) = $(flag) ;
545}
546
547rule IsUpdateHaikuImageOnly
548{
549	on $(HAIKU_IMAGE_CONTAINER_NAME) return $(HAIKU_CONTAINER_UPDATE_ONLY) ;
550}
551
552rule AddDirectoryToHaikuImage directoryTokens : attributeFiles
553{
554	# AddDirectoryToHaikuImage <directoryTokens>
555
556	local dir = [ AddDirectoryToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
557		: $(directoryTokens) ] ;
558
559	if $(attributeFiles) {
560		SEARCH on $(attributeFiles)
561			+= [ FDirName $(HAIKU_TOP) data image_directories ] ;
562		ATTRIBUTE_FILES on $(dir) += $(attributeFiles) ;
563	}
564
565	return $(dir) ;
566}
567
568rule AddFilesToHaikuImage directory : targets : destName
569{
570	# AddFilesToHaikuImage <directory> : <targets> [ : dest name ]
571
572	AddFilesToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directory)
573		: $(targets) : $(destName) ;
574}
575
576rule AddSymlinkToHaikuImage directoryTokens : linkTarget : linkName
577{
578	# AddSymlinkToHaikuImage <directory> : <link target> [ : <link name> ] ;
579
580	AddSymlinkToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directoryTokens)
581		: $(linkTarget) : $(linkName) ;
582}
583
584rule CopyDirectoryToHaikuImage directoryTokens : sourceDirectory
585	: targetDirectoryName : excludePatterns : alwaysUpdate
586{
587	CopyDirectoryToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directoryTokens)
588		: $(sourceDirectory) : $(targetDirectoryName) : $(excludePatterns)
589		: $(alwaysUpdate) ;
590}
591
592rule AddSourceDirectoryToHaikuImage dirTokens : alwaysUpdate
593{
594	# AddSourceDirectoryToHaikuImage <dirTokens> : <alwaysUpdate> ;
595
596	CopyDirectoryToHaikuImage home HaikuSources
597		: [ FDirName $(HAIKU_TOP) $(dirTokens) ]
598		: : -x .svn : $(alwaysUpdate) ;
599}
600
601rule AddHeaderDirectoryToHaikuImage dirTokens : dirName : alwaysUpdate
602{
603	# AddHeaderDirectoryToHaikuImage <dirTokens> : [ <dirName> ]
604	#	: <alwaysUpdate> ;
605
606	CopyDirectoryToHaikuImage develop headers
607		: [ FDirName $(HAIKU_TOP) headers $(dirTokens) ]
608		: $(dirName) : -x .svn : $(alwaysUpdate) ;
609}
610
611rule UnzipArchiveToHaikuImage dirTokens : zipFile : alwaysUpdate
612{
613	# UnzipArchiveToHaikuImage <dirTokens> : <zipFile> : <alwaysUpdate> ;
614
615	# If the image shall only be updated, we unzip only, if explicitely
616	# requested.
617	if ! [ IsUpdateHaikuImageOnly ] || $(alwaysUpdate) {
618		UnzipArchiveToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(dirTokens)
619			: $(zipFile) ;
620	}
621}
622
623rule AddDriversToHaikuImage relativeDirectoryTokens : targets
624{
625	# AddDriversToHaikuImage <relative directory> : <targets> ;
626
627	AddDriversToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
628		: $(relativeDirectoryTokens) : $(targets) ;
629}
630
631rule AddDriverRegistrationToHaikuImage relativeDirectoryTokens : target : links
632{
633	# AddDriverRegistrationToHaikuImage <directory> : <link target> : <link names> ] ;
634
635	AddDriverRegistrationToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
636		: $(relativeDirectoryTokens) : $(target) : $(links) ;
637}
638
639rule AddBootModuleSymlinksToHaikuImage targets
640{
641	# AddBootModuleSymlinksToHaikuImage <targets> ;
642
643	AddBootModuleSymlinksToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
644		: $(targets) ;
645}
646
647rule AddOptionalHaikuImagePackages packages
648{
649	HAIKU_OPTIONAL_PACKAGE_ADDED on $(packages) = 1 ;
650}
651
652rule IsOptionalHaikuImagePackageAdded package
653{
654	if [ on $(package) return $(HAIKU_OPTIONAL_PACKAGE_ADDED) ] {
655		return 1 ;
656	}
657
658	return $(HAIKU_ADD_ALL_OPTIONAL_PACKAGES) ;
659}
660
661rule OptionalPackageDependencies package : dependencies
662{
663	if [ IsOptionalHaikuImagePackageAdded $(package) ] {
664		AddOptionalHaikuImagePackages $(dependencies) ;
665	}
666}
667
668rule InstallOptionalHaikuImagePackage package : url : dirTokens
669{
670	# download zip file
671	local zipFile = $(package:G=download).zip ;
672	MakeLocate $(zipFile) : $(HAIKU_DOWNLOAD_DIR) ;
673	DownloadFile $(zipFile) : $(url) ;
674
675	# unzip onto image
676	UnzipArchiveToHaikuImage $(dirTokens) : $(zipFile) ;
677}
678
679
680rule CreateHaikuImageMakeDirectoriesScript script
681{
682	CreateContainerMakeDirectoriesScript $(HAIKU_IMAGE_CONTAINER_NAME)
683		: $(script) ;
684}
685
686rule CreateHaikuImageCopyFilesScript script
687{
688	CreateContainerCopyFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ;
689}
690
691rule CreateHaikuImageUnzipFilesScript script
692{
693	CreateContainerUnzipFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ;
694}
695
696rule BuildHaikuImage haikuImage : scripts : isImage : isVMwareImage
697{
698	# BuildHaikuImage <haiku image> : <scripts> : <is image> : <isVMwareImage> ;
699
700	if $(isImage) = 1 || $(isImage) = true {
701		IS_IMAGE on $(haikuImage) = 1 ;
702	} else {
703		IS_IMAGE on $(haikuImage) = "" ;
704	}
705
706	if $(isVMwareImage) = 1 || $(isVMwareImage) = true {
707		IS_VMWARE_IMAGE on $(haikuImage) = 1 ;
708	} else {
709		IS_VMWARE_IMAGE on $(haikuImage) = "" ;
710	}
711
712	local mainScript = build_haiku_image ;
713	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
714
715	Depends $(haikuImage) : $(mainScript) $(scripts) ;
716	BuildHaikuImage1 $(haikuImage) : $(mainScript) $(scripts) ;
717}
718
719actions BuildHaikuImage1
720{
721	export imagePath="$(1)"
722	export isImage="$(IS_IMAGE)"
723	export isVMwareImage="$(IS_VMWARE_IMAGE)"
724	$(2[1]) $(2[2-])
725}
726
727rule BuildVMWareImage vmwareImage : plainImage : imageSize
728{
729	# BuildVMWareImage <vmware image> : <plain image> : <image size in MB>
730
731	IMAGE_SIZE on $(vmwareImage) = $(imageSize) ;
732
733	Depends $(vmwareImage) : <build>vmdkheader $(plainImage) ;
734	BuildVMWareImage1 $(vmwareImage) : <build>vmdkheader $(plainImage) ;
735}
736
737actions BuildVMWareImage1
738{
739	$(RM) $(1)
740	$(2[1]) -h 64k -i$(IMAGE_SIZE)M $(1) &&
741	cat $(2[2]) >> $(1)
742}
743
744
745#pragma mark - Network Boot Archive rules
746
747rule AddDirectoryToNetBootArchive directoryTokens
748{
749	# AddDirectoryToNetBootArchive <directoryTokens>
750
751	return [ AddDirectoryToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
752		: $(directoryTokens) ] ;
753}
754
755rule AddFilesToNetBootArchive directory : targets : destName
756{
757	# AddFilesToNetBootArchive <directory> : <targets> [ : dest name ]
758
759	AddFilesToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(directory)
760		: $(targets) : $(destName) ;
761}
762
763rule AddSymlinkToNetBootArchive directoryTokens : linkTarget : linkName
764{
765	# AddSymlinkToNetBootArchive <directory> : <link target> [ : <link name> ] ;
766
767	AddSymlinkToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
768		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
769}
770
771rule AddDriversToNetBootArchive relativeDirectoryTokens : targets
772{
773	# AddDriversToNetBootArchive <relative directory> : <targets> ;
774
775	AddDriversToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
776		: $(relativeDirectoryTokens) : $(targets) ;
777}
778
779rule AddDriverRegistrationToNetBootArchive relativeDirectoryTokens : target
780	: links
781{
782	# AddDriverRegistrationToNetBootArchive <directory> : <link target>
783	#	: <link names> ] ;
784
785	AddDriverRegistrationToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
786		: $(relativeDirectoryTokens) : $(target) : $(links) ;
787}
788
789rule AddBootModuleSymlinksToNetBootArchive targets
790{
791	# AddBootModuleSymlinksToNetBootArchive <targets> ;
792
793	AddBootModuleSymlinksToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
794		: $(targets) ;
795}
796
797rule CreateNetBootArchiveMakeDirectoriesScript script
798{
799	CreateContainerMakeDirectoriesScript
800		$(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(script) ;
801}
802
803rule CreateNetBootArchiveCopyFilesScript script
804{
805	CreateContainerCopyFilesScript $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
806		: $(script) ;
807}
808
809rule BuildNetBootArchive archive : scripts
810{
811	# BuildHNetBootArchive <archive> : <scripts>  ;
812
813	local mainScript = build_tgz_archive ;
814	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
815
816	Depends $(archive) : $(mainScript) $(scripts) ;
817	BuildNetBootArchive1 $(archive) : $(mainScript) $(scripts) ;
818}
819
820actions BuildNetBootArchive1
821{
822	$(2[1]) $(1) $(2[2-])
823}
824
825
826#pragma mark - Floppy Boot Archive rules
827
828rule AddDirectoryToFloppyBootArchive directoryTokens
829{
830	# AddDirectoryToFloppyBootArchive <directoryTokens>
831
832	return [ AddDirectoryToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
833		: $(directoryTokens) ] ;
834}
835
836rule AddFilesToFloppyBootArchive directory : targets : destName
837{
838	# AddFilesToFloppyBootArchive <directory> : <targets> [ : dest name ]
839
840	AddFilesToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(directory)
841		: $(targets) : $(destName) ;
842}
843
844rule AddSymlinkToFloppyBootArchive directoryTokens : linkTarget : linkName
845{
846	# AddSymlinkToFloppyBootArchive <directory> : <link target> [ : <link name> ] ;
847
848	AddSymlinkToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
849		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
850}
851
852rule AddDriversToFloppyBootArchive relativeDirectoryTokens : targets
853{
854	# AddDriversToFloppyBootArchive <relative directory> : <targets> ;
855
856	AddDriversToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
857		: $(relativeDirectoryTokens) : $(targets) ;
858}
859
860rule AddDriverRegistrationToFloppyBootArchive relativeDirectoryTokens : target
861	: links
862{
863	# AddDriverRegistrationToFloppyBootArchive <directory> : <link target>
864	#	: <link names> ] ;
865
866	AddDriverRegistrationToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
867		: $(relativeDirectoryTokens) : $(target) : $(links) ;
868}
869
870rule AddBootModuleSymlinksToFloppyBootArchive targets
871{
872	# AddBootModuleSymlinksToFloppyBootArchive <targets> ;
873
874	AddBootModuleSymlinksToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
875		: $(targets) ;
876}
877
878rule CreateFloppyBootArchiveMakeDirectoriesScript script
879{
880	CreateContainerMakeDirectoriesScript
881		$(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(script) ;
882}
883
884rule CreateFloppyBootArchiveCopyFilesScript script
885{
886	CreateContainerCopyFilesScript $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
887		: $(script) ;
888}
889
890rule BuildFloppyBootArchive archive : scripts
891{
892	# BuildHFloppyBootArchive <archive> : <scripts>  ;
893
894	local mainScript = build_tgz_archive ;
895	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
896
897	Depends $(archive) : $(mainScript) $(scripts) ;
898	BuildFloppyBootArchive1 $(archive) : $(mainScript) $(scripts) ;
899}
900
901actions BuildFloppyBootArchive1
902{
903	$(2[1]) $(1) $(2[2-])
904}
905
906# warning: that is quite x86 dependant...
907
908rule BuildFloppyBootImage image : zbeos : archive
909{
910	Depends $(image) : $(zbeos) ;
911	Depends $(image) : $(archive) ;
912	#MakeLocateDebug $(image) ;
913	BuildFloppyBootImage1 $(image) : $(zbeos) $(archive) ;
914}
915
916actions BuildFloppyBootImage1
917{
918	$(RM) $(<)
919	# make an empty image
920	dd if=/dev/zero of=$(<) bs=1k count=1440
921	# add zbeos
922	dd if=$(>[1]) of=$(<) conv=notrunc
923	# add the boot drivers tgz archive
924	# keep the offset in sync with
925	# src/system/boot/loader/file_systems/tarfs/tarfs.cpp:kFloppyArchiveOffset
926	dd if=$(>[2]) of=$(<) bs=192k seek=1 conv=notrunc
927}
928
929
930#pragma mark - CD Boot Image rules
931
932rule BuildCDBootImage image : bootfloppy : extrafiles
933{
934	Depends $(image) : $(bootfloppy) ;
935	Depends $(image) : $(extrafiles) ;
936	BOOTIMG on $(image) = $(bootfloppy) ;
937
938	BuildCDBootImage1 $(image) : $(bootfloppy) $(extrafiles) ;
939}
940
941actions BuildCDBootImage1
942{
943	$(RM) $(<)
944	mkisofs -b $(BOOTIMG) -r -J -V bootimg -o $(<) $(>[1]) $(>[2-])
945}
946
947
948