xref: /haiku/build/jam/ImageRules (revision e221c09e508ffc3c62738140c9b6fc4fa211662a)
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
141rule AddFilesToContainer container : directoryTokens : targets : destName
142{
143	# AddFilesToContainer <container> : <directoryTokens> : <targets>
144	#	[ : dest name ]
145	#
146	local directory = [ AddDirectoryToContainer $(container)
147		: $(directoryTokens) ] ;
148	local containerGrist = [ on $(container) return $(HAIKU_CONTAINER_GRIST) ] ;
149
150	# If the image shall only be updated, we filter out all targets not marked
151	# accordingly.
152	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
153		local filterVar
154			= [ on $(container) return $(HAIKU_INCLUDE_IN_CONTAINER_VAR) ] ;
155		if $(filterVar) {
156			targets = [ FilterContainerUpdateTargets $(targets)
157				: $(filterVar) ] ;
158		}
159	}
160
161	# We create a unique dummy target per target to install.
162	local installTargetsVar
163		= [ on $(container) return $(HAIKU_INSTALL_TARGETS_VAR) ] ;
164	local target ;
165	for target in $(targets) {
166		local name ;
167		if $(destName) {
168			name = $(destName) ;
169		} else {
170			name = $(target:G=:D=) ;
171		}
172
173		local destTarget = $(name:G=$(containerGrist)__$(directory:G=)) ;
174		TARGET on $(destTarget) = $(target) ;
175		INSTALL_DIR on $(destTarget) = $(directory) ;
176		$(installTargetsVar) on $(target) += $(destTarget) ;
177		TARGETS_TO_INSTALL on $(directory) += $(destTarget) ;
178	}
179}
180
181rule FFilesInContainerDirectory container : directoryTokens
182{
183	local containerGrist = [ on $(container) return $(HAIKU_CONTAINER_GRIST) ] ;
184	local directory = [ FDirName $(directoryTokens) ] ;
185	directory = $(directory:G=$(containerGrist)) ;
186
187	if [ on $(directory) return $(__is_on_image) ] {
188		on $(directory) return $(TARGETS_TO_INSTALL) ;
189	}
190
191	return ;
192}
193
194rule AddSymlinkToContainer container : directoryTokens : linkTarget : linkName
195{
196	# AddSymlinkToContainer <container> : <directory> : <link target>
197	#	[ : <link name> ] ;
198	#
199
200	# If the image shall only be updated, we don't add any symlinks.
201	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
202		return ;
203	}
204
205	local directory = [ AddDirectoryToContainer $(container)
206		: $(directoryTokens) ] ;
207
208	if ! $(linkName) {
209		local path = [ FReverse [ FSplitPath $(linkTarget) ] ] ;
210		linkName = $(path[1]) ;
211	}
212
213	local link = $(directory)/$(linkName) ;
214	SYMLINK_TARGET on $(link) = $(linkTarget) ;
215	SYMLINKS_TO_INSTALL on $(directory) += $(link) ;
216}
217
218rule FSymlinksInContainerDirectory container : directoryTokens
219{
220	local containerGrist = [ on $(container) return $(HAIKU_CONTAINER_GRIST) ] ;
221	local directory = [ FDirName $(directoryTokens) ] ;
222	directory = $(directory:G=$(containerGrist)) ;
223
224	if [ on $(directory) return $(__is_on_image) ] {
225		on $(directory) return $(SYMLINKS_TO_INSTALL) ;
226	}
227
228	return ;
229}
230
231rule CopyDirectoryToContainer container : directoryTokens : sourceDirectory
232	: targetDirectoryName : excludePatterns : alwaysUpdate
233{
234	# CopyDirectoryToContainer <container> : <directoryTokens>
235	#	: <sourceDirectory> : <targetDirectoryName> : <excludePatterns>
236	#	: <alwaysUpdate> ;
237	#
238
239	# If the image shall only be updated, we don't copy any directories
240	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ]
241			&& ! $(alwaysUpdate) {
242		return ;
243	}
244
245	if ! $(targetDirectoryName) {
246		local path = [ FReverse [ FSplitPath $(sourceDirectory) ] ] ;
247		targetDirectoryName = $(path[1]) ;
248	}
249
250	local directory = [ AddDirectoryToContainer $(container)
251		: $(directoryTokens) $(targetDirectoryName) ] ;
252
253	local targetDir = $(directory)/-/$(sourceDirectory) ;
254	EXCLUDE_PATTERNS on $(targetDir) = $(excludePatterns) ;
255	SOURCE_DIRECTORY on $(targetDir) = $(sourceDirectory) ;
256	TARGET_DIRECTORY on $(targetDir) = $(directory) ;
257	DIRECTORIES_TO_INSTALL on $(directory) += $(targetDir) ;
258}
259
260rule UnzipArchiveToContainer container : directoryTokens : zipFile
261{
262	# UnzipArchiveToContainer <container> : <directory> : <zipFile> ] ;
263	#
264
265	local directory = [ AddDirectoryToContainer $(container)
266		: $(directoryTokens) ] ;
267
268	ZIP_FILES_TO_INSTALL on $(directory) += $(zipFile) ;
269}
270
271rule AddDriversToContainer container : relativeDirectoryTokens : targets
272{
273	# AddDriversToContainer <container> : <relative directory> : <targets> ;
274	#
275	local directoryTokens = beos system add-ons kernel drivers dev
276		$(relativeDirectoryTokens) ;
277
278	AddFilesToContainer $(container) : beos system add-ons kernel drivers bin
279		: $(targets) ;
280
281	# If the image shall only be updated, we don't add any symlinks.
282	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
283		return ;
284	}
285
286	# get the relative symlink path prefix
287	local linkPrefix = ;
288	for i in $(relativeDirectoryTokens) {
289		linkPrefix += .. ;
290	}
291	linkPrefix += .. bin ;
292
293	# add the symlinks
294	local name ;
295	for name in $(targets:BS) {
296		AddSymlinkToContainer $(container) : $(directoryTokens)
297			: [ FDirName $(linkPrefix) $(name) ] : $(name) ;
298	}
299}
300
301rule AddNewDriversToContainer container : relativeDirectoryTokens
302	: targets
303{
304	# AddNewDriversToContainer <container> : <directory> : <targets> ;
305	#
306	local directoryTokens = beos system add-ons kernel drivers
307		$(relativeDirectoryTokens) ;
308
309	AddFilesToContainer $(container) : $(directoryTokens)
310		: $(targets) ;
311}
312
313rule AddBootModuleSymlinksToContainer container : targets
314{
315	# AddBootModuleSymlinksToContainer <container> : <targets> ;
316	#
317
318	# If the image shall only be updated, we don't add any symlinks.
319	if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
320		return ;
321	}
322
323	# add the symlinks
324	local installTargetsVar
325		= [ on $(container) return $(HAIKU_INSTALL_TARGETS_VAR) ] ;
326	local target ;
327	for target in $(targets) {
328		# Symlink to the first place where the target has been installed.
329		local destTarget = [ on $(target) return $($(installTargetsVar)[1]) ] ;
330		local installDir = [ on $(destTarget) return $(INSTALL_DIR) ] ;
331
332		if ! $(installDir) {
333			Echo "ERROR: AddBootModuleSymlinksToContainer: Can't create a "
334				"symlink to target" \"$(target)"\"." ;
335			Exit "ERROR: Add*ToContainer has not been invoked for it yet." ;
336		}
337
338		local name = $(target:BS) ;
339		local linkTarget = [ FDirName /boot $(installDir:G=) $(name) ] ;
340
341		AddSymlinkToContainer $(container) : beos system add-ons kernel boot
342			: $(linkTarget) : $(name) ;
343	}
344}
345
346
347rule CreateContainerMakeDirectoriesScript container : script
348{
349	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
350	Always $(script) ;
351
352	local initScript = [ InitScript $(script) ] ;
353
354	local scriptBody
355		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
356	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
357	Depends $(scriptBody) : $(initScript) ;
358	Depends $(script) : $(scriptBody) ;
359
360	# collect the directories to create
361	local dirsToCreate ;
362	local directories = [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] ;
363	local dir ;
364	for dir in $(directories) {
365		if ! [ on $(dir) return $(DONT_CREATE) ] {
366			dirsToCreate += $(dir) ;
367		}
368	}
369
370	# If the image shall only be updated, we don't create directories.
371	if $(dirsToCreate)
372		&& ! [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] {
373		Depends $(scriptBody) : $(dirsToCreate) ;
374		CreateContainerMakeDirectoriesScript1 $(scriptBody) : $(dirsToCreate) ;
375
376		# For directories with attributes, we convert those the specified
377		# resource files to files with attributes and add commands to the script
378		# adding the attributes to the directories.
379		for dir in $(directories) {
380			local resourceFiles = [ on $(dir) return $(ATTRIBUTE_FILES) ] ;
381			if $(resourceFiles) {
382				local dirTokens = [ on $(dir) return $(DIRECTORY_TOKENS) ] ;
383
384				# translate resources file to file with attributes
385				local attributeFile = $(script)-attributes-$(dirTokens:J=-) ;
386				ResAttr $(attributeFile) : $(resourceFiles) ;
387
388				# use a unique dummy target for this file, on which we
389				# can define the TARGET_DIR variable
390				local dummyTarget = $(script)-attributes-dummy-$(dir:G=) ;
391				NotFile $(dummyTarget) ;
392				TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
393
394				Depends $(dummyTarget) : $(initScript) $(attributeFile) ;
395				Depends $(script) : $(dummyTarget) ;
396
397				AppendToContainerMakeDirectoriesScriptAttributes $(dummyTarget)
398					: $(initScript) $(attributeFile) ;
399			}
400		}
401	}
402}
403
404actions piecemeal CreateContainerMakeDirectoriesScript1
405{
406	echo \$mkdir -p "\"\${tPrefix}$(2:G=)\"" >> $(1)
407}
408
409actions AppendToContainerMakeDirectoriesScriptAttributes
410{
411	echo \$copyAttrs "\"\${sPrefix}$(2[2])\"" \
412		"\"\${tPrefix}$(TARGET_DIR)\"" >> $(2[1])
413}
414
415rule CreateContainerCopyFilesScript container : script
416{
417	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
418	Always $(script) ;
419
420	local initScript = [ InitScript $(script) ] ;
421
422	local scriptBody
423		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
424	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
425	Depends $(scriptBody) : $(initScript) ;
426	Depends $(script) : $(scriptBody) ;
427
428	local dir ;
429	for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] {
430		# filter the targets that shall be renamed; they have to be copied
431		# individually
432		local destTargets = [ on $(dir) return $(TARGETS_TO_INSTALL) ] ;
433		local remainingTargets ;
434		local destTarget ;
435		for destTarget in $(destTargets) {
436			local target = [ on $(destTarget) return $(TARGET) ] ;
437			local name = $(destTarget:BS) ;
438			if $(name) != $(target:BS) {
439				# use a unique dummy target for this file, on which we
440				# can define the TARGET_DIR variable
441				local dummyTarget = $(script)-dummy-$(dir:G=)-$(target) ;
442				NotFile $(dummyTarget) ;
443				TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
444				INSTALL_TARGET_NAME on $(dummyTarget) = $(name) ;
445
446				Depends $(dummyTarget) : $(initScript) $(target) ;
447				Depends $(script) : $(dummyTarget) ;
448
449				AppendToContainerCopyFilesScriptSingleFile $(dummyTarget)
450					: $(initScript) $(target) ;
451			} else {
452				remainingTargets += $(target) ;
453			}
454		}
455		targets = $(remainingTargets) ;
456
457		if $(targets) {
458			# use a unique dummy target for this directory, on which we
459			# can define the TARGET_DIR variable
460			local dummyTarget = $(script)-dummy-$(dir:G=) ;
461			NotFile $(dummyTarget) ;
462			TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
463
464			Depends $(dummyTarget) : $(initScript) $(targets) ;
465			Depends $(script) : $(dummyTarget) ;
466
467			OUTPUT_SCRIPT on $(dummyTarget) = $(initScript) ;
468			AppendToContainerCopyFilesScript $(dummyTarget) : $(targets) ;
469		}
470
471		local symlinks = [ on $(dir) return $(SYMLINKS_TO_INSTALL) ] ;
472		local symlink ;
473		for symlink in $(symlinks) {
474			NotFile $(symlink) ;
475
476			Depends $(script) : $(symlink) ;
477			Depends $(symlink) : $(initScript) ;
478
479			AddSymlinkToContainerCopyFilesScript $(symlink) : $(initScript) ;
480		}
481
482		local targetDirs = [ on $(dir) return $(DIRECTORIES_TO_INSTALL) ] ;
483		local targetDir ;
484		for targetDir in $(targetDirs) {
485			NotFile $(targetDir) ;
486
487			Depends $(script) : $(targetDir) ;
488			Depends $(targetDir) : $(initScript) ;
489
490			AddDirectoryToContainerCopyFilesScript $(targetDir) : $(initScript) ;
491		}
492	}
493}
494
495actions piecemeal AppendToContainerCopyFilesScript bind OUTPUT_SCRIPT
496{
497	echo \$cp "\"\${sPrefix}$(2)\"" "\"\${tPrefix}$(TARGET_DIR)\"" >> $(OUTPUT_SCRIPT)
498}
499
500actions AppendToContainerCopyFilesScriptSingleFile
501{
502	echo \$cp "\"\${sPrefix}$(2[2])\"" \
503		"\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" >> $(2[1])
504}
505
506actions AddSymlinkToContainerCopyFilesScript
507{
508	echo \$ln -sfn "\"$(SYMLINK_TARGET)\"" "\"\${tPrefix}$(1:G=)\"" >> $(2[1])
509}
510
511actions AddDirectoryToContainerCopyFilesScript
512{
513	echo \$cp -r $(EXCLUDE_PATTERNS) "\"\${sPrefix}$(SOURCE_DIRECTORY)/.\"" \
514		"\"\${tPrefix}$(TARGET_DIRECTORY:G=)\"" >> $(2[1])
515}
516
517
518rule CreateContainerUnzipFilesScript container : script
519{
520	MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ;
521	Always $(script) ;
522
523	local initScript = [ InitScript $(script) ] ;
524
525	local scriptBody
526		= [ FSameTargetWithPrependedGrist $(script) : script-body ] ;
527	LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ;
528	Depends $(scriptBody) : $(initScript) ;
529	Depends $(script) : $(scriptBody) ;
530
531	local dir ;
532	for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] {
533		local zipFiles = [ on $(dir) return $(ZIP_FILES_TO_INSTALL) ] ;
534		local zipFile ;
535		for zipFile in $(zipFiles) {
536			# use a unique dummy target for this file, on which we
537			# can define the TARGET_DIR variable
538			local dummyTarget = $(script)-dummy-$(dir:G=)-$(zipFile) ;
539			NotFile $(dummyTarget) ;
540			TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
541
542			Depends $(dummyTarget) : $(initScript) $(zipFile) ;
543			Depends $(script) : $(dummyTarget) ;
544
545			AddUnzipFileToContainerUnzipFilesScript $(dummyTarget)
546				: $(initScript) $(zipFile) ;
547		}
548	}
549}
550
551actions AddUnzipFileToContainerUnzipFilesScript
552{
553	echo unzipFile "\"$(2[2])\"" "\"$(TARGET_DIR)\"" >> $(2[1])
554}
555
556
557#pragma mark - Haiku Image rules
558
559rule SetUpdateHaikuImageOnly flag
560{
561	HAIKU_CONTAINER_UPDATE_ONLY on $(HAIKU_IMAGE_CONTAINER_NAME) = $(flag) ;
562}
563
564rule IsUpdateHaikuImageOnly
565{
566	on $(HAIKU_IMAGE_CONTAINER_NAME) return $(HAIKU_CONTAINER_UPDATE_ONLY) ;
567}
568
569rule AddDirectoryToHaikuImage directoryTokens : attributeFiles
570{
571	# AddDirectoryToHaikuImage <directoryTokens>
572
573	local dir = [ AddDirectoryToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
574		: $(directoryTokens) ] ;
575
576	if $(attributeFiles) {
577		SEARCH on $(attributeFiles)
578			+= [ FDirName $(HAIKU_TOP) data image_directories ] ;
579		ATTRIBUTE_FILES on $(dir) += $(attributeFiles) ;
580	}
581
582	return $(dir) ;
583}
584
585rule AddFilesToHaikuImage directory : targets : destName
586{
587	# AddFilesToHaikuImage <directory> : <targets> [ : dest name ]
588
589	AddFilesToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directory)
590		: $(targets) : $(destName) ;
591}
592
593rule FFilesInHaikuImageDirectory directoryTokens
594{
595	return [ FFilesInContainerDirectory $(HAIKU_IMAGE_CONTAINER_NAME)
596		: $(directoryTokens) ] ;
597}
598
599rule AddSymlinkToHaikuImage directoryTokens : linkTarget : linkName
600{
601	# AddSymlinkToHaikuImage <directory> : <link target> [ : <link name> ] ;
602
603	AddSymlinkToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directoryTokens)
604		: $(linkTarget) : $(linkName) ;
605}
606
607rule FSymlinksInHaikuImageDirectory directoryTokens
608{
609	return [ FSymlinksInContainerDirectory $(HAIKU_IMAGE_CONTAINER_NAME)
610		: $(directoryTokens) ] ;
611}
612
613rule CopyDirectoryToHaikuImage directoryTokens : sourceDirectory
614	: targetDirectoryName : excludePatterns : alwaysUpdate
615{
616	CopyDirectoryToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directoryTokens)
617		: $(sourceDirectory) : $(targetDirectoryName) : $(excludePatterns)
618		: $(alwaysUpdate) ;
619}
620
621rule AddSourceDirectoryToHaikuImage dirTokens : alwaysUpdate
622{
623	# AddSourceDirectoryToHaikuImage <dirTokens> : <alwaysUpdate> ;
624
625	CopyDirectoryToHaikuImage home HaikuSources
626		: [ FDirName $(HAIKU_TOP) $(dirTokens) ]
627		: : -x .svn : $(alwaysUpdate) ;
628}
629
630rule AddHeaderDirectoryToHaikuImage dirTokens : dirName : alwaysUpdate
631{
632	# AddHeaderDirectoryToHaikuImage <dirTokens> : [ <dirName> ]
633	#	: <alwaysUpdate> ;
634
635	CopyDirectoryToHaikuImage develop headers
636		: [ FDirName $(HAIKU_TOP) headers $(dirTokens) ]
637		: $(dirName) : -x .svn : $(alwaysUpdate) ;
638}
639
640rule UnzipArchiveToHaikuImage dirTokens : zipFile : alwaysUpdate
641{
642	# UnzipArchiveToHaikuImage <dirTokens> : <zipFile> : <alwaysUpdate> ;
643
644	# If the image shall only be updated, we unzip only, if explicitely
645	# requested.
646	if ! [ IsUpdateHaikuImageOnly ] || $(alwaysUpdate) {
647		UnzipArchiveToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(dirTokens)
648			: $(zipFile) ;
649	}
650}
651
652rule AddDriversToHaikuImage relativeDirectoryTokens : targets
653{
654	# AddDriversToHaikuImage <relative directory> : <targets> ;
655
656	AddDriversToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
657		: $(relativeDirectoryTokens) : $(targets) ;
658}
659
660rule AddNewDriversToHaikuImage relativeDirectoryTokens : targets
661{
662	# AddNewDriversToHaikuImage <relative directory> : <targets> ;
663
664	AddNewDriversToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
665		: $(relativeDirectoryTokens) : $(targets) ;
666}
667
668rule AddBootModuleSymlinksToHaikuImage targets
669{
670	# AddBootModuleSymlinksToHaikuImage <targets> ;
671
672	AddBootModuleSymlinksToContainer $(HAIKU_IMAGE_CONTAINER_NAME)
673		: $(targets) ;
674}
675
676rule AddOptionalHaikuImagePackages packages
677{
678	HAIKU_OPTIONAL_PACKAGE_ADDED on $(packages) = 1 ;
679}
680
681rule IsOptionalHaikuImagePackageAdded package
682{
683	if [ on $(package) return $(HAIKU_OPTIONAL_PACKAGE_ADDED) ] {
684		return 1 ;
685	}
686
687	return $(HAIKU_ADD_ALL_OPTIONAL_PACKAGES) ;
688}
689
690rule OptionalPackageDependencies package : dependencies
691{
692	if [ IsOptionalHaikuImagePackageAdded $(package) ] {
693		AddOptionalHaikuImagePackages $(dependencies) ;
694	}
695}
696
697rule InstallOptionalHaikuImagePackage package : url : dirTokens
698{
699	# download zip file
700	local zipFile = $(package:G=download).zip ;
701	MakeLocate $(zipFile) : $(HAIKU_DOWNLOAD_DIR) ;
702	DownloadFile $(zipFile) : $(url) ;
703
704	# unzip onto image
705	UnzipArchiveToHaikuImage $(dirTokens) : $(zipFile) ;
706}
707
708rule AddEntryToHaikuImageUserGroupFile file : entry
709{
710	local allEntries = [ on $(file) return $(HAIKU_IMAGE_USER_GROUP_ENTRIES) ] ;
711
712	if $(allEntries) {
713		allEntries = $(allEntries)|$(entry) ;
714	} else {
715		allEntries = $(entry) ;
716
717		Always $(file) ;
718		MakeLocate $(file) : $(HAIKU_COMMON_PLATFORM_OBJECT_DIR) ;
719		BuildHaikuImageUserGroupFile $(file) ;
720		AddFilesToHaikuImage beos etc : $(file) ;
721	}
722
723	HAIKU_IMAGE_USER_GROUP_ENTRIES on $(file) = $(allEntries) ;
724}
725
726actions BuildHaikuImageUserGroupFile
727{
728	echo "$(HAIKU_IMAGE_USER_GROUP_ENTRIES)" | tr '|' '\n' > $(1)
729}
730
731rule AddUserToHaikuImage user : uid : gid : home : shell : realName
732{
733	if ! $(user) || ! $(uid) || ! $(gid) || ! $(home) {
734		Exit "Invalid haiku user specification passed to AddUserToHaikuImage." ;
735	}
736
737	local entry
738		= $(user):x:$(uid):$(gid):$(realName:E=$(user)):$(home):$(shell:E="") ;
739
740	AddEntryToHaikuImageUserGroupFile <haiku-image>passwd : $(entry) ;
741}
742
743rule AddGroupToHaikuImage group : gid : members
744{
745	if ! $(group) || ! $(gid) {
746		Exit "Invalid haiku group specification passed to"
747			"AddGroupToHaikuImage." ;
748	}
749
750	local entry = $(group):x:$(gid):$(members:J=,:E) ;
751
752	AddEntryToHaikuImageUserGroupFile <haiku-image>group : $(entry) ;
753}
754
755rule AddOptionalPackageDescriptionToHaikuImage file : searchPath
756{
757	if $(searchPath) {
758		SEARCH on $(file) = [ FDirName $(searchPath) ] ;
759	}
760
761	HAIKU_IMAGE_OPTIONAL_PACKAGE_DESCRIPTIONS += $(file) ;
762}
763
764rule AddLicenseToHaikuImage file : name : searchPath
765{
766	if $(searchPath) {
767		SEARCH on $(file) = [ FDirName $(searchPath) ] ;
768	}
769
770	if $(name) && $(file:BS) = $(name) {
771		name = ;
772	}
773
774	AddFilesToHaikuImage beos etc licenses : $(file) : $(name) ;
775}
776
777
778rule CreateHaikuImageMakeDirectoriesScript script
779{
780	CreateContainerMakeDirectoriesScript $(HAIKU_IMAGE_CONTAINER_NAME)
781		: $(script) ;
782}
783
784rule CreateHaikuImageCopyFilesScript script
785{
786	CreateContainerCopyFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ;
787}
788
789rule CreateHaikuImageUnzipFilesScript script
790{
791	CreateContainerUnzipFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ;
792}
793
794rule BuildHaikuImage haikuImage : scripts : isImage : isVMwareImage
795{
796	# BuildHaikuImage <haiku image> : <scripts> : <is image> : <isVMwareImage> ;
797
798	if $(isImage) = 1 || $(isImage) = true {
799		IS_IMAGE on $(haikuImage) = 1 ;
800	} else {
801		IS_IMAGE on $(haikuImage) = "" ;
802	}
803
804	if $(isVMwareImage) = 1 || $(isVMwareImage) = true {
805		IS_VMWARE_IMAGE on $(haikuImage) = 1 ;
806	} else {
807		IS_VMWARE_IMAGE on $(haikuImage) = "" ;
808	}
809
810	local mainScript = build_haiku_image ;
811	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
812
813	Depends $(haikuImage) : $(mainScript) $(scripts) ;
814	BuildHaikuImage1 $(haikuImage) : $(mainScript) $(scripts) ;
815}
816
817actions BuildHaikuImage1
818{
819	export imagePath="$(1)"
820	export isImage="$(IS_IMAGE)"
821	export isVMwareImage="$(IS_VMWARE_IMAGE)"
822	$(2[1]) $(2[2-])
823}
824
825rule BuildVMWareImage vmwareImage : plainImage : imageSize
826{
827	# BuildVMWareImage <vmware image> : <plain image> : <image size in MB>
828
829	IMAGE_SIZE on $(vmwareImage) = $(imageSize) ;
830
831	Depends $(vmwareImage) : <build>vmdkheader $(plainImage) ;
832	BuildVMWareImage1 $(vmwareImage) : <build>vmdkheader $(plainImage) ;
833}
834
835actions BuildVMWareImage1
836{
837	$(RM) $(1)
838	$(2[1]) -h 64k -i$(IMAGE_SIZE)M $(1) &&
839	cat $(2[2]) >> $(1)
840}
841
842
843#pragma mark - Network Boot Archive rules
844
845rule AddDirectoryToNetBootArchive directoryTokens
846{
847	# AddDirectoryToNetBootArchive <directoryTokens>
848
849	return [ AddDirectoryToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
850		: $(directoryTokens) ] ;
851}
852
853rule AddFilesToNetBootArchive directory : targets : destName
854{
855	# AddFilesToNetBootArchive <directory> : <targets> [ : dest name ]
856
857	AddFilesToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(directory)
858		: $(targets) : $(destName) ;
859}
860
861rule AddSymlinkToNetBootArchive directoryTokens : linkTarget : linkName
862{
863	# AddSymlinkToNetBootArchive <directory> : <link target> [ : <link name> ] ;
864
865	AddSymlinkToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
866		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
867}
868
869rule AddDriversToNetBootArchive relativeDirectoryTokens : targets
870{
871	# AddDriversToNetBootArchive <relative directory> : <targets> ;
872
873	AddDriversToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
874		: $(relativeDirectoryTokens) : $(targets) ;
875}
876
877rule AddDriverRegistrationToNetBootArchive relativeDirectoryTokens : target
878	: links
879{
880	# AddDriverRegistrationToNetBootArchive <directory> : <link target>
881	#	: <link names> ] ;
882
883	AddDriverRegistrationToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
884		: $(relativeDirectoryTokens) : $(target) : $(links) ;
885}
886
887rule AddBootModuleSymlinksToNetBootArchive targets
888{
889	# AddBootModuleSymlinksToNetBootArchive <targets> ;
890
891	AddBootModuleSymlinksToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
892		: $(targets) ;
893}
894
895rule CreateNetBootArchiveMakeDirectoriesScript script
896{
897	CreateContainerMakeDirectoriesScript
898		$(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(script) ;
899}
900
901rule CreateNetBootArchiveCopyFilesScript script
902{
903	CreateContainerCopyFilesScript $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
904		: $(script) ;
905}
906
907rule BuildNetBootArchive archive : scripts
908{
909	# BuildHNetBootArchive <archive> : <scripts>  ;
910
911	local mainScript = build_tgz_archive ;
912	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
913
914	Depends $(archive) : $(mainScript) $(scripts) ;
915	BuildNetBootArchive1 $(archive) : $(mainScript) $(scripts) ;
916}
917
918actions BuildNetBootArchive1
919{
920	$(2[1]) $(1) $(2[2-])
921}
922
923
924#pragma mark - Floppy Boot Archive rules
925
926rule AddDirectoryToFloppyBootArchive directoryTokens
927{
928	# AddDirectoryToFloppyBootArchive <directoryTokens>
929
930	return [ AddDirectoryToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
931		: $(directoryTokens) ] ;
932}
933
934rule AddFilesToFloppyBootArchive directory : targets : destName
935{
936	# AddFilesToFloppyBootArchive <directory> : <targets> [ : dest name ]
937
938	AddFilesToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(directory)
939		: $(targets) : $(destName) ;
940}
941
942rule AddSymlinkToFloppyBootArchive directoryTokens : linkTarget : linkName
943{
944	# AddSymlinkToFloppyBootArchive <directory> : <link target> [ : <link name> ] ;
945
946	AddSymlinkToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
947		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
948}
949
950rule AddDriversToFloppyBootArchive relativeDirectoryTokens : targets
951{
952	# AddDriversToFloppyBootArchive <relative directory> : <targets> ;
953
954	AddDriversToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
955		: $(relativeDirectoryTokens) : $(targets) ;
956}
957
958rule AddDriverRegistrationToFloppyBootArchive relativeDirectoryTokens : target
959	: links
960{
961	# AddDriverRegistrationToFloppyBootArchive <directory> : <link target>
962	#	: <link names> ] ;
963
964	AddDriverRegistrationToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
965		: $(relativeDirectoryTokens) : $(target) : $(links) ;
966}
967
968rule AddBootModuleSymlinksToFloppyBootArchive targets
969{
970	# AddBootModuleSymlinksToFloppyBootArchive <targets> ;
971
972	AddBootModuleSymlinksToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
973		: $(targets) ;
974}
975
976rule CreateFloppyBootArchiveMakeDirectoriesScript script
977{
978	CreateContainerMakeDirectoriesScript
979		$(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(script) ;
980}
981
982rule CreateFloppyBootArchiveCopyFilesScript script
983{
984	CreateContainerCopyFilesScript $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
985		: $(script) ;
986}
987
988rule BuildFloppyBootArchive archive : scripts
989{
990	# BuildHFloppyBootArchive <archive> : <scripts>  ;
991
992	local mainScript = build_tgz_archive ;
993	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
994
995	Depends $(archive) : $(mainScript) $(scripts) ;
996	BuildFloppyBootArchive1 $(archive) : $(mainScript) $(scripts) ;
997}
998
999actions BuildFloppyBootArchive1
1000{
1001	$(2[1]) $(1) $(2[2-])
1002}
1003
1004# warning: that is quite x86 dependant...
1005
1006rule BuildFloppyBootImage image : zbeos : archive
1007{
1008	Depends $(image) : $(zbeos) ;
1009	Depends $(image) : $(archive) ;
1010	#MakeLocateDebug $(image) ;
1011	BuildFloppyBootImage1 $(image) : $(zbeos) $(archive) ;
1012}
1013
1014actions BuildFloppyBootImage1
1015{
1016	$(RM) $(<)
1017	# make an empty image
1018	dd if=/dev/zero of=$(<) bs=1k count=1440
1019	# add zbeos
1020	dd if=$(>[1]) of=$(<) conv=notrunc
1021	# add the boot drivers tgz archive
1022	# keep the offset in sync with
1023	# src/system/boot/loader/file_systems/tarfs/tarfs.cpp:kFloppyArchiveOffset
1024	dd if=$(>[2]) of=$(<) bs=192k seek=1 conv=notrunc
1025}
1026
1027
1028#pragma mark - CD Boot Image rules
1029
1030rule BuildCDBootImage image : bootfloppy : extrafiles
1031{
1032	Depends $(image) : $(bootfloppy) ;
1033	Depends $(image) : $(extrafiles) ;
1034	BOOTIMG on $(image) = $(bootfloppy) ;
1035
1036	BuildCDBootImage1 $(image) : $(bootfloppy) $(extrafiles) ;
1037}
1038
1039actions BuildCDBootImage1
1040{
1041	$(RM) $(<)
1042	mkisofs -b $(BOOTIMG) -r -J -V bootimg -o $(<) $(>[1]) $(>[2-])
1043}
1044
1045
1046