summaryrefslogtreecommitdiff
path: root/source4/build/smb_build/env.pm
blob: 70c4d7e968065ac6d03e9c6b48724ee4b305cd2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Environment class
#
# Samba Build Environment
#
# (C) 2005 Jelmer Vernooij <jelmer@samba.org>
#
# Published under the GNU GPL

package smb_build::env;
use smb_build::input;

use strict;

sub new($$)
{ 
	my ($name, $config) = @_;
	my $self = { };
	bless $self, $name;

	$self->{items} = {};
	$self->{info} = {};
	
	$self->_set_config($config);

	return $self;
}

sub _set_config($$)
{
	my ($self, $config) = @_;

	$self->{config} = $config;

	if (not defined($self->{config}->{srcdir})) {
		$self->{config}->{srcdir} = '.';
	}

	if (not defined($self->{config}->{builddir})) {
		$self->{config}->{builddir}  = '.';
	}

	if ($self->{config}->{prefix} eq "NONE") {
		$self->{config}->{prefix} = $self->{config}->{ac_default_prefix};
	}

	if ($self->{config}->{exec_prefix} eq "NONE") {
		$self->{config}->{exec_prefix} = $self->{config}->{prefix};
	}
	
	$self->{developer} = ($self->{config}->{developer} eq "yes");
	$self->{automatic_deps} = ($self->{config}->{automatic_dependencies} eq "yes");
}

sub PkgConfig($$$$$$$$)
{
	my ($self,$path,$name,$libs,$cflags,$version,$desc,$hasmodules) = @_;

	print __FILE__.": creating $path\n";

	open(OUT, ">$path") or die("Can't open $path: $!");

	print OUT <<"__EOF__";
prefix=$self->{config}->{prefix}
exec_prefix=$self->{config}->{exec_prefix}
libdir=$self->{config}->{libdir}
includedir=$self->{config}->{includedir}
__EOF__

	if ($hasmodules) {
		print OUT "modulesdir=$self->{config}->{modulesdir}\n" ;
	}

	print OUT "\n";

	print OUT "Name: $name\n";
	if (defined($desc)) {
		print OUT "Description: $desc\n";
	}
	print OUT "Version: $version\n";
	print OUT "Libs: -L\${libdir} $libs\n";
	print OUT "Cflags: -I\${includedir} $cflags\n";
	if ($hasmodules) {
		print OUT "Modulesdir: \${modulesdir}\n";
	}

	close(OUT);
}

sub Import($$)
{
	my ($self,$items) = @_;

	foreach (keys %$items) {
		if (defined($self->{items})) {
			print "Warning: Importing $_ twice!\n";
		}
		$self->{items}->{$_} = $items->{$_};
	}
}

sub GetInfo($$)
{
	my ($self,$name) = @_;

	unless (defined($self->{info}->{$name})) 
	{
		$self->{info}->{$name} = $self->{items}->Build($self);
	}

	return $self->{info}->{$name};
}

1;