Alien-Bit
view release on metacpan or search on metacpan
# This builds the test program too
['%{make} test'],
# This builds the benchmark programs
['%{make} bench']
];
# Post-build file handling - copy files to staging directory
after 'build' => sub {
my ($build) = @_;
# Determine destination directory
my $stage_dir = path( $build->install_prop->{stage} );
my $source_dir = path( $build->install_prop->{extract} );
# Create lib and include directories
my $lib_dir = $stage_dir->child('lib');
my $include_dir = $stage_dir->child('include');
$lib_dir->mkpath;
$include_dir->mkpath;
# Copy shared library to lib directory
my $build_dir = $source_dir->child('build');
my @libs;
# Handle different platform library extensions
if ( $^O eq 'MSWin32' ) {
@libs = $build_dir->children(qr/\.(dll|lib)$/);
}
elsif ( $^O eq 'darwin' ) {
@libs = $build_dir->children(qr/\.(dylib|a)$/);
}
else {
@libs = $build_dir->children(qr/\.(so|a)$/);
}
# Copy each library file
foreach my $lib (@libs) {
my $dest = $lib_dir->child( $lib->basename );
$lib->copy($dest) or croak "Failed to copy $lib to $dest: $!";
print "Copied library: ", $lib->basename, "\n";
}
# Copy test and benchmark executables
my @executables;
if ( $^O eq 'MSWin32' ) {
@executables = $build_dir->children(qr/\.(exe)$/);
}
else {
@executables = grep {
-x $_
&& !-d $_
&& $_->basename !~ /\.(so|dylib|dll|o|a)$/
} $build_dir->children;
}
foreach my $exe (@executables) {
my $dest = $lib_dir->child( $exe->basename );
$exe->copy($dest) or croak "Failed to copy $exe to $dest: $!";
chmod 0755, $dest; # Ensure executable permissions
print "Copied executable: ", $exe->basename, "\n";
}
# Copy header files
my $headers_dir = $source_dir->child('include');
my @headers = $headers_dir->children(qr/\.h$/);
foreach my $header (@headers) {
my $dest = $include_dir->child( $header->basename );
$header->copy($dest) or croak "Failed to copy $header to $dest: $!";
print "Copied header: ", $header->basename, "\n";
}
};
# Set runtime properties for client code
gather sub {
my ($build) = @_;
my $prefix = $build->runtime_prop->{prefix};
# Set include and library paths
my $include_dir = path( $prefix, 'include' )->stringify;
my $lib_dir = path( $prefix, 'lib' )->stringify;
# Set compiler flags
$build->runtime_prop->{cflags} = "-I$include_dir";
# Set linker flags with appropriate library name
$build->runtime_prop->{libs} = "-L$lib_dir -lbit";
# Store raw paths for Platypus FFI
$build->runtime_prop->{ffi_name} = "bit";
$build->runtime_prop->{include_dir} = $include_dir;
$build->runtime_prop->{lib_dir} = $lib_dir;
# Print confirmation
print "Alien::Bit configured with:\n";
print " cflags: ", $build->runtime_prop->{cflags}, "\n";
print " libs: ", $build->runtime_prop->{libs}, "\n";
print " ffi_name: ", $build->runtime_prop->{ffi_name}, "\n";
print " include_dir: ", $build->runtime_prop->{include_dir}, "\n";
print " lib_dir: ", $build->runtime_prop->{lib_dir}, "\n";
};
# Run tests after installation
test sub {
my ($build) = @_;
my $lib_dir = path( $build->install_prop->{stage}, 'lib' );
# Define test executable names based on platform
my $test_exe = $^O eq 'MSWin32' ? 'test_bit.exe' : 'test_bit';
my $bench_exe = $^O eq 'MSWin32' ? 'benchmark.exe' : 'benchmark';
my $gpu_bench = (uc $ENV{GPU} eq 'NONE') ? "_nogpu" : "";
my $openmp_exe = $^O eq 'MSWin32' ? "openmp_bit${gpu_bench}.exe" : "openmp_bit${gpu_bench}";
# Get full paths
my $test_path = $lib_dir->child($test_exe);
my $bench_path = $lib_dir->child($bench_exe);
my $openmp_path = $lib_dir->child($openmp_exe);
# Run main tests if available
( run in 0.425 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )