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