xref: /haiku/build/jam/FileRules (revision b30304acc8c37e678a1bf66976d15bdab103f931)
1rule SymLink
2{
3	# SymLink <target> : <source> : <makeDefaultDependencies> ;
4	# Links <target> to <source>.
5	# <source> is the exact link contents. No binding is done.
6	# <makeDefaultDependencies> If true, <target> will be made a dependency
7	# of the `all' pseudo target, i.e. it will be made by default, and removed
8	# on `jam clean'.
9
10	local target = $(1) ;
11	local source = $(2) ;
12	local makeDefaultDependencies = $(3) ;
13	if ! $(makeDefaultDependencies) {
14		makeDefaultDependencies = true ;
15	}
16	LINKCONTENTS on $(target) = $(source) ;
17	SymLink1 $(target) ;
18	if $(makeDefaultDependencies) = true {
19		LocalDepends files : $(target) ;
20		LocalClean clean : $(target) ;
21	}
22}
23
24actions SymLink1
25{
26	$(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)"
27}
28
29rule RelSymLink
30{
31	# RelSymLink <link> : <link target> : <makeDefaultDependencies> ;
32	# Creates a relative symbolic link from <link> to <link target>.
33	# <link> and <link target> can be usual targets. They may have a grist
34	# and don't need to have any dirname. Their LOCATE variables are used to
35	# find their locations.
36	# <makeDefaultDependencies> If true (which is the default), <link> will be
37	# made a dependency of the `files' pseudo target, i.e. it will be made by
38	# default, and removed on `jam clean'.
39
40	local target = $(1) ;
41	local source = $(2) ;
42	local makeDefaultDependencies = $(3) ;
43	local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ;
44	local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ;
45	local sourcePath = $(source:G=) ;
46	sourcePath = $(sourcePath:D=$(sourceDir)) ;
47	local targetDirComponents = [ FSplitPath $(targetDir) ] ;
48	local sourceComponents = [ FSplitPath $(sourcePath) ] ;
49
50	SymLink $(target)
51		: [ FRelPath $(targetDirComponents) : $(sourceComponents) ]
52		: $(makeDefaultDependencies) ;
53	NOUPDATE $(target) ;
54	Depends $(target) : $(source) ;
55}
56
57rule AbsSymLink
58{
59	# AbsSymLink <link> : <link target> : <link dir>
60	#			: <makeDefaultDependencies> ;
61	# Creates an absolute symbolic link from <link> to <link target>.
62	# <link> and <link target> must be usual targets. If <link dir> is
63	# given, then it is set as LOCATE directory on <link>.
64	# <makeDefaultDependencies> If true (which is the default), <link> will be
65	# made a dependency of the `files' pseudo target, i.e. it will be made by
66	# default, and removed on `jam clean'.
67
68	local makeDefaultDependencies = $(4) ;
69	if ! $(makeDefaultDependencies) {
70		makeDefaultDependencies = true ;
71	}
72
73	Depends $(1) : $(2) ;
74	if $(3) {
75		MakeLocate $(1) : $(3) ;
76	}
77	SEARCH on $(2) += $(SEARCH_SOURCE) ;
78	if $(makeDefaultDependencies) = true {
79		LocalDepends files : $(1) ;
80		LocalClean clean : $(1) ;
81	}
82}
83
84actions AbsSymLink
85{
86	target="$(2)"
87	case "$target" in
88		/*) ;;
89		*) target=`pwd`/"$target";;
90	esac
91	$(RM) "$(1)" && $(LN) -s "$target" "$(1)"
92}
93
94rule HaikuInstall
95{
96	# Usage: HaikuInstall <[ install [ and uninstall ] pseudotarget ]>
97	#					 : <directory> : <sources to install>
98	#					 : [ <installgrist> ] : [ <install rule> ] ;
99	local install = $(1[1]) ;
100	install ?= install ;
101	local uninstall = $(1[2]) ;
102	uninstall ?= un$(install) ;
103	local dir = $(2) ;
104	local sources = $(3) ;
105	local installgrist = $(4) ;
106	installgrist ?= $(INSTALLGRIST) ;
107	local installRule = $(5) ;
108	installRule ?= Install ;
109	local targets = $(sources:G=$(installgrist)) ;
110
111	NotFile $(install) ;
112	NotFile $(uninstall) ;
113	Depends $(install) : $(targets) ;
114	Clean $(uninstall) : $(targets) ;
115
116	SEARCH on $(sources) += $(SEARCH_SOURCE) ;
117	MakeLocate $(targets) : $(dir) ;
118
119	local source ;
120	for source in $(sources) {
121		local target = $(source:G=$(installgrist)) ;
122
123		Depends $(target) : $(source) ;
124		$(installRule) $(target) : $(source) ;
125
126		if [ on $(target) return $(MODE) ] {
127			Chmod $(target) ;
128		}
129
130		if $(OWNER) && $(CHOWN) {
131			Chown $(target) ;
132			OWNER on $(target) = $(OWNER) ;
133		}
134
135		if $(GROUP) && $(CHGRP) {
136			Chgrp $(target) ;
137			GROUP on $(target) = $(GROUP) ;
138		}
139	}
140}
141
142rule InstallAbsSymLinkAdapter
143{
144	# InstallAbsSymLinkAdapter <link> : <link target>
145	if ! [ on $(2) return $(TARGET) ] {
146		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
147	}
148	AbsSymLink $(1) : $(2) : : false ;
149}
150
151rule HaikuInstallAbsSymLink
152{
153	# Usage: HaikuInstallAbsSymLink <[ install [ and uninstall ] pseudotarget ]>
154	#							   : <directory> : <sources to install>
155	#							   : [ <installgrist> ] ;
156	HaikuInstall $(1) : $(2) : $(3) : $(4) : InstallAbsSymLinkAdapter ;
157}
158
159rule InstallRelSymLinkAdapter
160{
161	# InstallRelSymLinkAdapter <link> : <link target>
162	if ! [ on $(2) return $(TARGET) ] {
163		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
164	}
165	RelSymLink $(1) : $(2) : false ;
166}
167
168rule HaikuInstallRelSymLink
169{
170	# Usage: HaikuInstallRelSymLink <[ install [ and uninstall ] pseudotarget ]>
171	#							   : <directory> : <sources to install>
172	#							   : [ <installgrist> ] ;
173	HaikuInstall $(1) : $(2) : $(3) : $(4) : InstallRelSymLinkAdapter ;
174}
175
176
177rule UnarchiveObjects
178{
179	# UnarchiveObjects <target objects> : <static object>
180
181	MakeLocateArch $(1) ;
182	Depends $(1) : $(2) ;
183	SEARCH on $(2) = $(SEARCH_SOURCE) ;
184}
185
186actions UnarchiveObjects
187{
188	( cd $(1[1]:D) && $(TARGET_AR) $(TARGET_UNARFLAGS) "$(2)" $(1:BS) )
189}
190
191
192rule ObjectReference
193{
194	# ObjectReference <reference object> : <source object>
195	# Makes <reference object> refer to the same file as <source object>.
196	# The filenames must of course be identical.
197	# <source object> must have already been LOCATEd.
198
199	local ref = $(1) ;
200	local source = $(2) ;
201	if $(ref) != $(source) {
202		Depends $(ref) : $(source) ;
203		LOCATE on $(ref) = [ on $(source) return $(LOCATE) ] ;
204	}
205}
206
207rule ObjectReferences
208{
209	# ObjectReferences <source objects>
210	# Creates local references to <source objects>, i.e. identifiers with the
211	# current grist referring to the same files. <source objects> must have
212	# already been LOCATEd.
213
214	local source ;
215	for source in $(1) {
216		ObjectReference [ FGristFiles $(source) ] : $(source) ;
217	}
218}
219
220rule CopySetHaikuRevision target : source
221{
222	# CopySetHaikuRevision <target> : <source>
223	#
224	# Copy <source> to <target>, writing the SVN revision of the working root
225	# directory into the haiku revision section of <target>.
226	#
227	# <target> - Output file target. Gristed and located target.
228	# <source> - ELF object to be copied. Gristed and located target.
229
230	# If existent, make the target depend on the .svn/entries file in the
231	# root directory, so it gets updated when the revision changes due to
232	# "svn up".
233	if [ Glob [ FDirName $(HAIKU_TOP) .svn ] : entries ] {
234		local svnEntries = <haiku-rootdir-svn>entries ;
235		SEARCH on $(svnEntries) = [ FDirName $(HAIKU_TOP) .svn ] ;
236		Depends $(target) : $(svnEntries) ;
237	}
238
239	HAIKU_INCLUDE_IN_IMAGE on $(target)
240		= [ on $(source) return $(HAIKU_INCLUDE_IN_IMAGE) ] ;
241
242	Depends $(target) : <build>copyattr <build>set_haiku_revision $(source) ;
243	CopySetHaikuRevision1 $(target)
244		: <build>copyattr <build>set_haiku_revision $(source) ;
245}
246
247actions CopySetHaikuRevision1
248{
249	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
250	revision=`(LC_ALL=C LANG=C svn info $(HAIKU_TOP) 2> /dev/null || echo Revision: 0) |
251		grep Revision | awk '{printf $2}'`
252	$(2[1]) --data $(2[3]) $(1) &&
253	$(2[2]) $(1) ${revision}
254}
255
256rule DataFileToSourceFile sourceFile : dataFile : dataVariable : sizeVariable
257{
258	sourceFile = [ FGristFiles $(sourceFile) ] ;
259	MakeLocateCommonPlatform $(sourceFile) ;
260
261	sizeVariable ?= $(dataVariable)Size ;
262
263	DATA_VARIABLE on $(sourceFile) = $(dataVariable) ;
264	SIZE_VARIABLE on $(sourceFile) = $(sizeVariable) ;
265
266	Depends $(sourceFile) : <build>data_to_source $(dataFile) ;
267	DataFileToSourceFile1 $(sourceFile) : <build>data_to_source $(dataFile) ;
268	LocalClean clean : $(sourceFile) ;
269}
270
271actions DataFileToSourceFile1
272{
273	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
274	$(2[1]) $(DATA_VARIABLE) $(SIZE_VARIABLE) $(2[2]) $(1)
275}
276
277rule DownloadFile target : url
278{
279	URL on $(target) = $(url) ;
280
281	DownloadFile1 $(target) ;
282}
283
284actions DownloadFile1
285{
286	wget -O $(1) $(URL)
287}
288