Move some variables to a separate .mk file that could also be included by a non-smb_b...
[ira/wip.git] / source / build / smb_build / makefile.pm
index 3b43dfb0b75760a4ebee0e8853b0da86f9e3f9e5..dfa7387c753d6a1b99c4cb87b130f1ea1994da91 100644 (file)
@@ -27,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} = [];
@@ -45,6 +46,7 @@ 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");
 
@@ -110,51 +112,9 @@ __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 \$@ \\
-    `\$(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 \$@
+FIRST_PREREQ = $self->{config}->{FIRST_PREREQ}
 
 __EOD__
 );
@@ -190,7 +150,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
@@ -210,13 +171,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}
@@ -340,7 +303,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};
@@ -494,7 +457,6 @@ sub Binary($$)
                push (@{$self->{torture_progs}}, "$installdir/$ctx->{BINARY}");
        }
 
-
        push (@{$self->{binaries}}, "$localdir/$ctx->{BINARY}");
 
        $self->_prepare_list($ctx, "OBJ_LIST");
@@ -532,8 +494,9 @@ sub PythonFiles($$)
                my $target = "bin/python/".basename($_);
                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_dsos}}, $target);
+               push (@{$self->{python_pys}}, $target);
        }
 }
 
@@ -545,100 +508,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;
-
-       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}"
-               ]
-       ); 
-}
-
 sub ProtoHeader($$)
 {
        my ($self,$ctx) = @_;
@@ -690,6 +559,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");