Avoid autogenerating the Makefile but rather include a data.mk file
[samba.git] / source / 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 = ["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 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->StaticLibrary($key) if grep(/STATIC_LIBRARY/, @{$key->{OUTPUT_TYPE}});
63         if (defined($key->{PC_FILE})) {
64                 push(@{$mkenv->{pc_files}}, "$key->{BASEDIR}/$key->{PC_FILE}");
65         } 
66         $mkenv->SharedLibrary($key) if ($key->{TYPE} eq "LIBRARY") and
67                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
68         if ($key->{TYPE} eq "LIBRARY" and 
69             ${$key->{OUTPUT_TYPE}}[0] eq "SHARED_LIBRARY") {
70                 $shared_libs_used = 1;
71         }
72         $mkenv->SharedModule($key) if ($key->{TYPE} eq "MODULE" or 
73                                                                    $key->{TYPE} eq "PYTHON") and
74                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
75         $mkenv->Binary($key) if grep(/BINARY/, @{$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 $mkenv->write("data.mk");
84 header::create_smb_build_h($OUTPUT, "include/build.h");
85
86 cflags::create_cflags($OUTPUT, $config::config{srcdir},
87                     $config::config{builddir}, "extra_cflags.txt");
88
89 summary::show($OUTPUT, \%config::config);
90
91 if ($shared_libs_used) {
92         print <<EOF;
93 To run binaries without installing, set the following environment variable:
94         $config::config{LIB_PATH_VAR}=$config::config{builddir}/bin/shared
95 EOF
96 }
97
98 1;