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