ExtUtils-CppGuess-0.07000755001750001750 011605420771 14036 5ustar00tseetsee000000000000ExtUtils-CppGuess-0.07/Changes000444001750001750 171311605420771 15470 0ustar00tseetsee000000000000Revision history for Perl extension ExtUtils::CppGuess. 0.07 Thu Jul 7 17:00:00 CEST 2011 - Fix for unknown enum `vtype' on solaris 2.11 (Tobias Leich) See http://www.cpantesters.org/cpan/report/a0cca9ee-39e3-11e0-83a5-34754e7aadc9 - NetBSD fix for: Undefined PLT symbol _Unwind_Resume (Tobias Leich) 0.06 Sun Jun 5 21:00:00 CEST 2011 - Fix for -D_FILE_OFFSET_BITS (Tobias Leich) See http://www.cpantesters.org/cpan/report/b6e29992-894c-11e0-b6b1-f9d75287cfae 0.05 Tue Feb 15 23:00:00 CEST 2010 - Fix test failures on win32 (Shmuel Fomberg) 0.04 Mon Jul 12 18:00:00 CEST 2010 - Fix problem with duplicate extra-linker/compiler options 0.03 Thu Jul 1 18:00:00 CEST 2010 - Fix tests to use the current perl - Make tests use Capture::Tiny - Very explicit dependencies in Build.PL 0.02 Mon Jun 28 20:00:00 CEST 2010 - Just removed debugging code. 0.01 Mon Jun 28 20:00:00 CEST 2010 - First release. ExtUtils-CppGuess-0.07/Build.PL000444001750001750 125711605420771 15474 0ustar00tseetsee000000000000#!/usr/bin/perl -w use strict; use Module::Build; my $build = Module::Build->new ( module_name => 'ExtUtils::CppGuess', license => 'perl', requires => { 'Capture::Tiny' => '0', 'File::Basename' => '0', }, build_requires => { 'Module::Build' => '0', }, test_requires => { 'Capture::Tiny' => '0', 'Module::Build' => '0', 'ExtUtils::MakeMaker' => '0', 'Test::More' => '0', 'File::Spec' => '0', 'ExtUtils::Manifest' => '0', 'Fatal' => '0', 'Cwd' => '0', }, add_to_cleanup => [ 't/module_build', 't/makemaker' ], ); $build->create_build_script; ExtUtils-CppGuess-0.07/MANIFEST.SKIP000444001750001750 247411605420771 16100 0ustar00tseetsee000000000000 #!start included /opt/perl/modules/lib/perl5/ExtUtils/MANIFEST.SKIP # Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b \B\.cvsignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ \bDESCRIP.MMS$ \bdescrip.mms$ # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ \bBuild.bat$ \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ \.tmp$ \.# \.rej$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid Devel::Cover and Devel::CoverX::Covered files. \bcover_db\b \bcovered\b # Avoid MYMETA files ^MYMETA\. #!end included /opt/perl/modules/lib/perl5/ExtUtils/MANIFEST.SKIP # Avoid configuration metadata file ^MYMETA\. # Avoid Module::Build generated and utility files. \bBuild$ \bBuild.bat$ \b_build \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ # Avoid archives of this distribution \bExtUtils-CppGuess-[\d\.\_]+ # Ignore test byproducts CppGuessTest\.bs CppGuessTest\.c CppGuessTest\.o CppGuessTest\.obj ^t/module/lib/CppGuessTest.xs$ ^t/module/MYMETA\. ExtUtils-CppGuess-0.07/MANIFEST000444001750001750 53111605420771 15303 0ustar00tseetsee000000000000Build.PL Changes lib/ExtUtils/CppGuess.pm MANIFEST This list of files MANIFEST.SKIP META.yml README t/001_load.t t/010_module_build.t t/011_makemaker.t t/lib/TestUtils.pm t/module/Build.PL t/module/CppGuessTest.xs t/module/lib/CppGuessTest.pm t/module/Makefile.PL t/module/MANIFEST t/module/t/001_load.t t/module/t/002_base.t t/module/typemap ExtUtils-CppGuess-0.07/README000444001750001750 447311605420771 15063 0ustar00tseetsee000000000000NAME ExtUtils::CppGuess - guess C++ compiler and flags SYNOPSIS With Extutils::MakeMaker: use ExtUtils::CppGuess; my $guess = ExtUtils::CppGuess->new; WriteMakefile ( # MakeMaker args, $guess->makemaker_options, ); With Module::Build: my $guess = ExtUtils::CppGuess->new; my $build = Module::Build->new ( # Module::Build arguments $guess->module_build_options, ); $build->create_build_script; DESCRIPTION "ExtUtils::CppGuess" attempts to guess the system's C++ compiler that is compatible with the C compiler that your perl was built with. It can generate the necessary options to the Module::Build constructor or to ExtUtils::MakeMaker's "WriteMakefile" function. METHODS new Creates a new "ExtUtils::CppGuess" object. Takes the path to the C compiler as the "cc" argument, but falls back to the value of $Config{cc}, which should be what you want anyway. You can specify "extra_compiler_flags" and "extra_linker_flags" (as strings) which will be merged in with the auto-detected ones. module_build_options Returns the correct options to the constructor of "Module::Build". These are: extra_compiler_flags extra_linker_flags makemaker_options Returns the correct options to the "WriteMakefile" function of "ExtUtils::MakeMaker". These are: CCFLAGS dynamic_lib => { OTHERLDFLAGS => ... } If you specify the extra compiler or linker flags in the constructor, they'll be merged into "CCFLAGS" or "OTHERLDFLAGS" respectively. is_gcc Returns true if the detected compiler is in the gcc family. is_msvc Returns true if the detected compiler is in the MS VC family. add_extra_compiler_flags Takes a string as argument that is added to the string of extra compiler flags. add_extra_linker_flags Takes a string as argument that is added to the string of extra linker flags. AUTHOR Mattia Barbon Steffen Mueller Tobias Leich COPYRIGHT AND LICENSE Copyright 2010, 2011 by Mattia Barbon. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. ExtUtils-CppGuess-0.07/META.yml000444001750001750 115411605420771 15445 0ustar00tseetsee000000000000--- abstract: 'guess C++ compiler and flags' author: - 'Mattia Barbon ' - 'Steffen Mueller ' - 'Tobias Leich ' build_requires: Module::Build: 0 configure_requires: Module::Build: 0.36 generated_by: 'Module::Build version 0.3624' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: ExtUtils-CppGuess provides: ExtUtils::CppGuess: file: lib/ExtUtils/CppGuess.pm version: 0.07 requires: Capture::Tiny: 0 File::Basename: 0 resources: license: http://dev.perl.org/licenses/ version: 0.07 ExtUtils-CppGuess-0.07/t000755001750001750 011605420771 14301 5ustar00tseetsee000000000000ExtUtils-CppGuess-0.07/t/011_makemaker.t000444001750001750 101411605420771 17135 0ustar00tseetsee000000000000#!/usr/bin/perl -w use strict; use Test::More tests => 1; use t::lib::TestUtils; my $separator = ( '=' x 40 . "\n" ); prepare_test( 't/module', 't/makemaker' ); my( $ok, $configure, $build, $test ) = build_makemaker( 't/makemaker' ); ok( $ok, 'build with ExtUtils::MakeMaker' ); if( !$ok ) { diag( "Makefile.PL output\n", $separator, $configure, $separator ); diag( "make output\n", $separator, $build, $separator ) if $build; diag( "make test output\n", $separator, $test, $separator ) if $test; } ExtUtils-CppGuess-0.07/t/010_module_build.t000444001750001750 101411605420771 17643 0ustar00tseetsee000000000000#!/usr/bin/perl -w use strict; use Test::More tests => 1; use t::lib::TestUtils; my $separator = ( '=' x 40 . "\n" ); prepare_test( 't/module', 't/module_build' ); my( $ok, $configure, $build, $test ) = build_module_build( 't/module_build' ); ok( $ok, 'build with Module::Build' ); if( !$ok ) { diag( "Build.PL output\n", $separator, $configure, $separator ); diag( "Build output\n", $separator, $build, $separator ) if $build; diag( "Build test output\n", $separator, $test, $separator ) if $test; } ExtUtils-CppGuess-0.07/t/001_load.t000444001750001750 13411605420771 16100 0ustar00tseetsee000000000000#!/usr/bin/perl -w use strict; use Test::More tests => 1; use_ok( 'ExtUtils::CppGuess' ); ExtUtils-CppGuess-0.07/t/lib000755001750001750 011605420771 15047 5ustar00tseetsee000000000000ExtUtils-CppGuess-0.07/t/lib/TestUtils.pm000444001750001750 423211605420771 17503 0ustar00tseetsee000000000000package t::lib::TestUtils; use strict; use ExtUtils::Manifest qw(manicopy maniread); use File::Path qw(rmtree); use File::Spec::Functions qw(rel2abs); use Cwd qw(cwd); use Fatal qw(chdir); use Config qw(); use Capture::Tiny 'capture_merged'; require Exporter; *import = \&Exporter::import; our @EXPORT = qw(prepare_test build_makemaker build_module_build); sub _run_capture { my @cmd = @_; my $captured = capture_merged { system(@cmd); }; my $status = $?; return($captured, $status); } sub prepare_test { my( $source, $destination ) = @_; my $cwd = cwd(); $destination = rel2abs( $destination ); rmtree( $destination ); chdir( $source ); manicopy( maniread(), $destination ); chdir( $cwd ); } sub build_module_build { my( $path ) = @_; my $cwd = cwd(); chdir $path; my ($build_pl, $build_pl_ok) = _run_capture($^X, "Build.PL"); if( $build_pl_ok != 0 ) { chdir( $cwd ); return ( 0, $build_pl, undef, undef ); } my ($build, $build_ok) = _run_capture($^X, "Build"); if( $build_ok != 0 ) { chdir( $cwd ); return ( 0, $build_pl, $build, undef ); } my ($build_test, $build_test_ok) = _run_capture($^X, "Build", "test"); if( $build_test_ok != 0 ) { chdir( $cwd ); return ( 0, $build_pl, $build, $build_test ); } else { chdir( $cwd ); return ( 1, $build_pl, $build, $build_test ); } } sub build_makemaker { my( $path ) = @_; my $cwd = cwd(); chdir $path; my ($makefile_pl, $makefile_pl_ok) = _run_capture($^X, "Makefile.PL"); if( $makefile_pl_ok != 0 ) { chdir( $cwd ); return ( 0, $makefile_pl, undef, undef ); } my ($make, $make_ok) = _run_capture($Config::Config{make}); if( $make_ok != 0 ) { chdir( $cwd ); return ( 0, $makefile_pl, $make, undef ); } my ($make_test, $make_test_ok) = _run_capture($Config::Config{make}, "test"); if( $make_test_ok != 0 ) { chdir( $cwd ); return ( 0, $makefile_pl, $make, $make_test ); } else { chdir( $cwd ); return ( 1, $makefile_pl, $make, $make_test ); } } 1; ExtUtils-CppGuess-0.07/t/module000755001750001750 011605420771 15566 5ustar00tseetsee000000000000ExtUtils-CppGuess-0.07/t/module/CppGuessTest.xs000444001750001750 223111605420771 20666 0ustar00tseetsee000000000000#ifdef _WIN32 #include #endif #if defined (__SVR4) && defined (__sun) #include #endif #include typedef std::string std__string; #include #include #include #include // Perl likes to pollute your namespace #undef bool #if defined( PERL_IMPLICIT_CONTEXT ) #undef abort #undef clearerr #undef close #undef eof #undef exit #undef fclose #undef feof #undef ferror #undef fflush #undef fgetpos #undef fopen #undef form #undef fputc #undef fputs #undef fread #undef free #undef freopen #undef fseek #undef fsetpos #undef ftell #undef fwrite #undef getc #undef getenv #undef malloc #undef open #undef read #undef realloc #undef rename #undef seekdir #undef setbuf #undef setvbuf #undef tmpfile #undef tmpnam #undef ungetc #undef vform #undef vfprintf #undef write #endif // defined( PERL_IMPLICIT_SYS ) int silly_test( int value ) { return 2 * value + 1; } std::string useless_test( const std::string& a, const std::string& b ) { return a + b; } MODULE=CppGuessTest PACKAGE=CppGuessTest PROTOTYPES: DISABLE int silly_test( int value ) std::string useless_test( std::string a, std::string b ) ExtUtils-CppGuess-0.07/t/module/Makefile.PL000444001750001750 45611605420771 17662 0ustar00tseetsee000000000000#!/usr/bin/perl -w use strict; use blib '../..'; use ExtUtils::MakeMaker; use ExtUtils::CppGuess; my $guess = ExtUtils::CppGuess->new; WriteMakefile ( NAME => 'CppGuessTest', VERSION_FROM => 'lib/CppGuessTest.pm', PL_FILES => {}, $guess->makemaker_options, ); ExtUtils-CppGuess-0.07/t/module/Build.PL000444001750001750 63611605420771 17204 0ustar00tseetsee000000000000#!/usr/bin/perl -w use strict; use blib '../..'; use Module::Build; use ExtUtils::CppGuess; my $guess = ExtUtils::CppGuess->new; my $build = Module::Build->new ( module_name => 'CppGuessTest', dist_abstract => 'a test module', license => 'perl', xs_files => { 'CppGuessTest.xs' => 'lib/CppGuessTest.xs' }, $guess->module_build_options, ); $build->create_build_script; ExtUtils-CppGuess-0.07/t/module/MANIFEST000444001750001750 14411605420771 17033 0ustar00tseetsee000000000000Build.PL CppGuessTest.xs MANIFEST Makefile.PL lib/CppGuessTest.pm t/001_load.t t/002_base.t typemap ExtUtils-CppGuess-0.07/t/module/typemap000444001750001750 26511605420771 17310 0ustar00tseetsee000000000000std::string T_STD_STRING INPUT T_STD_STRING $var = std::string( SvPV_nolen( $arg ), SvCUR( $arg ) ); OUTPUT T_STD_STRING $arg = newSVpvn( $var.c_str(), $var.length() ); ExtUtils-CppGuess-0.07/t/module/t000755001750001750 011605420771 16031 5ustar00tseetsee000000000000ExtUtils-CppGuess-0.07/t/module/t/002_base.t000444001750001750 26311605420771 17627 0ustar00tseetsee000000000000#!/usr/bin/perl -w use strict; use Test::More tests => 2; use CppGuessTest; is( CppGuessTest::silly_test( 4 ), 9 ); is( CppGuessTest::useless_test( "foo", "bar" ), "foobar" ); ExtUtils-CppGuess-0.07/t/module/t/001_load.t000444001750001750 12611605420771 17631 0ustar00tseetsee000000000000#!/usr/bin/perl -w use strict; use Test::More tests => 1; use_ok( 'CppGuessTest' ); ExtUtils-CppGuess-0.07/t/module/lib000755001750001750 011605420771 16334 5ustar00tseetsee000000000000ExtUtils-CppGuess-0.07/t/module/lib/CppGuessTest.pm000444001750001750 15311605420771 21377 0ustar00tseetsee000000000000package CppGuessTest; our $VERSION = '0.01'; use XSLoader; XSLoader::load 'CppGuessTest', $VERSION; 1; ExtUtils-CppGuess-0.07/lib000755001750001750 011605420771 14604 5ustar00tseetsee000000000000ExtUtils-CppGuess-0.07/lib/ExtUtils000755001750001750 011605420771 16365 5ustar00tseetsee000000000000ExtUtils-CppGuess-0.07/lib/ExtUtils/CppGuess.pm000444001750001750 1547211605420771 20642 0ustar00tseetsee000000000000package ExtUtils::CppGuess; use strict; use warnings; =head1 NAME ExtUtils::CppGuess - guess C++ compiler and flags =head1 SYNOPSIS With L: use ExtUtils::CppGuess; my $guess = ExtUtils::CppGuess->new; WriteMakefile ( # MakeMaker args, $guess->makemaker_options, ); With L: my $guess = ExtUtils::CppGuess->new; my $build = Module::Build->new ( # Module::Build arguments $guess->module_build_options, ); $build->create_build_script; =head1 DESCRIPTION C attempts to guess the system's C++ compiler that is compatible with the C compiler that your perl was built with. It can generate the necessary options to the L constructor or to L's C function. =head1 METHODS =head2 new Creates a new C object. Takes the path to the C compiler as the C argument, but falls back to the value of C<$Config{cc}>, which should be what you want anyway. You can specify C and C (as strings) which will be merged in with the auto-detected ones. =head2 module_build_options Returns the correct options to the constructor of C. These are: extra_compiler_flags extra_linker_flags =head2 makemaker_options Returns the correct options to the C function of C. These are: CCFLAGS dynamic_lib => { OTHERLDFLAGS => ... } If you specify the extra compiler or linker flags in the constructor, they'll be merged into C or C respectively. =head2 is_gcc Returns true if the detected compiler is in the gcc family. =head2 is_msvc Returns true if the detected compiler is in the MS VC family. =head2 add_extra_compiler_flags Takes a string as argument that is added to the string of extra compiler flags. =head2 add_extra_linker_flags Takes a string as argument that is added to the string of extra linker flags. =head1 AUTHOR Mattia Barbon Steffen Mueller Tobias Leich =head1 COPYRIGHT AND LICENSE Copyright 2010, 2011 by Mattia Barbon. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut use Config (); use File::Basename qw(); use Capture::Tiny 'capture_merged'; our $VERSION = '0.07'; sub new { my( $class, %args ) = @_; my $self = bless { cc => $Config::Config{cc}, %args }, $class; return $self; } sub guess_compiler { my( $self ) = @_; return $self->{guess} if $self->{guess}; if( $^O =~ /^mswin/i ) { $self->_guess_win32() or return(); } else { $self->_guess_unix() or return(); } return $self->{guess}; } sub _get_cflags { my( $self ) = @_; $self->guess_compiler || die; my $cflags = $self->{guess}{extra_cflags}; $cflags .= ' ' . $self->{extra_compiler_flags} if defined $self->{extra_compiler_flags}; return $cflags; } sub _get_lflags { my( $self ) = @_; $self->guess_compiler || die; my $lflags = $self->{guess}{extra_lflags}; $lflags .= ' ' . $self->{extra_linker_flags} if defined $self->{extra_linker_flags}; return $lflags; } sub makemaker_options { my( $self ) = @_; my $lflags = $self->_get_lflags; my $cflags = $self->_get_cflags; return ( CCFLAGS => $cflags, dynamic_lib => { OTHERLDFLAGS => $lflags }, ); } sub module_build_options { my( $self ) = @_; my $lflags = $self->_get_lflags; my $cflags = $self->_get_cflags; return ( extra_compiler_flags => $cflags, extra_linker_flags => $lflags, ); } sub _guess_win32 { my( $self ) = @_; my $c_compiler = $self->{cc}; $c_compiler = $Config::Config{cc} if not defined $c_compiler; if( $self->_cc_is_gcc( $c_compiler ) ) { $self->{guess} = { extra_cflags => ' -xc++ ', extra_lflags => ' -lstdc++ ', }; } elsif( $self->_cc_is_msvc( $c_compiler ) ) { $self->{guess} = { extra_cflags => ' -TP -EHsc ', extra_lflags => ' msvcprt.lib ', }; } else { die "Unable to determine a C++ compiler for '$c_compiler'"; } return 1; } sub _guess_unix { my( $self ) = @_; my $c_compiler = $self->{cc}; $c_compiler = $Config::Config{cc} if not defined $c_compiler; if( !$self->_cc_is_gcc( $c_compiler ) ) { die "Unable to determine a C++ compiler for '$c_compiler'"; } $self->{guess} = { extra_cflags => ' -xc++ ', extra_lflags => ' -lstdc++ ', }; $self->{guess}{extra_cflags} .= ' -D_FILE_OFFSET_BITS=64' if $Config::Config{ccflags} =~ /-D_FILE_OFFSET_BITS=64/; $self->{guess}{extra_lflags} .= ' -lgcc_s' if $^O eq 'netbsd' && $self->{guess}{extra_lflags} !~ /-lgcc_s/; return 1; } # originally from Alien::wxWidgets::Utility my $quotes = $^O =~ /MSWin32/ ? '"' : "'"; sub _capture { my @cmd = @_; my $out = capture_merged { system(@cmd); }; $out = '' if not defined $out; return $out; } # capture the output of a command that is run with piping # to stdin of the command. We immediately close the pipe. sub _capture_empty_stdin { my( $cmd ) = @_; my $out = capture_merged { if (open(my $fh, '|-', $cmd)) { close $fh; } }; $out = '' if not defined $out; return $out; } sub _cc_is_msvc { my( $self, $cc ) = @_; $self->{is_msvc} = ($^O =~ /MSWin32/ and File::Basename::basename( $cc ) =~ /^cl/i); return $self->{is_msvc}; } sub _cc_is_gcc { my( $self, $cc ) = @_; $self->{is_gcc} = 0; my $cc_version = _capture( "$cc --version" ); if ( $cc_version =~ m/\bg(?:cc|\+\+)/i # 3.x, some 4.x || scalar( _capture( "$cc" ) =~ m/\bgcc\b/i ) # 2.95 || scalar(_capture_empty_stdin("$cc -dM -E -") =~ /__GNUC__/) # more or less universal? || scalar($cc_version =~ m/\bcc\b.*Free Software Foundation/si) # some 4.x? ) { $self->{is_gcc} = 1; } return $self->{is_gcc}; } sub is_gcc { my( $self ) = @_; $self->guess_compiler || die; return $self->{is_gcc}; } sub is_msvc { my( $self ) = @_; $self->guess_compiler || die; return $self->{is_msvc}; } sub add_extra_compiler_flags { my( $self, $string ) = @_; $self->{extra_compiler_flags} = defined($self->{extra_compiler_flags}) ? $self->{extra_compiler_flags} . ' ' . $string : $string; } sub add_extra_linker_flags { my( $self, $string ) = @_; $self->{extra_linker_flags} = defined($self->{extra_linker_flags}) ? $self->{extra_linker_flags} . ' ' . $string : $string; } 1;