| 1 |
use strictscip-perl cpan PGPLOT 2.36 strict/; |
| 2 |
|
| 3 |
use ExtUtils::MakeMakerscip-perl cpan PGPLOT 2.36 ExtUtils/MakeMaker/; |
| 4 |
use Configscip-perl cpan PGPLOT 2.36 Config/; |
| 5 |
use Devel::CheckLibscip-perl cpan PGPLOT 2.36 Devel/CheckLib/ qw(check_lib); |
| 6 |
use ExtUtils::F77scip-perl cpan PGPLOT 2.36 ExtUtils/F77/; # need imports else doesn't work |
| 7 |
|
| 8 |
# Examples of how to explicitly override default automatic choice |
| 9 |
# of OS and compiler (currently commented out): |
| 10 |
|
| 11 |
#use ExtUtils::F77 qw(solaris); |
| 12 |
#use ExtUtils::F77 qw(generic g77); |
| 13 |
|
| 14 |
# use command line KEY=VALUE to override defaults. VALUES are comma |
| 15 |
# separated lists |
| 16 |
|
| 17 |
my %Arg = ( |
| 18 |
# X11 library directories |
| 19 |
XDIR => '/usr/openwin/lib,/usr/X11/lib,/usr/X11R6/lib', |
| 20 |
|
| 21 |
# X11 libraries |
| 22 |
XLIB => 'X11', |
| 23 |
|
| 24 |
# where cpgplot.h should be |
| 25 |
IDIR => undef, |
| 26 |
|
| 27 |
# where libpgplot.a should be |
| 28 |
LDIR => undef, |
| 29 |
|
| 30 |
# extra libraries and directories |
| 31 |
EXLIB => joinscip-perl cpan PGPLOT 2.36 main/join().(',', grepscip-perl cpan PGPLOT 2.36 main/grep(). check_libscip-perl cpan PGPLOT 2.36 main/check_lib().(lib => $_scip-perl cpan PGPLOT 2.36 main/$_.), qw(png12 png16 z)), |
| 32 |
EXDIR => '/Applications/PDL/pgplot,/usr/local/lib', |
| 33 |
); |
| 34 |
|
| 35 |
# Get user preferences |
| 36 |
my @NARGV; |
| 37 |
while( $_scip-perl cpan PGPLOT 2.36 main/$_. = shiftscip-perl cpan PGPLOT 2.36 main/shift(). @ARGVscip-perl cpan PGPLOT 2.36 main/`@ARGV`. ) |
| 38 |
{ |
| 39 |
if ( /^([\S]+)=(.+)/ && existsscip-perl cpan PGPLOT 2.36 main/exists(). $Arg{$1scip-perl cpan PGPLOT 2.36 main/$1.} ) |
| 40 |
{ |
| 41 |
$Arg{$1scip-perl cpan PGPLOT 2.36 main/$1.} = $2scip-perl cpan PGPLOT 2.36 main/$2.; |
| 42 |
} |
| 43 |
else |
| 44 |
{ |
| 45 |
pushscip-perl cpan PGPLOT 2.36 main/push(). @NARGV, $_scip-perl cpan PGPLOT 2.36 main/$_.; |
| 46 |
} |
| 47 |
} |
| 48 |
@ARGVscip-perl cpan PGPLOT 2.36 main/`@ARGV`. = @NARGV; |
| 49 |
|
| 50 |
# look for libraries and includes if not specified on the command line |
| 51 |
if ( !definedscip-perl cpan PGPLOT 2.36 main/defined(). $Arg{IDIR} || !definedscip-perl cpan PGPLOT 2.36 main/defined(). $Arg{LDIR} ) { |
| 52 |
|
| 53 |
my $IDIR; |
| 54 |
my $LDIR; |
| 55 |
|
| 56 |
# Specification of PGPLOT location via environment variable |
| 57 |
if ( definedscip-perl cpan PGPLOT 2.36 main/defined(). $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{PGPLOT_DIR} ) { |
| 58 |
|
| 59 |
$IDIR = $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{PGPLOT_DIR}; |
| 60 |
$LDIR = $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{PGPLOT_DIR}; |
| 61 |
} |
| 62 |
|
| 63 |
# if using the autotool'd version of PGPLOT (see the "OBTAINING PGPLOT" |
| 64 |
# section in PGPLOT.pm for more details) pkg-config may be able to |
| 65 |
# find everything needed. |
| 66 |
|
| 67 |
# First try pure-perl vesion |
| 68 |
elsif ( eval { requirescip-perl cpan PGPLOT 2.36 main/require(). PkgConfig; 1 } ) { |
| 69 |
|
| 70 |
my $pkg = PkgConfig->findscip-perl cpan PGPLOT 2.36 PkgConfig/find().( 'cpgplot' ); |
| 71 |
if ( $pkg->pkg_existsscip-perl cpan PGPLOT 2.36 PkgConfig/pkg_exists(). ) { |
| 72 |
|
| 73 |
my @libdirs = mapscip-perl cpan PGPLOT 2.36 main/map(). { s/-L//; $_scip-perl cpan PGPLOT 2.36 main/$_. } grepscip-perl cpan PGPLOT 2.36 main/grep(). { /^-L/ } $pkg->get_ldflagsscip-perl cpan PGPLOT 2.36 PkgConfig/get_ldflags().; |
| 74 |
$LDIR = joinscip-perl cpan PGPLOT 2.36 main/join().( ',', @libdirs ); |
| 75 |
|
| 76 |
my @incdirs = mapscip-perl cpan PGPLOT 2.36 main/map(). { s/-I//; $_scip-perl cpan PGPLOT 2.36 main/$_. } grepscip-perl cpan PGPLOT 2.36 main/grep(). { /^-I/ } $pkg->get_cflagsscip-perl cpan PGPLOT 2.36 PkgConfig/get_cflags().; |
| 77 |
$IDIR = joinscip-perl cpan PGPLOT 2.36 main/join().( ',', @incdirs ); |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
# now try the wrapper around the pkg-config executable |
| 84 |
elsif ( eval { requirescip-perl cpan PGPLOT 2.36 main/require(). ExtUtils::PkgConfig; 1; } ) { |
| 85 |
|
| 86 |
my %pkg = eval { ExtUtils::PkgConfig->findscip-perl cpan PGPLOT 2.36 ExtUtils/PkgConfig/find().( 'cpgplot' ); }; |
| 87 |
|
| 88 |
if ( !$@scip-perl cpan PGPLOT 2.36 main/`$@`. ) { |
| 89 |
my @libdirs = mapscip-perl cpan PGPLOT 2.36 main/map(). { s/^-L//; $_scip-perl cpan PGPLOT 2.36 main/$_. } grepscip-perl cpan PGPLOT 2.36 main/grep(). { /^-L/ } |
| 90 |
splitscip-perl cpan PGPLOT 2.36 main/split().( ' ', ExtUtils::PkgConfig->libs_only_Lscip-perl cpan PGPLOT 2.36 ExtUtils/PkgConfig/libs_only_L().( 'cpgplot' ) ); |
| 91 |
|
| 92 |
$LDIR = joinscip-perl cpan PGPLOT 2.36 main/join().( ',', @libdirs ); |
| 93 |
|
| 94 |
|
| 95 |
my @incdirs = mapscip-perl cpan PGPLOT 2.36 main/map(). { s/^-I//; $_scip-perl cpan PGPLOT 2.36 main/$_. } grepscip-perl cpan PGPLOT 2.36 main/grep(). { /^-I/ } |
| 96 |
splitscip-perl cpan PGPLOT 2.36 main/split().( ' ', ExtUtils::PkgConfig->cflagsscip-perl cpan PGPLOT 2.36 ExtUtils/PkgConfig/cflags().( 'cpgplot' ) ); |
| 97 |
|
| 98 |
$IDIR = joinscip-perl cpan PGPLOT 2.36 main/join().( ',', @incdirs ); |
| 99 |
|
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
# and if nothing worked, use some defaults |
| 104 |
|
| 105 |
$Arg{IDIR} ||= $IDIR || '/usr/include,/Applications/PDL/pgplot,/usr/local/pgplot,/opt/homebrew/opt/pgplot/include'; |
| 106 |
$Arg{LDIR} ||= $LDIR || '/usr/lib,/usr/lib64,/opt/homebrew/opt/pgplot/lib'; |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
my $LIBDIRS = joinscip-perl cpan PGPLOT 2.36 main/join().(' ', mapscip-perl cpan PGPLOT 2.36 main/map(). { "-L$_" } |
| 111 |
mapscip-perl cpan PGPLOT 2.36 main/map(). { splitscip-perl cpan PGPLOT 2.36 main/split().( ',', $_scip-perl cpan PGPLOT 2.36 main/$_. ) } |
| 112 |
@Arg{qw/ XDIR LDIR EXDIR /} |
| 113 |
); |
| 114 |
|
| 115 |
my $LIBS = joinscip-perl cpan PGPLOT 2.36 main/join().(' ', mapscip-perl cpan PGPLOT 2.36 main/map(). { "-l$_" } |
| 116 |
qw/ cpgplot pgplot /, |
| 117 |
); |
| 118 |
|
| 119 |
my $IDIRS = joinscip-perl cpan PGPLOT 2.36 main/join().( ' ', mapscip-perl cpan PGPLOT 2.36 main/map(). { "-I$_" } splitscip-perl cpan PGPLOT 2.36 main/split().( ',', $Arg{IDIR} ) ); |
| 120 |
|
| 121 |
# |
| 122 |
# Usage: |
| 123 |
# $needed_libs = find_required_driver_libs($dir); |
| 124 |
# |
| 125 |
# Aim: |
| 126 |
# Parse the drivers.list file to find out what extra libraries |
| 127 |
# are needed by the module. The file is assumed to be in |
| 128 |
# the directory $dir. If the file can not be read then |
| 129 |
# "" is returned rather than exiting with an error. |
| 130 |
# |
| 131 |
# The return value is a string like "-lpng -laquaterm", which |
| 132 |
# can be "". |
| 133 |
# |
| 134 |
# This is only used in the OS-X case. It is not currently guaranteed |
| 135 |
# to be complete since I have not made a complete study of the |
| 136 |
# drivers. |
| 137 |
# |
| 138 |
sub find_required_driver_libsscip-perl cpan PGPLOT 2.36 main/find_required_driver_libs(). ($) { |
| 139 |
my $indir = shiftscip-perl cpan PGPLOT 2.36 main/shift().; |
| 140 |
my $infile = "${indir}/drivers.list"; |
| 141 |
|
| 142 |
my $retval = ""; |
| 143 |
|
| 144 |
openscip-perl cpan PGPLOT 2.36 main/open(). my $fh, '<', $infile or return $retval; |
| 145 |
|
| 146 |
# known library requirements |
| 147 |
# |
| 148 |
my %libs = ( |
| 149 |
'PNDRIV' => 'png', |
| 150 |
'AQDRIV' => 'aquaterm', |
| 151 |
); |
| 152 |
|
| 153 |
while (<$fh>) { |
| 154 |
next if /^\s*$/ or /^!/; # /; (comment is to un-confuse emacs highlighting) |
| 155 |
chompscip-perl cpan PGPLOT 2.36 main/chomp().; |
| 156 |
my @words = splitscip-perl cpan PGPLOT 2.36 main/split().; |
| 157 |
if ( existsscip-perl cpan PGPLOT 2.36 main/exists(). $libs{$words[0]} ) { |
| 158 |
$retval .= " -l" . $libs{$words[0]}; |
| 159 |
deletescip-perl cpan PGPLOT 2.36 main/delete(). $libs{$words[0]}; # since the driver can appear multiple times in drivers.list |
| 160 |
} |
| 161 |
} |
| 162 |
$fh->closescip-perl cpan PGPLOT 2.36 main/close().; |
| 163 |
|
| 164 |
return $retval; |
| 165 |
|
| 166 |
} # sub: find_required_driver_libs() |
| 167 |
|
| 168 |
# What os are we using? |
| 169 |
# |
| 170 |
my $is_vms = $^Oscip-perl cpan PGPLOT 2.36 main/`$^O`. eq "VMS"; |
| 171 |
my $is_osx = $^Oscip-perl cpan PGPLOT 2.36 main/`$^O`. eq "darwin"; |
| 172 |
my $is_win32 = $^Oscip-perl cpan PGPLOT 2.36 main/`$^O`. =~ /mswin32/i; |
| 173 |
|
| 174 |
# Move the logic out of the WriteMakefile statement to make it a |
| 175 |
# bit easier to follow. We use the %items hash to store key,value |
| 176 |
# pairs that will be used in the WriteMakefile call. Note that |
| 177 |
# some key settings are platform specific. |
| 178 |
# |
| 179 |
my %items; |
| 180 |
|
| 181 |
$items{DEFINE} = "-DNO_TRAILING_USCORE" |
| 182 |
unless ExtUtils::F77->trail_scip-perl cpan PGPLOT 2.36 ExtUtils/F77/trail_().; |
| 183 |
|
| 184 |
$items{DLEXT} = "xs.dll" if $is_win32; |
| 185 |
|
| 186 |
if ( $is_vms ) { |
| 187 |
$items{INC} = 'pgplot_dir:'; |
| 188 |
$items{LIBS} = 'pgplot_dir:cpgplot.olb'; |
| 189 |
} else { |
| 190 |
|
| 191 |
$items{INC} = $IDIRS; |
| 192 |
|
| 193 |
$items{OBJECT} = '$(BASEEXT)$(OBJ_EXT) pgplot_tmp/libcpgplot.a ' . |
| 194 |
'pgplot_tmp/libpgplot.a' |
| 195 |
if -d 'pgplot_tmp'; |
| 196 |
|
| •197 |
$items{LIBS} = [ joinscip-perl cpan PGPLOT 2.36 main/join().( ' ', $LIBDIRS, $LIBS ) ]; |
| 198 |
|
| 199 |
# This is not ideal since it assumes that: |
| 200 |
# objc is required |
| 201 |
# the logic in find_required_driver_libs() is correct |
| 202 |
# the libraries are located either in a location pointed to by LDFLAGS |
| 203 |
# or in /sw/lib |
| 204 |
# |
| 205 |
if ($is_osx) { |
| 206 |
my $pgplot_dir = definedscip-perl cpan PGPLOT 2.36 main/defined(). $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{PGPLOT_DIR} ? $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{PGPLOT_DIR} : "/usr/lib"; |
| 207 |
my $dir = -d 'pgplot_tmp' ? 'pgplot_tmp' : $pgplot_dir; |
| 208 |
$items{LIBS}[0] .= " -lobjc " . |
| 209 |
(definedscip-perl cpan PGPLOT 2.36 main/defined(). $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{LDFLAGS} ? $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{LDFLAGS} : "-L/sw/lib") . |
| 210 |
find_required_driver_libsscip-perl cpan PGPLOT 2.36 main/find_required_driver_libs().($pgplot_dir); |
| 211 |
} |
| 212 |
|
| 213 |
# The following is needed for PGPLOT compiled on OS-X, at least |
| 214 |
# for both the version used from FINK and a hand-compiled version. |
| 215 |
# |
| 216 |
$items{LDDLFLAGS} = "$Config{lddlflags} -Wl,-framework -Wl,Foundation" |
| 217 |
if $is_osx; |
| 218 |
|
| 219 |
# Nasty hack to build only i386/x86_64 only instead of a Universal binary on OS X |
| 220 |
# I put this in to avoid an error if linking with the pgplot libs in |
| 221 |
# SciKarl (2.4.6 and above). Hope one day to remove this. |
| 222 |
# - Karl Glazebrook |
| 223 |
if ($is_osx) { |
| 224 |
|
| 225 |
$items{CCFLAGS} = $Configscip-perl cpan PGPLOT 2.36 main/`%Config`.{ccflags}; |
| 226 |
$items{LDFLAGS} = $Configscip-perl cpan PGPLOT 2.36 main/`%Config`.{ldflags}; |
| 227 |
$items{LDDLFLAGS} = $Configscip-perl cpan PGPLOT 2.36 main/`%Config`.{lddlflags}; |
| 228 |
|
| 229 |
# Added this 11/1/2021 to avoid warnings about 'compact unwinds' on MacOS11 |
| 230 |
my @darwin_vers = splitscip-perl cpan PGPLOT 2.36 main/split().("\\.",$Configscip-perl cpan PGPLOT 2.36 main/`%Config`.{osvers}); # Darwin version XX.YY.ZZ |
| 231 |
if ($darwin_vers[0]>=20) { # Big Sur |
| 232 |
$items{LDDLFLAGS} .= " -Wl,-no_compact_unwind"; # Avoid mess of warnings about this |
| 233 |
} |
| 234 |
|
| 235 |
# Karl - now figure out automagically WHICH binary arch |
| 236 |
# to build for and change the various flags |
| 237 |
|
| 238 |
mac_universalscip-perl cpan PGPLOT 2.36 main/mac_universal().( \$items{CCFLAGS}, \$items{LDFLAGS}, \$items{LDDLFLAGS}); |
| 239 |
printscip-perl cpan PGPLOT 2.36 main/print(). "TEST $items{CCFLAGS}\n"; |
| 240 |
printscip-perl cpan PGPLOT 2.36 main/print(). "TEST $items{LDFLAGS}\n"; |
| 241 |
printscip-perl cpan PGPLOT 2.36 main/print(). "TEST $items{LDDLFLAGS}\n"; |
| 242 |
|
| 243 |
|
| 244 |
} |
| 245 |
|
| 246 |
} |
| 247 |
|
| 248 |
my @prereq; |
| 249 |
my %min_version = ( |
| 250 |
'PDL' => '2.089', # broadcast_define, no PGPLOT |
| 251 |
); |
| 252 |
for my $opt_dep (sortscip-perl cpan PGPLOT 2.36 main/sort(). keysscip-perl cpan PGPLOT 2.36 main/keys(). %min_version) { |
| 253 |
(my $file = $opt_dep) =~ s#::#/#g; |
| 254 |
next if !eval { requirescip-perl cpan PGPLOT 2.36 main/require(). "$file.pm"; 1 }; # not installed, fine |
| 255 |
next if eval { $opt_dep->VERSIONscip-perl cpan PGPLOT 2.36 main/VERSION().($min_version{$opt_dep}); 1 }; |
| 256 |
pushscip-perl cpan PGPLOT 2.36 main/push(). @prereq, $opt_dep => $min_version{$opt_dep}; |
| 257 |
} |
| 258 |
|
| 259 |
WriteMakefilescip-perl cpan PGPLOT 2.36 main/WriteMakefile().( |
| 260 |
'NAME' => 'PGPLOT', |
| 261 |
MIN_PERL_VERSION => '5.010001', |
| 262 |
'CONFIGURE_REQUIRES' => { 'ExtUtils::F77' => 1.13, 'Devel::CheckLib' => '1.14' }, |
| 263 |
'TEST_REQUIRES' => { 'Test::More' => '0.88' }, |
| 264 |
PREREQ_PM => { @prereq }, |
| 265 |
'VERSION_FROM' => 'lib/PGPLOT.pm', |
| 266 |
'dist' => { COMPRESS=>"gzip", SUFFIX=>"gz" }, |
| 267 |
'depend' => { '$(OBJECT)' => q[pgfun.c arrays.c PGPLOT.c]}, |
| 268 |
'META_MERGE' => { |
| 269 |
"meta-spec" => { version => 2 }, |
| 270 |
dynamic_config => 1, # deps actually do change |
| 271 |
resources => { |
| 272 |
bugtracker => {web=>'https://github.com/PDLPorters/perl5-PGPLOT/issues'}, |
| 273 |
repository => { |
| 274 |
url => 'git://github.com/PDLPorters/perl5-PGPLOT.git', |
| 275 |
type => 'git', |
| 276 |
web => 'https://github.com/PDLPorters/perl5-PGPLOT', |
| 277 |
}, |
| 278 |
}, |
| 279 |
prereqs => { |
| 280 |
develop => { |
| 281 |
requires => { |
| 282 |
'CPAN::Changes' => '0', |
| 283 |
}, |
| 284 |
}, |
| 285 |
runtime => { |
| 286 |
recommends => \%min_version, |
| 287 |
requires => {}, |
| 288 |
}, |
| 289 |
}, |
| 290 |
x_IRC => 'irc://irc.perl.org/#pdl', |
| 291 |
}, |
| 292 |
%items |
| 293 |
); |
| 294 |
|
| 295 |
|
| 296 |
# This subroutine is a nasty hack to modify OS X compile strings |
| 297 |
# to only build for a single architectutre |
| 298 |
# Karl Glazebrook (Dec 2010); |
| 299 |
|
| 300 |
sub mac_universalscip-perl cpan PGPLOT 2.36 main/mac_universal(). { # Note args passed as refs otherwise don't get modified! |
| 301 |
my @args = @_scip-perl cpan PGPLOT 2.36 main/`@_`.; |
| 302 |
my $s = ${$args[0]}; |
| 303 |
|
| 304 |
my $count=0; |
| 305 |
|
| 306 |
# Do matching against various combinations of |
| 307 |
# -arch ppc -arch i386 -arch x86_64 |
| 308 |
# Prefer i386 then prefer x86_64. |
| 309 |
|
| 310 |
|
| 311 |
$count++ while $s =~ /-arch\s\S+/g; |
| 312 |
return if $count <2; # Do nothing |
| 313 |
|
| 314 |
printscip-perl cpan PGPLOT 2.36 main/print(). "\nMac OS X with multiple architecture perl detected...\n"; |
| 315 |
printscip-perl cpan PGPLOT 2.36 main/print(). "Trying to figure out which arch to build for...\n"; |
| 316 |
|
| 317 |
# Figure out which single architecture to build for |
| 318 |
# when we have more than one |
| 319 |
|
| 320 |
my $singlearch = 'x86_64'; |
| 321 |
$singlearch = 'i386' if $s=~/-arch\s+i386/ & $s=~/-arch\s+ppc/; |
| 322 |
$singlearch = 'x86_64' if $s=~/-arch\s+x86_64/; |
| 323 |
|
| 324 |
# If we can find pgplot's xwindow server try and match the arch it is built for |
| 325 |
|
| 326 |
my $pgarch = ''; |
| 327 |
my $f1 = `which pgxwin_server`; chompscip-perl cpan PGPLOT 2.36 main/chomp(). $f1; # Find in path |
| 328 |
$f1 = '/usr/local/bin/pgxwin_server' if !-e $f1; # Backuo choice |
| 329 |
|
| 330 |
if (-e $f1) { |
| 331 |
printscip-perl cpan PGPLOT 2.36 main/print(). "- Found $f1, trying to determine binary type\n"; |
| 332 |
my $exe = `file $f1`; chompscip-perl cpan PGPLOT 2.36 main/chomp(). $exe; |
| 333 |
$pgarch = (splitscip-perl cpan PGPLOT 2.36 main/split().(' ',$exe))[-1]; |
| 334 |
} |
| 335 |
if ($pgarch ne '') { |
| 336 |
printscip-perl cpan PGPLOT 2.36 main/print(). "- Found binary type $pgarch\n"; |
| 337 |
$singlearch = $pgarch; |
| 338 |
} |
| 339 |
|
| 340 |
printscip-perl cpan PGPLOT 2.36 main/print(). "- Building for single architecture -arch $singlearch\n"; |
| 341 |
# Now substitute the single arch for the multiple pnes |
| 342 |
|
| 343 |
my $t; |
| 344 |
for $t (@args) { |
| 345 |
$$t =~ s/-arch\s\S+/TESTMARKER/; # Temp mark first occurence |
| 346 |
$$t =~ s/-arch\s\S+/ /g; # Remove all -arch's |
| 347 |
$$t =~ s/TESTMARKER/-arch $singlearch/; # Put one back |
| 348 |
printscip-perl cpan PGPLOT 2.36 main/print(). "\nRESULT: $$t\n"; |
| 349 |
} |
| 350 |
|
| 351 |
} |