This file is indexed.

/usr/lib/x86_64-linux-gnu/perl5/5.24/Module/Build/FFI.pm is in libffi-platypus-perl 0.45-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
package Module::Build::FFI;

use strict;
use warnings;
use ExtUtils::CBuilder;
use File::Glob       qw( bsd_glob );
use File::Spec       ();
use File::ShareDir   ();
use File::Path       ();
use Text::ParseWords ();
use Config;
use base qw( Module::Build );

# ABSTRACT: Build Perl extensions in C with FFI
our $VERSION = '0.45'; # VERSION


__PACKAGE__->add_property( ffi_libtest_dir =>
  default => [ 'libtest' ],
);

__PACKAGE__->add_property( ffi_include_dir =>
  default => [ 'include' ],
);

__PACKAGE__->add_property( ffi_libtest_optional =>
  default => 1,
);

__PACKAGE__->add_property( ffi_source_dir => 
  default => [ 'ffi' ],
);

sub _inflate ($)
{
  my($self) = @_;
  $self->ffi_source_dir([$self->ffi_source_dir])
    unless ref $self->ffi_source_dir;

  $self->ffi_libtest_dir([$self->ffi_libtest_dir])
    unless ref $self->ffi_libtest_dir;
}

sub new
{
  my($class, %args) = @_;

  my $self = $class->SUPER::new(%args);

  _inflate($self);
  my $have_compiler = $self->ffi_have_compiler;

  if(-d $self->ffi_source_dir->[0] && !$have_compiler)
  {
    print STDERR "This distribution requires a compiler\n";
    exit;
  }
  
  if(-d $self->ffi_libtest_dir->[0] && !$self->ffi_libtest_optional && !$have_compiler)
  {
    print STDERR "This distribution requires a compiler\n";
    exit;
  }

  $self;
}


my @cpp_extensions = qw( c cpp cxx cc c++ );

sub ffi_have_compiler
{
  my($self) = @_;
  
  my $cpp = 0;
  
  foreach my $dir (@{ $self->ffi_source_dir }, @{ $self->ffi_libtest_dir })
  {
    next unless -d $dir;
    $cpp = 1 if scalar map { bsd_glob("$dir/*.$_") } @cpp_extensions;
  }
  
  my $cb = $self->cbuilder;
  $cpp ? $cb->have_cplusplus && $cb->have_compiler : $cb->have_compiler;
}


sub _ffi_headers ($$)
{
  my($self, $dir) = @_;

  my @headers;
  
  my @dirs = @$dir;
  push @dirs, grep { -d $_ } ref $self->ffi_include_dir ? @{ $self->ffi_include_dir } : ($self->ffi_include_dir);

  push @headers, map { bsd_glob("$_/*.h") } @dirs;
  
  \@headers;
}

sub _ffi_include_dirs ($$)
{
  my($self, $dir) = @_;
  
  my @includes = (@$dir);

  push @includes, grep { -d $_ } ref $self->ffi_include_dir ? @{ $self->ffi_include_dir } : ($self->ffi_include_dir);

  push @includes, $ENV{FFI_PLATYPUS_INCLUDE_DIR} || File::Spec->catdir(File::ShareDir::dist_dir('FFI-Platypus'), 'include');

  push @includes, ref($self->include_dirs) ? @{ $self->include_dirs } : $self->include_dirs
    if defined $self->include_dirs;
  
  \@includes;
}


sub ffi_build_dynamic_lib ($$$;$)
{
  my($self, $dirs, $name, $dest_dir) = @_;
  
  $dest_dir ||= $dirs->[0];
  
  my $header_time = do {
    my @list = sort map { (stat $_)[9] } @{ _ffi_headers $self, $dirs };
    pop @list;
  } || 0;
  my $compile_count = 0;
  my $b = $self->cbuilder;

  my @obj;
  
  foreach my $dir (@$dirs)
  {
    push @obj,  map {
      my $filename = $_;
      my($source_time) = reverse sort ((stat $filename)[9], $header_time);
      my $obj_name = $b->object_file($filename);
      $self->add_to_cleanup($obj_name);
      my $obj_time = -e $obj_name ? ((stat $obj_name)[9]) : 0;

      my %compile_options = (
        source               => $filename,
        include_dirs         => _ffi_include_dirs($self, $dirs),
        extra_compiler_flags => $self->extra_compiler_flags,
      );
      $compile_options{"C++"} = 1 if $filename =~ /\.(cpp|cxx|cc|\c\+\+)$/;

      if($obj_time < $source_time)
      {
        $b->compile(%compile_options);
        $compile_count++;
      }
      $obj_name;
    } sort map { bsd_glob("$dir/*.$_") } qw( c cpp cxx cc c++ s );
  }

  return unless $compile_count > 0;

  if($^O ne 'MSWin32')
  {
    return $b->link(
      lib_file           => $b->lib_file(File::Spec->catfile($dest_dir, $b->object_file("$name.c"))),
      objects            => \@obj,
      extra_linker_flags => $self->extra_linker_flags,
    );
  }
  else
  {
    # On windows we can't depend on MM::CBuilder to make the .dll file because it creates dlls
    # that export only one symbol (which is used for bootstrapping XS modules).
    my $dll = File::Spec->catfile($dest_dir, "$name.dll");
    $dll =~ s{\\}{/}g;
    my @cmd;
    my $cc = $Config{cc};
    if($cc !~ /cl(.exe)?$/i)
    {
      my $lddlflags = $Config{lddlflags};
      $lddlflags =~ s{\\}{/}g;
      @cmd = ($cc, Text::ParseWords::shellwords($lddlflags), -o => $dll, "-Wl,--export-all-symbols", @obj);
    }
    else
    {
      @cmd = ($cc, @obj, '/link', '/dll', '/out:' . $dll);
    }
    print "@cmd\n";
    system @cmd;
    exit 2 if $?;
    return $dll;
  }
}


sub ffi_dlext
{
  require FFI::Platypus::ConfigData;
  @{ FFI::Platypus::ConfigData->config('config_dlext') };
}

sub _ffi_libtest_name ()
{
  $^O eq 'cygwin' ? 'cygtest-1' : $^O eq 'msys' ? 'msys-test-1' : 'libtest';
}

sub ACTION_libtest
{
  my $self = shift;
  _inflate($self);
  my @dirs = @{ $self->ffi_libtest_dir };
  
  return unless -d $dirs[0];
  
  foreach my $dir (@dirs)
  {
    $self->add_to_cleanup(map { "$dir/$_" } qw(
      *.o
      *.obj
      *.so
      *.dll
      *.bundle
    ));
  }
  
  my $have_compiler = $self->ffi_have_compiler;
  
  unless($have_compiler)
  {
    print STDERR "libtest directory is included, but not compiler is available\n";
    print STDERR "some tests may fail if they depend on libtest\n";
    return;
  }
  
  $self->ffi_build_dynamic_lib(\@dirs, _ffi_libtest_name);
}

sub ACTION_ffi
{
  my $self = shift;
  _inflate($self);
  my @dirs = @{ $self->ffi_source_dir };
  
  return unless -d $dirs[0];
  
  foreach my $dir (@dirs)
  {
    $self->add_to_cleanup(map { "$dir/$_" } qw(
      *.o
      *.obj
      *.so
      *.dll
      *.bundle
    ));
  }
  
  unless($self->ffi_have_compiler)
  {
    print STDERR "a compiler is required.\n";
    exit 2;
  }

  die "Can't determine module name" unless $self->module_name;
  my @parts = split /::/, $self->module_name;

  my $arch_dir = File::Spec->catdir($self->blib, 'arch', 'auto', @parts);  
  File::Path::mkpath($arch_dir, 0, oct(777)) unless -d $arch_dir;

  my $name = $parts[-1];
  # yes, of course Strawberry has to be "different"
  if($^O eq 'MSWin32' && $Config{dlext} eq 'xs.dll')
  {
    $name = "$name.xs";
  }

  $self->ffi_build_dynamic_lib(\@dirs, $name, $arch_dir);
}

sub ACTION_build
{
  my $self = shift;
  $self->depends_on('ffi');
  $self->SUPER::ACTION_build(@_);
}

sub ACTION_test
{
  my $self = shift;
  $self->depends_on('libtest');
  $self->SUPER::ACTION_test(@_);
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Module::Build::FFI - Build Perl extensions in C with FFI

=head1 VERSION

version 0.45

=head1 SYNOPSIS

In your C<Build.PL>

 use Modue::Build::FFI 0.04;
 Module::Build::FFI->new(
   module_name => 'Foo::Bar',
   ...
 )->create_build_script;

or C<dist.ini>:

 [ModuleBuild]
 mb_class = Module::Build::FFI
 
 [Prereqs / ConfigureRequires]
 Module::Build::FFI = 0.04

Put your .c and .h files in C<ffi> (C<ffi/example.c>):

 #include <ffi_util.h>
 #include <stdio.h>
 
 FFI_UTIL_EXPORT void
 print_hello(void)
 {
   printf("hello world\n");
 }

Attach it to Perl in your main module (C<lib/Foo/Bar.pm>):

 package Foo::Bar;
 
 use FFI::Platypus;
 
 my $ffi = FFI::Platypus->new;
 $ffi->package;  # search for symbols in your bundled C code
 $ffi->attach( hello_world => [] => 'void');

Finally, use it from your perl script or module:

 use Foo::Bar;
 Foo::Bar::hello_world();  # prints "hello world\n"

=head1 DESCRIPTION

Module::Build variant for writing Perl extensions in C and FFI (sans XS).

=head1 PROPERTIES

=over 4

=item ffi_source_dir

[version 0.15]

By default, C source files in the C<ffi> directory are compiled and
linked, if that directory exists.  You can change that directory
with this property.

[version 0.18]

This can be a scalar or a array reference.

=item ffi_libtest_dir

[version 0.15]

If the libtest directory (C<libtest> by default) exists, then C source
files will be compiled and linked into a test dynamic library that you
can use to test your FFI module with.  You can use FFI::CheckLib to
find the library from your test:

 use Test::More;
 use FFI::Platypus;
 use FFI::CheckLib;
 
 FFI::Platypus->new->lib(find_lib lib => 'test', libpath => 'libtest');

[version 0.18]

This can be a scalar or a array reference.

=item ffi_include_dir

[version 0.15]

If there is an C<include> directory with your distribution with C header
files in it, it will be included in the search path for the C files in
both the C<ffi> and C<libtest> directories.

[version 0.18]

This can be a scalar or a array reference.

=item ffi_libtest_optional

[version 0.15]

If there is no compiler then libtest cannot be built.  By default this is
not fatal.  Your tests need to be written in such a way that any that use
libtest are skipped when it is not there.

 use Test::More;
 use FFI::CheckLib;
 
 plan skip_all => 'test requires a compiler'
   unless find_lib lib => 'test', libpath => 'libtest';

If you do not want to support environments without a compiler you can set
this property to C<1> and you won't need to have that check in your test
files.

=back

=head1 ACTIONS

=head2 ffi

 ./Build ffi

This builds any C files that are bundled with your distribution (usually
in the C<ffi> directory).  If there is no C<ffi> directory, then this
action does nothing.

This action is triggered automatically before C<./Build build>.

=head2 libtest

 ./Build libtest

This builds libtest.  If you do not have a libtest directory, then
this action does nothing.

This action is triggered automatically before C<./Build test>.

=head1 MACROS

Defined in C<ffi_util.h>

=over 4

=item FFI_UTIL_VERSION

[version 0.04]

This is the L<FFI::Platypus> (prior to version 0.15 it was the 
L<FFI::Util> version number) version number multiplied by 100 (so it 
would be 4 for 0.04 and 101 for 1.01).

=item FFI_UTIL_EXPORT

[version 0.04]

The appropriate attribute needed to export functions from shared 
libraries / DLLs.  For now this is only necessary on Windows when using 
Microsoft Visual C++, but it may be necessary elsewhere in the future.

=back

=head1 METHODS

=head2 ffi_have_compiler

[version 0.18]

 my $has_compiler = $mb->ffi_have_compiler;

Returns true if a C or C++ compiler is available.

Only checks for C++ if you appear to have C++ source.

Override for other foreign language subclasses.

=head2 ffi_build_dynamic_lib

[version 0.18]

 my $dll_path = $mb->ffi_build_dynamic_lib($src_dir, $name, $target_dir);
 my $dll_path = $mb->ffi_build_dynamic_lib($src_dir, $name);

Compiles the C and C++ source in the C<$src_dir> and link it into a
dynamic library with base name of C<$name.$Config{dlext}>.  If
C<$target_dir> is specified then the dynamic library will be delivered
into that directory.

Override for other foreign language subclasses.

=head2 ffi_dlext

 my @dlext = Module::Build::FFI->ffi_dlext;

Returns a list of legal dynamic library extensions.  C<$Config{dlext}> is good,
but many platforms use more than one extension for dynamic libraries.  For
example, on Mac OS X, there are two different dynamic library types C<.bundle>
and C<.dylib> and sometimes these renamed C<.so> files.  Although C<.bundle>
and C<.dylib> have subtle differences, they can both be used by L<FFI::Platypus>.

=head1 AUTHOR

Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>

Contributors:

Bakkiaraj Murugesan (bakkiaraj)

Dylan Cali (calid)

pipcet

Zaki Mughal (zmughal)

Fitz Elliott (felliott)

Vickenty Fesunov (vyf)

Gregor Herrmann (gregoa)

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut