6d67eedf60c9a91940f3fcdd2e67b07ae2af65b5
[samba.git] / source / build / smb_build / smb_build_h.pm
1 ###########################################################
2 ### SMB Build System                                    ###
3 ### - create output for smb_build.h                     ###
4 ###                                                     ###
5 ###  Copyright (C) Stefan (metze) Metzmacher 2004       ###
6 ###  Released under the GNU GPL                         ###
7 ###########################################################
8
9 package smb_build_h;
10 use strict;
11
12 sub _add_define_section($)
13 {
14         my $DEFINE = shift;
15         my $output = "";
16
17         $output .= "
18 /* $DEFINE->{COMMENT} */
19 #define $DEFINE->{KEY} $DEFINE->{VAL}
20 ";
21
22         return $output;
23 }
24
25 sub _prepare_smb_build_h($)
26 {
27         my $depend = shift;
28         my @defines = ();
29
30         #
31         # loop over all binaries
32         #
33         foreach my $key (values %{$depend}) {
34                 next if ($key->{TYPE} ne "BINARY");
35
36                 my $NAME = $key->{NAME};
37                 my $DEFINE = ();
38                 my $name = lc($NAME);
39
40                 #
41                 # Static modules
42                 # 
43                 $DEFINE->{COMMENT} = "BINARY $NAME INIT";
44                 $DEFINE->{KEY} = $name . "_init_subsystems";
45                 $DEFINE->{VAL} = "do { \\\n";
46                 foreach my $subkey (@{$key->{SUBSYSTEM_INIT_FUNCTIONS}}) {
47                         $DEFINE->{VAL} .= "\t\textern NTSTATUS $subkey(void); \\\n";
48                 }
49         
50                 foreach my $subkey (@{$key->{SUBSYSTEM_INIT_FUNCTIONS}}) {
51                         $DEFINE->{VAL} .= "\t\tif (NT_STATUS_IS_ERR($subkey())) exit(1); \\\n";
52                 }
53                 $DEFINE->{VAL} .= "\t} while(0)";
54                 
55                 push(@defines,$DEFINE);
56         }
57
58         #
59         # Shared modules
60         #
61         foreach my $key (values %{$depend}) {
62                 next if $key->{TYPE} ne "MODULE";
63                 next if $key->{ENABLE} ne "YES";
64                 next if $key->{OUTPUT_TYPE} ne "SHARED_LIBRARY";
65
66                 my $name = $key->{NAME};
67                 my $func = $key->{INIT_FUNCTION};
68                 next if $func eq "";
69
70                 my $DEFINE = ();
71                 
72                 $DEFINE->{COMMENT} = "$name is built shared";
73                 $DEFINE->{KEY} = $func;
74                 $DEFINE->{VAL} = "init_module";
75
76                 push(@defines,$DEFINE);
77         }
78
79         #
80         # loop over all SMB_BUILD_H define sections
81         #
82         my $output = "";
83         foreach my $key (@defines) {
84                 $output .= _add_define_section($key);
85         }
86
87         return $output;
88 }
89
90 ###########################################################
91 # This function creates include/smb_build.h from the SMB_BUILD 
92 # context
93 #
94 # create_smb_build_h($SMB_BUILD_CTX)
95 #
96 # $SMB_BUILD_CTX -      the global SMB_BUILD context
97 #
98 # $output -             the resulting output buffer
99 sub create_smb_build_h($)
100 {
101         my $CTX = shift;
102         my $output = "/* autogenerated by config.smb_build.pl */\n";
103
104         $output .= _prepare_smb_build_h($CTX);
105
106         open(SMB_BUILD_H,"> include/smb_build.h") || die ("Can't open include/smb_build.h\n");
107
108         print SMB_BUILD_H $output;
109
110         close(SMB_BUILD_H);
111
112         print "config.smb_build.pl: creating include/smb_build.h\n";
113         return; 
114 }
115 1;