Merge branch 'v4-0-test' of git://git.samba.org/samba into 4-0-local
[kai/samba.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 "MODULE" and
34                                  $key->{TYPE} ne "SUBSYSTEM" and
35                                  $key->{TYPE} ne "BINARY");
36                 next unless defined($key->{INIT_FUNCTIONS});
37
38                 my $name = $key->{NAME};
39                 $name =~ s/-/_/g;
40                 $DEFINE->{COMMENT} = "$key->{TYPE} $key->{NAME} INIT";
41                 $DEFINE->{KEY} = "STATIC_$name\_MODULES";
42                 $DEFINE->{VAL} = "\\\n";
43                 foreach (@{$key->{INIT_FUNCTIONS}}) {
44                         $DEFINE->{VAL} .= "\t$_, \\\n";
45                         unless (/{/) {
46                                 my $fn = $key->{INIT_FUNCTION_TYPE};
47                                 my $n = $_;
48                                 if ($fn =~ /\(\*\)/) {
49                                         $fn =~ s/\(\*\)/$n/;
50                                         $output .= "$fn;\n";
51                                 } else {
52                                         $n =~ s/\&//;
53                                         $output .= "$fn $n;\n";
54                                 }
55                         }
56                 }
57
58                 $DEFINE->{VAL} .= "\t$key->{INIT_FUNCTION_SENTINEL} \n";
59
60                 push(@defines,$DEFINE);
61         }
62
63         #
64         # loop over all BUILD_H define sections
65         #
66         foreach (@defines) { $output .= _add_define_section($_); }
67
68         return $output;
69 }
70
71 ###########################################################
72 # This function creates include/build.h from the SMB_BUILD 
73 # context
74 #
75 # create_build_h($SMB_BUILD_CTX)
76 #
77 # $SMB_BUILD_CTX -      the global SMB_BUILD context
78 #
79 # $output -             the resulting output buffer
80 sub create_smb_build_h($$)
81 {
82         my ($CTX, $file) = @_;
83
84         open(BUILD_H,">$file") || die ("Can't open `$file'\n");
85         print BUILD_H "/* autogenerated by build/smb_build/main.pl */\n";
86         print BUILD_H _prepare_build_h($CTX);
87         close(BUILD_H);
88
89         print __FILE__.": creating $file\n";
90 }
91
92 1;