setup.pm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #
  2. # Copyright 1999, 2000, 2001 Patrik Stridvall
  3. #
  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.
  8. #
  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.
  13. #
  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  17. #
  18. package setup;
  19. use strict;
  20. use warnings 'all';
  21. BEGIN {
  22. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
  23. require Exporter;
  24. @ISA = qw(Exporter);
  25. @EXPORT = qw();
  26. @EXPORT_OK = qw($current_dir $wine_dir $winapi_dir);
  27. use vars qw($current_dir $wine_dir $winapi_dir);
  28. my $tool = $0;
  29. $tool =~ s%^(?:.*?/)?([^/]+)$%$1%;
  30. if(defined($current_dir) && defined($wine_dir) &&
  31. defined($winapi_dir))
  32. {
  33. # Nothing
  34. } elsif($0 =~ m%^(.*?)/?tools/([^/]+)/[^/]+$%) {
  35. my $dir = $2;
  36. if(defined($1) && $1 ne "")
  37. {
  38. $wine_dir = $1;
  39. } else {
  40. $wine_dir = ".";
  41. }
  42. require Cwd;
  43. my $cwd = Cwd::cwd();
  44. if($wine_dir =~ /^\./) {
  45. $current_dir = ".";
  46. my $pwd; chomp($pwd = $cwd);
  47. foreach my $n (1..((length($wine_dir) + 1) / 3)) {
  48. $pwd =~ s/\/([^\/]*)$//;
  49. $current_dir = "$1/$current_dir";
  50. }
  51. $current_dir =~ s%/\.$%%;
  52. } elsif($wine_dir eq $cwd) {
  53. $wine_dir = ".";
  54. $current_dir = ".";
  55. } elsif($cwd =~ m%^$wine_dir/(.*?)?$%) {
  56. $current_dir = $1;
  57. $wine_dir = ".";
  58. foreach my $dir (split(m%/%, $current_dir)) {
  59. $wine_dir = "../$wine_dir";
  60. }
  61. $wine_dir =~ s%/\.$%%;
  62. } else {
  63. print STDERR "$tool: You must run this tool in the main Wine directory or a sub directory\n";
  64. exit 1;
  65. }
  66. $winapi_dir = "$wine_dir/tools/winapi";
  67. $winapi_dir =~ s%^\./%%;
  68. push @INC, $winapi_dir;
  69. } else {
  70. print STDERR "$tool: You must run this tool in the main Wine directory or a sub directory\n";
  71. exit 1;
  72. }
  73. }
  74. 1;