xref: /haiku/build/jam/ImageRules (revision 125183f9e5c136781f71c879faaeab43fdc3ea7b)
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 IsOptionalHaikuImagePackageAdded package
789{
790	if ! [ on $(package) return $(HAIKU_OPTIONAL_PACKAGE_EXISTS) ] {
791		HAIKU_OPTIONAL_PACKAGE_EXISTS on $(package) = 1 ;
792		HAIKU_EXISTING_OPTIONAL_PACKAGES += $(package) ;
793	}
794
795	if [ on $(package) return $(HAIKU_OPTIONAL_PACKAGE_ADDED) ] {
796		return 1 ;
797	}
798
799	return ;
800}
801
802rule OptionalPackageDependencies package : dependencies
803{
804	HAIKU_OPTIONAL_PACKAGE_DEPENDENCIES on $(package) = $(dependencies) ;
805	if [ on $(package) return $(HAIKU_OPTIONAL_PACKAGE_ADDED) ] {
806		AddOptionalHaikuImagePackages $(dependencies) ;
807	}
808}
809
810rule InstallSourceArchive file : url
811{
812	if $(HAIKU_INCLUDE_SOURCES) = 1 {
813		# download archive file
814		local archiveFile = [ DownloadFile $(file) : $(url) ] ;
815
816		# copy directly into image
817		AddFilesToHaikuImage _sources_ : $(archiveFile) ;
818	}
819}
820
821rule InstallOptionalHaikuImagePackage package : url : dirTokens : isCDPackage
822	: isGCCAgnostic
823{
824	# download archive file
825	local archiveFile = [ DownloadFile $(package) : $(url) ] ;
826
827	if ( $(isCDPackage) = true || $(isCDPackage) = 1 ) && $(HAIKU_CD_NAME) {
828		# TODO: If HAIKU_CD_NAME is set, that doesn't mean we're building a CD
829		# image!
830		# copy onto image
831		AddFilesToHaikuImage _packages_ : $(archiveFile) ;
832		#if $(isGCCAgnostic) {
833		# 	TODO: The archives would need to be marked whether they are
834		#	gcc-agnostic (e.g. via attribute). Installer's UnzipEngine would
835		#	also need to be updated, to read this attribute and create the
836		#	alt gcc dir and symlinks as needed.
837		#}
838	} else {
839		# extract onto image
840		ExtractArchiveToHaikuImage $(dirTokens) : $(archiveFile) : :
841			: $(isGCCAgnostic) ;
842	}
843}
844
845rule AddEntryToHaikuImageUserGroupFile file : entry
846{
847	local allEntries = [ on $(file) return $(HAIKU_IMAGE_USER_GROUP_ENTRIES) ] ;
848
849	if $(allEntries) {
850		allEntries = $(allEntries)|$(entry) ;
851	} else {
852		allEntries = $(entry) ;
853
854		Always $(file) ;
855		MakeLocate $(file) : $(HAIKU_COMMON_PLATFORM_OBJECT_DIR) ;
856		BuildHaikuImageUserGroupFile $(file) ;
857		AddFilesToHaikuImage common etc : $(file) ;
858	}
859
860	HAIKU_IMAGE_USER_GROUP_ENTRIES on $(file) = $(allEntries) ;
861}
862
863actions BuildHaikuImageUserGroupFile
864{
865	echo "$(HAIKU_IMAGE_USER_GROUP_ENTRIES)" | tr '|' '\n' > $(1)
866}
867
868rule AddUserToHaikuImage user : uid : gid : home : shell : realName
869{
870	if ! $(user) || ! $(uid) || ! $(gid) || ! $(home) {
871		Exit "Invalid haiku user specification passed to AddUserToHaikuImage." ;
872	}
873
874	local entry
875		= $(user):x:$(uid):$(gid):$(realName:E=$(user)):$(home):$(shell:E="") ;
876
877	AddEntryToHaikuImageUserGroupFile <haiku-image>passwd : $(entry) ;
878}
879
880rule AddGroupToHaikuImage group : gid : members
881{
882	if ! $(group) || ! $(gid) {
883		Exit "Invalid haiku group specification passed to"
884			"AddGroupToHaikuImage." ;
885	}
886
887	local entry = $(group):x:$(gid):$(members:J=,:E) ;
888
889	AddEntryToHaikuImageUserGroupFile <haiku-image>group : $(entry) ;
890}
891
892rule AddEntryToHaikuImageExpanderRuleFile file : entry
893{
894	local allEntries
895		= [ on $(file) return $(HAIKU_IMAGE_EXPANDER_RULES_ENTRIES) ] ;
896
897	if $(allEntries) {
898		allEntries = $(allEntries)!$(entry) ;
899	} else {
900		allEntries = $(entry) ;
901
902		Always $(file) ;
903		MakeLocate $(file) : $(HAIKU_COMMON_PLATFORM_OBJECT_DIR) ;
904		BuildHaikuImageExpanderRules $(file) ;
905		AddFilesToHaikuImage common data : $(file) ;
906	}
907
908	HAIKU_IMAGE_EXPANDER_RULES_ENTRIES on $(file) = $(allEntries) ;
909}
910
911actions BuildHaikuImageExpanderRules
912{
913	echo -e "$(HAIKU_IMAGE_EXPANDER_RULES_ENTRIES)" | tr '!' '\n' > $(1)
914}
915
916rule AddExpanderRuleToHaikuImage mimetype : extension : list : extract
917{
918	#AddExpanderRuleToHaikuImage <mimetype> : <extension> : <list> : <extract>
919
920	if ! $(mimetype) || ! $(extension) || ! $(list) || ! $(extract) {
921		Exit "Invalid expander rule specification passed to AddExpanderRule." ;
922	}
923
924	local entry = "\\\"$(mimetype)\\\"\\\t$(extension)\\\t\\\"$(list)\\\"\\\t\\\"$(extract)\\\"" ;
925	AddEntryToHaikuImageExpanderRuleFile <haiku-image>expander.rules
926		: $(entry) ;
927}
928
929rule AddOptionalPackageDescriptionToHaikuImage file : searchPath
930{
931	if $(searchPath) {
932		SEARCH on $(file) = [ FDirName $(searchPath) ] ;
933	}
934
935	HAIKU_IMAGE_OPTIONAL_PACKAGE_DESCRIPTIONS += $(file) ;
936}
937
938rule AddLicenseToHaikuImage file : name : searchPath
939{
940	if $(searchPath) {
941		SEARCH on $(file) = [ FDirName $(searchPath) ] ;
942	}
943
944	if $(name) && $(file:BS) = $(name) {
945		name = ;
946	}
947
948	AddFilesToHaikuImage system data licenses : $(file) : $(name) ;
949}
950
951
952rule CreateHaikuImageMakeDirectoriesScript script
953{
954	CreateContainerMakeDirectoriesScript $(HAIKU_IMAGE_CONTAINER_NAME)
955		: $(script) ;
956}
957
958rule CreateHaikuImageCopyFilesScript script
959{
960	CreateContainerCopyFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ;
961}
962
963rule CreateHaikuImageExtractFilesScript script
964{
965	CreateContainerExtractFilesScript $(HAIKU_IMAGE_CONTAINER_NAME)
966		: $(script) ;
967}
968
969rule BuildHaikuImage haikuImage : scripts : isImage : isVMwareImage
970{
971	# BuildHaikuImage <haiku image> : <scripts> : <is image> : <isVMwareImage> ;
972
973	if $(isImage) = 1 || $(isImage) = true {
974		IS_IMAGE on $(haikuImage) = 1 ;
975	} else {
976		IS_IMAGE on $(haikuImage) = "" ;
977	}
978
979	if $(isVMwareImage) = 1 || $(isVMwareImage) = true {
980		IS_VMWARE_IMAGE on $(haikuImage) = 1 ;
981	} else {
982		IS_VMWARE_IMAGE on $(haikuImage) = "" ;
983	}
984
985	local mainScript = build_haiku_image ;
986	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
987
988	Depends $(haikuImage) : $(mainScript) $(scripts) ;
989	BuildHaikuImage1 $(haikuImage) : $(mainScript) $(scripts) ;
990}
991
992actions BuildHaikuImage1
993{
994	export imagePath="$(1)"
995	export isImage="$(IS_IMAGE)"
996	export isVMwareImage="$(IS_VMWARE_IMAGE)"
997	$(2[1]) $(2[2-])
998}
999
1000rule BuildVMWareImage vmwareImage : plainImage : imageSize
1001{
1002	# BuildVMWareImage <vmware image> : <plain image> : <image size in MB>
1003
1004	IMAGE_SIZE on $(vmwareImage) = $(imageSize) ;
1005
1006	Depends $(vmwareImage) : <build>vmdkheader $(plainImage) ;
1007	BuildVMWareImage1 $(vmwareImage) : <build>vmdkheader $(plainImage) ;
1008}
1009
1010actions BuildVMWareImage1
1011{
1012	$(RM) $(1)
1013	$(2[1]) -h 64k -i$(IMAGE_SIZE)M $(1) &&
1014	cat $(2[2]) >> $(1)
1015}
1016
1017
1018#pragma mark - Network Boot Archive rules
1019
1020rule AddDirectoryToNetBootArchive directoryTokens
1021{
1022	# AddDirectoryToNetBootArchive <directoryTokens>
1023
1024	return [ AddDirectoryToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
1025		: $(directoryTokens) ] ;
1026}
1027
1028rule AddFilesToNetBootArchive directory : targets : destName
1029{
1030	# AddFilesToNetBootArchive <directory> : <targets> [ : dest name ]
1031
1032	AddFilesToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(directory)
1033		: $(targets) : $(destName) ;
1034}
1035
1036rule AddSymlinkToNetBootArchive directoryTokens : linkTarget : linkName
1037{
1038	# AddSymlinkToNetBootArchive <directory> : <link target> [ : <link name> ] ;
1039
1040	AddSymlinkToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
1041		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
1042}
1043
1044rule AddDriversToNetBootArchive relativeDirectoryTokens : targets
1045{
1046	# AddDriversToNetBootArchive <relative directory> : <targets> ;
1047
1048	AddDriversToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
1049		: $(relativeDirectoryTokens) : $(targets) ;
1050}
1051
1052rule AddNewDriversToNetBootArchive relativeDirectoryTokens : targets
1053{
1054	# AddNewDriversToNetBootArchive <relative directory> : <targets> ;
1055
1056	AddNewDriversToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
1057		: $(relativeDirectoryTokens) : $(targets) ;
1058}
1059
1060rule AddDriverRegistrationToNetBootArchive relativeDirectoryTokens : target
1061	: links
1062{
1063	# AddDriverRegistrationToNetBootArchive <directory> : <link target>
1064	#	: <link names> ] ;
1065
1066	AddDriverRegistrationToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
1067		: $(relativeDirectoryTokens) : $(target) : $(links) ;
1068}
1069
1070rule AddBootModuleSymlinksToNetBootArchive targets
1071{
1072	# AddBootModuleSymlinksToNetBootArchive <targets> ;
1073
1074	AddBootModuleSymlinksToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
1075		: $(targets) ;
1076}
1077
1078rule CreateNetBootArchiveMakeDirectoriesScript script
1079{
1080	CreateContainerMakeDirectoriesScript
1081		$(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(script) ;
1082}
1083
1084rule CreateNetBootArchiveCopyFilesScript script
1085{
1086	CreateContainerCopyFilesScript $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
1087		: $(script) ;
1088}
1089
1090rule BuildNetBootArchive archive : scripts
1091{
1092	# BuildNetBootArchive <archive> : <scripts>  ;
1093
1094	local mainScript = build_archive ;
1095	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
1096
1097	Depends $(archive) : $(mainScript) $(scripts) ;
1098	BuildNetBootArchive1 $(archive) : $(mainScript) $(scripts) ;
1099}
1100
1101actions BuildNetBootArchive1
1102{
1103	$(2[1]) $(1) $(2[2-])
1104}
1105
1106
1107#pragma mark - Alternative GCC Archive rules
1108
1109
1110rule AddDirectoryToAlternativeGCCArchive directoryTokens
1111{
1112	# AddDirectoryToAlternativeGCCArchive <directoryTokens>
1113
1114	return [ AddDirectoryToContainer
1115		$(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME) : $(directoryTokens) ] ;
1116}
1117
1118rule AddFilesToAlternativeGCCArchive directory : targets : destName
1119{
1120	# AddFilesToAlternativeGCCArchive <directory> : <targets> [ : dest name ]
1121
1122	AddFilesToContainer $(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME)
1123		: $(directory) : $(targets) : $(destName) ;
1124}
1125
1126rule AddSymlinkToAlternativeGCCArchive directoryTokens : linkTarget : linkName
1127{
1128	# AddSymlinkToAlternativeGCCArchive <directory> : <link target>
1129	#	[ : <link name> ] ;
1130
1131	AddSymlinkToContainer $(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME)
1132		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
1133}
1134
1135rule CopyDirectoryToAlternativeGCCArchive directoryTokens : sourceDirectory
1136	: targetDirectoryName : excludePatterns : alwaysUpdate
1137{
1138	CopyDirectoryToContainer $(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME)
1139		: $(directoryTokens) : $(sourceDirectory) : $(targetDirectoryName)
1140		: $(excludePatterns) : $(alwaysUpdate) ;
1141}
1142
1143rule CreateAlternativeGCCArchiveMakeDirectoriesScript script
1144{
1145	CreateContainerMakeDirectoriesScript
1146		$(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME) : $(script) ;
1147}
1148
1149rule CreateAlternativeGCCArchiveCopyFilesScript script
1150{
1151	CreateContainerCopyFilesScript
1152		$(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME) : $(script) ;
1153}
1154
1155rule BuildAlternativeGCCArchive archive : scripts
1156{
1157	# BuildAlternativeGCCArchive <archive> : <scripts>  ;
1158
1159	local mainScript = build_archive ;
1160	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
1161
1162	Depends $(archive) : $(mainScript) $(scripts) ;
1163	BuildAlternativeGCCArchive1 $(archive) : $(mainScript) $(scripts) ;
1164}
1165
1166actions BuildAlternativeGCCArchive1
1167{
1168	$(2[1]) $(1) $(2[2-])
1169}
1170
1171
1172#pragma mark - Haiku Hybrid Image rules
1173
1174
1175rule AddFilesToHaikuHybridImage directory : targets : destName
1176	: useABISubDir
1177{
1178	# AddFilesToHaikuHybridImage <directory> : <targets> : <destName>
1179	#	: <useABISubDir>
1180	#
1181	# Convenience rule calling both AddFilesToHaikuImage and
1182	# AddFilesToAlternativeGCCArchive.
1183	#
1184	# <useABISubDir>
1185	#	if non-empty, specifies that an ABI subdirectory shall be appended to
1186	#	<directory> for the alternative GCC archive.
1187
1188	local alternativeSubDir ;
1189	if $(useABISubDir) {
1190		alternativeSubDir = gcc$(HAIKU_GCC_VERSION[1]) ;
1191	}
1192
1193	AddFilesToHaikuImage $(directory) : $(targets) : $(destName) ;
1194	AddFilesToAlternativeGCCArchive $(directory) $(alternativeSubDir)
1195		: $(targets) : $(destName) ;
1196}
1197
1198rule AddSymlinkToHaikuHybridImage directoryTokens : linkTarget : linkName
1199	: useSymlinkTargetABISubDir : useABISubDir
1200{
1201	# AddSymlinkToHaikuHybridImage <directoryTokens> : <linkTarget> : <linkName>
1202	#	[ : <useSymlinkTargetABISubDir> [ :  <useABISubDir> ] ]
1203	#
1204	# Convenience rule calling both AddSymlinkToHaikuImage and
1205	# AddSymlinkToAlternativeGCCArchive.
1206	#
1207	# <linkTarget>
1208	#	Can be a list of components that will be joined to path inserting
1209	#	"/"s inbetween.
1210	# <useSymlinkTargetABISubDir>
1211	#	If non-empty, specifies that an ABI subdirectory shall be inserted
1212	#	into <linkTarget> (between the first and second component) for the
1213	#	alternative GCC archive.
1214	# <useABISubDir>
1215	#	If non-empty, specifies that an ABI subdirectory part shall be appended
1216	#	to the directory tokens for the alternative GCC archive.
1217
1218	local alternativeDirTokens = $(directoryTokens) ;
1219	if $(useABISubDir) {
1220		alternativeDirTokens += gcc$(HAIKU_GCC_VERSION[1]) ;
1221	}
1222
1223	local alternativeLinkTarget = $(linkTarget) ;
1224	if $(useSymlinkTargetABISubDir) {
1225		alternativeLinkTarget = $(linkTarget[1]) gcc$(HAIKU_GCC_VERSION[1])
1226			$(linkTarget[2-]) ;
1227	}
1228	linkTarget = $(linkTarget:J=/) ;
1229	alternativeLinkTarget = $(alternativeLinkTarget:J=/) ;
1230
1231	AddSymlinkToHaikuImage $(directoryTokens) : $(linkTarget) : $(linkName) ;
1232	AddSymlinkToAlternativeGCCArchive $(alternativeDirTokens)
1233		: $(alternativeLinkTarget) : $(linkName) ;
1234}
1235
1236rule AddLibrariesToHaikuHybridImage directory : libs
1237{
1238	# AddLibraryToHaikuHybridImage <directory> : <libs>
1239	#
1240	# Installs libraries with the appropriate links onto the image.
1241	#
1242
1243	local lib ;
1244	for lib in $(libs) {
1245		local abiVersion = [ on $(lib) return $(HAIKU_LIB_ABI_VERSION) ] ;
1246		if $(abiVersion) {
1247			local abiVersionedLib = $(lib).$(abiVersion) ;
1248			AddFilesToHaikuHybridImage $(directory)
1249				: $(lib) : $(abiVersionedLib) : true ;
1250			AddSymlinkToHaikuHybridImage $(directory)
1251				: $(abiVersionedLib) : $(lib) : : true ;
1252		} else {
1253			AddFilesToHaikuHybridImage $(directory) : $(lib) : : true ;
1254		}
1255	}
1256}
1257
1258
1259#pragma mark - Floppy Boot Archive rules
1260
1261
1262rule AddDirectoryToFloppyBootArchive directoryTokens
1263{
1264	# AddDirectoryToFloppyBootArchive <directoryTokens>
1265
1266	return [ AddDirectoryToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1267		: $(directoryTokens) ] ;
1268}
1269
1270rule AddFilesToFloppyBootArchive directory : targets : destName
1271{
1272	# AddFilesToFloppyBootArchive <directory> : <targets> [ : dest name ]
1273
1274	AddFilesToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(directory)
1275		: $(targets) : $(destName) ;
1276}
1277
1278rule AddSymlinkToFloppyBootArchive directoryTokens : linkTarget : linkName
1279{
1280	# AddSymlinkToFloppyBootArchive <directory> : <link target>
1281	#	[ : <link name> ] ;
1282
1283	AddSymlinkToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1284		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
1285}
1286
1287rule AddDriversToFloppyBootArchive relativeDirectoryTokens : targets
1288{
1289	# AddDriversToFloppyBootArchive <relative directory> : <targets> ;
1290
1291	AddDriversToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1292		: $(relativeDirectoryTokens) : $(targets) ;
1293}
1294
1295rule AddNewDriversToFloppyBootArchive relativeDirectoryTokens : targets
1296{
1297	# AddNewDriversToFloppyBootArchive <relative directory> : <targets> ;
1298
1299	AddNewDriversToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1300		: $(relativeDirectoryTokens) : $(targets) ;
1301}
1302
1303rule AddDriverRegistrationToFloppyBootArchive relativeDirectoryTokens : target
1304	: links
1305{
1306	# AddDriverRegistrationToFloppyBootArchive <directory> : <link target>
1307	#	: <link names> ] ;
1308
1309	AddDriverRegistrationToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1310		: $(relativeDirectoryTokens) : $(target) : $(links) ;
1311}
1312
1313rule AddBootModuleSymlinksToFloppyBootArchive targets
1314{
1315	# AddBootModuleSymlinksToFloppyBootArchive <targets> ;
1316
1317	AddBootModuleSymlinksToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1318		: $(targets) ;
1319}
1320
1321rule CreateFloppyBootArchiveMakeDirectoriesScript script
1322{
1323	CreateContainerMakeDirectoriesScript
1324		$(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(script) ;
1325}
1326
1327rule CreateFloppyBootArchiveCopyFilesScript script
1328{
1329	CreateContainerCopyFilesScript $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
1330		: $(script) ;
1331}
1332
1333rule BuildFloppyBootArchive archive : scripts
1334{
1335	# BuildHFloppyBootArchive <archive> : <scripts>  ;
1336
1337	local mainScript = build_archive ;
1338	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
1339
1340	Depends $(archive) : $(mainScript) $(scripts) ;
1341	BuildFloppyBootArchive1 $(archive) : $(mainScript) $(scripts) ;
1342}
1343
1344actions BuildFloppyBootArchive1
1345{
1346	$(2[1]) $(1) $(2[2-])
1347}
1348
1349# warning: that is quite x86 dependant...
1350
1351rule BuildFloppyBootImage image : haikuLoader : archive
1352{
1353	Depends $(image) : $(haikuLoader) ;
1354	Depends $(image) : $(archive) ;
1355	#MakeLocateDebug $(image) ;
1356	FLOPPY_IMAGE_SIZE on $(image) = $(HAIKU_BOOT_FLOPPY_IMAGE_SIZE) ;
1357	ARCHIVE_IMAGE_OFFSET on $(image) = $(HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET) ;
1358	BuildFloppyBootImage1 $(image) : $(haikuLoader) $(archive) ;
1359	if $(HAIKU_BOOT_PLATFORM) = atari_m68k {
1360		Depends $(image) : <build>fixup_tos_boot_checksum ;
1361		BuildFloppyBootImageFixupM68K $(image)
1362			: <build>fixup_tos_boot_checksum ;
1363	}
1364	if $(HAIKU_BOOT_PLATFORM) = amiga_m68k {
1365		Depends $(image) : <build>fixup_amiga_boot_checksum ;
1366		BuildFloppyBootImageFixupM68K $(image)
1367			: <build>fixup_amiga_boot_checksum ;
1368	}
1369}
1370
1371actions BuildFloppyBootImage1
1372{
1373	$(RM) $(<)
1374	# make an empty image
1375	dd if=/dev/zero of=$(<) bs=1k count=$(FLOPPY_IMAGE_SIZE)
1376	# add haiku_loader
1377	dd if=$(>[1]) of=$(<) conv=notrunc
1378	# add the boot drivers tgz archive
1379	dd if=$(>[2]) of=$(<) bs=$(ARCHIVE_IMAGE_OFFSET)k seek=1 conv=notrunc
1380}
1381
1382actions BuildFloppyBootImageFixupM68K
1383{
1384	# fixup the boot sector checksum
1385	$(>[1]) $(<)
1386}
1387
1388#pragma mark - CD Boot Image rules
1389
1390rule BuildCDBootImage image : bootfloppy : extrafiles
1391{
1392	Depends $(image) : $(bootfloppy) ;
1393	Depends $(image) : $(extrafiles) ;
1394	BOOTIMG on $(image) = $(bootfloppy) ;
1395
1396	BuildCDBootImage1 $(image) : $(bootfloppy) $(extrafiles) ;
1397}
1398
1399actions BuildCDBootImage1
1400{
1401	$(RM) $(<)
1402	mkisofs -b $(BOOTIMG) -r -J -V bootimg -o $(<) $(>[1]) $(>[2-])
1403}
1404
1405
1406#pragma mark - CD Boot PPC Image rules
1407
1408rule BuildCDBootPPCImage image : hfsmaps : elfloader : coffloader : chrpscript
1409	: extrafiles
1410{
1411	Depends $(image) : $(elfloader) ;
1412	Depends $(image) : $(coffloader) ;
1413	Depends $(image) : $(chrpscript) ;
1414	Depends $(image) : $(extrafiles) ;
1415	Depends $(image) : $(hfsmaps) ;
1416	MAPS on $(image) = $(hfsmaps) ;
1417
1418	BuildCDBootPPCImage1 $(image) : $(elfloader) $(coffloader) $(chrpscript)
1419		$(extrafiles) ;
1420}
1421
1422actions BuildCDBootPPCImage1 bind MAPS
1423{
1424	$(RM) $(<)
1425	mkdir -p $(HAIKU_OUTPUT_DIR)/cd/ppc
1426	cp $(>) $(HAIKU_OUTPUT_DIR)/cd/ppc/
1427	cp $(>[3]) $(HAIKU_OUTPUT_DIR)/cd/ppc/bootinfo.txt
1428	cp $(>[1]) $(HAIKU_OUTPUT_DIR)/cd/ofwboot.elf
1429	cp $(>[2]) $(HAIKU_OUTPUT_DIR)/cd/ofwboot.xcf
1430	#mkisofs -r -U -chrp-boot -V bootimg -o $(<) $(>[1]) $(>[2-])
1431	#mkisofs -hfs -r -U -chrp-boot -part -map $(MAPS) -no-desktop \
1432	#	-hfs-volid bootimg -V bootimg -prep-boot $(>[1]:D=) -o $(<) $(>[1])
1433	#	- $(>[2-])
1434	#mkisofs -v -hfs -part -map $(MAPS) -no-desktop -hfs-volid bootimg \
1435	#	-V bootimg -hfs-bless $(HAIKU_OUTPUT_DIR)/cd/ppc -r -o $(<) $(>[1]) \
1436	#	$(>[2-]) $(HAIKU_OUTPUT_DIR)/cd
1437	#mkisofs -r -U -chrp-boot -V bootimg -prep-boot $(>[1]:D=) -o $(<) $(>[1]) \
1438	#	$(>[2-])
1439	#mkisofs -r -U -V bootimg -prep-boot $(>[1]:D=) -o $(<) $(>[1]) $(>[2-])
1440	# $(HAIKU_OUTPUT_DIR)/cd
1441	# -hfs -hfs-bless .
1442	mkisofs -v -hfs -part -map $(MAPS) -no-desktop -hfs-volid bootimg \
1443		-V bootimg -hfs-bless $(HAIKU_OUTPUT_DIR)/cd/ppc -prep-boot \
1444		ppc/$(>[2]:D=) -r -o $(<) $(HAIKU_OUTPUT_DIR)/cd
1445	#$(RM) -R $(HAIKU_OUTPUT_DIR)/cd
1446}
1447
1448
1449