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