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