ExtUtils-LibBuilder-0.08000755000765000024 012611220356 14441 5ustar00ambsstaff000000000000ExtUtils-LibBuilder-0.08/Build.PL000444000765000024 147112611220356 16075 0ustar00ambsstaff000000000000use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'ExtUtils::LibBuilder', license => 'perl', dist_author => q{Alberto Simoes }, dist_version_from => 'lib/ExtUtils/LibBuilder.pm', requires => { 'perl' => '5.006', }, build_requires => { 'ExtUtils::CBuilder' => '0.23', 'File::Spec' => 0, 'File::Temp' => 0, 'Test::More' => 0, }, add_to_cleanup => [ 'ExtUtils-LibBuilder-*' ], meta_merge => { resources => { repository => 'http://github.com/ambs/ExtUtils-LibBuilder', }, }, ); $builder->create_build_script(); ExtUtils-LibBuilder-0.08/Changes000444000765000024 207012611220356 16070 0ustar00ambsstaff000000000000Revision history for ExtUtils-LibBuilder 0.08 Mon Oct 19 17:46:02 WEST 2015 - Minor spelling fix (thanks to Gregor Herrmann, from Debian community). 0.07 Mon Sep 28 14:53:40 WEST 2015 - Added minimum required Perl Version (kwalitee++). 0.06 Sun Aug 31 21:02:44 WEST 2014 - Fixed metadata for metacpan (thanks to Gabor Szabo). 0.05 Sun Aug 31 13:44:44 WEST 2014 - Added metadata for metacpan. 0.04 Sun Nov 21 13:38:35 WET 2010 - Trying my luck on IRIX... 0.03 Sat Oct 9 15:06:40 WEST 2010 - Mainly documentation fixes. 0.02 Fri Sep 24 09:34:01 WEST 2010 - Fixed tests and their relative search paths. 0.01 Thu Sep 23 21:19:17 WEST 2010 - Ported the code from Config::AutoConf::Linker to this new module - Factorized the code for readability and usability - Still missing real documentation (check t/01-simple.t for an example) - Should work on Linux, MacOS X and Strawberry Perl. Let me know of other supported operating systems. Thank you! ExtUtils-LibBuilder-0.08/MANIFEST000444000765000024 20212611220356 15701 0ustar00ambsstaff000000000000Build.PL Changes MANIFEST README lib/ExtUtils/LibBuilder.pm t/00-load.t t/01-simple.t t/pod-coverage.t t/pod.t META.yml META.json ExtUtils-LibBuilder-0.08/META.json000444000765000024 232312611220356 16217 0ustar00ambsstaff000000000000{ "abstract" : "A tool to build C libraries.", "author" : [ "Alberto Simoes " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4214", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "ExtUtils-LibBuilder", "prereqs" : { "build" : { "requires" : { "ExtUtils::CBuilder" : "0.23", "File::Spec" : "0", "File::Temp" : "0", "Test::More" : "0" } }, "configure" : { "requires" : { "Module::Build" : "0.42" } }, "runtime" : { "requires" : { "perl" : "5.006" } } }, "provides" : { "ExtUtils::LibBuilder" : { "file" : "lib/ExtUtils/LibBuilder.pm", "version" : "0.08" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "http://github.com/ambs/ExtUtils-LibBuilder" } }, "version" : "0.08", "x_serialization_backend" : "JSON::PP version 2.27300" } ExtUtils-LibBuilder-0.08/META.yml000444000765000024 137712611220356 16057 0ustar00ambsstaff000000000000--- abstract: 'A tool to build C libraries.' author: - 'Alberto Simoes ' build_requires: ExtUtils::CBuilder: '0.23' File::Spec: '0' File::Temp: '0' Test::More: '0' configure_requires: Module::Build: '0.42' dynamic_config: 1 generated_by: 'Module::Build version 0.4214, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: ExtUtils-LibBuilder provides: ExtUtils::LibBuilder: file: lib/ExtUtils/LibBuilder.pm version: '0.08' requires: perl: '5.006' resources: license: http://dev.perl.org/licenses/ repository: http://github.com/ambs/ExtUtils-LibBuilder version: '0.08' x_serialization_backend: 'CPAN::Meta::YAML version 0.016' ExtUtils-LibBuilder-0.08/README000444000765000024 242012611220356 15454 0ustar00ambsstaff000000000000 == ExtUtils-LibBuilder == Some Perl modules need to ship C libraries together with their Perl code. Although there are mechanisms to compile and link (or glue) C code in your Perl programs, there isn't a clear method to compile standard, self-contained C libraries. This module main goal is to help in that task. INSTALLATION To install this module, run the following commands: perl Build.PL ./Build ./Build test ./Build install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc ExtUtils::LibBuilder You can also look for information at: RT, CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=ExtUtils-LibBuilder AnnoCPAN, Annotated CPAN documentation http://annocpan.org/dist/ExtUtils-LibBuilder CPAN Ratings http://cpanratings.perl.org/d/ExtUtils-LibBuilder Search CPAN http://search.cpan.org/dist/ExtUtils-LibBuilder/ LICENSE AND COPYRIGHT Copyright (C) 2010 Alberto Simoes This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. ExtUtils-LibBuilder-0.08/lib000755000765000024 012611220356 15207 5ustar00ambsstaff000000000000ExtUtils-LibBuilder-0.08/lib/ExtUtils000755000765000024 012611220356 16770 5ustar00ambsstaff000000000000ExtUtils-LibBuilder-0.08/lib/ExtUtils/LibBuilder.pm000444000765000024 1335112611220356 21523 0ustar00ambsstaff000000000000package ExtUtils::LibBuilder; use warnings; use strict; our $VERSION = '0.08'; our $DEBUG = 0; use base 'ExtUtils::CBuilder'; use File::Spec; use File::Temp qw/tempdir/; =head1 NAME ExtUtils::LibBuilder - A tool to build C libraries. =head1 SYNOPSIS use ExtUtils::LibBuilder; my $libbuilder = ExtUtils::LibBuilder->new( %options ); =head1 METHODS Supports all the method from ExtUtils::CBuilder. The following three methods were adapted to be used in standalone C libraries. =head2 new This method creates a new ExtUtils::LibBuilder object. While it supports all C methods some might work slightly differently (namely the two below). You can supply to the constructor any option recognized by C constructor. None of them will be used by C. =head2 link $libbuilder -> link( objects => [ "foo.o", "bar.o" ], module_name => "foobar", lib_file => "libfoobar$libbuilder->{libext}"); Options to the link method are the same as the C counterpart. Note that the result is a standalone C Library and not a bundle to be loaded by Perl. Also, note that you can use the C key to retrieve from the object the common library extension on the running system (including the dot). =head2 link_executable $libbuilder->link_executable( objects => ["main.o"], extra_linker_flags => "-L. -lfoobar", exe_file => "foobarcmd$libbuilder->{exeext}"); The C needs, as C options, the name of the library and the search path. Future versions might include better handling on the library files. Also, note that you can use the C key to retrieve from the object the common executable extension on the running system (including the dot). =cut sub new { my $class = shift; my %options = @_; my $self = bless ExtUtils::CBuilder->new(%options) => $class; # $self->{quiet} = 1; $self->{libext} = $^O eq "darwin" ? ".dylib" : ( $^O =~ /win/i ? ".dll" : ".so"); $self->{exeext} = $^O =~ /win32/i ? ".exe" : ""; $DEBUG && print STDERR "\nTesting Linux\n\n"; return $self if $^O !~ /darwin|win32/i && $self->_try; $DEBUG && print STDERR "\nTesting Darwin\n\n"; $self->{config}{lddlflags} =~ s/-bundle/-dynamiclib/; return $self if $^O !~ /win32/i && $self->_try; $DEBUG && print STDERR "\nTesting Win32\n\n"; *link = sub { my ($self, %options) = @_; my $LD = $self->{config}{ld}; $options{objects} = [$options{objects}] unless ref $options{objects}; system($LD, "-shared", "-o", $options{lib_file}, @{$options{objects}}); }; *link_executable = sub { my ($self, %options) = @_; my $LD = $self->{config}{ld}; my @CFLAGS = split /\s+/, $options{extra_linker_flags}; $options{objects} = [$options{objects}] unless ref $options{objects}; system($LD, "-o", $options{exe_file}, @CFLAGS, @{$options{objects}}); }; return $self if $self->_try; $DEBUG && print STDERR "\nNothing...\n\n"; return undef; } sub _try { my ($self) = @_; my $tmp = tempdir CLEANUP => 1; _write_files($tmp); my @csources = map { File::Spec->catfile($tmp, $_) } qw'library.c test.c'; my @cobjects = map { $self->compile( source => $_) } @csources; my $libfile = File::Spec->catfile($tmp => "libfoo$self->{libext}"); my $exefile = File::Spec->catfile($tmp => "foo$self->{exeext}"); $self->link( objects => [$cobjects[0]], module_name => "foo", lib_file => $libfile ); return 0 unless -f $libfile; $self->link_executable( exe_file => $exefile, extra_linker_flags => "-L$tmp -lfoo", objects => [$cobjects[1]]); return 0 unless -f $exefile && -x _; return 1; } =head1 AUTHOR Alberto Simoes, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc ExtUtils::LibBuilder You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 LICENSE AND COPYRIGHT Copyright 2010 Alberto Simoes. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut sub _write_files { my $outpath = shift; my $fh; seek DATA, 0, 0; while() { if (m!^==\[(.*?)\]==!) { my $fname = $1; $fname = File::Spec->catfile($outpath, $fname); open $fh, ">$fname" or die "Can't create temporary file $fname\n"; } elsif ($fh) { print $fh $_; } } } 1; # End of ExtUtils::LibBuilder __DATA__ ==[library.c]== int answer(void) { return 42; } ==[test.c]== #include extern int answer(void); int main() { int a = answer(); printf("%d\n", a); return 0; } ExtUtils-LibBuilder-0.08/t000755000765000024 012611220356 14704 5ustar00ambsstaff000000000000ExtUtils-LibBuilder-0.08/t/00-load.t000444000765000024 30512611220356 16340 0ustar00ambsstaff000000000000#!perl -T use Test::More tests => 1; BEGIN { use_ok( 'ExtUtils::LibBuilder' ) || print "Bail out!\n"; } diag( "Testing ExtUtils::LibBuilder $ExtUtils::LibBuilder::VERSION, Perl $], $^X" ); ExtUtils-LibBuilder-0.08/t/01-simple.t000444000765000024 371412611220356 16742 0ustar00ambsstaff000000000000#!perl use Test::More tests => 7; use ExtUtils::LibBuilder; our @CLEAN; my $libbuilder = ExtUtils::LibBuilder->new(); isa_ok($libbuilder, 'ExtUtils::CBuilder'); open OUT, ">", "lib.c" or die "Can't create test file"; print OUT <<'EOT'; int sum(int a, int b) { return a + b; } EOT close OUT; add_to_cleanup("lib.c"); $libbuilder->compile( source => 'lib.c' ); ok(-f "lib.o"); add_to_cleanup("lib.o"); $libbuilder->link( objects => "lib.o", module_name => "bar", lib_file => "libbar$libbuilder->{libext}"); ok(-f "libbar$libbuilder->{libext}"); add_to_cleanup("libbar$libbuilder->{libext}"); open OUT, ">", "main.c" or die "Can't create test file"; print OUT <<'EOT'; #include extern int sum(int a, int b); int main(void) { int a, b, c; a = 5; b = sum(a, a); c = sum(a, b); printf("%d\n", c); return 0; } EOT close OUT; add_to_cleanup("main.c"); $libbuilder->compile( source => 'main.c' ); add_to_cleanup("main.o"); ok(-f "main.o"); $libbuilder->link_executable( exe_file => "add$libbuilder->{exeext}", extra_linker_flags => "-L. -lbar", objects => ["main.o"]); ok(-f "add$libbuilder->{exeext}"); ok(-x "add$libbuilder->{exeext}"); add_to_cleanup("add$libbuilder->{exeext}"); if ($^O =~ /mswin32/i) { $ENV{PATH} = ".;$ENV{PATH}"; } elsif ($^O =~ /darwin/i) { $ENV{DYLD_LIBRARY_PATH} = "."; } elsif ($^O =~ /(?:linux|bsd|sun|sol|dragonfly|hpux|irix)/i) { $ENV{LD_LIBRARY_PATH} = "."; if ($^O =~ /irix/) { # trying my luck $ENV{LD_LIBRARYN32_PATH} = "."; $ENV{LD_LIBRARYN64_PATH} = "."; } } elsif ($^O =~ /aix/i) { my $oldlibpath = $ENV{LIBPATH} || '/lib:/usr/lib'; $ENV{LIBPATH} = ".:$oldlibpath"; } my $P; $P = "./" unless $^O =~ /mswin32/i; my $ans = `${P}add$libbuilder->{exeext}`; chomp $ans; is($ans, 15); clean(); sub add_to_cleanup { push @CLEAN, @_; } sub clean { unlink $_ for @CLEAN; } ExtUtils-LibBuilder-0.08/t/pod-coverage.t000444000765000024 104712611220356 17603 0ustar00ambsstaff000000000000use strict; use warnings; use Test::More; # Ensure a recent version of Test::Pod::Coverage my $min_tpc = 1.08; eval "use Test::Pod::Coverage $min_tpc"; plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage" if $@; # Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, # but older versions don't recognize some common documentation styles my $min_pc = 0.18; eval "use Pod::Coverage $min_pc"; plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" if $@; all_pod_coverage_ok(); ExtUtils-LibBuilder-0.08/t/pod.t000444000765000024 35012611220356 15766 0ustar00ambsstaff000000000000#!perl -T use strict; use warnings; use Test::More; # Ensure a recent version of Test::Pod my $min_tp = 1.22; eval "use Test::Pod $min_tp"; plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; all_pod_files_ok();