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