Move some static makefile variables to rules.mk.
[ira/wip.git] / source / build / smb_build / makefile.pm
index 3c48d031e910583b19d65546c4866ff4849dda4b..0b1cc7eac232edf14fece5c7f4a6098f66254287 100644 (file)
@@ -7,6 +7,7 @@
 
 package smb_build::makefile;
 use smb_build::env;
+use smb_build::output;
 use File::Basename;
 use strict;
 
@@ -26,6 +27,7 @@ sub new($$$)
        $self->{torture_progs} = [];
        $self->{static_libs} = [];
        $self->{python_dsos} = [];
+       $self->{python_pys} = [];
        $self->{shared_libs} = [];
        $self->{installable_shared_libs} = [];
        $self->{headers} = [];
@@ -118,43 +120,6 @@ sub _prepare_suffix_rules($)
        $self->output(<< "__EOD__"
 FIRST_PREREQ = $first_prereq
 
-# Dependencies command
-DEPENDS = \$(CC) -M -MG -MP -MT \$(<:.c=.o) -MT \$@ \\
-    `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-    \$(CFLAGS) \$(FIRST_PREREQ) -o \$@
-# Dependencies for host objects
-HDEPENDS = \$(CC) -M -MG -MP -MT \$(<:.c=.ho) -MT \$@ \\
-    `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-    \$(HOSTCC_FLAGS) \$(FIRST_PREREQ) -o \$@
-# Dependencies for precompiled headers
-PCHDEPENDS = \$(CC) -M -MG -MT include/includes.h.gch -MT \$@ \\
-    \$(CFLAGS) \$(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) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-    \$(CFLAGS) \$(PICFLAG) -c \$(FIRST_PREREQ) -o \$@
-
-# Run the configured compiler
-COMPILE = \$(CC) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-    \$(CFLAGS) \$(PICFLAG) -c \$(FIRST_PREREQ) -o \$@
-
-# Run the compiler for the build host
-HCOMPILE = \$(HOSTCC) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-    \$(HOSTCC_FLAGS) -c \$(FIRST_PREREQ) -o \$@
-
-# Precompile headers
-PCHCOMPILE = @\$(CC) -Ilib/replace \\
-    `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
-    \$(CFLAGS) \$(PICFLAG) -c \$(FIRST_PREREQ) -o \$@
-
 __EOD__
 );
 }
@@ -189,7 +154,8 @@ 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} \$(CPPFLAGS)
+CFLAGS=$self->{config}->{CFLAGS}
+CFLAG_NO_UNUSED_MACROS=$self->{config}->{CFLAG_NO_UNUSED_MACROS}
 PICFLAG=$self->{config}->{PICFLAG}
 
 INSTALL_LINK_FLAGS=$extra_link_flags
@@ -209,13 +175,15 @@ MDLD_FLAGS=$self->{config}->{MDLD_FLAGS} -L\$(builddir)/bin/shared
 SHLIBEXT=$self->{config}->{SHLIBEXT}
 
 HOSTCC=$self->{config}->{HOSTCC}
-HOSTCC_FLAGS=-D_SAMBA_HOSTCC_ $self->{config}->{CFLAGS} \$(CPPFLAGS)
+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}
@@ -339,7 +307,7 @@ sub SharedModule($$)
 
        push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
 
-       if (defined($ctx->{INIT_FUNCTION})) {
+       if (defined($ctx->{INIT_FUNCTION}) and $ctx->{TYPE} ne "PYTHON") {
                my $init_fn = $ctx->{INIT_FUNCTION_TYPE};
                $init_fn =~ s/\(\*\)/init_module/;
                my $proto_fn = $ctx->{INIT_FUNCTION_TYPE};
@@ -463,12 +431,8 @@ sub Header($$)
 {
        my ($self,$ctx) = @_;
 
-       my $dir = $ctx->{BASEDIR};
-
-       $dir =~ s/^\.\///g;
-
        foreach (@{$ctx->{PUBLIC_HEADERS}}) {
-               push (@{$self->{headers}}, "$dir/$_");
+               push (@{$self->{headers}}, output::add_dir_str($ctx->{BASEDIR}, $_));
        }
 }
 
@@ -533,152 +497,59 @@ sub PythonFiles($$)
 
        foreach (@{$ctx->{PYTHON_FILES}}) {
                my $target = "bin/python/".basename($_);
-               $self->output("$target: $ctx->{BASEDIR}/$_\n" .
-                             "\tcp $ctx->{BASEDIR}/$_ \$@\n\n");
-               push (@{$self->{python_dsos}}, $target);
-  }
+               my $source = output::add_dir_str($ctx->{BASEDIR}, $_);
+               $self->output("$target: $source\n" .
+                                         "\tmkdir -p \$(builddir)/bin/python\n" .
+                             "\tcp $source \$@\n\n");
+               push (@{$self->{python_pys}}, $target);
+       }
 }
 
 sub Manpage($$)
 {
        my ($self,$ctx) = @_;
 
-       my $dir = $ctx->{BASEDIR};
-       
-       $dir =~ s/^\.\///g;
-
-       push (@{$self->{manpages}}, "$dir/$ctx->{MANPAGE}");
-}
-
-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 = "$ctx->{BASEDIR}/$link_name.pc";
-
-       push (@{$self->{pc_files}}, $path);
-
-       my $pubs;
-       my $privs;
-       my $privlibs;
-
-       if (defined($ctx->{PUBLIC_DEPENDENCIES})) {
-               foreach (@{$ctx->{PUBLIC_DEPENDENCIES}}) {
-                       next if ($other->{$_}->{ENABLE} eq "NO");
-                       if ($other->{$_}->{TYPE} eq "LIBRARY") {
-                               s/^LIB//g;
-                               $_ = lc($_);
-
-                               $pubs .= "$_ ";
-                       } 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 "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",
-               $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}"
-               ]
-       ); 
+       my $path = output::add_dir_str($ctx->{BASEDIR}, $ctx->{MANPAGE});
+       push (@{$self->{manpages}}, $path);
 }
 
 sub ProtoHeader($$)
 {
        my ($self,$ctx) = @_;
 
-       my $dir = $ctx->{BASEDIR};
-
-       $dir =~ s/^\.\///g;
-
        my $target = "";
-
        my $comment = "Creating ";
+
+       my $priv = undef;
+       my $pub = undef;
+
        if (defined($ctx->{PRIVATE_PROTO_HEADER})) {
-               $target.= "$dir/$ctx->{PRIVATE_PROTO_HEADER}";
-               $comment.= "$dir/$ctx->{PRIVATE_PROTO_HEADER}";
+               $priv = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PRIVATE_PROTO_HEADER});
+               $target .= $priv;
+               $comment .= $priv;
                if (defined($ctx->{PUBLIC_PROTO_HEADER})) {
                        $comment .= " and ";
                        $target.= " ";
                }
-               push (@{$self->{proto_headers}}, "$dir/$ctx->{PRIVATE_PROTO_HEADER}");
+               push (@{$self->{proto_headers}}, $priv);
        } else {
                $ctx->{PRIVATE_PROTO_HEADER} = $ctx->{PUBLIC_PROTO_HEADER};
+               $priv = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PRIVATE_PROTO_HEADER});
        }
-       
+
        if (defined($ctx->{PUBLIC_PROTO_HEADER})) {
-               $comment.= "$dir/$ctx->{PUBLIC_PROTO_HEADER}";
-               $target .= "$dir/$ctx->{PUBLIC_PROTO_HEADER}";
-               push (@{$self->{proto_headers}}, "$dir/$ctx->{PUBLIC_PROTO_HEADER}");
+               $pub = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PUBLIC_PROTO_HEADER});
+               $comment .= $pub;
+               $target .= $pub;
+               push (@{$self->{proto_headers}}, $pub);
        } else {
                $ctx->{PUBLIC_PROTO_HEADER} = $ctx->{PRIVATE_PROTO_HEADER};
-       }       
+               $pub = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PUBLIC_PROTO_HEADER});
+       }
 
-       $self->output("$dir/$ctx->{PUBLIC_PROTO_HEADER}: $ctx->{MK_FILE} \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST:.o=.c) \$(srcdir)/script/mkproto.pl\n");
+       $self->output("$pub: $ctx->{MK_FILE} \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST:.o=.c) \$(srcdir)/script/mkproto.pl\n");
        $self->output("\t\@echo \"$comment\"\n");
-
-       $self->output("\t\@\$(PERL) \$(srcdir)/script/mkproto.pl --srcdir=\$(srcdir) --builddir=\$(builddir) --private=$dir/$ctx->{PRIVATE_PROTO_HEADER} --public=$dir/$ctx->{PUBLIC_PROTO_HEADER} \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)\n\n");
+       $self->output("\t\@\$(PERL) \$(srcdir)/script/mkproto.pl --srcdir=\$(srcdir) --builddir=\$(builddir) --private=$priv --public=$pub \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)\n\n");
 }
 
 sub write($$)
@@ -693,6 +564,7 @@ sub write($$)
        $self->output("STATIC_LIBS = " . array2oneperline($self->{static_libs}) . "\n");
        $self->output("SHARED_LIBS = " . array2oneperline($self->{shared_libs}) . "\n");
        $self->output("PYTHON_DSOS = " . array2oneperline($self->{python_dsos}) . "\n");
+       $self->output("PYTHON_PYS = " . array2oneperline($self->{python_pys}) . "\n");
        $self->output("INSTALLABLE_SHARED_LIBS = " . array2oneperline($self->{installable_shared_libs}) . "\n");
        $self->output("PUBLIC_HEADERS = " . array2oneperline($self->{headers}) . "\n");
        $self->output("PC_FILES = " . array2oneperline($self->{pc_files}) . "\n");