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