Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-gmake3
[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         push(@{$mkenv->{all_objs}}, "\$($key->{NAME}_OBJ_FILES)");
47 }
48
49 foreach my $key (values %$OUTPUT) {
50         next unless defined $key->{OUTPUT_TYPE};
51
52         $mkenv->StaticLibraryPrimitives($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
53         $mkenv->MergedObj($key) if grep(/MERGED_OBJ/, @{$key->{OUTPUT_TYPE}});
54         $kenv->SharedLibraryPrimitives($key) if ($key->{TYPE} eq "LIBRARY") and
55                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
56         if ($key->{TYPE} eq "LIBRARY" and 
57             ${$key->{OUTPUT_TYPE}}[0] eq "SHARED_LIBRARY") {
58                 $shared_libs_used = 1;
59         }
60         $mkenv->PythonFiles($key) if defined($key->{PYTHON_FILES});
61         if ($key->{TYPE} eq "MODULE" and @{$key->{OUTPUT_TYPE}}[0] eq "MERGED_OBJ" and defined($key->{INIT_FUNCTION})) {
62                 $mkenv->output("$key->{SUBSYSTEM}_INIT_FUNCTIONS += $key->{INIT_FUNCTION},\n");
63         }
64         $mkenv->CFlags($key);
65 }
66
67 foreach my $key (values %$OUTPUT) {
68         next unless defined $key->{OUTPUT_TYPE};
69
70         $mkenv->Integrated($key) if grep(/INTEGRATED/, @{$key->{OUTPUT_TYPE}});
71 }
72
73 foreach my $key (values %$OUTPUT) {
74         next unless defined $key->{OUTPUT_TYPE};
75         $mkenv->StaticLibrary($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
76
77         $mkenv->SharedLibrary($key) if ($key->{TYPE} eq "LIBRARY") and
78                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
79         $mkenv->SharedModule($key) if ($key->{TYPE} eq "MODULE" and
80                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}}));
81         $mkenv->PythonModule($key) if ($key->{TYPE} eq "PYTHON");
82         $mkenv->Binary($key) if grep(/BINARY/, @{$key->{OUTPUT_TYPE}});
83         $mkenv->ProtoHeader($key) if defined($key->{PRIVATE_PROTO_HEADER});
84         $mkenv->InitFunctions($key) if defined($key->{INIT_FUNCTIONS});
85 }
86
87 $mkenv->write("data.mk");
88
89 summary::show($OUTPUT, \%config::config);
90
91 1;