RepositoryRules revision 938bf9fa
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 portName
359	portName=`basename "$package" | sed 's@-.*@@'`
360	case $portName in
361		*_devel|*_doc|*_source|*_debuginfo)
362			portName=`echo $portName | sed 's@_[^_]*$@@'`
363			;;
364		*_source_rigged)
365			portName=`echo $portName | sed 's@_source_rigged$@@'`
366			;;
367	esac
368
369	cd $(HAIKU_REPOSITORY_BUILD_DIRECTORY)
370
371	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
372	if [ -n "$secondaryCrossDevelPackages" ]; then
373		$(HOST_HAIKU_PORTER) -j$(HAIKU_PORTER_CONCURRENT_JOBS) \
374			$(HAIKU_PORTER_EXTRA_OPTIONS) \
375			--cross-devel-package "$haikuCrossDevelPackage" \
376			"$secondaryCrossDevelPackages" $portName
377	else
378		$(HOST_HAIKU_PORTER) -j$(HAIKU_PORTER_CONCURRENT_JOBS) \
379			$(HAIKU_PORTER_EXTRA_OPTIONS) \
380			--cross-devel-package "$haikuCrossDevelPackage" $portName
381	fi
382}
383
384
385actions BuildBootstrapRepositoryConfig
386{
387cat > $(1) << EOF
388PACKAGER="The Haiku build system <build-system@haiku-os.org>"
389TREE_PATH="$(HAIKU_REPOSITORY_TREE_PATH)"
390TARGET_ARCHITECTURE="$(HAIKU_PACKAGING_ARCH)"
391
392DOWNLOAD_IN_PORT_DIRECTORY="yes"
393PACKAGE_COMMAND="$(2[1])"
394MIMESET_COMMAND="$(2[2])"
395SYSTEM_MIME_DB="$(2[3])"
396LICENSES_DIRECTORY="$(HAIKU_TOP)/data/system/data/licenses"
397OUTPUT_DIRECTORY="$(HAIKU_REPOSITORY_BUILD_DIRECTORY)"
398EOF
399
400	# If we have cross tools, add the cross tools directory.
401	gcc=$(HAIKU_CC_$(HAIKU_PACKAGING_ARCH))
402	if [ "x$gcc" != "x${gcc#/}" ]; then
403		if [ `basename $gcc` = \
404				$(HAIKU_GCC_MACHINE_$(HAIKU_PACKAGING_ARCH))-gcc ]; then
405			dir=`dirname $gcc`
406			dir=`dirname $dir`
407			echo CROSS_TOOLS=\"$dir\" >> $(1)
408		fi
409	fi
410
411	# Add secondary architectures and cross tools.
412	secondaryArchs="$(HAIKU_PACKAGING_ARCHS[2-]:E=)"
413	if [ -n "$secondaryArchs" ]; then
414		echo SECONDARY_TARGET_ARCHITECTURES=\" >> $(1)
415		for arch in $secondaryArchs; do
416			echo "  $arch" >> $(1)
417		done
418		echo \" >> $(1)
419
420		echo SECONDARY_CROSS_TOOLS=\" >> $(1)
421		for gcc in $(HAIKU_CC_$(HAIKU_PACKAGING_ARCHS[2-])) ; do
422			dir=`dirname $gcc`
423			dir=`dirname $dir`
424			echo "  $dir" >> $(1)
425		done
426		echo \" >> $(1)
427	fi
428}
429
430
431rule BootstrapPackageRepository repository : architecture
432	: anyPackages : packagesStage1 : packagesStage2 : sourcePackages
433	: debugInfoPackages
434{
435	repository = $(repository:G=repository) ;
436	packagesStage1 = [ FFilterByBuildFeatures $(packagesStage1) ] ;
437	packagesStage2 = [ FFilterByBuildFeatures $(packagesStage2) ] ;
438	sourcePackages = [ FFilterByBuildFeatures $(sourcePackages) ] ;
439	debugInfoPackages = [ FFilterByBuildFeatures $(debugInfoPackages) ] ;
440
441	SetRepositoryMethod $(repository) : PackageFamily
442		: BootstrapRepositoryPackageFamily ;
443	SetRepositoryMethod $(repository) : FetchPackage
444		: BootstrapRepositoryFetchPackage ;
445
446	# register repository with stage 1 packages
447	local stage1PackageTargets = [ PackageRepository $(repository)
448		: $(architecture) : $(anyPackages) : $(packagesStage1)
449		: $(sourcePackages) : $(debugInfoPackages) ] ;
450	if ! $(stage1PackageTargets) {
451		return ;
452	}
453	local crossDevelPackageSuffixes = $(architecture)
454		$(architecture)_$(HAIKU_PACKAGING_ARCHS[2-]) ;
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	local outputDir = [ FDirName
467		$(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture))
468		$(repository:G=)-build ] ;
469	local configFile = haikuports.conf ;
470	configFile = $(configFile:G=repository-config-$(repository:G=)) ;
471	MakeLocate $(configFile) : $(outputDir) ;
472	NoUpdate $(configFile) ;
473	Depends $(configFile) : <build>package <build>mimeset <mimedb>mime_db ;
474	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(configFile) = $(outputDir) ;
475	HAIKU_PACKAGING_ARCH on $(configFile) = $(architecture) ;
476	HAIKU_REPOSITORY_TREE_PATH on $(configFile) = $(HAIKU_PORTS_CROSS) ;
477	BuildBootstrapRepositoryConfig $(configFile)
478		: <build>package <build>mimeset <mimedb>mime_db ;
479
480	HAIKU_REPOSITORY_BUILD_CONFIG_FILE on $(repository) = $(configFile) ;
481	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(repository) = $(outputDir) ;
482
483	# Serialize all package file targets. We need to do this, since
484	# haikuporter uses a common directory for building the ports, so building
485	# two ports concurrently isn't possible.
486	local previousPackageFile ;
487	local package ;
488	for package in $(stage1PackageTargets) $(stage2PackageTargets) {
489		local fileName = [ on $(package) return $(HAIKU_PACKAGE_FILE_NAME) ] ;
490		local packageFile = [ BootstrapRepositoryFetchPackage $(repository)
491			: $(package) : $(fileName) ] ;
492		Depends $(packageFile) : $(previousPackageFile) ;
493
494		previousPackageFile = $(packageFile) ;
495	}
496}
497
498
499#pragma mark - Public
500
501
502rule FSplitPackageName packageName
503{
504	local splitName = [ Match "(.*)_([^_]*)" : $(packageName) ] ;
505	local knownPackageSuffixes = devel doc source debuginfo ;
506	if $(splitName[2]) && $(splitName[2]) in $(knownPackageSuffixes) {
507		return $(splitName) ;
508	}
509
510	return $(packageName) ;
511}
512
513
514rule IsPackageAvailable packageName : flags
515{
516	# for a secondary architecture adjust the package name
517	if $(TARGET_PACKAGING_ARCH) != $(TARGET_PACKAGING_ARCHS[1])
518		&& ! nameResolved in $(flags) {
519		# The position of the secondary architecture within the package name
520		# is not well defined, so we scan for it starting from the back.
521		local packageNameHead = $(packageName) ;
522		local packageNameTail = ;
523		while $(packageNameHead) {
524			local splitName = [ FSplitPackageName $(packageNameHead) ] ;
525			splitName = $(splitName[1]) $(TARGET_PACKAGING_ARCH) $(splitName[2])
526				$(packageNameTail) ;
527			packageName = $(splitName:J=_) ;
528			if $(packageName) in $(HAIKU_AVAILABLE_PACKAGES) {
529				return $(packageName) ;
530			}
531			local splitHead = [ Match "(.*)_([^_]*)" : $(packageNameHead) ] ;
532			packageNameHead = $(splitHead[1]) ;
533			packageNameTail = $(splitHead[2]) $(packageNameTail) ;
534		}
535	}
536
537	if $(packageName) in $(HAIKU_AVAILABLE_PACKAGES) {
538		return $(packageName) ;
539	}
540
541	return ;
542}
543
544
545rule FetchPackage packageName : flags
546{
547	local foundPackageName = [ IsPackageAvailable $(packageName) : $(flags) ] ;
548	if ! $(foundPackageName) {
549		Exit "FetchPackage: package" $(packageName) "not available!" ;
550		return ;
551	}
552	packageName = $(foundPackageName) ;
553
554	# TODO: We should support explicitly specified versions (or partial/minimum
555	# versions like gcc-2 or gcc-4).
556
557	local packageFamily = [ PackageFamily $(packageName) ] ;
558	local package
559		= [ on $(packageFamily) return $(HAIKU_PACKAGE_VERSIONS[1]) ] ;
560	local fileName = [ on $(package) return $(HAIKU_PACKAGE_FILE_NAME) ] ;
561	local repository = [ on $(package) return $(HAIKU_PACKAGE_REPOSITORY) ] ;
562
563	if $(HAIKU_DONT_FETCH_PACKAGES) {
564		Exit "FetchPackage: file" $(fileName) "not found and fetching"
565			"disabled!" ;
566		return ;
567	}
568
569	return [ InvokeRepositoryMethod $(repository) : FetchPackage : $(package)
570		: $(fileName) ] ;
571}
572
573
574rule BuildHaikuPortsSourcePackageDirectory
575{
576	local architecture = $(TARGET_PACKAGING_ARCH) ;
577	local outputDir = [ FDirName
578		$(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture))
579		HaikuPorts-sources-build ] ;
580
581	local sourcePackageDir = <HaikuPorts-repository-source-packages>packages ;
582	MakeLocate $(sourcePackageDir) : $(outputDir) ;
583
584	# build the package list file
585	local packageList
586		= <repository-package-list-HaikuPorts-sources>package_list ;
587	MakeLocate $(packageList) : $(outputDir) ;
588	Depends $(packageList) :
589		[ FDirName $(HAIKU_BUILD_RULES_DIR) repositories HaikuPorts
590			$(architecture) ] ;
591	BuildHaikuPortsPackageList $(packageList) ;
592
593	# prepare the config file for the HaikuPorts build
594	local configFile = <repository-config-HaikuPorts-sources>haikuports.conf ;
595	MakeLocate $(configFile) : $(outputDir) ;
596	NoUpdate $(configFile) ;
597	Depends $(configFile) : <build>package <build>mimeset <mimedb>mime_db ;
598	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(configFile) = $(outputDir) ;
599	HAIKU_PACKAGING_ARCH on $(configFile) = $(architecture) ;
600	HAIKU_REPOSITORY_TREE_PATH on $(configFile) = $(HAIKU_PORTS) ;
601	BuildBootstrapRepositoryConfig $(configFile)
602		: <build>package <build>mimeset <mimedb>mime_db ;
603
604	# get Haiku cross-devel packages and build the sources
605	local crossDevelPackageSuffixes = $(architecture)
606		$(architecture)_$(HAIKU_PACKAGING_ARCHS[2-]) ;
607	local haikuCrossDevelPackages
608		= haiku_cross_devel_sysroot_stage1_$(crossDevelPackageSuffixes).hpkg ;
609
610	HAIKU_REPOSITORY_BUILD_DIRECTORY on $(sourcePackageDir) = $(outputDir) ;
611
612	Depends $(sourcePackageDir) : $(packageList) $(haikuCrossDevelPackages)
613		$(configFile) ;
614	BuildHaikuPortsSourcePackageDirectory1 $(sourcePackageDir)
615		: $(packageList) $(haikuCrossDevelPackages) ;
616
617	return $(sourcePackageDir) ;
618}
619
620
621actions BuildHaikuPortsPackageList
622{
623	$(JAM:E=jam) $(HAIKU_BOOTSTRAP_SOURCES_PROFILE) build-package-list $(1) \
624		$(HAIKU_REPOSITORY_BUILD_ADDITIONAL_PACKAGES)
625}
626
627
628actions BuildHaikuPortsSourcePackageDirectory1
629{
630	packageList="$(2[1])"
631
632	# make Haiku cross devel package path absolute
633	haikuCrossDevelPackage="$(2[2])"
634	if [ "x$haikuCrossDevelPackage" = "x${haikuCrossDevelPackage#/}" ]; then
635		haikuCrossDevelPackage="`pwd`/$haikuCrossDevelPackage"
636	fi
637
638	# make secondary Haiku cross devel packages path absolute
639	secondaryCrossDevelPackages=
640	if [ -n "$(2[3-]:J)" ]; then
641		for secondaryCrossDevelPackage in "$(2[3-])" ; do
642			if [ "x$secondaryCrossDevelPackage" = "x${secondaryCrossDevelPackage#/}" ]; then
643				secondaryCrossDevelPackage="`pwd`/$secondaryCrossDevelPackage"
644			fi
645			if [ -n "$secondaryCrossDevelPackages" ]; then
646				secondaryCrossDevelPackages="secondaryCrossDevelPackages,$secondaryCrossDevelPackage"
647			else
648				secondaryCrossDevelPackages="--secondary-cross-devel-package=$secondaryCrossDevelPackage"
649			fi
650		done
651	fi
652
653	cd $(HAIKU_REPOSITORY_BUILD_DIRECTORY)
654
655	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
656	if [ -n "$secondaryCrossDevelPackages" ]; then
657		$(HOST_HAIKU_PORTER) --cross-devel-package "$haikuCrossDevelPackage" \
658			"$secondaryCrossDevelPackages" \
659			$(HAIKU_PORTER_EXTRA_OPTIONS) \
660			--create-source-packages-for-bootstrap --portsfile $packageList
661	else
662		$(HOST_HAIKU_PORTER) --cross-devel-package "$haikuCrossDevelPackage" \
663			$(HAIKU_PORTER_EXTRA_OPTIONS) \
664			--create-source-packages-for-bootstrap --portsfile $packageList
665	fi
666}
667
668
669rule BuildHaikuPortsRepositoryConfig treePath
670{
671	local architecture = $(TARGET_PACKAGING_ARCH) ;
672	local outputDir = [ FDirName
673		$(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture))
674		HaikuPorts-bootstrap ] ;
675
676	local configFile = <repository-config-HaikuPorts-bootstrap>haikuports.conf ;
677	MakeLocate $(configFile) : $(outputDir) ;
678	NoUpdate $(configFile) ;
679
680	HAIKU_REPOSITORY_TREE_PATH on $(configFile) = $(treePath) ;
681	BuildHaikuPortsRepositoryConfig1 $(configFile) ;
682
683	return $(configFile) ;
684}
685
686
687actions BuildHaikuPortsRepositoryConfig1
688{
689	# use a specific packager for continuous integration builds (buildbot)
690	if [ "$(HAIKU_CONTINUOUS_INTEGRATION_BUILD)" = "1" ]; then
691		echo 'PACKAGER="Haiku buildmaster <buildmaster@haiku-os.org>"' > $(1)
692	else
693		echo '#PACKAGER="Joe Hacker <user@host.com>"' > $(1)
694	fi
695	cat >> $(1) << EOF
696TREE_PATH="$(HAIKU_REPOSITORY_TREE_PATH)"
697TARGET_ARCHITECTURE="$(HAIKU_PACKAGING_ARCH)"
698EOF
699}
700
701
702rule UploadPackages target : packages
703{
704	local packageListFile = <repository-package-list>HaikuPorts-packages ;
705	Depends $(target) : $(packageListFile) ;
706
707	HAIKU_REMOTE_REPOSITORY_PACKAGES on $(target) = $(packages) ;
708	UploadPackages1 $(target) : $(packageListFile) ;
709}
710
711
712actions UploadPackages1
713{
714	remote=git.haiku-os.org
715	remoteUser=$(HAIKU_REMOTE_USER)
716	if [ -n "$remoteUser" ]; then
717		remote="$remoteUser@$remote"
718	fi
719
720	if [ -n "$(HAIKU_REMOTE_REPOSITORY_PACKAGES:E=:J)" ]; then
721		for package in $(HAIKU_REMOTE_REPOSITORY_PACKAGES) ; do
722			file=`basename $package`
723			if ! grep -q $file $(2); then
724				echo "Error: $file is not being referenced in $(2)"
725				exit 1
726			fi
727		done
728		ssh $remote mkdir -p 'hpkg-upload'
729		scp $(HAIKU_REMOTE_REPOSITORY_PACKAGES) $remote:hpkg-upload/
730	fi
731}
732
733
734rule BuildRemoteHaikuPortsRepository target : packages
735{
736	UploadPackages $(target) : $(packages) ;
737
738	local packageListFile = <repository-package-list>HaikuPorts-packages ;
739	BuildRemoteHaikuPortsRepository1 $(target) : $(packageListFile) ;
740}
741
742
743actions BuildRemoteHaikuPortsRepository1
744{
745	remote=git.haiku-os.org
746	remoteUser=$(HAIKU_REMOTE_USER)
747	if [ -n "$remoteUser" ]; then
748		remote="$remoteUser@$remote"
749	fi
750
751	repoArch=$(TARGET_PACKAGING_ARCH)
752	scp $(2) $remote:hpkg-upload/$repoArch
753
754	cd $(HAIKU_TOP)
755	branch=`git branch | cut -c3-`
756
757	ssh $remote "build_repository_for_testing.sh $branch $repoArch"
758}
759
760
761rule HaikuRepository repository : repoInfoTemplate : packages
762{
763	# HaikuRepository <repository> : <repoInfoTemplate> : <packages>
764	#	[ : <url> [ : <versionFile> ] ] ;
765	# Builds the Haiku repository from the given packages and repository info
766	# template. <repository> must already be located.
767	#
768	# <repository> - The repository target. Resolves to a directory that will be
769	#	(removed,) created and populated with the package files and repository
770	#	meta data files.
771	# <repoInfoTemplate> - The repository info template file to be used.
772	# <packages> - The packages to be added to the repository.
773
774	local architecture = $(HAIKU_PACKAGING_ARCH) ;
775	local secondaryArchitecture ;
776	if $(TARGET_PACKAGING_ARCH) != $(architecture) {
777		secondaryArchitecture = $(TARGET_PACKAGING_ARCH) ;
778	}
779
780	local repositoriesDir = $(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture)) ;
781
782	# build the repository info
783	local repositoryInfo = $(repository:G=repository-info)-info ;
784	MakeLocate $(repositoryInfo) : $(repositoriesDir) ;
785	PreprocessPackageOrRepositoryInfo $(repositoryInfo) : $(repoInfoTemplate)
786		: $(architecture) : $(secondaryArchitecture) ;
787
788	# build the respository config
789	local repositoryConfig = $(repository:G=repository-config)-config ;
790	MakeLocate $(repositoryConfig) : $(repositoriesDir) ;
791	RepositoryConfig $(repositoryConfig) : $(repositoryInfo) ;
792	HAIKU_REPOSITORY_CONFIG_FILE on $(repository) = $(repositoryConfig) ;
793
794	# setup the repository cache file
795	local repositoryCache = $(repository:B=repo:G=repository-cache) ;
796	MakeLocate $(repositoryCache)
797		: [ FDirName $(repositoriesDir) $(repository:G=) ] ;
798	Depends $(repositoryCache) : $(repository) ;
799	HAIKU_REPOSITORY_CACHE_FILE on $(repository) = $(repositoryCache) ;
800
801	# add the repository to the list of known package repositories
802	HAIKU_REPOSITORIES += $(repository) ;
803
804	# prepare the script that initializes the shell variables
805	local initVariablesScript = $(repository)-repository-init-vars ;
806	MakeLocate $(initVariablesScript)
807		: $(HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture)) ;
808	Always $(initVariablesScript) ;
809
810	local script = $(initVariablesScript) ;
811	AddVariableToScript $(script) : addBuildCompatibilityLibDir
812		: $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ;
813	AddVariableToScript $(script) : sha256 : $(HOST_SHA256) ;
814	AddVariableToScript $(script) : sedExtendedRegex
815		: $(HOST_EXTENDED_REGEX_SED) ;
816	AddTargetVariableToScript $(script) : <build>package ;
817	AddTargetVariableToScript $(script) : <build>package_repo : packageRepo ;
818
819	# call the build actions
820	local mainScript = build_haiku_repository ;
821	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
822
823	Depends $(repository) : $(mainScript) $(initVariablesScript)
824		$(repositoryInfo) $(packages) ;
825	HaikuRepository1 $(repository) : $(mainScript) $(initVariablesScript)
826		$(repositoryInfo) $(packages) ;
827	Always $(repository) ;
828
829	RmTemps $(repository) : $(initVariablesScript) ;
830}
831
832
833actions HaikuRepository1
834{
835	$(2[1]) "$(2[2])" "$(1)" "$(2[3-])"
836}
837