r11382: Require number of required M4 macros
[samba.git] / source4 / build / smb_build / main.pl
1 ###########################################################
2 ### SMB Build System                                    ###
3 ### - the main program                                  ###
4 ###                                                     ###
5 ###  Copyright (C) Stefan (metze) Metzmacher 2004       ###
6 ###  Copyright (C) Jelmer Vernooij 2005
7 ###  Released under the GNU GPL                         ###
8 ###########################################################
9
10 use smb_build::makefile;
11 use smb_build::smb_build_h;
12 use smb_build::input;
13 use smb_build::config_mk;
14 use smb_build::output;
15 use smb_build::dot;
16 use smb_build::env;
17 use config;
18 use strict;
19
20 my $INPUT = {};
21
22 my $mkfile = smb_build::config_mk::run_config_mk($INPUT, "main.mk");
23
24 if (defined($ENV{"SUBSYSTEM_OUTPUT_TYPE"})) {
25         $smb_build::input::subsystem_output_type = $ENV{SUBSYSTEM_OUTPUT_TYPE};
26 } elsif ($config::config{BLDMERGED} eq "true") {
27         $smb_build::input::subsystem_output_type = "MERGEDOBJ";
28 }
29
30 if (defined($ENV{"LIBRARY_OUTPUT_TYPE"})) {
31         $smb_build::input::library_output_type = $ENV{LIBRARY_OUTPUT_TYPE};
32 } elsif ($config::config{BLDSHARED} eq "true") {
33         #FIXME: This should eventually become SHARED_LIBRARY 
34         # rather then MERGEDOBJ once I'm certain it works ok -- jelmer
35         $smb_build::input::library_output_type = "MERGEDOBJ";
36 } elsif ($config::config{BLDMERGED} eq "true") {
37         $smb_build::input::library_output_type = "MERGEDOBJ";
38 }
39
40 if (defined($ENV{"MODULE_OUTPUT_TYPE"})) {
41         $smb_build::input::module_output_type = $ENV{MODULE_OUTPUT_TYPE};
42 } elsif ($config::config{BLDSHARED} eq "true") {
43         #FIXME: This should eventually become SHARED_LIBRARY 
44         # rather then MERGEDOBJ once I'm certain it works ok -- jelmer
45         $smb_build::input::module_output_type = "MERGEDOBJ";
46 } elsif ($config::config{BLDMERGED} eq "true") {
47         $smb_build::input::module_output_type = "MERGEDOBJ";
48 }
49
50 my $DEPEND = smb_build::input::check($INPUT, \%config::enabled);
51 my $OUTPUT = output::create_output($DEPEND);
52 my $mkenv = new smb_build::makefile(\%config::config, $mkfile);
53
54 foreach my $key (values %$OUTPUT) {
55         next unless defined $key->{OUTPUT_TYPE};
56
57         $mkenv->MergedObj($key) if $key->{OUTPUT_TYPE} eq "MERGEDOBJ";
58         $mkenv->ObjList($key) if $key->{OUTPUT_TYPE} eq "OBJLIST";
59         $mkenv->StaticLibrary($key) if $key->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
60         $mkenv->PkgConfig($key) if ($key->{OUTPUT_TYPE} eq "SHARED_LIBRARY") and
61                                                 defined($key->{MAJOR_VERSION});
62         $mkenv->SharedLibrary($key) if $key->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
63         $mkenv->Binary($key) if $key->{OUTPUT_TYPE} eq "BINARY";
64         $mkenv->Manpage($key) if defined($key->{MANPAGE});
65         $mkenv->Header($key) if defined($key->{PUBLIC_HEADERS});
66 }
67
68 # FIXME: These two lines are a hack
69 $mkenv->ProtoHeader($OUTPUT->{PROTO});
70 $mkenv->ProtoHeader($OUTPUT->{ALL_OBJS});
71
72 $mkenv->write("Makefile");
73 smb_build_h::create_smb_build_h($OUTPUT, "include/smb_build.h");
74
75 open DOTTY, ">samba4-deps.dot";
76 print DOTTY dot::generate($DEPEND);
77 close DOTTY;
78
79 1;