Fix build with partial linking.
[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::header;
10 use smb_build::input;
11 use smb_build::config_mk;
12 use smb_build::output;
13 use smb_build::env;
14 use smb_build::cflags;
15 use smb_build::summary;
16 use smb_build::config;
17 use strict;
18
19 my $INPUT = {};
20 my $mkfile = smb_build::config_mk::run_config_mk($INPUT, $config::config{srcdir}, $config::config{builddir}, "main.mk");
21
22 my $subsys_output_type;
23 $subsys_output_type = ["MERGED_OBJ"];
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 foreach my $key (values %$OUTPUT) {
52         next unless defined $key->{OUTPUT_TYPE};
53
54         $mkenv->Integrated($key) if grep(/INTEGRATED/, @{$key->{OUTPUT_TYPE}});
55 }
56
57 my $shared_libs_used = 0;
58
59 foreach my $key (values %$OUTPUT) {
60         next unless defined $key->{OUTPUT_TYPE};
61
62         $mkenv->MergedObj($key) if grep(/MERGED_OBJ/, @{$key->{OUTPUT_TYPE}});
63         $mkenv->StaticLibrary($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
64         if (defined($key->{PC_FILE})) {
65                 push(@{$mkenv->{pc_files}}, "$key->{BASEDIR}/$key->{PC_FILE}");
66         } 
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         $mkenv->SharedModulePrimitives($key) if ($key->{TYPE} eq "MODULE" or 
74                                                                    $key->{TYPE} eq "PYTHON") and
75                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
76         $mkenv->PythonFiles($key) if defined($key->{PYTHON_FILES});
77         $mkenv->Manpage($key) if defined($key->{MANPAGE});
78         $mkenv->Header($key) if defined($key->{PUBLIC_HEADERS});
79         $mkenv->ProtoHeader($key) if defined($key->{PRIVATE_PROTO_HEADER}) or 
80                                          defined($key->{PUBLIC_PROTO_HEADER});
81 }
82
83 foreach my $key (values %$OUTPUT) {
84         next unless defined $key->{OUTPUT_TYPE};
85
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 }
93
94 $mkenv->write("data.mk");
95 header::create_smb_build_h($OUTPUT, "include/build.h");
96
97 cflags::create_cflags($OUTPUT, $config::config{srcdir},
98                     $config::config{builddir}, "extra_cflags.txt");
99
100 summary::show($OUTPUT, \%config::config);
101
102 if ($shared_libs_used) {
103         print <<EOF;
104 To run binaries without installing, set the following environment variable:
105         $config::config{LIB_PATH_VAR}=$config::config{builddir}/bin/shared
106 EOF
107 }
108
109 1;