config.pm 3.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# Copyright 1999, 2000, 2001 Patrik Stridvall
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 18
#

19 20 21 22
package config;

use strict;

23
use setup qw($current_dir $wine_dir $winapi_dir);
24 25 26 27 28 29

use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter;

@ISA = qw(Exporter);
@EXPORT = qw(
30 31 32 33 34 35 36 37
    file_absolutize file_normalize
    file_directory
    file_type files_filter
    file_skip files_skip
    get_c_files
    get_h_files
    get_makefile_in_files
    get_spec_files
38 39
);
@EXPORT_OK = qw(
40
    $current_dir $wine_dir $winapi_dir
41 42
);

43
use vars qw($current_dir $wine_dir $winapi_dir);
44

45
use output qw($output);
46

47 48
use File::Find;

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
sub file_normalize($) {
    local $_ = shift;

    foreach my $dir (split(m%/%, $current_dir)) {
	if(s%^(\.\./)*\.\./$dir/%%) {
	    if(defined($1)) {
		$_ = "$1$_";
	    }
	}
    }

    while(m%^(.*?)([^/\.]+)/\.\./(.*?)$%) {
	if($2 ne "." && $2 ne "..") {
	    $_ = "$1$3";
	}
    }

    return $_;
}

sub file_absolutize($) {
    local $_ = shift;

    $_ = file_normalize($_);
    if(!s%^$wine_dir/%%) {
	$_ = "$current_dir/$_";
    }
    s%^\./%%;

    return $_;
}

sub file_type($) {
82
    local $_ = shift;
83

84
    $_ = file_absolutize($_);
85

86 87
    m%^(?:server|tests|tools)/% && return "";
    m%^(?:programs)/% && return "wineapp";
Patrik Stridvall's avatar
Patrik Stridvall committed
88
    m%^(?:libs)/% && return "library";
89

90 91 92
    return "winelib";
}

93
sub files_filter($@) {
94 95 96 97 98 99 100
    my $type = shift;

    my @files;
    foreach my $file (@_) {
	if(file_type($file) eq $type) {
	    push @files, $file;
	}
101
    }
102 103

    return @files;
104 105
}

106
sub file_skip($) {
107 108
    local $_ = shift;

109
    $_ = file_absolutize($_);
110

111 112
    m%^(?:dlls|include)/% || return 1;
    m%^dlls/wineps\.drv/data/% && return 1;
113 114 115
    return 0;
}

116
sub files_skip(@) {
117 118 119 120 121 122 123 124 125 126
    my @files;
    foreach my $file (@_) {
	if(!file_skip($file)) {
	    push @files, $file;
	}
    }

    return @files;
}

127
sub file_directory($) {
Patrik Stridvall's avatar
Patrik Stridvall committed
128
    local $_ = shift;
129

Patrik Stridvall's avatar
Patrik Stridvall committed
130 131 132
    s%/?[^/]*$%%;
    if(!$_) {
	$_ = ".";
133
    }
Patrik Stridvall's avatar
Patrik Stridvall committed
134 135 136 137

    s%^(?:\./)?(.*?)(?:/\.)?%$1%;

    return $_;
138 139
}

140
sub _get_files($$;$) {
141
    my $pattern = shift;
142
    my $type = shift;
143
    my $dir = shift;
144

145
    $output->progress("$wine_dir: searching for /$pattern/");
146

147 148 149 150 151 152 153 154
    if(!defined($dir)) {
	$dir = $wine_dir;
    }

    my @files;

    my @dirs = ($dir);
    while(defined(my $dir = shift @dirs)) {
155
	opendir(DIR, $dir) || die "Can't open directory $dir: $!\n";
156 157 158
	my @entries= readdir(DIR);
	closedir(DIR);
	foreach (@entries) {
159
	    my $basefile = $_;
160
	    $_ = "$dir/$_";
161 162 163 164
	    if(/\.\.?$/) {
		# Nothing
	    } elsif(-d $_) {
		push @dirs, $_;
165
	    } elsif($basefile =~ /$pattern/ && (!defined($type) || file_type($_) eq $type)) {
166 167 168
		s%^$wine_dir/%%;
		push @files, $_;
	    }
169
	}
170
    }
171

172
    return @files;
173 174
}

175 176 177 178
sub get_c_files($;$) { return _get_files('\.c$', $_[0], $_[1]); }
sub get_h_files($;$) { return _get_files('\.h$', $_[0], $_[1]); }
sub get_spec_files($;$) { return _get_files('\.spec$', $_[0], $_[1]); }
sub get_makefile_in_files($;$) { return _get_files('^Makefile.in$', $_[0], $_[1]); }
179

180
1;