summaryrefslogtreecommitdiff
path: root/source4/build/smb_build/depend.pm
blob: 2be9c4bdf2b2f06e36b2633eb8f3effd7906c327 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
###########################################################
### SMB Build System					###
### - the dependency calculation functions		###
###							###
###  Copyright (C) Stefan (metze) Metzmacher 2004	###
###  Released under the GNU GPL				###
###########################################################

package depend;
use strict;

###########################################################
# This function resolves the dependencies 
# for the SUBSYSTEMS_LIST
# @SUBSYSTEMS_LIST = _do_calc_subsystem_list($SMB_BUILD_CTX, \@SUBSYSTEMS_LIST);
#
# $SMB_BUILD_CTX -	the global SMB_BUILD context
#
# \@SUBSYSTEMS_LIST -	the reference to the SUBSYSTEMS_LIST
#
# @SUBSYSTEMS_LIST -	the expanded resulting SUBSYSTEMS_LIST
#
sub _do_calc_subsystem_list($$)
{
	my $CTX = shift;
	my $subsys_list = shift;
	my @SUBSYSTEMS_LIST = @$subsys_list;

	#
	# now try to resolve the dependencies for the library
	#
	my $i = 0;
	my $count = $#SUBSYSTEMS_LIST;
	for (;$i<=$count;$i++) {			
		#
		# see if the current subsystem depends on other not listed subsystems
		#
		foreach my $elem (@{$CTX->{DEPEND}{SUBSYSTEMS}{$SUBSYSTEMS_LIST[$i]}{SUBSYSTEMS_LIST}}) {
			my $seen = 0;
			#
			# check if it's already in the list
			#
			foreach my $elem2 (@SUBSYSTEMS_LIST) {
				#
				# check of the names matche
				#
				if ($elem eq $elem2) {
					#
					# mark it as already in the list
					#
					$seen = 1;
					last;
				}
			}

			#
			# if it's already there skip it
			#
			if ($seen == 1) {
				next;
			}

			#
			# if it's not there add it
			# and $count++
			#
			push(@SUBSYSTEMS_LIST,$elem);
			$count++;
		}
	}

	return @SUBSYSTEMS_LIST;
}

###########################################################
# This function resolves the dependencies 
# for the LIBRARIES_LIST based on the SUBSYSTEMS_LIST
# @LIBRARIES_LIST = _do_calc_libraries_list($SMB_BUILD_CTX, \@SUBSYSTEMS_LIST, \@LIBRARIES_LIST);
#
# $SMB_BUILD_CTX -	the global SMB_BUILD context
#
# \@SUBSYSTEMS_LIST -	the reference to the SUBSYSTEMS_LIST
#
# \@LIBRARIES_LIST -	the reference to the LIBRARIES_LIST
#
# @LIBRARIES_LIST -	the expanded resulting LIBRARIES_LIST
#
sub _do_calc_libraries_list($$$)
{
	my $CTX = shift;
	my $subsys_list = shift;
	my @SUBSYSTEMS_LIST = @$subsys_list;
	my $libs_list = shift;
	my @LIBRARIES_LIST = @$libs_list;

	#
	# add the LIBARARIES of each subsysetm in the @SUBSYSTEMS_LIST
	#
	foreach my $elem (@SUBSYSTEMS_LIST) {			
		#
		# see if the subsystem depends on a not listed LIBRARY
		#
		foreach my $elem1 (@{$CTX->{DEPEND}{SUBSYSTEMS}{$elem}{LIBRARIES_LIST}}) {
			my $seen = 0;
			#
			# check if it's already in the list
			#
			foreach my $elem2 (@LIBRARIES_LIST) {
				#
				# check of the names matche
				#
				if ($elem1 eq $elem2) {
					#
					# mark it as already in the list
					#
					$seen = 1;
					last;
				}
			}

			#
			# if it's already there skip it
			#
			if ($seen == 1) {
				next;
			}

			#
			# if it's not there add it
			#
			push(@LIBRARIES_LIST,$elem1);
		}
	}

	return @LIBRARIES_LIST;
}

###########################################################
# This function creates the dependencies for subsystems
# _do_depend_subsystems($SMB_BUILD_CTX)
#
# $SMB_BUILD_CTX -	the global SMB_BUILD context
sub _do_depend_subsystems($)
{
	my $CTX = shift;

	#
	# loop on all subsystems
	#
	foreach my $key (sort keys %{$CTX->{INPUT}{SUBSYSTEMS}}) {
		my $name = $CTX->{INPUT}{SUBSYSTEMS}{$key}{NAME};
		my @STATIC_MODULES_LIST = ();
		my @INIT_FUNCTIONS = ();

		#
		# skip when the subsystem was disabled
		#
		if ($CTX->{INPUT}{SUBSYSTEMS}{$key}{ENABLE} ne "YES" ) {
			next;
		}

		#
		# create the subsystems used OBJ_LIST
		#
		my @OBJ_LIST = ();
		push (@OBJ_LIST, @{$CTX->{INPUT}{SUBSYSTEMS}{$key}{INIT_OBJ_FILES}});
		push (@OBJ_LIST, @{$CTX->{INPUT}{SUBSYSTEMS}{$key}{ADD_OBJ_FILES}});

		#
		# create the subsystems used SUBSYSTEMS_LIST
		#
		my @SUBSYSTEMS_LIST = ();
		push (@SUBSYSTEMS_LIST, (@{$CTX->{INPUT}{SUBSYSTEMS}{$key}{REQUIRED_SUBSYSTEMS}}));
		#
		# create the subsystems used LIBRARIES_LIST
		#
		my @LIBRARIES_LIST = ();
		push (@LIBRARIES_LIST, @{$CTX->{INPUT}{SUBSYSTEMS}{$key}{REQUIRED_LIBRARIES}});

		#
		# now collect the info from the subsystems static modules
		#
		foreach my $subkey (sort keys %{$CTX->{INPUT}{MODULES}}) {
			#
			# we only want STATIC modules
			#
			if ($CTX->{INPUT}{MODULES}{$subkey}{BUILD} ne "STATIC") {
				next;
			}

			#
			# we only want modules which belong to the current subsystem
			#
			if ($CTX->{INPUT}{MODULES}{$subkey}{SUBSYSTEM} ne $name) {
				next;
			}

			#
			# add it to the STATIC_MODULES_LIST
			#
			push(@STATIC_MODULES_LIST,$subkey);
			push (@INIT_FUNCTIONS, $CTX->{INPUT}{MODULES}{$subkey}{INIT_FUNCTION}) if $CTX->{INPUT}{MODULES}{$subkey}{INIT_FUNCTION} ne "";

			#
			# add OBJS of static modules to the subsystems used OBJ_LIST
			#
			push (@OBJ_LIST, (@{$CTX->{INPUT}{MODULES}{$subkey}{INIT_OBJ_FILES}}));
			push (@OBJ_LIST, (@{$CTX->{INPUT}{MODULES}{$subkey}{ADD_OBJ_FILES}}));

			#
			# add SUBSYSTEMS of static modules to the subsystems used SUBSYSTEMS_LIST
			#
			push (@SUBSYSTEMS_LIST, (@{$CTX->{INPUT}{MODULES}{$subkey}{REQUIRED_SUBSYSTEMS}}));

			#
			# add LIBRARIES of static modules to  the subsystems used LIBRARIES_LIST
			#
			push (@LIBRARIES_LIST, (@{$CTX->{INPUT}{MODULES}{$subkey}{REQUIRED_LIBRARIES}}));
		}

		#
		# set the lists
		#
		@{$CTX->{DEPEND}{SUBSYSTEMS}{$key}{INIT_FUNCTIONS}} = @INIT_FUNCTIONS;
		@{$CTX->{DEPEND}{SUBSYSTEMS}{$key}{OBJ_LIST}} = @OBJ_LIST;
		@{$CTX->{DEPEND}{SUBSYSTEMS}{$key}{STATIC_MODULES_LIST}} = @STATIC_MODULES_LIST;
		@{$CTX->{DEPEND}{SUBSYSTEMS}{$key}{SUBSYSTEMS_LIST}} = @SUBSYSTEMS_LIST;
		@{$CTX->{DEPEND}{SUBSYSTEMS}{$key}{LIBRARIES_LIST}} = @LIBRARIES_LIST;
	}

	return;
}

###########################################################
# This function creates the dependencies for ext libs
# _do_depend_ext_libs($SMB_BUILD_CTX)
#
# $SMB_BUILD_CTX -	the global SMB_BUILD context
sub _do_depend_ext_libs($)
{
	my $CTX = shift;

	#
	# loop over all ext libs
	#
	foreach my $key (sort keys %{$CTX->{INPUT}{EXT_LIBS}}) {
		my $name = $CTX->{INPUT}{EXT_LIBS}{$key}{NAME};

		#
		# if it's not a shared module skip it
		#
		if ($CTX->{INPUT}{EXT_LIBS}{$key}{ENABLE} ne "YES") {
			next;
		}

		#
		# set the lists
		#
		$CTX->{DEPEND}{EXT_LIBS}{$key}{NAME} = $name;
		@{$CTX->{DEPEND}{EXT_LIBS}{$key}{LIBS}} = @{$CTX->{INPUT}{EXT_LIBS}{$key}{LIBS}};
		@{$CTX->{DEPEND}{EXT_LIBS}{$key}{CFLAGS}} = @{$CTX->{INPUT}{EXT_LIBS}{$key}{CFLAGS}};
		@{$CTX->{DEPEND}{EXT_LIBS}{$key}{CPPFLAGS}} = @{$CTX->{INPUT}{EXT_LIBS}{$key}{CPPFLAGS}};
		@{$CTX->{DEPEND}{EXT_LIBS}{$key}{LDFLAGS}} = @{$CTX->{INPUT}{EXT_LIBS}{$key}{LDFLAGS}};
	}

	return;
}

###########################################################
# This function creates the dependencies for shared modules
# _do_depend_shared_modules($SMB_BUILD_CTX)
#
# $SMB_BUILD_CTX -	the global SMB_BUILD context
sub _do_depend_shared_modules($)
{
	my $CTX = shift;

	#
	# loop over all shared modules
	#
	foreach my $key (sort keys %{$CTX->{INPUT}{MODULES}}) {
		my $name = $CTX->{INPUT}{MODULES}{$key}{NAME};

		#
		# if it's not a shared module skip it
		#
		if ($CTX->{INPUT}{MODULES}{$key}{BUILD} ne "SHARED" ) {
			next;
		}

		#
		# create the shared modules used SUBSYSTEMS_LIST
		#
		my @SUBSYSTEMS_LIST = ();
		push (@SUBSYSTEMS_LIST, (@{$CTX->{INPUT}{MODULES}{$key}{REQUIRED_SUBSYSTEMS}}));

		#
		# now try to resolve the dependencies for the shared module
		#
		@SUBSYSTEMS_LIST = _do_calc_subsystem_list($CTX, \@SUBSYSTEMS_LIST);

		#
		# create the shared modules used LIBRARIES_LIST
		#
		my @LIBRARIES_LIST = ();
		push (@LIBRARIES_LIST, @{$CTX->{INPUT}{MODULES}{$key}{REQUIRED_LIBRARIES}});

		#
		# add the LIBARARIES of each subsysetm in the @SUBSYSTEMS_LIST
		#
		@LIBRARIES_LIST = _do_calc_libraries_list($CTX, \@SUBSYSTEMS_LIST, \@LIBRARIES_LIST);

		#
		# set the lists
		#
		@{$CTX->{DEPEND}{SHARED_MODULES}{$key}{SUBSYSTEMS_LIST}} = @SUBSYSTEMS_LIST;
		@{$CTX->{DEPEND}{SHARED_MODULES}{$key}{LIBRARIES_LIST}} = @LIBRARIES_LIST;
	}

	return;
}

###########################################################
# This function creates the dependencies for libraries
# _do_depend_libraries($SMB_BUILD_CTX)
#
# $SMB_BUILD_CTX -	the global SMB_BUILD context
sub _do_depend_libraries($)
{
	my $CTX = shift;

	#
	# loop over all libraries
	#
	foreach my $key (sort keys %{$CTX->{INPUT}{LIBRARIES}}) {
		my $name = $CTX->{INPUT}{LIBRARIES}{$key}{NAME};

		#
		# if it's not a library skip it
		#
		if ($CTX->{INPUT}{LIBRARIES}{$key}{ENABLE} ne "YES" ) {
			next;
		}

		#
		# create the libraries used SUBSYSTEMS_LIST
		#
		my @SUBSYSTEMS_LIST = ();
		push (@SUBSYSTEMS_LIST, @{$CTX->{INPUT}{LIBRARIES}{$key}{REQUIRED_SUBSYSTEMS}});

		#
		# now try to resolve the dependencies for the library
		#
		@SUBSYSTEMS_LIST = _do_calc_subsystem_list($CTX, \@SUBSYSTEMS_LIST);

		#
		# create the libraries used LIBRARIES_LIST
		#
		my @LIBRARIES_LIST = ();
		push (@LIBRARIES_LIST, @{$CTX->{INPUT}{LIBRARIES}{$key}{REQUIRED_LIBRARIES}});

		#
		# add the LIBARARIES of each subsysetm in the @SUBSYSTEMS_LIST
		#
		@LIBRARIES_LIST = _do_calc_libraries_list($CTX, \@SUBSYSTEMS_LIST, \@LIBRARIES_LIST);

		#
		# set the lists
		#
		@{$CTX->{DEPEND}{LIBRARIES}{$key}{SUBSYSTEMS_LIST}} = @SUBSYSTEMS_LIST;
		@{$CTX->{DEPEND}{LIBRARIES}{$key}{LIBRARIES_LIST}} = @LIBRARIES_LIST;
	}

	return;
}

###########################################################
# This function creates the dependencies for binaries
# _do_depend_binaries($SMB_BUILD_CTX)
#
# $SMB_BUILD_CTX -	the global SMB_BUILD context
sub _do_depend_binaries($)
{
	my $CTX = shift;

	#
	# loop over all binaries
	#
	foreach my $key (sort keys %{$CTX->{INPUT}{BINARIES}}) {
		my $name = $CTX->{INPUT}{BINARIES}{$key}{NAME};

		#
		# skip when the binary was disabled
		#
		if ($CTX->{INPUT}{BINARIES}{$key}{ENABLE} ne "YES" ) {
			next;
		}

		#
		# create the binaries used SUBSYSTEMS_LIST
		#
		my @SUBSYSTEMS_LIST = ();
		push (@SUBSYSTEMS_LIST, @{$CTX->{INPUT}{BINARIES}{$key}{REQUIRED_SUBSYSTEMS}});

		#
		# now try to resolve the dependencies for the binary
		#
		@SUBSYSTEMS_LIST = _do_calc_subsystem_list($CTX, \@SUBSYSTEMS_LIST);

		my @INIT_FUNCTIONS = ();

		foreach my $subkey (@SUBSYSTEMS_LIST)
		{
			push (@INIT_FUNCTIONS, $CTX->{INPUT}{SUBSYSTEMS}{$subkey}{INIT_FUNCTION}) if defined ($CTX->{INPUT}{SUBSYSTEMS}{$subkey}{INIT_FUNCTION}) and $CTX->{INPUT}{SUBSYSTEMS}{$subkey}{INIT_FUNCTION} ne "";
		}

		#
		# create the binaries used LIBRARIES_LIST
		#
		my @LIBRARIES_LIST = ();
		push (@LIBRARIES_LIST, @{$CTX->{INPUT}{BINARIES}{$key}{REQUIRED_LIBRARIES}});

		#
		# add the LIBARARIES of each subsysetm in the @SUBSYSTEMS_LIST
		#
		@LIBRARIES_LIST = _do_calc_libraries_list($CTX, \@SUBSYSTEMS_LIST, \@LIBRARIES_LIST);

		#
		# set the lists
		#
		@{$CTX->{DEPEND}{BINARIES}{$key}{SUBSYSTEMS_LIST}} = @SUBSYSTEMS_LIST;
		@{$CTX->{DEPEND}{BINARIES}{$key}{LIBRARIES_LIST}} = @LIBRARIES_LIST;
		@{$CTX->{DEPEND}{BINARIES}{$key}{INIT_FUNCTIONS}} = @INIT_FUNCTIONS;
	}

	return;
}

###########################################################
# This function creates the dependency tree from the SMB_BUILD 
# context
# create_depend($SMB_BUILD_CTX)
#
# $SMB_BUILD_CTX -	the global SMB_BUILD context
sub create_depend($)
{
	my $CTX = shift;

	_do_depend_ext_libs($CTX);

	_do_depend_subsystems($CTX);

	_do_depend_shared_modules($CTX);

	_do_depend_libraries($CTX);

	_do_depend_binaries($CTX);

	return;
}
1;