You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2014/11/08 19:55:25 UTC
[08/11] lucy-clownfish git commit: Compile core C files for Perl
build using make
Compile core C files for Perl build using make
Create a static library of the core C code using the generated Makefile
and link the result with the compiled XS code. Make options can be
passed by running
perl Build.PL --clownfish_params make_options=<options>
Module::Build options can also be specified in ~/.modulebuildrc, so an
easy way to always launch parallel builds is to add a line like
Build_PL --clownfish_params make_options=-j5
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/5a4413b2
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/5a4413b2
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/5a4413b2
Branch: refs/heads/perl_build_with_make
Commit: 5a4413b2a3da287bc68318ce9f19fdefc9902327
Parents: f85267d
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Wed Oct 29 20:29:30 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Nov 8 19:37:59 2014 +0100
----------------------------------------------------------------------
compiler/perl/lib/Clownfish/CFC/Perl/Build.pm | 70 ++++++++++++++------
.../lib/Clownfish/CFC/Perl/Build/Charmonic.pm | 18 +++--
runtime/perl/.gitignore | 6 +-
runtime/perl/buildlib/Clownfish/Build.pm | 1 +
4 files changed, 69 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5a4413b2/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm b/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
index 641bb4d..3e29832 100644
--- a/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
+++ b/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
@@ -379,6 +379,10 @@ sub ACTION_compile_custom_xs {
$self->depends_on('ppport');
+ my $is_charmonic = $self->isa('Clownfish::CFC::Perl::Build::Charmonic');
+ $self->depends_on('charmony')
+ if $is_charmonic;
+
require ExtUtils::CBuilder;
require ExtUtils::ParseXS;
@@ -394,27 +398,41 @@ sub ACTION_compile_custom_xs {
my @objects;
# Compile C source files.
- my $c_files = [];
- my $source_dirs = $self->clownfish_params('source');
- for my $source_dir (@$source_dirs) {
- push @$c_files, @{ $self->rscan_dir( $source_dir, qr/\.c$/ ) };
- }
- my $extra_cflags = $self->clownfish_params('cflags');
- for my $c_file (@$c_files) {
- my $o_file = $c_file;
- my $ccs_file = $c_file;
- $o_file =~ s/\.c$/$Config{_o}/ or die "no match";
- $ccs_file =~ s/\.c$/.ccs/ or die "no match";
- push @objects, $o_file;
- next if $self->up_to_date( $c_file, $o_file );
- $self->add_to_cleanup($o_file);
- $self->add_to_cleanup($ccs_file);
- $cbuilder->compile(
- source => $c_file,
- extra_compiler_flags => $extra_cflags,
- include_dirs => [ $self->cf_c_include_dirs ],
- object_file => $o_file,
+ if ($is_charmonic && $self->charmonizer_params('create_makefile')) {
+ my $make_options = $self->clownfish_params('make_options');
+ my $static_lib_file = $self->charmony('STATIC_LIB_FILENAME');
+ push @objects, $static_lib_file;
+ my @command = (
+ $self->config('make'),
+ $self->split_like_shell($make_options),
+ $static_lib_file,
);
+ print join(' ', @command), "\n";
+ system @command and die($self->config('make') . " failed");
+ }
+ else {
+ my $c_files = [];
+ my $source_dirs = $self->clownfish_params('source');
+ for my $source_dir (@$source_dirs) {
+ push @$c_files, @{ $self->rscan_dir( $source_dir, qr/\.c$/ ) };
+ }
+ my $extra_cflags = $self->clownfish_params('cflags');
+ for my $c_file (@$c_files) {
+ my $o_file = $c_file;
+ my $ccs_file = $c_file;
+ $o_file =~ s/\.c$/$Config{_o}/ or die "no match";
+ $ccs_file =~ s/\.c$/.ccs/ or die "no match";
+ push @objects, $o_file;
+ next if $self->up_to_date( $c_file, $o_file );
+ $self->add_to_cleanup($o_file);
+ $self->add_to_cleanup($ccs_file);
+ $cbuilder->compile(
+ source => $c_file,
+ extra_compiler_flags => $extra_cflags,
+ include_dirs => [ $self->cf_c_include_dirs ],
+ object_file => $o_file,
+ );
+ }
}
# .xs => .c
@@ -510,6 +528,18 @@ sub ACTION_code {
$self->SUPER::ACTION_code;
}
+sub ACTION_clean {
+ my $self = shift;
+
+ my $is_charmonic = $self->isa('Clownfish::CFC::Perl::Build::Charmonic');
+ if ($is_charmonic && $self->charmonizer_params('create_makefile')) {
+ system $self->config('make'), 'distclean'
+ if -e 'Makefile';
+ }
+
+ $self->SUPER::ACTION_clean;
+}
+
# Monkey patch ExtUtils::CBuilder::Platform::Windows::GCC::format_linker_cmd
# to make extensions work on MinGW.
#
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5a4413b2/compiler/perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm b/compiler/perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm
index a37b6b4..eb7df56 100644
--- a/compiler/perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm
+++ b/compiler/perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm
@@ -31,6 +31,7 @@ use File::Spec::Functions qw( catfile curdir );
# Add a custom Module::Build hashref property to pass the following build
# parameters.
# charmonizer_c: Charmonizer C file, required
+# create_makefile: Whether to create a Makefile.
if ( $Module::Build::VERSION <= 0.30 ) {
__PACKAGE__->add_property( charmonizer_params => {} );
}
@@ -59,9 +60,10 @@ sub ACTION_charmony {
and die "Failed to compile $CHARMONIZER_EXE_PATH";
}
- return if $self->up_to_date( $CHARMONIZER_EXE_PATH, [
- $CHARMONY_H_PATH, $CHARMONY_PM_PATH,
- ] );
+ my $create_makefile = $self->charmonizer_params('create_makefile');
+ my @derived_files = ( $CHARMONY_H_PATH, $CHARMONY_PM_PATH );
+ push @derived_files, 'Makefile' if $create_makefile;
+ return if $self->up_to_date( $CHARMONIZER_EXE_PATH, \@derived_files );
print "\nRunning $CHARMONIZER_EXE_PATH...\n\n";
$self->add_to_cleanup($CHARMONY_H_PATH);
@@ -82,10 +84,18 @@ sub ACTION_charmony {
'--enable-c',
'--enable-perl',
);
+ if ($create_makefile) {
+ push @command,
+ '--make=' . $self->config('make'),
+ '--enable-makefile';
+ }
if ( !$self->config('usethreads') ) {
push @command, '--disable-threads';
}
- push @command, ( '--', @cc_args, $self->config('ccflags') );
+ push @command, (
+ '--', @cc_args, $self->config('ccflags'),
+ '-I' . File::Spec->catdir($self->config('archlibexp'), 'CORE'),
+ );
if ( $ENV{CHARM_VALGRIND} ) {
unshift @command, "valgrind", "--leak-check=yes";
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5a4413b2/runtime/perl/.gitignore
----------------------------------------------------------------------
diff --git a/runtime/perl/.gitignore b/runtime/perl/.gitignore
index 6221610..d9d866b 100644
--- a/runtime/perl/.gitignore
+++ b/runtime/perl/.gitignore
@@ -1,18 +1,20 @@
+
*.pod
/Build
/Build.bat
/Charmony.pm
/MYMETA.json
/MYMETA.yml
+/Makefile
/_build/
/autogen/
/blib/
+/charmonize.c
/charmonizer
/charmonizer.exe
-/charmonize.c
/charmony.h
/lib/Clownfish.c
/lib/Clownfish.xs
+/libcfish.*
/ppport.h
/typemap
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5a4413b2/runtime/perl/buildlib/Clownfish/Build.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/buildlib/Clownfish/Build.pm b/runtime/perl/buildlib/Clownfish/Build.pm
index 0b7da01..5955b10 100644
--- a/runtime/perl/buildlib/Clownfish/Build.pm
+++ b/runtime/perl/buildlib/Clownfish/Build.pm
@@ -90,6 +90,7 @@ sub new {
$self->config( optimize => $optimize );
}
+ $self->charmonizer_params( create_makefile => 1 );
$self->charmonizer_params( charmonizer_c => $CHARMONIZER_C );
return $self;