r14347: Add registration function to allow registering smbtorture test(suites)
[jelmer/samba4-debian.git] / source / build / smb_build / header.pm
1 # SMB Build System
2 # - create output for build.h
3 #
4 #  Copyright (C) Stefan (metze) Metzmacher 2004
5 #  Copyright (C) Jelmer Vernooij 2005
6 #  Released under the GNU GPL
7
8 package header;
9 use strict;
10
11 sub _add_define_section($)
12 {
13         my $DEFINE = shift;
14         my $output = "";
15
16         $output .= "
17 /* $DEFINE->{COMMENT} */
18 #define $DEFINE->{KEY} $DEFINE->{VAL}
19 ";
20
21         return $output;
22 }
23
24 sub _prepare_build_h($)
25 {
26         my $depend = shift;
27         my @defines = ();
28         my $output = "";
29
30         foreach my $key (values %{$depend}) {
31                 my $DEFINE = ();
32                 next if ($key->{TYPE} ne "LIBRARY" and 
33                                  $key->{TYPE} ne "SUBSYSTEM" and
34                                  $key->{TYPE} ne "BINARY");
35                 next unless defined($key->{INIT_FUNCTIONS});
36
37                 $DEFINE->{COMMENT} = "$key->{TYPE} $key->{NAME} INIT";
38                 $DEFINE->{KEY} = "STATIC_$key->{NAME}_MODULES";
39                 $DEFINE->{VAL} = "{ \\\n";
40                 foreach (@{$key->{INIT_FUNCTIONS}}) {
41                         $DEFINE->{VAL} .= "\t$_, \\\n";
42                         my $fn = $key->{INIT_FUNCTION_TYPE};
43                         unless(defined($fn)) { $fn = "NTSTATUS (*) (void)"; }
44                         $fn =~ s/\(\*\)/$_/;
45                         $output .= "$fn;\n";
46                 }
47
48                 $DEFINE->{VAL} .= "\tNULL \\\n }";
49
50                 push(@defines,$DEFINE);
51         }
52
53         #
54         # loop over all BUILD_H define sections
55         #
56         foreach (@defines) { $output .= _add_define_section($_); }
57
58         return $output;
59 }
60
61 ###########################################################
62 # This function creates include/build.h from the SMB_BUILD 
63 # context
64 #
65 # create_build_h($SMB_BUILD_CTX)
66 #
67 # $SMB_BUILD_CTX -      the global SMB_BUILD context
68 #
69 # $output -             the resulting output buffer
70 sub create_smb_build_h($$)
71 {
72         my ($CTX, $file) = @_;
73
74         open(BUILD_H,">$file") || die ("Can't open `$file'\n");
75         print BUILD_H "/* autogenerated by build/smb_build/main.pl */\n";
76         print BUILD_H _prepare_build_h($CTX);
77         close(BUILD_H);
78
79         print __FILE__.": creating $file\n";
80 }
81 1;