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