aboutsummaryrefslogtreecommitdiffstats
path: root/php.req
blob: 62001d83bb4258994f13b372e6a6e6dd708700ae (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
#!/usr/bin/perl
#####################################################################
#                                                                   #
# Check system dependences between php-pear modules                 #
#                                                                   #
# Paweł Gołaszewski <blues@ds.pg.gda.pl>                            #
# Michał Moskal <malekith@pld-linux.org>                            #
# ------------------------------------------------------------------#
# TODO:                                                             #
# - extension_loaded - dependencies.                                #
# - some clean-up...                                                #
#####################################################################

use File::Find;

$pear = "/usr/share/pear";

@files = ();
%req = ();

foreach (@ARGV ? $ARGV : <> ) {
	chomp;
	$f = $_;
	push @files, $f;
	open(F, "< $f") or die;

	if ($f =~ /$pear/) {
		$file_dir = $f;
		$file_dir =~ s|.*$pear/||;
		$file_dir =~ s|/[^/]*$||;
	} else {
		$file_dir = undef;
	}

	while (<F>) {
		# skip comments
		next if (/^\s*(#|\/\/|\*|\/\*)/);
		while (/(\W|^)(require|include)(_once)?
			  \s* \(? \s* ("([^"]*)"|'([^']*)') 
			  \s* \)? \s* ;/xg) {

			if ($5 ne "") {
				$x = $5;
			} elsif ($6 ne "") {
				$x = $6;
			} else {
				next;
			}
			do $x =~ s/\/\.?\//\//g while $x =~ /\/\.?\//;
			do $x =~ s/(\/|^)[^\/]*[^.]\/\.\.\//\1/g while $x =~ /(\/|^)[^\/]*[^.]\/\.\.\//;
			next if ($x =~ m|^\.\.?/| or $x =~ /\$/);
			next unless ($x =~ /\.php$/);
			$req{$x} = 1;
		}

		next unless (defined $file_dir);

		while (/(\W|^)(require|include)(_once)?
			  \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s*
			  ("([^"]*)"|'([^']*)') 
			  \s* \)? \s* ;/xg) {
			if ($5 ne "") {
				$x = $5;
			} elsif ($6 ne "") {
				$x = $6;
			} else {
				next;
			}

			next unless ($x =~ /\.php$/);

			$x = "$file_dir/$x";
			do $x =~ s/\/\.?\//\//g while $x =~ /\/\.?\//;
			do $x =~ s/(\/|^)[^\/]*[^.]\/\.\.\//\1/g while $x =~ /(\/|^)[^\/]*[^.]\/\.\.\//;
			$req{$x} = 1;
		}
	}
}

my $wanted = sub {
    return if $File::Find::name !~ /\.php$/;
    return if $File::Find::name =~ /\/usr\/share\/doc/;
    $File::Find::name =~ s/$ENV{RPM_BUILD_ROOT}//;
    push @files, $File::Find::name;
};

@files = ();
find($wanted, $ENV{RPM_BUILD_ROOT});

f: for $f (keys %req) {
	for $g (@files) { next f if ($g =~ /\Q$f\E$/); }
	print "pear($f)\n";
}