Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-test
[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 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 my $useshared = (defined($ENV{USESHARED})?$ENV{USESHARED}:$config::config{USESHARED});
35
36 if ($useshared eq "true") {
37         $library_output_type = ["SHARED_LIBRARY", "MERGED_OBJ"];
38 } else {
39         $library_output_type = ["MERGED_OBJ"];
40         push (@$library_output_type, "SHARED_LIBRARY") if 
41                                                 ($config::config{BLDSHARED} eq "true")
42 }
43
44 my $module_output_type;
45 if ($useshared eq "true") {
46         $module_output_type = ["SHARED_LIBRARY"];
47 } else {
48         $module_output_type = ["MERGED_OBJ"];
49 }
50
51 my $DEPEND = smb_build::input::check($INPUT, \%config::enabled,
52                                      $subsys_output_type,
53                                      $library_output_type,
54                                      $module_output_type);
55 my $OUTPUT = output::create_output($DEPEND, \%config::config);
56 my $mkenv = new smb_build::makefile(\%config::config, $mkfile);
57
58 my $shared_libs_used = 0;
59 foreach my $key (values %$OUTPUT) {
60         next if ($key->{ENABLE} ne "YES");
61         push(@{$mkenv->{all_objs}}, "\$($key->{NAME}_OBJ_FILES)");
62 }
63
64 foreach my $key (values %$OUTPUT) {
65         next unless defined $key->{OUTPUT_TYPE};
66
67         $mkenv->StaticLibraryPrimitives($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
68         $mkenv->MergedObj($key) if grep(/MERGED_OBJ/, @{$key->{OUTPUT_TYPE}});
69         $mkenv->SharedLibraryPrimitives($key) if ($key->{TYPE} eq "LIBRARY") and
70                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
71         if ($key->{TYPE} eq "LIBRARY" and 
72             ${$key->{OUTPUT_TYPE}}[0] eq "SHARED_LIBRARY") {
73                 $shared_libs_used = 1;
74         }
75         if ($key->{TYPE} eq "MODULE" and @{$key->{OUTPUT_TYPE}}[0] eq "MERGED_OBJ" and defined($key->{INIT_FUNCTION})) {
76                 $mkenv->output("$key->{SUBSYSTEM}_INIT_FUNCTIONS += $key->{INIT_FUNCTION},\n");
77         }
78         $mkenv->CFlags($key);
79 }
80
81 foreach my $key (values %$OUTPUT) {
82         next unless defined $key->{OUTPUT_TYPE};
83
84         $mkenv->Integrated($key) if grep(/INTEGRATED/, @{$key->{OUTPUT_TYPE}});
85 }
86
87 foreach my $key (values %$OUTPUT) {
88         next unless defined $key->{OUTPUT_TYPE};
89         $mkenv->StaticLibrary($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
90
91         $mkenv->SharedLibrary($key) if ($key->{TYPE} eq "LIBRARY") and
92                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
93         $mkenv->SharedModule($key) if ($key->{TYPE} eq "MODULE" and
94                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}}));
95         $mkenv->PythonModule($key) if ($key->{TYPE} eq "PYTHON");
96         $mkenv->Binary($key) if grep(/BINARY/, @{$key->{OUTPUT_TYPE}});
97         $mkenv->InitFunctions($key) if defined($key->{INIT_FUNCTIONS});
98 }
99
100 $mkenv->write($output_file);
101
102 summary::show($OUTPUT, \%config::config);
103
104 1;