xref: /haiku/build/jam/BeOSRules (revision 204dee708a999d5a71d0cb9497650ee7cef85d0a)
1# BeOS specific rules
2
3rule AddFileDataAttribute target : attrName : attrType : dataFile
4{
5	# AddFileAttribute <target> : <attrName> : <attrType> : <dataFile> ;
6	# Adds a single attribute to a file, retrieving the attribute data from
7	# a separate file.
8	# <target>: The file to which the attribute shall be added.
9	# <attrName>: The name of the attribute.
10	# <attrType>: Attribute type as supported by addattr (string, int, etc.)
11	# <dataFile>: The data to be written to the attribute will be read from
12	#             that file.
13	#             Note that this is supposed to be a build target, not a path
14	#             name - if you need to add a data file in a different path,
15	#			  you have to locate it first.
16	#
17
18	# We need to create a temporary file in which we store the attribute name
19	# and type. Otherwise we wouldn't have these data available in the
20	# addattr actions.
21	local id = [ NextID ] ;
22	local attrMetaFile
23		= [ FGristFiles $(target:G=)-attr-$(attrName)-$(attrType)-$(id) ] ;
24
25	ATTRIBUTE_NAME on $(attrMetaFile) = $(attrName) ;
26	ATTRIBUTE_TYPE on $(attrMetaFile) = $(attrType) ;
27	MakeLocateArch $(attrMetaFile) ;
28	CreateAttributeMetaFile $(attrMetaFile) ;
29
30	Depends $(target) : <build>addattr $(attrMetaFile) $(dataFile) ;
31	AddFileDataAttribute1 $(target)
32		: <build>addattr $(attrMetaFile) $(dataFile) ;
33}
34
35actions CreateAttributeMetaFile
36{
37	echo "-t $(ATTRIBUTE_TYPE)" "$(ATTRIBUTE_NAME)" > "$(1)"
38}
39
40actions AddFileDataAttribute1
41{
42	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
43	$(2[1]) -f $(2[3]) `cat $(2[2])` $(1)
44}
45
46rule AddStringDataResource
47{
48	# AddStringDataResource <target> : <resourceID> : <dataString>
49	# Adds a single resource to the resources of an executable/library.
50	# <target>: The executable/library.
51	# <resourceID>: A resource ID string as understood by xres (type:id[:name]).
52	# <dataString>: The string <dataString> will be written to the resource.
53	#               Defaults to "".
54	#
55	local target = $(1) ;
56	local resourceID = $(2) ;
57	local dataString = $(3:E="") ;
58
59	# the resource file
60	local resources
61		= [ FGristFiles $(target:B)-added-string-data-resources.rsrc ] ;
62
63	# add the resource file to the target, if not yet done
64	if ! [ on $(resources) return $(RESOURCES_ADDED) ] {
65		RESOURCES_ADDED on $(resources) = true ;
66		MakeLocateArch $(resources) ;
67		Depends $(resources) : <build>xres ;
68		AddStringDataResource1 $(resources) : <build>xres ;
69		AddResources $(target) : $(resources) ;
70	}
71
72	RESOURCE_STRINGS on $(resources)
73		+= "-a "$(resourceID)" -s \""$(dataString)"\"" ;
74}
75
76actions together AddStringDataResource1
77{
78	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
79	$(2[1]) -o "$(1)" $(RESOURCE_STRINGS)
80}
81
82rule AddFileDataResource
83{
84	# AddFileDataResource <target> : <resourceID> : [ <dataFile> ]
85	# Adds a single resource to the resources of an executable/library.
86	# <target>: The executable/library.
87	# <resourceID>: A resource ID string as understood by xres (type:id[:name]).
88	# <dataFile>: The data to be written into the resource will be read from
89	#             that file.
90	#             Note that this is supposed to be a build target, not a path
91	#             name - if you need to add a data file in a different path, you
92	#             have to locate it first.
93	#
94	local target = $(1) ;
95	local resourceID = $(2) ;
96	local dataFile = $(3) ;
97
98	# the resource file
99	local resources
100		= <added-resources>file-data-$(resourceID)-$(dataFile).rsrc ;
101
102	# add it to the resources of the given target
103	AddResources $(target) : $(resources) ;
104
105	# if the rule for creating the resource file has not been invoked yet, do it
106	if ! [ on $(resources) return $(RESOURCES_DEFINED) ] {
107		RESOURCES_DEFINED on $(resources) = true ;
108		RESOURCE_ID on $(resources) = $(resourceID) ;
109		MakeLocateArch $(resources) ;
110
111		Depends $(resources) : <build>xres $(dataFile) ;
112		AddFileDataResource1 $(resources) : <build>xres $(dataFile) ;
113	}
114}
115
116actions AddFileDataResource1
117{
118	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
119	$(2[1]) -o "$(1)" -a "$(RESOURCE_ID)" "$(2[2])" ;
120}
121
122rule XRes
123{
124	# XRes <target> : <resource files>
125	if $(2)
126	{
127		Depends $(1) : <build>xres $(2) ;
128		XRes1 $(1) : <build>xres $(2) ;
129	}
130}
131
132actions XRes1
133{
134	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
135	$(2[1]) -o "$(1)" "$(2[2-])" ;
136}
137
138rule SetVersion
139{
140	# SetVersion <target>
141
142	Depends $(1) : <build>setversion ;
143	SetVersion1 $(1) : <build>setversion ;
144}
145
146actions SetVersion1
147{
148	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
149	$(2[1]) "$(1)" -system $(HAIKU_BUILD_VERSION) -short "$(HAIKU_BUILD_DESCRIPTION)" ;
150}
151
152rule SetType
153{
154	# SetType <target>
155
156	Depends $(1) : <build>settype ;
157	SetType1 $(1) : <build>settype ;
158}
159
160actions SetType1
161{
162	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
163	$(2[1]) -t $(TARGET_EXECUTABLE_MIME_TYPE) "$(1)" ;
164}
165
166rule MimeSet target
167{
168	# MimeSet <target> ;
169
170	Depends $(target) : <build>mimeset <mimedb>mime_db ;
171	MimeSet1 $(target) : <build>mimeset <mimedb>mime_db ;
172}
173
174
175actions MimeSet1
176{
177	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
178	$(2[1]) -f --mimedb "$(2[2])" "$(1)"
179}
180
181
182rule CreateAppMimeDBEntries target
183{
184	# MimeSetApp <target> ;
185	# Create the app meta MIME DB entries for the given target. The
186	# HAIKU_MIME_DB_ENTRIES variable on <target> is set to the generated
187	# resulting target directory that contains the MIME DB entries.
188
189	local appGrist = $(target:G) ;
190	local appMimeDB = $(target:BS)_mimedb ;
191	appMimeDB = $(appMimeDB:G=mimedb-app-$(appGrist:E=)) ;
192	MakeLocateDebug $(appMimeDB) ;
193	Depends $(appMimeDB) : <build>mimeset $(target) <mimedb>mime_db ;
194	CreateAppMimeDBEntries1 $(appMimeDB)
195		: <build>mimeset $(target) <mimedb>mime_db ;
196
197	HAIKU_MIME_DB_ENTRIES on $(target) = $(appMimeDB) ;
198}
199
200
201actions CreateAppMimeDBEntries1
202{
203	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
204
205	appMimeDB="$(1)"
206	$(RM) -rf "$appMimeDB"
207	$(MKDIR) "$appMimeDB"
208	$(2[1]) -f --apps --mimedb "$appMimeDB" --mimedb "$(2[3])" "$(2[2])"
209}
210
211
212rule ResComp
213{
214	# ResComp <resource file> : <rdef file> ;
215	#
216	# <resource file> and <rdef file> must be gristed.
217
218	# get compiler and defines for the platform
219	local cc ;
220	local defines ;
221	local localIncludesOption ;
222
223	on $(1) { # use on $(1) variable values
224		defines = $(DEFINES) ;
225
226		if $(PLATFORM) = host {
227			defines += $(HOST_DEFINES) ;
228			cc = $(HOST_CC) ;
229			localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ;
230		} else {
231			defines += $(TARGET_DEFINES) ;
232			cc = $(TARGET_CC) ;
233			localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ;
234		}
235	}
236
237	DEFINES on $(1) = $(defines) ;
238	CCDEFS on $(1) = [ FDefines $(defines) ] ;
239	HDRS on $(1) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS)
240		: $(localIncludesOption) ] ;
241	RCHDRS on $(1) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS)
242		: "-I " ] ;
243	CC on $(1) = $(cc) ;
244
245	# set up other vars
246	SEARCH on $(2) += $(SEARCH_SOURCE) ;
247	MakeLocateArch $(1) ;
248	Depends $(1) : $(2) <build>rc ;
249	LocalClean clean : $(1) ;
250	ResComp1 $(1) : <build>rc $(2) ;
251}
252
253# Note: We pipe the input files into the preprocessor, since *.rdef files are
254# considered linker scripts, and thus we can use preprocessor features.
255actions ResComp1
256{
257	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
258	cat "$(2[2-])" | $(CC) -E $(CCDEFS) $(HDRS) - | egrep -v '^#' | $(2[1]) $(RCHDRS) --auto-names -o "$(1)" -
259}
260
261rule ResAttr attributeFile : _resourceFiles : deleteAttributeFile
262{
263	# ResAttr <attribute file> : <resource files> [ : <delete file> ] ;
264	#
265	# <attribute file> and <resource files> must be gristed.
266	# <resource files> can also be .rdef files -- they will be compiled first in
267	# this case.
268	# <clear file> is a boolean that specifies wether or not the target file
269	# should be removed before writing. Defaults to true.
270
271	local resourceFiles ;
272	local resourceFile ;
273	deleteAttributeFile ?= true ;
274	deleteAttributeFile1 on $(1) = $(deleteAttributeFile) ;
275
276	for resourceFile in $(_resourceFiles) {
277		# if the specified resource file is an .rdef file, we compile it first
278		if $(resourceFile:S) = ".rdef" {
279			local rdefFile = $(resourceFile) ;
280			resourceFile = $(rdefFile:S=.rsrc) ;
281			ResComp $(resourceFile) : $(rdefFile) ;
282		} else {
283			SEARCH on $(resourceFile) += $(SEARCH_SOURCE) ;
284		}
285
286		resourceFiles += $(resourceFile) ;
287	}
288
289	MakeLocateArch $(attributeFile) ;
290	Depends $(attributeFile) : $(resourceFiles) <build>resattr ;
291	LocalClean clean : $(attributeFile) ;
292	ResAttr1 $(attributeFile) : <build>resattr $(resourceFiles) ;
293}
294
295actions ResAttr1
296{
297	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
298	if [ \\"$(deleteAttributeFile1)\\" = "true" ]; then
299		$(RM) $(1)
300	fi
301	$(2[1]) -O -o "$(1)" "$(2[2-])"
302}
303