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