diff options
Diffstat (limited to 'source4/build/smb_build')
-rw-r--r-- | source4/build/smb_build/README.txt | 7 | ||||
-rwxr-xr-x | source4/build/smb_build/cflags.pm | 69 | ||||
-rw-r--r-- | source4/build/smb_build/config_mk.pm | 14 | ||||
-rw-r--r-- | source4/build/smb_build/env.pm | 57 | ||||
-rw-r--r-- | source4/build/smb_build/header.pm | 92 | ||||
-rw-r--r-- | source4/build/smb_build/input.pm | 8 | ||||
-rw-r--r-- | source4/build/smb_build/main.pl | 45 | ||||
-rw-r--r-- | source4/build/smb_build/makefile.pm | 359 | ||||
-rw-r--r-- | source4/build/smb_build/output.pm | 43 |
9 files changed, 165 insertions, 529 deletions
diff --git a/source4/build/smb_build/README.txt b/source4/build/smb_build/README.txt index a5e4db99e0..eac3905cce 100644 --- a/source4/build/smb_build/README.txt +++ b/source4/build/smb_build/README.txt @@ -1,6 +1,5 @@ The Samba Build System
-----------------------
-----------------------
+======================
The build system basically has two main parts: the autoconf-generated
shell scripts which check for availability of functions and libraries
@@ -29,7 +28,7 @@ EXT_LIB: BINARY:
a BINARY means a executable binary file.
(e.g. 'smbtorture' or 'ldbedit')
- a BINARY typicly has only commandline handling and basic
+ a BINARY typically has only commandline handling and basic
functionality code in it and depends on the functions of
SUBSYSTEM's (REQUIRED_SUBSYSTEMS).
@@ -50,8 +49,6 @@ input.pm - Input validation main.pm - Main
makefile.pm - Makefile generation
output.pm - Dependency calculation
-header.pm - build.h generation
-cflags.pm - Generates cflags.txt for file-specific cflags
Layout
-------
diff --git a/source4/build/smb_build/cflags.pm b/source4/build/smb_build/cflags.pm deleted file mode 100755 index a4ab90a8cd..0000000000 --- a/source4/build/smb_build/cflags.pm +++ /dev/null @@ -1,69 +0,0 @@ -# SMB Build System -# -# Copyright (C) Jelmer Vernooij 2006 -# Released under the GNU GPL - -package cflags; -use strict; - -my $sort_available = eval "use sort 'stable'; return 1;"; -$sort_available = 0 unless defined($sort_available); - -sub by_path { - return 1 if($a =~ m#^\-I/#); - return -1 if($b =~ m#^\-I/#); - return 0; -} - -sub create_cflags($$$$) { - my $CTX = shift; - my $srcdir = shift; - my $builddir = shift; - my $file = shift; - - open(CFLAGS_TXT,">$file") || die ("Can't open `$file'\n"); - - print CFLAGS_TXT "include mkconfig.mk\n"; - - my $src_ne_build = ($srcdir ne $builddir) ? 1 : 0; - - foreach my $key (values %{$CTX}) { - next unless defined ($key->{OBJ_LIST}); - next unless defined ($key->{FINAL_CFLAGS}); - next unless (@{$key->{FINAL_CFLAGS}} > 0); - - my @sorted_cflags = @{$key->{FINAL_CFLAGS}}; - if ($sort_available) { - @sorted_cflags = sort by_path @{$key->{FINAL_CFLAGS}}; - } - - # Rewrite CFLAGS so that both the source and the build - # directories are in the path. - my @cflags = (); - foreach my $flag (@sorted_cflags) { - if($src_ne_build) { - if($flag =~ m#^-I([^/].*$)#) { - my $dir = $1; - $dir =~ s#^\$\((?:src|build)dir\)/?##; - push(@cflags, "-I$builddir/$dir", "-I$srcdir/$dir"); - next; - } - } - push(@cflags, $flag); - } - - my $cflags = join(' ', @cflags); - - foreach (@{$key->{OBJ_LIST}}) { - my $ofile = $_; - my $dfile = $_; - $dfile =~ s/\.o$/.d/; - $dfile =~ s/\.ho$/.d/; - print CFLAGS_TXT "$ofile $dfile: CFLAGS+= $cflags\n"; - } - } - close(CFLAGS_TXT); - - print __FILE__.": creating $file\n"; -} -1; diff --git a/source4/build/smb_build/config_mk.pm b/source4/build/smb_build/config_mk.pm index 4d8db8a04e..7e0d2f8f56 100644 --- a/source4/build/smb_build/config_mk.pm +++ b/source4/build/smb_build/config_mk.pm @@ -36,13 +36,8 @@ my $section_types = { "ENABLE" => "bool", - "MANPAGE" => "string", - - "PUBLIC_PROTO_HEADER" => "string", "PRIVATE_PROTO_HEADER" => "string", - "PUBLIC_HEADERS" => "list", - "CFLAGS" => "list", "LDFLAGS" => "list", "STANDARD_VISIBILITY" => "string", @@ -62,7 +57,6 @@ my $section_types = { "OUTPUT_TYPE" => "list", - "MANPAGE" => "string", "PRIVATE_PROTO_HEADER" => "string", "CFLAGS" => "list" @@ -74,7 +68,6 @@ my $section_types = { "ENABLE" => "bool", - "MANPAGE" => "string", "INSTALLDIR" => "string", "PRIVATE_PROTO_HEADER" => "string", @@ -102,11 +95,6 @@ my $section_types = { "ENABLE" => "bool", - "MANPAGE" => "string", - - "PUBLIC_HEADERS" => "list", - - "PUBLIC_PROTO_HEADER" => "string", "PRIVATE_PROTO_HEADER" => "string", "CFLAGS" => "list", @@ -245,6 +233,7 @@ sub run_config_mk($$$$) $subdir =~ s/^\.$//g; $subdir =~ s/^\.\///g; $subdir .= "/" if ($subdir ne ""); + $makefile .= "basedir := $subdir\n"; $makefile .= run_config_mk($input, $srcdir, $builddir, $subdir.$subfile); next; } @@ -263,7 +252,6 @@ sub run_config_mk($$$$) $infragment = 1; next; } - # Assignment if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) { diff --git a/source4/build/smb_build/env.pm b/source4/build/smb_build/env.pm deleted file mode 100644 index 76cd8d1a26..0000000000 --- a/source4/build/smb_build/env.pm +++ /dev/null @@ -1,57 +0,0 @@ -# Environment class -# -# Samba Build Environment -# -# (C) 2005 Jelmer Vernooij <jelmer@samba.org> -# -# Published under the GNU GPL - -package smb_build::env; -use smb_build::input; -use File::Path; -use File::Basename; - -use strict; - -sub new($$) -{ - my ($name, $config) = @_; - my $self = { }; - bless $self, $name; - - $self->{items} = {}; - $self->{info} = {}; - - $self->_set_config($config); - - return $self; -} - -sub _set_config($$) -{ - my ($self, $config) = @_; - - $self->{config} = $config; - - if (not defined($self->{config}->{srcdir})) { - $self->{config}->{srcdir} = '.'; - } - - if (not defined($self->{config}->{builddir})) { - $self->{config}->{builddir} = '.'; - } - - if ($self->{config}->{prefix} eq "NONE") { - $self->{config}->{prefix} = $self->{config}->{ac_default_prefix}; - } - - if ($self->{config}->{exec_prefix} eq "NONE") { - $self->{config}->{exec_prefix} = $self->{config}->{prefix}; - } - - $self->{developer} = ($self->{config}->{developer} eq "yes"); - $self->{gnu_make} = ($self->{config}->{GNU_MAKE} eq "yes"); - $self->{automatic_deps} = ($self->{config}->{automatic_dependencies} eq "yes"); -} - -1; diff --git a/source4/build/smb_build/header.pm b/source4/build/smb_build/header.pm deleted file mode 100644 index c2bdbaf4c8..0000000000 --- a/source4/build/smb_build/header.pm +++ /dev/null @@ -1,92 +0,0 @@ -# SMB Build System -# - create output for build.h -# -# Copyright (C) Stefan (metze) Metzmacher 2004 -# Copyright (C) Jelmer Vernooij 2005 -# Released under the GNU GPL - -package header; -use strict; - -sub _add_define_section($) -{ - my $DEFINE = shift; - my $output = ""; - - $output .= " -/* $DEFINE->{COMMENT} */ -#define $DEFINE->{KEY} $DEFINE->{VAL} -"; - - return $output; -} - -sub _prepare_build_h($) -{ - my $depend = shift; - my @defines = (); - my $output = ""; - - foreach my $key (values %$depend) { - my $DEFINE = (); - next if ($key->{TYPE} ne "LIBRARY" and - $key->{TYPE} ne "MODULE" and - $key->{TYPE} ne "SUBSYSTEM" and - $key->{TYPE} ne "BINARY"); - next unless defined($key->{INIT_FUNCTIONS}); - - my $name = $key->{NAME}; - $name =~ s/-/_/g; - $DEFINE->{COMMENT} = "$key->{TYPE} $key->{NAME} INIT"; - $DEFINE->{KEY} = "STATIC_$name\_MODULES"; - $DEFINE->{VAL} = "\\\n"; - foreach (@{$key->{INIT_FUNCTIONS}}) { - $DEFINE->{VAL} .= "\t$_, \\\n"; - unless (/{/) { - my $fn = $key->{INIT_FUNCTION_TYPE}; - my $n = $_; - if ($fn =~ /\(\*\)/) { - $fn =~ s/\(\*\)/$n/; - $output .= "$fn;\n"; - } else { - $n =~ s/\&//; - $output .= "$fn $n;\n"; - } - } - } - - $DEFINE->{VAL} .= "\t$key->{INIT_FUNCTION_SENTINEL} \n"; - - push(@defines,$DEFINE); - } - - # - # loop over all BUILD_H define sections - # - foreach (@defines) { $output .= _add_define_section($_); } - - return $output; -} - -########################################################### -# This function creates include/build.h from the SMB_BUILD -# context -# -# create_build_h($SMB_BUILD_CTX) -# -# $SMB_BUILD_CTX - the global SMB_BUILD context -# -# $output - the resulting output buffer -sub create_smb_build_h($$) -{ - my ($CTX, $file) = @_; - - open(BUILD_H,">$file") || die ("Can't open `$file'\n"); - print BUILD_H "/* autogenerated by build/smb_build/main.pl */\n"; - print BUILD_H _prepare_build_h($CTX); - close(BUILD_H); - - print __FILE__.": creating $file\n"; -} - -1; diff --git a/source4/build/smb_build/input.pm b/source4/build/smb_build/input.pm index 8c9a6efacc..948f2657b4 100644 --- a/source4/build/smb_build/input.pm +++ b/source4/build/smb_build/input.pm @@ -233,14 +233,6 @@ sub check($$$$$) my ($INPUT, $enabled, $subsys_ot, $lib_ot, $module_ot) = @_; foreach my $part (values %$INPUT) { - unless (defined($part->{PUBLIC_HEADERS})) { - $part->{PUBLIC_HEADERS} = []; - } - - if (defined($part->{PUBLIC_PROTO_HEADER})) { - push (@{$part->{PUBLIC_HEADERS}}, $part->{PUBLIC_PROTO_HEADER}); - } - if (defined($enabled->{$part->{NAME}})) { $part->{ENABLE} = $enabled->{$part->{NAME}}; next; diff --git a/source4/build/smb_build/main.pl b/source4/build/smb_build/main.pl index 3ed0327d6d..cb7bf7439e 100644 --- a/source4/build/smb_build/main.pl +++ b/source4/build/smb_build/main.pl @@ -6,12 +6,9 @@ # Released under the GNU GPL use smb_build::makefile; -use smb_build::header; use smb_build::input; use smb_build::config_mk; use smb_build::output; -use smb_build::env; -use smb_build::cflags; use smb_build::summary; use smb_build::config; use strict; @@ -53,10 +50,10 @@ foreach my $key (values %$OUTPUT) { foreach my $key (values %$OUTPUT) { next unless defined $key->{OUTPUT_TYPE}; + $mkenv->StaticLibraryPrimitives($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}}); $mkenv->MergedObj($key) if grep(/MERGED_OBJ/, @{$key->{OUTPUT_TYPE}}); - $mkenv->StaticLibrary($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}}); if (defined($key->{PC_FILE})) { - push(@{$mkenv->{pc_files}}, "$key->{BASEDIR}/$key->{PC_FILE}"); + $mkenv->output("PC_FILES += $key->{BASEDIR}/$key->{PC_FILE}\n"); } $mkenv->SharedLibraryPrimitives($key) if ($key->{TYPE} eq "LIBRARY") and grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}}); @@ -64,40 +61,36 @@ foreach my $key (values %$OUTPUT) { ${$key->{OUTPUT_TYPE}}[0] eq "SHARED_LIBRARY") { $shared_libs_used = 1; } - $mkenv->SharedModulePrimitives($key) if ($key->{TYPE} eq "MODULE" or - $key->{TYPE} eq "PYTHON") and - grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}}); $mkenv->PythonFiles($key) if defined($key->{PYTHON_FILES}); - $mkenv->Manpage($key) if defined($key->{MANPAGE}); - $mkenv->Header($key) if defined($key->{PUBLIC_HEADERS}); - $mkenv->ProtoHeader($key) if defined($key->{PRIVATE_PROTO_HEADER}) or - defined($key->{PUBLIC_PROTO_HEADER}); + if ($key->{TYPE} eq "MODULE" and @{$key->{OUTPUT_TYPE}}[0] eq "MERGED_OBJ" and defined($key->{INIT_FUNCTION})) { + $mkenv->output("$key->{SUBSYSTEM}_INIT_FUNCTIONS += $key->{INIT_FUNCTION},\n"); + } + $mkenv->CFlags($key); } foreach my $key (values %$OUTPUT) { next unless defined $key->{OUTPUT_TYPE}; + $mkenv->Integrated($key) if grep(/INTEGRATED/, @{$key->{OUTPUT_TYPE}}); +} + +foreach my $key (values %$OUTPUT) { + next unless defined $key->{OUTPUT_TYPE}; + + $mkenv->StaticLibrary($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}}); $mkenv->SharedLibrary($key) if ($key->{TYPE} eq "LIBRARY") and grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}}); - $mkenv->SharedModule($key) if ($key->{TYPE} eq "MODULE" or - $key->{TYPE} eq "PYTHON") and - grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}}); + $mkenv->SharedModule($key) if ($key->{TYPE} eq "MODULE" and + grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}})); + $mkenv->PythonModule($key) if ($key->{TYPE} eq "PYTHON"); $mkenv->Binary($key) if grep(/BINARY/, @{$key->{OUTPUT_TYPE}}); + $mkenv->ProtoHeader($key) if defined($key->{PRIVATE_PROTO_HEADER}) or + defined($key->{PUBLIC_PROTO_HEADER}); + $mkenv->InitFunctions($key) if defined($key->{INIT_FUNCTIONS}); } $mkenv->write("data.mk"); -header::create_smb_build_h($OUTPUT, "include/build.h"); - -cflags::create_cflags($OUTPUT, $config::config{srcdir}, - $config::config{builddir}, "extra_cflags.txt"); summary::show($OUTPUT, \%config::config); -if ($shared_libs_used) { - print <<EOF; -To run binaries without installing, set the following environment variable: - $config::config{LIB_PATH_VAR}=$config::config{builddir}/bin/shared -EOF -} - 1; diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm index 29da771353..9aa4e409bd 100644 --- a/source4/build/smb_build/makefile.pm +++ b/source4/build/smb_build/makefile.pm @@ -6,32 +6,21 @@ # Released under the GNU GPL package smb_build::makefile; -use smb_build::env; use smb_build::output; use File::Basename; use strict; -use base 'smb_build::env'; use Cwd 'abs_path'; sub new($$$) { my ($myname, $config, $mkfile) = @_; - my $self = new smb_build::env($config); - + my $self = {}; + bless($self, $myname); - $self->{manpages} = []; - $self->{sbin_progs} = []; - $self->{bin_progs} = []; - $self->{static_libs} = []; - $self->{python_dsos} = []; - $self->{python_pys} = []; - $self->{shared_libs} = []; - $self->{headers} = []; - $self->{plugins} = []; - $self->{pc_files} = []; - $self->{proto_headers} = []; + $self->_set_config($config); + $self->{output} = ""; $self->{mkfile} = $mkfile; @@ -41,12 +30,30 @@ sub new($$$) $self->output("################################################\n"); $self->output("\n"); - if (!$self->{automatic_deps}) { - $self->output("ALL_PREDEP = proto\n"); - $self->output(".NOTPARALLEL:\n"); + return $self; +} + +sub _set_config($$) +{ + my ($self, $config) = @_; + + $self->{config} = $config; + + if (not defined($self->{config}->{srcdir})) { + $self->{config}->{srcdir} = '.'; } - return $self; + if (not defined($self->{config}->{builddir})) { + $self->{config}->{builddir} = '.'; + } + + if ($self->{config}->{prefix} eq "NONE") { + $self->{config}->{prefix} = $self->{config}->{ac_default_prefix}; + } + + if ($self->{config}->{exec_prefix} eq "NONE") { + $self->{config}->{exec_prefix} = $self->{config}->{prefix}; + } } sub output($$) @@ -66,23 +73,17 @@ sub _prepare_mk_files($) push (@tmp, $_); } - if ($self->{gnu_make}) { - $self->output(" + $self->output(" ifneq (\$(MAKECMDGOALS),clean) ifneq (\$(MAKECMDGOALS),distclean) ifneq (\$(MAKECMDGOALS),realdistclean) "); - } - $self->output("MK_FILES = " . array2oneperline(\@tmp) . "\n"); - - if ($self->{gnu_make}) { - $self->output(" + $self->output(" endif endif endif "); - } } sub array2oneperline($) @@ -112,46 +113,43 @@ sub _prepare_list($$$) $self->output("$ctx->{NAME}_$var =$tmplist\n"); } -sub SharedModulePrimitives($$) +sub PythonModule($$) { my ($self,$ctx) = @_; - - #FIXME + + $self->output("$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n"); + $self->_prepare_list($ctx, "FULL_OBJ_LIST"); + $self->_prepare_list($ctx, "DEPEND_LIST"); + $self->_prepare_list($ctx, "LINK_FLAGS"); + + $self->output("\$(eval \$(call python_c_module_template,$ctx->{LIBRARY_REALNAME},\$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST), \$($ctx->{NAME}\_FULL_OBJ_LIST) \$($ctx->{NAME}_LINK_FLAGS)))\n"); } sub SharedModule($$) { my ($self,$ctx) = @_; - my $init_obj = ""; - my $sane_subsystem = lc($ctx->{SUBSYSTEM}); $sane_subsystem =~ s/^lib//; - if ($ctx->{TYPE} eq "PYTHON") { - push (@{$self->{python_dsos}}, - "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}"); - } else { - push (@{$self->{plugins}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}"); - $self->output("installplugins:: $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}\n"); - $self->output("\t\@echo Installing $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} as \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n"); - $self->output("\t\@mkdir -p \$(DESTDIR)\$(modulesdir)/$sane_subsystem/\n"); - $self->output("\t\@cp $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n"); - if (defined($ctx->{ALIASES})) { - foreach (@{$ctx->{ALIASES}}) { - $self->output("\t\@rm -f \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n"); - $self->output("\t\@ln -fs $ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n"); - } + $self->output("PLUGINS += $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}\n"); + $self->output("installplugins:: $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}\n"); + $self->output("\t\@echo Installing $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} as \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n"); + $self->output("\t\@mkdir -p \$(DESTDIR)\$(modulesdir)/$sane_subsystem/\n"); + $self->output("\t\@cp $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n"); + if (defined($ctx->{ALIASES})) { + foreach (@{$ctx->{ALIASES}}) { + $self->output("\t\@ln -fs $ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n"); } + } - $self->output("uninstallplugins::\n"); - $self->output("\t\@echo Uninstalling \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n"); - $self->output("\t\@-rm \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n"); + $self->output("uninstallplugins::\n"); + $self->output("\t\@echo Uninstalling \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n"); + $self->output("\t\@-rm \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n"); - if (defined($ctx->{ALIASES})) { - foreach (@{$ctx->{ALIASES}}) { - $self->output("\t\@-rm \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n"); - } + if (defined($ctx->{ALIASES})) { + foreach (@{$ctx->{ALIASES}}) { + $self->output("\t\@-rm \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n"); } } @@ -160,47 +158,19 @@ sub SharedModule($$) $self->_prepare_list($ctx, "DEPEND_LIST"); $self->_prepare_list($ctx, "LINK_FLAGS"); - if (defined($ctx->{INIT_FUNCTION}) and $ctx->{TYPE} ne "PYTHON" and - $ctx->{INIT_FUNCTION_TYPE} =~ /\(\*\)/) { - my $init_fn = $ctx->{INIT_FUNCTION_TYPE}; - $init_fn =~ s/\(\*\)/init_module/; - my $proto_fn = $ctx->{INIT_FUNCTION_TYPE}; - $proto_fn =~ s/\(\*\)/$ctx->{INIT_FUNCTION}/; - - $self->output(<< "__EOD__" -bin/$ctx->{NAME}_init_module.c: - \@echo Creating \$\@ - \@echo \"#include \\\"includes.h\\\"\" > \$\@ - \@echo \"$proto_fn;\" >> \$\@ - \@echo \"_PUBLIC_ $init_fn\" >> \$\@ - \@echo \"{\" >> \$\@ - \@echo \" return $ctx->{INIT_FUNCTION}();\" >> \$\@ - \@echo \"}\" >> \$\@ - \@echo \"\" >> \$\@ -__EOD__ -); - $init_obj = "bin/$ctx->{NAME}_init_module.o"; + if (defined($ctx->{INIT_FUNCTION}) and $ctx->{INIT_FUNCTION_TYPE} =~ /\(\*\)/) { + $self->output("\$($ctx->{NAME}_OBJ_LIST): CFLAGS+=-D$ctx->{INIT_FUNCTION}=init_module\n"); } - $self->output(<< "__EOD__" -# - -$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}: \$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST) $init_obj - \@echo Linking \$\@ - \@mkdir -p $ctx->{SHAREDDIR} - \@\$(MDLD) \$(LDFLAGS) \$(MDLD_FLAGS) \$(INTERN_LDFLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\ - \$($ctx->{NAME}\_FULL_OBJ_LIST) $init_obj \\ - \$($ctx->{NAME}_LINK_FLAGS) -__EOD__ -); + $self->output("\$(eval \$(call shared_module_template,$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}, \$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST), \$($ctx->{NAME}\_FULL_OBJ_LIST) \$($ctx->{NAME}_LINK_FLAGS)))\n"); if (defined($ctx->{ALIASES})) { foreach (@{$ctx->{ALIASES}}) { - $self->output("\t\@rm -f $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n"); - $self->output("\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n"); + $self->output("$ctx->{SHAREDDIR}/$_.\$(SHLIBEXT): $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}\n"); + $self->output("\t\@ln -fs \$(<F) \$@\n"); + $self->output("PLUGINS += $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n"); } } - $self->output("\n"); } sub SharedLibraryPrimitives($$) @@ -220,36 +190,27 @@ sub SharedLibrary($$) { my ($self,$ctx) = @_; - push (@{$self->{shared_libs}}, $ctx->{RESULT_SHARED_LIBRARY}) if (defined($ctx->{SO_VERSION})); + $self->output("SHARED_LIBS += $ctx->{RESULT_SHARED_LIBRARY}\n") if (defined($ctx->{SO_VERSION})); $self->_prepare_list($ctx, "DEPEND_LIST"); $self->_prepare_list($ctx, "LINK_FLAGS"); - my $soarg = ""; - my $lns = ""; - if ($self->{config}->{SONAMEFLAG} ne "#" and defined($ctx->{LIBRARY_SONAME})) { - $soarg = "$self->{config}->{SONAMEFLAG}$ctx->{LIBRARY_SONAME}"; - if ($ctx->{LIBRARY_REALNAME} ne $ctx->{LIBRARY_SONAME}) { - $lns .= "\n\t\@test \$($ctx->{NAME}_VERSION) = \$($ctx->{NAME}_SOVERSION) || ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}"; - } - } - - if (defined($ctx->{LIBRARY_SONAME})) { - $lns .= "\n\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}"; - } - $self->output(<< "__EOD__" -# $ctx->{RESULT_SHARED_LIBRARY}: \$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST) \@echo Linking \$\@ - \@mkdir -p $ctx->{SHAREDDIR} + \@mkdir -p \$(\@D) \@\$(SHLD) \$(LDFLAGS) \$(SHLD_FLAGS) \$(INTERN_LDFLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\ \$($ctx->{NAME}\_FULL_OBJ_LIST) \\ \$($ctx->{NAME}_LINK_FLAGS) \\ - $soarg$lns + \$(if \$(SONAMEFLAG), \$(SONAMEFLAG)$ctx->{LIBRARY_SONAME}) +ifneq ($ctx->{LIBRARY_REALNAME}, $ctx->{LIBRARY_SONAME}) + \@test \$($ctx->{NAME}_VERSION) = \$($ctx->{NAME}_SOVERSION) || ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME} +endif +ifdef $ctx->{NAME}_SOVERSION + \@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME} +endif __EOD__ ); - $self->output("\n"); } sub MergedObj($$) @@ -259,78 +220,56 @@ sub MergedObj($$) return unless defined($ctx->{OUTPUT}); $self->output("$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n"); - $self->output(<< "__EOD__" -# -$ctx->{RESULT_MERGED_OBJ}: \$($ctx->{NAME}_OBJ_LIST) - \@echo Partially linking \$@ - \@mkdir -p bin/mergedobj - \$(PARTLINK) -o \$@ \$($ctx->{NAME}_OBJ_LIST) - -__EOD__ -); + $self->output("\$(call partial_link_template, \$($ctx->{NAME}_OUTPUT), \$($ctx->{NAME}_OBJ_LIST))\n"); } -sub StaticLibrary($$) +sub StaticLibraryPrimitives($$) { my ($self,$ctx) = @_; return unless (defined($ctx->{OBJ_FILES})); - push (@{$self->{static_libs}}, $ctx->{RESULT_STATIC_LIBRARY}) if ($ctx->{TYPE} eq "LIBRARY"); - $self->output("$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n"); $self->_prepare_list($ctx, "FULL_OBJ_LIST"); +} - $self->output("$ctx->{RESULT_STATIC_LIBRARY}: \$($ctx->{NAME}_FULL_OBJ_LIST)\n"); +sub InitFunctions($$) +{ + my ($self, $ctx) = @_; + $self->output("\$($ctx->{NAME}_OBJ_LIST): CFLAGS+=-DSTATIC_$ctx->{NAME}_MODULES=\"\$($ctx->{NAME}_INIT_FUNCTIONS)$ctx->{INIT_FUNCTION_SENTINEL}\"\n"); } -sub Header($$) +sub StaticLibrary($$) { my ($self,$ctx) = @_; - foreach (@{$ctx->{PUBLIC_HEADERS}}) { - push (@{$self->{headers}}, output::add_dir_str($ctx->{BASEDIR}, $_)); - } + return unless (defined($ctx->{OBJ_FILES})); + + $self->output("STATIC_LIBS += $ctx->{RESULT_STATIC_LIBRARY}\n") if ($ctx->{TYPE} eq "LIBRARY"); + $self->output("$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n"); + $self->output("$ctx->{RESULT_STATIC_LIBRARY}: \$($ctx->{NAME}_FULL_OBJ_LIST)\n"); } sub Binary($$) { my ($self,$ctx) = @_; - my $extradir = ""; - unless (defined($ctx->{INSTALLDIR})) { + $self->output("binaries:: $ctx->{TARGET_BINARY}\n"); } elsif ($ctx->{INSTALLDIR} eq "SBINDIR") { - push (@{$self->{sbin_progs}}, $ctx->{RESULT_BINARY}); + $self->output("SBIN_PROGS += $ctx->{RESULT_BINARY}\n"); } elsif ($ctx->{INSTALLDIR} eq "BINDIR") { - push (@{$self->{bin_progs}}, $ctx->{RESULT_BINARY}); + $self->output("BIN_PROGS += $ctx->{RESULT_BINARY}\n"); } - $self->output("binaries:: $ctx->{TARGET_BINARY}\n"); - $self->_prepare_list($ctx, "FULL_OBJ_LIST"); $self->_prepare_list($ctx, "DEPEND_LIST"); $self->_prepare_list($ctx, "LINK_FLAGS"); -$self->output(<< "__EOD__" -$ctx->{RESULT_BINARY}: \$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST) - \@echo Linking \$\@ -__EOD__ - ); - if (defined($ctx->{USE_HOSTCC}) && $ctx->{USE_HOSTCC} eq "YES") { - $self->output(<< "__EOD__" - \@\$(HOSTLD) \$(HOSTLD_FLAGS) -L\${builddir}/bin/static -o \$\@ \$(INSTALL_LINK_FLAGS) \\ - \$\($ctx->{NAME}_LINK_FLAGS) -__EOD__ - ); +$self->output("\$(call host_binary_link_template, $ctx->{RESULT_BINARY}, \$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST), \$($ctx->{NAME}_LINK_FLAGS))\n"); } else { - $self->output(<< "__EOD__" - \@\$(BNLD) \$(BNLD_FLAGS) \$(INTERN_LDFLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\ - \$\($ctx->{NAME}_LINK_FLAGS) - -__EOD__ - ); +$self->output("\$(call binary_link_template, $ctx->{RESULT_BINARY}, \$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST), \$($ctx->{NAME}_LINK_FLAGS))\n"); } } @@ -339,110 +278,80 @@ sub PythonFiles($$) my ($self,$ctx) = @_; foreach (@{$ctx->{PYTHON_FILES}}) { - 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_pys}}, $target); + $self->output("\$(eval \$(call python_py_module_template," . basename($_) . ",\$(addprefix $ctx->{BASEDIR}/, $_)))\n"); } } -sub Manpage($$) +sub ProtoHeader($$) { my ($self,$ctx) = @_; - my $path = output::add_dir_str($ctx->{BASEDIR}, $ctx->{MANPAGE}); - push (@{$self->{manpages}}, $path); + my $target = "\$(addprefix $ctx->{BASEDIR}/, $ctx->{PRIVATE_PROTO_HEADER})"; + $self->output("PROTO_HEADERS += $target\n"); + $self->output("\$(call proto_header_template, $target, \$($ctx->{NAME}_OBJ_LIST:.o=.c))\n"); } -sub ProtoHeader($$) +sub write($$) { - my ($self,$ctx) = @_; + my ($self, $file) = @_; - my $target = ""; - my $comment = "Creating "; + $self->_prepare_mk_files(); - my $priv = undef; - my $pub = undef; + $self->output($self->{mkfile}); - if (defined($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}}, $priv); - } else { - $ctx->{PRIVATE_PROTO_HEADER} = $ctx->{PUBLIC_PROTO_HEADER}; - $priv = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PRIVATE_PROTO_HEADER}); - } + open(MAKEFILE,">$file") || die ("Can't open $file\n"); + print MAKEFILE $self->{output}; + close(MAKEFILE); - if (defined($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}); - } + print __FILE__.": creating $file\n"; +} + +my $sort_available = eval "use sort 'stable'; return 1;"; +$sort_available = 0 unless defined($sort_available); - $self->output("$pub: $ctx->{MK_FILE} \$($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=$priv --public=$pub \$($ctx->{NAME}_OBJ_LIST)\n\n"); +sub by_path { + return 1 if($a =~ m#^\-I/#); + return -1 if($b =~ m#^\-I/#); + return 0; } -sub write($$) +sub CFlags($$) { - my ($self, $file) = @_; + my ($self, $key) = @_; - $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("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("PUBLIC_HEADERS = " . array2oneperline($self->{headers}) . "\n"); - $self->output("PC_FILES = " . array2oneperline($self->{pc_files}) . "\n"); - $self->output("ALL_OBJS = " . array2oneperline($self->{all_objs}) . "\n"); - $self->output("PROTO_HEADERS = " . array2oneperline($self->{proto_headers}) . "\n"); - $self->output("PLUGINS = " . array2oneperline($self->{plugins}) . "\n"); + my $srcdir = $self->{config}->{srcdir}; + my $builddir = $self->{config}->{builddir}; - $self->_prepare_mk_files(); + my $src_ne_build = ($srcdir ne $builddir) ? 1 : 0; - $self->output($self->{mkfile}); + return unless defined ($key->{OBJ_LIST}); + return unless defined ($key->{FINAL_CFLAGS}); + return unless (@{$key->{FINAL_CFLAGS}} > 0); - if ($self->{automatic_deps}) { - $self->output(" -ifneq (\$(MAKECMDGOALS),clean) -ifneq (\$(MAKECMDGOALS),distclean) -ifneq (\$(MAKECMDGOALS),realdistclean) -ifneq (\$(SKIP_DEP_FILES),yes) --include \$(DEP_FILES) -endif -endif -endif -endif - -ifneq (\$(SKIP_DEP_FILES),yes) -clean:: - \@echo Removing dependency files - \@find . -name '*.d' -o -name '*.hd' | xargs rm -f -endif -"); - } else { - $self->output("include \$(srcdir)/static_deps.mk\n"); + my @sorted_cflags = @{$key->{FINAL_CFLAGS}}; + if ($sort_available) { + @sorted_cflags = sort by_path @{$key->{FINAL_CFLAGS}}; } - open(MAKEFILE,">$file") || die ("Can't open $file\n"); - print MAKEFILE $self->{output}; - close(MAKEFILE); + # Rewrite CFLAGS so that both the source and the build + # directories are in the path. + my @cflags = (); + foreach my $flag (@sorted_cflags) { + if($src_ne_build) { + if($flag =~ m#^-I([^/].*$)#) { + my $dir = $1; + $dir =~ s#^\$\((?:src|build)dir\)/?##; + push(@cflags, "-I$builddir/$dir", "-I$srcdir/$dir"); + next; + } + } + push(@cflags, $flag); + } + + my $cflags = join(' ', @cflags); - print __FILE__.": creating $file\n"; + my $ext = "o"; + $self->output("\$($key->{NAME}_OBJ_LIST) \$(patsubst %.ho,%.d,\$($key->{NAME}_OBJ_LIST:.o=.d)): CFLAGS+=$cflags\n"); } 1; diff --git a/source4/build/smb_build/output.pm b/source4/build/smb_build/output.pm index ff9afe8e8c..eec438b108 100644 --- a/source4/build/smb_build/output.pm +++ b/source4/build/smb_build/output.pm @@ -9,38 +9,6 @@ package output; use strict; use smb_build::config; -sub add_dir_str($$) -{ - my ($dir,$file) = @_; - my $dirsep = "/"; - - $dir =~ s/^\.$//g; - $dir =~ s/^\.\///g; - - $dirsep = "" if ($dir eq ""); - - my $ret = $file; - if (substr($ret, 0, 1) ne "\$") { - $ret = "$dir$dirsep$file"; - $ret =~ s/([^\/\.]+)\/\.\.\///g; - $ret =~ s/([^\/\.]+)\/\.\.\///g; - } - - return $ret; -} - -sub add_dir_array($$) -{ - my ($dir,$files) = @_; - my @ret = (); - - foreach (@{$files}) { - push (@ret, add_dir_str($dir, $_)); - } - - return @ret; -} - sub generate_shared_library($) { my $lib = shift; @@ -168,8 +136,15 @@ sub create_output($$) next unless(defined($part->{OUTPUT_TYPE})); # Combine object lists - my @list = add_dir_array($part->{BASEDIR}, $part->{OBJ_FILES}); - push(@{$part->{OBJ_LIST}}, @list) if defined($part->{OBJ_FILES}); + if (defined($part->{OBJ_FILES})) { + my $list; + + $list = join(" ", @{$part->{OBJ_FILES}}); + unless ($list =~ /^\.\//) { + $list = "\$(addprefix $part->{BASEDIR}/, $list)" + } + push(@{$part->{OBJ_LIST}}, $list); + } generate_binary($part) if grep(/BINARY/, @{$part->{OUTPUT_TYPE}}); generate_shared_library($part) if grep(/SHARED_LIBRARY/, @{$part->{OUTPUT_TYPE}}); |