Fix use of realpath, fix init functions for ldb.
[ira/wip.git] / source4 / build / smb_build / main.pl
1 # Samba Build System                                    
2 # - the main program                                    
3 #                                                       
4 #  Copyright (C) Stefan (metze) Metzmacher 2004 
5 #  Copyright (C) Jelmer Vernooij 2005
6 #  Released under the GNU GPL                           
7
8 use smb_build::makefile;
9 use smb_build::input;
10 use smb_build::config_mk;
11 use smb_build::output;
12 use smb_build::summary;
13 use smb_build::config;
14 use strict;
15
16 my $INPUT = {};
17 my $mkfile = smb_build::config_mk::run_config_mk($INPUT, $config::config{srcdir}, $config::config{builddir}, "main.mk");
18
19 my $subsys_output_type = ["MERGED_OBJ"];
20
21 my $library_output_type;
22 if ($config::config{USESHARED} eq "true") {
23         $library_output_type = ["SHARED_LIBRARY", "STATIC_LIBRARY"];
24 } else {
25         $library_output_type = ["STATIC_LIBRARY"];
26         push (@$library_output_type, "SHARED_LIBRARY") if 
27                                                 ($config::config{BLDSHARED} eq "true")
28 }
29
30 my $module_output_type;
31 if ($config::config{USESHARED} eq "true") {
32         $module_output_type = ["SHARED_LIBRARY"];
33 } else {
34         $module_output_type = ["MERGED_OBJ"];
35 }
36
37 my $DEPEND = smb_build::input::check($INPUT, \%config::enabled,
38                                      $subsys_output_type,
39                                      $library_output_type,
40                                      $module_output_type);
41 my $OUTPUT = output::create_output($DEPEND, \%config::config);
42 my $mkenv = new smb_build::makefile(\%config::config, $mkfile);
43
44 my $shared_libs_used = 0;
45 foreach my $key (values %$OUTPUT) {
46         $mkenv->_prepare_list($key, "OBJ_LIST");
47         push(@{$mkenv->{all_objs}}, "\$($key->{NAME}_OBJ_LIST)");
48 }
49
50 foreach my $key (values %$OUTPUT) {
51         next unless defined $key->{OUTPUT_TYPE};
52
53         $mkenv->StaticLibraryPrimitives($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
54         $mkenv->MergedObj($key) if grep(/MERGED_OBJ/, @{$key->{OUTPUT_TYPE}});
55         if (defined($key->{PC_FILE})) {
56                 $mkenv->output("PC_FILES += $key->{BASEDIR}/$key->{PC_FILE}\n");
57         } 
58         $mkenv->SharedLibraryPrimitives($key) if ($key->{TYPE} eq "LIBRARY") and
59                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
60         if ($key->{TYPE} eq "LIBRARY" and 
61             ${$key->{OUTPUT_TYPE}}[0] eq "SHARED_LIBRARY") {
62                 $shared_libs_used = 1;
63         }
64         $mkenv->SharedModulePrimitives($key) if ($key->{TYPE} eq "MODULE" or 
65                                                                    $key->{TYPE} eq "PYTHON") and
66                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
67         $mkenv->PythonFiles($key) if defined($key->{PYTHON_FILES});
68         $mkenv->Manpage($key) if defined($key->{MANPAGE});
69         $mkenv->Header($key) if defined($key->{PUBLIC_HEADERS});
70         if ($key->{TYPE} eq "MODULE" and $key->{OUTPUT_TYPE} eq "MERGED_OBJ" and defined($key->{INIT_FUNCTION})) {
71                 $mkenv->output("$key->{SUBSYSTEM}_INIT_FUNCTIONS += $key->{INIT_FUNCTION},\n");
72         }
73         $mkenv->CFlags($key);
74 }
75
76 foreach my $key (values %$OUTPUT) {
77         next unless defined $key->{OUTPUT_TYPE};
78
79         $mkenv->Integrated($key) if grep(/INTEGRATED/, @{$key->{OUTPUT_TYPE}});
80 }
81
82 foreach my $key (values %$OUTPUT) {
83         next unless defined $key->{OUTPUT_TYPE};
84
85         $mkenv->StaticLibrary($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
86         $mkenv->SharedLibrary($key) if ($key->{TYPE} eq "LIBRARY") and
87                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
88         $mkenv->SharedModule($key) if ($key->{TYPE} eq "MODULE" or 
89                                                                    $key->{TYPE} eq "PYTHON") and
90                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
91         $mkenv->Binary($key) if grep(/BINARY/, @{$key->{OUTPUT_TYPE}});
92         $mkenv->ProtoHeader($key) if defined($key->{PRIVATE_PROTO_HEADER}) or 
93                                          defined($key->{PUBLIC_PROTO_HEADER});
94         $mkenv->InitFunctions($key) if defined($key->{INIT_FUNCTIONS});
95 }
96
97 $mkenv->write("data.mk");
98
99 summary::show($OUTPUT, \%config::config);
100
101 1;