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