Makefile.PL (PDL-2.080) | : | Makefile.PL (PDL-2.081) | ||
---|---|---|---|---|
use strict; | use strict; | |||
use warnings; | use warnings; | |||
use ExtUtils::MakeMaker; | use ExtUtils::MakeMaker; | |||
use File::Spec; | use File::Spec; | |||
eval { require Devel::CheckLib; Devel::CheckLib->import; }; | eval { require Devel::CheckLib; Devel::CheckLib->import; }; | |||
eval { require File::Which; }; | ||||
my @pack = (["browser.pd", qw(Browser PDL::IO::Browser)]); | my @pack = (["browser.pd", qw(Browser PDL::IO::Browser)]); | |||
my %hash = pdlpp_stdargs_int(@pack); | my %hash = pdlpp_stdargs_int(@pack); | |||
$hash{'OBJECT'} .= ' browse$(OBJ_EXT)'; | $hash{'OBJECT'} .= ' browse$(OBJ_EXT)'; | |||
$hash{'clean'}{FILES} .= ' browse$(OBJ_EXT) browse$(EXE_EXT) Browser.c Browser.p m Browser.xs Browser$(OBJ_EXT)'; | $hash{'clean'}{FILES} .= ' browse$(OBJ_EXT) browse$(EXE_EXT) Browser.c Browser.p m Browser.xs Browser$(OBJ_EXT)'; | |||
# Here we check for working curses/ncurses | # Here we check for working curses/ncurses | |||
# and the corresponding "curses.h" and "ncurses/curses.h" | # and the corresponding "curses.h" and "ncurses/curses.h" | |||
# | # | |||
# (1) Determine which library we have: curses or ncurses | # (1) Determine which library we have: curses or ncurses | |||
# (2) determine which include path | # (2) determine which include path | |||
# (3) determine which include file | # (3) determine which include file | |||
# (4) confirm configuration | # (4) confirm configuration | |||
# (5) write Makefile or dummy as appropriate | # (5) write Makefile or dummy as appropriate | |||
my $incstring; | sub _read_pipe { | |||
foreach my $incl ( qw( curses.h ncurses/curses.h ncurses.h ncurses/ncurses.h ncu | my (@command) = @_; | |||
rsesw/ncurses.h ) ) { | open( my $fh, '-|', @command) or die "Unable to run @command: $!"; | |||
chomp(my $output = do { local $/; <$fh> }); | ||||
$output; | ||||
} | ||||
my @possible_headers = qw( curses.h ncurses/curses.h ncurses.h ncurses/ncurses.h | ||||
ncursesw/ncurses.h ); | ||||
my $found_header; | ||||
foreach my $incl (@possible_headers) { | ||||
if (eval { check_lib(header=>$incl) }) { | if (eval { check_lib(header=>$incl) }) { | |||
$incstring = $incl; | $found_header = $incl; | |||
last; | last; | |||
} | } | |||
}; | } | |||
$hash{DEFINE} .= ' -DCURSES=' . '\\"' . $incstring . '\\"' if defined $incstring | ||||
; | sub conf_via_ncurses_config { | |||
return () unless $found_header; | ||||
# NOTE the ncurses*-config executables are shell scripts so `sh` is | ||||
# required. | ||||
return () unless File::Which::which('sh'); | ||||
my @nc_configs = qw( | ||||
ncurses6-config | ||||
ncursesw6-config | ||||
ncurses5-config | ||||
ncursesw5-config | ||||
); | ||||
for my $nc_conf (@nc_configs) { | ||||
local $ENV{NCURSES_CONFIG_PROG} = $nc_conf; | ||||
# NOTE which() can not find the script on Windows because it does have | ||||
# have a PATHEXT suffix. For now, just try to run it anyway. | ||||
next unless File::Which::which($nc_conf) || $^O eq 'MSWin32'; | ||||
if( eval { (my $version = _read_pipe(qw(sh -c), '$NCURSES_CONFIG_PROG --ve | ||||
rsion')) =~ / \A [0-9.]+ \Z /x } ) { | ||||
my $cflags = _read_pipe(qw(sh -c), '$NCURSES_CONFIG_PROG --cflags'); | ||||
my $libs = _read_pipe(qw(sh -c), '$NCURSES_CONFIG_PROG --libs'); | ||||
return ( | ||||
header => $found_header, | ||||
inc => $cflags, | ||||
libs => $libs, | ||||
); | ||||
} | ||||
} | ||||
return (); | ||||
} | ||||
my $libstring; | sub conf_via_checklib { | |||
foreach my $libr ( qw( curses ncurses ncursesw ) ) { | return () unless $found_header; | |||
if (eval { check_lib(lib=>$libr) }) { | ||||
$libstring = '-l' . $libr; | my $libstring; | |||
last; | foreach my $libr ( qw( curses ncurses ncursesw ) ) { | |||
if (eval { check_lib(lib=>$libr) }) { | ||||
$libstring = '-l' . $libr; | ||||
last; | ||||
} | ||||
} | ||||
if( defined $libstring ) { | ||||
return ( | ||||
header => $found_header, | ||||
inc => '', | ||||
libs => $libstring, | ||||
); | ||||
} | } | |||
return (); | ||||
} | ||||
my %conf_data; | ||||
%conf_data = conf_via_ncurses_config(); | ||||
%conf_data = conf_via_checklib() unless %conf_data; | ||||
if( %conf_data ) { | ||||
$hash{DEFINE} .= ' -DCURSES=' . '\\"' . $conf_data{header} . '\\"'; | ||||
$hash{INC} .= ' ' . $conf_data{inc} if $conf_data{inc}; | ||||
push @{$hash{LIBS}} , $conf_data{libs}; | ||||
} | } | |||
push @{$hash{LIBS}} , $libstring if defined $libstring; | ||||
# Add genpp rule | # Add genpp rule | |||
undef &MY::postamble; # suppress warning | undef &MY::postamble; # suppress warning | |||
*MY::postamble = sub { pdlpp_postamble_int(@pack); }; | *MY::postamble = sub { pdlpp_postamble_int(@pack); }; | |||
if (defined($incstring) && defined($libstring)) { | if ( %conf_data ) { | |||
WriteMakefile(%hash); | WriteMakefile(%hash); | |||
} else { | } else { | |||
write_dummy_make("Curses capable library not found, not building PDL::IO::Bro wser"); | write_dummy_make("Curses capable library not found, not building PDL::IO::Bro wser"); | |||
} | } | |||
End of changes. 8 change blocks. | ||||
14 lines changed or deleted | 74 lines changed or added |