pax_global_header00006660000000000000000000000064121356417440014521gustar00rootroot0000000000000052 comment=027372d57a00f1ffa7142f0a57c5d91d6344f21d perl-Module-Install-XSUtil-0.44/000075500000000000000000000000001213564174400164255ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/.gitignore000075500000000000000000000001731213564174400204210ustar00rootroot00000000000000.* *~ !.gitignore !.shipit *.o *.obj *.bs *.bak Makefile* !Makefile.PL *blib META.yml MYMETA.yml MYMETA.json inc/ MANIFEST perl-Module-Install-XSUtil-0.44/.shipit000064400000000000000000000003231213564174400177240ustar00rootroot00000000000000# auto-generated shipit config file. steps = FindVersion, ChangeAllVersions, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN git.tagpattern = %v git.push_to = origin CheckChangeLog.files = Changes perl-Module-Install-XSUtil-0.44/Changes000064400000000000000000000126511213564174400177250ustar00rootroot00000000000000Revision history for Perl extension Module::Install::XSUtil 0.44 2013-04-24 11:30:07 - Support PUREPERL_ONLY=1 0.43 2012-06-25 09:23:04 - Remove experimental requires_xs() because Module::Install provides another requires_xs() - Move t/01_example.t to xt/ 0.42 2011-10-19 20:00:07 - Remove cc_inc_paths, which is already defined in M::I (thanks to @shohex) 0.41 2011-10-04 12:05:54 - Complete support for requires_cplusplus() 0.40 2011-09-24 00:56:33 - ExtUtils::ParseXS is now configure_requires, instead of build_requires (xaicron++) 0.39 2011-08-22 11:28:15 - Add cc_inc_paths() as an alias to cc_include_paths() - Add requires_cplusplus() as an experimental feature; currently it chnages only warnings flags 0.38 2011-06-22 15:15:37 - Workaround MacOSX's system perl failure caused by multiple -arch for gcc (thanks to @kazuho) 0.37 2011-05-16 23:33:49 - Makefile.PL -g implices "-g -ggdb -g3" for gcc (EXPERIMENTAL) - PERL_ONLY=1 means --pp for modules with XS/PP dual backends 0.36 Thu Oct 7 16:49:04 2010 - Resolve RT #61660 (SREZIC): Support for ccache missing - Resolve RT #61770 (bokutin): A typo in SYNOPSIS 0.35 Wed Sep 29 23:46:17 2010 - Checks C99 specification more strictly - Add some macros to xshelper.h 0.34 Sun Sep 26 12:18:18 2010 - Oops! The change in 0.33 did not work. 0.33 Sun Sep 19 22:15:10 2010 - Disable -Wdeclaration-after-statement by requires_c99() 0.32 Mon Sep 13 14:18:33 2010 - Don't clean xshelper.h by default. Use use_xshelper -clean (or -realclean) to clean the file. 0.31 Mon Sep 13 13:09:16 2010 - Fix a check for STATIC_INLINE (s/__cplusplus__/__cplusplus/) 0.30 Sat Sep 11 14:17:06 2010 - Add use_xshelper() command to create xshelper.h 0.27 Sun Sep 5 11:47:03 2010 - c99_available() should not have any side effects (reported by makamaka) 0.26 Sat Aug 7 17:47:37 2010 - Use the version of installed gcc, not $Config{gccversion} (xaicron) 0.25 Tue Jul 13 19:43:34 2010 - Add requires_c99() to assert that the compiler supports C99 - Fix Win32 problems, hopefully 0.24 Sun May 16 13:24:58 2010 - Compliant with Module::Install 0.97 0.23_02 Fri May 14 11:42:09 2010 - Don't exit if include dirs don't exist (lestrrat) - Add cc_assert_lib() as an interface to Devel::CheckLib (lestrrat) - Add want_xs() (lestrrat) - Separate out detection of "-" and stuff to cc_libs(), and let cc_append_to_lib()s just be a simple function (lestrrat) 0.23_01 Mon May 10 12:10:59 2010 - Clarify docs (lestrrat) - Add want_xs() command (lestrrat) 0.23 Sun May 9 11:15:41 2010 - Setup clean_files for gcov output files (*.gcov, *.gcno, *.gcda) - Add cc_libs() for MakeMaker's LIBS option (currently, it is just an ailas to cc_append_libs()) - cc_append_libs (and then cc_libs) accepts raw arguments as "cc_libs qw(-L/path/to/libs -lfoo)" (lestrrat++) 0.22 Thu Mar 11 19:02:18 2010 - Add Devel::PPPort to build_requires if needed 0.21 Sun Jan 10 15:22:20 2010 - Enable -Wc++-compat on gcc >= 4.1 0.20 Sat Jan 9 16:31:53 2010 - Change cc_warnings() - Add -Wc++-compat on gcc 4 - Add -Wno-comment on gcc 3 - Remove ExtUtils::CBuilder dependency, use can_cc() instead 0.19 Tue Dec 8 10:35:19 2009 - Make cc_available recognize the '--pp' and '--xs' options 0.18 Tue Nov 17 10:15:03 2009 - Optimize cc_available() by caching its value 0.17 Thu Nov 12 13:30:47 2009 - Fix cc_warnings() for old gcc - Add cc_available() using ExtUtils::CBuuilder 0.16 Mon Nov 2 11:55:46 2009 - Fix a typo in cc_warnings() 0.15 Thu Oct 29 09:31:07 2009 - Requires newer versions in prerequisites - Switch the use of -Wextra/-W by gcc versions - Revert "-g option is set implicitly in author's mode" 0.14 Mon Sep 14 15:02:19 2009 - Improve debugging mode - "-g" option is set implicitly in author's mode - Set -DXS_ASSERT in author's mode (see XS::Assert) - Set -Wdeclaration-after-statement in cc_warnings() 0.13 Wed Sep 2 17:59:04 2009 - fix RT #48738 and add tests on it 0.12 Fri Aug 21 12:54:20 2009 - re-fix the algorithm to find functions again (RT #48797) - refer to Module::Install::AuthorRequires 0.11 Wed Aug 19 16:15:33 2009 - re-fix the algorithm to find functions (RT #48797) - remove -DDEBUGGING in '-g' option 0.10 Tue Aug 18 13:05:46 2009 - add '-g' command line option (perl Makefile.PL -g) - avoid optimization (remove -Ox from OPTIMIZE) - add -DDEBUGGING to DEFINE - make the function finding algorithm more smart (fix RT #48738 in XS::MagicExt) 0.09 Thu Aug 13 22:27:20 2009 - fix a linking library issue on Cygwin 0.08 Wed Aug 12 11:36:27 2009 - fix checklib algorithm - enhance tests 0.07 Tue Aug 4 17:02:32 2009 - apply a patch from RT #48321-2 (thanks to Taro Nishino) 0.06 Tue Aug 4 09:20:08 2009 - fix tests for Win32 (RT #48321-1 reported by Taro Nishino) - add cc_define() command 0.05 Mon Aug 3 16:55:20 2009 - fix the algorithm for searching headers and libs 0.04 Wed Jul 29 11:41:55 2009 - fix cc_append_to_ccflags() on non-Win32 system - code refactering 0.03 Tue Jul 28 12:05:42 2009 - May this work on Windows! 0.02 Mon Jul 27 13:59:29 2009 - no 'provides' section for header files - add rpository info 0.01 Sun Jul 26 09:52:01 2009 - original version; created by Module::Setup perl-Module-Install-XSUtil-0.44/MANIFEST.SKIP000064400000000000000000000012611213564174400203230ustar00rootroot00000000000000 #!start included /usr/local/lib/perl5/5.10.0/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 # 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/ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ # Avoid Devel::Cover files. \bcover_db\b #!end included /usr/local/lib/perl5/5.10.0/ExtUtils/MANIFEST.SKIP # skip dot files ^\. # skip author's files \bauthor\b MYMETA\.yml$ MYMETA\.json$ perl-Module-Install-XSUtil-0.44/Makefile.PL000064400000000000000000000011231213564174400203740ustar00rootroot00000000000000#!perl use strict; use inc::Module::Install; all_from 'lib/Module/Install/XSUtil.pm'; requires 'Module::Install' => 0.91; test_requires 'Test::More' => 0.88; # these modules are required for t/01_example.t test_requires 'Devel::PPPort' => 3.19; test_requires 'ExtUtils::ParseXS' => 2.21; test_requires 'XSLoader' => 0.10; test_requires 'B::Hooks::OP::Annotation' => 0.43; tests 't/*.t'; author_tests 'xt'; auto_set_repository; clean_files qw( Module-Install-XSUtil-* *.stackdump cover_db nytprof *.out ); WriteAll check_nmake => 0; perl-Module-Install-XSUtil-0.44/README000064400000000000000000000010651213564174400173070ustar00rootroot00000000000000This is Perl module Module::Install::XSUtil. INSTALLATION Module::Install::XSUtil installation is straightforward. If your CPAN shell is set up, you should just be able to do $ cpan Module::Install::XSUtil Download it, unpack it, then build it as per the usual: $ perl Makefile.PL $ make && make test Then install it: $ make install DOCUMENTATION Module::Install::XSUtil documentation is available as in POD. So you can do: $ perldoc Module::Install::XSUtil to read the documentation online with your favorite pager. Goro Fuji (gfx) perl-Module-Install-XSUtil-0.44/example/000075500000000000000000000000001213564174400200605ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/example/MyMakefile.PL000064400000000000000000000007411213564174400223420ustar00rootroot00000000000000#!perl -w use strict; use FindBin qw($Bin); use File::Spec; use lib File::Spec->join($Bin, '..', 'lib'); use Config; use inc::Module::Install; BEGIN{ @ARGV = qw(-g) unless @ARGV; } all_from 'lib/Foo.pm'; requires_xs 'B::Hooks::OP::Annotation'; # for testing only use_ppport 3.19; use_xshelper -clean; cc_warnings; requires_c99 if $Config{gccversion}; cc_include_paths 'include'; cc_src_paths 'src'; cc_define -DFOO_OK; install_headers; WriteAll check_nmake => 0; perl-Module-Install-XSUtil-0.44/example/README000075500000000000000000000001331213564174400207400ustar00rootroot00000000000000This is an example distriution using Module::Install::XSUtil See Makefile.PL for details. perl-Module-Install-XSUtil-0.44/example/include/000075500000000000000000000000001213564174400215035ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/example/include/foo.h000075500000000000000000000002021213564174400224340ustar00rootroot00000000000000/* foo.h for testing */ #ifdef USE_PPPORT #include "ppport.h" #endif bool foo_is_ok(void); typedef int (*fake_decl)(int, int); perl-Module-Install-XSUtil-0.44/example/include/foo/000075500000000000000000000000001213564174400222665ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/example/include/foo/bar.h000075500000000000000000000013351213564174400232100ustar00rootroot00000000000000/* foo/bar.h for testing */ #define X(name) int name #ifndef __attribute__warn_unused_result__ #ifdef HASATTRIBUTE_WARN_UNUSED_RESULT # define __attribute__warn_unused_result__ __attribute__((warn_unused_result)) #else # define __attribute__warn_unused_result__ #endif #endif /* !defined(__attribute__warn_unused_result__) */ #ifndef PERL_UNUSED_DECL # if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus) && defined(__attribute__unused__) # define PERL_UNUSED_DECL __attribute__unused__ # else # define PERL_UNUSED_DECL # endif #endif X(bar_is_ok)( X(a) PERL_UNUSED_DECL, X(b), X(c) ) __attribute__warn_unused_result__; struct mi_xsutil_testing { void* (*not_a_function)(int a PERL_UNUSED_DECL, int); }; perl-Module-Install-XSUtil-0.44/example/include/foo/baz.h000075500000000000000000000000361213564174400232150ustar00rootroot00000000000000/* foo/baz.h for testing */ perl-Module-Install-XSUtil-0.44/example/lib/000075500000000000000000000000001213564174400206265ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/example/lib/Foo.pm000075500000000000000000000007351213564174400217170ustar00rootroot00000000000000package Foo; use 5.005_03; $VERSION = '1.23'; use XSLoader; XSLoader::load(__PACKAGE__, $VERSION); use B::Hooks::OP::Annotation; 1; __END__ =head1 NAME Foo - A testing module for Module::Install::XSUtil =head1 AUTHOR Goro Fuji (gfx) Egfuji(at)cpan.orgE. =head1 LICENSE AND COPYRIGHT Copyright (c) 2009, Goro Fuji (gfx). Some rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut perl-Module-Install-XSUtil-0.44/example/src/000075500000000000000000000000001213564174400206475ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/example/src/Foo.xs000075500000000000000000000007511213564174400217540ustar00rootroot00000000000000#include "xshelper.h" #include "foo.h" #include "foo/bar.h" #include "foo/baz.h" #include "Install/hook_op_annotation.h" bool foo_is_ok(void){ #ifdef FOO_OK return TRUE; #else return FALSE; #endif } STATIC OPAnnotationGroup MYMODULE_ANNOTATIONS; MODULE = Foo PACKAGE = Foo PROTOTYPES: DISABLE BOOT: MYMODULE_ANNOTATIONS = op_annotation_group_new(); void END() CODE: op_annotation_group_free(aTHX_ MYMODULE_ANNOTATIONS); bool foo_is_ok() int bar_is_ok(int a, int b, int c) perl-Module-Install-XSUtil-0.44/example/src/bar.c000075500000000000000000000002141213564174400215570ustar00rootroot00000000000000#include "xshelper.h" #include "foo.h" #include "foo/bar.h" #include "foo/baz.h" X(bar_is_ok)( X(a), X(b), X(c) ){ return a + b + c; } perl-Module-Install-XSUtil-0.44/example/t/000075500000000000000000000000001213564174400203235ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/example/t/foo.t000075500000000000000000000003151213564174400212750ustar00rootroot00000000000000#!perl -w use strict; use Test::More; BEGIN { use_ok 'Foo' } ok eval{ Foo::foo_is_ok() }, 'foo_is_ok()' or diag $@; is eval{ Foo::bar_is_ok(10, 20, 12) }, 42, 'bar_is_ok()' or diag $@; done_testing; perl-Module-Install-XSUtil-0.44/lib/000075500000000000000000000000001213564174400171735ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/lib/Module/000075500000000000000000000000001213564174400204205ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/lib/Module/Install/000075500000000000000000000000001213564174400220265ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/lib/Module/Install/XSUtil.pm000064400000000000000000000577541213564174400235760ustar00rootroot00000000000000package Module::Install::XSUtil; use 5.005_03; $VERSION = '0.44'; use Module::Install::Base; @ISA = qw(Module::Install::Base); use strict; use Config; use File::Spec; use File::Find; use constant _VERBOSE => $ENV{MI_VERBOSE} ? 1 : 0; my %ConfigureRequires = ( 'ExtUtils::ParseXS' => 2.21, ); my %BuildRequires = ( ); my %Requires = ( 'XSLoader' => 0.02, ); my %ToInstall; my $UseC99 = 0; my $UseCplusplus = 0; sub _verbose{ print STDERR q{# }, @_, "\n"; } sub _xs_debugging{ return $ENV{XS_DEBUG} || scalar( grep{ $_ eq '-g' } @ARGV ); } sub _xs_initialize{ my($self) = @_; unless($self->{xsu_initialized}){ $self->{xsu_initialized} = 1; if(!$self->cc_available()){ warn "This distribution requires a C compiler, but it's not available, stopped.\n"; exit; } $self->configure_requires(%ConfigureRequires); $self->build_requires(%BuildRequires); $self->requires(%Requires); $self->makemaker_args->{OBJECT} = '$(O_FILES)'; $self->clean_files('$(O_FILES)'); $self->clean_files('*.stackdump') if $^O eq 'cygwin'; if($self->_xs_debugging()){ # override $Config{optimize} if(_is_msvc()){ $self->makemaker_args->{OPTIMIZE} = '-Zi'; } else{ $self->makemaker_args->{OPTIMIZE} = '-g -ggdb -g3'; } $self->cc_define('-DXS_ASSERT'); } } return; } # GNU C Compiler sub _is_gcc{ return $Config{gccversion}; } # Microsoft Visual C++ Compiler (cl.exe) sub _is_msvc{ return $Config{cc} =~ /\A cl \b /xmsi; } { my $cc_available; sub cc_available { return defined $cc_available ? $cc_available : ($cc_available = shift->can_cc()) ; } # cf. https://github.com/sjn/toolchain-site/blob/219db464af9b2f19b04fec05547ac10180a469f3/lancaster-consensus.md my $want_xs; sub want_xs { my($self, $default) = @_; return $want_xs if defined $want_xs; # you're using this module, you must want XS by default # unless PERL_ONLY is true. $default = !$ENV{PERL_ONLY} if not defined $default; foreach my $arg(@ARGV){ my ($k, $v) = split '=', $arg; # MM-style named args if ($k eq 'PUREPERL_ONLY' && defined $v) { return $want_xs = !$v; } elsif($arg eq '--pp'){ # old-style return $want_xs = 0; } elsif($arg eq '--xs'){ return $want_xs = 1; } } if ($ENV{PERL_MM_OPT}) { my($v) = $ENV{PERL_MM_OPT} =~ /\b PUREPERL_ONLY = (\S+) /xms; if (defined $v) { return $want_xs = !$v; } } return $want_xs = $default; } } sub use_ppport{ my($self, $dppp_version) = @_; return if $self->{_ppport_ok}++; $self->_xs_initialize(); my $filename = 'ppport.h'; $dppp_version ||= 3.19; # the more, the better $self->configure_requires('Devel::PPPort' => $dppp_version); $self->build_requires('Devel::PPPort' => $dppp_version); print "Writing $filename\n"; my $e = do{ local $@; eval qq{ use Devel::PPPort; Devel::PPPort::WriteFile(q{$filename}); }; $@; }; if($e){ print "Cannot create $filename because: $@\n"; } if(-e $filename){ $self->clean_files($filename); $self->cc_define('-DUSE_PPPORT'); $self->cc_append_to_inc('.'); } return; } sub use_xshelper { my($self, $opt) = @_; $self->_xs_initialize(); $self->use_ppport(); my $file = 'xshelper.h'; open my $fh, '>', $file or die "Cannot open $file for writing: $!"; print $fh $self->_xshelper_h(); close $fh or die "Cannot close $file: $!"; if(defined $opt) { if($opt eq '-clean') { $self->clean_files($file); } else { $self->realclean_files($file); } } return; } sub _gccversion { my $res = `$Config{cc} --version`; my ($version) = $res =~ /\(GCC\) ([0-9.]+)/; no warnings 'numeric', 'uninitialized'; return sprintf '%g', $version; } sub cc_warnings{ my($self) = @_; $self->_xs_initialize(); if(_is_gcc()){ $self->cc_append_to_ccflags(qw(-Wall)); my $gccversion = _gccversion(); if($gccversion >= 4.0){ $self->cc_append_to_ccflags(qw(-Wextra)); if(!($UseC99 or $UseCplusplus)) { # Note: MSVC++ doesn't support C99, # so -Wdeclaration-after-statement helps # ensure C89 specs. $self->cc_append_to_ccflags(qw(-Wdeclaration-after-statement)); } if($gccversion >= 4.1 && !$UseCplusplus) { $self->cc_append_to_ccflags(qw(-Wc++-compat)); } } else{ $self->cc_append_to_ccflags(qw(-W -Wno-comment)); } } elsif(_is_msvc()){ $self->cc_append_to_ccflags(qw(-W3)); } else{ # TODO: support other compilers } return; } sub c99_available { my($self) = @_; return 0 if not $self->cc_available(); require File::Temp; require File::Basename; my $tmpfile = File::Temp->new(SUFFIX => '.c'); $tmpfile->print(<<'C99'); // include a C99 header #include inline // a C99 keyword with C99 style comments int test_c99() { int i = 0; i++; int j = i - 1; // another C99 feature: declaration after statement return j; } C99 $tmpfile->close(); system "$Config{cc} -c " . $tmpfile->filename; (my $objname = File::Basename::basename($tmpfile->filename)) =~ s/\Q.c\E$/$Config{_o}/; unlink $objname or warn "Cannot unlink $objname (ignored): $!"; return $? == 0; } sub requires_c99 { my($self) = @_; if(!$self->c99_available) { warn "This distribution requires a C99 compiler, but $Config{cc} seems not to support C99, stopped.\n"; exit; } $self->_xs_initialize(); $UseC99 = 1; return; } sub requires_cplusplus { my($self) = @_; if(!$self->cc_available) { warn "This distribution requires a C++ compiler, but $Config{cc} seems not to support C++, stopped.\n"; exit; } $self->_xs_initialize(); $UseCplusplus = 1; return; } sub cc_append_to_inc{ my($self, @dirs) = @_; $self->_xs_initialize(); for my $dir(@dirs){ unless(-d $dir){ warn("'$dir' not found: $!\n"); } _verbose "inc: -I$dir" if _VERBOSE; } my $mm = $self->makemaker_args; my $paths = join q{ }, map{ s{\\}{\\\\}g; qq{"-I$_"} } @dirs; if($mm->{INC}){ $mm->{INC} .= q{ } . $paths; } else{ $mm->{INC} = $paths; } return; } sub cc_libs { my ($self, @libs) = @_; @libs = map{ my($name, $dir) = ref($_) eq 'ARRAY' ? @{$_} : ($_, undef); my $lib; if(defined $dir) { $lib = ($dir =~ /^-/ ? qq{$dir } : qq{-L$dir }); } else { $lib = ''; } $lib .= ($name =~ /^-/ ? qq{$name} : qq{-l$name}); _verbose "libs: $lib" if _VERBOSE; $lib; } @libs; $self->cc_append_to_libs( @libs ); } sub cc_append_to_libs{ my($self, @libs) = @_; $self->_xs_initialize(); return unless @libs; my $libs = join q{ }, @libs; my $mm = $self->makemaker_args; if ($mm->{LIBS}){ $mm->{LIBS} .= q{ } . $libs; } else{ $mm->{LIBS} = $libs; } return $libs; } sub cc_assert_lib { my ($self, @dcl_args) = @_; if ( ! $self->{xsu_loaded_checklib} ) { my $loaded_lib = 0; foreach my $checklib (qw(inc::Devel::CheckLib Devel::CheckLib)) { eval "use $checklib 0.4"; if (!$@) { $loaded_lib = 1; last; } } if (! $loaded_lib) { warn "Devel::CheckLib not found in inc/ nor \@INC"; exit 0; } $self->{xsu_loaded_checklib}++; $self->configure_requires( "Devel::CheckLib" => "0.4" ); $self->build_requires( "Devel::CheckLib" => "0.4" ); } Devel::CheckLib::check_lib_or_exit(@dcl_args); } sub cc_append_to_ccflags{ my($self, @ccflags) = @_; $self->_xs_initialize(); my $mm = $self->makemaker_args; $mm->{CCFLAGS} ||= $Config{ccflags}; $mm->{CCFLAGS} .= q{ } . join q{ }, @ccflags; return; } sub cc_define{ my($self, @defines) = @_; $self->_xs_initialize(); my $mm = $self->makemaker_args; if(exists $mm->{DEFINE}){ $mm->{DEFINE} .= q{ } . join q{ }, @defines; } else{ $mm->{DEFINE} = join q{ }, @defines; } return; } sub requires_xs_module { my $self = shift; return $self->requires() unless @_; $self->_xs_initialize(); my %added = $self->requires(@_); my(@inc, @libs); my $rx_lib = qr{ \. (?: lib | a) \z}xmsi; my $rx_dll = qr{ \. dll \z}xmsi; # for Cygwin while(my $module = each %added){ my $mod_basedir = File::Spec->join(split /::/, $module); my $rx_header = qr{\A ( .+ \Q$mod_basedir\E ) .+ \. h(?:pp)? \z}xmsi; SCAN_INC: foreach my $inc_dir(@INC){ my @dirs = grep{ -e } File::Spec->join($inc_dir, 'auto', $mod_basedir), File::Spec->join($inc_dir, $mod_basedir); next SCAN_INC unless @dirs; my $n_inc = scalar @inc; find(sub{ if(my($incdir) = $File::Find::name =~ $rx_header){ push @inc, $incdir; } elsif($File::Find::name =~ $rx_lib){ my($libname) = $_ =~ /\A (?:lib)? (\w+) /xmsi; push @libs, [$libname, $File::Find::dir]; } elsif($File::Find::name =~ $rx_dll){ # XXX: hack for Cygwin my $mm = $self->makemaker_args; $mm->{macro}->{PERL_ARCHIVE_AFTER} ||= ''; $mm->{macro}->{PERL_ARCHIVE_AFTER} .= ' ' . $File::Find::name; } }, @dirs); if($n_inc != scalar @inc){ last SCAN_INC; } } } my %uniq = (); $self->cc_append_to_inc (grep{ !$uniq{ $_ }++ } @inc); %uniq = (); $self->cc_libs(grep{ !$uniq{ $_->[0] }++ } @libs); return %added; } sub cc_src_paths{ my($self, @dirs) = @_; $self->_xs_initialize(); return unless @dirs; my $mm = $self->makemaker_args; my $XS_ref = $mm->{XS} ||= {}; my $C_ref = $mm->{C} ||= []; my $_obj = $Config{_o}; my @src_files; find(sub{ if(/ \. (?: xs | c (?: c | pp | xx )? ) \z/xmsi){ # *.{xs, c, cc, cpp, cxx} push @src_files, $File::Find::name; } }, @dirs); my $xs_to = $UseCplusplus ? '.cpp' : '.c'; foreach my $src_file(@src_files){ my $c = $src_file; if($c =~ s/ \.xs \z/$xs_to/xms){ $XS_ref->{$src_file} = $c; _verbose "xs: $src_file" if _VERBOSE; } else{ _verbose "c: $c" if _VERBOSE; } push @{$C_ref}, $c unless grep{ $_ eq $c } @{$C_ref}; } $self->clean_files(map{ File::Spec->catfile($_, '*.gcov'), File::Spec->catfile($_, '*.gcda'), File::Spec->catfile($_, '*.gcno'), } @dirs); $self->cc_append_to_inc('.'); return; } sub cc_include_paths{ my($self, @dirs) = @_; $self->_xs_initialize(); push @{ $self->{xsu_include_paths} ||= []}, @dirs; my $h_map = $self->{xsu_header_map} ||= {}; foreach my $dir(@dirs){ my $prefix = quotemeta( File::Spec->catfile($dir, '') ); find(sub{ return unless / \.h(?:pp)? \z/xms; (my $h_file = $File::Find::name) =~ s/ \A $prefix //xms; $h_map->{$h_file} = $File::Find::name; }, $dir); } $self->cc_append_to_inc(@dirs); return; } sub install_headers{ my $self = shift; my $h_files; if(@_ == 0){ $h_files = $self->{xsu_header_map} or die "install_headers: cc_include_paths not specified.\n"; } elsif(@_ == 1 && ref($_[0]) eq 'HASH'){ $h_files = $_[0]; } else{ $h_files = +{ map{ $_ => undef } @_ }; } $self->_xs_initialize(); my @not_found; my $h_map = $self->{xsu_header_map} || {}; while(my($ident, $path) = each %{$h_files}){ $path ||= $h_map->{$ident} || File::Spec->join('.', $ident); $path = File::Spec->canonpath($path); unless($path && -e $path){ push @not_found, $ident; next; } $ToInstall{$path} = File::Spec->join('$(INST_ARCHAUTODIR)', $ident); _verbose "install: $path as $ident" if _VERBOSE; my @funcs = $self->_extract_functions_from_header_file($path); if(@funcs){ $self->cc_append_to_funclist(@funcs); } } if(@not_found){ die "Header file(s) not found: @not_found\n"; } return; } my $home_directory; sub _extract_functions_from_header_file{ my($self, $h_file) = @_; my @functions; ($home_directory) = <~> unless defined $home_directory; # get header file contents through cpp(1) my $contents = do { my $mm = $self->makemaker_args; my $cppflags = q{"-I}. File::Spec->join($Config{archlib}, 'CORE') . q{"}; $cppflags =~ s/~/$home_directory/g; $cppflags .= ' ' . $mm->{INC} if $mm->{INC}; $cppflags .= ' ' . ($mm->{CCFLAGS} || $Config{ccflags}); $cppflags .= ' ' . $mm->{DEFINE} if $mm->{DEFINE}; my $add_include = _is_msvc() ? '-FI' : '-include'; $cppflags .= ' ' . join ' ', map{ qq{$add_include "$_"} } qw(EXTERN.h perl.h XSUB.h); my $cppcmd = qq{$Config{cpprun} $cppflags $h_file}; # remove all the -arch options to workaround gcc errors: # "-E, -S, -save-temps and -M options are not allowed # with multiple -arch flags" $cppcmd =~ s/ -arch \s* \S+ //xmsg; _verbose("extract functions from: $cppcmd") if _VERBOSE; `$cppcmd`; }; unless(defined $contents){ die "Cannot call C pre-processor ($Config{cpprun}): $! ($?)"; } # remove other include file contents my $chfile = q/\# (?:line)? \s+ \d+ /; $contents =~ s{ ^$chfile \s+ (?!"\Q$h_file\E") .*? ^(?= $chfile) }{}xmsig; if(_VERBOSE){ local *H; open H, "> $h_file.out" and print H $contents and close H; } while($contents =~ m{ ([^\\;\s]+ # type \s+ ([a-zA-Z_][a-zA-Z0-9_]*) # function name \s* \( [^;#]* \) # argument list [\w\s\(\)]* # attributes or something ;) # end of declaration }xmsg){ my $decl = $1; my $name = $2; next if $decl =~ /\b typedef \b/xms; next if $name =~ /^_/xms; # skip something private push @functions, $name; if(_VERBOSE){ $decl =~ tr/\n\r\t / /s; $decl =~ s/ (\Q$name\E) /<$name>/xms; _verbose("decl: $decl"); } } return @functions; } sub cc_append_to_funclist{ my($self, @functions) = @_; $self->_xs_initialize(); my $mm = $self->makemaker_args; push @{$mm->{FUNCLIST} ||= []}, @functions; $mm->{DL_FUNCS} ||= { '$(NAME)' => [] }; return; } sub _xshelper_h { my $h = <<'XSHELPER_H'; :/* THIS FILE IS AUTOMATICALLY GENERATED BY Module::Install::XSUtil $VERSION. */ :/* :=head1 NAME : :xshelper.h - Helper C header file for XS modules : :=head1 DESCRIPTION : : // This includes all the perl header files and ppport.h : #include "xshelper.h" : :=head1 SEE ALSO : :L, where this file is distributed as a part of : :=head1 AUTHOR : :Fuji, Goro (gfx) Egfuji at cpan.orgE : :=head1 LISENCE : :Copyright (c) 2010, Fuji, Goro (gfx). All rights reserved. : :This library is free software; you can redistribute it and/or modify :it under the same terms as Perl itself. : :=cut :*/ : :#ifdef __cplusplus :extern "C" { :#endif : :#define PERL_NO_GET_CONTEXT /* we want efficiency */ :#include :#include :#define NO_XSLOCKS /* for exceptions */ :#include : :#ifdef __cplusplus :} /* extern "C" */ :#endif : :#include "ppport.h" : :/* portability stuff not supported by ppport.h yet */ : :#ifndef STATIC_INLINE /* from 5.13.4 */ :# if defined(__GNUC__) || defined(__cplusplus) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) :# define STATIC_INLINE static inline :# else :# define STATIC_INLINE static :# endif :#endif /* STATIC_INLINE */ : :#ifndef __attribute__format__ :#define __attribute__format__(a,b,c) /* nothing */ :#endif : :#ifndef LIKELY /* they are just a compiler's hint */ :#define LIKELY(x) (!!(x)) :#define UNLIKELY(x) (!!(x)) :#endif : :#ifndef newSVpvs_share :#define newSVpvs_share(s) Perl_newSVpvn_share(aTHX_ STR_WITH_LEN(s), 0U) :#endif : :#ifndef get_cvs :#define get_cvs(name, flags) get_cv(name, flags) :#endif : :#ifndef GvNAME_get :#define GvNAME_get GvNAME :#endif :#ifndef GvNAMELEN_get :#define GvNAMELEN_get GvNAMELEN :#endif : :#ifndef CvGV_set :#define CvGV_set(cv, gv) (CvGV(cv) = (gv)) :#endif : :/* general utility */ : :#if PERL_BCDVERSION >= 0x5008005 :#define LooksLikeNumber(x) looks_like_number(x) :#else :#define LooksLikeNumber(x) (SvPOKp(x) ? looks_like_number(x) : (I32)SvNIOKp(x)) :#endif : :#define newAV_mortal() (AV*)sv_2mortal((SV*)newAV()) :#define newHV_mortal() (HV*)sv_2mortal((SV*)newHV()) :#define newRV_inc_mortal(sv) sv_2mortal(newRV_inc(sv)) :#define newRV_noinc_mortal(sv) sv_2mortal(newRV_noinc(sv)) : :#define DECL_BOOT(name) EXTERN_C XS(CAT2(boot_, name)) :#define CALL_BOOT(name) STMT_START { \ : PUSHMARK(SP); \ : CALL_FPTR(CAT2(boot_, name))(aTHX_ cv); \ : } STMT_END XSHELPER_H $h =~ s/^://xmsg; $h =~ s/\$VERSION\b/$Module::Install::XSUtil::VERSION/xms; return $h; } package MY; # XXX: We must append to PM inside ExtUtils::MakeMaker->new(). sub init_PM { my $self = shift; $self->SUPER::init_PM(@_); while(my($k, $v) = each %ToInstall){ $self->{PM}{$k} = $v; } return; } # append object file names to CCCMD sub const_cccmd { my $self = shift; my $cccmd = $self->SUPER::const_cccmd(@_); return q{} unless $cccmd; if (Module::Install::XSUtil::_is_msvc()){ $cccmd .= ' -Fo$@'; } else { $cccmd .= ' -o $@'; } return $cccmd } sub xs_c { my($self) = @_; my $mm = $self->SUPER::xs_c(); $mm =~ s/ \.c /.cpp/xmsg if $UseCplusplus; return $mm; } sub xs_o { my($self) = @_; my $mm = $self->SUPER::xs_o(); $mm =~ s/ \.c /.cpp/xmsg if $UseCplusplus; return $mm; } 1; __END__ =for stopwords gfx API =head1 NAME Module::Install::XSUtil - Utility functions for XS modules =head1 VERSION This document describes Module::Install::XSUtil version 0.44. =head1 SYNOPSIS # in Makefile.PL use inc::Module::Install; # Enables C compiler warnings cc_warnings; # Uses ppport.h # No need to include it. It's created here. use_ppport 3.19; # Sets C pre-processor macros. cc_define q{-DUSE_SOME_FEATURE=42}; # Sets paths for header files cc_include_paths 'include'; # all the header files are in include/ # Sets paths for source files cc_src_paths 'src'; # all the XS and C source files are in src/ # Installs header files install_headers; # all the header files in @cc_include_paths =head1 DESCRIPTION Module::Install::XSUtil provides a set of utilities to setup distributions which include or depend on XS module. See L and L for example. =head1 FUNCTIONS =head2 cc_available Returns true if a C compiler is available. YOU DO NOT NEED TO CALL THIS FUNCTION YOURSELF: it will be called for you when this module is initialized, and your Makefile.PL process will exit with 0 status. Only explicitly call if you need to do some esoteric handling when no compiler is available (for example, when you have a pure perl alternative) =head2 c99_available Returns true if a C compiler is available and it supports C99 features. =head2 want_xs ?$default Returns true if the user asked for the XS version or pure perl version of the module. Will return true if C<--xs> is explicitly specified as the argument to F, and false if C<--pp> is specified. If neither is explicitly specified, will return the value specified by C<$default>. If you do not specify the value of C<$default>, then it will be true. =head2 use_ppport ?$version Creates F using C. This command calls C<< configure_requires 'Devel::PPPort' => $version >> and adds C<-DUSE_PPPORT> to C's C. =head2 use_xshelper ?-clean|-realclean Create sF, which is a helper header file to include F, F, F and F, and defines some portability stuff which are not supported by F. Optional argument C<-clean> and C<-realclean> set C or C to the generated file F respectably. This command includes C. =head2 cc_warnings Enables C compiler warnings. =head2 cc_define @macros Sets C macros as compiler options. =head2 cc_src_paths @source_paths Sets source file directories which include F<*.xs> or F<*.c>. =head2 cc_include_paths @include_paths Sets include paths for a C compiler. =head2 cc_inc_paths @include_paths; This B an alias to C, but from 0.42, this is C, which replaces the EUMM's C parameter. Don't use this function. Use C instead. =head2 cc_libs @libs Sets C's C. If a name starts C<->, it will be interpreted as is. Otherwise prefixed C<-l>. e.g.: cc_libs -lfoo; cc_libs 'foo'; # ditto. cc_libs qw(-L/path/to/libs foo bar); # with library paths =head2 cc_assert_lib %args Checks if the given C library is installed via Devel::CheckLib. Takes exactly what Devel::CheckLib takes. Note that you must pass the path names explicitly. =head2 requires_c99 Tells the build system to use C99 features. =head2 requires_cplusplus Tells the build system to use C++ language. =head2 install_headers ?@header_files Declares providing header files, extracts functions from these header files, and adds these functions to C's C. If I<@header_files> are omitted, all the header files in B will be installed. =head2 cc_append_to_inc @include_paths Low level API. =head2 cc_append_to_libs @libraries Low level API. =head2 cc_append_to_ccflags @ccflags Low level API. =head2 cc_append_to_funclist @funclist Low level API. =head1 OPTIONS Under the control of this module, F accepts C<-g> option, which sets C's C C<-g> (or something like). It will disable optimization and enable some debugging features. =head1 DEPENDENCIES Perl 5.5.3 or later. =head1 NOTE In F, you might want to use C, which is provided by C, in order to tell co-developers that they need to install this plugin. author_requires 'Module::Install::XSUtil'; =head1 BUGS No bugs have been reported. Please report any bugs or feature requests to the author. =head1 ACKNOWLEDGEMENT Thanks to Taro Nishino for the test reports. Tanks to lestrrat for the suggestions and patches. =head1 AUTHOR Goro Fuji (gfx) Egfuji(at)cpan.orgE. =head1 SEE ALSO L. L. L. L. L. =head1 LICENSE AND COPYRIGHT Copyright (c) 2009-2010, Goro Fuji (gfx). All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut perl-Module-Install-XSUtil-0.44/t/000075500000000000000000000000001213564174400166705ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/t/00_load.t000075500000000000000000000002511213564174400202740ustar00rootroot00000000000000#!perl -w use strict; use Test::More tests => 1; BEGIN { use_ok 'Module::Install::XSUtil' } diag "Testing Module::Install::XSUtil/$Module::Install::XSUtil::VERSION"; perl-Module-Install-XSUtil-0.44/xt/000075500000000000000000000000001213564174400170605ustar00rootroot00000000000000perl-Module-Install-XSUtil-0.44/xt/01_podspell.t000075500000000000000000000003701213564174400213720ustar00rootroot00000000000000#!perl -w use strict; use Test::More; use Test::Spellunker v0.2.1; load_dictionary(\*DATA); all_pod_files_spelling_ok('lib'); __DATA__ Goro Fuji (gfx) gfuji(at)cpan.org Module::Install::XSUtil Nishino lestrrat ACKNOWLEDGEMENT XS RT co realclean perl-Module-Install-XSUtil-0.44/xt/02_pod.t000075500000000000000000000002331213564174400203310ustar00rootroot00000000000000#!perl -w use strict; use Test::More; eval q{use Test::Pod 1.14}; plan skip_all => 'Test::Pod 1.14 required for testing POD' if $@; all_pod_files_ok(); perl-Module-Install-XSUtil-0.44/xt/04_example.t000075500000000000000000000030541213564174400212100ustar00rootroot00000000000000#!perl -w use strict; use Test::More skip_all => 'no longer maintained'; use FindBin qw($Bin); use File::Spec; use Config; use File::Find; use File::Copy qw(copy); my $dist_dir = File::Spec->join($Bin, '..', 'example'); chdir $dist_dir or die "Cannot chdir to $dist_dir: $!"; # workaround subdir auto-building :( copy "MyMakefile.PL" => "Makefile.PL"; END { unlink 'Makefile.PL'; } my $make = $Config{make}; my $out; note "$^X Makefile.PL"; ok($out = `$^X Makefile.PL`, "$^X Makefile.PL"); is $?, 0, '... success' or diag $out; ok($out = `$make`, $make); is $?, 0, '... success' or diag $out; ok($out = `$make test`, "$make test"); is $?, 0, '... success' or diag $out; ok -e 'ppport.h', 'ppport.h exists'; my %h_files; find sub{ $h_files{$_} = File::Spec->canonpath($File::Find::name) if / \.h \z/xms; }, qw(blib); is scalar(keys %h_files), 3, 'two head files are installed'; ok exists $h_files{'foo.h'}, 'foo.h exists'; ok exists $h_files{'bar.h'}, 'bar.h exists'; ok exists $h_files{'baz.h'}, 'baz.h exists'; sub f2rx{ my $f = quotemeta( File::Spec->join(@_) ); return qr/$f/xmsi; } like $h_files{'foo.h'}, f2rx(qw(Foo foo.h)); like $h_files{'bar.h'}, f2rx(qw(Foo bar.h)); like $h_files{'baz.h'}, f2rx(qw(Foo foo baz.h)); my $Makefile = do{ local *MF; open MF, 'Makefile' or die $!; local $/; ; }; like $Makefile, qr/\b foo_is_ok \b/xms, 'Makefile includes foo_is_ok()'; like $Makefile, qr/\b bar_is_ok \b/xms, 'Makefile includes bar_is_ok()'; ok scalar `$make realclean`, "$make realclean"; is $?, 0, '... success'; done_testing;