942ecd24c3c56685632d306a91f9de631f5ae893
[gd/samba/.git] / source4 / build / smb_build / makefile.pm
1 ###########################################################
2 ### SMB Build System                                    ###
3 ### - create output for Makefile                        ###
4 ###                                                     ###
5 ###  Copyright (C) Stefan (metze) Metzmacher 2004       ###
6 ###  Copyright (C) Jelmer Vernooij 2005                 ###
7 ###  Released under the GNU GPL                         ###
8 ###########################################################
9
10 package makefile;
11 use config qw(%config);
12 use strict;
13
14 sub _prepare_path_vars()
15 {
16         my $output;
17
18         $output = << '__EOD__';
19 prefix = @prefix@
20 exec_prefix = @exec_prefix@
21 VPATH = @srcdir@
22 srcdir = @srcdir@
23 builddir = @builddir@
24
25 BASEDIR = @prefix@
26 BINDIR = @bindir@
27 SBINDIR = @sbindir@
28 LIBDIR = @libdir@
29 CONFIGDIR = @configdir@
30 localstatedir = @localstatedir@
31 SWATDIR = @swatdir@
32 VARDIR = @localstatedir@
33
34 # The permissions to give the executables
35 INSTALLPERMS = 0755
36
37 # set these to where to find various files
38 # These can be overridden by command line switches (see smbd(8))
39 # or in smb.conf (see smb.conf(5))
40 LOGFILEBASE = @logfilebase@
41 CONFIGFILE = $(CONFIGDIR)/smb.conf
42 LMHOSTSFILE = $(CONFIGDIR)/lmhosts
43 NCALRPCDIR = @localstatedir@/ncalrpc
44
45 # This is where smbpasswd et al go
46 PRIVATEDIR = @privatedir@
47 SMB_PASSWD_FILE = $(PRIVATEDIR)/smbpasswd
48
49 # the directory where lock files go
50 LOCKDIR = @lockdir@
51
52 # the directory where pid files go
53 PIDDIR = @piddir@
54
55 MANDIR = @mandir@
56
57 PATH_FLAGS = -DCONFIGFILE=\"$(CONFIGFILE)\"  -DSBINDIR=\"$(SBINDIR)\" \
58          -DBINDIR=\"$(BINDIR)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\" \
59          -DLOCKDIR=\"$(LOCKDIR)\" -DPIDDIR=\"$(PIDDIR)\" -DLIBDIR=\"$(LIBDIR)\" \
60          -DLOGFILEBASE=\"$(LOGFILEBASE)\" -DSHLIBEXT=\"@SHLIBEXT@\" \
61          -DCONFIGDIR=\"$(CONFIGDIR)\" -DNCALRPCDIR=\"$(NCALRPCDIR)\" \
62          -DSWATDIR=\"$(SWATDIR)\" -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\" \
63          -DPRIVATE_DIR=\"$(PRIVATEDIR)\"
64 __EOD__
65
66         return $output;
67 }
68
69 sub _prepare_compiler_linker()
70 {
71         return << "__EOD__";
72 SHELL=$config{SHELL}
73 PERL=$config{PERL}
74 CC=$config{CC}
75 CFLAGS=-I\$(srcdir)/include -I\$(srcdir) -D_SAMBA_BUILD_ -DHAVE_CONFIG_H -I\$(srcdir)/lib $config{CFLAGS} $config{CPPFLAGS}
76
77 LD=$config{LD}
78 LD_FLAGS=$config{LDFLAGS} -Lbin
79
80 STLD=$config{AR}
81 STLD_FLAGS=-rc
82
83 SHLD=$config{CC}
84 SHLD_FLAGS=$config{LDSHFLAGS} -Lbin
85
86 XSLTPROC=$config{XSLTPROC}
87
88 LEX=$config{LEX}
89 YACC=$config{YACC}
90
91 __EOD__
92 }
93
94 sub _prepare_default_rule()
95 {
96         return << '__EOD__';
97 default: all
98
99 __EOD__
100 }
101
102 sub _prepare_SUFFIXES()
103 {
104         return << '__EOD__';
105 .SUFFIXES:
106 .SUFFIXES: .c .et .y .l .d .o .h .h.gch .a .so .1 .1.xml .3 .3.xml .5 .5.xml .7 .7.xml
107
108 __EOD__
109 }
110
111 sub _prepare_IDL()
112 {
113         return << '__EOD__';
114 idl_full: build/pidl/Parse/Pidl/IDL.pm
115         @CPP="$(CPP)" PERL="$(PERL)" script/build_idl.sh FULL @PIDL_ARGS@
116
117 idl: build/pidl/Parse/Pidl/IDL.pm
118         @CPP="$(CPP)" PERL="$(PERL)" script/build_idl.sh PARTIAL @PIDL_ARGS@
119
120 build/pidl/Parse/Pidl/IDL.pm: build/pidl/idl.yp
121         -yapp -s -m 'Parse::Pidl::IDL' -o build/pidl/Parse/Pidl/IDL.pm build/pidl/idl.yp 
122
123 smb_interfaces: build/pidl/smb_interfaces.pm
124         $(PERL) -Ibuild/pidl script/build_smb_interfaces.pl \
125                 include/smb_interfaces.h
126
127 build/pidl/smb_interfaces.pm: build/pidl/smb_interfaces.yp
128         -yapp -s -m 'smb_interfaces' -o build/pidl/smb_interfaces.pm build/pidl/smb_interfaces.yp 
129
130 pch: proto include/includes.h.gch
131
132 pch_clean:
133         -rm -f include/includes.h.gch
134
135 basics: idl proto_exists HEIMDAL_EXTERNAL
136
137 test: @DEFAULT_TEST_TARGET@
138
139 test-swrap: all
140         ./script/tests/selftest.sh @selftest_prefix@/st all SOCKET_WRAPPER
141
142 test-noswrap: all
143         ./script/tests/selftest.sh @selftest_prefix@/st all
144
145 quicktest: all
146         ./script/tests/selftest.sh @selftest_prefix@/st quick SOCKET_WRAPPER
147
148 valgrindtest: all
149         SMBD_VALGRIND="xterm -n smbd -e valgrind -q --db-attach=yes --num-callers=30" \
150         ./script/tests/selftest.sh @selftest_prefix@/st quick SOCKET_WRAPPER
151
152 __EOD__
153 }
154
155 sub _prepare_man_rule($)
156 {
157         my $suffix = shift;
158
159         return << "__EOD__";
160 .$suffix.xml.$suffix:
161         \$(XSLTPROC) -o \$@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl \$<
162
163 __EOD__
164 }
165
166 sub _prepare_binaries($)
167 {
168         my $ctx = shift;
169
170         my @bbn_list = ();
171         my @sbn_list = ();
172
173         foreach (values %$ctx) {
174                 next unless defined $_->{OUTPUT_TYPE};
175                 next unless ($_->{OUTPUT_TYPE} eq "BINARY");
176
177                 push (@sbn_list, $_->{OUTPUT}) if ($_->{INSTALLDIR} eq "SBINDIR");
178                 push(@bbn_list, $_->{OUTPUT}) if ($_->{INSTALLDIR} eq "BINDIR");
179         }
180
181         my $bbn = array2oneperline(\@bbn_list);
182         my $sbn = array2oneperline(\@sbn_list);
183         return << "__EOD__";
184 BIN_PROGS = $bbn
185 SBIN_PROGS = $sbn
186
187 binaries: \$(BIN_PROGS) \$(SBIN_PROGS)
188
189 __EOD__
190 }
191
192 sub _prepare_manpages($)
193 {
194         my $ctx = shift;
195
196         my @mp_list = ();
197
198         foreach (values %$ctx) {
199                 push (@mp_list, $_->{MANPAGE}) if (defined($_->{MANPAGE}) and $_->{MANPAGE} ne "");
200         }
201         
202         my $mp = array2oneperline(\@mp_list);
203         return << "__EOD__";
204 MANPAGES = $mp
205
206 manpages: \$(MANPAGES)
207
208 __EOD__
209 }
210
211 sub _prepare_dummy_MAKEDIR()
212 {
213         my $ctx = shift;
214
215         return  << '__EOD__';
216 bin/.dummy:
217         @: >> $@ || : > $@
218
219 dynconfig.o: dynconfig.c Makefile
220         @echo Compiling $*.c
221         @$(CC) $(CFLAGS) @PICFLAG@ $(PATH_FLAGS) -c $< -o $@
222 @BROKEN_CC@     -mv `echo $@ | sed 's%^.*/%%g'` $@
223
224 __EOD__
225 }
226
227 sub _prepare_et_rule()
228 {
229         return << '__EOD__';
230
231 .et.c: 
232         $(MAKE) bin/compile_et
233         ./bin/compile_et $<
234         mv `basename $@` $@
235
236 __EOD__
237 }
238
239 sub _prepare_yacc_rule()
240 {
241         return << '__EOD__';
242 .y.c:
243         $(YACC) -d -o $@ $<     
244         
245 __EOD__
246 }
247
248 sub _prepare_lex_rule()
249 {
250         return << '__EOD__';
251 .l.c:
252         $(LEX) -o $@ $<
253
254 __EOD__
255 }
256
257 sub _prepare_depend_CC_rule()
258 {
259         return << '__EOD__';
260
261 .c.d:
262         @echo "Generating dependencies for $<"
263         @$(CC) -MM -MG -MT $(<:.c=.o) -MF $@ $(CFLAGS) $<
264
265 __EOD__
266 }
267
268 ###########################################################
269 # This function creates a standard make rule which is using $(CC)
270 #
271 # $output = _prepare_std_CC_rule($srcext,$destext,$flags,$message,$comment)
272 #
273 # $srcext -     sourcefile extension
274 #
275 # $destext -    destinationfile extension
276 #
277 # $flags -      additional compiler flags
278 #
279 # $message -    logmessage which is echoed while running this rule
280 #
281 # $comment -    just a comment what this rule should do
282 #
283 # $output -             the resulting output buffer
284 sub _prepare_std_CC_rule($$$$$)
285 {
286         my ($src,$dst,$flags,$message,$comment) = @_;
287
288         return << "__EOD__";
289 # $comment
290 .$src.$dst:
291         \@echo $message \$\*.$src
292         \@\$(CC) `script/cflags.sh \$\@` \$(CFLAGS) $flags -c \$< -o \$\@
293 \@BROKEN_CC\@   -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
294
295 __EOD__
296 }
297
298 sub array2oneperline($)
299 {
300         my $array = shift;
301         my $output = "";
302
303         foreach (@$array) {
304                 next unless defined($_);
305
306                 $output .= " \\\n\t\t$_";
307         }
308
309         return $output;
310 }
311
312 ###########################################################
313 # This function creates a object file list
314 #
315 # $output = _prepare_var_obj_list($var, $var_ctx)
316 #
317 # $var_ctx -            the subsystem context
318 #
319 # $var_ctx->{NAME}      -       the <var> name
320 # $var_ctx->{OBJ_LIST}  -       the list of objectfiles which sould be linked to this <var>
321 #
322 # $output -             the resulting output buffer
323 sub _prepare_obj_list($$)
324 {
325         my ($var,$ctx) = @_;
326
327         my $tmplist = array2oneperline($ctx->{OBJ_LIST});
328
329         return << "__EOD__";
330 # $var $ctx->{NAME} OBJ LIST
331 $var\_$ctx->{NAME}_OBJS =$tmplist
332
333 __EOD__
334 }
335
336 sub _prepare_cflags($$)
337 {
338         my ($var,$ctx) = @_;
339
340         my $tmplist = array2oneperline($ctx->{CFLAGS});
341
342         return << "__EOD__";
343 $var\_$ctx->{NAME}_CFLAGS =$tmplist
344
345 __EOD__
346 }
347
348 ###########################################################
349 # This function creates a make rule for linking a library
350 #
351 # $output = _prepare_shared_library_rule($library_ctx)
352 #
353 # $library_ctx -                the library context
354 #
355 # $library_ctx->{NAME} -                the library name
356 #
357 # $library_ctx->{DEPEND_LIST} -         the list of rules on which this library depends
358 #
359 # $library_ctx->{LIBRARY_NAME} -        the shared library name
360 # $library_ctx->{LIBRARY_REALNAME} -    the shared library real name
361 # $library_ctx->{LIBRARY_SONAME} - the shared library soname
362 # $library_ctx->{LINK_LIST} -   the list of objectfiles and external libraries
363 #                                       which sould be linked to this shared library
364 # $library_ctx->{LINK_FLAGS} -  linker flags used by this shared library
365 #
366 # $output -             the resulting output buffer
367 sub _prepare_shared_library_rule($)
368 {
369         my $ctx = shift;
370         my $output;
371
372         my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
373         my $tmpshlink = array2oneperline($ctx->{LINK_LIST});
374         my $tmpshflag = array2oneperline($ctx->{LINK_FLAGS});
375
376         $output = << "__EOD__";
377 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
378 #
379 LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST =$tmpshlink
380 LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS =$tmpshflag
381 #
382
383 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) \$(LIBRARY_$ctx->{NAME}_OBJS) bin/.dummy
384         \@echo Linking \$\@
385         \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \\
386                 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS) \\
387                 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST)
388
389 __EOD__
390
391         if (defined($ctx->{LIBRARY_SONAME})) {
392             $output .= << "__EOD__";
393 # Symlink $ctx->{LIBRARY_SONAME}
394 bin/$ctx->{LIBRARY_SONAME}: bin/$ctx->{LIBRARY_REALNAME} bin/.dummy
395         \@echo Symlink \$\@
396         \@ln -sf $ctx->{LIBRARY_REALNAME} \$\@
397 # Symlink $ctx->{LIBRARY_NAME}
398 bin/$ctx->{LIBRARY_NAME}: bin/$ctx->{LIBRARY_SONAME} bin/.dummy
399         \@echo Symlink \$\@
400         \@ln -sf $ctx->{LIBRARY_SONAME} \$\@
401
402 __EOD__
403         }
404
405 $output .= << "__EOD__";
406 library_$ctx->{NAME}: basics bin/lib$ctx->{LIBRARY_NAME}
407
408 __EOD__
409
410         return $output;
411 }
412
413 sub _prepare_mergedobj_rule($)
414 {
415         my $ctx = shift;
416
417         return "" unless $ctx->{TARGET};
418
419         my $output = "";
420
421         my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
422
423         $output .= "$ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST = $tmpdepend\n";
424
425         $output .= "$ctx->{TARGET}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJS)\n";
426
427         $output .= "\t\@echo \"Pre-Linking $ctx->{TYPE} $ctx->{NAME}\"\n";
428         $output .= "\t@\$(LD) -r \$($ctx->{TYPE}_$ctx->{NAME}_OBJS) -o $ctx->{TARGET}\n";
429         $output .= "\n";
430
431         return $output;
432 }
433
434 sub _prepare_objlist_rule($)
435 {
436         my $ctx = shift;
437         my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
438
439         return "" unless $ctx->{TARGET};
440
441         my $output = "$ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST = $tmpdepend\n";
442         $output .= "$ctx->{TARGET}: ";
443         $output .= "\$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJS)\n";
444         $output .= "\t\@touch $ctx->{TARGET}\n";
445
446         return $output;
447 }
448
449 ###########################################################
450 # This function creates a make rule for linking a library
451 #
452 # $output = _prepare_static_library_rule($library_ctx)
453 #
454 # $library_ctx -                the library context
455 #
456 # $library_ctx->{NAME} -                the library name
457 #
458 # $library_ctx->{DEPEND_LIST} -         the list of rules on which this library depends
459 #
460 # $library_ctx->{LIBRARY_NAME} -        the static library name
461 # $library_ctx->{LINK_LIST} -   the list of objectfiles which sould be linked
462 #                                       to this static library
463 # $library_ctx->{LINK_FLAGS} -  linker flags used by this static library
464 #
465 # $output -             the resulting output buffer
466 sub _prepare_static_library_rule($)
467 {
468         my $ctx = shift;
469         my $output;
470
471         my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
472         my $tmpstlink = array2oneperline($ctx->{LINK_LIST});
473         my $tmpstflag = array2oneperline($ctx->{LINK_FLAGS});
474
475         $output = << "__EOD__";
476 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
477 #
478 LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
479 #
480 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) \$(LIBRARY_$ctx->{NAME}_OBJS) bin/.dummy
481         \@echo Linking \$@
482         \@\$(STLD) \$(STLD_FLAGS) \$@ \\
483                 \$(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)
484
485 library_$ctx->{NAME}: basics $ctx->{TARGET}
486
487 __EOD__
488
489         return $output;
490 }
491
492 ###########################################################
493 # This function creates a make rule for linking a binary
494 #
495 # $output = _prepare_binary_rule($binary_ctx)
496 #
497 # $binary_ctx -         the binary context
498 #
499 # $binary_ctx->{NAME} -         the binary name
500 # $binary_ctx->{BINARY} -       the binary binary name
501 #
502 # $binary_ctx->{DEPEND_LIST} -  the list of rules on which this binary depends
503 # $binary_ctx->{LINK_LIST} -    the list of objectfiles and external libraries
504 #                               which sould be linked to this binary
505 # $binary_ctx->{LINK_FLAGS} -   linker flags used by this binary
506 #
507 # $output -             the resulting output buffer
508 sub _prepare_binary_rule($)
509 {
510         my $ctx = shift;
511
512         my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
513         my $tmplink = array2oneperline($ctx->{LINK_LIST});
514         my $tmpflag = array2oneperline($ctx->{LINK_FLAGS});
515
516         my $output = << "__EOD__";
517 #
518 BINARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
519 BINARY_$ctx->{NAME}_LINK_LIST =$tmplink
520 BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
521 #
522 bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST) \$(BINARY_$ctx->{NAME}_OBJS)
523         \@echo Linking \$\@
524         \@\$(CC) \$(LD_FLAGS) -o \$\@ \\
525                 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS) \\
526                 \$\(BINARY_$ctx->{NAME}_LINK_LIST) \\
527                 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS)
528 binary_$ctx->{BINARY}: basics bin/$ctx->{BINARY}
529
530 __EOD__
531
532         return $output;
533 }
534
535 sub _prepare_custom_rule($)
536 {
537         my $ctx = shift;
538         return "
539 $ctx->{NAME}: bin/.TARGET_$ctx->{NAME}
540
541 bin/.TARGET_$ctx->{NAME}:
542         $ctx->{CMD}
543         touch bin/.TARGET_$ctx->{NAME}
544 ";
545 }
546
547 sub _prepare_proto_rules()
548 {
549         my $output = << '__EOD__';
550 # Making this target will just make sure that the prototype files
551 # exist, not necessarily that they are up to date.  Since they're
552 # removed by 'make clean' this will always be run when you do anything
553 # afterwards.
554 proto_exists: include/proto.h
555
556 delheaders: pch_clean
557         -rm -f $(builddir)/include/proto.h
558
559 include/proto.h:
560         @cd $(srcdir) && $(SHELL) script/mkproto.sh "$(PERL)" \
561           -h _PROTO_H_ $(builddir)/include/proto.h \
562           $(PROTO_PROTO_OBJS)
563
564 # 'make headers' or 'make proto' calls a subshell because we need to
565 # make sure these commands are executed in sequence even for a
566 # parallel make.
567 headers: delheaders proto_exists
568
569 proto: idl headers
570
571 proto_test:
572         @[ -f $(builddir)/include/proto.h ] || $(MAKE) proto
573
574 clean: delheaders
575         @echo Removing objects
576         @-find . -name '*.o' -exec rm -f '{}' \;
577         @echo Removing binaries
578         @-rm -f bin/*
579         @echo Removing dummy targets
580         @-rm -f bin/.*_*
581         @echo Removing generated files
582         @-rm -rf librpc/gen_*
583         @echo Removing generated ASN1 files
584         @-find heimdal/lib/asn1 -name 'asn1_*.[xc]' -exec rm -f '{}' \;
585         @-find heimdal/lib/gssapi -name 'asn1_*.[xc]' -exec rm -f '{}' \;
586         @-find heimdal/lib/hdb -name 'asn1_*.[xc]' -exec rm -f '{}' \;
587
588 distclean: clean
589         -rm -f bin/.dummy
590         -rm -f include/config.h include/smb_build.h
591         -rm -f Makefile*
592         -rm -f config.status
593         -rm -f config.log config.cache
594         -rm -f samba4-deps.dot
595         -rm -f config.pm config.mk
596         -rm -f lib/registry/winregistry.pc
597 __EOD__
598
599         if ($config{developer} eq "yes") {
600                 $output .= "\t@-rm -f \$(_ALL_OBJS_OBJS:.o=.d)\n";
601         }
602
603         $output .= << '__EOD__';
604
605 removebackup:
606         -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
607
608 realdistclean: distclean removebackup
609         -rm -f include/config.h.in
610         -rm -f include/version.h
611         -rm -f configure
612         -rm -f $(MANPAGES)
613 __EOD__
614
615         return $output;
616 }
617
618 sub _prepare_make_target($)
619 {
620         my $ctx = shift;
621         my $tmpdepend;
622
623         $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
624
625         return << "__EOD__";
626 $ctx->{TARGET}: basics $tmpdepend
627
628 __EOD__
629 }
630
631 sub _prepare_target_settings($)
632 {
633         my $CTX = shift;
634         my $output = "";
635
636         foreach my $key (values %$CTX) {
637                 if (defined($key->{OBJ_LIST})) {
638                         $output .= _prepare_obj_list($key->{TYPE}, $key);
639                         $output .= _prepare_cflags($key->{TYPE}, $key);
640                 }
641         }
642
643         return $output;
644 }
645
646 sub _prepare_install_rules()
647 {
648         return << '__EOD__';
649
650 showlayout: 
651         @echo "Samba will be installed into:"
652         @echo "  basedir: $(BASEDIR)"
653         @echo "  bindir:  $(BINDIR)"
654         @echo "  sbindir: $(SBINDIR)"
655         @echo "  libdir:  $(LIBDIR)"
656         @echo "  vardir:  $(VARDIR)"
657         @echo "  privatedir:  $(PRIVATEDIR)"
658         @echo "  piddir:   $(PIDDIR)"
659         @echo "  lockdir:  $(LOCKDIR)"
660         @echo "  swatdir:  $(SWATDIR)"
661         @echo "  mandir:   $(MANDIR)"
662
663 showflags:
664         @echo "Samba will be compiled with flags:"
665         @echo "  CFLAGS = $(CFLAGS)"
666         @echo "  LD_FLAGS = $(LD_FLAGS)"
667         @echo "  STLD_FLAGS = $(STLD_FLAGS)"
668         @echo "  SHLD_FLAGS = $(SHLD_FLAGS)"
669
670 install: showlayout installbin installdat installswat
671
672 # DESTDIR is used here to prevent packagers wasting their time
673 # duplicating the Makefile. Remove it and you will have the privilege
674 # of packaging each samba release for multiple versions of multiple
675 # distributions and operating systems, or at least supplying patches
676 # to all the packaging files required for this, prior to committing
677 # the removal of DESTDIR. Do not remove it even though you think it
678 # is not used.
679
680 installdirs:
681         @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(PRIVATEDIR) $(DESTDIR)$(PIDDIR) $(DESTDIR)$(LOCKDIR) $(DESTDIR)$(PRIVATEDIR)/tls
682
683 installbin: all installdirs
684         @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(SBIN_PROGS)
685         @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(BIN_PROGS)
686
687 installdat: installdirs
688         @$(SHELL) $(srcdir)/script/installdat.sh $(DESTDIR)$(LIBDIR) $(srcdir)
689
690 installswat: installdirs
691         @$(SHELL) $(srcdir)/script/installswat.sh $(DESTDIR)$(SWATDIR) $(srcdir) $(DESTDIR)$(LIBDIR)
692
693 installman: installdirs
694         @$(SHELL) $(srcdir)/script/installman.sh $(DESTDIR)$(MANDIR) $(MANPAGES)
695
696 uninstall: uninstallbin uninstallman
697
698 uninstallbin:
699         @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(SBIN_PROGS)
700         @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(BIN_PROGS)
701
702 uninstallman:
703         @$(SHELL) $(srcdir)/script/uninstallman.sh $(DESTDIR)$(MANDIR) $(MANPAGES)
704
705 # Swig extensions
706 swig: scripting/swig/_tdb.so scripting/swig/_dcerpc.so
707
708 scripting/swig/tdb_wrap.c: scripting/swig/tdb.i
709         swig -python scripting/swig/tdb.i
710
711 scripting/swig/_tdb.so: scripting/swig/tdb_wrap.o $(LIBRARY_swig_tdb_DEPEND_LIST)
712         $(SHLD) $(SHLD_FLAGS) -o scripting/swig/_tdb.so scripting/swig/tdb_wrap.o \
713                 $(LIBRARY_swig_tdb_SHARED_LINK_LIST) $(LIBRARY_swig_tdb_SHARED_LINK_FLAGS)
714
715 SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i
716
717 scripting/swig/dcerpc_wrap.c: scripting/swig/dcerpc.i scripting/swig/samba.i scripting/swig/status_codes.i $(SWIG_INCLUDES)
718         swig -python scripting/swig/dcerpc.i
719
720 scripting/swig/_dcerpc.so: scripting/swig/dcerpc_wrap.o $(LIBRARY_swig_dcerpc_DEPEND_LIST)
721         $(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)
722
723 swig_clean:
724         -rm -f scripting/swig/_tdb.so scripting/swig/tdb.pyc \
725                 scripting/swig/tdb.py scripting/swig/tdb_wrap.c \
726                 scripting/swig/tdb_wrap.o
727
728 everything: all
729
730 etags:
731         etags `find $(srcdir) -name "*.[ch]"`
732
733 ctags:
734         ctags `find $(srcdir) -name "*.[ch]"`
735
736 __EOD__
737 }
738
739 sub _prepare_rule_lists($)
740 {
741         my $depend = shift;
742         my $output = "";
743
744         foreach my $key (values %{$depend}) {
745                 next unless defined $key->{OUTPUT_TYPE};
746
747                 ($output .= _prepare_mergedobj_rule($key)) if $key->{OUTPUT_TYPE} eq "MERGEDOBJ";
748                 ($output .= _prepare_objlist_rule($key)) if $key->{OUTPUT_TYPE} eq "OBJLIST";
749                 ($output .= _prepare_static_library_rule($key)) if $key->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
750                 ($output .= _prepare_shared_library_rule($key)) if $key->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
751                 ($output .= _prepare_binary_rule($key)) if $key->{OUTPUT_TYPE} eq "BINARY";
752                 ($output .= _prepare_custom_rule($key) ) if $key->{TYPE} eq "TARGET";
753         }
754
755         $output .= _prepare_IDL();
756         $output .= _prepare_proto_rules();
757         $output .= _prepare_install_rules();
758
759         return $output;
760 }
761
762 ###########################################################
763 # This function prepares the output for Makefile
764 #
765 # $output = _prepare_makefile_in($OUTPUT)
766 #
767 # $OUTPUT -     the global OUTPUT context
768 #
769 # $output -             the resulting output buffer
770 sub _prepare_makefile_in($)
771 {
772         my ($CTX) = @_;
773         my $output;
774
775         $output  = "########################################\n";
776         $output .= "# Autogenerated by config.smb_build.pl #\n";
777         $output .= "########################################\n";
778         $output .= "\n";
779
780         $output .= _prepare_path_vars();
781         $output .= _prepare_compiler_linker();
782         $output .= _prepare_default_rule();
783         $output .= _prepare_SUFFIXES();
784         $output .= _prepare_dummy_MAKEDIR();
785         $output .= _prepare_std_CC_rule("c","o",$config{PICFLAG},"Compiling","Rule for std objectfiles");
786         $output .= _prepare_std_CC_rule("h","h.gch",$config{PICFLAG},"Precompiling","Rule for precompiled headerfiles");
787         $output .= _prepare_lex_rule();
788         $output .= _prepare_yacc_rule();
789         $output .= _prepare_et_rule();
790
791         $output .= _prepare_depend_CC_rule();
792         
793         $output .= _prepare_man_rule("1");
794         $output .= _prepare_man_rule("3");
795         $output .= _prepare_man_rule("5");
796         $output .= _prepare_man_rule("7");
797         $output .= _prepare_manpages($CTX);
798         $output .= _prepare_binaries($CTX);
799         $output .= _prepare_target_settings($CTX);
800         $output .= _prepare_rule_lists($CTX);
801
802         my @all = ();
803         
804         foreach my $part (values %{$CTX}) {
805                 push (@all, $part->{TARGET}) if defined ($part->{OUTPUT_TYPE}) and $part->{OUTPUT_TYPE} eq "BINARY";    
806         }
807         
808         $output .= _prepare_make_target({ TARGET => "all", DEPEND_LIST => \@all });
809
810         if ($config{developer} eq "yes") {
811                 $output .= <<__EOD__
812 #-include \$(_ALL_OBJS_OBJS:.o=.d)
813 IDL_FILES = \$(wildcard librpc/idl/*.idl)
814 \$(patsubst librpc/idl/%.idl,librpc/gen_ndr/ndr_%.c,\$(IDL_FILES)) \\
815 \$(patsubst librpc/idl/%.idl,librpc/gen_ndr/ndr_\%_c.c,\$(IDL_FILES)) \\
816 \$(patsubst librpc/idl/%.idl,librpc/gen_ndr/ndr_%.h,\$(IDL_FILES)): idl
817 __EOD__
818         }
819
820         return $output;
821 }
822
823 ###########################################################
824 # This function creates Makefile.in from the OUTPUT 
825 # context
826 #
827 # create_makefile_in($OUTPUT)
828 #
829 # $OUTPUT       -       the global OUTPUT context
830 #
831 # $output -             the resulting output buffer
832 sub create_makefile_in($$$)
833 {
834         my ($CTX, $mk, $file) = @_;
835
836         open(MAKEFILE_IN,">$file") || die ("Can't open $file\n");
837         print MAKEFILE_IN _prepare_makefile_in($CTX) . $mk;
838         close(MAKEFILE_IN);
839
840         print "config.smb_build.pl: creating $file\n";
841         return; 
842 }
843
844 1;