Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into 4-0-abartlet
[kai/samba.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 Getopt::Long;
15 use strict;
16
17 my $output_file = "data.mk";
18
19 my $result = GetOptions (
20         'output=s' => \$output_file);
21
22 if (not $result) {
23         exit(1);
24 }
25
26 my $input_file = shift @ARGV;
27
28 my $INPUT = {};
29 my $mkfile = smb_build::config_mk::run_config_mk($INPUT, $config::config{srcdir}, $config::config{builddir}, $input_file);
30
31 my $subsys_output_type = ["MERGED_OBJ"];
32
33 my $library_output_type;
34 if ($config::config{USESHARED} eq "true") {
35         $library_output_type = ["SHARED_LIBRARY", "MERGED_OBJ"];
36 } else {
37         $library_output_type = ["MERGED_OBJ"];
38         push (@$library_output_type, "SHARED_LIBRARY") if 
39                                                 ($config::config{BLDSHARED} eq "true")
40 }
41
42 my $module_output_type;
43 if ($config::config{USESHARED} eq "true") {
44         $module_output_type = ["SHARED_LIBRARY"];
45 } else {
46         $module_output_type = ["MERGED_OBJ"];
47 }
48
49 my $DEPEND = smb_build::input::check($INPUT, \%config::enabled,
50                                      $subsys_output_type,
51                                      $library_output_type,
52                                      $module_output_type);
53 my $OUTPUT = output::create_output($DEPEND, \%config::config);
54 my $mkenv = new smb_build::makefile(\%config::config, $mkfile);
55
56 my $shared_libs_used = 0;
57 foreach my $key (values %$OUTPUT) {
58         next if ($key->{ENABLE} ne "YES");
59         push(@{$mkenv->{all_objs}}, "\$($key->{NAME}_OBJ_FILES)");
60 }
61
62 foreach my $key (values %$OUTPUT) {
63         next unless defined $key->{OUTPUT_TYPE};
64
65         $mkenv->StaticLibraryPrimitives($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
66         $mkenv->MergedObj($key) if grep(/MERGED_OBJ/, @{$key->{OUTPUT_TYPE}});
67         $mkenv->SharedLibraryPrimitives($key) if ($key->{TYPE} eq "LIBRARY") and
68                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
69         if ($key->{TYPE} eq "LIBRARY" and 
70             ${$key->{OUTPUT_TYPE}}[0] eq "SHARED_LIBRARY") {
71                 $shared_libs_used = 1;
72         }
73         if ($key->{TYPE} eq "MODULE" and @{$key->{OUTPUT_TYPE}}[0] eq "MERGED_OBJ" and defined($key->{INIT_FUNCTION})) {
74                 $mkenv->output("$key->{SUBSYSTEM}_INIT_FUNCTIONS += $key->{INIT_FUNCTION},\n");
75         }
76         $mkenv->CFlags($key);
77 }
78
79 foreach my $key (values %$OUTPUT) {
80         next unless defined $key->{OUTPUT_TYPE};
81
82         $mkenv->Integrated($key) if grep(/INTEGRATED/, @{$key->{OUTPUT_TYPE}});
83 }
84
85 foreach my $key (values %$OUTPUT) {
86         next unless defined $key->{OUTPUT_TYPE};
87         $mkenv->StaticLibrary($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
88
89         $mkenv->SharedLibrary($key) if ($key->{TYPE} eq "LIBRARY") and
90                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
91         $mkenv->SharedModule($key) if ($key->{TYPE} eq "MODULE" and
92                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}}));
93         $mkenv->PythonModule($key) if ($key->{TYPE} eq "PYTHON");
94         $mkenv->Binary($key) if grep(/BINARY/, @{$key->{OUTPUT_TYPE}});
95         $mkenv->InitFunctions($key) if defined($key->{INIT_FUNCTIONS});
96 }
97
98 $mkenv->write($output_file);
99
100 summary::show($OUTPUT, \%config::config);
101
102 1;