1
0
mirror of https://github.com/samba-team/samba.git synced 2025-10-29 04:23:51 +03:00
Files
samba-mirror/source/build/smb_build/smb_build_h.pm
Jelmer Vernooij b6d2ad4ce0 r12494: Support loading modules from .so files for most subsystems.
We now use a different system for initializing the modules for a subsystem.
Most subsystems now have an init function that looks something like this:

	init_module_fn static_init[] = STATIC_AUTH_MODULES;
	init_module_fn *shared_init = load_samba_modules(NULL, "auth");

	run_init_functions(static_init);
	run_init_functions(shared_init);

	talloc_free(shared_init);

I hope to eliminate the other init functions later on (the
init_programname_subsystems; defines).
2007-10-10 13:47:45 -05:00

129 lines
2.8 KiB
Perl

# SMB Build System
# - create output for smb_build.h
#
# Copyright (C) Stefan (metze) Metzmacher 2004
# Released under the GNU GPL
package smb_build_h;
use strict;
sub _add_define_section($)
{
my $DEFINE = shift;
my $output = "";
$output .= "
/* $DEFINE->{COMMENT} */
#define $DEFINE->{KEY} $DEFINE->{VAL}
";
return $output;
}
sub _prepare_smb_build_h($)
{
my $depend = shift;
my @defines = ();
my %declared = ();
my $output = "";
#
# loop over all binaries
#
foreach my $key (values %{$depend}) {
next if ($key->{TYPE} ne "BINARY");
my $NAME = $key->{NAME};
my $DEFINE = ();
my $name = lc($NAME);
#
# Static modules
#
$DEFINE->{COMMENT} = "BINARY $NAME INIT";
$DEFINE->{KEY} = $name . "_init_subsystems";
$DEFINE->{VAL} = "do { \\\n";
foreach my $subkey (@{$key->{SUBSYSTEM_INIT_FUNCTIONS}}) {
next if defined($declared{$subkey});
$output .= "NTSTATUS $subkey(void);\n";
$declared{$subkey} = 1;
}
foreach my $subkey (@{$key->{SUBSYSTEM_INIT_FUNCTIONS}}) {
$DEFINE->{VAL} .= "\t\tif (NT_STATUS_IS_ERR($subkey())) exit(1); \\\n";
}
$DEFINE->{VAL} .= "\t} while(0)";
push(@defines,$DEFINE);
}
foreach my $key (values %{$depend}) {
my $DEFINE = ();
next if ($key->{TYPE} ne "LIBRARY" and $key->{TYPE} ne "SUBSYSTEM");
next unless defined($key->{INIT_FUNCTIONS});
$DEFINE->{COMMENT} = "$key->{TYPE} $key->{NAME} INIT";
$DEFINE->{KEY} = "STATIC_$key->{NAME}_MODULES";
$DEFINE->{VAL} = "{ \\\n";
foreach (@{$key->{INIT_FUNCTIONS}}) {
$DEFINE->{VAL} .= "\t$_, \\\n";
$output .= "NTSTATUS $_(void);\n";
}
$DEFINE->{VAL} .= "\tNULL \\\n }";
push(@defines,$DEFINE);
}
#
# Shared modules
#
foreach my $key (values %{$depend}) {
next if $key->{TYPE} ne "MODULE";
next if $key->{ENABLE} ne "YES";
next if $key->{OUTPUT_TYPE} ne "SHARED_LIBRARY";
my $name = $key->{NAME};
next if not defined($key->{INIT_FUNCTION});
my $func = join(' ', @{$key->{INIT_FUNCTION}});
next if $func eq "";
my $DEFINE = ();
$DEFINE->{COMMENT} = "$name is built shared";
$DEFINE->{KEY} = $func;
$DEFINE->{VAL} = "init_module";
push(@defines,$DEFINE);
}
#
# loop over all SMB_BUILD_H define sections
#
foreach (@defines) { $output .= _add_define_section($_); }
return $output;
}
###########################################################
# This function creates include/smb_build.h from the SMB_BUILD
# context
#
# create_smb_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(SMB_BUILD_H,">$file") || die ("Can't open `$file'\n");
print SMB_BUILD_H "/* autogenerated by build/smb_build/main.pl */\n";
print SMB_BUILD_H _prepare_smb_build_h($CTX);
close(SMB_BUILD_H);
print __FILE__.": creating $file\n";
}
1;