| 170 | | my $ghcver = `$ghc --version`; |
| 171 | | ($ghcver =~ /Glasgow.*\bversion\s*(\S+)/s) or die << '.'; |
| | 171 | |
| | 172 | # This local subroutine returns the version of ghc passed to it. |
| | 173 | |
| | 174 | my $test_ghc_ver = sub { |
| | 175 | (`$_[0] --version` =~ /Glasgow.*\bversion\s*(\S+)/s)[0]; |
| | 176 | }; |
| | 177 | |
| | 178 | my ($ghc_version) = $test_ghc_ver->($ghc); |
| | 179 | |
| | 180 | if (!$ghc_version and ( $Config{osname} eq "cygwin" |
| | 181 | or $Config{osname} eq "MSWin32" |
| | 182 | ) |
| | 183 | ) { |
| | 184 | |
| | 185 | # Looks like we're on a Windows-ish system, without GHC |
| | 186 | # in our path. Let's hunt around for it. |
| | 187 | |
| | 188 | my $ghc_root = "$ENV{SYSTEMDRIVE}/ghc"; |
| | 189 | |
| | 190 | warn "*** ghc not found in path. Looking in $ghc_root\n"; |
| | 191 | |
| | 192 | if (-d $ghc_root) { |
| | 193 | # Looks like we've found a GHC directory. Find the latest |
| | 194 | # ghc inside that. Sorted from lexically highest to lowest. |
| | 195 | |
| | 196 | # XXX - This will bite us should GHC contain a two-digit |
| | 197 | # revision. Eg, 6.9.0 vs 6.10.0 |
| | 198 | |
| | 199 | my @ghc_choices = reverse glob(qq{$ghc_root/ghc-*}); |
| | 200 | |
| | 201 | GHC_TEST: |
| | 202 | for my $ghc_dir (@ghc_choices) { |
| | 203 | my $ghc_candidate = qq{$ghc_dir/bin/ghc.exe}; |
| | 204 | if ($ghc_version = $test_ghc_ver->($ghc_candidate)) { |
| | 205 | $ghc = $ghc_candidate; |
| | 206 | warn "*** Found $ghc\n"; |
| | 207 | } |
| | 208 | } |
| | 209 | } |
| | 210 | } |
| | 211 | |
| | 212 | $ghc_version or die << '.'; |
| 215 | | $ghc_pkg = $self->can_run($ghc_pkg) || $self->can_run('ghc-pkg'); |
| | 271 | |
| | 272 | |
| | 273 | my $ghc_exe = $self->can_run($ghc_pkg) || $self->can_run('ghc-pkg'); |
| | 274 | |
| | 275 | # This above fails under cygwin with a Win32-flavoured ghc-pkg. |
| | 276 | # https://rt.cpan.org/Ticket/Display.html?id=16375 fixes this, |
| | 277 | # but we can't rely upon everyone having it. As such, we have |
| | 278 | # a very special cygwin work-around. Ugh! |
| | 279 | |
| | 280 | |
| | 281 | if (not $ghc_exe and $Config{osname} eq 'cygwin') { |
| | 282 | |
| | 283 | warn "*** ghc-pkg not found in path. Testing $ghc_pkg\n"; |
| | 284 | |
| | 285 | # If the file exists, and it looks like it's in windows |
| | 286 | # land, and it has an executable extension... |
| | 287 | |
| | 288 | if ( -f $ghc_pkg |
| | 289 | and $ghc_pkg =~ m{^(?:/cygdrive|[A-Za-z]:)/.*$Config{_exe}$} |
| | 290 | ) { |
| | 291 | |
| | 292 | # Smells like a Windows executable called from cygwin-land. |
| | 293 | # Keep it. |
| | 294 | |
| | 295 | $ghc_exe = $ghc_pkg; |
| | 296 | |
| | 297 | } |
| | 298 | } |
| | 299 | |
| | 300 | # Our ghc-pkg is whatever executable we've found (which could be |
| | 301 | # undef, if we didn't find anything). |
| | 302 | |
| | 303 | $ghc_pkg = $ghc_exe; |
| | 304 | |