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