config.pm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 config;
  19. use strict;
  20. use warnings 'all';
  21. use setup qw($current_dir $wine_dir $winapi_dir);
  22. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
  23. require Exporter;
  24. @ISA = qw(Exporter);
  25. @EXPORT = qw(
  26. file_absolutize file_normalize
  27. file_directory
  28. file_type files_filter
  29. file_skip files_skip
  30. get_c_files
  31. get_h_files
  32. get_makefile_in_files
  33. get_spec_files
  34. );
  35. @EXPORT_OK = qw(
  36. $current_dir $wine_dir $winapi_dir
  37. );
  38. use vars qw($current_dir $wine_dir $winapi_dir);
  39. use output qw($output);
  40. use File::Find;
  41. sub file_normalize($) {
  42. local $_ = shift;
  43. foreach my $dir (split(m%/%, $current_dir)) {
  44. if(s%^(\.\./)*\.\./$dir/%%) {
  45. if(defined($1)) {
  46. $_ = "$1$_";
  47. }
  48. }
  49. }
  50. while(m%^(.*?)([^/\.]+)/\.\./(.*?)$%) {
  51. if($2 ne "." && $2 ne "..") {
  52. $_ = "$1$3";
  53. }
  54. }
  55. return $_;
  56. }
  57. sub file_absolutize($) {
  58. local $_ = shift;
  59. $_ = file_normalize($_);
  60. if(!s%^$wine_dir/%%) {
  61. $_ = "$current_dir/$_";
  62. }
  63. s%^\./%%;
  64. return $_;
  65. }
  66. sub file_type($) {
  67. local $_ = shift;
  68. $_ = file_absolutize($_);
  69. m%^(?:server|tests|tools)/% && return "";
  70. m%^(?:programs)/% && return "wineapp";
  71. m%^(?:libs)/% && return "library";
  72. return "winelib";
  73. }
  74. sub files_filter($@) {
  75. my $type = shift;
  76. my @files;
  77. foreach my $file (@_) {
  78. if(file_type($file) eq $type) {
  79. push @files, $file;
  80. }
  81. }
  82. return @files;
  83. }
  84. sub file_skip($) {
  85. local $_ = shift;
  86. $_ = file_absolutize($_);
  87. m%^(?:dlls|include)/% || return 1;
  88. m%^dlls/wineps\.drv/data/% && return 1;
  89. return 0;
  90. }
  91. sub files_skip(@) {
  92. my @files;
  93. foreach my $file (@_) {
  94. if(!file_skip($file)) {
  95. push @files, $file;
  96. }
  97. }
  98. return @files;
  99. }
  100. sub file_directory($) {
  101. local $_ = shift;
  102. s%/?[^/]*$%%;
  103. if(!$_) {
  104. $_ = ".";
  105. }
  106. s%^(?:\./)?(.*?)(?:/\.)?%$1%;
  107. return $_;
  108. }
  109. sub _get_files($$;$) {
  110. my $pattern = shift;
  111. my $type = shift;
  112. my $dir = shift;
  113. $output->progress("$wine_dir: searching for /$pattern/");
  114. if(!defined($dir)) {
  115. $dir = $wine_dir;
  116. }
  117. my @files;
  118. my @dirs = ($dir);
  119. while(defined(my $dir = shift @dirs)) {
  120. opendir(DIR, $dir) || die "Can't open directory $dir: $!\n";
  121. my @entries= readdir(DIR);
  122. closedir(DIR);
  123. foreach (@entries) {
  124. my $basefile = $_;
  125. $_ = "$dir/$_";
  126. if(/\.\.?$/) {
  127. # Nothing
  128. } elsif(-d $_) {
  129. push @dirs, $_;
  130. } elsif($basefile =~ /$pattern/ && (!defined($type) || file_type($_) eq $type)) {
  131. s%^$wine_dir/%%;
  132. push @files, $_;
  133. }
  134. }
  135. }
  136. return @files;
  137. }
  138. sub get_c_files($;$) { return _get_files('\.c$', $_[0], $_[1]); }
  139. sub get_h_files($;$) { return _get_files('\.h$', $_[0], $_[1]); }
  140. sub get_spec_files($;$) { return _get_files('\.spec$', $_[0], $_[1]); }
  141. sub get_makefile_in_files($;$) { return _get_files('^Makefile.in$', $_[0], $_[1]); }
  142. 1;