Debian Codegraph @

Makefile.PL

raw symbols ◀ ▶ SCIP
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 );
118
119 my $IDIRS = join( ' ', map { "-I$_" } 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_libs ($) {
139 my $indir = shift;
140 my $infile = "${indir}/drivers.list";
141
142 my $retval = "";
143
144 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 chomp;
156 my @words = split;
157 if ( exists $libs{$words[0]} ) {
158 $retval .= " -l" . $libs{$words[0]};
159 delete $libs{$words[0]}; # since the driver can appear multiple times in drivers.list
160 }
161 }
162 $fh->close;
163
164 return $retval;
165
166 } # sub: find_required_driver_libs()
167
168 # What os are we using?
169 #
170 my $is_vms = $^O eq "VMS";
171 my $is_osx = $^O eq "darwin";
172 my $is_win32 = $^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_;
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} = [ 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 = defined $ENV{PGPLOT_DIR} ? $ENV{PGPLOT_DIR} : "/usr/lib";
207 my $dir = -d 'pgplot_tmp' ? 'pgplot_tmp' : $pgplot_dir;
208 $items{LIBS}[0] .= " -lobjc " .
209 (defined $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "-L/sw/lib") .
210 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} = $Config{ccflags};
226 $items{LDFLAGS} = $Config{ldflags};
227 $items{LDDLFLAGS} = $Config{lddlflags};
228
229 # Added this 11/1/2021 to avoid warnings about 'compact unwinds' on MacOS11
230 my @darwin_vers = split("\\.",$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_universal( \$items{CCFLAGS}, \$items{LDFLAGS}, \$items{LDDLFLAGS});
239 print "TEST $items{CCFLAGS}\n";
240 print "TEST $items{LDFLAGS}\n";
241 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 (sort keys %min_version) {
253 (my $file = $opt_dep) =~ s#::#/#g;
254 next if !eval { require "$file.pm"; 1 }; # not installed, fine
255 next if eval { $opt_dep->VERSION($min_version{$opt_dep}); 1 };
256 push @prereq, $opt_dep => $min_version{$opt_dep};
257 }
258
259 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_universal { # Note args passed as refs otherwise don't get modified!
301 my @args = @_;
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 print "\nMac OS X with multiple architecture perl detected...\n";
315 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`; chomp $f1; # Find in path
328 $f1 = '/usr/local/bin/pgxwin_server' if !-e $f1; # Backuo choice
329
330 if (-e $f1) {
331 print "- Found $f1, trying to determine binary type\n";
332 my $exe = `file $f1`; chomp $exe;
333 $pgarch = (split(' ',$exe))[-1];
334 }
335 if ($pgarch ne '') {
336 print "- Found binary type $pgarch\n";
337 $singlearch = $pgarch;
338 }
339
340 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 print "\nRESULT: $$t\n";
349 }
350
351 }