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	MakeLocateCommonPlatform $(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 target : type
153{
154	# SetType <target> [ : <type> ]
155	# Sets the MIME type on the target. If none is given, the executable MIME
156	# type is used.
157
158	TARGET_MIME_TYPE on $(target) = $(type:E=$(TARGET_EXECUTABLE_MIME_TYPE)) ;
159
160	Depends $(target) : <build>settype ;
161	SetType1 $(target) : <build>settype ;
162}
163
164actions SetType1
165{
166	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) \
167	$(2[1]) -t $(TARGET_MIME_TYPE) "$(1)"
168}
169
170rule MimeSet target
171{
172	# MimeSet <target> ;
173
174	Depends $(target) : <build>mimeset <mimedb>mime_db ;
175	MimeSet1 $(target) : <build>mimeset <mimedb>mime_db ;
176}
177
178
179actions MimeSet1
180{
181	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) \
182	$(2[1]) -f --mimedb "$(2[2])" "$(1)"
183}
184
185
186rule CreateAppMimeDBEntries target
187{
188	# MimeSetApp <target> ;
189	# Create the app meta MIME DB entries for the given target. The
190	# HAIKU_MIME_DB_ENTRIES variable on <target> is set to the generated
191	# resulting target directory that contains the MIME DB entries.
192
193	local appGrist = $(target:G) ;
194	local appMimeDB = $(target:BS)_mimedb ;
195	appMimeDB = $(appMimeDB:G=mimedb-app-$(appGrist:E=)) ;
196	MakeLocateDebug $(appMimeDB) ;
197	Depends $(appMimeDB) : <build>mimeset $(target) <mimedb>mime_db ;
198	CreateAppMimeDBEntries1 $(appMimeDB)
199		: <build>mimeset $(target) <mimedb>mime_db ;
200
201	HAIKU_MIME_DB_ENTRIES on $(target) = $(appMimeDB) ;
202}
203
204
205actions CreateAppMimeDBEntries1
206{
207	export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
208
209	appMimeDB="$(1)"
210	$(RM) -rf "$appMimeDB"
211	$(MKDIR) "$appMimeDB"
212	$(2[1]) -f --apps --mimedb "$appMimeDB" --mimedb "$(2[3])" "$(2[2])"
213}
214
215
216rule ResComp
217{
218	# ResComp <resource file> : <rdef file> ;
219	#
220	# <resource file> and <rdef file> must be gristed.
221
222	# get compiler and defines for the platform
223	local cc ;
224	local defines ;
225	local flags ;
226	local localIncludesOption ;
227
228	on $(1) { # use on $(1) variable values
229		defines = $(DEFINES) ;
230
231		if $(PLATFORM) = host {
232			defines += $(HOST_DEFINES) ;
233			cc = $(HOST_CC) ;
234			flags += $(HOST_CCFLAGS) ;
235			localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ;
236		} else {
237			defines += $(TARGET_DEFINES_$(TARGET_PACKAGING_ARCH))
238				$(TARGET_DEFINES) ;
239			cc = $(TARGET_CC_$(TARGET_PACKAGING_ARCH)) ;
240			flags += $(TARGET_CCFLAGS_$(TARGET_PACKAGING_ARCH)) ;
241			localIncludesOption
242				= $(TARGET_LOCAL_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
243		}
244	}
245
246	DEFINES on $(1) = $(defines) ;
247	CCDEFS on $(1) = [ FDefines $(defines) ] ;
248	CCFLAGS on $(1) = $(flags) ;
249	HDRS on $(1) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS)
250		: $(localIncludesOption) ] ;
251	RCHDRS on $(1) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS)
252		: "-I " ] ;
253	CC on $(1) = $(cc) ;
254
255	# set up other vars
256	SEARCH on $(2) += $(SEARCH_SOURCE) ;
257	MakeLocateArch $(1) ;
258	Depends $(1) : $(2) <build>rc ;
259	LocalClean clean : $(1) ;
260	ResComp1 $(1) : <build>rc $(2) ;
261}
262
263# Note: We pipe the input files into the preprocessor, since *.rdef files are
264# considered linker scripts, and thus we can use preprocessor features.
265actions ResComp1
266{
267	export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
268	cat "$(2[2-])" | $(CC) $(CCFLAGS) -E $(CCDEFS) $(HDRS) - \
269		| grep -E -v '^#' | $(2[1]) $(RCHDRS) --auto-names -o "$(1)" -
270}
271
272rule ResAttr attributeFile : _resourceFiles : deleteAttributeFile
273{
274	# ResAttr <attribute file> : <resource files> [ : <delete file> ] ;
275	#
276	# <attribute file> and <resource files> must be gristed.
277	# <resource files> can also be .rdef files -- they will be compiled first in
278	# this case.
279	# <clear file> is a boolean that specifies wether or not the target file
280	# should be removed before writing. Defaults to true.
281
282	local resourceFiles ;
283	local resourceFile ;
284	deleteAttributeFile ?= true ;
285	deleteAttributeFile1 on $(1) = $(deleteAttributeFile) ;
286
287	for resourceFile in $(_resourceFiles) {
288		# if the specified resource file is an .rdef file, we compile it first
289		if $(resourceFile:S) = ".rdef" {
290			local rdefFile = $(resourceFile) ;
291			resourceFile = $(rdefFile:S=.rsrc) ;
292			ResComp $(resourceFile) : $(rdefFile) ;
293		} else {
294			SEARCH on $(resourceFile) += $(SEARCH_SOURCE) ;
295		}
296
297		resourceFiles += $(resourceFile) ;
298	}
299
300	MakeLocateArch $(attributeFile) ;
301	Depends $(attributeFile) : $(resourceFiles) <build>resattr ;
302	LocalClean clean : $(attributeFile) ;
303	ResAttr1 $(attributeFile) : <build>resattr $(resourceFiles) ;
304}
305
306actions ResAttr1
307{
308	export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
309	if [ \\"$(deleteAttributeFile1)\\" = "true" ]; then
310		$(RM) $(1)
311	fi
312	$(2[1]) -O -o "$(1)" "$(2[2-])"
313}
314