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