2 # Copyright 1999, 2000, 2001 Patrik Stridvall
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 use vars
qw($VERSION @ISA @EXPORT @EXPORT_OK);
28 @EXPORT_OK = qw($modules);
30 use vars qw($modules);
35 get_c_files get_spec_files
36 $current_dir $wine_dir
39 use options qw($options);
40 use output qw($output);
43 $Exporter::ExportLevel++;
45 $Exporter::ExportLevel--;
47 if (defined($modules)) {
51 $modules = 'modules'->new;
54 sub get_spec_file_type($) {
61 $module =~ s%^.*?([^/]+)\.spec$%$1%;
63 open(IN, "< $file") || die "$file: $!\n";
67 while($lookahead || defined($_ = <IN>)) {
74 if(/^\d+|@/) { $header = 0; $lookahead = 1; }
78 if(/^(\d+|@)\s+pascal(?:16)?/) {
89 return ($type, $module);
92 sub find_spec_files($) {
95 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
96 my $spec_file2dir = \%{$self->{SPEC_FILE2DIR}};
98 $output->progress("modules");
100 my $spec_file_found = {};
104 my @spec_files = <{dlls/*/*.spec,dlls/*/*/*.spec}>;
106 foreach $spec_file (@spec_files) {
107 $spec_file =~ /(.*)\/.*\.spec/;
111 $$spec_file_found{$spec_file}++;
112 $$spec_file2dir{$spec_file}{$allowed_dir}++;
113 $$dir2spec_file{$allowed_dir}{$spec_file}++;
116 return $spec_file_found;
119 sub read_spec_files($$) {
122 my $spec_file_found = shift;
124 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
125 my $spec_files16 = \@{$self->{SPEC_FILES16}};
126 my $spec_files32 = \@{$self->{SPEC_FILES32}};
127 my $spec_file2module = \%{$self->{SPEC_FILE2MODULE}};
128 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
131 if($wine_dir eq ".") {
132 @spec_files = get_spec_files("winelib");
135 foreach my $dir ($options->directories) {
136 $dir = "$current_dir/$dir";
138 foreach my $spec_file (sort(keys(%{$$dir2spec_file{$dir}}))) {
139 $spec_files{$spec_file}++;
142 @spec_files = sort(keys(%spec_files));
147 foreach my $spec_file (@spec_files) {
148 (my $type, my $module) = get_spec_file_type("$wine_dir/$spec_file");
150 $$spec_file2module{$spec_file} = $module;
151 $$module2spec_file{$module} = $spec_file;
153 if($type eq "win16") {
154 push @$spec_files16, $spec_file;
155 } elsif($type eq "win32") {
156 push @$spec_files32, $spec_file;
158 $output->write("$spec_file: unknown type '$type'\n");
162 foreach my $spec_file (@spec_files) {
163 if(!$$spec_file_found{$spec_file} && $spec_file !~ m%tests/[^/]+$%) {
164 $output->write("modules: $spec_file: exists but is not specified\n");
171 my $class = ref($proto) || $proto;
173 bless ($self, $class);
175 my $spec_file_found = $self->find_spec_files();
176 $self->read_spec_files($spec_file_found);
184 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
186 return sort(keys(%$module2spec_file));
189 sub complete_modules($$) {
196 foreach my $file (@$c_files) {
197 my $dir = file_directory("$current_dir/$file");
201 my @c_files = get_c_files("winelib");
202 @c_files = files_skip(@c_files);
203 foreach my $file (@c_files) {
204 my $dir = file_directory($file);
205 if(exists($dirs{$dir})) {
210 my @complete_modules = ();
211 foreach my $module ($self->all_modules) {
213 my @dirs = $self->allowed_dirs_for_module($module);
214 foreach my $dir (@dirs) {
215 if(exists($dirs{$dir}) && $dirs{$dir} == 0) {
219 if($index == $#dirs) {
220 push @complete_modules, $module;
224 return @complete_modules;
227 sub is_allowed_module($$) {
230 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
234 return defined($$module2spec_file{$module});
237 sub is_allowed_module_in_file($$$) {
240 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
241 my $spec_file2module = \%{$self->{SPEC_FILE2MODULE}};
248 $dir =~ s/\/[^\/]*$//;
250 if($dir =~ m%^include%) {
254 foreach my $spec_file (sort(keys(%{$$dir2spec_file{$dir}}))) {
255 if($$spec_file2module{$spec_file} eq $module) {
263 sub allowed_modules_in_file($$) {
266 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
267 my $spec_file2module = \%{$self->{SPEC_FILE2MODULE}};
273 $dir =~ s/\/[^\/]*$//;
275 my %allowed_modules = ();
276 foreach my $spec_file (sort(keys(%{$$dir2spec_file{$dir}}))) {
277 my $module = $$spec_file2module{$spec_file};
278 $allowed_modules{$module}++;
281 my $module = join(" & ", sort(keys(%allowed_modules)));
286 sub allowed_dirs_for_module($$) {
289 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
290 my $spec_file2dir = \%{$self->{SPEC_FILE2DIR}};
294 my $spec_file = $$module2spec_file{$module};
296 return sort(keys(%{$$spec_file2dir{$spec_file}}));
299 sub allowed_spec_files16($) {
302 my $spec_files16 = \@{$self->{SPEC_FILES16}};
304 return @$spec_files16;
307 sub allowed_spec_files32($) {
310 my $spec_files32 = \@{$self->{SPEC_FILES32}};
312 return @$spec_files32;
315 sub found_module_in_dir($$$) {
321 my $used_module_dirs = \%{$self->{USED_MODULE_DIRS}};
323 $dir = "$current_dir/$dir";
326 $$used_module_dirs{$module}{$dir}++;
329 sub global_report($) {
332 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
333 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
334 my $used_module_dirs = \%{$self->{USED_MODULE_DIRS}};
337 foreach my $dir ($options->directories) {
338 $dir = "$current_dir/$dir";
340 foreach my $module ($self->all_modules) {
341 if(!$$used_module_dirs{$module}{$dir}) {
342 my $spec_file = $$module2spec_file{$module};
343 push @messages, "modules: $spec_file: directory ($dir) is not used\n";
348 foreach my $message (sort(@messages)) {
349 $output->write($message);