Use make to create lists of pc files and prototype headers.
[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 = ["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                 $mkenv->output("PC_FILES += $key->{BASEDIR}/$key->{PC_FILE}\n");
65         } 
66         $mkenv->SharedLibraryPrimitives($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->SharedModulePrimitives($key) if ($key->{TYPE} eq "MODULE" or 
73                                                                    $key->{TYPE} eq "PYTHON") and
74                                         grep(/SHARED_LIBRARY/, @{$key->{OUTPUT_TYPE}});
75         $mkenv->PythonFiles($key) if defined($key->{PYTHON_FILES});
76         $mkenv->Manpage($key) if defined($key->{MANPAGE});
77         $mkenv->Header($key) if defined($key->{PUBLIC_HEADERS});
78         $mkenv->ProtoHeader($key) if defined($key->{PRIVATE_PROTO_HEADER}) or 
79                                          defined($key->{PUBLIC_PROTO_HEADER});
80 }
81
82 foreach my $key (values %$OUTPUT) {
83         next unless defined $key->{OUTPUT_TYPE};
84
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 }
92
93 $mkenv->write("data.mk");
94 header::create_smb_build_h($OUTPUT, "include/build.h");
95
96 cflags::create_cflags($OUTPUT, $config::config{srcdir},
97                     $config::config{builddir}, "extra_cflags.txt");
98
99 summary::show($OUTPUT, \%config::config);
100
101 if ($shared_libs_used) {
102         print <<EOF;
103 To run binaries without installing, set the following environment variable:
104         $config::config{LIB_PATH_VAR}=$config::config{builddir}/bin/shared
105 EOF
106 }
107
108 1;