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