summaryrefslogtreecommitdiff
path: root/source4/build/smb_build/makefile.pm
blob: 5d567d9b72497fd79fc5ced8044c52302abb68f5 (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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
###########################################################
### SMB Build System					###
### - create output for Makefile			###
###							###
###  Copyright (C) Stefan (metze) Metzmacher 2004	###
###  Released under the GNU GPL				###
###########################################################

package makefile;
use strict;

sub _prepare_command_interpreters($)
{
	my $ctx = shift;
	my $output;

	$output = "
SHELL=/bin/sh
PERL=\@PERL\@
";
	return $output;
}

sub _prepare_path_vars($)
{
	my $ctx = shift;
	my $output;

	$output = "
prefix=\@prefix\@
exec_prefix=\@exec_prefix\@
VPATH=\@srcdir\@
srcdir=\@srcdir\@
builddir=\@builddir\@

BASEDIR= \@prefix\@
BINDIR = \@bindir\@
SBINDIR = \@sbindir\@
LIBDIR = \@libdir\@
CONFIGDIR = \@configdir\@
VARDIR = \@localstatedir\@


# The permissions to give the executables
INSTALLPERMS = 0755

# set these to where to find various files
# These can be overridden by command line switches (see smbd(8))
# or in smb.conf (see smb.conf(5))
LOGFILEBASE = \@logfilebase\@
CONFIGFILE = \$(CONFIGDIR)/smb.conf
LMHOSTSFILE = \$(CONFIGDIR)/lmhosts
NCALRPCDIR = \@localstatedir\@/ncalrpc

# This is where smbpasswd et al go
PRIVATEDIR = \@privatedir\@
SMB_PASSWD_FILE = \$(PRIVATEDIR)/smbpasswd

# the directory where lock files go
LOCKDIR = \@lockdir\@

# the directory where pid files go
PIDDIR = \@piddir\@

PASSWD_FLAGS = -DSMB_PASSWD_FILE=\\\"\$(SMB_PASSWD_FILE)\\\" -DPRIVATE_DIR=\\\"\$(PRIVATEDIR)\\\"
PATH_FLAGS1 = -DCONFIGFILE=\\\"\$(CONFIGFILE)\\\"  -DSBINDIR=\\\"\$(SBINDIR)\\\"
PATH_FLAGS2 = \$(PATH_FLAGS1) -DBINDIR=\\\"\$(BINDIR)\\\" 
PATH_FLAGS3 = \$(PATH_FLAGS2) -DLMHOSTSFILE=\\\"\$(LMHOSTSFILE)\\\" 
PATH_FLAGS4 = \$(PATH_FLAGS3) -DLOCKDIR=\\\"\$(LOCKDIR)\\\" -DPIDDIR=\\\"\$(PIDDIR)\\\"
PATH_FLAGS5 = \$(PATH_FLAGS4) -DLIBDIR=\\\"\$(LIBDIR)\\\" \\
	      -DLOGFILEBASE=\\\"\$(LOGFILEBASE)\\\" -DSHLIBEXT=\\\"\@SHLIBEXT\@\\\"
PATH_FLAGS6 = \$(PATH_FLAGS5) -DCONFIGDIR=\\\"\$(CONFIGDIR)\\\" -DNCALRPCDIR=\\\"\$(NCALRPCDIR)\\\"
PATH_FLAGS = \$(PATH_FLAGS6) \$(PASSWD_FLAGS)
";
	return $output;
}

sub _prepare_compiler_linker($)
{
	my $ctx = shift;
	my $output;

	$output = "
CC=\@CC\@
CC_FLAGS=-Iinclude -I. -I\$(srcdir)/include -I\$(srcdir) -D_SAMBA_BUILD_ -Ilib \@CFLAGS\@ \@CPPFLAGS\@

LD=\@CC\@
LD_FLAGS=\@LDFLAGS\@ \@CFLAGS\@

STLD=ar
STLD_FLAGS=-rc

SHLD=\@CC\@
SHLD_FLAGS=\@LDSHFLAGS\@ \@LDFLAGS\@
";
	return $output;
}

sub _prepare_default_rule($)
{
	my $ctx = shift;
	my $output;

	$output = "
default: all
";
	return $output;
}

sub _prepare_SUFFIXES($)
{
	my $ctx = shift;
	my $output;

	$output = "
.SUFFIXES:
.SUFFIXES: .c .o .h .h.gch .a .so
";
	return $output;
}

sub _prepare_IDL($)
{
	my $ctx = shift;
	my $output;

	$output = "
idl_full: build/pidl/idl.pm
	CPP=\"\@CPP\@\" PERL=\"\$(PERL)\" script/build_idl.sh FULL

idl: build/pidl/idl.pm
	\@CPP=\"\@CPP\@\" PERL=\"\$(PERL)\" script/build_idl.sh PARTIAL

build/pidl/idl.pm: build/pidl/idl.yp
	-yapp -s build/pidl/idl.yp

pch: proto include/includes.h.gch

pch_clean:
	-rm -f include/includes.h.gch

basics: idl proto_exists

";
	return $output;
}

sub _prepare_dummy_MAKEDIR()
{
	my $ctx = shift;
	my $output;

	$output = "
bin/.dummy:
	\@: >> \$\@ || : > \$\@

dynconfig.o: dynconfig.c Makefile
	\@echo Compiling \$*.c
	\@\$(CC) \$(CC_FLAGS) \@PICFLAG\@ \$(PATH_FLAGS) -c \$< -o \$\@
\@BROKEN_CC\@	-mv `echo \$\@ | sed 's%^.*/%%g'` \$\@

";
	return $output;
}

###########################################################
# This function creates a standard make rule which is using $(CC)
#
# $output = _prepare_std_CC_rule($srcext,$destext,$flags,$message,$comment)
#
# $srcext -	sourcefile extension
#
# $destext -	destinationfile extension
#
# $flags -	additional compiler flags
#
# $message -	logmessage which is echoed while running this rule
#
# $comment -	just a comment what this rule should do
#
# $output -		the resulting output buffer
sub _prepare_std_CC_rule($$$$$)
{
	my $src = shift;
	my $dst = shift;
	my $flags = shift;
	my $message = shift;
	my $comment = shift;
	my $flagsstr = "";
	my $output;

	$output = "
###################################
# Start $comment
.$src.$dst:
	\@echo $message \$*.$src
	\@\$(CC) \$(CC_FLAGS) $flags -c \$< -o \$\@
\@BROKEN_CC\@	-mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
#End $comment
###################################
";

	return $output;
}

sub array2oneperline($)
{
	my $array = shift;
	my $i;
	my $output = "";

	foreach my $str (@{$array}) {
		if (!defined($str)) {
			next;
		}

		$output .= " \\\n\t\t";
		$output .= $str;
	}

	return $output;
}

sub array2oneline($)
{
	my $array = shift;
	my $i;
	my $output = "";

	foreach my $str (@{$array}) {
		if (!defined($str)) {
			next;
		}

		$output .= $str;
		$output .= " ";
	}

	return $output;
}

###########################################################
# This function creates a object file list
#
# $output = _prepare_var_obj_list($var, $var_ctx)
#
# $var_ctx -		the subsystem context
#
# $var_ctx->{NAME} 	-	the <var> name
# $var_ctx->{OBJ_LIST} 	-	the list of objectfiles which sould be linked to this <var>
#
# $output -		the resulting output buffer
sub _prepare_obj_list($$)
{
	my $var = shift;
	my $ctx = shift;
	my $tmpobjlist;
	my $output;

	$tmpobjlist = array2oneperline($ctx->{OBJ_LIST});

	$output = "
###################################
# Start $var $ctx->{NAME} OBJ LIST
$var\_$ctx->{NAME}_OBJS =$tmpobjlist
# End $var $ctx->{NAME} OBJ LIST
###################################
";

	return $output;
}

###########################################################
# This function creates a object file list for a subsystem
#
# $output = _prepare_subsystem_obj_list($subsystem_ctx)
#
# $subsystem_ctx -		the subsystem context
#
# $subsystem_ctx->{NAME} -	the subsystem name
# $subsystem_ctx->{OBJ_LIST} -	the list of objectfiles which sould be linked to this subsystem
#
# $output -		the resulting output buffer
sub _prepare_subsystem_obj_list($)
{
	my $ctx = shift;

	return _prepare_var_obj_list("SUBSYSTEM",$ctx);
}

###########################################################
# This function creates a object file list for a module
#
# $output = _prepare_module_obj_and_lib_list($module_ctx)
#
# $module_ctx -		the module context
#
# $module_ctx->{NAME} -		the module binary name
# $module_ctx->{OBJ_LIST} -	the list of objectfiles which sould be linked to this module
#
# $output -		the resulting output buffer
sub _prepare_module_obj_list($)
{
	my $ctx = shift;

	return _prepare_var_obj_list("MODULE",$ctx);

}

###########################################################
# This function creates a make rule for linking a library
#
# $output = _prepare_shared_library_rule($library_ctx)
#
# $library_ctx -		the library context
#
# $library_ctx->{NAME} -		the library name
#
# $library_ctx->{DEPEND_LIST} -		the list of rules on which this library depends
#
# $library_ctx->{LIBRARY_NAME} -	the shared library name
# $library_ctx->{LIBRARY_REALNAME} -	the shared library real name
# $library_ctx->{LIBRARY_SONAME} - the shared library soname
# $library_ctx->{LINK_LIST} -	the list of objectfiles and external libraries
#					which sould be linked to this shared library
# $library_ctx->{LINK_FLAGS} -	linker flags used by this shared library
#
# $output -		the resulting output buffer
sub _prepare_shared_library_rule($)
{
	my $ctx = shift;
	my $tmpdepend;
	my $tmpstlink;
	my $tmpstflag;
	my $tmpshlink;
	my $tmpshflag;
	my $tmprules;
	my $output;
	my $outname = $ctx->{OUTPUT};

	$tmpdepend = array2oneperline($ctx->{DEPEND_LIST});

	$tmpshlink = array2oneperline($ctx->{LINK_LIST});
	$tmpshflag = array2oneperline($ctx->{LINK_FLAGS});

	$output = "
###################################
# Start Library $ctx->{NAME}
#
LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
#
LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST =$tmpshlink
LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS =$tmpshflag
#

# Shared $ctx->{LIBRARY_NAME}
$ctx->{OUTPUT}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
	\@echo Linking \$\@
	\@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \\
		\$(LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS) \\
		\$(LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST)
";

	if (defined($ctx->{LIBRARY_SONAME})) {
		$output .= "
# Symlink $ctx->{LIBRARY_SONAME}
bin/$ctx->{LIBRARY_SONAME}: bin/$ctx->{LIBRARY_REALNAME} bin/.dummy
	\@echo Symlink \$\@
	\@ln -sf $ctx->{LIBRARY_REALNAME} \$\@
# Symlink $ctx->{LIBRARY_NAME}
bin/$ctx->{LIBRARY_NAME}: bin/$ctx->{LIBRARY_SONAME} bin/.dummy
	\@echo Symlink \$\@
	\@ln -sf $ctx->{LIBRARY_SONAME} \$\@
";
		$outname = $ctx->{LIBRARY_NAME};
	}

	$output .= "
library_$ctx->{NAME}: basics bin/$outname
# End Library $ctx->{NAME}
###################################
";

	return $output;
}

###########################################################
# This function creates a make rule for linking a library
#
# $output = _prepare_static_library_rule($library_ctx)
#
# $library_ctx -		the library context
#
# $library_ctx->{NAME} -		the library name
#
# $library_ctx->{DEPEND_LIST} -		the list of rules on which this library depends
#
# $library_ctx->{LIBRARY_NAME} -	the static library name
# $library_ctx->{LINK_LIST} -	the list of objectfiles	which sould be linked
#					to this static library
# $library_ctx->{LINK_FLAGS} -	linker flags used by this static library
#
# $output -		the resulting output buffer
sub _prepare_static_library_rule($)
{
	my $ctx = shift;
	my $tmpdepend;
	my $tmpstlink;
	my $tmpstflag;
	my $tmpshlink;
	my $tmpshflag;
	my $tmprules;
	my $output;

	$tmpdepend = array2oneperline($ctx->{DEPEND_LIST});

	$tmpstlink = array2oneperline($ctx->{LINK_LIST});
	$tmpstflag = array2oneperline($ctx->{LINK_FLAGS});

	$tmprules = "bin/$ctx->{LIBRARY_NAME}";

	$output = "
###################################
# Start Library $ctx->{NAME}
#
LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
#
LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
#
# Static $ctx->{LIBRARY_NAME}
$ctx->{OUTPUT}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
	\@echo Linking \$\@
	\@\$(STLD) \$(STLD_FLAGS) \$\@ \\
		\$(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)

library_$ctx->{NAME}: basics $tmprules
# End Library $ctx->{NAME}
###################################
";

	return $output;
}



###########################################################
# This function creates a make rule for linking a binary
#
# $output = _prepare_binary_rule($binary_ctx)
#
# $binary_ctx -		the binary context
#
# $binary_ctx->{NAME} -		the binary name
# $binary_ctx->{BINARY} -	the binary binary name
#
# $binary_ctx->{DEPEND_LIST} -	the list of rules on which this binary depends
# $binary_ctx->{LINK_LIST} -	the list of objectfiles and external libraries
#				which sould be linked to this binary
# $binary_ctx->{LINK_FLAGS} -	linker flags used by this binary
#
# $output -		the resulting output buffer
sub _prepare_binary_rule($)
{
	my $ctx = shift;
	my $tmpdepend;
	my $tmplink;
	my $tmpflag;
	my $output;

	$tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
	$tmplink = array2oneperline($ctx->{LINK_LIST});
	$tmpflag = array2oneperline($ctx->{LINK_FLAGS});

	$output = "
###################################
# Start Binary $ctx->{BINARY}
#
BINARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
BINARY_$ctx->{NAME}_LINK_LIST =$tmplink
BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
#
bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST)
	\@echo Linking \$\@
	\@\$(LD) \$(LD_FLAGS) -o \$\@ \\
		\$(BINARY_$ctx->{NAME}_LINK_FLAGS) \\
		\$(BINARY_$ctx->{NAME}_LINK_LIST) \\
		\$(BINARY_$ctx->{NAME}_LINK_FLAGS)
binary_$ctx->{BINARY}: basics bin/$ctx->{BINARY}
# End Binary $ctx->{BINARY}
###################################
";

	return $output;
}

sub _prepare_proto_rules()
{
	my $output = "";

	$output .= "
# Making this target will just make sure that the prototype files
# exist, not necessarily that they are up to date.  Since they're
# removed by 'make clean' this will always be run when you do anything
# afterwards.
proto_exists: include/proto.h include/build_env.h

delheaders: pch_clean
	-rm -f \$(builddir)/include/proto.h \$(builddir)/include/build_env.h:

include/proto.h:
	\@cd \$(srcdir) && \$(SHELL) script/mkproto.sh \"\$(PERL)\" \\
	  -h _PROTO_H_ \$(builddir)/include/proto.h \\
	  \$(PROTO_PROTO_OBJS)

include/build_env.h:
	\@echo Building include/build_env.h
	\@cd \$(srcdir) && \$(SHELL) script/build_env.sh \$(srcdir) \$(builddir) \$(CC) > \$(builddir)/include/build_env.h

# 'make headers' or 'make proto' calls a subshell because we need to
# make sure these commands are executed in sequence even for a
# parallel make.
headers: delheaders proto_exists

proto: idl headers

proto_test:
	\@[ -f \$(builddir)/include/proto.h ] || \$(MAKE) proto

clean: delheaders
	-rm -f *.o */*.o */*/*.o */*/*/*.o bin/*
	-rm -rf librpc/gen_*

distclean: clean
	-rm -f bin/.dummy
	-rm -f include/config.h 
	-rm -f Makefile*
	-rm -f config.status
	-rm -f config.smb_build.*
	-rm -f config.log config.cache

removebackup:
	-rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~

realdistclean: distclean removebackup
	-rm -f include/config.h.in
	-rm -f lib/version.h
	-rm -f configure
";

	return $output;
}

sub _prepare_make_target($)
{
	my $ctx = shift;
	my $tmpdepend;
	my $output;

	$tmpdepend = array2oneperline($ctx->{DEPEND_LIST});

	$output = "
###################################
# Start Target $ctx->{TARGET}
$ctx->{TARGET}: basics $tmpdepend
# End Target $ctx->{TARGET}
###################################
";

	return $output;
}

sub _prepare_obj_lists($)
{
	my $CTX = shift;
	my $output = "";

	foreach my $key (values %{$CTX}) {
		next if not defined($key->{OBJ_LIST});
		$output .= _prepare_obj_list($key->{TYPE}, $key);
	}

	return $output;
}

sub _prepare_install_rules($)
{
	my $CTX = shift;
	my $output = "";

	$output .= "

showlayout: 
	\@echo \"Samba will be installed into:\"
	\@echo \"  basedir: \$(BASEDIR)\"
	\@echo \"  bindir:  \$(BINDIR)\"
	\@echo \"  sbindir: \$(SBINDIR)\"
	\@echo \"  libdir:  \$(LIBDIR)\"
	\@echo \"  vardir:  \$(VARDIR)\"
	\@echo \"  privatedir:  \$(PRIVATEDIR)\"
	\@echo \"  piddir:  \$(PIDDIR)\"
	\@echo \"  lockdir:  \$(LOCKDIR)\"

showflags:
	\@echo \"Samba will be compiled with flags:\"
	\@echo \"  CC_FLAGS = \$(CC_FLAGS)\"
	\@echo \"  LD_FLAGS = \$(LD_FLAGS)\"
	\@echo \"  STLD_FLAGS = \$(STLD_FLAGS)\"
	\@echo \"  SHLD_FLAGS = \$(SHLD_FLAGS)\"

SBIN_PROGS = bin/smbd

BIN_PROGS = bin/smbclient \\
		bin/net \\
		bin/nmblookup \\
		bin/ntlm_auth

TORTURE_PROGS = bin/smbtorture \\
		bin/gentest \\
		bin/locktest \\
		bin/masktest \\
		bin/ndrdump

LDB_PROGS = 	bin/ldbadd \\
		bin/ldbdel \\
		bin/ldbmodify \\
		bin/ldbedit \\
		bin/ldbsearch

REG_PROGS = 	bin/regpatch \\
		bin/regshell \\
		bin/regtree \\
		bin/regpatch \\
		bin/regdiff

install: showlayout installbin installtorture installldb installreg installdat 

# DESTDIR is used here to prevent packagers wasting their time
# duplicating the Makefile. Remove it and you will have the privelege
# of package each samba release for muliple versions of multiple
# distributions and operating systems, or at least supplying patches
# to all the packaging files required for this, prior to committing
# the removal of DESTDIR. Do not remove it even though you think it
# is not used

installdirs:
	\@\$(SHELL) \$(srcdir)/script/installdirs.sh \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(SBINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(DESTDIR)\$(PRIVATEDIR) \$(DESTDIR)\$(PIDDIR) \$(DESTDIR)\$(LOCKDIR)

installbin: all installdirs
	\@\$(SHELL) \$(srcdir)/script/installbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(SBINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(SBIN_PROGS)
	\@\$(SHELL) \$(srcdir)/script/installbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(BIN_PROGS)

installtorture: all installdirs
	\@\$(SHELL) \$(srcdir)/script/installbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(TORTURE_PROGS)

installldb: all installdirs
	\@\$(SHELL) \$(srcdir)/script/installbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(LDB_PROGS)

installreg: all installdirs
	\@\$(SHELL) \$(srcdir)/script/installbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(REG_PROGS)

installdat: installdirs
	\@\$(SHELL) \$(srcdir)/script/installdat.sh \$(DESTDIR)\$(LIBDIR) \$(srcdir)

uninstall: uninstallbin uninstalltorture uninstallldb uninstallreg

uninstallbin:
	\@\$(SHELL) \$(srcdir)/script/uninstallbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(SBINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(DESTDIR)\$(SBIN_PROGS)

uninstalltorture:
	\@\$(SHELL) \$(srcdir)/script/uninstallbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(DESTDIR)\$(TORTURE_PROGS)

uninstallldb:
	\@\$(SHELL) \$(srcdir)/script/uninstallbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(DESTDIR)\$(LDB_PROGS)

uninstallreg:
	\@\$(SHELL) \$(srcdir)/script/uninstallbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(DESTDIR)\$(REG_PROGS)

# Swig extensions

swig: scripting/swig/_tdb.so scripting/swig/_dcerpc.so

scripting/swig/tdb_wrap.c: scripting/swig/tdb.i
	swig -python scripting/swig/tdb.i

scripting/swig/_tdb.so: scripting/swig/tdb_wrap.o \$(LIBRARY_swig_tdb_DEPEND_LIST)
	\$(SHLD) \$(SHLD_FLAGS) -o scripting/swig/_tdb.so scripting/swig/tdb_wrap.o \\
		\$(LIBRARY_swig_tdb_SHARED_LINK_LIST) \$(LIBRARY_swig_tdb_SHARED_LINK_FLAGS)

SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i

scripting/swig/dcerpc_wrap.c: scripting/swig/dcerpc.i scripting/swig/samba.i scripting/swig/status_codes.i \$(SWIG_INCLUDES)
	swig -python scripting/swig/dcerpc.i

scripting/swig/_dcerpc.so: scripting/swig/dcerpc_wrap.o \$(LIBRARY_swig_dcerpc_DEPEND_LIST)
	\$(SHLD) \$(SHLD_FLAGS) -o scripting/swig/_dcerpc.so scripting/swig/dcerpc_wrap.o \$(LIBRARY_swig_dcerpc_SHARED_LINK_LIST) \$(LIBRARY_swig_dcerpc_SHARED_LINK_FLAGS)

swig_clean:
	-rm -f scripting/swig/_tdb.so scripting/swig/tdb.pyc \\
		scripting/swig/tdb.py scripting/swig/tdb_wrap.c \\
		scripting/swig/tdb_wrap.o

everything: all

etags:
	etags `find \$(srcdir) -name \"*.[ch]\"`

ctags:
	ctags `find \$(srcdir) -name \"*.[ch]\"`

";

	return $output;
}

sub _prepare_rule_lists($)
{
	my $depend = shift;
	my $output = "";

	foreach my $key (values %{$depend}) {
		next if not defined $key->{OUTPUT_TYPE};
		($output .= _prepare_static_library_rule($key)) if $key->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
		($output .= _prepare_shared_library_rule($key)) if $key->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
		($output .= _prepare_binary_rule($key)) if $key->{OUTPUT_TYPE} eq "BINARY";
	}

	my $idl_ctx;
	$output .= _prepare_IDL($idl_ctx);

	$output .= _prepare_proto_rules();

	$output .= _prepare_install_rules($depend);

	return $output;
}

###########################################################
# This function prepares the output for Makefile
#
# $output = _prepare_makefile_in($SMB_BUILD_CTX)
#
# $SMB_BUILD_CTX -	the global SMB_BUILD context
#
# $output -		the resulting output buffer
sub _prepare_makefile_in($)
{
	my $CTX = shift;
	my $output;

	$output  = "########################################\n";
	$output .= "# Autogenerated by config.smb_build.pl #\n";
	$output .= "########################################\n";

	my $cmd_ctx;
	$output .= _prepare_command_interpreters($cmd_ctx);

	my $path_ctx;
	$output .= _prepare_path_vars($path_ctx);

	my $compiler_ctx;
	$output .= _prepare_compiler_linker($compiler_ctx);

	my $rules_ctx;
	$output .= _prepare_default_rule($rules_ctx);

	my $suffix_ctx;
	$output .= _prepare_SUFFIXES($suffix_ctx);

	$output .= _prepare_dummy_MAKEDIR();

	$output .= _prepare_std_CC_rule("c","o","\@PICFLAG\@","Compiling","Rule for std objectfiles");
	$output .= _prepare_std_CC_rule("h","h.gch","\@PICFLAG\@","Precompiling","Rule for precompiled headerfiles");

	$output .= _prepare_obj_lists($CTX);

	$output .= _prepare_rule_lists($CTX);

	my @all = ();
	
	foreach my $part (values %{$CTX}) {
		push (@all, $part->{OUTPUT}) if defined ($part->{OUTPUT_TYPE}) and $part->{OUTPUT_TYPE} eq "BINARY";	
	}
	
	$output .= _prepare_make_target({ TARGET => "all", DEPEND_LIST => \@all });

	return $output;
}

###########################################################
# This function creates Makefile.in from the SMB_BUILD 
# context
#
# create_makefile_in($SMB_BUILD_CTX)
#
# $SMB_BUILD_CTX -	the global SMB_BUILD context
#
# $output -		the resulting output buffer
sub create_makefile_in($)
{
	my $CTX = shift;

	open(MAKEFILE_IN,"> Makefile.in") || die ("Can't open Makefile.in\n");
	print MAKEFILE_IN _prepare_makefile_in($CTX);
	close(MAKEFILE_IN);

	print "config.smb_build.pl: creating Makefile.in\n";
	return;	
}

1;