A few bug fixes.
[wine] / tools / winapi / setup.pm
1 package setup;
2
3 use strict;
4
5 BEGIN {
6     use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
7     require Exporter;
8
9     @ISA = qw(Exporter);
10     @EXPORT = qw();
11     @EXPORT_OK = qw($current_dir $wine_dir $winapi_dir $winapi_check_dir);
12
13     use vars qw($current_dir $wine_dir $winapi_dir $winapi_check_dir);
14
15     my $tool = $0; 
16     $tool =~ s%^(?:.*?/)?([^/]+)$%$1%;
17
18     if(defined($current_dir) && defined($wine_dir) &&
19        defined($winapi_dir) && defined($winapi_check_dir))
20     {
21         # Nothing
22     } elsif($0 =~ m%^(.*?)/?tools/([^/]+)/[^/]+$%) {
23         my $dir = $2;
24
25         if(defined($1) && $1 ne "")
26         {
27             $wine_dir = $1;
28         } else {
29             $wine_dir = ".";
30             
31         } 
32
33         require Cwd;
34         my $cwd = Cwd::cwd();
35
36         if($wine_dir =~ /^\./) {
37             $current_dir = ".";
38             my $pwd; chomp($pwd = `pwd`);
39             foreach my $n (1..((length($wine_dir) + 1) / 3)) {
40                 $pwd =~ s/\/([^\/]*)$//;
41                 $current_dir = "$1/$current_dir";
42             }
43             $current_dir =~ s%/\.$%%;
44         } elsif($wine_dir eq $cwd) {
45             $wine_dir = ".";
46             $current_dir = ".";
47         } elsif($cwd =~ m%^$wine_dir/(.*?)?$%) {
48             $current_dir = $1;
49             $wine_dir = ".";
50             foreach my $dir (split(m%/%, $current_dir)) {
51                 $wine_dir = "../$wine_dir";
52             }
53             $wine_dir =~ s%/\.$%%;
54         } else {
55             print STDERR "$tool: You must run this tool in the main Wine directory or a sub directory\n";
56             exit 1;
57         }
58
59         $winapi_dir = "$wine_dir/tools/winapi";
60         $winapi_dir =~ s%^\./%%;
61
62         $winapi_check_dir = "$wine_dir/tools/winapi_check";
63         $winapi_check_dir =~ s%^\./%%;
64
65         push @INC, ($winapi_dir, $winapi_check_dir);
66     } else {
67         print STDERR "$tool: You must run this tool in the main Wine directory or a sub directory\n";
68         exit 1;
69     }
70 }
71
72 1;