r12254: Add some (hopefully correct) descriptions for libraries that are installed.
[ira/wip.git] / source / build / smb_build / makefile.pm
index 74ca539a098c061c7d7b052a0fbf03a9d8543842..6982e28977193b1be3bea11c8c034fc44fe73179 100644 (file)
-###########################################################
-### 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 = << '__EOD__';
-SHELL=/bin/sh
-PERL=@PERL@
-
-__EOD__
-
-       return $output;
-}
-
-sub _prepare_path_vars($)
-{
-       my $ctx = shift;
-       my $output;
-
-       $output = << '__EOD__';
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-VPATH=@srcdir@
-srcdir=@srcdir@
-builddir=@builddir@
-
-BASEDIR= @prefix@
-BINDIR = @bindir@
-SBINDIR = @sbindir@
-LIBDIR = @libdir@
-CONFIGDIR = @configdir@
-VARDIR = @localstatedir@
-SWATDIR = @swatdir@
-
-# 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_FLAGS7 = $(PATH_FLAGS6) -DSWATDIR=\"$(SWATDIR)\"
-PATH_FLAGS = $(PATH_FLAGS7) $(PASSWD_FLAGS)
+# Samba Build System
+# - create output for Makefile
+#
+#  Copyright (C) Stefan (metze) Metzmacher 2004
+#  Copyright (C) Jelmer Vernooij 2005
+#  Released under the GNU GPL
 
-__EOD__
+package smb_build::makefile;
+use smb_build::env;
+use strict;
 
-       return $output;
-}
+use base 'smb_build::env';
 
-sub _prepare_compiler_linker($)
+sub new($$$)
 {
-       my $ctx = shift;
-       my $output;
+       my ($myname, $config, $mkfile) = @_;
+       my $self = new smb_build::env($config);
+       
+       bless($self, $myname);
 
-       $output = << '__EOD__';
-CC=@CC@
-CC_FLAGS=-Iinclude -I. -I$(srcdir)/include -I$(srcdir) -D_SAMBA_BUILD_ -DHAVE_CONFIG_H -Ilib @CFLAGS@ @CPPFLAGS@
+       $self->{manpages} = [];
+       $self->{sbin_progs} = [];
+       $self->{bin_progs} = [];
+       $self->{static_libs} = [];
+       $self->{shared_libs} = [];
+       $self->{headers} = [];
+       $self->{pc_files} = [];
+       $self->{output} = "";
 
-LD=@CC@
-LD_FLAGS=@LDFLAGS@ @CFLAGS@ -Lbin
+       $self->{mkfile} = $mkfile;
 
-STLD=ar
-STLD_FLAGS=-rc
+       $self->output("################################################\n");
+       $self->output("# Autogenerated by build/smb_build/makefile.pm #\n");
+       $self->output("################################################\n");
+       $self->output("\n");
 
-SHLD=@CC@
-SHLD_FLAGS=@LDSHFLAGS@ @LDFLAGS@ -Lbin
+       $self->output("default: all\n\n");
 
-__EOD__
+       $self->_prepare_path_vars();
+       $self->_prepare_compiler_linker();
+       $self->_prepare_hostcc_rule();
+       $self->_prepare_std_CC_rule("c","o",'$(PICFLAG)',"Compiling","Rule for std objectfiles");
+       $self->_prepare_std_CC_rule("h","h.gch",'$(PICFLAG)',"Precompiling","Rule for precompiled headerfiles");
 
-       return $output;
+       return $self;
 }
 
-
-#############################
-# return makefile fragment for 
-# target specific rules
-sub add_target_flags($$)
+sub output($$)
 {
-       my $ctx = shift;
-       my $name = shift;
-       my $output = "";
-       if ($ctx->{TARGET_CFLAGS}) {
-$output .= << "__EOD__";
-$name: TARGET_CFLAGS = $ctx->{TARGET_CFLAGS}
-__EOD__
-}
-        return $output;
-}
+       my ($self, $text) = @_;
 
+       $self->{output} .= $text;
+}
 
-sub _prepare_default_rule($)
+sub _prepare_path_vars($)
 {
-       my $ctx = shift;
-       my $output;
-
-       $output = << '__EOD__';
-default: all
+       my ($self) = @_;
+
+       $self->output(<< "__EOD__"
+prefix = $self->{config}->{prefix}
+exec_prefix = $self->{config}->{exec_prefix}
+selftest_prefix = $self->{config}->{selftest_prefix}
+VPATH = $self->{config}->{srcdir}
+srcdir = $self->{config}->{srcdir}
+builddir = $self->{config}->{builddir}
+
+BASEDIR = $self->{config}->{prefix}
+BINDIR = $self->{config}->{bindir}
+SBINDIR = $self->{config}->{sbindir}
+datadir = $self->{config}->{datadir}
+LIBDIR = $self->{config}->{libdir}
+INCLUDEDIR = $self->{config}->{includedir}
+CONFIGDIR = $self->{config}->{configdir}
+localstatedir = $self->{config}->{localstatedir}
+SWATDIR = $self->{config}->{swatdir}
+VARDIR = $self->{config}->{localstatedir}
+LOGFILEBASE = $self->{config}->{logfilebase}
+NCALRPCDIR = $self->{config}->{localstatedir}/ncalrpc
+LOCKDIR = $self->{config}->{lockdir}
+PIDDIR = $self->{config}->{piddir}
+MANDIR = $self->{config}->{mandir}
+PRIVATEDIR = $self->{config}->{privatedir}
 
 __EOD__
-
-       return $output;
+);
 }
 
-sub _prepare_SUFFIXES($)
+sub _prepare_compiler_linker($)
 {
-       my $ctx = shift;
-       my $output;
+       my ($self) = @_;
 
-       $output = << '__EOD__';
-.SUFFIXES:
-.SUFFIXES: .c .o .h .h.gch .a .so
+       my $devld_local = "";
+       my $devld_install = "";
 
-__EOD__
+       $self->{duplicate_build} = 0;
+       if ($self->{config}->{LIBRARY_OUTPUT_TYPE} eq "SHARED_LIBRARY") {
+               if ($self->{developer}) {
+                       $self->{duplicate_build} = 1;
+                       $devld_local = " -Wl,-rpath,\$(builddir)/bin";
+               }
+               $devld_install = " -Wl,-rpath-link,\$(builddir)/bin";
+       }
 
-       return $output;
-}
+       $self->output(<< "__EOD__"
+SHELL=$self->{config}->{SHELL}
 
-sub _prepare_IDL($)
-{
-       my $ctx = shift;
-       my $output;
+PERL=$self->{config}->{PERL}
 
-       $output = << '__EOD__';
-idl_full: build/pidl/idl.pm
-       CPP="@CPP@" PERL="$(PERL)" script/build_idl.sh FULL
+CPP=$self->{config}->{CPP}
+CPPFLAGS=$self->{config}->{CPPFLAGS}
 
-idl: build/pidl/idl.pm
-       @CPP="@CPP@" PERL="$(PERL)" script/build_idl.sh PARTIAL
+CC=$self->{config}->{CC}
+CFLAGS=-I\$(srcdir)/include -I\$(srcdir) -I\$(srcdir)/lib -D_SAMBA_BUILD_ -DHAVE_CONFIG_H $self->{config}->{CFLAGS} \$(CPPFLAGS)
+PICFLAG=$self->{config}->{PICFLAG}
+HOSTCC=$self->{config}->{HOSTCC}
 
-build/pidl/idl.pm: build/pidl/idl.yp
-       -yapp -s build/pidl/idl.yp
+LD=$self->{config}->{LD} 
+LDFLAGS=$self->{config}->{LDFLAGS} -L\$(builddir)/bin
+LOCAL_LINK_FLAGS=$devld_local
+INSTALL_LINK_FLAGS=$devld_install
 
-pch: proto include/includes.h.gch
+STLD=$self->{config}->{AR}
+STLD_FLAGS=-rc -L\$(builddir)/bin
 
-pch_clean:
-       -rm -f include/includes.h.gch
+SHLD=$self->{config}->{CC}
+SHLD_FLAGS=$self->{config}->{LDSHFLAGS} -L\$(builddir)/bin
+SONAMEFLAG=$self->{config}->{SONAMEFLAG}
+SHLIBEXT=$self->{config}->{SHLIBEXT}
 
-basics: idl proto_exists
+XSLTPROC=$self->{config}->{XSLTPROC}
 
-test: @DEFAULT_TEST_TARGET@
+LEX=$self->{config}->{LEX}
+YACC=$self->{config}->{YACC}
+YAPP=$self->{config}->{YAPP}
+PIDL_ARGS=$self->{config}->{PIDL_ARGS}
 
-test-swrap: all
-       SOCKET_WRAPPER_DIR=. ./script/tests/selftest.sh `pwd`/prefix-test
+GCOV=$self->{config}->{GCOV}
 
-test-noswrap: all
-       ./script/tests/selftest.sh `pwd`/prefix-test
+DEFAULT_TEST_TARGET=$self->{config}->{DEFAULT_TEST_TARGET}
 
 __EOD__
-
-       return $output;
+);
 }
 
-sub _prepare_dummy_MAKEDIR()
+sub _prepare_mk_files($)
 {
-       my $ctx = shift;
-       my $output;
+       my $self = shift;
+       my @tmp = ();
 
-       $output =  << '__EOD__';
-bin/.dummy:
-       @: >> $@ || : > $@
+       
+       foreach (@smb_build::config_mk::parsed_files) {
+               s/ .*$//g;
+               push (@tmp, $_);
+       }
+
+       $self->output("MK_FILES = " . array2oneperline(\@tmp) . "\n");
+}
 
+sub _prepare_dummy_MAKEDIR($)
+{
+       my ($self) = @_;
+
+       $self->output(<< '__EOD__'
 dynconfig.o: dynconfig.c Makefile
        @echo Compiling $*.c
-       @$(CC) $(CC_FLAGS) @PICFLAG@ $(PATH_FLAGS) -c $< -o $@
-@BROKEN_CC@    -mv `echo $@ | sed 's%^.*/%%g'` $@
-
+       @$(CC) $(CFLAGS) $(PICFLAG) $(PATH_FLAGS) -c $< -o $@
 __EOD__
-
-       return $output;
+);
+       if ($self->{config}->{BROKEN_CC} eq "yes") {
+               $self->output(' -mv `echo $@ | sed \'s%^.*/%%g\'` $@
+');
+       }
+       $self->output("\n");
 }
 
-###########################################################
-# 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($$$$$)
+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 = << "__EOD__";
-###################################
-# Start $comment
+       my ($self,$src,$dst,$flags,$message,$comment) = @_;
+
+       $self->output(<< "__EOD__"
+# $comment
 .$src.$dst:
        \@echo $message \$\*.$src
-       \@\$(CC) \$(TARGET_CFLAGS) \$(CC_FLAGS) $flags -c \$< -o \$\@
-\@BROKEN_CC\@  -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
-#End $comment
-###################################
-
+       \@\$(CC) `script/cflags.sh \$\@` \$(CFLAGS) $flags -c \$< -o \$\@
 __EOD__
+);
+       if ($self->{config}->{BROKEN_CC} eq "yes") {
+               $self->output(' -mv `echo $@ | sed \'s%^.*/%%g\'` $@
+');
+       }
 
-       return $output;
+       $self->output("\n");
 }
 
-sub array2oneperline($)
+sub _prepare_hostcc_rule($)
 {
-       my $array = shift;
-       my $i;
-       my $output = "";
-
-       foreach my $str (@{$array}) {
-               if (!defined($str)) {
-                       next;
-               }
-
-               $output .= " \\\n\t\t";
-               $output .= $str;
+       my ($self) = @_;
+       
+       $self->output(<< "__EOD__"
+.c.ho:
+       \@echo Compiling \$\*.c with host compiler
+       \@\$(HOSTCC) `script/cflags.sh \$\@` \$(CFLAGS) -c \$< -o \$\@
+__EOD__
+);
+       if ($self->{config}->{BROKEN_CC} eq "yes") {
+               $self->output(' -mv `echo $@ | sed \'s%^.*/%%g\' -e \'s%\.ho$$%.o%\'` $@
+');
        }
 
-       return $output;
+       $self->output("\n");
 }
 
-sub array2oneline($)
+sub array2oneperline($)
 {
        my $array = shift;
-       my $i;
        my $output = "";
 
-       foreach my $str (@{$array}) {
-               if (!defined($str)) {
-                       next;
-               }
+       foreach (@$array) {
+               next unless defined($_);
 
-               $output .= $str;
-               $output .= " ";
+               $output .= " \\\n\t\t$_";
        }
 
        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($$)
+sub _prepare_list($$$)
 {
-       my $var = shift;
-       my $ctx = shift;
-       my $tmpobjlist;
-       my $output;
-
-       $tmpobjlist = array2oneperline($ctx->{OBJ_LIST});
-
-       $output = << "__EOD__";
-###################################
-# Start $var $ctx->{NAME} OBJ LIST
-$var\_$ctx->{NAME}_OBJS =$tmpobjlist
-# End $var $ctx->{NAME} OBJ LIST
-###################################
+       my ($self,$ctx,$var) = @_;
 
-__EOD__
+       my $tmplist = array2oneperline($ctx->{$var});
+       return if ($tmplist eq "");
 
-       return $output;
+       $self->output("$ctx->{TYPE}\_$ctx->{NAME}_$var =$tmplist\n");
 }
 
-###########################################################
-# 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($)
+sub SharedLibrary($$)
 {
-       my $ctx = shift;
+       my ($self,$ctx) = @_;
 
-       return _prepare_var_obj_list("SUBSYSTEM",$ctx);
-}
+       push (@{$self->{shared_libs}}, "bin/$ctx->{LIBRARY_REALNAME}");
 
-###########################################################
-# 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);
+       $self->_prepare_list($ctx, "OBJ_LIST");
+       $self->_prepare_list($ctx, "CFLAGS");
+       $self->_prepare_list($ctx, "DEPEND_LIST");
+       $self->_prepare_list($ctx, "LINK_LIST");
+       $self->_prepare_list($ctx, "LINK_FLAGS");
 
-}
-
-###########################################################
-# 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;
-
-       $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
-
-       $tmpshlink = array2oneperline($ctx->{LINK_LIST});
-       $tmpshflag = array2oneperline($ctx->{LINK_FLAGS});
-
-       $output = << "__EOD__";
-###################################
-# Start Library $ctx->{NAME}
-#
-LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
-#
-LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST =$tmpshlink
-LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS =$tmpshflag
+       $self->output(<< "__EOD__"
 #
 
-# Shared $ctx->{LIBRARY_NAME}
-$ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
+bin/$ctx->{LIBRARY_REALNAME}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST) bin/.dummy
        \@echo Linking \$\@
        \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \\
-               \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS) \\
-               \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST)
+               \$($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS) \\
+               \$($ctx->{TYPE}_$ctx->{NAME}_LINK_LIST)
 
 __EOD__
-
+);
        if (defined($ctx->{LIBRARY_SONAME})) {
-           $output .= << "__EOD__";
+           $self->output(<< "__EOD__"
 # Symlink $ctx->{LIBRARY_SONAME}
 bin/$ctx->{LIBRARY_SONAME}: bin/$ctx->{LIBRARY_REALNAME} bin/.dummy
        \@echo Symlink \$\@
@@ -414,453 +269,207 @@ bin/$ctx->{LIBRARY_NAME}: bin/$ctx->{LIBRARY_SONAME} bin/.dummy
        \@ln -sf $ctx->{LIBRARY_SONAME} \$\@
 
 __EOD__
+);
        }
-
-$output .= << "__EOD__";
-library_$ctx->{NAME}: basics bin/lib$ctx->{LIBRARY_NAME}
-
-# End Library $ctx->{NAME}
-###################################
-
-__EOD__
-
-$output .= add_target_flags($ctx, "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($)
+sub MergedObj($$)
 {
-       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});
-
-       $output = << "__EOD__";
-###################################
-# Start Library $ctx->{NAME}
-#
-LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
-#
-LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
-#
-# Static $ctx->{LIBRARY_NAME}
-$ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
-       \@echo Linking \$@
-       \@\$(STLD) \$(STLD_FLAGS) \$@ \\
-               \$(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)
+       my ($self,$ctx) = @_;
 
-library_$ctx->{NAME}: basics $ctx->{TARGET}
-# End Library $ctx->{NAME}
-###################################
+       return unless $ctx->{TARGET};
 
-__EOD__
+       $self->_prepare_list($ctx, "OBJ_LIST");
+       $self->_prepare_list($ctx, "CFLAGS");
+       $self->_prepare_list($ctx, "DEPEND_LIST");
 
-$output .= add_target_flags($ctx, "library_" . $ctx->{NAME});
+       $self->output("$ctx->{TARGET}: \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)\n");
 
-       return $output;
+       $self->output("\t\@echo \"Pre-Linking $ctx->{TYPE} $ctx->{NAME}\"\n");
+       $self->output("\t@\$(LD) -r \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST) -o $ctx->{TARGET}\n");
+       $self->output("\n");
 }
 
-
-
-###########################################################
-# 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($)
+sub ObjList($$)
 {
-       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 = << "__EOD__";
-###################################
-# 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}
-###################################
+       my ($self,$ctx) = @_;
 
-__EOD__
+       return unless $ctx->{TARGET};
 
-$output .= add_target_flags($ctx, "binary_" . $ctx->{BINARY});
-
-       return $output;
+       $self->_prepare_list($ctx, "OBJ_LIST");
+       $self->_prepare_list($ctx, "CFLAGS");
+       $self->_prepare_list($ctx, "DEPEND_LIST");
+       $self->output("$ctx->{TARGET}: ");
+       $self->output("\$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)\n");
+       $self->output("\t\@touch $ctx->{TARGET}\n");
 }
 
-sub _prepare_proto_rules()
+sub StaticLibrary($$)
 {
-       my $output = "";
+       my ($self,$ctx) = @_;
 
-       $output .= << '__EOD__';
-# 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
-__EOD__
+       push (@{$self->{static_libs}}, $ctx->{OUTPUT});
 
-       return $output;
-}
+       $self->_prepare_list($ctx, "OBJ_LIST");
+       $self->_prepare_list($ctx, "CFLAGS");
 
-sub _prepare_make_target($)
-{
-       my $ctx = shift;
-       my $tmpdepend;
-       my $output;
+       $self->_prepare_list($ctx, "DEPEND_LIST");
+       $self->_prepare_list($ctx, "LINK_LIST");
+       $self->_prepare_list($ctx, "LINK_FLAGS");
 
-       $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
-
-       $output = << "__EOD__";
-###################################
-# Start Target $ctx->{TARGET}
-$ctx->{TARGET}: basics $tmpdepend
-# End Target $ctx->{TARGET}
-###################################
+       $self->output(<< "__EOD__"
+#
+$ctx->{TARGET}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST) bin/.dummy
+       \@echo Linking \$@
+       \@\$(STLD) \$(STLD_FLAGS) \$@ \\
+               \$($ctx->{TYPE}_$ctx->{NAME}_LINK_LIST)
 
 __EOD__
-
-       return $output;
+);
 }
 
-sub _prepare_obj_lists($)
+sub Header($$)
 {
-       my $CTX = shift;
-       my $output = "";
+       my ($self,$ctx) = @_;
 
-       foreach my $key (values %$CTX) {
-               next if not defined($key->{OBJ_LIST});
-               $output .= _prepare_obj_list($key->{TYPE}, $key);
+       foreach (@{$ctx->{PUBLIC_HEADERS}}) {
+               push (@{$self->{headers}}, "$ctx->{BASEDIR}/$_");
        }
-
-       return $output;
 }
 
-sub _prepare_install_rules($)
+sub Binary($$)
 {
-       my $CTX = shift;
-       my $output = "";
-
-       $output .= << '__EOD__';
-
-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)"
-       @echo "  swatdir:  $(SWATDIR)"
-
-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 installswat
+       my ($self,$ctx) = @_;
 
-# 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) $(DESTDIR)$(PRIVATEDIR)/tls
-
-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)
-
-installswat: installdirs
-       @$(SHELL) $(srcdir)/script/installswat.sh $(DESTDIR)$(SWATDIR) $(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
+       my $installdir;
+       
+       if ($self->{duplicate_build}) {
+               $installdir = "bin/install";
+       } else {
+               $installdir = "bin";
+       }
 
-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
+       unless (defined($ctx->{INSTALLDIR})) {
+       } elsif ($ctx->{INSTALLDIR} eq "SBINDIR") {
+               push (@{$self->{sbin_progs}}, "$installdir/$ctx->{BINARY}");
+       } elsif ($ctx->{INSTALLDIR} eq "BINDIR") {
+               push (@{$self->{bin_progs}}, "$installdir/$ctx->{BINARY}");
+       }
 
-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)
+       push (@{$self->{binaries}}, "bin/$ctx->{BINARY}");
 
-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
+       $self->_prepare_list($ctx, "OBJ_LIST");
+       $self->_prepare_list($ctx, "CFLAGS");
+       $self->_prepare_list($ctx, "DEPEND_LIST");
+       $self->_prepare_list($ctx, "LINK_LIST");
+       $self->_prepare_list($ctx, "LINK_FLAGS");
 
-everything: all
+       if ($self->{duplicate_build}) {
+       $self->output(<< "__EOD__"
+#
+bin/$ctx->{BINARY}: bin/.dummy \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)
+       \@echo Linking \$\@
+       \@\$(CC) \$(LDFLAGS) -o \$\@ \$(LOCAL_LINK_FLAGS) \\
+               \$\($ctx->{TYPE}_$ctx->{NAME}_LINK_LIST) \\
+               \$\($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS)
 
-etags:
-       etags `find $(srcdir) -name "*.[ch]"`
+__EOD__
+);
+       }
 
-ctags:
-       ctags `find $(srcdir) -name "*.[ch]"`
+$self->output(<< "__EOD__"
+$installdir/$ctx->{BINARY}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)
+       \@echo Linking \$\@
+       \@\$(CC) \$(LDFLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
+               \$\($ctx->{TYPE}_$ctx->{NAME}_LINK_LIST) \\
+               \$\($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS) 
 
 __EOD__
-
-       return $output;
+);
 }
 
-sub _prepare_rule_lists($)
+sub Manpage($$)
 {
-       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);
+       my ($self,$ctx) = @_;
 
-       $output .= _prepare_proto_rules();
+       my $dir = $ctx->{BASEDIR};
 
-       $output .= _prepare_install_rules($depend);
+       $dir =~ s/^\.\///g;
 
-       return $output;
+       push (@{$self->{manpages}}, "$dir/$ctx->{MANPAGE}");
 }
 
-###########################################################
-# This function prepares the output for Makefile
-#
-# $output = _prepare_makefile_in($OUTPUT)
-#
-# $OUTPUT -    the global OUTPUT context
-#
-# $output -            the resulting output buffer
-sub _prepare_makefile_in($)
+sub PkgConfig($$)
 {
-       my $CTX = shift;
-       my $output;
-
-       $output  = "########################################\n";
-       $output .= "# Autogenerated by config.smb_build.pl #\n";
-       $output .= "########################################\n";
-       $output .= "\n";
-
-       my $cmd_ctx;
-       $output .= _prepare_command_interpreters($cmd_ctx);
-
-       my $path_ctx;
-       $output .= _prepare_path_vars($path_ctx);
+       my ($self,$ctx) = @_;
+       
+       my $link_name = $ctx->{NAME};
 
-       my $compiler_ctx;
-       $output .= _prepare_compiler_linker($compiler_ctx);
+       $link_name =~ s/^LIB//g;
+       $link_name = lc($link_name);
 
-       my $rules_ctx;
-       $output .= _prepare_default_rule($rules_ctx);
+       if (not defined($ctx->{DESCRIPTION})) {
+               warn("$ctx->{NAME} has not DESCRIPTION set, not generating .pc file");
+               return;
+       }
 
-       my $suffix_ctx;
-       $output .= _prepare_SUFFIXES($suffix_ctx);
+       my $path = "$ctx->{BASEDIR}/$link_name.pc";
 
-       $output .= _prepare_dummy_MAKEDIR();
+       push (@{$self->{pc_files}}, $path);
 
-       $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");
+       smb_build::env::PkgConfig($self,
+               $path,
+               $link_name,
+               $ctx->{OUTPUT},
+               join(' ', @{$ctx->{CFLAGS}}), 
+               "$ctx->{MAJOR_VERSION}.$ctx->{MINOR_VERSION}.$ctx->{RELEASE_VERSION}",
+               $ctx->{DESCRIPTION}
+       ); 
+}
 
-       $output .= _prepare_obj_lists($CTX);
+sub ProtoHeader($$)
+{
+       my ($self,$ctx) = @_;
 
-       $output .= _prepare_rule_lists($CTX);
+       $self->_prepare_list($ctx, "OBJ_LIST");
+}
 
-       my @all = ();
-       
-       foreach my $part (values %{$CTX}) {
-               push (@all, $part->{TARGET}) if defined ($part->{OUTPUT_TYPE}) and $part->{OUTPUT_TYPE} eq "BINARY";    
+sub write($$)
+{
+       my ($self,$file) = @_;
+
+       $self->output("MANPAGES = ".array2oneperline($self->{manpages})."\n");
+       $self->output("BIN_PROGS = " . array2oneperline($self->{bin_progs}) . "\n");
+       $self->output("SBIN_PROGS = " . array2oneperline($self->{sbin_progs}) . "\n");
+       $self->output("BINARIES = " . array2oneperline($self->{binaries}) . "\n");
+       $self->output("STATIC_LIBS = " . array2oneperline($self->{static_libs}) . "\n");
+       $self->output("SHARED_LIBS = " . array2oneperline($self->{shared_libs}) . "\n");
+       $self->output("PUBLIC_HEADERS = " . array2oneperline($self->{headers}) . "\n");
+       $self->output("PC_FILES = " . array2oneperline($self->{pc_files}) . "\n");
+
+
+       $self->_prepare_mk_files();
+
+       if ($self->{developer}) {
+               $self->output(<<__EOD__
+#-include \$(_ALL_OBJS_OBJ_LIST:.o=.d)
+IDL_FILES = \$(wildcard librpc/idl/*.idl)
+\$(patsubst librpc/idl/%.idl,librpc/gen_ndr/ndr_%.c,\$(IDL_FILES)) \\
+\$(patsubst librpc/idl/%.idl,librpc/gen_ndr/ndr_\%_c.c,\$(IDL_FILES)) \\
+\$(patsubst librpc/idl/%.idl,librpc/gen_ndr/ndr_%.h,\$(IDL_FILES)): idl
+__EOD__
+);
        }
-       
-       $output .= _prepare_make_target({ TARGET => "all", DEPEND_LIST => \@all });
 
-       return $output;
-}
+       $self->_prepare_dummy_MAKEDIR();
 
-###########################################################
-# This function creates Makefile.in from the OUTPUT 
-# context
-#
-# create_makefile_in($OUTPUT)
-#
-# $OUTPUT      -       the global OUTPUT context
-#
-# $output -            the resulting output buffer
-sub create_makefile_in($$)
-{
-       my $CTX = shift;
-       my $file = shift;
+       $self->output($self->{mkfile});
 
-       open(MAKEFILE_IN,">$file") || die ("Can't open $file\n");
-       print MAKEFILE_IN _prepare_makefile_in($CTX);
-       close(MAKEFILE_IN);
+       open(MAKEFILE,">$file") || die ("Can't open $file\n");
+       print MAKEFILE $self->{output};
+       close(MAKEFILE);
 
-       print "config.smb_build.pl: creating $file\n";
-       return; 
+       print __FILE__.": creating $file\n";
 }
 
 1;