File: subst_lib_name

package info (click to toggle)
udev 164-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,336 kB
  • ctags: 1,738
  • sloc: ansic: 18,516; sh: 11,378; perl: 1,725; xml: 1,286; makefile: 692; python: 34
file content (57 lines) | stat: -rw-r--r-- 1,295 bytes parent folder | download
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
#!/usr/bin/perl

use warnings;
use strict;

my $base = $ARGV[0] || die;

my $file = "$base/lib/udev/rules.d/70-acl.rules";
my $program = "$base/lib/udev/udev-acl";
my $library = 'libglib-2.0.so.0';

##############################################################################
my $rules = read_file($file);

my $libfile = library_path($program, $library)
	or die "Cannot find the path of $library in $program!";

$rules =~ s#\@GLIB_PATH\@#$libfile#;

print "Updating $file for $libfile.\n";
write_file($file, $rules);

exit 0;

##############################################################################
sub library_path {
	my ($file, $library) = @_;

	open(LDD, "ldd $file |") or die "open(ldd $file |): $!";
	my $libfile;
	while (<LDD>) {
		next unless m#^\s*(\S+)\s+=>\s+(\S+)\s+#;
		next unless $1 eq $library;
		$libfile = $2;
	}
	close LDD or die "close(ldd $file |): status=$?";

	return $libfile;
}

##############################################################################
sub read_file {
	my ($file) = @_;
	open(FILE, $file) or die "open($file): $!";
	local $/ = undef;
	my $data = <FILE>;
	close FILE;
	return $data;
}

sub write_file {
	my ($file, $data) = @_;
	open(FILE, '>', $file) or die "open(> $file): $!";
	print FILE $data;
	close FILE or die "close($file): $!";
}