setup.pm 2.22 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 23 24 25 26 27 28
package setup;

use strict;

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

    @ISA = qw(Exporter);
    @EXPORT = qw();
29
    @EXPORT_OK = qw($current_dir $wine_dir $winapi_dir);
30

31
    use vars qw($current_dir $wine_dir $winapi_dir);
32

33
    my $tool = $0;
Patrik Stridvall's avatar
Patrik Stridvall committed
34
    $tool =~ s%^(?:.*?/)?([^/]+)$%$1%;
35

Patrik Stridvall's avatar
Patrik Stridvall committed
36
    if(defined($current_dir) && defined($wine_dir) &&
37
       defined($winapi_dir))
38
    {
Patrik Stridvall's avatar
Patrik Stridvall committed
39 40 41 42 43
	# Nothing
    } elsif($0 =~ m%^(.*?)/?tools/([^/]+)/[^/]+$%) {
	my $dir = $2;

	if(defined($1) && $1 ne "")
44
	{
Patrik Stridvall's avatar
Patrik Stridvall committed
45
	    $wine_dir = $1;
46 47
	} else {
	    $wine_dir = ".";
48 49

	}
Patrik Stridvall's avatar
Patrik Stridvall committed
50 51 52 53

	require Cwd;
	my $cwd = Cwd::cwd();

54 55 56 57 58 59 60 61
	if($wine_dir =~ /^\./) {
	    $current_dir = ".";
	    my $pwd; chomp($pwd = `pwd`);
	    foreach my $n (1..((length($wine_dir) + 1) / 3)) {
		$pwd =~ s/\/([^\/]*)$//;
		$current_dir = "$1/$current_dir";
	    }
	    $current_dir =~ s%/\.$%%;
Patrik Stridvall's avatar
Patrik Stridvall committed
62 63 64 65 66 67 68 69 70 71 72 73 74
	} elsif($wine_dir eq $cwd) {
	    $wine_dir = ".";
	    $current_dir = ".";
	} elsif($cwd =~ m%^$wine_dir/(.*?)?$%) {
	    $current_dir = $1;
	    $wine_dir = ".";
	    foreach my $dir (split(m%/%, $current_dir)) {
		$wine_dir = "../$wine_dir";
	    }
	    $wine_dir =~ s%/\.$%%;
	} else {
	    print STDERR "$tool: You must run this tool in the main Wine directory or a sub directory\n";
	    exit 1;
75
	}
Patrik Stridvall's avatar
Patrik Stridvall committed
76 77

	$winapi_dir = "$wine_dir/tools/winapi";
78
	$winapi_dir =~ s%^\./%%;
Patrik Stridvall's avatar
Patrik Stridvall committed
79

80
	push @INC, $winapi_dir;
81 82 83 84 85 86 87
    } else {
	print STDERR "$tool: You must run this tool in the main Wine directory or a sub directory\n";
	exit 1;
    }
}

1;