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