xref: /haiku/build/jam/RepositoryRules (revision efafab643ce980e3f3c916795ed302599f6b4f66)
1#pragma mark - Private
2
3# default value for the build profile that defines the set of source packages
4# that will be put onto the bootstrap image
5HAIKU_BOOTSTRAP_SOURCES_PROFILE ?= @minimum-raw ;
6
7rule PackageFamily packageBaseName
8{
9	return $(packageBaseName:G=package-family) ;
10}
11
12
13rule SetRepositoryMethod repository : methodName : method
14{
15	HAIKU_REPOSITORY_METHOD_$(methodName) on $(repository) = $(method) ;
16}
17
18rule InvokeRepositoryMethod repository : methodName : arg1 : arg2 : arg3 : arg4
19	: arg5 : arg6 : arg7
20{
21	local method
22		= [ on $(repository) return $(HAIKU_REPOSITORY_METHOD_$(methodName)) ] ;
23	if ! $(method) {
24		Exit "Method" $(methodName) " not defined for repository"
25			$(repository) ;
26	}
27
28	return [ $(method) $(repository) : $(arg1) : $(arg2) : $(arg3) : $(arg4)
29		: $(arg5) : $(arg6) : $(arg7) ] ;
30}
31
32
33rule AddRepositoryPackage repository : architecture : baseName : version
34{
35	local package = $(baseName)-$(version) ;
36	package = $(package:E=$(baseName):G=package-in-$(repository:G=)) ;
37	HAIKU_PACKAGE_REPOSITORY on $(package) = $(repository) ;
38	HAIKU_PACKAGE_ARCHITECTURE on $(package) = $(architecture) ;
39	local packageFileName = $(package:G=)-$(architecture).hpkg ;
40	HAIKU_PACKAGE_FILE_NAME on $(package) = $(packageFileName) ;
41
42	local packageFamily = [ InvokeRepositoryMethod $(repository) : PackageFamily
43		: $(baseName) ] ;
44	baseName = $(packageFamily:G=) ;
45
46	if $(HAIKU_NO_DOWNLOADS) = 1 && $(HAIKU_IS_BOOTSTRAP) != 1 {
47		# Only add packages to repository that already exist in download
48		# directory.
49		if ! [ Glob $(HAIKU_DOWNLOAD_DIR) : $(packageFileName) ] {
50			return ;
51		}
52	}
53
54	if ! $(baseName) in $(HAIKU_AVAILABLE_PACKAGES) {
55		HAIKU_AVAILABLE_PACKAGES += $(baseName) ;
56	}
57
58	HAIKU_PACKAGE_VERSIONS on $(packageFamily) += $(package) ;
59	HAIKU_REPOSITORY_PACKAGES on $(repository) += $(package) ;
60
61	return $(package) ;
62}
63
64
65rule AddRepositoryPackages repository : architecture : packages : sourcePackages
66	: debugInfoPackages
67{
68	local packageTargets ;
69	local package ;
70	for package in $(packages) {
71		local splitName = [ Match "([^-]*)-(.*)" : $(package) ] ;
72		local baseName = $(splitName[1]:E=$(package)) ;
73		local version = $(splitName[2]) ;
74		packageTargets += [ AddRepositoryPackage $(repository) : $(architecture)
75			: $(baseName) : $(version) ] ;
76		if $(baseName) in $(sourcePackages) {
77			AddRepositoryPackage $(repository) : source : $(baseName)_source
78				: $(version) ;
79		}
80		if $(baseName) in $(debugInfoPackages) {
81			packageTargets += [ AddRepositoryPackage $(repository)
82				: $(architecture) : $(baseName)_debuginfo : $(version) ] ;
83		}
84	}
85
86	return $(packageTargets) ;
87}
88
89
90rule PackageRepository repository : architecture : anyPackages : packages
91	: sourcePackages : debugInfoPackages
92{
93	if $(architecture) != $(HAIKU_PACKAGING_ARCHS[1]) {
94		return ;
95	}
96
97	HAIKU_REPOSITORIES += $(repository) ;
98	HAIKU_REPOSITORY_DEFINITION_FILE on $(repository)
99		= $(HAIKU_REPOSITORY_JAMFILE) ;
100
101	return [ AddRepositoryPackages $(repository) : any : $(anyPackages)
102			: $(sourcePackages) : $(debugInfoPackages) ]
103		[ AddRepositoryPackages $(repository) : $(architecture) : $(packages)
104			: $(sourcePackages) : $(debugInfoPackages) ] ;
105}
106
107
108#pragma mark - Remote Repository
109
110
111rule RemoteRepositoryPackageFamily repository : packageBaseName
112{
113	return [ PackageFamily $(packageBaseName) ] ;
114}
115
116
117rule RemoteRepositoryFetchPackage repository : package : fileName
118{
119	local baseUrl = [ on $(repository) return $(HAIKU_REPOSITORY_URL) ] ;
120	local packagesChecksumFile
121		= [ on $(repository)
122			return $(HAIKU_REPOSITORY_PACKAGES_CHECKSUM_FILE) ] ;
123
124	local downloadedFile = [ DownloadFile $(fileName)
125		: "$(baseUrl)/`cat $source`/packages/$(fileName)"
126		: $(packagesChecksumFile) ] ;
127	NoUpdate $(downloadedFile) ;
128		# Don't download the file again when something in the repository
129		# changes. It is (supposed to be) still the same file.
130	return $(downloadedFile) ;
131}
132
133
134rule RemotePackageRepository repository : architecture : repositoryUrl
135	: anyPackages : packages : sourcePackages : debugInfoPackages
136{
137	repository = $(repository:G=repository) ;
138
139	if ! $(HOST_EXTENDED_REGEX_SED) {
140		ECHO "Variable HOST_EXTENDED_REGEX_SED not set. Please run ./configure or" ;
141		EXIT "specify it manually." ;
142	}
143
144	SetRepositoryMethod $(repository) : PackageFamily
145		: RemoteRepositoryPackageFamily ;
146	SetRepositoryMethod $(repository) : FetchPackage
147		: RemoteRepositoryFetchPackage ;
148
149	HAIKU_REPOSITORY_URL on $(repository) = $(repositoryUrl) ;
150
151	PackageRepository $(repository) : $(architecture) : $(anyPackages)
152		: $(packages) : $(sourcePackages) : $(debugInfoPackages) ;
153
154	# build package list file
155	local packageListFile = $(repository:G=repository-package-list)-packages ;
156	local repositoriesDir = $(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture)) ;
157	MakeLocate $(packageListFile) : $(repositoriesDir) ;
158	GeneratedRepositoryPackageList $(packageListFile) : $(repository) ;
159
160	# build package list checksum file
161	local packagesChecksumFile
162		= $(repository:G=repository-package-checksum)-checksum ;
163	local thisPackageRepositoryFile = [ Glob [ FDirName
164		$(HAIKU_BUILD_RULES_DIR) repositories HaikuPorts ] :
165			$(HAIKU_PACKAGING_ARCH) ] ;
166	MakeLocate $(packagesChecksumFile) : $(repositoriesDir) ;
167	Depends $(packagesChecksumFile) : $(thisPackageRepositoryFile) ;
168	ChecksumFileSHA256 $(packagesChecksumFile) : $(thisPackageRepositoryFile) ;
169
170	local repositoryInfo = $(repository:G=repository-info)-info ;
171	local repositoryFile = $(repository:G=repository-cache) ;
172	local repositoryConfig = $(repository:G=repository-config)-config ;
173	MakeLocate $(repositoryInfo) $(repositoryFile) $(repositoryConfig)
174		: $(repositoriesDir) ;
175	# Use a locally created dummy repository if downloads have been disabled.
176	# This is useful when trying to build everything locally from source.
177	if $(HAIKU_NO_DOWNLOADS) = 1 {
178		# build repository file
179		local packageFileNames = [
180			on $(packageListFile) return $(HAIKU_REPOSITORY_PACKAGE_FILE_NAMES)
181		] ;
182		local packageFiles ;
183		local packageFile ;
184		for packageFile in $(packageFileNames) {
185			MakeLocate $(packageFile) : $(HAIKU_DOWNLOAD_DIR) ;
186			packageFiles += $(packageFile) ;
187		}
188		RepositoryCache $(repositoryFile) : $(repositoryInfo)
189			: $(packageFiles) ;
190	} else {
191		# download repository file
192		local repoUrl = [ on $(repository) return $(HAIKU_REPOSITORY_URL) ] ;
193		DownloadLocatedFile $(repositoryFile)
194			: "$(repoUrl)/`cat $source`/repo"
195			: $(packagesChecksumFile) ;
196	}
197
198	# build the repository info file
199	local repositoryInfoTemplate = <repository-info-template>haikuports ;
200	SEARCH on $(repositoryInfoTemplate)
201		= $(HAIKU_TOP)/src/data/repository_infos ;
202	PreprocessPackageOrRepositoryInfo $(repositoryInfo)
203		: $(repositoryInfoTemplate) : $(architecture) ;
204
205	# build repository config file
206	RepositoryConfig $(repositoryConfig) : $(repositoryInfo)
207		: $(packagesChecksumFile) ;
208
209	HAIKU_REPOSITORY_CACHE_FILE on $(repository) = $(repositoryFile) ;
210	HAIKU_REPOSITORY_CONFIG_FILE on $(repository) = $(repositoryConfig) ;
211	HAIKU_REPOSITORY_PACKAGES_CHECKSUM_FILE on $(repository)
212		= $(packagesChecksumFile) ;
213}
214
215
216rule GeneratedRepositoryPackageList target : repository
217{
218	repository = $(repository:G=repository) ;
219
220	# construct a list of file names
221	local fileNames ;
222	local package ;
223	for package in [ on $(repository) return $(HAIKU_REPOSITORY_PACKAGES) ] {
224		fileNames += [ on $(package) return $(HAIKU_PACKAGE_FILE_NAME) ] ;
225	}
226
227	local definitionFile
228		= [ on $(repository) return $(HAIKU_REPOSITORY_DEFINITION_FILE) ] ;
229	Depends $(target) : $(definitionFile) ;
230
231	HAIKU_REPOSITORY_PACKAGE_FILE_NAMES on $(target) = $(fileNames) ;
232	GeneratedRepositoryPackageList1 $(target) ;
233}
234
235
236actions GeneratedRepositoryPackageList1
237{
238	(for file in $(HAIKU_REPOSITORY_PACKAGE_FILE_NAMES) ; do
239		echo $file
240	done) | LC_ALL=C sort -u > $(1)
241}
242
243
244rule RepositoryConfig repoConfig : repoInfo : checksumFile
245{
246	Depends $(repoConfig)
247		: <build>create_repository_config $(repoInfo) $(checksumFile) ;
248	RepositoryConfig1 $(repoConfig)
249		: <build>create_repository_config $(repoInfo) $(checksumFile) ;
250}
251
252
253actions RepositoryConfig1
254{
255	version=
256	if [ -n "$(2[3]:E)" ]; then
257		version=`cat "$(2[3]:E)"`
258	fi
259	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
260	$(2[1]) $(2[2]) $(1)
261}
262
263
264rule RepositoryCache repoCache : repoInfo : packageFiles
265{
266	Depends $(repoCache)
267		: <build>package_repo $(repoInfo) $(packageFiles) ;
268	RepositoryCache1 $(repoCache)
269		: <build>package_repo $(repoInfo) $(packageFiles) ;
270}
271
272
273actions RepositoryCache1
274{
275	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
276	$(2[1]) create -q $(2[2-])
277	mv $(1:B=repo) $(1)
278}
279
280
281#pragma mark - Bootstrap Repository
282
283
284rule BootstrapRepositoryPackageFamily repository : packageBaseName
285{
286	local splitBaseName = [ Match "(.*)_bootstrap(.*)" : $(packageBaseName) ] ;
287	if $(splitBaseName) {
288		packageBaseName = $(splitBaseName[1])$(splitBaseName[2]) ;
289	}
290
291	return [ PackageFamily $(packageBaseName) ] ;
292}
293
294
295rule BootstrapRepositoryFetchPackage repository : package : fileName
296{
297	local outputDir
298		= [ on $(repository) return $(HAIKU_REPOSITORY_BUILD_DIRECTORY) ] ;
299	local configFile
300		= [ on $(repository) return $(HAIKU_REPOSITORY_BUILD_CONFIG_FILE) ] ;
301	local haikuCrossDevelPackages = [ on $(package)
302		return $(HAIKU_REPOSITORY_HAIKU_CROSS_DEVEL_PACKAGES) ] ;
303
304	local packageFile = <cross-built>$(fileName) ;
305	if [ on $(packageFile) return $(HAIKU_REPOSITORY_BUILD_DIRECTORY) ] {
306		# rule already called for this package
307		return $(packageFile) ;
308	}
309
310	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(packageFile) = $(outputDir) ;
311
312	MakeLocate $(packageFile) : [ FDirName $(outputDir) packages ] ;
313	NoUpdate $(packageFile) ;
314		# Don't rebuild the file. Since the haiku cross devel package is
315		# a dependency and is updated always, this package would otherwise be
316		# rebuilt always as well.
317
318	Depends $(packageFile) : $(haikuCrossDevelPackages) $(configFile) ;
319	BootstrapRepositoryFetchPackage1 $(packageFile)
320		: $(haikuCrossDevelPackages) ;
321
322	return $(packageFile) ;
323}
324
325
326actions BootstrapRepositoryFetchPackage1
327{
328	# don't rebuild existing package
329	package="$(1)"
330	if [ -e "$package" ]; then
331		exit 0
332	fi
333
334	# make Haiku cross devel package path absolute
335	haikuCrossDevelPackage="$(2[1])"
336	if [ "x$haikuCrossDevelPackage" = "x${haikuCrossDevelPackage#/}" ]; then
337		haikuCrossDevelPackage="`pwd`/$haikuCrossDevelPackage"
338	fi
339
340	# make secondary Haiku cross devel packages path absolute
341	secondaryCrossDevelPackages=
342	if [ -n "$(2[2-]:J)" ]; then
343		for secondaryCrossDevelPackage in "$(2[2-])" ; do
344			if [ "x$secondaryCrossDevelPackage" = "x${secondaryCrossDevelPackage#/}" ]; then
345				secondaryCrossDevelPackage="`pwd`/$secondaryCrossDevelPackage"
346			fi
347			if [ -n "$secondaryCrossDevelPackages" ]; then
348				secondaryCrossDevelPackages="$secondaryCrossDevelPackages,$secondaryCrossDevelPackage"
349			else
350				secondaryCrossDevelPackages="--secondary-cross-devel-package=$secondaryCrossDevelPackage"
351			fi
352		done
353	fi
354
355	# determine the port-specification from the package name
356	portSpec=`basename "$package" | sed 's@-.*@@'`
357
358	cd $(HAIKU_REPOSITORY_BUILD_DIRECTORY)
359
360	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
361	if [ -n "$secondaryCrossDevelPackages" ]; then
362		$(HOST_HAIKU_PORTER) -j$(HAIKU_PORTER_CONCURRENT_JOBS) \
363			--all-dependencies $(HAIKU_PORTER_EXTRA_OPTIONS) \
364			--cross-devel-package "$haikuCrossDevelPackage" \
365			"$secondaryCrossDevelPackages" $portSpec
366	else
367		$(HOST_HAIKU_PORTER) -j$(HAIKU_PORTER_CONCURRENT_JOBS) \
368			--all-dependencies $(HAIKU_PORTER_EXTRA_OPTIONS) \
369			--cross-devel-package "$haikuCrossDevelPackage" $portSpec
370	fi
371}
372
373
374actions BuildBootstrapRepositoryConfig
375{
376cat > $(1) << EOF
377PACKAGER="The Haiku build system <build-system@haiku-os.org>"
378TREE_PATH="$(HAIKU_REPOSITORY_TREE_PATH)"
379TARGET_ARCHITECTURE="$(HAIKU_PACKAGING_ARCH)"
380
381DOWNLOAD_IN_PORT_DIRECTORY="yes"
382PACKAGE_COMMAND="$(PWD)/$(2[1])"
383MIMESET_COMMAND="$(PWD)/$(2[2])"
384SYSTEM_MIME_DB="$(PWD)/$(2[3])"
385LICENSES_DIRECTORY="$(HAIKU_ABSOLUTE_TOP)/data/system/data/licenses"
386OUTPUT_DIRECTORY="$(HAIKU_REPOSITORY_BUILD_DIRECTORY)"
387EOF
388
389	# If we have cross tools, add the cross tools directory.
390	gcc=$(HAIKU_CC_$(HAIKU_PACKAGING_ARCH))
391	if [ "x$gcc" != "x${gcc#/}" ]; then
392		if [ `basename $gcc` = \
393				$(HAIKU_GCC_MACHINE_$(HAIKU_PACKAGING_ARCH))-gcc ]; then
394			dir=`dirname $gcc`
395			dir=`dirname $dir`
396			echo CROSS_TOOLS=\"$dir\" >> $(1)
397		fi
398	fi
399
400	# Add secondary architectures and cross tools.
401	secondaryArchs="$(HAIKU_PACKAGING_ARCHS[2-]:E=)"
402	if [ -n "$secondaryArchs" ]; then
403		echo SECONDARY_TARGET_ARCHITECTURES=\" >> $(1)
404		for arch in $secondaryArchs; do
405			echo "  $arch" >> $(1)
406		done
407		echo \" >> $(1)
408
409		echo SECONDARY_CROSS_TOOLS=\" >> $(1)
410		for gcc in $(HAIKU_CC_$(HAIKU_PACKAGING_ARCHS[2-])) ; do
411			dir=`dirname $gcc`
412			dir=`dirname $dir`
413			echo "  $dir" >> $(1)
414		done
415		echo \" >> $(1)
416	fi
417}
418
419
420rule BootstrapPackageRepository repository : architecture
421	: anyPackages : packagesStage0 : packagesStage1 : packagesStage2
422	: sourcePackages : debugInfoPackages
423{
424	repository = $(repository:G=repository) ;
425	packagesStage0 = [ FFilterByBuildFeatures $(packagesStage0) ] ;
426	packagesStage1 = [ FFilterByBuildFeatures $(packagesStage1) ] ;
427	packagesStage2 = [ FFilterByBuildFeatures $(packagesStage2) ] ;
428	sourcePackages = [ FFilterByBuildFeatures $(sourcePackages) ] ;
429	debugInfoPackages = [ FFilterByBuildFeatures $(debugInfoPackages) ] ;
430
431	SetRepositoryMethod $(repository) : PackageFamily
432		: BootstrapRepositoryPackageFamily ;
433	SetRepositoryMethod $(repository) : FetchPackage
434		: BootstrapRepositoryFetchPackage ;
435
436	# register repository with stage 0 packages
437	local stage0PackageTargets = [ PackageRepository $(repository)
438		: $(architecture) : $(anyPackages) : $(packagesStage0)
439		: $(sourcePackages) : $(debugInfoPackages) ] ;
440	if ! $(stage0PackageTargets) {
441		return ;
442	}
443	local crossDevelPackageSuffixes = $(architecture)
444		$(architecture)_$(HAIKU_PACKAGING_ARCHS[2-]) ;
445	HAIKU_REPOSITORY_HAIKU_CROSS_DEVEL_PACKAGES on $(stage0PackageTargets)
446		= haiku_cross_devel_sysroot_stage0_$(crossDevelPackageSuffixes).hpkg ;
447
448	# register repository with stage 1 packages
449	local stage1PackageTargets = [ PackageRepository $(repository)
450		: $(architecture) : $(anyPackages) : $(packagesStage1)
451		: $(sourcePackages) : $(debugInfoPackages) ] ;
452	if ! $(stage1PackageTargets) {
453		return ;
454	}
455	HAIKU_REPOSITORY_HAIKU_CROSS_DEVEL_PACKAGES on $(stage1PackageTargets)
456		= haiku_cross_devel_sysroot_stage1_$(crossDevelPackageSuffixes).hpkg ;
457
458	# add stage 2 packages
459	local stage2PackageTargets = [ AddRepositoryPackages $(repository)
460		: $(architecture) : $(packagesStage2) : $(sourcePackages)
461		: $(debugInfoPackages) ] ;
462	HAIKU_REPOSITORY_HAIKU_CROSS_DEVEL_PACKAGES on $(stage2PackageTargets)
463		= haiku_cross_devel_sysroot_$(crossDevelPackageSuffixes).hpkg ;
464
465	# prepare the config file for the HaikuPorts cross build
466	# This path needs to be absolute due to haikuporter's cwd
467	local outputDir = [ FDirName
468		$(PWD)
469		$(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture))
470		$(repository:G=)-build ] ;
471	local configFile = haikuports.conf ;
472	configFile = $(configFile:G=repository-config-$(repository:G=)) ;
473	MakeLocate $(configFile) : $(outputDir) ;
474	NoUpdate $(configFile) ;
475	Depends $(configFile) : <build>package <build>mimeset <mimedb>mime_db ;
476	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(configFile) = $(outputDir) ;
477	HAIKU_PACKAGING_ARCH on $(configFile) = $(architecture) ;
478	HAIKU_REPOSITORY_TREE_PATH on $(configFile) = $(HAIKU_PORTS_CROSS) ;
479	BuildBootstrapRepositoryConfig $(configFile)
480		: <build>package <build>mimeset <mimedb>mime_db ;
481
482	HAIKU_REPOSITORY_BUILD_CONFIG_FILE on $(repository) = $(configFile) ;
483	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(repository) = $(outputDir) ;
484
485	# Serialize all package file targets. We need to do this, since
486	# haikuporter uses a common directory for building the ports, so building
487	# two ports concurrently isn't possible.
488	local previousPackageFile ;
489	local package ;
490	for package in $(stage1PackageTargets) $(stage2PackageTargets) {
491		local fileName = [ on $(package) return $(HAIKU_PACKAGE_FILE_NAME) ] ;
492		local packageFile = [ BootstrapRepositoryFetchPackage $(repository)
493			: $(package) : $(fileName) ] ;
494		Depends $(packageFile) : $(previousPackageFile) ;
495
496		previousPackageFile = $(packageFile) ;
497	}
498}
499
500
501#pragma mark - Public
502
503
504rule FSplitPackageName packageName
505{
506	local splitName = [ Match "(.*)_([^_]*)" : $(packageName) ] ;
507	local knownPackageSuffixes = devel doc source debuginfo ;
508	if $(splitName[2]) && $(splitName[2]) in $(knownPackageSuffixes) {
509		return $(splitName) ;
510	}
511
512	return $(packageName) ;
513}
514
515
516rule IsPackageAvailable packageName : flags
517{
518	# for a secondary architecture adjust the package name
519	if $(TARGET_PACKAGING_ARCH) != $(TARGET_PACKAGING_ARCHS[1])
520		&& ! nameResolved in $(flags) {
521		# The position of the secondary architecture within the package name
522		# is not well defined, so we scan for it starting from the back.
523		local packageNameHead = $(packageName) ;
524		local packageNameTail = ;
525		while $(packageNameHead) {
526			local splitName = [ FSplitPackageName $(packageNameHead) ] ;
527			splitName = $(splitName[1]) $(TARGET_PACKAGING_ARCH) $(splitName[2])
528				$(packageNameTail) ;
529			packageName = $(splitName:J=_) ;
530			if $(packageName) in $(HAIKU_AVAILABLE_PACKAGES) {
531				return $(packageName) ;
532			}
533			local splitHead = [ Match "(.*)_([^_]*)" : $(packageNameHead) ] ;
534			packageNameHead = $(splitHead[1]) ;
535			packageNameTail = $(splitHead[2]) $(packageNameTail) ;
536		}
537	}
538
539	if $(packageName) in $(HAIKU_AVAILABLE_PACKAGES) {
540		return $(packageName) ;
541	}
542
543	return ;
544}
545
546
547rule FetchPackage packageName : flags
548{
549	local foundPackageName = [ IsPackageAvailable $(packageName) : $(flags) ] ;
550	if ! $(foundPackageName) {
551		Exit "FetchPackage: package" $(packageName) "not available!" ;
552		return ;
553	}
554	packageName = $(foundPackageName) ;
555
556	# TODO: We should support explicitly specified versions (or partial/minimum
557	# versions like gcc-2 or gcc-4).
558
559	local packageFamily = [ PackageFamily $(packageName) ] ;
560	local package
561		= [ on $(packageFamily) return $(HAIKU_PACKAGE_VERSIONS[1]) ] ;
562	local fileName = [ on $(package) return $(HAIKU_PACKAGE_FILE_NAME) ] ;
563	local repository = [ on $(package) return $(HAIKU_PACKAGE_REPOSITORY) ] ;
564
565	if $(HAIKU_DONT_FETCH_PACKAGES) {
566		Exit "FetchPackage: file" $(fileName) "not found and fetching"
567			"disabled!" ;
568		return ;
569	}
570
571	return [ InvokeRepositoryMethod $(repository) : FetchPackage : $(package)
572		: $(fileName) ] ;
573}
574
575
576rule BuildHaikuPortsSourcePackageDirectory
577{
578	local architecture = $(TARGET_PACKAGING_ARCH) ;
579	local outputDir = [ FDirName
580		$(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture))
581		HaikuPorts-sources-build ] ;
582
583	local sourcePackageDir = <HaikuPorts-repository-source-packages>packages ;
584	MakeLocate $(sourcePackageDir) : $(outputDir) ;
585
586	# build the package list file
587	local packageList
588		= <repository-package-list-HaikuPorts-sources>package_list ;
589	MakeLocate $(packageList) : $(outputDir) ;
590	Depends $(packageList) :
591		[ FDirName $(HAIKU_BUILD_RULES_DIR) repositories HaikuPorts
592			$(architecture) ] ;
593	BuildHaikuPortsPackageList $(packageList) ;
594
595	# prepare the config file for the HaikuPorts build
596	local configFile = <repository-config-HaikuPorts-sources>haikuports.conf ;
597	MakeLocate $(configFile) : $(outputDir) ;
598	NoUpdate $(configFile) ;
599	Depends $(configFile) : <build>package <build>mimeset <mimedb>mime_db ;
600	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(configFile) = $(outputDir) ;
601	HAIKU_PACKAGING_ARCH on $(configFile) = $(architecture) ;
602	HAIKU_REPOSITORY_TREE_PATH on $(configFile) = $(HAIKU_PORTS) ;
603	BuildBootstrapRepositoryConfig $(configFile)
604		: <build>package <build>mimeset <mimedb>mime_db ;
605
606	# get Haiku cross-devel packages and build the sources
607	local crossDevelPackageSuffixes = $(architecture)
608		$(architecture)_$(HAIKU_PACKAGING_ARCHS[2-]) ;
609	local haikuCrossDevelPackages
610		= haiku_cross_devel_sysroot_stage1_$(crossDevelPackageSuffixes).hpkg ;
611
612	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(sourcePackageDir) = $(outputDir) ;
613
614	Depends $(sourcePackageDir) : $(packageList) $(haikuCrossDevelPackages)
615		$(configFile) ;
616	BuildHaikuPortsSourcePackageDirectory1 $(sourcePackageDir)
617		: $(packageList) $(haikuCrossDevelPackages) ;
618
619	return $(sourcePackageDir) ;
620}
621
622
623actions BuildHaikuPortsPackageList
624{
625	$(JAM:E=jam) $(HAIKU_BOOTSTRAP_SOURCES_PROFILE) build-package-list $(1) \
626		$(HAIKU_REPOSITORY_BUILD_ADDITIONAL_PACKAGES)
627}
628
629
630actions BuildHaikuPortsSourcePackageDirectory1
631{
632	packageList="$(2[1])"
633
634	# make Haiku cross devel package path absolute
635	haikuCrossDevelPackage="$(2[2])"
636	if [ "x$haikuCrossDevelPackage" = "x${haikuCrossDevelPackage#/}" ]; then
637		haikuCrossDevelPackage="`pwd`/$haikuCrossDevelPackage"
638	fi
639
640	# make secondary Haiku cross devel packages path absolute
641	secondaryCrossDevelPackages=
642	if [ -n "$(2[3-]:J)" ]; then
643		for secondaryCrossDevelPackage in "$(2[3-])" ; do
644			if [ "x$secondaryCrossDevelPackage" = "x${secondaryCrossDevelPackage#/}" ]; then
645				secondaryCrossDevelPackage="`pwd`/$secondaryCrossDevelPackage"
646			fi
647			if [ -n "$secondaryCrossDevelPackages" ]; then
648				secondaryCrossDevelPackages="$secondaryCrossDevelPackages,$secondaryCrossDevelPackage"
649			else
650				secondaryCrossDevelPackages="--secondary-cross-devel-package=$secondaryCrossDevelPackage"
651			fi
652		done
653	fi
654
655	cd $(HAIKU_REPOSITORY_BUILD_DIRECTORY)
656
657	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
658	if [ -n "$secondaryCrossDevelPackages" ]; then
659		$(HOST_HAIKU_PORTER) --cross-devel-package "$haikuCrossDevelPackage" \
660			"$secondaryCrossDevelPackages" \
661			--all-dependencies $(HAIKU_PORTER_EXTRA_OPTIONS) \
662			--create-source-packages-for-bootstrap --portsfile $packageList
663	else
664		$(HOST_HAIKU_PORTER) --cross-devel-package "$haikuCrossDevelPackage" \
665			--all-dependencies $(HAIKU_PORTER_EXTRA_OPTIONS) \
666			--create-source-packages-for-bootstrap --portsfile $packageList
667	fi
668}
669
670
671rule BuildHaikuPortsRepositoryConfig treePath
672{
673	local architecture = $(TARGET_PACKAGING_ARCH) ;
674	local outputDir = [ FDirName
675		$(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture))
676		HaikuPorts-bootstrap ] ;
677
678	local configFile = <repository-config-HaikuPorts-bootstrap>haikuports.conf ;
679	MakeLocate $(configFile) : $(outputDir) ;
680	NoUpdate $(configFile) ;
681
682	HAIKU_REPOSITORY_TREE_PATH on $(configFile) = $(treePath) ;
683	BuildHaikuPortsRepositoryConfig1 $(configFile) ;
684
685	return $(configFile) ;
686}
687
688
689actions BuildHaikuPortsRepositoryConfig1
690{
691	# use a specific packager for continuous integration builds (buildbot)
692	if [ "$(HAIKU_CONTINUOUS_INTEGRATION_BUILD)" = "1" ]; then
693		echo 'PACKAGER="Haiku buildmaster <buildmaster@haiku-os.org>"' > $(1)
694	else
695		echo '#PACKAGER="Joe Hacker <user@host.com>"' > $(1)
696	fi
697	cat >> $(1) << EOF
698TREE_PATH="$(HAIKU_REPOSITORY_TREE_PATH)"
699TARGET_ARCHITECTURE="$(HAIKU_PACKAGING_ARCH)"
700EOF
701}
702
703
704rule HaikuRepository repository : repoInfoTemplate : packages
705{
706	# HaikuRepository <repository> : <repoInfoTemplate> : <packages>
707	#	[ : <url> [ : <versionFile> ] ] ;
708	# Builds the Haiku repository from the given packages and repository info
709	# template. <repository> must already be located.
710	#
711	# <repository> - The repository target. Resolves to a directory that will be
712	#	(removed,) created and populated with the package files and repository
713	#	meta data files.
714	# <repoInfoTemplate> - The repository info template file to be used.
715	# <packages> - The packages to be added to the repository.
716
717	local architecture = $(HAIKU_PACKAGING_ARCH) ;
718	local secondaryArchitecture ;
719	if $(TARGET_PACKAGING_ARCH) != $(architecture) {
720		secondaryArchitecture = $(TARGET_PACKAGING_ARCH) ;
721	}
722
723	local repositoriesDir = $(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture)) ;
724
725	# build the repository info
726	local repositoryInfo = $(repository:G=repository-info)-info ;
727	MakeLocate $(repositoryInfo) : $(repositoriesDir) ;
728	PreprocessPackageOrRepositoryInfo $(repositoryInfo) : $(repoInfoTemplate)
729		: $(architecture) : $(secondaryArchitecture) ;
730
731	# build the respository config
732	local repositoryConfig = $(repository:G=repository-config)-config ;
733	MakeLocate $(repositoryConfig) : $(repositoriesDir) ;
734	RepositoryConfig $(repositoryConfig) : $(repositoryInfo) ;
735	HAIKU_REPOSITORY_CONFIG_FILE on $(repository) = $(repositoryConfig) ;
736
737	# setup the repository cache file
738	local repositoryCache = $(repository:B=repo:G=repository-cache) ;
739	MakeLocate $(repositoryCache)
740		: [ FDirName $(repositoriesDir) $(repository:G=) ] ;
741	Depends $(repositoryCache) : $(repository) ;
742	HAIKU_REPOSITORY_CACHE_FILE on $(repository) = $(repositoryCache) ;
743
744	# add the repository to the list of known package repositories
745	HAIKU_REPOSITORIES += $(repository) ;
746
747	# prepare the script that initializes the shell variables
748	local initVariablesScript = $(repository)-repository-init-vars ;
749	MakeLocate $(initVariablesScript)
750		: $(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture)) ;
751	Always $(initVariablesScript) ;
752
753	local script = $(initVariablesScript) ;
754	AddVariableToScript $(script) : addBuildCompatibilityLibDir
755		: $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ;
756	AddVariableToScript $(script) : sha256 : $(HOST_SHA256) ;
757	AddVariableToScript $(script) : sedExtendedRegex
758		: $(HOST_EXTENDED_REGEX_SED) ;
759	AddTargetVariableToScript $(script) : <build>package ;
760	AddTargetVariableToScript $(script) : <build>package_repo : packageRepo ;
761
762	# call the build actions
763	local mainScript = build_haiku_repository ;
764	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
765
766	Depends $(repository) : $(mainScript) $(initVariablesScript)
767		$(repositoryInfo) $(packages) ;
768	HaikuRepository1 $(repository) : $(mainScript) $(initVariablesScript)
769		$(repositoryInfo) $(packages) ;
770	Always $(repository) ;
771
772	RmTemps $(repository) : $(initVariablesScript) ;
773}
774
775
776actions HaikuRepository1
777{
778	$(2[1]) "$(2[2])" "$(1)" "$(2[3-])"
779}
780