RepositoryRules revision 014eed80
1rule PackageFamily packageBaseName
2{
3	return $(packageBaseName:G=package-family) ;
4}
5
6
7rule AddRepositoryPackage repository : architecture : baseName : version
8{
9	local package = $(baseName)-$(version) ;
10	package = $(package:E=$(baseName):G=package-in-$(repository:G=)) ;
11	HAIKU_PACKAGE_REPOSITORY on $(package) = $(repository) ;
12	HAIKU_PACKAGE_ARCHITECTURE on $(package) = $(architecture) ;
13	HAIKU_PACKAGE_FILE_NAME on $(package) = $(package:G=)-$(architecture).hpkg ;
14
15	if ! $(baseName) in $(HAIKU_AVAILABLE_PACKAGES) {
16		HAIKU_AVAILABLE_PACKAGES += $(baseName) ;
17	}
18
19	local packageFamily = [ PackageFamily $(baseName) ] ;
20	HAIKU_PACKAGE_VERSIONS on $(packageFamily) += $(package) ;
21	HAIKU_REPOSITORY_PACKAGES on $(repository) += $(package) ;
22}
23
24
25rule AddRepositoryPackages repository : architecture : packages : sourcePackages
26{
27	local package ;
28	for package in $(packages) {
29		local splitName = [ Match "([^-]*)-(.*)" : $(package) ] ;
30		local baseName = $(splitName[1]:E=$(package)) ;
31		local version = $(splitName[2]) ;
32		AddRepositoryPackage $(repository) : $(architecture) : $(baseName)
33			: $(version) ;
34		if $(baseName) in $(sourcePackages) {
35			AddRepositoryPackage $(repository) : source : $(baseName)_source
36				: $(version) ;
37		}
38	}
39}
40
41
42rule PackageRepository repository : architecture : repositoryUrl : anyPackages
43	: packages : sourcePackages
44{
45	repository = $(repository:G=repository) ;
46
47	if $(architecture) != $(HAIKU_PACKAGING_ARCH) {
48		return ;
49	}
50
51	HAIKU_REPOSITORIES += $(repository) ;
52	HAIKU_REPOSITORY_URL on $(repository) = $(repositoryUrl) ;
53	HAIKU_REPOSITORY_DEFINITION_FILE on $(repository)
54		= $(HAIKU_REPOSITORY_JAMFILE) ;
55
56	AddRepositoryPackages $(repository) : any : $(anyPackages)
57		: $(sourcePackages) ;
58	AddRepositoryPackages $(repository) : $(architecture) : $(packages)
59		: $(sourcePackages) ;
60
61	# build package list file
62	local packageListFile = $(repository:G=repository-package-list)-packages ;
63	MakeLocate $(packageListFile) : $(HAIKU_PACKAGE_REPOSITORIES_DIR) ;
64	GeneratedRepositoryPackageList $(packageListFile) : $(repository) ;
65
66	# build package list checksum file
67	local packagesChecksumFile
68		= $(repository:G=repository-package-checksum)-checksum ;
69	MakeLocate $(packagesChecksumFile) : $(HAIKU_PACKAGE_REPOSITORIES_DIR) ;
70	Depends $(packagesChecksumFile) : $(packageListFile) ;
71	ChecksumFileSHA256 $(packagesChecksumFile) : $(packageListFile) ;
72
73	# download repository info file
74	local repositoryInfo = $(repository:G=repository-info)-info ;
75	MakeLocate $(repositoryInfo) : $(HAIKU_PACKAGE_REPOSITORIES_DIR) ;
76	local repoUrl = [ on $(repository) return $(HAIKU_REPOSITORY_URL) ] ;
77	DownloadLocatedFile $(repositoryInfo)
78		: "$(repoUrl)/`cat $source`/repo.info"
79		: $(packagesChecksumFile) ;
80
81	# download repository file
82	local repositoryFile = $(repository:G=repository-cache) ;
83	MakeLocate $(repositoryFile) : $(HAIKU_PACKAGE_REPOSITORIES_DIR) ;
84	local repoUrl = [ on $(repository) return $(HAIKU_REPOSITORY_URL) ] ;
85	DownloadLocatedFile $(repositoryFile)
86		: "$(repoUrl)/`cat $source`/repo"
87		: $(packagesChecksumFile) ;
88
89	# build repository config file
90	local repositoryConfig = $(repository:G=repository-config)-config ;
91	MakeLocate $(repositoryConfig) : $(HAIKU_PACKAGE_REPOSITORIES_DIR) ;
92	RepositoryConfig $(repositoryConfig) : $(repositoryInfo)
93		: $(packagesChecksumFile) : $(repository) ;
94
95	HAIKU_REPOSITORY_CACHE_FILE on $(repository) = $(repositoryFile) ;
96	HAIKU_REPOSITORY_CONFIG_FILE on $(repository) = $(repositoryConfig) ;
97	HAIKU_REPOSITORY_PACKAGES_CHECKSUM_FILE on $(repository)
98		= $(packagesChecksumFile) ;
99}
100
101
102rule GeneratedRepositoryPackageList target : repository
103{
104	repository = $(repository:G=repository) ;
105
106	# construct a list of file names
107	local fileNames ;
108	local package ;
109	for package in [ on $(repository) return $(HAIKU_REPOSITORY_PACKAGES) ] {
110		fileNames += [ on $(package) return $(HAIKU_PACKAGE_FILE_NAME) ] ;
111	}
112
113	local definitionFile
114		= [ on $(repository) return $(HAIKU_REPOSITORY_DEFINITION_FILE) ] ;
115	Depends $(target) : $(definitionFile) ;
116
117	HAIKU_REPOSITORY_PACKAGE_FILE_NAMES on $(target) = $(fileNames) ;
118	GeneratedRepositoryPackageList1 $(target) ;
119}
120
121
122actions GeneratedRepositoryPackageList1
123{
124	(for file in $(HAIKU_REPOSITORY_PACKAGE_FILE_NAMES) ; do
125		echo $file
126	done) | LC_ALL=C sort -u > $(1)
127}
128
129
130rule RepositoryConfig repoConfig : repoInfo : packagesChecksumFile : repository
131{
132	repository = $(repository:G=repository) ;
133
134	HAIKU_REPOSITORY_URL on $(repoConfig)
135		= [ on $(repository) return $(HAIKU_REPOSITORY_URL) ] ;
136	Depends $(repoConfig)
137		: <build>create_repository_config $(repoInfo) $(packagesChecksumFile) ;
138	RepositoryConfig1 $(repoConfig)
139		: <build>create_repository_config $(repoInfo) $(packagesChecksumFile) ;
140}
141
142
143actions RepositoryConfig1
144{
145	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
146	$(2[1]) $(HAIKU_REPOSITORY_URL)/`cat $(2[3])` $(2[2]) $(1)
147}
148
149
150rule IsPackageAvailable package
151{
152	if $(package) in $(HAIKU_AVAILABLE_PACKAGES) {
153		return 1 ;
154	}
155
156	return ;
157}
158
159
160rule DownloadPackage packageName
161{
162	if ! [ IsPackageAvailable $(packageName) ] {
163		Exit "DownloadPackage: package" $(packageName) "not available!" ;
164		return ;
165	}
166
167	# TODO: We should support explicitly specified versions (or partial/minimum
168	# versions like gcc-2 or gcc-4).
169
170	local packageFamily = [ PackageFamily $(packageName) ] ;
171	local package
172		= [ on $(packageFamily) return $(HAIKU_PACKAGE_VERSIONS[1]) ] ;
173	local fileName = [ on $(package) return $(HAIKU_PACKAGE_FILE_NAME) ] ;
174	local repository = [ on $(package) return $(HAIKU_PACKAGE_REPOSITORY) ] ;
175	local baseUrl = [ on $(repository) return $(HAIKU_REPOSITORY_URL) ] ;
176	local packagesChecksumFile
177		= [ on $(repository)
178			return $(HAIKU_REPOSITORY_PACKAGES_CHECKSUM_FILE) ] ;
179
180	local downloadedFile = [ DownloadFile $(fileName)
181		: "$(baseUrl)/`cat $source`/packages/$(fileName)"
182		: $(packagesChecksumFile) ] ;
183	NoUpdate $(downloadedFile) ;
184		# Don't download the file again when something in the repository
185		# changes. It is (supposed to be) still the same file.
186	return $(downloadedFile) ;
187}
188