File: confsub

package info (click to toggle)
dpkg-cross 1.2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 172 kB
  • ctags: 8
  • sloc: perl: 1,457; makefile: 56; sh: 21; sed: 9
file content (82 lines) | stat: -rw-r--r-- 1,896 bytes parent folder | download | duplicates (2)
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
#
# general code to read dpkg-cross configuration
#

sub read_config {
	my $package;
	
	open( F, "<$conffile" ) || return;
	while( <F> ) {
		next if /^(\s*#|$)/;
		if (/\s*([\w\d_]+)\s*=\s*(.*)\s*$/) {
			if ($package) {
				${$pkgvars{$package}}{$1} = $2;
			}
			elsif (grep $_ eq $1, @intern_vars) {
				eval "\$$1 = '$2'";
			}
			else {
				warn "$progname: Warning: definition of unknown variable $1 ".
					 "in $conffile, line $.\n";
				next;
			}
		}
		elsif (/^\s*([\w\d.-]+):\s*$/) {
			$package = $1;
		}
		else {
			warn "$progname: unrecognized line in $conffile, line $.\n";
		}
	}
	close( F );
}


sub setup {
	my( $package, $var );
	my @vars = ( "arch", @intern_vars );

	# finalize, no subst possible crossbase
	$crossbase ||= "/usr/local";

	# set defaults for internal vars, if not set
	$crossprefix ||= "\$(ARCH)-linux-";
	$crossdir    ||= "\$(CROSSBASE)/\$(ARCH)-linux";
	$crossbin    ||= "\$(CROSSDIR)/bin";
	$crosslib    ||= "\$(CROSSDIR)/lib";
	$crossinc    ||= "\$(CROSSDIR)/include";
	$crossinfo   ||= "\$(CROSSLIB)/dpkg-cross-info";
	# and substitute references in them
	foreach $var ( @intern_vars ) {
		next if $var eq "crossbase" || $var eq "maintainer";
		subst( eval "\\\$$var", $var, @vars );
	}

	# substitute variable references in package var definitions
	foreach $package ( keys %pkgvars ) {
		foreach $var ( keys %{$pkgvars{$package}} ) {
			subst( \${$pkgvars{$package}}{$var}, $var, @vars );
		}
	}
}


sub subst {
	my $valref = shift(@_);
	my $varname = shift(@_);
	my @defined_vars = @_;
	my( $fulltext, $name, $newval );

	while( $$valref =~ /\$\((\w+)\)/ ) {
		$name = $1;
		if (grep "\U$_\E" eq $name, @defined_vars ) {
			$newval = eval "\"\$\L$name\E\"";
		}
		elsif (!($newval = $ENV{$name})) {
			warn "$progname: Cannot substitute \$($name) in definition ".
				 "of $varname\n";
			$newval = "";
		}
		$$valref =~ s/\$\($name\)/$newval/;
	}
}