ImageRules revision d41c97f7
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 UnzipArchiveToContainer container : directoryTokens : zipFile
206{
207	# UnzipArchiveToContainer <container> : <directory> : <zipFile> ] ;
208	#
209
210	local directory = [ AddDirectoryToContainer $(container)
211		: $(directoryTokens) ] ;
212
213	ZIP_FILES_TO_INSTALL on $(directory) += $(zipFile) ;
214}
215
216rule AddDriversToContainer container : relativeDirectoryTokens : targets
217{
218	# AddDriversToContainer <container> : <relative directory> : <targets> ;
219	#
220	local directoryTokens = beos system add-ons kernel drivers dev
221		$(relativeDirectoryTokens) ;
222
223	AddFilesToContainer $(container) : beos system add-ons kernel drivers bin
224		: $(targets) ;
225
226	# If the image shall only be updated, we don't add any symlinks.
227	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
228		return ;
229	}
230
231	# get the relative symlink path prefix
232	local linkPrefix = ;
233	for i in $(relativeDirectoryTokens) {
234		linkPrefix += .. ;
235	}
236	linkPrefix += .. bin ;
237
238	# add the symlinks
239	local name ;
240	for name in $(targets:BS) {
241		AddSymlinkToContainer $(container) : $(directoryTokens)
242			: [ FDirName $(linkPrefix) $(name) ] : $(name) ;
243	}
244}
245
246rule AddDriverRegistrationToContainer container : relativeDirectoryTokens
247	: target : links
248{
249	# AddDriverRegistrationToContainer <container> : <directory>
250	#	: <link target> : <link names> ] ;
251	#
252	local directoryTokens = beos system add-ons kernel registration
253		$(relativeDirectoryTokens) ;
254
255	# get the relative symlink path prefix
256	local linkPrefix = ;
257	for i in $(relativeDirectoryTokens) {
258		linkPrefix += .. ;
259	}
260	linkPrefix += .. drivers bin ;
261
262	# add the symlink
263	AddSymlinkToContainer $(container) : $(directoryTokens)
264		: [ FDirName $(linkPrefix) $(target:BS) ] : $(links) ;
265}
266
267rule AddBootModuleSymlinksToContainer container : targets
268{
269	# AddBootModuleSymlinksToContainer <container> : <targets> ;
270	#
271
272	# If the image shall only be updated, we don't add any symlinks.
273	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
274		return ;
275	}
276
277	# add the symlinks
278	local installTargetsVar
279		= [ on $(container) return $(HAIKU_INSTALL_TARGETS_VAR) ] ;
280	local target ;
281	for target in $(targets) {
282		# Symlink to the first place where the target has been installed.
283		local destTarget = [ on $(target) return $($(installTargetsVar)[1]) ] ;
284		local installDir = [ on $(destTarget) return $(INSTALL_DIR) ] ;
285
286		if ! $(installDir) {
287			Echo "ERROR: AddBootModuleSymlinksToContainer: Can't create a "
288				"symlink to target" \"$(target)"\"." ;
289			Exit "ERROR: Add*ToContainer has not been invoked for it yet." ;
290		}
291
292		local name = $(target:BS) ;
293		local linkTarget = [ FDirName /boot $(installDir:G=) $(name) ] ; 
294
295		AddSymlinkToContainer $(container) : beos system add-ons kernel boot
296			: $(linkTarget) : $(name) ;
297	}
298}
299
300
301rule CreateContainerMakeDirectoriesScript container : script
302{
303	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
304	Always $(script) ;
305
306	local initScript = [ InitScript $(script) ] ;
307
308	local scriptBody
309		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
310	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
311	Depends $(scriptBody) : $(initScript) ;
312	Depends $(script) : $(scriptBody) ;
313
314	# collect the directories to create
315	local dirsToCreate ;
316	local directories = [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] ;
317	local dir ;
318	for dir in $(directories) {
319		if ! [ on $(dir) return $(DONT_CREATE) ] {
320			dirsToCreate += $(dir) ;
321		}
322	}
323
324	# If the image shall only be updated, we don't create directories.
325	if $(dirsToCreate)
326		&& ! [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
327		Depends $(scriptBody) : $(dirsToCreate) ;
328		CreateContainerMakeDirectoriesScript1 $(scriptBody) : $(dirsToCreate) ;
329
330		# For directories with attributes, we convert those the specified
331		# resource files to files with attributes and add commands to the script
332		# adding the attributes to the directories.
333		for dir in $(directories) {
334			local resourceFiles = [ on $(dir) return $(ATTRIBUTE_FILES) ] ;
335			if $(resourceFiles) {
336				local dirTokens = [ on $(dir) return $(DIRECTORY_TOKENS) ] ;
337	
338				# translate resources file to file with attributes
339				local attributeFile = $(script)-attributes-$(dirTokens:J=-) ;
340				ResAttr $(attributeFile) : $(resourceFiles) ;
341	
342				# use a unique dummy target for this file, on which we
343				# can define the TARGET_DIR variable
344				local dummyTarget = $(script)-attributes-dummy-$(dir:G=) ;
345				NotFile $(dummyTarget) ;
346				TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
347	
348				Depends $(dummyTarget) : $(initScript) $(attributeFile) ;
349				Depends $(script) : $(dummyTarget) ;
350	
351				AppendToContainerMakeDirectoriesScriptAttributes $(dummyTarget)
352					: $(initScript) $(attributeFile) ;
353			}
354		}
355	}
356}
357
358actions piecemeal CreateContainerMakeDirectoriesScript1
359{
360	echo \$mkdir -p "\"\${tPrefix}$(2:G=)\"" >> $(1)
361}
362
363actions AppendToContainerMakeDirectoriesScriptAttributes
364{
365	echo \$copyAttrs "\"\${sPrefix}$(2[2])\"" \
366		"\"\${tPrefix}$(TARGET_DIR)\"" >> $(2[1])
367}
368
369rule CreateContainerCopyFilesScript container : script
370{
371	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
372	Always $(script) ;
373
374	local initScript = [ InitScript $(script) ] ;
375
376	local scriptBody
377		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
378	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
379	Depends $(scriptBody) : $(initScript) ;
380	Depends $(script) : $(scriptBody) ;
381
382	local dir ;
383	for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] {
384		# filter the targets that shall be renamed; they have to be copied
385		# individually
386		local destTargets = [ on $(dir) return $(TARGETS_TO_INSTALL) ] ;
387		local remainingTargets ;
388		local destTarget ;
389		for destTarget in $(destTargets) {
390			local target = [ on $(destTarget) return $(TARGET) ] ;
391			local name = $(destTarget:BS) ;
392			if $(name) != $(target:BS) {
393				# use a unique dummy target for this file, on which we
394				# can define the TARGET_DIR variable
395				local dummyTarget = $(script)-dummy-$(dir:G=)-$(target) ;
396				NotFile $(dummyTarget) ;
397				TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
398				INSTALL_TARGET_NAME on $(dummyTarget) = $(name) ;
399	
400				Depends $(dummyTarget) : $(initScript) $(target) ;
401				Depends $(script) : $(dummyTarget) ;
402
403				AppendToContainerCopyFilesScriptSingleFile $(dummyTarget)
404					: $(initScript) $(target) ;
405			} else {
406				remainingTargets += $(target) ;
407			}
408		}
409		targets = $(remainingTargets) ;
410
411		if $(targets) {
412			# use a unique dummy target for this directory, on which we
413			# can define the TARGET_DIR variable
414			local dummyTarget = $(script)-dummy-$(dir:G=) ;
415			NotFile $(dummyTarget) ;
416			TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
417
418			Depends $(dummyTarget) : $(initScript) $(targets) ;
419			Depends $(script) : $(dummyTarget) ;
420
421			OUTPUT_SCRIPT on $(dummyTarget) = $(initScript) ;
422			AppendToContainerCopyFilesScript $(dummyTarget) : $(targets) ;
423		}
424	
425		local symlinks = [ on $(dir) return $(SYMLINKS_TO_INSTALL) ] ;
426		local symlink ;
427		for symlink in $(symlinks) {
428			NotFile $(symlink) ;
429
430			Depends $(script) : $(symlink) ;
431			Depends $(symlink) : $(initScript) ;
432
433			AddSymlinkToContainerCopyFilesScript $(symlink) : $(initScript) ;
434		}
435	}
436}
437
438actions piecemeal AppendToContainerCopyFilesScript bind OUTPUT_SCRIPT
439{
440	echo \$cp "\"\${sPrefix}$(2)\"" "\"\${tPrefix}$(TARGET_DIR)\"" >> $(OUTPUT_SCRIPT)
441}
442
443actions AppendToContainerCopyFilesScriptSingleFile
444{
445	echo \$cp "\"\${sPrefix}$(2[2])\"" \
446		"\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" >> $(2[1])
447}
448
449actions AddSymlinkToContainerCopyFilesScript
450{
451	echo \$ln -sfn "\"$(SYMLINK_TARGET)\"" "\"\${tPrefix}$(1:G=)\"" >> $(2[1])
452}
453
454
455rule CreateContainerUnzipFilesScript container : script
456{
457	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
458	Always $(script) ;
459
460	local initScript = [ InitScript $(script) ] ;
461
462	local scriptBody
463		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
464	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
465	Depends $(scriptBody) : $(initScript) ;
466	Depends $(script) : $(scriptBody) ;
467
468	local dir ;
469	for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] {
470		local zipFiles = [ on $(dir) return $(ZIP_FILES_TO_INSTALL) ] ;
471		local zipFile ;
472		for zipFile in $(zipFiles) {
473			# use a unique dummy target for this file, on which we
474			# can define the TARGET_DIR variable
475			local dummyTarget = $(script)-dummy-$(dir:G=)-$(zipFile) ;
476			NotFile $(dummyTarget) ;
477			TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
478
479			Depends $(dummyTarget) : $(initScript) $(zipFile) ;
480			Depends $(script) : $(dummyTarget) ;
481
482			AddUnzipFileToContainerUnzipFilesScript $(dummyTarget)
483				: $(initScript) $(zipFile) ;
484		}
485	}
486}
487
488actions AddUnzipFileToContainerUnzipFilesScript
489{
490	echo unzipFile "\"$(2[2])\"" "\"$(TARGET_DIR)\"" >> $(2[1])
491}
492
493
494#pragma mark - Haiku Image rules
495
496rule SetUpdateHaikuImageOnly flag
497{
498	HAIKU_CONTAINER_UPDATE_ONLY on $(HAIKU_IMAGE_CONTAINER_NAME) = $(flag) ;
499}
500
501rule IsUpdateHaikuImageOnly
502{
503	on $(HAIKU_IMAGE_CONTAINER_NAME) return $(HAIKU_CONTAINER_UPDATE_ONLY) ;
504}
505
506rule AddDirectoryToHaikuImage directoryTokens : attributeFiles
507{
508	# AddDirectoryToHaikuImage <directoryTokens>
509
510	local dir = [ AddDirectoryToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
511		: $(directoryTokens) ] ;
512
513	if $(attributeFiles) {
514		SEARCH on $(attributeFiles)
515			+= [ FDirName $(HAIKU_TOP) data image_directories ] ;
516		ATTRIBUTE_FILES on $(dir) += $(attributeFiles) ;
517	}
518
519	return $(dir) ;
520}
521
522rule AddFilesToHaikuImage directory : targets : destName
523{
524	# AddFilesToHaikuImage <directory> : <targets> [ : dest name ]
525
526	AddFilesToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directory)
527		: $(targets) : $(destName) ;
528}
529
530rule AddSymlinkToHaikuImage directoryTokens : linkTarget : linkName
531{
532	# AddSymlinkToHaikuImage <directory> : <link target> [ : <link name> ] ;
533
534	AddSymlinkToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directoryTokens)
535		: $(linkTarget) : $(linkName) ;
536}
537
538rule AddSourceDirectoryToHaikuImage dirTokens : alwaysUpdate
539{
540	# AddSourceDirectoryToHaikuImage <dirTokens> : <alwaysUpdate> ;
541
542	# If the image shall only be updated, we update sources only, if explicitely
543	# requested.
544	if ! [ IsUpdateHaikuImageOnly ] || $(alwaysUpdate) {
545		HAIKU_INSTALL_SOURCE_DIRS += [ FDirName $(HAIKU_TOP) $(dirTokens) ] ;
546	}
547}
548
549rule AddHeaderDirectoryToHaikuImage dirTokens : alwaysUpdate
550{
551	# AddHeaderDirectoryToHaikuImage <dirTokens> : <alwaysUpdate> ;
552
553	# If the image shall only be updated, we update sources only, if explicitely
554	# requested.
555	if ! [ IsUpdateHaikuImageOnly ] || $(alwaysUpdate) {
556		HAIKU_INSTALL_HEADER_DIRS += [ FDirName $(HAIKU_TOP) headers $(dirTokens) ] ;
557	}
558}
559
560rule UnzipArchiveToHaikuImage dirTokens : zipFile : alwaysUpdate
561{
562	# UnzipArchiveToHaikuImage <dirTokens> : <zipFile> : <alwaysUpdate> ;
563
564	# If the image shall only be updated, we unzip only, if explicitely
565	# requested.
566	if ! [ IsUpdateHaikuImageOnly ] || $(alwaysUpdate) {
567		UnzipArchiveToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(dirTokens)
568			: $(zipFile) ;
569	}
570}
571
572rule AddDriversToHaikuImage relativeDirectoryTokens : targets
573{
574	# AddDriversToHaikuImage <relative directory> : <targets> ;
575
576	AddDriversToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
577		: $(relativeDirectoryTokens) : $(targets) ;
578}
579
580rule AddDriverRegistrationToHaikuImage relativeDirectoryTokens : target : links
581{
582	# AddDriverRegistrationToHaikuImage <directory> : <link target> : <link names> ] ;
583
584	AddDriverRegistrationToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
585		: $(relativeDirectoryTokens) : $(target) : $(links) ;
586}
587
588rule AddBootModuleSymlinksToHaikuImage targets
589{
590	# AddBootModuleSymlinksToHaikuImage <targets> ;
591
592	AddBootModuleSymlinksToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
593		: $(targets) ;
594}
595
596rule AddOptionalHaikuImagePackages packages
597{
598	HAIKU_OPTIONAL_PACKAGE_ADDED on $(packages) = 1 ;
599}
600
601rule IsOptionalHaikuImagePackageAdded package
602{
603	if [ on $(package) return $(HAIKU_OPTIONAL_PACKAGE_ADDED) ] {
604		return 1 ;
605	}
606
607	return $(HAIKU_ADD_ALL_OPTIONAL_PACKAGES) ;
608}
609
610rule InstallOptionalHaikuImagePackage package : url : dirTokens
611{
612	# download zip file
613	local zipFile = $(package:G=download).zip ;
614	MakeLocate $(zipFile) : $(HAIKU_DOWNLOAD_DIR) ;
615	DownloadFile $(zipFile) : $(url) ;
616
617	# unzip onto image
618	UnzipArchiveToHaikuImage $(dirTokens) : $(zipFile) ;
619}
620
621
622rule CreateHaikuImageMakeDirectoriesScript script
623{
624	CreateContainerMakeDirectoriesScript $(HAIKU_IMAGE_CONTAINER_NAME)
625		: $(script) ;
626}
627
628rule CreateHaikuImageCopyFilesScript script
629{
630	CreateContainerCopyFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ;
631}
632
633rule CreateHaikuImageUnzipFilesScript script
634{
635	CreateContainerUnzipFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ;
636}
637
638rule BuildHaikuImage haikuImage : scripts : isImage : isVMwareImage
639{
640	# BuildHaikuImage <haiku image> : <scripts> : <is image> : <isVMwareImage> ;
641
642	if $(isImage) = 1 || $(isImage) = true {
643		IS_IMAGE on $(haikuImage) = 1 ;
644	} else {
645		IS_IMAGE on $(haikuImage) = "" ;
646	}
647
648	if $(isVMwareImage) = 1 || $(isVMwareImage) = true {
649		IS_VMWARE_IMAGE on $(haikuImage) = 1 ;
650	} else {
651		IS_VMWARE_IMAGE on $(haikuImage) = "" ;
652	}
653
654	local mainScript = build_haiku_image ;
655	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
656
657	Depends $(haikuImage) : $(mainScript) $(scripts) ;
658	BuildHaikuImage1 $(haikuImage) : $(mainScript) $(scripts) ;
659}
660
661actions BuildHaikuImage1
662{
663	export imagePath="$(1)"
664	export isImage="$(IS_IMAGE)"
665	export isVMwareImage="$(IS_VMWARE_IMAGE)"
666	$(2[1]) $(2[2-])
667}
668
669rule BuildVMWareImage vmwareImage : plainImage : imageSize
670{
671	# BuildVMWareImage <vmware image> : <plain image> : <image size in MB>
672
673	IMAGE_SIZE on $(vmwareImage) = $(imageSize) ;
674
675	Depends $(vmwareImage) : <build>vmdkheader $(plainImage) ;
676	BuildVMWareImage1 $(vmwareImage) : <build>vmdkheader $(plainImage) ;
677}
678
679actions BuildVMWareImage1
680{
681	$(RM) $(1)
682	$(2[1]) -h 64k -i$(IMAGE_SIZE)M $(1) &&
683	cat $(2[2]) >> $(1)
684}
685
686
687#pragma mark - Network Boot Archive rules
688
689rule AddDirectoryToNetBootArchive directoryTokens
690{
691	# AddDirectoryToNetBootArchive <directoryTokens>
692
693	return [ AddDirectoryToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
694		: $(directoryTokens) ] ;
695}
696
697rule AddFilesToNetBootArchive directory : targets : destName
698{
699	# AddFilesToNetBootArchive <directory> : <targets> [ : dest name ]
700
701	AddFilesToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(directory)
702		: $(targets) : $(destName) ;
703}
704
705rule AddSymlinkToNetBootArchive directoryTokens : linkTarget : linkName
706{
707	# AddSymlinkToNetBootArchive <directory> : <link target> [ : <link name> ] ;
708
709	AddSymlinkToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
710		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
711}
712
713rule AddDriversToNetBootArchive relativeDirectoryTokens : targets
714{
715	# AddDriversToNetBootArchive <relative directory> : <targets> ;
716
717	AddDriversToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
718		: $(relativeDirectoryTokens) : $(targets) ;
719}
720
721rule AddDriverRegistrationToNetBootArchive relativeDirectoryTokens : target
722	: links
723{
724	# AddDriverRegistrationToNetBootArchive <directory> : <link target>
725	#	: <link names> ] ;
726
727	AddDriverRegistrationToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
728		: $(relativeDirectoryTokens) : $(target) : $(links) ;
729}
730
731rule AddBootModuleSymlinksToNetBootArchive targets
732{
733	# AddBootModuleSymlinksToNetBootArchive <targets> ;
734
735	AddBootModuleSymlinksToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
736		: $(targets) ;
737}
738
739rule CreateNetBootArchiveMakeDirectoriesScript script
740{
741	CreateContainerMakeDirectoriesScript
742		$(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(script) ;
743}
744
745rule CreateNetBootArchiveCopyFilesScript script
746{
747	CreateContainerCopyFilesScript $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
748		: $(script) ;
749}
750
751rule BuildNetBootArchive archive : scripts
752{
753	# BuildHNetBootArchive <archive> : <scripts>  ;
754
755	local mainScript = build_tgz_archive ;
756	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
757
758	Depends $(archive) : $(mainScript) $(scripts) ;
759	BuildNetBootArchive1 $(archive) : $(mainScript) $(scripts) ;
760}
761
762actions BuildNetBootArchive1
763{
764	$(2[1]) $(1) $(2[2-])
765}
766
767
768#pragma mark - Floppy Boot Archive rules
769
770rule AddDirectoryToFloppyBootArchive directoryTokens
771{
772	# AddDirectoryToFloppyBootArchive <directoryTokens>
773
774	return [ AddDirectoryToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
775		: $(directoryTokens) ] ;
776}
777
778rule AddFilesToFloppyBootArchive directory : targets : destName
779{
780	# AddFilesToFloppyBootArchive <directory> : <targets> [ : dest name ]
781
782	AddFilesToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(directory)
783		: $(targets) : $(destName) ;
784}
785
786rule AddSymlinkToFloppyBootArchive directoryTokens : linkTarget : linkName
787{
788	# AddSymlinkToFloppyBootArchive <directory> : <link target> [ : <link name> ] ;
789
790	AddSymlinkToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
791		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
792}
793
794rule AddDriversToFloppyBootArchive relativeDirectoryTokens : targets
795{
796	# AddDriversToFloppyBootArchive <relative directory> : <targets> ;
797
798	AddDriversToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
799		: $(relativeDirectoryTokens) : $(targets) ;
800}
801
802rule AddDriverRegistrationToFloppyBootArchive relativeDirectoryTokens : target
803	: links
804{
805	# AddDriverRegistrationToFloppyBootArchive <directory> : <link target>
806	#	: <link names> ] ;
807
808	AddDriverRegistrationToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
809		: $(relativeDirectoryTokens) : $(target) : $(links) ;
810}
811
812rule AddBootModuleSymlinksToFloppyBootArchive targets
813{
814	# AddBootModuleSymlinksToFloppyBootArchive <targets> ;
815
816	AddBootModuleSymlinksToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
817		: $(targets) ;
818}
819
820rule CreateFloppyBootArchiveMakeDirectoriesScript script
821{
822	CreateContainerMakeDirectoriesScript
823		$(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(script) ;
824}
825
826rule CreateFloppyBootArchiveCopyFilesScript script
827{
828	CreateContainerCopyFilesScript $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
829		: $(script) ;
830}
831
832rule BuildFloppyBootArchive archive : scripts
833{
834	# BuildHFloppyBootArchive <archive> : <scripts>  ;
835
836	local mainScript = build_tgz_archive ;
837	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
838
839	Depends $(archive) : $(mainScript) $(scripts) ;
840	BuildFloppyBootArchive1 $(archive) : $(mainScript) $(scripts) ;
841}
842
843actions BuildFloppyBootArchive1
844{
845	$(2[1]) $(1) $(2[2-])
846}
847
848# warning: that is quite x86 dependant...
849
850rule BuildFloppyBootImage image : zbeos : archive
851{
852	Depends $(image) : $(zbeos) ;
853	Depends $(image) : $(archive) ;
854	#MakeLocateDebug $(image) ;
855	BuildFloppyBootImage1 $(image) : $(zbeos) $(archive) ;
856}
857
858actions BuildFloppyBootImage1
859{
860	$(RM) $(<)
861	# make an empty image
862	dd if=/dev/zero of=$(<) bs=1k count=1440
863	# add zbeos
864	dd if=$(>[1]) of=$(<) conv=notrunc
865	# add the boot drivers tgz archive
866	# keep the offset in sync with
867	# src/system/boot/loader/file_systems/tarfs/tarfs.cpp:kFloppyArchiveOffset
868	dd if=$(>[2]) of=$(<) bs=192k seek=1 conv=notrunc
869}
870
871
872#pragma mark - CD Boot Image rules
873
874rule BuildCDBootImage image : bootfloppy : extrafiles
875{
876	Depends $(image) : $(bootfloppy) ;
877	Depends $(image) : $(extrafiles) ;
878	BOOTIMG on $(image) = $(bootfloppy) ;
879
880	BuildCDBootImage1 $(image) : $(bootfloppy) $(extrafiles) ;
881}
882
883actions BuildCDBootImage1
884{
885	$(RM) $(<)
886	mkisofs -b $(BOOTIMG) -r -J -V bootimg -o $(<) $(>[1]) $(>[2-])
887}
888
889
890