Debian Codegraph @

Makefile.PL

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