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