Diff of /Makefile.PL [b63b9b] .. [2f07de] Maximize Restore

  Switch to unified view

a/Makefile.PL b/Makefile.PL
1
# PDL interface to  FFTW
1
# PDL interface to FFTW 2.x
2
# Makefile.PL for a package defined by PP code.
3
2
4
use ExtUtils::MakeMaker;
3
use ExtUtils::MakeMaker;
5
use Config;
4
use Config;
5
use PDL::Core::Dev;
6
6
7
PDL::Core::Dev->import();
7
require './fftw.conf';
8
8
9
BEGIN {
9
$msg = "";
10
11
# Setup the FFTW library we will link to: (single/double precision)
12
#  Default is double precision
13
$want_float = 0;
14
$want_double = 1;
15
if (defined $FFTW_CONFIG{FFTW_TYPE} && $FFTW_CONFIG{FFTW_TYPE} =~ /single/i ) {
16
   $want_float = 1;
17
   $want_double = 0;
18
}
19
20
$found_float = $found_double = 'none';
21
22
# Look for FFTW includes/libs
23
# default locations:
24
@FFTW_inc_locations = ('/usr/include', '/usr/local/include', $Config{usrinc}); 
25
@FFTW_lib_locations = ('/lib','/usr/lib','/usr/local/lib',split(/ /, $Config{libpth}));
26
27
# get locations from perldl.conf, if specified there:
28
@FFTW_inc_locations = @{$FFTW_CONFIG{FFTW_INC}} if( defined $FFTW_CONFIG{FFTW_INC} );
29
@FFTW_lib_locations = @{$FFTW_CONFIG{FFTW_LIBS}} if( defined $FFTW_CONFIG{FFTW_LIBS} );
30
31
foreach $i (@FFTW_inc_locations) {
32
   if (-e "$i/dfftw.h") {
33
      print  "Found FFTW2 double version in $i/dfftw.h !\n";
34
      $double_rinclude = 'drfftw.h';
35
      $double_lib = '-ldfftw -ldrfftw';
36
37
      # Inc found, now try to find libs:
38
      if( findLibs($double_lib, @FFTW_lib_locations)){
39
         print " FFTW Libs also found.\n";
40
         $found_double = 'dfftw.h';
41
42
      }
43
   }
44
   if (-e "$i/sfftw.h") {
45
      print  "Found FFTW2 single version $i/sfftw.h !\n";
46
      $single_rinclude = 'srfftw.h';
47
      $single_lib = '-lsfftw -lsrfftw';
48
49
      # Inc found, now try to find libs:
50
      if( findLibs($single_lib, @FFTW_lib_locations)){
51
         print " FFTW Libs also found.\n";
52
         $found_float = 'sfftw.h';
53
      }
54
   }
55
   if (-e "$i/fftw.h") {
56
      open F,"$i/fftw.h";
57
      $is_float=0;
58
      while (<F>) {
59
         if (/define FFTW_ENABLE_FLOAT 1/) {$is_float=1;}
60
      }
61
      close F;
62
      if ($is_float) {
63
         print "Found FFTW2 single version in $i/fftw.h !\n";
64
         $single_rinclude = 'rfftw.h';
65
         $single_lib = '-lfftw -lrfftw';
66
         # Inc found, now try to find libs:
67
         if( findLibs($single_lib, @FFTW_lib_locations)){
68
            print " FFTW Libs also found.\n";
69
            $found_float = 'fftw.h';
70
         }
71
      }
72
      else {
73
         print  "Found FFTW2 double version in $i/fftw.h !\n";
74
         $double_rinclude = 'rfftw.h';
75
         $double_lib = '-lfftw -lrfftw';
76
         if( findLibs($double_lib, @FFTW_lib_locations)){
77
            print " FFTW Libs also found.\n";
78
            $found_double = 'fftw.h';
79
         }
80
      }
81
   }
82
}
83
84
$donot = 1;
85
$wanted_not_found = 0;
86
87
# want float, found float
88
if ($found_float ne 'none' && $want_float ) {
89
   $include = $found_float;
90
   print "Building single version\n";
91
   $pdltype = 'PDL_F';
92
   $lib = $single_lib;
93
   $rinclude = $single_rinclude;
94
   $out = '$fftwtype=\'float\'';
95
   $donot = 0;
96
}
97
98
# want double, found double
99
elsif ($found_double ne 'none' && $want_double ) {
100
   $include = $found_double;
101
   print "Building double version\n";
102
   $pdltype = 'PDL_D';
103
   $lib = $double_lib;
104
   $rinclude = $double_rinclude;
105
   $out = '$fftwtype=\'double\'';
106
   $donot = 0;
107
}
10
108
11
109
12
  $msg = ""; $forcebuild=0;  # Note: forcebuild not used
110
if ( $donot )   {
111
   $msg .= "\n Skipping build of PDL::FFTW.\n";
13
112
14
  if (defined $PDL::Config{WITH_FFTW} && $PDL::Config{WITH_FFTW}==0) {
113
   # maybe we found something, but it wasn't what was wanted...
15
     $msg = "\n   Will skip build of PDL::FFTW on this system   \n";
114
   if ( $found_double ne 'none' )
16
     goto skip;
115
   { $msg .= "Found double version, wanted float!\n" }
17
  }
18
116
19
  if (defined $PDL::Config{WITH_FFTW} && $PDL::Config{WITH_FFTW}==1) {
117
   if ( $found_float ne 'none' )
20
     print "\n   Will forcibly try and build PDL::FFTW on this system   \n\n";
118
   { $msg .= "Found float version, wanted double!\n" }
21
     $forcebuild=1;
22
  }
119
}
23
120
24
  # Setup the FFTW library we will link to: (single/double precision)
121
if ($msg ne "") {
25
  #  Default is double precision
122
   warn $msg . "\n";
26
  $want_float = 0;
123
   $donot = 1;
27
  $want_double = 1;
124
} else {
28
  if (defined $PDL::Config{FFTW_TYPE} && $PDL::Config{FFTW_TYPE} =~ /single/i ) {
125
   print "\n   Building PDL::FFTW. Turn off WITH_FFTW if there are any problems\n\n";
29
      $want_float = 1;
30
      $want_double = 0;
31
  }
126
}
32
127
33
  $found_float = $found_double = 'none';
128
# Sub to find libs
129
sub findLibs {
130
   my ($libstring, @libdirs) = @_;
131
   # make a list of libs from the libstring
132
   my @libs = split ' ',$double_lib;
133
   grep s/\-l//g, @libs;
134
   grep $_ = "lib$_.a", @libs;
135
   my %libs;
136
   my $lib;
137
   foreach $libdir(@libdirs){
138
      foreach $lib(@libs){
139
         if( -e "$libdir/$lib"){
140
            $libs{$lib} = 1;
141
         }
142
      }
34
143
35
  # Look for FFTW includes/libs
144
   }
36
  # default locations:
145
   if( scalar(keys %libs) == scalar(@libs) ){
37
  @FFTW_inc_locations = ('/usr/include', '/usr/local/include', $Config{usrinc}); 
146
      return 1;   # all libs in the list were found
38
  @FFTW_lib_locations = ('/lib','/usr/lib','/usr/local/lib',split(/ /, $Config{libpth}));
147
   }
148
   print "     Libs: '".join("', '",@libs)."' Not Found\n";
149
   print "     Looked in: '".join("', '",@libdirs)."'\n";
150
   return 0; # all libs in the list not found
39
151
40
  # get locations from perldl.conf, if specified there:
152
}
41
  @FFTW_inc_locations = @{$PDL::Config{FFTW_INC}} if( defined $PDL::Config{FFTW_INC} );
42
  @FFTW_lib_locations = @{$PDL::Config{FFTW_LIBS}} if( defined $PDL::Config{FFTW_LIBS} );
43
153
44
  foreach $i (@FFTW_inc_locations) {
154
if ($donot) {
45
    if (-e "$i/dfftw.h") {
155
   return if (caller); exit 0;
46
      print  "Found FFTW2 double version in $i/dfftw.h !\n";
47
      $double_rinclude = 'drfftw.h';
48
      $double_lib = '-ldfftw -ldrfftw';
49
50
      # Inc found, now try to find libs:
51
      if( findLibs($double_lib, @FFTW_lib_locations)){
52
          print " FFTW Libs also found.\n";
53
          $found_double = 'dfftw.h';
54
55
      }
56
    }
57
    if (-e "$i/sfftw.h") {
58
      print  "Found FFTW2 single version $i/sfftw.h !\n";
59
      $single_rinclude = 'srfftw.h';
60
      $single_lib = '-lsfftw -lsrfftw';
61
62
      # Inc found, now try to find libs:
63
      if( findLibs($single_lib, @FFTW_lib_locations)){
64
          print " FFTW Libs also found.\n";
65
          $found_float = 'sfftw.h';
66
      }
67
    }
68
    if (-e "$i/fftw.h") {
69
      open F,"$i/fftw.h";
70
      $is_float=0;
71
      while (<F>) {
72
        if (/define FFTW_ENABLE_FLOAT 1/) {$is_float=1;}
73
      }
74
      close F;
75
      if ($is_float) {
76
          print "Found FFTW2 single version in $i/fftw.h !\n";
77
          $single_rinclude = 'rfftw.h';
78
          $single_lib = '-lfftw -lrfftw';
79
          # Inc found, now try to find libs:
80
          if( findLibs($single_lib, @FFTW_lib_locations)){
81
              print " FFTW Libs also found.\n";
82
              $found_float = 'fftw.h';
83
          }
84
      }
85
      else {
86
          print  "Found FFTW2 double version in $i/fftw.h !\n";
87
          $double_rinclude = 'rfftw.h';
88
          $double_lib = '-lfftw -lrfftw';
89
          if( findLibs($double_lib, @FFTW_lib_locations)){
90
              print " FFTW Libs also found.\n";
91
              $found_double = 'fftw.h';
92
          }
93
      }
94
    }
95
  }
96
97
  $donot = 1;
98
  $wanted_not_found = 0;
99
  
100
        # want float, found float
101
        if ($found_float ne 'none' && $want_float ) {
102
            $include = $found_float;
103
            print "Building single version\n";
104
            $pdltype = 'PDL_F';
105
            $lib = $single_lib;
106
            $rinclude = $single_rinclude;
107
            $out = '$fftwtype=\'float\'';
108
            $donot = 0;
109
        }
110
111
        # want double, found double
112
        elsif ($found_double ne 'none' && $want_double ) {
113
            $include = $found_double;
114
            print "Building double version\n";
115
            $pdltype = 'PDL_D';
116
            $lib = $double_lib;
117
            $rinclude = $double_rinclude;
118
            $out = '$fftwtype=\'double\'';
119
            $donot = 0;
120
        }
121
122
123
        if ( $donot )   {
124
125
          $msg .= "\n Skipping build of PDL::FFTW.\n";
126
127
          # maybe we found something, but it wasn't what was wanted...
128
          if ( $found_double ne 'none' )
129
            { $msg .= "Found double version, wanted float!\n" }
130
131
          if ( $found_float ne 'none' )
132
            { $msg .= "Found float version, wanted double!\n" }
133
        }
134
135
skip:
136
137
  if ($msg ne "" && $forcebuild==0) {
138
139
      warn $msg . "\n";
140
      $msg =~ s/\n//g;
141
      write_dummy_make( $msg );
142
      $donot = 1;
143
      $PDL::Config{WITH_FFTW}=0;
144
  } else {
145
      $PDL::Config{WITH_FFTW}=1;
146
            print "\n   Building PDL::FFTW. Turn off WITH_FFTW if there are any problems\n\n";
147
  }
148
149
  # Sub to find libs
150
  sub findLibs {
151
      my ($libstring, @libdirs) = @_;
152
      # make a list of libs from the libstring
153
      my @libs = split ' ',$double_lib;
154
      grep s/\-l//g, @libs;
155
      grep $_ = "lib$_.a", @libs;
156
      my %libs;
157
      my $lib;
158
      foreach $libdir(@libdirs){
159
          foreach $lib(@libs){
160
              if( -e "$libdir/$lib"){
161
                  $libs{$lib} = 1;
162
              }
163
          }
164
  
165
      }
166
      if( scalar(keys %libs) == scalar(@libs) ){
167
          return 1;   # all libs in the list were found
168
      }
169
      print "     Libs: '".join("', '",@libs)."' Not Found\n";
170
      print "     Looked in: '".join("', '",@libdirs)."'\n";
171
      return 0; # all libs in the list not found
172
  
173
  }
174
}
156
}
175
##############################################################################
176
177
178
return if $donot;
179
157
180
open F,'>typespec';
158
open F,'>typespec';
181
print F $out,";\n";
159
print F $out,";\n";
182
print F 'pp_addhdr(\'',"\n";
160
print F 'pp_addhdr(\'',"\n";
183
print F '#include "',$include,'"',"\n";
161
print F '#include "',$include,'"',"\n";
...
...
185
print F '#define PDL_MYTYPE ',$pdltype,"\n";
163
print F '#define PDL_MYTYPE ',$pdltype,"\n";
186
print F '\');',"\n";
164
print F '\');',"\n";
187
close F;
165
close F;
188
166
189
@pack = (["fftw.pd",FFTW,PDL::FFTW]);
167
@pack = (["fftw.pd",FFTW,PDL::FFTW]);
190
%hash = pdlpp_stdargs_int(@::pack);
168
%hash = pdlpp_stdargs(@::pack);
191
$hash{INC} .= " -I".join(' -I',@FFTW_inc_locations);
169
$hash{INC} .= " -I".join(' -I',@FFTW_inc_locations);
192
$hash{clean}->{FILES} .= ' typespec';
170
$hash{clean}->{FILES} .= ' typespec';
193
push @{$hash{LIBS}},"-lm -L".join(" -L",@FFTW_lib_locations)." $lib";
171
push @{$hash{LIBS}},"-lm -L".join(" -L",@FFTW_lib_locations)." $lib";
194
WriteMakefile(%hash);
172
WriteMakefile(%hash);
195
173
196
174
197
sub MY::postamble {
175
sub MY::postamble {
198
        pdlpp_postamble_int(@::pack);
176
   pdlpp_postamble(@::pack);
199
}  # Add genpp rule                             
177
}  # Add genpp rule