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