d2ee5a9165b66d9435951e08d4adea9bd78ed8d7
[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->{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} = $lib->{NAME}.".so";
27         $lib->{OUTPUT} = "bin/$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->{OUTPUT} = "bin/$lib->{LIBRARY_REALNAME}";
32                 @{$lib->{LINK_FLAGS}} = ("\@SONAMEFLAG\@$lib->{LIBRARY_SONAME}");
33         }
34 }
35
36 sub generate_static_library($)
37 {
38         my $lib = shift;
39
40         @{$lib->{DEPEND_LIST}} = ("\$($lib->{TYPE}_$lib->{NAME}\_OBJS)");
41
42         $lib->{LIBRARY_NAME} = $lib->{NAME}.".a";
43         @{$lib->{LINK_LIST}} = ("\$($lib->{TYPE}_$lib->{NAME}\_OBJS)");
44         @{$lib->{LINK_FLAGS}} = ();
45
46         $lib->{OUTPUT} = "bin/$lib->{LIBRARY_NAME}";
47 }
48
49 sub generate_binary($)
50 {
51         my $bin = shift;
52
53         @{$bin->{DEPEND_LIST}} = ("\$($bin->{TYPE}_$bin->{NAME}\_OBJS)");
54         @{$bin->{LINK_LIST}} = ("\$($bin->{TYPE}_$bin->{NAME}\_OBJS)");
55         @{$bin->{LINK_FLAGS}} = ();
56
57         $bin->{OUTPUT} = "bin/$bin->{NAME}";
58         $bin->{BINARY} = $bin->{NAME};
59 }
60
61 sub create_output($)
62 {
63         my $depend = shift;
64         my %output = ();
65         my $part;
66
67         $depend->{PROTO}{OUTPUT_TYPE} = "OBJLIST";
68         $depend->{PROTO}{TYPE} = "PROTO";
69         $depend->{PROTO}{NAME} = "PROTO";
70         
71         foreach $part (values %{$depend}) {
72                 next if not defined($part->{OUTPUT_TYPE});
73
74                 generate_binary($part) if $part->{OUTPUT_TYPE} eq "BINARY";
75                 generate_objlist($part) if $part->{OUTPUT_TYPE} eq "OBJLIST";
76                 generate_shared_library($part) if $part->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
77                 generate_static_library($part) if $part->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
78
79                 # Combine object lists
80                 push(@{$part->{OBJ_LIST}}, @{$part->{INIT_OBJ_FILES}}) if defined($part->{INIT_OBJ_FILES});
81                 push(@{$part->{OBJ_LIST}}, @{$part->{ADD_OBJ_FILES}}) if defined($part->{ADD_OBJ_FILES});
82                 push(@{$part->{OBJ_LIST}}, @{$part->{OBJ_FILES}}) if defined($part->{OBJ_FILES});
83
84                 push(@{$depend->{PROTO}{OBJ_LIST}}, @{$part->{OBJ_LIST}}) if ((not defined ($part->{NOPROTO}) or $part->{NOPROTO} eq "NO") and defined(@{$part->{OBJ_LIST}}));
85         }
86
87         foreach $part (values %{$depend}) {
88                 next if not defined($part->{OUTPUT_TYPE});
89
90                 # Always import the CFLAGS and CPPFLAGS of the unique dependencies
91                 foreach my $elem (values %{$part->{UNIQUE_DEPENDENCIES}}) {
92                         next if $elem == $part;
93
94                         push(@{$part->{CPPFLAGS}}, @{$elem->{CPPFLAGS}}) if defined(@{$elem->{CPPFLAGS}});
95                         push(@{$part->{CFLAGS}}, @{$elem->{CFLAGS}}) if defined(@{$elem->{CFLAGS}});
96                         push(@{$part->{DEPEND_LIST}}, $elem->{OUTPUT}) if defined($elem->{OUTPUT});
97                         push(@{$part->{LINK_LIST}}, $elem->{OUTPUT}) if defined($elem->{OUTPUT});
98                         push(@{$part->{LINK_FLAGS}}, @{$elem->{LIBS}}) if defined($elem->{LIBS});
99                         push(@{$part->{LINK_FLAGS}},@{$elem->{LDFLAGS}}) if defined($elem->{LDFLAGS});
100
101                         push(@{$part->{SUBSYSTEM_INIT_FUNCTIONS}}, @{$elem->{INIT_FUNCTION}}) if 
102                                 $part->{OUTPUT_TYPE} eq "BINARY" and 
103                                 defined($elem->{INIT_FUNCTION}) and 
104                                 $elem->{INIT_FUNCTION} ne "" and
105                                 $part->{OUTPUT_TYPE} ne "SHARED_LIBRARY";
106                 }
107         }
108
109         return %{$depend};
110 }
111
112 1;