r6839: Add support for building subsystems as shared libraries. This can be
[samba.git] / source / build / smb_build / output.pm
1 ###########################################################
2 ### SMB Build System                                    ###
3 ### - the output generating functions                   ###
4 ###                                                     ###
5 ###  Copyright (C) Stefan (metze) Metzmacher 2004       ###
6 ###  Copyright (C) Jelmer Vernooij 2004 ###
7 ###  Released under the GNU GPL                         ###
8 ###########################################################
9
10 package output;
11 use strict;
12
13 sub generate_objlist($)
14 {
15         my $subsys = shift;
16
17         $subsys->{TARGET} = $subsys->{OUTPUT} = "\$($subsys->{TYPE}_$subsys->{NAME}_OBJS)";
18 }
19
20 sub generate_shared_library($)
21 {
22         my $lib = shift;
23
24         @{$lib->{DEPEND_LIST}} = ("\$($lib->{TYPE}_$lib->{NAME}\_OBJS)");
25         @{$lib->{LINK_LIST}} = ("\$($lib->{TYPE}_$lib->{NAME}\_OBJS)");
26         $lib->{LIBRARY_NAME} = lc($lib->{NAME}).".so";
27         $lib->{TARGET} = "bin/lib$lib->{LIBRARY_NAME}";
28         if (defined($lib->{MAJOR_VERSION})) {
29                 $lib->{LIBRARY_SONAME} = $lib->{LIBRARY_NAME}.".$lib->{MAJOR_VERSION}";
30                 $lib->{LIBRARY_REALNAME} = $lib->{LIBRARY_SONAME}.".$lib->{MINOR_VERSION}.$lib->{RELEASE_VERSION}";
31                 $lib->{TARGET} = "bin/lib$lib->{LIBRARY_REALNAME}";
32                 @{$lib->{LINK_FLAGS}} = ("\@SONAMEFLAG\@$lib->{LIBRARY_SONAME}");
33         }
34         $lib->{OUTPUT} = "-l".lc($lib->{NAME});
35 }
36
37 sub generate_static_library($)
38 {
39         my $lib = shift;
40
41         @{$lib->{DEPEND_LIST}} = ("\$($lib->{TYPE}_$lib->{NAME}\_OBJS)");
42
43         $lib->{LIBRARY_NAME} = lc($lib->{NAME}).".a";
44         @{$lib->{LINK_LIST}} = ("\$($lib->{TYPE}_$lib->{NAME}\_OBJS)");
45         @{$lib->{LINK_FLAGS}} = ();
46
47         $lib->{TARGET} = "bin/lib$lib->{LIBRARY_NAME}";
48         $lib->{OUTPUT} = "-l".lc($lib->{NAME});
49 }
50
51 sub generate_binary($)
52 {
53         my $bin = shift;
54
55         @{$bin->{DEPEND_LIST}} = ("\$($bin->{TYPE}_$bin->{NAME}\_OBJS)");
56         @{$bin->{LINK_LIST}} = ("\$($bin->{TYPE}_$bin->{NAME}\_OBJS)");
57         @{$bin->{LINK_FLAGS}} = ();
58
59         $bin->{TARGET} = $bin->{OUTPUT} = "bin/$bin->{NAME}";
60         $bin->{BINARY} = $bin->{NAME};
61 }
62
63 sub create_output($)
64 {
65         my $depend = shift;
66         my %output = ();
67         my $part;
68
69         $depend->{PROTO}{OUTPUT_TYPE} = "OBJLIST";
70         $depend->{PROTO}{TYPE} = "PROTO";
71         $depend->{PROTO}{NAME} = "PROTO";
72         
73         foreach $part (values %{$depend}) {
74                 next if not defined($part->{OUTPUT_TYPE});
75
76                 generate_binary($part) if $part->{OUTPUT_TYPE} eq "BINARY";
77                 generate_objlist($part) if $part->{OUTPUT_TYPE} eq "OBJLIST";
78                 generate_shared_library($part) if $part->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
79                 generate_static_library($part) if $part->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
80
81                 # Combine object lists
82                 push(@{$part->{OBJ_LIST}}, @{$part->{INIT_OBJ_FILES}}) if defined($part->{INIT_OBJ_FILES});
83                 push(@{$part->{OBJ_LIST}}, @{$part->{ADD_OBJ_FILES}}) if defined($part->{ADD_OBJ_FILES});
84                 push(@{$part->{OBJ_LIST}}, @{$part->{OBJ_FILES}}) if defined($part->{OBJ_FILES});
85
86                 push(@{$depend->{PROTO}{OBJ_LIST}}, @{$part->{OBJ_LIST}}) if ((not defined ($part->{NOPROTO}) or $part->{NOPROTO} eq "NO") and defined(@{$part->{OBJ_LIST}}));
87         }
88
89         foreach $part (values %{$depend}) {
90                 next if not defined($part->{OUTPUT_TYPE});
91
92                 # Always import the CFLAGS and CPPFLAGS of the unique dependencies
93                 foreach my $elem (values %{$part->{UNIQUE_DEPENDENCIES}}) {
94                         next if $elem == $part;
95
96                         push(@{$part->{CPPFLAGS}}, @{$elem->{CPPFLAGS}}) if defined(@{$elem->{CPPFLAGS}});
97                         push(@{$part->{CFLAGS}}, @{$elem->{CFLAGS}}) if defined(@{$elem->{CFLAGS}});
98                         push(@{$part->{DEPEND_LIST}}, $elem->{TARGET}) if defined($elem->{TARGET});
99                         push(@{$part->{LINK_LIST}}, $elem->{OUTPUT}) if defined($elem->{OUTPUT});
100                         push(@{$part->{LINK_FLAGS}}, @{$elem->{LIBS}}) if defined($elem->{LIBS});
101                         push(@{$part->{LINK_FLAGS}},@{$elem->{LDFLAGS}}) if defined($elem->{LDFLAGS});
102
103                         push(@{$part->{SUBSYSTEM_INIT_FUNCTIONS}}, @{$elem->{INIT_FUNCTION}}) if 
104                                 $part->{OUTPUT_TYPE} eq "BINARY" and 
105                                 defined($elem->{INIT_FUNCTION}) and 
106                                 $elem->{INIT_FUNCTION} ne "" and
107                                 $part->{OUTPUT_TYPE} ne "SHARED_LIBRARY";
108                 }
109         }
110
111         return %{$depend};
112 }
113
114 1;