ImageRules revision 291785f88f68d0a3127d15b056236626a8ce8cb8
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	touch $(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
141
142rule IncludeAllTargetsInContainer container
143{
144	local filterVar
145		= [ on $(container) return $(HAIKU_INCLUDE_IN_CONTAINER_VAR) ] ;
146	if $(filterVar) {
147		return $($(filterVar)) ;
148	}
149
150	return ;
151}
152
153
154rule AddFilesToContainer container : directoryTokens : targets : destName
155{
156	# AddFilesToContainer <container> : <directoryTokens> : <targets>
157	#	[ : dest name ]
158	#
159	local directory = [ AddDirectoryToContainer $(container)
160		: $(directoryTokens) ] ;
161	local containerGrist = [ on $(container) return $(HAIKU_CONTAINER_GRIST) ] ;
162
163	# If the image shall only be updated, we filter out all targets not marked
164	# accordingly.
165	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ]
166		&& ! [ IncludeAllTargetsInContainer $(container) ] {
167		local filterVar
168			= [ on $(container) return $(HAIKU_INCLUDE_IN_CONTAINER_VAR) ] ;
169		if $(filterVar) {
170			targets = [ FilterContainerUpdateTargets $(targets)
171				: $(filterVar) ] ;
172		}
173	}
174
175	# We create a unique dummy target per target to install.
176	local installTargetsVar
177		= [ on $(container) return $(HAIKU_INSTALL_TARGETS_VAR) ] ;
178	local target ;
179	for target in $(targets) {
180		local name ;
181		if $(destName) {
182			name = $(destName) ;
183		} else {
184			name = $(target:G=:D=) ;
185		}
186
187		local destTarget = $(name:G=$(containerGrist)__$(directory:G=)) ;
188		TARGET on $(destTarget) = $(target) ;
189		INSTALL_DIR on $(destTarget) = $(directory) ;
190		$(installTargetsVar) on $(target) += $(destTarget) ;
191		TARGETS_TO_INSTALL on $(directory) += $(destTarget) ;
192	}
193}
194
195rule FFilesInContainerDirectory container : directoryTokens
196{
197	local containerGrist = [ on $(container) return $(HAIKU_CONTAINER_GRIST) ] ;
198	local directory = [ FDirName $(directoryTokens) ] ;
199	directory = $(directory:G=$(containerGrist)) ;
200
201	if [ on $(directory) return $(__is_on_image) ] {
202		on $(directory) return $(TARGETS_TO_INSTALL) ;
203	}
204
205	return ;
206}
207
208rule AddSymlinkToContainer container : directoryTokens : linkTarget : linkName
209{
210	# AddSymlinkToContainer <container> : <directory> : <link target>
211	#	[ : <link name> ] ;
212	#
213
214	# If the image shall only be updated, we don't add any symlinks.
215	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ]
216		&& ! [ IncludeAllTargetsInContainer $(container) ] {
217		return ;
218	}
219
220	local directory = [ AddDirectoryToContainer $(container)
221		: $(directoryTokens) ] ;
222
223	if ! $(linkName) {
224		local path = [ FReverse [ FSplitPath $(linkTarget) ] ] ;
225		linkName = $(path[1]) ;
226	}
227
228	local link = $(directory)/$(linkName) ;
229	SYMLINK_TARGET on $(link) = $(linkTarget) ;
230	SYMLINKS_TO_INSTALL on $(directory) += $(link) ;
231}
232
233rule FSymlinksInContainerDirectory container : directoryTokens
234{
235	local containerGrist = [ on $(container) return $(HAIKU_CONTAINER_GRIST) ] ;
236	local directory = [ FDirName $(directoryTokens) ] ;
237	directory = $(directory:G=$(containerGrist)) ;
238
239	if [ on $(directory) return $(__is_on_image) ] {
240		on $(directory) return $(SYMLINKS_TO_INSTALL) ;
241	}
242
243	return ;
244}
245
246rule CopyDirectoryToContainer container : directoryTokens : sourceDirectory
247	: targetDirectoryName : excludePatterns : alwaysUpdate
248{
249	# CopyDirectoryToContainer <container> : <directoryTokens>
250	#	: <sourceDirectory> : <targetDirectoryName> : <excludePatterns>
251	#	: <alwaysUpdate> ;
252	#
253
254	# If the image shall only be updated, we don't copy any directories
255	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ]
256			&& ! [ IncludeAllTargetsInContainer $(container) ]
257			&& ! $(alwaysUpdate) {
258		return ;
259	}
260
261	if ! $(targetDirectoryName) {
262		local path = [ FReverse [ FSplitPath $(sourceDirectory) ] ] ;
263		targetDirectoryName = $(path[1]) ;
264	}
265
266	local directory = [ AddDirectoryToContainer $(container)
267		: $(directoryTokens) $(targetDirectoryName) ] ;
268
269	local targetDir = $(directory)/-/$(sourceDirectory) ;
270	EXCLUDE_PATTERNS on $(targetDir) = $(excludePatterns) ;
271	SOURCE_DIRECTORY on $(targetDir) = $(sourceDirectory) ;
272	TARGET_DIRECTORY on $(targetDir) = $(directory) ;
273	DIRECTORIES_TO_INSTALL on $(directory) += $(targetDir) ;
274}
275
276rule UnzipArchiveToContainer container : directoryTokens : zipFile
277{
278	# UnzipArchiveToContainer <container> : <directory> : <zipFile> ] ;
279	#
280
281	local directory = [ AddDirectoryToContainer $(container)
282		: $(directoryTokens) ] ;
283
284	ZIP_FILES_TO_INSTALL on $(directory) += $(zipFile) ;
285}
286
287rule AddDriversToContainer container : relativeDirectoryTokens : targets
288{
289	# AddDriversToContainer <container> : <relative directory> : <targets> ;
290	#
291	local directoryTokens = system add-ons kernel drivers dev
292		$(relativeDirectoryTokens) ;
293
294	AddFilesToContainer $(container) : system add-ons kernel drivers bin
295		: $(targets) ;
296
297	# If the image shall only be updated, we don't add any symlinks.
298	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ]
299		&& ! [ IncludeAllTargetsInContainer $(container) ] {
300		return ;
301	}
302
303	# get the relative symlink path prefix
304	local linkPrefix = ;
305	for i in $(relativeDirectoryTokens) {
306		linkPrefix += .. ;
307	}
308	linkPrefix += .. bin ;
309
310	# add the symlinks
311	local name ;
312	for name in $(targets:BS) {
313		AddSymlinkToContainer $(container) : $(directoryTokens)
314			: [ FDirName $(linkPrefix) $(name) ] : $(name) ;
315	}
316}
317
318rule AddNewDriversToContainer container : relativeDirectoryTokens
319	: targets
320{
321	# AddNewDriversToContainer <container> : <directory> : <targets> ;
322	#
323	local directoryTokens = system add-ons kernel drivers
324		$(relativeDirectoryTokens) ;
325
326	AddFilesToContainer $(container) : $(directoryTokens)
327		: $(targets) ;
328}
329
330rule AddBootModuleSymlinksToContainer container : targets
331{
332	# AddBootModuleSymlinksToContainer <container> : <targets> ;
333	#
334
335	# If the image shall only be updated, we don't add any symlinks.
336	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ]
337		&& ! [ IncludeAllTargetsInContainer $(container) ] {
338		return ;
339	}
340
341	# add the symlinks
342	local installTargetsVar
343		= [ on $(container) return $(HAIKU_INSTALL_TARGETS_VAR) ] ;
344	local target ;
345	for target in $(targets) {
346		# Symlink to the first place where the target has been installed.
347		local destTarget = [ on $(target) return $($(installTargetsVar)[1]) ] ;
348		local installDir = [ on $(destTarget) return $(INSTALL_DIR) ] ;
349
350		if ! $(installDir) {
351			Echo "ERROR: AddBootModuleSymlinksToContainer: Can't create a "
352				"symlink to target" \"$(target)"\"." ;
353			Exit "ERROR: Add*ToContainer has not been invoked for it yet." ;
354		}
355
356		local name = $(target:BS) ;
357		local linkTarget = [ FDirName /boot $(installDir:G=) $(name) ] ;
358
359		AddSymlinkToContainer $(container) : system add-ons kernel boot
360			: $(linkTarget) : $(name) ;
361	}
362}
363
364
365rule CreateContainerMakeDirectoriesScript container : script
366{
367	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
368	Always $(script) ;
369
370	local initScript = [ InitScript $(script) ] ;
371
372	local scriptBody
373		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
374	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
375	Depends $(scriptBody) : $(initScript) ;
376	Depends $(script) : $(scriptBody) ;
377
378	# collect the directories to create
379	local dirsToCreate ;
380	local directories = [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] ;
381	local dir ;
382	for dir in $(directories) {
383		if ! [ on $(dir) return $(DONT_CREATE) ] {
384			dirsToCreate += $(dir) ;
385		}
386	}
387
388	# If the image shall only be updated, we don't create directories.
389	if $(dirsToCreate)
390		&& ( ! [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ]
391			|| [ IncludeAllTargetsInContainer $(container) ] ) {
392		Depends $(scriptBody) : $(dirsToCreate) ;
393		CreateContainerMakeDirectoriesScript1 $(scriptBody) : $(dirsToCreate) ;
394
395		local serializationDependency = $(scriptBody) ;
396			# Used to create a dependency chain between the dummy targets.
397			# This forces jam to build them one after the other, thus preventing
398			# concurrent writes to the script file when building with multiple
399			# jobs.
400
401		# For directories with attributes, we convert those the specified
402		# resource files to files with attributes and add commands to the script
403		# adding the attributes to the directories.
404		for dir in $(directories) {
405			local resourceFiles = [ on $(dir) return $(ATTRIBUTE_FILES) ] ;
406			if $(resourceFiles) {
407				local dirTokens = [ on $(dir) return $(DIRECTORY_TOKENS) ] ;
408
409				# translate resources file to file with attributes
410				local attributeFile = $(script)-attributes-$(dirTokens:J=-) ;
411				ResAttr $(attributeFile) : $(resourceFiles) ;
412
413				# use a unique dummy target for this file, on which we
414				# can define the TARGET_DIR variable
415				local dummyTarget = $(script)-attributes-dummy-$(dir:G=) ;
416				NotFile $(dummyTarget) ;
417				TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
418
419				Depends $(dummyTarget) : $(initScript) $(attributeFile)
420					$(serializationDependency) ;
421				Depends $(script) : $(dummyTarget) ;
422				serializationDependency = $(dummyTarget) ;
423
424				AppendToContainerMakeDirectoriesScriptAttributes $(dummyTarget)
425					: $(initScript) $(attributeFile) ;
426			}
427		}
428	}
429}
430
431actions piecemeal CreateContainerMakeDirectoriesScript1
432{
433	echo \$mkdir -p "\"\${tPrefix}$(2:G=)\"" >> $(1)
434}
435
436actions AppendToContainerMakeDirectoriesScriptAttributes
437{
438	echo \$copyAttrs "\"\${sPrefix}$(2[2])\"" \
439		"\"\${tPrefix}$(TARGET_DIR)\"" >> $(2[1])
440}
441
442rule CreateContainerCopyFilesScript container : script
443{
444	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
445	Always $(script) ;
446
447	local initScript = [ InitScript $(script) ] ;
448
449	local scriptBody
450		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
451	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
452	Depends $(scriptBody) : $(initScript) ;
453	Depends $(script) : $(scriptBody) ;
454
455	local serializationDependency = $(scriptBody) ;
456		# Used to create a dependency chain between the dummy targets.
457		# This forces jam to build them one after the other, thus preventing
458		# concurrent writes to the script file when building with multiple
459		# jobs.
460
461	local dir ;
462	for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] {
463		# filter the targets that shall be renamed; they have to be copied
464		# individually
465		local destTargets = [ on $(dir) return $(TARGETS_TO_INSTALL) ] ;
466		local remainingTargets ;
467		local destTarget ;
468		for destTarget in $(destTargets) {
469			local target = [ on $(destTarget) return $(TARGET) ] ;
470			local name = $(destTarget:BS) ;
471			if $(name) != $(target:BS) {
472				# use a unique dummy target for this file, on which we
473				# can define the TARGET_DIR variable
474				local dummyTarget = $(script)-dummy-$(dir:G=)-$(target) ;
475				NotFile $(dummyTarget) ;
476				TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
477				INSTALL_TARGET_NAME on $(dummyTarget) = $(name) ;
478
479				Depends $(dummyTarget) : $(initScript) $(target)
480					$(serializationDependency) ;
481				Depends $(script) : $(dummyTarget) ;
482				serializationDependency = $(dummyTarget) ;
483
484				AppendToContainerCopyFilesScriptSingleFile $(dummyTarget)
485					: $(initScript) $(target) ;
486			} else {
487				remainingTargets += $(target) ;
488			}
489		}
490		targets = $(remainingTargets) ;
491
492		if $(targets) {
493			# use a unique dummy target for this directory, on which we
494			# can define the TARGET_DIR variable
495			local dummyTarget = $(script)-dummy-$(dir:G=) ;
496			NotFile $(dummyTarget) ;
497			TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
498
499			Depends $(dummyTarget) : $(initScript) $(targets)
500				$(serializationDependency) ;
501			Depends $(script) : $(dummyTarget) ;
502			serializationDependency = $(dummyTarget) ;
503
504			OUTPUT_SCRIPT on $(dummyTarget) = $(initScript) ;
505			AppendToContainerCopyFilesScript $(dummyTarget) : $(targets) ;
506		}
507
508		local symlinks = [ on $(dir) return $(SYMLINKS_TO_INSTALL) ] ;
509		local symlink ;
510		for symlink in $(symlinks) {
511			NotFile $(symlink) ;
512
513			Depends $(script) : $(symlink) ;
514			Depends $(symlink) : $(initScript) $(serializationDependency) ;
515			serializationDependency = $(symlink) ;
516
517			AddSymlinkToContainerCopyFilesScript $(symlink) : $(initScript) ;
518		}
519
520		local targetDirs = [ on $(dir) return $(DIRECTORIES_TO_INSTALL) ] ;
521		local targetDir ;
522		for targetDir in $(targetDirs) {
523			NotFile $(targetDir) ;
524
525			Depends $(script) : $(targetDir) ;
526			Depends $(targetDir) : $(initScript) $(serializationDependency) ;
527			serializationDependency = $(targetDir) ;
528
529			AddDirectoryToContainerCopyFilesScript $(targetDir)
530				: $(initScript) ;
531		}
532	}
533}
534
535
536actions piecemeal AppendToContainerCopyFilesScript bind OUTPUT_SCRIPT
537{
538	echo \$cp "\"\${sPrefix}$(2)\"" "\"\${tPrefix}$(TARGET_DIR)\"" \
539		>> $(OUTPUT_SCRIPT)
540}
541
542
543actions AppendToContainerCopyFilesScriptSingleFile
544{
545	echo \$cp "\"\${sPrefix}$(2[2])\"" \
546		"\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" >> $(2[1])
547}
548
549
550actions AddSymlinkToContainerCopyFilesScript
551{
552	echo \$ln -sfn "\"$(SYMLINK_TARGET)\"" "\"\${tPrefix}$(1:G=)\"" >> $(2[1])
553}
554
555
556actions AddDirectoryToContainerCopyFilesScript
557{
558	echo \$cp -r $(EXCLUDE_PATTERNS) "\"\${sPrefix}$(SOURCE_DIRECTORY)/.\"" \
559		"\"\${tPrefix}$(TARGET_DIRECTORY:G=)\"" >> $(2[1])
560}
561
562
563rule CreateContainerUnzipFilesScript container : script
564{
565	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
566	Always $(script) ;
567
568	local initScript = [ InitScript $(script) ] ;
569
570	local scriptBody
571		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
572	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
573	Depends $(scriptBody) : $(initScript) ;
574	Depends $(script) : $(scriptBody) ;
575
576	local serializationDependency = $(scriptBody) ;
577		# Used to create a dependency chain between the dummy targets.
578		# This forces jam to build them one after the other, thus preventing
579		# concurrent writes to the script file when building with multiple
580		# jobs.
581
582	local dir ;
583	for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] {
584		local zipFiles = [ on $(dir) return $(ZIP_FILES_TO_INSTALL) ] ;
585		local zipFile ;
586		for zipFile in $(zipFiles) {
587			# use a unique dummy target for this file, on which we
588			# can define the TARGET_DIR variable
589			local dummyTarget = $(script)-dummy-$(dir:G=)-$(zipFile) ;
590			NotFile $(dummyTarget) ;
591			TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
592
593			Depends $(dummyTarget) : $(initScript) $(zipFile)
594				$(serializationDependency) ;
595			Depends $(script) : $(dummyTarget) ;
596			serializationDependency = $(dummyTarget) ;
597
598			AddUnzipFileToContainerUnzipFilesScript $(dummyTarget)
599				: $(initScript) $(zipFile) ;
600		}
601	}
602}
603
604actions AddUnzipFileToContainerUnzipFilesScript
605{
606	echo unzipFile "\"$(2[2])\"" "\"$(TARGET_DIR)\"" >> $(2[1])
607}
608
609
610#pragma mark - Haiku Image rules
611
612rule SetUpdateHaikuImageOnly flag
613{
614	HAIKU_CONTAINER_UPDATE_ONLY on $(HAIKU_IMAGE_CONTAINER_NAME) = $(flag) ;
615}
616
617rule IsUpdateHaikuImageOnly
618{
619	on $(HAIKU_IMAGE_CONTAINER_NAME) return $(HAIKU_CONTAINER_UPDATE_ONLY) ;
620}
621
622rule AddDirectoryToHaikuImage directoryTokens : attributeFiles
623{
624	# AddDirectoryToHaikuImage <directoryTokens>
625
626	local dir = [ AddDirectoryToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
627		: $(directoryTokens) ] ;
628
629	if $(attributeFiles) {
630		SEARCH on $(attributeFiles)
631			+= [ FDirName $(HAIKU_TOP) data image_directories ] ;
632		ATTRIBUTE_FILES on $(dir) += $(attributeFiles) ;
633	}
634
635	return $(dir) ;
636}
637
638rule AddFilesToHaikuImage directory : targets : destName
639{
640	# AddFilesToHaikuImage <directory> : <targets> [ : dest name ]
641
642	AddFilesToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directory)
643		: $(targets) : $(destName) ;
644}
645
646rule FFilesInHaikuImageDirectory directoryTokens
647{
648	return [ FFilesInContainerDirectory $(HAIKU_IMAGE_CONTAINER_NAME)
649		: $(directoryTokens) ] ;
650}
651
652rule AddSymlinkToHaikuImage directoryTokens : linkTarget : linkName
653{
654	# AddSymlinkToHaikuImage <directory> : <link target> [ : <link name> ] ;
655
656	AddSymlinkToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directoryTokens)
657		: $(linkTarget) : $(linkName) ;
658}
659
660rule FSymlinksInHaikuImageDirectory directoryTokens
661{
662	return [ FSymlinksInContainerDirectory $(HAIKU_IMAGE_CONTAINER_NAME)
663		: $(directoryTokens) ] ;
664}
665
666rule CopyDirectoryToHaikuImage directoryTokens : sourceDirectory
667	: targetDirectoryName : excludePatterns : alwaysUpdate
668{
669	CopyDirectoryToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directoryTokens)
670		: $(sourceDirectory) : $(targetDirectoryName) : $(excludePatterns)
671		: $(alwaysUpdate) ;
672}
673
674rule AddSourceDirectoryToHaikuImage dirTokens : alwaysUpdate
675{
676	# AddSourceDirectoryToHaikuImage <dirTokens> : <alwaysUpdate> ;
677
678	CopyDirectoryToHaikuImage home HaikuSources
679		: [ FDirName $(HAIKU_TOP) $(dirTokens) ]
680		: : -x .svn : $(alwaysUpdate) ;
681}
682
683rule AddHeaderDirectoryToHaikuImage dirTokens : dirName : alwaysUpdate
684{
685	# AddHeaderDirectoryToHaikuImage <dirTokens> : [ <dirName> ]
686	#	: <alwaysUpdate> ;
687
688	CopyDirectoryToHaikuImage develop headers
689		: [ FDirName $(HAIKU_TOP) headers $(dirTokens) ]
690		: $(dirName) : -x .svn : $(alwaysUpdate) ;
691}
692
693rule UnzipArchiveToHaikuImage dirTokens : zipFile : alwaysUpdate
694{
695	# UnzipArchiveToHaikuImage <dirTokens> : <zipFile> : <alwaysUpdate> ;
696
697	# If the image shall only be updated, we unzip only, if explicitely
698	# requested.
699	if ! [ IsUpdateHaikuImageOnly ] || $(alwaysUpdate) {
700		UnzipArchiveToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(dirTokens)
701			: $(zipFile) ;
702	}
703}
704
705rule AddDriversToHaikuImage relativeDirectoryTokens : targets
706{
707	# AddDriversToHaikuImage <relative directory> : <targets> ;
708
709	AddDriversToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
710		: $(relativeDirectoryTokens) : $(targets) ;
711}
712
713rule AddNewDriversToHaikuImage relativeDirectoryTokens : targets
714{
715	# AddNewDriversToHaikuImage <relative directory> : <targets> ;
716
717	AddNewDriversToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
718		: $(relativeDirectoryTokens) : $(targets) ;
719}
720
721rule AddBootModuleSymlinksToHaikuImage targets
722{
723	# AddBootModuleSymlinksToHaikuImage <targets> ;
724
725	AddBootModuleSymlinksToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
726		: $(targets) ;
727}
728
729rule AddOptionalHaikuImagePackages packages
730{
731	local package ;
732	for package in $(packages) {
733		if ! [ on $(package) return $(HAIKU_OPTIONAL_PACKAGE_ADDED) ] {
734			HAIKU_OPTIONAL_PACKAGE_ADDED on $(package) = 1 ;
735			HAIKU_ADDED_OPTIONAL_PACKAGES += $(package) ;
736		}
737	}
738}
739
740rule IsOptionalHaikuImagePackageAdded package
741{
742	if ! [ on $(package) return $(HAIKU_OPTIONAL_PACKAGE_EXISTS) ] {
743		HAIKU_OPTIONAL_PACKAGE_EXISTS on $(package) = 1 ;
744		HAIKU_EXISTING_OPTIONAL_PACKAGES += $(package) ;
745	}
746
747	if [ on $(package) return $(HAIKU_OPTIONAL_PACKAGE_ADDED) ] {
748		return 1 ;
749	}
750
751	return ;
752}
753
754rule OptionalPackageDependencies package : dependencies
755{
756	if [ IsOptionalHaikuImagePackageAdded $(package) ] {
757		AddOptionalHaikuImagePackages $(dependencies) ;
758	}
759}
760
761rule InstallOptionalHaikuImagePackage package : url : dirTokens : isCDPackage
762{
763	# download zip file
764	local zipFile = [ DownloadOptionalPackage $(package) : $(url) ] ;
765
766	if ( $(isCDPackage) = true || $(isCDPackage) = 1 ) && $(HAIKU_CD_NAME) {
767		# TODO: If HAIKU_CD_NAME is set, that doesn't mean we're building a CD
768		# image!
769		# copy onto image
770		AddFilesToHaikuImage _packages_ : $(zipFile) ;
771	} else {
772		# unzip onto image
773		UnzipArchiveToHaikuImage $(dirTokens) : $(zipFile) ;
774	}
775}
776
777rule AddEntryToHaikuImageUserGroupFile file : entry
778{
779	local allEntries = [ on $(file) return $(HAIKU_IMAGE_USER_GROUP_ENTRIES) ] ;
780
781	if $(allEntries) {
782		allEntries = $(allEntries)|$(entry) ;
783	} else {
784		allEntries = $(entry) ;
785
786		Always $(file) ;
787		MakeLocate $(file) : $(HAIKU_COMMON_PLATFORM_OBJECT_DIR) ;
788		BuildHaikuImageUserGroupFile $(file) ;
789		AddFilesToHaikuImage common etc : $(file) ;
790	}
791
792	HAIKU_IMAGE_USER_GROUP_ENTRIES on $(file) = $(allEntries) ;
793}
794
795actions BuildHaikuImageUserGroupFile
796{
797	echo "$(HAIKU_IMAGE_USER_GROUP_ENTRIES)" | tr '|' '\n' > $(1)
798}
799
800rule AddUserToHaikuImage user : uid : gid : home : shell : realName
801{
802	if ! $(user) || ! $(uid) || ! $(gid) || ! $(home) {
803		Exit "Invalid haiku user specification passed to AddUserToHaikuImage." ;
804	}
805
806	local entry
807		= $(user):x:$(uid):$(gid):$(realName:E=$(user)):$(home):$(shell:E="") ;
808
809	AddEntryToHaikuImageUserGroupFile <haiku-image>passwd : $(entry) ;
810}
811
812rule AddGroupToHaikuImage group : gid : members
813{
814	if ! $(group) || ! $(gid) {
815		Exit "Invalid haiku group specification passed to"
816			"AddGroupToHaikuImage." ;
817	}
818
819	local entry = $(group):x:$(gid):$(members:J=,:E) ;
820
821	AddEntryToHaikuImageUserGroupFile <haiku-image>group : $(entry) ;
822}
823
824rule AddOptionalPackageDescriptionToHaikuImage file : searchPath
825{
826	if $(searchPath) {
827		SEARCH on $(file) = [ FDirName $(searchPath) ] ;
828	}
829
830	HAIKU_IMAGE_OPTIONAL_PACKAGE_DESCRIPTIONS += $(file) ;
831}
832
833rule AddLicenseToHaikuImage file : name : searchPath
834{
835	if $(searchPath) {
836		SEARCH on $(file) = [ FDirName $(searchPath) ] ;
837	}
838
839	if $(name) && $(file:BS) = $(name) {
840		name = ;
841	}
842
843	AddFilesToHaikuImage system data licenses : $(file) : $(name) ;
844}
845
846
847rule CreateHaikuImageMakeDirectoriesScript script
848{
849	CreateContainerMakeDirectoriesScript $(HAIKU_IMAGE_CONTAINER_NAME)
850		: $(script) ;
851}
852
853rule CreateHaikuImageCopyFilesScript script
854{
855	CreateContainerCopyFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ;
856}
857
858rule CreateHaikuImageUnzipFilesScript script
859{
860	CreateContainerUnzipFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ;
861}
862
863rule BuildHaikuImage haikuImage : scripts : isImage : isVMwareImage
864{
865	# BuildHaikuImage <haiku image> : <scripts> : <is image> : <isVMwareImage> ;
866
867	if $(isImage) = 1 || $(isImage) = true {
868		IS_IMAGE on $(haikuImage) = 1 ;
869	} else {
870		IS_IMAGE on $(haikuImage) = "" ;
871	}
872
873	if $(isVMwareImage) = 1 || $(isVMwareImage) = true {
874		IS_VMWARE_IMAGE on $(haikuImage) = 1 ;
875	} else {
876		IS_VMWARE_IMAGE on $(haikuImage) = "" ;
877	}
878
879	local mainScript = build_haiku_image ;
880	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
881
882	Depends $(haikuImage) : $(mainScript) $(scripts) ;
883	BuildHaikuImage1 $(haikuImage) : $(mainScript) $(scripts) ;
884}
885
886actions BuildHaikuImage1
887{
888	export imagePath="$(1)"
889	export isImage="$(IS_IMAGE)"
890	export isVMwareImage="$(IS_VMWARE_IMAGE)"
891	$(2[1]) $(2[2-])
892}
893
894rule BuildVMWareImage vmwareImage : plainImage : imageSize
895{
896	# BuildVMWareImage <vmware image> : <plain image> : <image size in MB>
897
898	IMAGE_SIZE on $(vmwareImage) = $(imageSize) ;
899
900	Depends $(vmwareImage) : <build>vmdkheader $(plainImage) ;
901	BuildVMWareImage1 $(vmwareImage) : <build>vmdkheader $(plainImage) ;
902}
903
904actions BuildVMWareImage1
905{
906	$(RM) $(1)
907	$(2[1]) -h 64k -i$(IMAGE_SIZE)M $(1) &&
908	cat $(2[2]) >> $(1)
909}
910
911
912#pragma mark - Network Boot Archive rules
913
914rule AddDirectoryToNetBootArchive directoryTokens
915{
916	# AddDirectoryToNetBootArchive <directoryTokens>
917
918	return [ AddDirectoryToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
919		: $(directoryTokens) ] ;
920}
921
922rule AddFilesToNetBootArchive directory : targets : destName
923{
924	# AddFilesToNetBootArchive <directory> : <targets> [ : dest name ]
925
926	AddFilesToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(directory)
927		: $(targets) : $(destName) ;
928}
929
930rule AddSymlinkToNetBootArchive directoryTokens : linkTarget : linkName
931{
932	# AddSymlinkToNetBootArchive <directory> : <link target> [ : <link name> ] ;
933
934	AddSymlinkToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
935		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
936}
937
938rule AddDriversToNetBootArchive relativeDirectoryTokens : targets
939{
940	# AddDriversToNetBootArchive <relative directory> : <targets> ;
941
942	AddDriversToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
943		: $(relativeDirectoryTokens) : $(targets) ;
944}
945
946rule AddNewDriversToNetBootArchive relativeDirectoryTokens : targets
947{
948	# AddNewDriversToNetBootArchive <relative directory> : <targets> ;
949
950	AddNewDriversToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
951		: $(relativeDirectoryTokens) : $(targets) ;
952}
953
954rule AddDriverRegistrationToNetBootArchive relativeDirectoryTokens : target
955	: links
956{
957	# AddDriverRegistrationToNetBootArchive <directory> : <link target>
958	#	: <link names> ] ;
959
960	AddDriverRegistrationToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
961		: $(relativeDirectoryTokens) : $(target) : $(links) ;
962}
963
964rule AddBootModuleSymlinksToNetBootArchive targets
965{
966	# AddBootModuleSymlinksToNetBootArchive <targets> ;
967
968	AddBootModuleSymlinksToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
969		: $(targets) ;
970}
971
972rule CreateNetBootArchiveMakeDirectoriesScript script
973{
974	CreateContainerMakeDirectoriesScript
975		$(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(script) ;
976}
977
978rule CreateNetBootArchiveCopyFilesScript script
979{
980	CreateContainerCopyFilesScript $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
981		: $(script) ;
982}
983
984rule BuildNetBootArchive archive : scripts
985{
986	# BuildNetBootArchive <archive> : <scripts>  ;
987
988	local mainScript = build_tgz_archive ;
989	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
990
991	Depends $(archive) : $(mainScript) $(scripts) ;
992	BuildNetBootArchive1 $(archive) : $(mainScript) $(scripts) ;
993}
994
995actions BuildNetBootArchive1
996{
997	$(2[1]) $(1) $(2[2-])
998}
999
1000
1001#pragma mark - Alternative GCC Archive rules
1002
1003
1004rule AddDirectoryToAlternativeGCCArchive directoryTokens
1005{
1006	# AddDirectoryToAlternativeGCCArchive <directoryTokens>
1007
1008	return [ AddDirectoryToContainer
1009		$(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME) : $(directoryTokens) ] ;
1010}
1011
1012rule AddFilesToAlternativeGCCArchive directory : targets : destName
1013{
1014	# AddFilesToAlternativeGCCArchive <directory> : <targets> [ : dest name ]
1015
1016	AddFilesToContainer $(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME)
1017		: $(directory) : $(targets) : $(destName) ;
1018}
1019
1020rule AddSymlinkToAlternativeGCCArchive directoryTokens : linkTarget : linkName
1021{
1022	# AddSymlinkToAlternativeGCCArchive <directory> : <link target>
1023	#	[ : <link name> ] ;
1024
1025	AddSymlinkToContainer $(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME)
1026		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
1027}
1028
1029rule CopyDirectoryToAlternativeGCCArchive directoryTokens : sourceDirectory
1030	: targetDirectoryName : excludePatterns : alwaysUpdate
1031{
1032	CopyDirectoryToContainer $(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME)
1033		: $(directoryTokens) : $(sourceDirectory) : $(targetDirectoryName)
1034		: $(excludePatterns) : $(alwaysUpdate) ;
1035}
1036
1037rule CreateAlternativeGCCArchiveMakeDirectoriesScript script
1038{
1039	CreateContainerMakeDirectoriesScript
1040		$(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME) : $(script) ;
1041}
1042
1043rule CreateAlternativeGCCArchiveCopyFilesScript script
1044{
1045	CreateContainerCopyFilesScript
1046		$(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME) : $(script) ;
1047}
1048
1049rule BuildAlternativeGCCArchive archive : scripts
1050{
1051	# BuildAlternativeGCCArchive <archive> : <scripts>  ;
1052
1053	local mainScript = build_zip_archive ;
1054	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
1055
1056	Depends $(archive) : $(mainScript) $(scripts) ;
1057	BuildAlternativeGCCArchive1 $(archive) : $(mainScript) $(scripts) ;
1058}
1059
1060actions BuildAlternativeGCCArchive1
1061{
1062	$(2[1]) $(1) $(2[2-])
1063}
1064
1065
1066#pragma mark - Haiku Hybrid Image rules
1067
1068
1069rule AddFilesToHaikuHybridImage directory : targets : destName
1070	: useABISubDir
1071{
1072	# AddFilesToHaikuHybridImage <directory> : <targets> : <destName>
1073	#	: <useABISubDir>
1074	#
1075	# Convenience rule calling both AddFilesToHaikuImage and
1076	# AddFilesToAlternativeGCCArchive.
1077	#
1078	# <useABISubDir>
1079	#	if non-empty, specifies that an ABI subdirectory shall be appended to
1080	#	<directory> for the alternative GCC archive.
1081
1082	local alternativeSubDir ;
1083	if $(useABISubDir) {
1084		alternativeSubDir = gcc$(HAIKU_GCC_VERSION[1]) ;
1085	}
1086
1087	AddFilesToHaikuImage $(directory) : $(targets) : $(destName) ;
1088	AddFilesToAlternativeGCCArchive $(directory) $(alternativeSubDir)
1089		: $(targets) : $(destName) ;
1090}
1091
1092rule AddSymlinkToHaikuHybridImage directoryTokens : linkTarget : linkName
1093	: useSymlinkTargetABISubDir : useABISubDir
1094{
1095	# AddFilesToHaikuHybridImage <directoryTokens> : <linkTarget> : <linkName>
1096	#	[ : <useSymlinkTargetABISubDir> [ :  <useABISubDir> ] ]
1097	#
1098	# Convenience rule calling both AddSymlinkToHaikuImage and
1099	# AddSymlinkToAlternativeGCCArchive.
1100	#
1101	# <linkTarget>
1102	#	Can be a list of components that will be joined to path inserting
1103	#	"/"s inbetween.
1104	# <useSymlinkTargetABISubDir>
1105	#	If non-empty, specifies that an ABI subdirectory shall be inserted
1106	#	into <linkTarget> (between the first and second component) for the
1107	#	alternative GCC archive.
1108	# <useABISubDir>
1109	#	If non-empty, specifies that an ABI subdirectory part shall be appended
1110	#	to the directory tokens for the alternative GCC archive.
1111
1112	local alternativeDirTokens = $(directoryTokens) ;
1113	if $(useABISubDir) {
1114		alternativeDirTokens += gcc$(HAIKU_GCC_VERSION[1]) ;
1115	}
1116
1117	local alternativeLinkTarget = $(linkTarget) ;
1118	if $(useSymlinkTargetABISubDir) {
1119		alternativeLinkTarget = $(linkTarget[1]) gcc$(HAIKU_GCC_VERSION[1])
1120			$(linkTarget[2-]) ;
1121	}
1122	linkTarget = $(linkTarget:J=/) ;
1123	alternativeLinkTarget = $(alternativeLinkTarget:J=/) ;
1124
1125	AddSymlinkToHaikuImage $(directoryTokens) : $(linkTarget) : $(linkName) ;
1126	AddSymlinkToAlternativeGCCArchive $(alternativeDirTokens)
1127		: $(alternativeLinkTarget) : $(linkName) ;
1128}
1129
1130rule AddLibrariesToHaikuHybridImage directory : libs
1131{
1132	# AddLibraryToHaikuHybridImage <directory> : <libs>
1133	#
1134	# Installs libraries with the appropriate links onto the image.
1135	#
1136
1137	local lib ;
1138	for lib in $(libs) {
1139		local apiVersion = [ on $(lib) return $(HAIKU_LIB_API_VERSION) ] ;
1140		if $(apiVersion) {
1141			local apiLib = $(lib).$(apiVersion) ;
1142			AddFilesToHaikuHybridImage $(directory)
1143				: $(lib) : $(apiLib) : true ;
1144			AddSymlinkToHaikuHybridImage $(directory)
1145				: $(apiLib) : $(lib) : : true ;
1146		} else {
1147			AddFilesToHaikuHybridImage $(directory) : $(lib) : : true ;
1148		}
1149	}
1150}
1151
1152
1153#pragma mark - Floppy Boot Archive rules
1154
1155
1156rule AddDirectoryToFloppyBootArchive directoryTokens
1157{
1158	# AddDirectoryToFloppyBootArchive <directoryTokens>
1159
1160	return [ AddDirectoryToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1161		: $(directoryTokens) ] ;
1162}
1163
1164rule AddFilesToFloppyBootArchive directory : targets : destName
1165{
1166	# AddFilesToFloppyBootArchive <directory> : <targets> [ : dest name ]
1167
1168	AddFilesToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(directory)
1169		: $(targets) : $(destName) ;
1170}
1171
1172rule AddSymlinkToFloppyBootArchive directoryTokens : linkTarget : linkName
1173{
1174	# AddSymlinkToFloppyBootArchive <directory> : <link target> [ : <link name> ] ;
1175
1176	AddSymlinkToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1177		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
1178}
1179
1180rule AddDriversToFloppyBootArchive relativeDirectoryTokens : targets
1181{
1182	# AddDriversToFloppyBootArchive <relative directory> : <targets> ;
1183
1184	AddDriversToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1185		: $(relativeDirectoryTokens) : $(targets) ;
1186}
1187
1188rule AddNewDriversToFloppyBootArchive relativeDirectoryTokens : targets
1189{
1190	# AddNewDriversToFloppyBootArchive <relative directory> : <targets> ;
1191
1192	AddNewDriversToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1193		: $(relativeDirectoryTokens) : $(targets) ;
1194}
1195
1196rule AddDriverRegistrationToFloppyBootArchive relativeDirectoryTokens : target
1197	: links
1198{
1199	# AddDriverRegistrationToFloppyBootArchive <directory> : <link target>
1200	#	: <link names> ] ;
1201
1202	AddDriverRegistrationToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1203		: $(relativeDirectoryTokens) : $(target) : $(links) ;
1204}
1205
1206rule AddBootModuleSymlinksToFloppyBootArchive targets
1207{
1208	# AddBootModuleSymlinksToFloppyBootArchive <targets> ;
1209
1210	AddBootModuleSymlinksToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1211		: $(targets) ;
1212}
1213
1214rule CreateFloppyBootArchiveMakeDirectoriesScript script
1215{
1216	CreateContainerMakeDirectoriesScript
1217		$(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(script) ;
1218}
1219
1220rule CreateFloppyBootArchiveCopyFilesScript script
1221{
1222	CreateContainerCopyFilesScript $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1223		: $(script) ;
1224}
1225
1226rule BuildFloppyBootArchive archive : scripts
1227{
1228	# BuildHFloppyBootArchive <archive> : <scripts>  ;
1229
1230	local mainScript = build_tgz_archive ;
1231	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
1232
1233	Depends $(archive) : $(mainScript) $(scripts) ;
1234	BuildFloppyBootArchive1 $(archive) : $(mainScript) $(scripts) ;
1235}
1236
1237actions BuildFloppyBootArchive1
1238{
1239	$(2[1]) $(1) $(2[2-])
1240}
1241
1242# warning: that is quite x86 dependant...
1243
1244rule BuildFloppyBootImage image : haikuLoader : archive
1245{
1246	Depends $(image) : $(haikuLoader) ;
1247	Depends $(image) : $(archive) ;
1248	#MakeLocateDebug $(image) ;
1249	FLOPPY_IMAGE_SIZE on $(image) = $(HAIKU_BOOT_FLOPPY_IMAGE_SIZE) ;
1250	ARCHIVE_IMAGE_OFFSET on $(image) = $(HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET) ;
1251	BuildFloppyBootImage1 $(image) : $(haikuLoader) $(archive) ;
1252	if $(HAIKU_BOOT_PLATFORM) = atari_m68k {
1253		Depends $(image) : <build>fixup_tos_boot_checksum ;
1254		BuildFloppyBootImageFixupM68K $(image) : <build>fixup_tos_boot_checksum ;
1255	}
1256	if $(HAIKU_BOOT_PLATFORM) = amiga_m68k {
1257		Depends $(image) : <build>fixup_amiga_boot_checksum ;
1258		BuildFloppyBootImageFixupM68K $(image) : <build>fixup_amiga_boot_checksum ;
1259	}
1260}
1261
1262actions BuildFloppyBootImage1
1263{
1264	$(RM) $(<)
1265	# make an empty image
1266	dd if=/dev/zero of=$(<) bs=1k count=$(FLOPPY_IMAGE_SIZE)
1267	# add haiku_loader
1268	dd if=$(>[1]) of=$(<) conv=notrunc
1269	# add the boot drivers tgz archive
1270	dd if=$(>[2]) of=$(<) bs=$(ARCHIVE_IMAGE_OFFSET)k seek=1 conv=notrunc
1271}
1272
1273actions BuildFloppyBootImageFixupM68K
1274{
1275	# fixup the boot sector checksum
1276	$(>[1]) $(<)
1277}
1278
1279#pragma mark - CD Boot Image rules
1280
1281rule BuildCDBootImage image : bootfloppy : extrafiles
1282{
1283	Depends $(image) : $(bootfloppy) ;
1284	Depends $(image) : $(extrafiles) ;
1285	BOOTIMG on $(image) = $(bootfloppy) ;
1286
1287	BuildCDBootImage1 $(image) : $(bootfloppy) $(extrafiles) ;
1288}
1289
1290actions BuildCDBootImage1
1291{
1292	$(RM) $(<)
1293	mkisofs -b $(BOOTIMG) -r -J -V bootimg -o $(<) $(>[1]) $(>[2-])
1294}
1295
1296
1297#pragma mark - CD Boot PPC Image rules
1298
1299rule BuildCDBootPPCImage image : hfsmaps : elfloader : coffloader : chrpscript : extrafiles
1300{
1301	Depends $(image) : $(elfloader) ;
1302	Depends $(image) : $(coffloader) ;
1303	Depends $(image) : $(chrpscript) ;
1304	Depends $(image) : $(extrafiles) ;
1305	Depends $(image) : $(hfsmaps) ;
1306	MAPS on $(image) = $(hfsmaps) ;
1307
1308	BuildCDBootPPCImage1 $(image) : $(elfloader) $(coffloader) $(chrpscript) $(extrafiles) ;
1309}
1310
1311actions BuildCDBootPPCImage1 bind MAPS
1312{
1313	$(RM) $(<)
1314	mkdir -p $(HAIKU_OUTPUT_DIR)/cd/ppc
1315	cp $(>) $(HAIKU_OUTPUT_DIR)/cd/ppc/
1316	cp $(>[3]) $(HAIKU_OUTPUT_DIR)/cd/ppc/bootinfo.txt
1317	cp $(>[1]) $(HAIKU_OUTPUT_DIR)/cd/ofwboot.elf
1318	cp $(>[2]) $(HAIKU_OUTPUT_DIR)/cd/ofwboot.xcf
1319	#mkisofs -r -U -chrp-boot -V bootimg -o $(<) $(>[1]) $(>[2-])
1320	#mkisofs -hfs -r -U -chrp-boot -part -map $(MAPS) -no-desktop -hfs-volid bootimg -V bootimg -prep-boot $(>[1]:D=) -o $(<) $(>[1]) $(>[2-])
1321	#mkisofs -v -hfs -part -map $(MAPS) -no-desktop -hfs-volid bootimg -V bootimg -hfs-bless $(HAIKU_OUTPUT_DIR)/cd/ppc -r -o $(<) $(>[1]) $(>[2-]) $(HAIKU_OUTPUT_DIR)/cd
1322	#mkisofs -r -U -chrp-boot -V bootimg -prep-boot $(>[1]:D=) -o $(<) $(>[1]) $(>[2-])
1323	#mkisofs -r -U -V bootimg -prep-boot $(>[1]:D=) -o $(<) $(>[1]) $(>[2-])
1324	# $(HAIKU_OUTPUT_DIR)/cd
1325	# -hfs -hfs-bless .
1326	mkisofs -v -hfs -part -map $(MAPS) -no-desktop -hfs-volid bootimg -V bootimg -hfs-bless $(HAIKU_OUTPUT_DIR)/cd/ppc -prep-boot ppc/$(>[2]:D=) -r -o $(<) $(HAIKU_OUTPUT_DIR)/cd
1327	#$(RM) -R $(HAIKU_OUTPUT_DIR)/cd
1328}
1329
1330
1331