RepositoryRules revision 2ae3c649
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 {
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	MakeLocate $(packagesChecksumFile) : $(repositoriesDir) ;
164	Depends $(packagesChecksumFile) : $(packageListFile) ;
165	ChecksumFileSHA256 $(packagesChecksumFile) : $(packageListFile) ;
166
167	local repositoryInfo = $(repository:G=repository-info)-info ;
168	local repositoryFile = $(repository:G=repository-cache) ;
169	local repositoryConfig = $(repository:G=repository-config)-config ;
170	MakeLocate $(repositoryInfo) $(repositoryFile) $(repositoryConfig)
171		: $(repositoriesDir) ;
172	# Use a locally created dummy repository if downloads have been disabled.
173	# This is useful when trying to build everything locally from source.
174	if $(HAIKU_NO_DOWNLOADS) = 1 {
175		# build the dummy repository info file
176		local repositoryInfoTemplate = <repository-info-template>haikuports ;
177		SEARCH on $(repositoryInfoTemplate)
178			= $(HAIKU_TOP)/src/data/repository_infos ;
179		PreprocessPackageOrRepositoryInfo $(repositoryInfo)
180			: $(repositoryInfoTemplate) : $(architecture) ;
181
182		# build repository file
183		local packageFileNames = [
184			on $(packageListFile) return $(HAIKU_REPOSITORY_PACKAGE_FILE_NAMES)
185		] ;
186		local packageFiles ;
187		for packageFile in $(packageFileNames) {
188			MakeLocate $(packageFile) : $(HAIKU_DOWNLOAD_DIR) ;
189			packageFiles += $(packageFile) ;
190		}
191		RepositoryCache $(repositoryFile) : $(repositoryInfo)
192			: $(packageFiles) ;
193	} else {
194		# download repository info file
195		local repoUrl = [ on $(repository) return $(HAIKU_REPOSITORY_URL) ] ;
196		DownloadLocatedFile $(repositoryInfo)
197			: "$(repoUrl)/`cat $source`/repo.info"
198			: $(packagesChecksumFile) ;
199
200		# download repository file
201		DownloadLocatedFile $(repositoryFile)
202			: "$(repoUrl)/`cat $source`/repo"
203			: $(packagesChecksumFile) ;
204	}
205
206	# build repository config file
207	RepositoryConfig $(repositoryConfig) : $(repositoryInfo)
208		: $(repositoryUrl)/$version : $(packagesChecksumFile) ;
209
210	HAIKU_REPOSITORY_CACHE_FILE on $(repository) = $(repositoryFile) ;
211	HAIKU_REPOSITORY_CONFIG_FILE on $(repository) = $(repositoryConfig) ;
212	HAIKU_REPOSITORY_PACKAGES_CHECKSUM_FILE on $(repository)
213		= $(packagesChecksumFile) ;
214}
215
216
217rule GeneratedRepositoryPackageList target : repository
218{
219	repository = $(repository:G=repository) ;
220
221	# construct a list of file names
222	local fileNames ;
223	local package ;
224	for package in [ on $(repository) return $(HAIKU_REPOSITORY_PACKAGES) ] {
225		fileNames += [ on $(package) return $(HAIKU_PACKAGE_FILE_NAME) ] ;
226	}
227
228	local definitionFile
229		= [ on $(repository) return $(HAIKU_REPOSITORY_DEFINITION_FILE) ] ;
230	Depends $(target) : $(definitionFile) ;
231
232	HAIKU_REPOSITORY_PACKAGE_FILE_NAMES on $(target) = $(fileNames) ;
233	GeneratedRepositoryPackageList1 $(target) ;
234}
235
236
237actions GeneratedRepositoryPackageList1
238{
239	(for file in $(HAIKU_REPOSITORY_PACKAGE_FILE_NAMES) ; do
240		echo $file
241	done) | LC_ALL=C sort -u > $(1)
242}
243
244
245rule RepositoryConfig repoConfig : repoInfo : url : versionFile
246{
247	HAIKU_REPOSITORY_URL on $(repoConfig) = $(url) ;
248	Depends $(repoConfig)
249		: <build>create_repository_config $(repoInfo) $(versionFile) ;
250	RepositoryConfig1 $(repoConfig)
251		: <build>create_repository_config $(repoInfo) $(versionFile) ;
252}
253
254
255actions RepositoryConfig1
256{
257	version=
258	if [ -n "$(2[3]:E)" ]; then
259		version=`cat "$(2[3]:E)"`
260	fi
261	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
262	$(2[1]) $(HAIKU_REPOSITORY_URL) $(2[2]) $(1)
263}
264
265
266rule RepositoryCache repoCache : repoInfo : packageFiles
267{
268	Depends $(repoCache)
269		: <build>package_repo $(repoInfo) $(packageFiles) ;
270	RepositoryCache1 $(repoCache)
271		: <build>package_repo $(repoInfo) $(packageFiles) ;
272}
273
274
275actions RepositoryCache1
276{
277	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
278	$(2[1]) create -q $(2[2-])
279	mv $(1:B=repo) $(1)
280}
281
282
283#pragma mark - Bootstrap Repository
284
285
286rule BootstrapRepositoryPackageFamily repository : packageBaseName
287{
288	local splitBaseName = [ Match "(.*)_bootstrap(.*)" : $(packageBaseName) ] ;
289	if $(splitBaseName) {
290		packageBaseName = $(splitBaseName[1])$(splitBaseName[2]) ;
291	}
292
293	return [ PackageFamily $(packageBaseName) ] ;
294}
295
296
297rule BootstrapRepositoryFetchPackage repository : package : fileName
298{
299	local outputDir
300		= [ on $(repository) return $(HAIKU_REPOSITORY_BUILD_DIRECTORY) ] ;
301	local configFile
302		= [ on $(repository) return $(HAIKU_REPOSITORY_BUILD_CONFIG_FILE) ] ;
303	local haikuCrossDevelPackages = [ on $(package)
304		return $(HAIKU_REPOSITORY_HAIKU_CROSS_DEVEL_PACKAGES) ] ;
305
306	local packageFile = <cross-built>$(fileName) ;
307	if [ on $(packageFile) return $(HAIKU_REPOSITORY_BUILD_DIRECTORY) ] {
308		# rule already called for this package
309		return $(packageFile) ;
310	}
311
312	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(packageFile) = $(outputDir) ;
313
314	MakeLocate $(packageFile) : [ FDirName $(outputDir) packages ] ;
315	NoUpdate $(packageFile) ;
316		# Don't rebuild the file. Since the haiku cross devel package is
317		# a dependency and is updated always, this package would otherwise be
318		# rebuilt always as well.
319
320	Depends $(packageFile) : $(haikuCrossDevelPackages) $(configFile) ;
321	BootstrapRepositoryFetchPackage1 $(packageFile)
322		: $(haikuCrossDevelPackages) ;
323
324	return $(packageFile) ;
325}
326
327
328actions BootstrapRepositoryFetchPackage1
329{
330	# don't rebuild existing package
331	package="$(1)"
332	if [ -e "$package" ]; then
333		exit 0
334	fi
335
336	# make Haiku cross devel package path absolute
337	haikuCrossDevelPackage="$(2[1])"
338	if [ "x$haikuCrossDevelPackage" = "x${haikuCrossDevelPackage#/}" ]; then
339		haikuCrossDevelPackage="`pwd`/$haikuCrossDevelPackage"
340	fi
341
342	# make secondary Haiku cross devel packages path absolute
343	secondaryCrossDevelPackages=
344	if [ -n "$(2[2-]:J)" ]; then
345		for secondaryCrossDevelPackage in "$(2[2-])" ; do
346			if [ "x$secondaryCrossDevelPackage" = "x${secondaryCrossDevelPackage#/}" ]; then
347				secondaryCrossDevelPackage="`pwd`/$secondaryCrossDevelPackage"
348			fi
349			if [ -n "$secondaryCrossDevelPackages" ]; then
350				secondaryCrossDevelPackages="secondaryCrossDevelPackages,$secondaryCrossDevelPackage"
351			else
352				secondaryCrossDevelPackages="--secondary-cross-devel-package=$secondaryCrossDevelPackage"
353			fi
354		done
355	fi
356
357	# determine the portName
358	portName=`basename "$package" | sed 's@-.*@@'`
359	case $portName in
360		*_devel|*_doc|*_source|*_debuginfo)
361			portName=`echo $portName | sed 's@_[^_]*$@@'`
362			;;
363		*_source_rigged)
364			portName=`echo $portName | sed 's@_source_rigged$@@'`
365			;;
366	esac
367
368	cd $(HAIKU_REPOSITORY_BUILD_DIRECTORY)
369
370	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
371	if [ -n "$secondaryCrossDevelPackages" ]; then
372		$(HOST_HAIKU_PORTER) -j$(HAIKU_PORTER_CONCURRENT_JOBS) \
373			$(HAIKU_PORTER_EXTRA_OPTIONS) \
374			--cross-devel-package "$haikuCrossDevelPackage" \
375			"$secondaryCrossDevelPackages" $portName
376	else
377		$(HOST_HAIKU_PORTER) -j$(HAIKU_PORTER_CONCURRENT_JOBS) \
378			$(HAIKU_PORTER_EXTRA_OPTIONS) \
379			--cross-devel-package "$haikuCrossDevelPackage" $portName
380	fi
381}
382
383
384actions BuildBootstrapRepositoryConfig
385{
386cat > $(1) << EOF
387PACKAGER="The Haiku build system <build-system@haiku-os.org>"
388TREE_PATH="$(HAIKU_REPOSITORY_TREE_PATH)"
389TARGET_ARCHITECTURE="$(HAIKU_PACKAGING_ARCH)"
390
391DOWNLOAD_IN_PORT_DIRECTORY="yes"
392PACKAGE_COMMAND="$(2[1])"
393MIMESET_COMMAND="$(2[2])"
394SYSTEM_MIME_DB="$(2[3])"
395LICENSES_DIRECTORY="$(HAIKU_TOP)/data/system/data/licenses"
396OUTPUT_DIRECTORY="$(HAIKU_REPOSITORY_BUILD_DIRECTORY)"
397EOF
398
399	# If we have cross tools, add the cross tools directory.
400	gcc=$(HAIKU_CC_$(HAIKU_PACKAGING_ARCH))
401	if [ "x$gcc" != "x${gcc#/}" ]; then
402		if [ `basename $gcc` = \
403				$(HAIKU_GCC_MACHINE_$(HAIKU_PACKAGING_ARCH))-gcc ]; then
404			dir=`dirname $gcc`
405			dir=`dirname $dir`
406			echo CROSS_TOOLS=\"$dir\" >> $(1)
407		fi
408	fi
409
410	# Add secondary architectures and cross tools.
411	secondaryArchs="$(HAIKU_PACKAGING_ARCHS[2-]:E=)"
412	if [ -n "$secondaryArchs" ]; then
413		echo SECONDARY_TARGET_ARCHITECTURES=\" >> $(1)
414		for arch in $secondaryArchs; do
415			echo "  $arch" >> $(1)
416		done
417		echo \" >> $(1)
418
419		echo SECONDARY_CROSS_TOOLS=\" >> $(1)
420		for gcc in $(HAIKU_CC_$(HAIKU_PACKAGING_ARCHS[2-])) ; do
421			dir=`dirname $gcc`
422			dir=`dirname $dir`
423			echo "  $dir" >> $(1)
424		done
425		echo \" >> $(1)
426	fi
427}
428
429
430rule BootstrapPackageRepository repository : architecture
431	: anyPackages : packagesStage1 : packagesStage2 : sourcePackages
432	: debugInfoPackages
433{
434	repository = $(repository:G=repository) ;
435	packagesStage1 = [ FFilterByBuildFeatures $(packagesStage1) ] ;
436	packagesStage2 = [ FFilterByBuildFeatures $(packagesStage2) ] ;
437	sourcePackages = [ FFilterByBuildFeatures $(sourcePackages) ] ;
438	debugInfoPackages = [ FFilterByBuildFeatures $(debugInfoPackages) ] ;
439
440	SetRepositoryMethod $(repository) : PackageFamily
441		: BootstrapRepositoryPackageFamily ;
442	SetRepositoryMethod $(repository) : FetchPackage
443		: BootstrapRepositoryFetchPackage ;
444
445	# register repository with stage 1 packages
446	local stage1PackageTargets = [ PackageRepository $(repository)
447		: $(architecture) : $(anyPackages) : $(packagesStage1)
448		: $(sourcePackages) : $(debugInfoPackages) ] ;
449	if ! $(stage1PackageTargets) {
450		return ;
451	}
452	local crossDevelPackageSuffixes = $(architecture)
453		$(architecture)_$(HAIKU_PACKAGING_ARCHS[2-]) ;
454	HAIKU_REPOSITORY_HAIKU_CROSS_DEVEL_PACKAGES on $(stage1PackageTargets)
455		= haiku_cross_devel_sysroot_stage1_$(crossDevelPackageSuffixes).hpkg ;
456
457	# add stage 2 packages
458	local stage2PackageTargets = [ AddRepositoryPackages $(repository)
459		: $(architecture) : $(packagesStage2) : $(sourcePackages)
460		: $(debugInfoPackages) ] ;
461	HAIKU_REPOSITORY_HAIKU_CROSS_DEVEL_PACKAGES on $(stage2PackageTargets)
462		= haiku_cross_devel_sysroot_$(crossDevelPackageSuffixes).hpkg ;
463
464	# prepare the config file for the HaikuPorts cross build
465	local outputDir = [ FDirName
466		$(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture))
467		$(repository:G=)-build ] ;
468	local configFile = haikuports.conf ;
469	configFile = $(configFile:G=repository-config-$(repository:G=)) ;
470	MakeLocate $(configFile) : $(outputDir) ;
471	NoUpdate $(configFile) ;
472	Depends $(configFile) : <build>package <build>mimeset <mimedb>mime_db ;
473	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(configFile) = $(outputDir) ;
474	HAIKU_PACKAGING_ARCH on $(configFile) = $(architecture) ;
475	HAIKU_REPOSITORY_TREE_PATH on $(configFile) = $(HAIKU_PORTS_CROSS) ;
476	BuildBootstrapRepositoryConfig $(configFile)
477		: <build>package <build>mimeset <mimedb>mime_db ;
478
479	HAIKU_REPOSITORY_BUILD_CONFIG_FILE on $(repository) = $(configFile) ;
480	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(repository) = $(outputDir) ;
481
482	# Serialize all package file targets. We need to do this, since
483	# haikuporter uses a common directory for building the ports, so building
484	# two ports concurrently isn't possible.
485	local previousPackageFile ;
486	local package ;
487	for package in $(stage1PackageTargets) $(stage2PackageTargets) {
488		local fileName = [ on $(package) return $(HAIKU_PACKAGE_FILE_NAME) ] ;
489		local packageFile = [ BootstrapRepositoryFetchPackage $(repository)
490			: $(package) : $(fileName) ] ;
491		Depends $(packageFile) : $(previousPackageFile) ;
492
493		previousPackageFile = $(packageFile) ;
494	}
495}
496
497
498#pragma mark - Public
499
500
501rule FSplitPackageName packageName
502{
503	local splitName = [ Match "(.*)_([^_]*)" : $(packageName) ] ;
504	local knownPackageSuffixes = devel doc source debuginfo ;
505	if $(splitName[2]) && $(splitName[2]) in $(knownPackageSuffixes) {
506		return $(splitName) ;
507	}
508
509	return $(packageName) ;
510}
511
512
513rule IsPackageAvailable packageName : flags
514{
515	# for a secondary architecture adjust the package name
516	if $(TARGET_PACKAGING_ARCH) != $(TARGET_PACKAGING_ARCHS[1])
517		&& ! nameResolved in $(flags) {
518		# The position of the secondary architecture within the package name
519		# is not well defined, so we scan for it starting from the back.
520		local packageNameHead = $(packageName) ;
521		local packageNameTail = ;
522		while $(packageNameHead) {
523			local splitName = [ FSplitPackageName $(packageNameHead) ] ;
524			splitName = $(splitName[1]) $(TARGET_PACKAGING_ARCH) $(splitName[2])
525				$(packageNameTail) ;
526			packageName = $(splitName:J=_) ;
527			if $(packageName) in $(HAIKU_AVAILABLE_PACKAGES) {
528				return $(packageName) ;
529			}
530			local splitHead = [ Match "(.*)_([^_]*)" : $(packageNameHead) ] ;
531			packageNameHead = $(splitHead[1]) ;
532			packageNameTail = $(splitHead[2]) $(packageNameTail) ;
533		}
534	}
535
536	if $(packageName) in $(HAIKU_AVAILABLE_PACKAGES) {
537		return $(packageName) ;
538	}
539
540	return ;
541}
542
543
544rule FetchPackage packageName : flags
545{
546	local foundPackageName = [ IsPackageAvailable $(packageName) : $(flags) ] ;
547	if ! $(foundPackageName) {
548		Exit "FetchPackage: package" $(packageName) "not available!" ;
549		return ;
550	}
551	packageName = $(foundPackageName) ;
552
553	# TODO: We should support explicitly specified versions (or partial/minimum
554	# versions like gcc-2 or gcc-4).
555
556	local packageFamily = [ PackageFamily $(packageName) ] ;
557	local package
558		= [ on $(packageFamily) return $(HAIKU_PACKAGE_VERSIONS[1]) ] ;
559	local fileName = [ on $(package) return $(HAIKU_PACKAGE_FILE_NAME) ] ;
560	local repository = [ on $(package) return $(HAIKU_PACKAGE_REPOSITORY) ] ;
561
562	if $(HAIKU_DONT_FETCH_PACKAGES) {
563		Exit "FetchPackage: file" $(fileName) "not found and fetching"
564			"disabled!" ;
565		return ;
566	}
567
568	return [ InvokeRepositoryMethod $(repository) : FetchPackage : $(package)
569		: $(fileName) ] ;
570}
571
572
573rule BuildHaikuPortsSourcePackageDirectory
574{
575	local architecture = $(TARGET_PACKAGING_ARCH) ;
576	local outputDir = [ FDirName
577		$(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture))
578		HaikuPorts-sources-build ] ;
579
580	local sourcePackageDir = <HaikuPorts-repository-source-packages>packages ;
581	MakeLocate $(sourcePackageDir) : $(outputDir) ;
582
583	# build the package list file
584	local packageList
585		= <repository-package-list-HaikuPorts-sources>package_list ;
586	MakeLocate $(packageList) : $(outputDir) ;
587	Depends $(packageList) :
588		[ FDirName $(HAIKU_BUILD_RULES_DIR) repositories HaikuPorts
589			$(architecture) ] ;
590	BuildHaikuPortsPackageList $(packageList) ;
591
592	# prepare the config file for the HaikuPorts build
593	local configFile = <repository-config-HaikuPorts-sources>haikuports.conf ;
594	MakeLocate $(configFile) : $(outputDir) ;
595	NoUpdate $(configFile) ;
596	Depends $(configFile) : <build>package <build>mimeset <mimedb>mime_db ;
597	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(configFile) = $(outputDir) ;
598	HAIKU_PACKAGING_ARCH on $(configFile) = $(architecture) ;
599	HAIKU_REPOSITORY_TREE_PATH on $(configFile) = $(HAIKU_PORTS) ;
600	BuildBootstrapRepositoryConfig $(configFile)
601		: <build>package <build>mimeset <mimedb>mime_db ;
602
603	# get Haiku cross-devel packages and build the sources
604	local crossDevelPackageSuffixes = $(architecture)
605		$(architecture)_$(HAIKU_PACKAGING_ARCHS[2-]) ;
606	local haikuCrossDevelPackages
607		= haiku_cross_devel_sysroot_stage1_$(crossDevelPackageSuffixes).hpkg ;
608
609	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(sourcePackageDir) = $(outputDir) ;
610
611	Depends $(sourcePackageDir) : $(packageList) $(haikuCrossDevelPackages)
612		$(configFile) ;
613	BuildHaikuPortsSourcePackageDirectory1 $(sourcePackageDir)
614		: $(packageList) $(haikuCrossDevelPackages) ;
615
616	return $(sourcePackageDir) ;
617}
618
619
620actions BuildHaikuPortsPackageList
621{
622	$(JAM:E=jam) $(HAIKU_BOOTSTRAP_SOURCES_PROFILE) build-package-list $(1) \
623		$(HAIKU_REPOSITORY_BUILD_ADDITIONAL_PACKAGES)
624}
625
626
627actions BuildHaikuPortsSourcePackageDirectory1
628{
629	packageList="$(2[1])"
630
631	# make Haiku cross devel package path absolute
632	haikuCrossDevelPackage="$(2[2])"
633	if [ "x$haikuCrossDevelPackage" = "x${haikuCrossDevelPackage#/}" ]; then
634		haikuCrossDevelPackage="`pwd`/$haikuCrossDevelPackage"
635	fi
636
637	# make secondary Haiku cross devel packages path absolute
638	secondaryCrossDevelPackages=
639	if [ -n "$(2[3-]:J)" ]; then
640		for secondaryCrossDevelPackage in "$(2[3-])" ; do
641			if [ "x$secondaryCrossDevelPackage" = "x${secondaryCrossDevelPackage#/}" ]; then
642				secondaryCrossDevelPackage="`pwd`/$secondaryCrossDevelPackage"
643			fi
644			if [ -n "$secondaryCrossDevelPackages" ]; then
645				secondaryCrossDevelPackages="secondaryCrossDevelPackages,$secondaryCrossDevelPackage"
646			else
647				secondaryCrossDevelPackages="--secondary-cross-devel-package=$secondaryCrossDevelPackage"
648			fi
649		done
650	fi
651
652	cd $(HAIKU_REPOSITORY_BUILD_DIRECTORY)
653
654	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
655	if [ -n "$secondaryCrossDevelPackages" ]; then
656		$(HOST_HAIKU_PORTER) --cross-devel-package "$haikuCrossDevelPackage" \
657			"$secondaryCrossDevelPackages" \
658			$(HAIKU_PORTER_EXTRA_OPTIONS) \
659			--create-source-packages-for-bootstrap --portsfile $packageList
660	else
661		$(HOST_HAIKU_PORTER) --cross-devel-package "$haikuCrossDevelPackage" \
662			$(HAIKU_PORTER_EXTRA_OPTIONS) \
663			--create-source-packages-for-bootstrap --portsfile $packageList
664	fi
665}
666
667
668rule BuildHaikuPortsRepositoryConfig treePath
669{
670	local architecture = $(TARGET_PACKAGING_ARCH) ;
671	local outputDir = [ FDirName
672		$(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture))
673		HaikuPorts-bootstrap ] ;
674
675	local configFile = <repository-config-HaikuPorts-bootstrap>haikuports.conf ;
676	MakeLocate $(configFile) : $(outputDir) ;
677	NoUpdate $(configFile) ;
678
679	HAIKU_REPOSITORY_TREE_PATH on $(configFile) = $(treePath) ;
680	BuildHaikuPortsRepositoryConfig1 $(configFile) ;
681
682	return $(configFile) ;
683}
684
685
686actions BuildHaikuPortsRepositoryConfig1
687{
688	# use a specific packager for continuous integration builds (buildbot)
689	if [ "$(HAIKU_CONTINUOUS_INTEGRATION_BUILD)" = "1" ]; then
690		echo 'PACKAGER="Haiku buildmaster <buildmaster@haiku-os.org>"' > $(1)
691	else
692		echo '#PACKAGER="Joe Hacker <user@host.com>"' > $(1)
693	fi
694	cat >> $(1) << EOF
695TREE_PATH="$(HAIKU_REPOSITORY_TREE_PATH)"
696TARGET_ARCHITECTURE="$(HAIKU_PACKAGING_ARCH)"
697EOF
698}
699
700
701rule UploadPackages target : packages
702{
703	local packageListFile = <repository-package-list>HaikuPorts-packages ;
704	Depends $(target) : $(packageListFile) ;
705
706	HAIKU_REMOTE_REPOSITORY_PACKAGES on $(target) = $(packages) ;
707	UploadPackages1 $(target) : $(packageListFile) ;
708}
709
710
711actions UploadPackages1
712{
713	remote=git.haiku-os.org
714	remoteUser=$(HAIKU_REMOTE_USER)
715	if [ -n "$remoteUser" ]; then
716		remote="$remoteUser@$remote"
717	fi
718
719	if [ -n "$(HAIKU_REMOTE_REPOSITORY_PACKAGES:E=:J)" ]; then
720		for package in $(HAIKU_REMOTE_REPOSITORY_PACKAGES) ; do
721			file=`basename $package`
722			if ! grep -q $file $(2); then
723				echo "Error: $file is not being referenced in $(2)"
724				exit 1
725			fi
726		done
727		ssh $remote mkdir -p 'hpkg-upload'
728		scp $(HAIKU_REMOTE_REPOSITORY_PACKAGES) $remote:hpkg-upload/
729	fi
730}
731
732
733rule BuildRemoteHaikuPortsRepository target : packages
734{
735	UploadPackages $(target) : $(packages) ;
736
737	local packageListFile = <repository-package-list>HaikuPorts-packages ;
738	BuildRemoteHaikuPortsRepository1 $(target) : $(packageListFile) ;
739}
740
741
742actions BuildRemoteHaikuPortsRepository1
743{
744	remote=git.haiku-os.org
745	remoteUser=$(HAIKU_REMOTE_USER)
746	if [ -n "$remoteUser" ]; then
747		remote="$remoteUser@$remote"
748	fi
749
750	repoArch=$(TARGET_PACKAGING_ARCH)
751	scp $(2) $remote:hpkg-upload/$repoArch
752
753	cd $(HAIKU_TOP)
754	branch=`git branch | cut -c3-`
755
756	ssh $remote "build_repository_for_testing.sh $branch $repoArch"
757}
758
759
760rule HaikuRepository repository : repoInfoTemplate : packages
761{
762	# HaikuRepository <repository> : <repoInfoTemplate> : <packages>
763	#	[ : <url> [ : <versionFile> ] ] ;
764	# Builds the Haiku repository from the given packages and repository info
765	# template. <repository> must already be located.
766	#
767	# <repository> - The repository target. Resolves to a directory that will be
768	#	(removed,) created and populated with the package files and repository
769	#	meta data files.
770	# <repoInfoTemplate> - The repository info template file to be used.
771	# <packages> - The packages to be added to the repository.
772
773	local architecture = $(HAIKU_PACKAGING_ARCH) ;
774	local secondaryArchitecture ;
775	if $(TARGET_PACKAGING_ARCH) != $(architecture) {
776		secondaryArchitecture = $(TARGET_PACKAGING_ARCH) ;
777	}
778
779	local repositoriesDir = $(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture)) ;
780
781	# build the repository info
782	local repositoryInfo = $(repository:G=repository-info)-info ;
783	MakeLocate $(repositoryInfo) : $(repositoriesDir) ;
784	PreprocessPackageOrRepositoryInfo $(repositoryInfo) : $(repoInfoTemplate)
785		: $(architecture) : $(secondaryArchitecture) ;
786
787	# build the respository config
788	local repositoryConfig = $(repository:G=repository-config)-config ;
789	MakeLocate $(repositoryConfig) : $(repositoriesDir) ;
790	RepositoryConfig $(repositoryConfig) : $(repositoryInfo) ;
791	HAIKU_REPOSITORY_CONFIG_FILE on $(repository) = $(repositoryConfig) ;
792
793	# setup the repository cache file
794	local repositoryCache = $(repository:B=repo:G=repository-cache) ;
795	MakeLocate $(repositoryCache)
796		: [ FDirName $(repositoriesDir) $(repository:G=) ] ;
797	Depends $(repositoryCache) : $(repository) ;
798	HAIKU_REPOSITORY_CACHE_FILE on $(repository) = $(repositoryCache) ;
799
800	# add the repository to the list of known package repositories
801	HAIKU_REPOSITORIES += $(repository) ;
802
803	# prepare the script that initializes the shell variables
804	local initVariablesScript = $(repository)-repository-init-vars ;
805	MakeLocate $(initVariablesScript)
806		: $(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture)) ;
807	Always $(initVariablesScript) ;
808
809	local script = $(initVariablesScript) ;
810	AddVariableToScript $(script) : addBuildCompatibilityLibDir
811		: $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ;
812	AddVariableToScript $(script) : sha256 : $(HOST_SHA256) ;
813	AddVariableToScript $(script) : sedExtendedRegex
814		: $(HOST_EXTENDED_REGEX_SED) ;
815	AddTargetVariableToScript $(script) : <build>package ;
816	AddTargetVariableToScript $(script) : <build>package_repo : packageRepo ;
817
818	# call the build actions
819	local mainScript = build_haiku_repository ;
820	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
821
822	Depends $(repository) : $(mainScript) $(initVariablesScript)
823		$(repositoryInfo) $(packages) ;
824	HaikuRepository1 $(repository) : $(mainScript) $(initVariablesScript)
825		$(repositoryInfo) $(packages) ;
826	Always $(repository) ;
827
828	RmTemps $(repository) : $(initVariablesScript) ;
829}
830
831
832actions HaikuRepository1
833{
834	$(2[1]) "$(2[2])" "$(1)" "$(2[3-])"
835}
836