1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

r11377: Add support for building LIBRARY elements as shared libraries:

- Adds -rpath bin/ so you don't have to install Samba in order to use compiled binaries.
 - Writes out pkg-config files when building shared libs
 - Supports automatic fallback to MERGEDOBJ (which is the default) or
   OBJ_LIST (if ld -r is not supported)

Building with shared libs reduces the size of the Samba binaries from
197 Mb to 60 Mb (including libraries) on my system (GCC4, with debugging).

To build with shared libraries support enabled, run:

LIBRARY_OUTPUT_TYPE=SHARED_LIBRARY ./config.status

init functions don't get called correctly yet when using shared libs, so
you won't be able to actually run anything with success :-)

Once init functions are done, I'll look at support for loading shared
modules once again.

Based on a patch by Peter Novodvorsky (nidd on IRC).
(This used to be commit 0b54405685)
This commit is contained in:
Jelmer Vernooij 2005-10-28 18:26:26 +00:00 committed by Gerald (Jerry) Carter
parent 17f8b87cb0
commit 93fd08168f
20 changed files with 137 additions and 66 deletions

View File

@ -34,7 +34,7 @@ SUBSYSTEM = AUTH
INIT_OBJ_FILES = \
auth_winbind.o
REQUIRED_SUBSYSTEMS = \
LIB_WINBIND_CLIENT \
LIBWINBIND_CLIENT \
NDR_NETLOGON LIBNDR
# End MODULE auth_winbind
#######################

View File

@ -1,6 +1,9 @@
#################################
# Start SUBSYSTEM GENSEC
[SUBSYSTEM::GENSEC]
[LIBRARY::GENSEC]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
INIT_FUNCTION = gensec_init
INIT_OBJ_FILES = gensec.o
REQUIRED_SUBSYSTEMS = \

View File

@ -26,7 +26,6 @@ my $section_types = {
"OBJ_FILES" => "list",
"REQUIRED_SUBSYSTEMS" => "list",
"TARGET_DEPS" => "list",
"ENABLE" => "bool",
"NOPROTO" => "bool",
@ -42,7 +41,6 @@ my $section_types = {
"OBJ_FILES" => "list",
"REQUIRED_SUBSYSTEMS" => "list",
"TARGET_DEPS" => "list",
"ENABLE" => "bool",
"NOPROTO" => "bool",
@ -53,7 +51,6 @@ my $section_types = {
"OBJ_FILES" => "list",
"REQUIRED_SUBSYSTEMS" => "list",
"TARGET_DEPS" => "list",
"ENABLE" => "bool",
"NOPROTO" => "bool",
@ -65,12 +62,15 @@ my $section_types = {
"MAJOR_VERSION" => "string",
"MINOR_VERSION" => "string",
"RELEASE_VERSION" => "string",
"INIT_FUNCTION" => "string",
"INIT_OBJ_FILES" => "list",
"ADD_OBJ_FILES" => "list",
"OBJ_FILES" => "list",
"DESCRIPTION" => "string",
"REQUIRED_SUBSYSTEMS" => "list",
"TARGET_DEPS" => "list",
"ENABLE" => "bool",
"NOPROTO" => "bool",

View File

@ -50,9 +50,9 @@ sub _set_config($$)
}
}
sub PkgConfig($$$$$$)
sub PkgConfig($$$$$$$)
{
my ($self,$path,$name,$libs,$cflags,$version) = @_;
my ($self,$path,$name,$libs,$cflags,$version,$desc) = @_;
print __FILE__.": creating $path\n";
@ -67,9 +67,12 @@ includedir=$self->{config}->{includedir}
__EOF__
print OUT "Name: $name\n";
if (defined($desc)) {
print OUT "Description: $desc\n";
}
print OUT "Version: $version\n";
print OUT "Libs: $libs\n";
print OUT "Cflags: $cflags\n";
print OUT "Libs: -L\${libdir} $libs\n";
print OUT "Cflags: -I\${includedir} $cflags\n";
close(OUT);
}

View File

@ -39,7 +39,7 @@ sub check_subsystem($$)
{
my ($INPUT, $subsys) = @_;
if ($subsys->{ENABLE} ne "YES") {
printf("Subsystem: %s disabled!\n",$subsys->{NAME});
printf("Subsystem `%s' disabled\n",$subsys->{NAME});
return;
}
@ -54,7 +54,6 @@ sub check_module($$)
die("Module $mod->{NAME} does not have a SUBSYSTEM set") if not defined($mod->{SUBSYSTEM});
($mod->{DEFAULT_BUILD} = "STATIC") if not defined($mod->{DEFAULT_BUILD});
my $use_default = 0;
@ -62,7 +61,6 @@ sub check_module($$)
if (!(defined($INPUT->{$mod->{SUBSYSTEM}}))) {
$mod->{BUILD} = "NOT";
$mod->{ENABLE} = "NO";
printf("Module: %s...PARENT SUBSYSTEM ($mod->{SUBSYSTEM}) DISABLED\n",$mod->{NAME});
return;
}
@ -85,15 +83,13 @@ sub check_module($$)
$mod->{OUTPUT_TYPE} = "SHARED_LIBRARY";
$mod->{INSTALLDIR} = "LIBDIR/$mod->{SUBSYSTEM}";
push (@{$mod->{REQUIRED_SUBSYSTEMS}}, $mod->{SUBSYSTEM});
printf("Module: %s...shared\n",$mod->{NAME});
} elsif ($mod->{CHOSEN_BUILD} eq "STATIC") {
$mod->{ENABLE} = "YES";
push (@{$INPUT->{$mod->{SUBSYSTEM}}{REQUIRED_SUBSYSTEMS}}, $mod->{NAME});
printf("Module: %s...static\n",$mod->{NAME});
$mod->{OUTPUT_TYPE} = $subsystem_output_type;
} else {
$mod->{ENABLE} = "NO";
printf("Module: %s...not\n",$mod->{NAME});
printf("Module `%s' disabled\n",$mod->{NAME});
return;
}
}
@ -103,12 +99,18 @@ sub check_library($$)
my ($INPUT, $lib) = @_;
if ($lib->{ENABLE} ne "YES") {
printf("Library: %s...disabled\n",$lib->{NAME});
printf("Library `%s' disabled\n",$lib->{NAME});
return;
}
$lib->{OUTPUT_TYPE} = $library_output_type;
unless (defined($lib->{MAJOR_VERSION})) {
print "$lib->{NAME}: Please specify MAJOR_VERSION\n";
return;
}
$lib->{INSTALLDIR} = "LIBDIR";
}
@ -117,7 +119,7 @@ sub check_binary($$)
my ($INPUT, $bin) = @_;
if ($bin->{ENABLE} ne "YES") {
printf("Binary: %s...disabled\n",$bin->{NAME});
printf("Binary `%s' disabled\n",$bin->{NAME});
return;
}
@ -133,8 +135,11 @@ sub calc_unique_deps($$)
foreach my $dep (@{$deps}) {
if (not defined($udeps->{$$dep->{NAME}})) {
$udeps->{$$dep->{NAME}} = "BUSY";
calc_unique_deps($$dep->{DEPENDENCIES}, $udeps);
if (defined ($$dep->{OUTPUT_TYPE}) && (($$dep->{OUTPUT_TYPE} eq "OBJ_LIST")
or ($$dep->{OUTPUT_TYPE} eq "MERGEDOBJ"))) {
$udeps->{$$dep->{NAME}} = "BUSY";
calc_unique_deps($$dep->{DEPENDENCIES}, $udeps);
}
$udeps->{$$dep->{NAME}} = $$dep;
}
}

View File

@ -30,7 +30,8 @@ if (defined($ENV{"SUBSYSTEM_OUTPUT_TYPE"})) {
if (defined($ENV{"LIBRARY_OUTPUT_TYPE"})) {
$smb_build::input::library_output_type = $ENV{LIBRARY_OUTPUT_TYPE};
} elsif ($config::config{BLDSHARED} eq "true") {
# FIXME: This should really be SHARED_LIBRARY
#FIXME: This should eventually become SHARED_LIBRARY
# rather then MERGEDOBJ once I'm certain it works ok -- jelmer
$smb_build::input::library_output_type = "MERGEDOBJ";
} elsif ($config::config{BLDMERGED} eq "true") {
$smb_build::input::library_output_type = "MERGEDOBJ";

View File

@ -91,6 +91,11 @@ sub _prepare_compiler_linker($)
{
my ($self) = @_;
my $devld = "";
if ($self->{developer}) {
$devld = " \$(DEVEL_LDFLAGS)";
}
$self->output(<< "__EOD__"
SHELL=$self->{config}->{SHELL}
@ -104,14 +109,15 @@ HOSTCC=$self->{config}->{HOSTCC}
CPP=$self->{config}->{CPP}
CPPFLAGS=$self->{config}->{CPPFLAGS}
LD=$self->{config}->{LD}
LD_FLAGS=$self->{config}->{LDFLAGS}
DEVEL_LDFLAGS=-Wl,-rpath,bin/
LD=$self->{config}->{LD}
LDFLAGS=$self->{config}->{LDFLAGS} -Lbin/$devld
STLD=$self->{config}->{AR}
STLD_FLAGS=-rc
STLD_FLAGS=-rc -Lbin/
SHLD=$self->{config}->{CC}
SHLD_FLAGS=$self->{config}->{LDSHFLAGS}
SHLD_FLAGS=$self->{config}->{LDSHFLAGS} -Lbin/$devld
SONAMEFLAG=$self->{config}->{SONAMEFLAG}
SHLIBEXT=$self->{config}->{SHLIBEXT}
@ -236,7 +242,7 @@ sub SharedLibrary($$)
{
my ($self,$ctx) = @_;
push (@{$self->{shared_libs}}, $ctx->{OUTPUT});
push (@{$self->{shared_libs}}, "bin/$ctx->{LIBRARY_NAME}");
$self->_prepare_obj_list($ctx->{TYPE}, $ctx);
$self->_prepare_cflags($ctx->{TYPE}, $ctx);
@ -374,7 +380,7 @@ BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
#
bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST) \$(BINARY_$ctx->{NAME}_OBJS)
\@echo Linking \$\@
\@\$(CC) \$(LD_FLAGS) -o \$\@ \\
\@\$(CC) \$(LDFLAGS) -o \$\@ \\
\$\(BINARY_$ctx->{NAME}_LINK_FLAGS) \\
\$\(BINARY_$ctx->{NAME}_LINK_LIST) \\
\$\(BINARY_$ctx->{NAME}_LINK_FLAGS)
@ -399,11 +405,23 @@ sub PkgConfig($$)
{
my ($self,$ctx) = @_;
my $path = "$ctx->{BASEDIR}/$ctx->{NAME}.pc";
my $link_name = $ctx->{NAME};
$link_name =~ s/^LIB//g;
$link_name = lc($link_name);
my $path = "$ctx->{BASEDIR}/$link_name.pc";
push (@{$self->{pc_files}}, $path);
smb_build::env::PkgConfig($self,$path,$ctx->{NAME},"FIXME",join(' ', @{$ctx->{CFLAGS}}), "$ctx->{MAJOR_VERSION}.$ctx->{MINOR_VERSION}.$ctx->{RELEASE_VERSION}");
smb_build::env::PkgConfig($self,
$path,
$link_name,
$ctx->{OUTPUT},
join(' ', @{$ctx->{CFLAGS}}),
"$ctx->{MAJOR_VERSION}.$ctx->{MINOR_VERSION}.$ctx->{RELEASE_VERSION}",
$ctx->{DESCRIPTION}
);
}
sub ProtoHeader($$)

View File

@ -44,32 +44,42 @@ sub generate_objlist($)
sub generate_shared_library($)
{
my $lib = shift;
my $link_name;
@{$lib->{DEPEND_LIST}} = ();
@{$lib->{LINK_LIST}} = ("\$($lib->{TYPE}_$lib->{NAME}\_OBJS)");
$lib->{LIBRARY_NAME} = lc($lib->{NAME}).".so";
$lib->{TARGET} = "bin/lib$lib->{LIBRARY_NAME}";
$link_name = $lib->{NAME};
$link_name =~ s/^LIB//;
$link_name = lc($link_name);
$lib->{LIBRARY_NAME} = "lib$link_name.\$(SHLIBEXT)";
$lib->{TARGET} = "bin/$lib->{LIBRARY_NAME}";
if (defined($lib->{MAJOR_VERSION})) {
$lib->{LIBRARY_SONAME} = $lib->{LIBRARY_NAME}.".$lib->{MAJOR_VERSION}";
$lib->{LIBRARY_REALNAME} = $lib->{LIBRARY_SONAME}.".$lib->{MINOR_VERSION}.$lib->{RELEASE_VERSION}";
$lib->{TARGET} = "bin/lib$lib->{LIBRARY_REALNAME}";
$lib->{TARGET} = "bin/$lib->{LIBRARY_REALNAME}";
@{$lib->{LINK_FLAGS}} = ("\$(SONAMEFLAG)$lib->{LIBRARY_SONAME}");
}
$lib->{OUTPUT} = "-l".lc($lib->{NAME});
$lib->{OUTPUT} = "-l$link_name";
}
sub generate_static_library($)
{
my $lib = shift;
my $link_name;
@{$lib->{DEPEND_LIST}} = ();
$lib->{LIBRARY_NAME} = lc($lib->{NAME}).".a";
$link_name = $lib->{NAME};
$link_name =~ s/^LIB//;
$lib->{LIBRARY_NAME} = "lib".lc($link_name).".a";
@{$lib->{LINK_LIST}} = ("\$($lib->{TYPE}_$lib->{NAME}\_OBJS)");
@{$lib->{LINK_FLAGS}} = ();
$lib->{TARGET} = "bin/lib$lib->{LIBRARY_NAME}";
$lib->{OUTPUT} = "-l".lc($lib->{NAME});
$lib->{TARGET} = "bin/$lib->{LIBRARY_NAME}";
$lib->{OUTPUT} = "-l".lc($link_name);
}
sub generate_binary($)
@ -145,8 +155,11 @@ sub create_output($)
push(@{$part->{LINK_LIST}}, $elem->{OUTPUT}) if defined($elem->{OUTPUT});
push(@{$part->{LINK_FLAGS}}, @{$elem->{LIBS}}) if defined($elem->{LIBS});
push(@{$part->{LINK_FLAGS}},@{$elem->{LDFLAGS}}) if defined($elem->{LDFLAGS});
push(@{$part->{DEPEND_LIST}}, $elem->{TARGET}) if defined($elem->{TARGET});
if (defined($elem->{OUTPUT_TYPE}) and ($elem->{OUTPUT_TYPE} eq "SHARED_LIBRARY")) {
push(@{$part->{DEPEND_LIST}}, "bin/$elem->{LIBRARY_NAME}");
} else {
push(@{$part->{DEPEND_LIST}}, $elem->{TARGET}) if defined($elem->{TARGET});
}
push(@{$part->{SUBSYSTEM_INIT_FUNCTIONS}}, $elem->{INIT_FUNCTION}) if
$part->{OUTPUT_TYPE} eq "BINARY" and
defined($elem->{INIT_FUNCTION}) and

View File

@ -23,8 +23,6 @@
#define __GTK_SMB_H__
#ifdef HAVE_GTK
#define GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
@ -59,8 +57,6 @@ struct _GtkRpcBindingDialogClass
#define GTK_RPC_BINDING_DIALOG_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_rpc_binding_dialog_class_get_type (), GtkRpcBindingDialogClass)
#define IS_GTK_RPC_BINDING_DIALOG(obj) GTK_CHECK_TYPE (obj, gtk_rpc_binding_dialog_get_type ())
#endif
/* subsystem prototypes */
GtkWidget *create_gtk_samba_about_dialog (const char *appname);
void gtk_show_ntstatus(GtkWidget *win, const char *, NTSTATUS status);

View File

@ -2,7 +2,10 @@
##############################
# Start SUBSYSTEM GTKSMB
[SUBSYSTEM::GTKSMB]
[LIBRARY::GTKSMB]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
NOPROTO = YES
INIT_OBJ_FILES = common/gtk-smb.o
ADD_OBJ_FILES = common/select.o \

View File

@ -447,7 +447,7 @@ heimdal_clean: hdb_asn1_clean spnego_asn1_clean krb5_asn1_clean
#######################
# Start SUBSYSTEM HEIMDAL
[SUBSYSTEM::HEIMDAL]
[LIBRARY::HEIMDAL]
NOPROTO = YES
REQUIRED_SUBSYSTEMS = \
HEIMDAL_GSSAPI HEIMDAL_KRB5 \

View File

@ -26,7 +26,10 @@ ADD_OBJ_FILES = \
# End SUBSYSTEM LIBNETIF
##############################
[SUBSYSTEM::TDR]
[LIBRARY::TDR]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
INIT_OBJ_FILES = tdr/tdr.o
##############################

View File

@ -1,16 +1,11 @@
################################################
# Start SUBSYSTEM LIBSAMBA3
[SUBSYSTEM::LIBSAMBA3]
ADD_OBJ_FILES = \
smbpasswd.o \
tdbsam.o \
policy.o \
idmap.o \
winsdb.o \
samba3.o \
group.o \
registry.o \
secrets.o \
share_info.o
[LIBRARY::LIBSAMBA3]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
ADD_OBJ_FILES = smbpasswd.o tdbsam.o policy.o \
idmap.o winsdb.o samba3.o group.o \
registry.o secrets.o share_info.o
# End SUBSYSTEM LIBSAMBA3
################################################

View File

@ -1,7 +1,11 @@
##############################
# Start SUBSYSTEM SOCKET_WRAPPER
[SUBSYSTEM::SOCKET_WRAPPER]
[LIBRARY::SOCKET_WRAPPER]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
NOPROTO = YES
PUBLIC_HEADERS = socket_wrapper.h
INIT_OBJ_FILES = socket_wrapper.o
# End SUBSYSTEM SOCKET_WRAPPER
##############################

View File

@ -9,6 +9,7 @@ REQUIRED_SUBSYSTEMS = LIBREPLACE
NOPROTO = YES
MANPAGE = talloc.3
PUBLIC_HEADERS = talloc.h
DESCRIPTION = A hierarchical pool based memory system with destructors
#
# End LIBRARY LIBTALLOC
################################################

View File

@ -30,7 +30,10 @@ ADD_OBJ_FILES = \
smb_composite/fsinfo.o
REQUIRED_SUBSYSTEMS = LIBCLI_COMPOSITE
[SUBSYSTEM::LIBCLI_NBT]
[LIBRARY::LIBCLI_NBT]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
ADD_OBJ_FILES = \
nbt/nbtname.o \
nbt/nbtsocket.o \
@ -51,13 +54,19 @@ ADD_OBJ_FILES = \
NOPROTO=YES
REQUIRED_SUBSYSTEMS = LIBCLI_NBT
[SUBSYSTEM::LIBCLI_CLDAP]
[LIBRARY::LIBCLI_CLDAP]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
ADD_OBJ_FILES = \
cldap/cldap.o
NOPROTO=YES
REQUIRED_SUBSYSTEMS = LIBCLI_LDAP
[SUBSYSTEM::LIBCLI_WREPL]
[LIBRARY::LIBCLI_WREPL]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
ADD_OBJ_FILES = \
wrepl/winsrepl.o
REQUIRED_SUBSYSTEMS = NDR_WINSREPL SOCKET LIBEVENTS
@ -71,7 +80,10 @@ ADD_OBJ_FILES = \
resolve/host.o
REQUIRED_SUBSYSTEMS = LIBCLI_NBT
[SUBSYSTEM::LIBCLI]
[LIBRARY::LIBCLI]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
REQUIRED_SUBSYSTEMS = LIBCLI_RAW LIBCLI_UTILS LIBCLI_AUTH \
LIBCLI_SMB_COMPOSITE LIBCLI_NBT LIB_SECURITY LIBCLI_RESOLVE \
LIBCLI_DGRAM

View File

@ -1,6 +1,9 @@
#################################
# Start SUBSYSTEM LIBNET
[SUBSYSTEM::LIBNET]
[LIBRARY::LIBNET]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
INIT_OBJ_FILES = \
libnet.o
ADD_OBJ_FILES = \

View File

@ -1,6 +1,9 @@
################################################
# Start SUBSYSTEM LIBNDR
[LIBRARY::LIBNDR]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
PUBLIC_HEADERS = ndr/libndr.h
INIT_OBJ_FILES = \
ndr/ndr.o
@ -548,6 +551,9 @@ NOPROTO = YES
################################################
# Start SUBSYSTEM LIBRPC
[LIBRARY::LIBRPC]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
PUBLIC_HEADERS = rpc/dcerpc.h
REQUIRED_SUBSYSTEMS = LIBNDR RPC_RAW LIBSMB NDR_MISC NDR_DCERPC NDR_SCHANNEL NDR_LSA NDR_NETLOGON NDR_SAMR NDR_UNIXINFO RPC_NDR_NETLOGON RPC_NDR_EPMAPPER
# End SUBSYSTEM LIBRPC

View File

@ -185,6 +185,8 @@ clean: heimdal_clean
@-find . -name '*.o' -exec rm -f '{}' \;
@echo Removing binaries
@-rm -f $(BIN_PROGS) $(SBIN_PROGS)
@echo Removing libraries
@-rm -f bin/*.$(SHLIBEXT).*
@echo Removing dummy targets
@-rm -f bin/.*_*
@echo Removing generated files

View File

@ -1,7 +1,10 @@
#################################
# Start SUBSYSTEM LIB_WINBIND_CLIENT
[SUBSYSTEM::LIB_WINBIND_CLIENT]
# Start SUBSYSTEM LIBWINBIND_CLIENT
[LIBRARY::LIBWINBIND_CLIENT]
MAJOR_VERSION = 0
MINOR_VERSION = 0
RELEASE_VERSION = 1
ADD_OBJ_FILES = wb_common.o
NOPROTO=YES
# End SUBSYSTEM LIB_WINBIND_CLIENT
# End SUBSYSTEM LIBWINBIND_CLIENT
#################################