Automatically write AC_SUBST() vars to mkconfig.mk and use them.
[ira/wip.git] / source / build / smb_build / makefile.pm
index 7e715b47eb349db20413b0f2d78a90b52d473b70..c28229c23b1787b558aa6853244741addd53e940 100644 (file)
@@ -46,11 +46,10 @@ sub new($$$)
        $self->output("# Autogenerated by build/smb_build/makefile.pm #\n");
        $self->output("################################################\n");
        $self->output("\n");
+       $self->output("include mkconfig.mk\n");
 
        $self->output("default: all\n\n");
 
-       $self->_prepare_path_vars();
-       $self->_prepare_suffix_rules();
        $self->_prepare_compiler_linker();
 
        if (!$self->{automatic_deps}) {
@@ -68,101 +67,6 @@ sub output($$)
        $self->{output} .= $text;
 }
 
-sub _prepare_path_vars($)
-{
-       my ($self) = @_;
-
-       $self->output(<< "__EOD__"
-prefix = $self->{config}->{prefix}
-exec_prefix = $self->{config}->{exec_prefix}
-selftest_prefix = $self->{config}->{selftest_prefix}
-
-builddir = $self->{config}->{builddir}
-srcdir = $self->{config}->{srcdir}
-datarootdir = $self->{config}->{datarootdir}
-
-VPATH = \$(builddir):\$(srcdir):heimdal_build:heimdal/lib/asn1:heimdal/lib/krb5:heimdal/lib/gssapi:heimdal/lib/hdb:heimdal/lib/roken:heimdal/lib/des
-
-BASEDIR = $self->{config}->{prefix}
-BINDIR = $self->{config}->{bindir}
-SBINDIR = $self->{config}->{sbindir}
-LIBDIR = $self->{config}->{libdir}
-TORTUREDIR = $self->{config}->{libdir}/torture
-MODULESDIR = $self->{config}->{modulesdir}
-INCLUDEDIR = $self->{config}->{includedir}
-CONFIGDIR = $self->{config}->{sysconfdir}
-DATADIR = $self->{config}->{datadir}
-SWATDIR = \$(DATADIR)/swat
-JSDIR = \$(DATADIR)/js
-SETUPDIR = \$(DATADIR)/setup
-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}
-WINBINDD_SOCKET_DIR = $self->{config}->{winbindd_socket_dir}
-
-__EOD__
-);
-}
-
-sub _prepare_suffix_rules($)
-{
-       my ($self) = @_;
-       my $first_prereq = '$*.c';
-
-       if ($self->{config}->{GNU_MAKE} eq 'yes') {
-               $first_prereq = '$<';
-       }
-
-       $self->output(<< "__EOD__"
-FIRST_PREREQ = $first_prereq
-
-# Dependencies command
-DEPENDS = \$(CC) -M -MG -MP -MT \$(<:.c=.o) -MT \$@ \\
-    \$(CFLAGS) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-    \$(CPPFLAGS) \$(FIRST_PREREQ) -o \$@
-# Dependencies for host objects
-HDEPENDS = \$(CC) -M -MG -MP -MT \$(<:.c=.ho) -MT \$@ \\
-    \$(HOSTCC_FLAGS) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-    \$(CPPFLAGS) \$(FIRST_PREREQ) -o \$@
-# Dependencies for precompiled headers
-PCHDEPENDS = \$(CC) -M -MG -MT include/includes.h.gch -MT \$@ \\
-    \$(CFLAGS) \$(CPPFLAGS) \$(FIRST_PREREQ) -o \$@
-
-# \$< is broken in older BSD versions:
-# when \$@ is foo/bar.o, \$< could be torture/foo/bar.c
-# if it also exists. So better use \$* which is foo/bar
-# and append .c manually to get foo/bar.c
-#
-# If we have GNU Make, it is safe to use \$<, which also lets
-# building with \$srcdir != \$builddir work.
-
-# Run a static analysis checker
-CHECK = \$(CC_CHECKER) \$(CFLAGS) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-    \$(PICFLAG) \$(CPPLAGS) -c \$(FIRST_PREREQ) -o \$@
-
-# Run the configured compiler
-COMPILE = \$(CC) \$(CFLAGS)  \$(PICFLAG) \\
-          `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-                 \$(CPPFLAGS) \\
-                 -c \$(FIRST_PREREQ) -o \$@
-
-# Run the compiler for the build host
-HCOMPILE = \$(HOSTCC) \$(HOSTCC_FLAGS) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-        \$(CPPFLAGS) -c \$(FIRST_PREREQ) -o \$@
-
-# Precompile headers
-PCHCOMPILE = @\$(CC) -Ilib/replace \\
-    \$(CFLAGS) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-    \$(PICFLAG) \$(CPPFLAGS) -c \$(FIRST_PREREQ) -o \$@
-
-__EOD__
-);
-}
-
 sub _prepare_compiler_linker($)
 {
        my ($self) = @_;
@@ -183,54 +87,22 @@ sub _prepare_compiler_linker($)
        }
 
        $self->output(<< "__EOD__"
-SHELL=$self->{config}->{SHELL}
 
-PERL=$self->{config}->{PERL}
-PYTHON=$self->{config}->{PYTHON}
-SWIG=$self->{config}->{SWIG}
-
-CPP=$self->{config}->{CPP}
 CPPFLAGS=$builddir_headers-I\$(srcdir)/include -I\$(srcdir) -I\$(srcdir)/lib -I\$(srcdir)/lib/replace -I\$(srcdir)/lib/talloc -D_SAMBA_BUILD_=4 -DHAVE_CONFIG_H $self->{config}->{CPPFLAGS}
 
-CC=$self->{config}->{CC}
-CFLAGS=$self->{config}->{CFLAGS}
-CFLAG_NO_UNUSED_MACROS=$self->{config}->{CFLAG_NO_UNUSED_MACROS}
-PICFLAG=$self->{config}->{PICFLAG}
-
 INSTALL_LINK_FLAGS=$extra_link_flags
 
 BNLD=$self->{config}->{LD} 
 BNLD_FLAGS=$self->{config}->{LDFLAGS} -L$libdir
 
-STLD=$self->{config}->{STLD}
-STLD_FLAGS=$self->{config}->{STLD_FLAGS}
-
-SHLD=$self->{config}->{SHLD}
 SHLD_FLAGS=$self->{config}->{SHLD_FLAGS} -L\$(builddir)/bin/shared
 
-MDLD=$self->{config}->{MDLD}
 MDLD_FLAGS=$self->{config}->{MDLD_FLAGS} -L\$(builddir)/bin/shared
 
-SHLIBEXT=$self->{config}->{SHLIBEXT}
-
-HOSTCC=$self->{config}->{HOSTCC}
 HOSTCC_FLAGS=-D_SAMBA_HOSTCC_ \$(CFLAGS)
 
-HOSTLD=$self->{config}->{HOSTLD}
 HOSTLD_FLAGS=$self->{config}->{LDFLAGS}
 
-XSLTPROC=$self->{config}->{XSLTPROC}
-
-LIB_PATH_VAR=$self->{config}->{LIB_PATH_VAR}
-
-LEX=$self->{config}->{LEX}
-YACC=$self->{config}->{YACC}
-YAPP=$self->{config}->{YAPP}
-
-GCOV=$self->{config}->{GCOV}
-
-DEFAULT_TEST_OPTIONS=$self->{config}->{DEFAULT_TEST_OPTIONS}
-
 __EOD__
 );
 }
@@ -324,16 +196,16 @@ sub SharedModule($$)
        } else {
                push (@{$self->{shared_modules}}, "$ctx->{TARGET_SHARED_LIBRARY}");
                push (@{$self->{plugins}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}");
-               $self->{install_plugins} .= "\t\@echo Installing $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} as \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
-               $self->{install_plugins} .= "\t\@mkdir -p \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/\n";
-               $self->{install_plugins} .= "\t\@cp $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
-               $self->{uninstall_plugins} .= "\t\@echo Uninstalling \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
-               $self->{uninstall_plugins} .= "\t\@-rm \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
+               $self->{install_plugins} .= "\t\@echo Installing $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} as \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
+               $self->{install_plugins} .= "\t\@mkdir -p \$(DESTDIR)\$(modulesdir)/$sane_subsystem/\n";
+               $self->{install_plugins} .= "\t\@cp $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
+               $self->{uninstall_plugins} .= "\t\@echo Uninstalling \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
+               $self->{uninstall_plugins} .= "\t\@-rm \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
                if (defined($ctx->{ALIASES})) {
                        foreach (@{$ctx->{ALIASES}}) {
-                               $self->{install_plugins} .= "\t\@rm -f \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
-                               $self->{install_plugins} .= "\t\@ln -fs $ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
-                               $self->{uninstall_plugins} .= "\t\@-rm \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
+                               $self->{install_plugins} .= "\t\@rm -f \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
+                               $self->{install_plugins} .= "\t\@ln -fs $ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
+                               $self->{uninstall_plugins} .= "\t\@-rm \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
                        }
                }
        }
@@ -500,7 +372,6 @@ sub Binary($$)
                push (@{$self->{torture_progs}}, "$installdir/$ctx->{BINARY}");
        }
 
-
        push (@{$self->{binaries}}, "$localdir/$ctx->{BINARY}");
 
        $self->_prepare_list($ctx, "OBJ_LIST");
@@ -552,115 +423,6 @@ sub Manpage($$)
        push (@{$self->{manpages}}, $path);
 }
 
-sub PkgConfig($$$)
-{
-       my ($self,$ctx,$other) = @_;
-       
-       my $link_name = $ctx->{NAME};
-
-       $link_name =~ s/^LIB//g;
-       $link_name = lc($link_name);
-
-       return if (not defined($ctx->{DESCRIPTION}));
-
-       my $path = output::add_dir_str($ctx->{BASEDIR}, "$link_name.pc");
-
-       push (@{$self->{pc_files}}, $path);
-
-       my $pubs;
-       my $privs;
-       my $privlibs;
-       my $publibs = "";
-
-       if (defined($ctx->{PUBLIC_DEPENDENCIES})) {
-               foreach (@{$ctx->{PUBLIC_DEPENDENCIES}}) {
-                       next if ($other->{$_}->{ENABLE} eq "NO");
-                       if (defined($other->{$_}->{PC_NAME})) {
-                               $pubs .= "$other->{$_}->{PC_NAME} ";
-                       } elsif ($other->{$_}->{TYPE} eq "EXT_LIB") {
-                               my $e = $other->{$_};
-                               my $ldflags = join(" ", @{$e->{LDFLAGS}});
-                               $ldflags .= " " unless $ldflags eq "";
-                               my $libs = join(" ", @{$e->{LIBS}});
-                               $libs .= " " unless $libs eq "";
-
-                               $publibs .= $ldflags.$libs;
-                       } else {
-                               s/^LIB//g;
-                               $_ = lc($_);
-
-                               $privlibs .= "-l$_ ";
-                       }
-               }
-       }
-
-       if (defined($ctx->{PRIVATE_DEPENDENCIES})) {
-               foreach (@{$ctx->{PRIVATE_DEPENDENCIES}}) {
-                       next if ($other->{$_}->{ENABLE} eq "NO");
-                       if ($other->{$_}->{TYPE} eq "EXT_LIB") {
-                               my $e = $other->{$_};
-
-                               my $ldflags = join(" ", @{$e->{LDFLAGS}});
-                               $ldflags .= " " unless $ldflags eq "";
-                               my $libs = join(" ", @{$e->{LIBS}});
-                               $libs .= " " unless $libs eq "";
-
-                               $privlibs .= $ldflags.$libs;
-                       } elsif ($other->{$_}->{TYPE} eq "LIBRARY") {
-                               s/^LIB//g;
-                               $_ = lc($_);
-
-                               $privs .= "$_ ";
-                       } else {
-                               s/^LIB//g;
-                               $_ = lc($_);
-
-                               $privlibs .= "-l$_ ";
-                       }
-               }
-       }
-
-       smb_build::env::PkgConfig($self,
-               $path,
-               $link_name,
-               "-L\${libdir} -l$link_name $publibs",
-               $privlibs,
-               "",
-               "$ctx->{VERSION}",
-               $ctx->{DESCRIPTION},
-               defined($ctx->{INIT_FUNCTIONS}),
-               $pubs,
-               "",
-               [
-                       "prefix=$self->{config}->{prefix}",
-                       "exec_prefix=$self->{config}->{exec_prefix}",
-                       "libdir=$self->{config}->{libdir}",
-                       "includedir=$self->{config}->{includedir}"
-               ]
-       ); 
-       my $abs_srcdir = abs_path($self->{config}->{srcdir});
-       smb_build::env::PkgConfig($self,
-               "bin/pkgconfig/$link_name-uninstalled.pc",
-               $link_name,
-               "-Lbin/shared -Lbin/static -l$link_name",
-               $privlibs,
-               join(' ', 
-                       "-I$abs_srcdir",
-                       "-I$abs_srcdir/include",
-                       "-I$abs_srcdir/lib",
-                       "-I$abs_srcdir/lib/replace"),
-               "$ctx->{VERSION}",
-               $ctx->{DESCRIPTION},
-               defined($ctx->{INIT_FUNCTIONS}),
-               $pubs,
-               $privs,
-               [
-                       "prefix=bin/",
-                       "includedir=$ctx->{BASEDIR}"
-               ]
-       ); 
-}
-
 sub ProtoHeader($$)
 {
        my ($self,$ctx) = @_;