r11377: Add support for building LIBRARY elements as shared libraries:
[samba.git] / source4 / build / smb_build / env.pm
1 #
2 # Environment class
3 #
4 # Samba Build Environment
5 #
6 # (C) 2005 Jelmer Vernooij <jelmer@samba.org>
7 #
8 # Published under the GNU GPL
9
10 package smb_build::env;
11 use smb_build::input;
12
13 use strict;
14
15 sub new($$)
16
17         my ($name, $config) = @_;
18         my $self = { };
19         bless $self, $name;
20
21         $self->{items} = {};
22         $self->{info} = {};
23         
24         $self->_set_config($config);
25
26         return $self;
27 }
28
29 sub _set_config($$)
30 {
31         my ($self, $config) = @_;
32
33         $self->{config} = $config;
34
35         $self->{config}->{srcdir} = '.';
36         $self->{config}->{builddir} = '.';
37
38         if ($self->{config}->{prefix} eq "NONE") {
39                 $self->{config}->{prefix} = $self->{config}->{ac_default_prefix};
40         }
41
42         if ($self->{config}->{exec_prefix} eq "NONE") {
43                 $self->{config}->{exec_prefix} = $self->{config}->{prefix};
44         }
45         
46         if ($self->{config}->{developer} eq "yes") {
47                 $self->{developer} = 1;
48         } else {
49                 $self->{developer} = 0;
50         }
51 }
52
53 sub PkgConfig($$$$$$$)
54 {
55         my ($self,$path,$name,$libs,$cflags,$version,$desc) = @_;
56
57         print __FILE__.": creating $path\n";
58
59         open(OUT, ">$path") or die("Can't open $path: $!");
60
61         print OUT <<"__EOF__";
62 prefix=$self->{config}->{prefix}
63 exec_prefix=$self->{config}->{exec_prefix}
64 libdir=$self->{config}->{libdir}
65 includedir=$self->{config}->{includedir}
66
67 __EOF__
68
69         print OUT "Name: $name\n";
70         if (defined($desc)) {
71                 print OUT "Description: $desc\n";
72         }
73         print OUT "Version: $version\n";
74         print OUT "Libs: -L\${libdir} $libs\n";
75         print OUT "Cflags: -I\${includedir} $cflags\n";
76
77         close(OUT);
78 }
79
80 sub Import($$)
81 {
82         my ($self,$items) = @_;
83
84         foreach (keys %$items) {
85                 if (defined($self->{items})) {
86                         print "Warning: Importing $_ twice!\n";
87                 }
88                 $self->{items}->{$_} = $items->{$_};
89         }
90 }
91
92 sub GetInfo($$)
93 {
94         my ($self,$name) = @_;
95
96         unless (defined($self->{info}->{$name})) 
97         {
98                 $self->{info}->{$name} = $self->{items}->Build($self);
99         }
100
101         return $self->{info}->{$name};
102 }
103
104 1;