xref: /haiku/build/jam/PackageRules (revision b0944c78b074a8110bd98e060415d0e8f38a7f65)
1rule FHaikuPackageGrist package
2{
3	local grist = [ Match "<(.*)>" : $(package:G) ] ;
4	return hpkg_$(grist:E="")-$(package:G=) ;
5}
6
7
8rule HaikuPackage package
9{
10	local grist = [ FHaikuPackageGrist $(package) ] ;
11
12	HAIKU_CONTAINER_GRIST on $(package) = $(grist) ;
13	HAIKU_INCLUDE_IN_CONTAINER_VAR on $(package) = HAIKU_INCLUDE_IN_PACKAGES ;
14	HAIKU_INSTALL_TARGETS_VAR on $(package)
15		= $(grist)_HAIKU_PACKAGE_INSTALL_TARGETS ;
16	HAIKU_CONTAINER_SYSTEM_DIR_TOKENS on $(package) = ;
17
18	HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE = $(package) ;
19
20	if $(HAIKU_PACKAGES_UPDATE_ONLY) {
21		HAIKU_CONTAINER_UPDATE_ONLY on $(package) = 1 ;
22		HAIKU_CONTAINER_INHERIT_UPDATE_VARIABLE on $(package)
23			= HAIKU_INCLUDE_IN_IMAGE ;
24	} else if $(HAIKU_UPDATE_ALL_PACKAGES) {
25		HAIKU_INCLUDE_IN_IMAGE on $(package) = 1 ;
26	}
27
28	HAIKU_CONTAINER_ALWAYS_CREATE_DIRECTORIES on $(package) = 1 ;
29}
30
31
32rule PreprocessPackageInfo source : directory : architecture
33{
34	source = $(source:G=package-info-source) ;
35	SEARCH on $(source) +=
36		[ FDirName $(HAIKU_PACKAGE_INFOS_DIR) $(architecture) ]
37		[ FDirName $(HAIKU_PACKAGE_INFOS_DIR) any ]
38		[ FDirName $(HAIKU_PACKAGE_INFOS_DIR) generic ]
39	;
40
41	local target = $(source:BSG=package-info)-package-info ;
42	local defines = HAIKU_PACKAGING_ARCH=$(architecture) ;
43	if $(HAIKU_BOOTSTRAP_BUILD) {
44		defines += HAIKU_BOOTSTRAP_BUILD ;
45		target = $(target)-bootstrap ;
46	}
47
48	MakeLocate $(target) : $(directory) ;
49	Depends $(target) : $(source) ;
50
51	CCDEFS on $(target) = [ FDefines $(defines) ] ;
52
53	PreprocessPackageInfo1 $(target) : $(source) ;
54
55	return $(target) ;
56}
57
58
59actions PreprocessPackageInfo1
60{
61	$(HOST_CC) -E -w $(CCDEFS) - -o $(1) < $(2)
62}
63
64
65rule BuildHaikuPackage package : packageInfo
66{
67	local architecture = $(HAIKU_PACKAGING_ARCH) ;
68	local grist = [ FHaikuPackageGrist $(package) ] ;
69
70	local tempDir
71		= [ FDirName $(HAIKU_PACKAGES_BUILD_DIR_$(architecture)) $(grist) ] ;
72	local scriptDir = [ FDirName $(tempDir) scripts ] ;
73
74	#  build the package info and locate the package
75	packageInfo = [ PreprocessPackageInfo $(packageInfo) : $(tempDir)
76		: $(architecture) ] ;
77	MakeLocate $(package) : $(HAIKU_PACKAGES_DIR_$(architecture)) ;
78	Depends $(package) : $(packageInfo) ;
79
80	# prepare the script that initializes the shell variables
81	local initVariablesScript = <$(grist)>haiku.package-init-vars ;
82	MakeLocate $(initVariablesScript) : $(scriptDir) ;
83	Always $(initVariablesScript) ;
84
85	local script = $(initVariablesScript) ;
86	AddVariableToScript $(script) : sourceDir : $(HAIKU_TOP) ;
87	AddVariableToScript $(script) : outputDir : $(HAIKU_OUTPUT_DIR) ;
88	AddVariableToScript $(script) : tmpDir : $(tempDir) ;
89	AddVariableToScript $(script) : addBuildCompatibilityLibDir
90		: $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ;
91	AddVariableToScript $(script) : compressionLevel
92		: [ on $(package) return $(HAIKU_PACKAGE_COMPRESSION_LEVEL) ] ;
93	AddVariableToScript $(script) : updateOnly
94		: [ on $(package) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] ;
95	AddVariableToScript $(script) : cc : $(TARGET_CC_$(architecture)) ;
96	AddTargetVariableToScript $(script) : <build>addattr ;
97	AddTargetVariableToScript $(script) : <build>copyattr ;
98	AddTargetVariableToScript $(script) : <mimedb>mime_db : mimeDB ;
99	AddTargetVariableToScript $(script) : <build>mimeset ;
100	AddTargetVariableToScript $(script) : <build>package ;
101	AddTargetVariableToScript $(script) : <build>rc ;
102	AddTargetVariableToScript $(script) : <build>resattr ;
103	AddTargetVariableToScript $(script) : <build>unzip ;
104	if $(HOST_RM_ATTRS_TARGET) {
105		AddTargetVariableToScript $(script) : $(HOST_RM_ATTRS_TARGET)
106			: rmAttrs ;
107	} else {
108		AddVariableToScript $(script) : rmAttrs : rm ;
109	}
110
111	# create the other scripts
112	local makeDirsScript = <$(grist)>haiku.package-make-dirs ;
113	local copyFilesScript = <$(grist)>haiku.package-copy-files ;
114	local extractFilesScript = <$(grist)>haiku.package-extract-files ;
115
116	MakeLocate $(makeDirsScript) $(copyFilesScript) $(extractFilesScript)
117		: $(scriptDir) ;
118
119	CreateContainerMakeDirectoriesScript $(package) : $(makeDirsScript) ;
120	CreateContainerCopyFilesScript $(package) : $(copyFilesScript) ;
121	CreateContainerExtractFilesScript $(package) : $(extractFilesScript) ;
122
123	local scripts = $(initVariablesScript) $(makeDirsScript)
124		$(copyFilesScript) $(extractFilesScript) ;
125
126	# call the build actions
127	local mainScript = build_haiku_package ;
128	SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ;
129
130	LocalDepends $(package) : $(mainScript) $(scripts) ;
131	BuildHaikuPackage1 $(package) : $(mainScript) $(packageInfo) $(scripts) ;
132}
133
134
135actions BuildHaikuPackage1
136{
137	$(2[1]) "$(1)" "$(2[2])" $(2[3-])
138}
139
140
141rule AddDirectoryToPackage directoryTokens : attributeFiles
142{
143	return [ AddDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
144		: $(directoryTokens) : $(attributeFiles) ] ;
145}
146
147
148rule AddFilesToPackage directory : targets : destName
149{
150	AddFilesToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE) : $(directory)
151		: $(targets) : $(destName) ;
152}
153
154
155rule AddSymlinkToPackage directoryTokens : linkTarget : linkName
156{
157	linkTarget = $(linkTarget:J=/) ;
158
159	AddSymlinkToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
160		: $(directoryTokens) : $(linkTarget) : $(linkName) ;
161}
162
163
164rule CopyDirectoryToPackage directoryTokens : sourceDirectory
165	: targetDirectoryName : excludePatterns : flags
166{
167	CopyDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
168		: $(directoryTokens) : $(sourceDirectory) : $(targetDirectoryName)
169		: $(excludePatterns) : $(flags) ;
170}
171
172
173rule AddHeaderDirectoryToPackage dirTokens : dirName : flags
174{
175	AddHeaderDirectoryToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
176		: $(dirTokens) : $(dirName) : $(flags) ;
177}
178
179
180rule AddWifiFirmwareToPackage driver : subDirToExtract : archive
181	: extract
182{
183	AddWifiFirmwareToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
184		: $(driver) : $(subDirToExtract) : $(archive) : $(extract) ;
185}
186
187
188rule ExtractArchiveToPackage dirTokens : archiveFile : flags : extractedSubDir
189{
190	ExtractArchiveToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
191		: $(dirTokens) : $(archiveFile) : $(flags) : $(extractedSubDir) ;
192}
193
194
195rule AddDriversToPackage relativeDirectoryTokens : targets
196{
197	AddDriversToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
198		: $(relativeDirectoryTokens) : $(targets) ;
199}
200
201
202rule AddNewDriversToPackage relativeDirectoryTokens : targets
203{
204	AddNewDriversToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
205		: $(relativeDirectoryTokens) : $(targets) ;
206}
207
208
209rule AddBootModuleSymlinksToPackage targets
210{
211	AddBootModuleSymlinksToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
212		: $(targets) ;
213}
214
215
216rule AddLibrariesToPackage directory : libs
217{
218	AddLibrariesToContainer $(HAIKU_CURRENTLY_BUILT_HAIKU_PACKAGE)
219		: $(directory) : $(libs) ;
220}
221
222
223# default value for the package compression level
224HAIKU_PACKAGE_COMPRESSION_LEVEL ?= 9 ;
225