Merge branch 'v4-0-trivial' 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::env;
13 use smb_build::cflags;
14 use smb_build::summary;
15 use smb_build::config;
16 use strict;
17
18 my $INPUT = {};
19 my $mkfile = smb_build::config_mk::run_config_mk($INPUT, $config::config{srcdir}, $config::config{builddir}, "main.mk");
20
21 my $subsys_output_type;
22 #$subsys_output_type = ["MERGED_OBJ"];
23 $subsys_output_type = ["STATIC_LIBRARY"];
24
25 my $library_output_type;
26 if ($config::config{USESHARED} eq "true") {
27         $library_output_type = ["SHARED_LIBRARY", "STATIC_LIBRARY"];
28 } else {
29         $library_output_type = ["STATIC_LIBRARY"];
30         push (@$library_output_type, "SHARED_LIBRARY") if 
31                                                 ($config::config{BLDSHARED} eq "true")
32 }
33
34 my $module_output_type;
35 if ($config::config{USESHARED} eq "true") {
36         $module_output_type = ["SHARED_LIBRARY"];
37 } else {
38         $module_output_type = ["INTEGRATED"];
39 }
40
41 my $DEPEND = smb_build::input::check($INPUT, \%config::enabled,
42                                      $subsys_output_type,
43                                      $library_output_type,
44                                      $module_output_type);
45 my $OUTPUT = output::create_output($DEPEND, \%config::config);
46 $config::config{SUBSYSTEM_OUTPUT_TYPE} = $subsys_output_type;
47 $config::config{LIBRARY_OUTPUT_TYPE} = $library_output_type;
48 $config::config{MODULE_OUTPUT_TYPE} = $module_output_type;
49 my $mkenv = new smb_build::makefile(\%config::config, $mkfile);
50
51 my $shared_libs_used = 0;
52
53 foreach my $key (values %$OUTPUT) {
54         next unless defined $key->{OUTPUT_TYPE};
55
56         $mkenv->StaticLibraryPrimitives($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
57         $mkenv->MergedObj($key) if grep(/MERGED_OBJ/, @{$key->{OUTPUT_TYPE}});
58         if (defined($key->{PC_FILE})) {
59                 $mkenv->output("PC_FILES += $key->{BASEDIR}/$key->{PC_FILE}\n");
60         } 
61         $mkenv->SharedLibraryPrimitives($key) if ($key->{TYPE} eq "LIBRARY") and
62                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
63         if ($key->{TYPE} eq "LIBRARY" and 
64             ${$key->{OUTPUT_TYPE}}[0] eq "SHARED_LIBRARY") {
65                 $shared_libs_used = 1;
66         }
67         $mkenv->SharedModulePrimitives($key) if ($key->{TYPE} eq "MODULE" or 
68                                                                    $key->{TYPE} eq "PYTHON") and
69                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
70         $mkenv->PythonFiles($key) if defined($key->{PYTHON_FILES});
71         $mkenv->Manpage($key) if defined($key->{MANPAGE});
72         $mkenv->Header($key) if defined($key->{PUBLIC_HEADERS});
73 }
74
75 foreach my $key (values %$OUTPUT) {
76         next unless defined $key->{OUTPUT_TYPE};
77
78         $mkenv->Integrated($key) if grep(/INTEGRATED/, @{$key->{OUTPUT_TYPE}});
79 }
80
81 foreach my $key (values %$OUTPUT) {
82         next unless defined $key->{OUTPUT_TYPE};
83
84         $mkenv->StaticLibrary($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
85         $mkenv->SharedLibrary($key) if ($key->{TYPE} eq "LIBRARY") and
86                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
87         $mkenv->SharedModule($key) if ($key->{TYPE} eq "MODULE" or 
88                                                                    $key->{TYPE} eq "PYTHON") and
89                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
90         $mkenv->Binary($key) if grep(/BINARY/, @{$key->{OUTPUT_TYPE}});
91         $mkenv->ProtoHeader($key) if defined($key->{PRIVATE_PROTO_HEADER}) or 
92                                          defined($key->{PUBLIC_PROTO_HEADER});
93         $mkenv->InitFunctions($key) if defined($key->{INIT_FUNCTIONS});
94 }
95
96 $mkenv->write("data.mk");
97
98 cflags::create_cflags($OUTPUT, $config::config{srcdir},
99                     $config::config{builddir}, "extra_cflags.txt");
100
101 summary::show($OUTPUT, \%config::config);
102
103 if ($shared_libs_used) {
104         print <<EOF;
105 To run binaries without installing, set the following environment variable:
106         $config::config{LIB_PATH_VAR}=$config::config{builddir}/bin/shared
107 EOF
108 }
109
110 1;