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