ExtUtils-CppGuess-0.11/0000755000175100017520000000000012574353154014633 5ustar doswalddoswaldExtUtils-CppGuess-0.11/META.yml0000664000175100017520000000126512574353153016111 0ustar doswalddoswald--- abstract: unknown author: - unknown build_requires: Capture::Tiny: '0' Cwd: '0' Data::Dumper: '0' ExtUtils::MakeMaker: '0' ExtUtils::Manifest: '0' Fatal: '0' File::Spec: '0' Module::Build: '0' Test::More: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: ExtUtils-CppGuess no_index: directory: - t - inc requires: Capture::Tiny: '0' File::Basename: '0' resources: repository: git://github.com/tsee/extutils-cppguess version: '0.11' ExtUtils-CppGuess-0.11/README0000644000175100017520000000447312574352455015526 0ustar doswalddoswaldNAME 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.11/MANIFEST0000644000175100017520000000053012574352455015765 0ustar doswalddoswaldMakefile.PL Changes MANIFEST This list of files README META.json META.yml lib/ExtUtils/CppGuess.pm 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/MANIFEST t/module/Makefile.PL t/module/lib/CppGuessTest.pm t/module/t/001_load.t t/module/t/002_base.t t/module/typemap ExtUtils-CppGuess-0.11/lib/0000755000175100017520000000000012574353153015400 5ustar doswalddoswaldExtUtils-CppGuess-0.11/lib/ExtUtils/0000755000175100017520000000000012574353153017161 5ustar doswalddoswaldExtUtils-CppGuess-0.11/lib/ExtUtils/CppGuess.pm0000644000175100017520000001740712574352645021266 0ustar doswalddoswaldpackage 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.11'; sub new { my( $class, %args ) = @_; my $self = bless { %args }, $class; # Allow override of default %Config::Config; useful in testing. if( ! exists $self->{config} || ! defined $self->{config} ) { $self->{config} = \%Config::Config; } # Allow a 'cc' %args. If not supplied, pull from {config}, or $Config{cc}. if( ! exists $self->{cc} || ! defined $self->{cc} ) { $self->{cc} = exists $self->{config}{cc} && defined $self->{config}{cc} ? $self->{config}{cc} : $Config::Config{cc}; } # Set up osname. if( ! exists $self->{os} || ! defined $self->{os} ) { $self->{os} = exists $self->{config}{osname} && defined $self->{config}{osname} ? $self->{config}{osname} : $^O; } return $self; } # Thus saith the law: All references to %Config::Config shall come through # $self->_config. Accessors shall provide access to key components thereof. # Testing shall thus grow stronger, verifying performance for platforms diverse # to which access we have not. sub _config { shift->{config} } sub _cc { shift->{cc} } sub _os { shift->{os} } sub guess_compiler { my $self = shift; return $self->{guess} if $self->{guess}; if( $self->_os =~ /^mswin/i ) { $self->_guess_win32() or return; } else { $self->_guess_unix() or return; } return $self->{guess}; } sub _get_cflags { my $self = shift; $self->guess_compiler or die; my $cflags = ' ' . $self->_config->{ccflags}; $cflags .= ' ' . $self->{guess}{extra_cflags}; $cflags .= ' ' . $self->{extra_compiler_flags} if defined $self->{extra_compiler_flags}; return $cflags; } sub _get_lflags { my $self = shift; $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 = shift; my $lflags = $self->_get_lflags; my $cflags = $self->_get_cflags; return ( CCFLAGS => $cflags, dynamic_lib => { OTHERLDFLAGS => $lflags }, ); } sub module_build_options { my $self = shift; my $lflags = $self->_get_lflags; my $cflags = $self->_get_cflags; return ( extra_compiler_flags => $cflags, extra_linker_flags => $lflags, ); } sub _guess_win32 { my $self = shift; 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 = shift; 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_lflags} .= ' -lgcc_s' if $self->_os eq 'netbsd' && $self->{guess}{extra_lflags} !~ /-lgcc_s/; return 1; } # originally from Alien::wxWidgets::Utility # Why was this hanging around outside of all functions, and without any other # use of $quotes? # my $quotes = $self->_os =~ /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 = shift; 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} = ($self->_os =~ /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 = shift; $self->guess_compiler || die; return $self->{is_gcc}; } sub is_msvc { my $self = shift; $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; ExtUtils-CppGuess-0.11/META.json0000664000175100017520000000263712574353154016266 0ustar doswalddoswald{ "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "ExtUtils-CppGuess", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Capture::Tiny" : "0", "File::Basename" : "0" } }, "test" : { "requires" : { "Capture::Tiny" : "0", "Cwd" : "0", "Data::Dumper" : "0", "ExtUtils::MakeMaker" : "0", "ExtUtils::Manifest" : "0", "Fatal" : "0", "File::Spec" : "0", "Module::Build" : "0", "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "url" : "git://github.com/tsee/extutils-cppguess", "web" : "https://github.com/tsee/extutils-cppguess" } }, "version" : "0.11" } ExtUtils-CppGuess-0.11/Changes0000644000175100017520000000246712574353113016132 0ustar doswalddoswaldRevision history for Perl extension ExtUtils::CppGuess. 0.11 Thu Sep 10 13:12:17 MDT 2015 - Add leading whitespace to $cflags in _get_cflags (bulk88) 0.10 Tue Sep 08 21:15:30 MDT 2015 - Config's ccflags must always be used. (bulk88) 0.09 Sat Apr 11 16:05:50 BST 2015 - Convert to EUMM - Make tests divulge guessed options for better debugging 0.08 Thu Jan 15 03:07:38 GMT 2015 - Update metadata 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.11/t/0000755000175100017520000000000012574353153015075 5ustar doswalddoswaldExtUtils-CppGuess-0.11/t/001_load.t0000644000175100017520000000047112574352455016567 0ustar doswalddoswald#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; use Test::More tests => 2; my $MODULE = 'ExtUtils::CppGuess'; use_ok($MODULE); my $guess = $MODULE->new; isa_ok $guess, $MODULE; diag 'EUMM:', Dumper { $guess->makemaker_options }; diag '---'; diag 'MB:', Dumper { $guess->module_build_options }; ExtUtils-CppGuess-0.11/t/lib/0000755000175100017520000000000012574353153015643 5ustar doswalddoswaldExtUtils-CppGuess-0.11/t/lib/TestUtils.pm0000644000175100017520000000423212574352455020146 0ustar doswalddoswaldpackage 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.11/t/010_module_build.t0000644000175100017520000000101412574352455020306 0ustar doswalddoswald#!/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.11/t/011_makemaker.t0000644000175100017520000000101412574352455017600 0ustar doswalddoswald#!/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.11/t/module/0000755000175100017520000000000012574353153016362 5ustar doswalddoswaldExtUtils-CppGuess-0.11/t/module/CppGuessTest.xs0000644000175100017520000000223112574352455021331 0ustar doswalddoswald#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.11/t/module/Build.PL0000644000175100017520000000063612574352455017667 0ustar doswalddoswald#!/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.11/t/module/typemap0000644000175100017520000000026512574352455017773 0ustar doswalddoswaldstd::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.11/t/module/MANIFEST0000644000175100017520000000014412574352455017516 0ustar doswalddoswaldBuild.PL CppGuessTest.xs MANIFEST Makefile.PL lib/CppGuessTest.pm t/001_load.t t/002_base.t typemap ExtUtils-CppGuess-0.11/t/module/lib/0000755000175100017520000000000012574353153017130 5ustar doswalddoswaldExtUtils-CppGuess-0.11/t/module/lib/CppGuessTest.pm0000644000175100017520000000015312574352455022062 0ustar doswalddoswaldpackage CppGuessTest; our $VERSION = '0.01'; use XSLoader; XSLoader::load 'CppGuessTest', $VERSION; 1; ExtUtils-CppGuess-0.11/t/module/t/0000755000175100017520000000000012574353153016625 5ustar doswalddoswaldExtUtils-CppGuess-0.11/t/module/t/001_load.t0000644000175100017520000000012612574352455020314 0ustar doswalddoswald#!/usr/bin/perl -w use strict; use Test::More tests => 1; use_ok( 'CppGuessTest' ); ExtUtils-CppGuess-0.11/t/module/t/002_base.t0000644000175100017520000000026312574352455020312 0ustar doswalddoswald#!/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.11/t/module/Makefile.PL0000644000175100017520000000045612574352455020345 0ustar doswalddoswald#!/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.11/Makefile.PL0000644000175100017520000000163312574352455016613 0ustar doswalddoswald#!/usr/bin/perl -w use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'ExtUtils::CppGuess', VERSION_FROM => 'lib/ExtUtils/CppGuess.pm', LICENSE => 'perl', PREREQ_PM => { 'Capture::Tiny' => '0', 'File::Basename' => '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', 'Data::Dumper' => 0, }, clean => { FILES => 't/module_build t/makemaker' }, META_MERGE => { "meta-spec" => { version => 2 }, resources => { repository => { type => 'git', url => 'git://github.com/tsee/extutils-cppguess', web => 'https://github.com/tsee/extutils-cppguess', }, }, }, );