Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 56f1982e7 -> 0be314b9d


Add "xs_prereqs" module parameter

This parameter lists the names of other Clownfish XS modules whose
symbols are referenced from a module. The corresponding libraries
are linked against on Windows.

This obviates the need to call cf_linker_flags manually.

If we start to install parcel metadata, it should be possible to
determine the XS prerequisites automatically (see CLOWNFISH-83).


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/a80e405e
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/a80e405e
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/a80e405e

Branch: refs/heads/master
Commit: a80e405ea7878f2eafc3562ab35c3e9ba6eff0c4
Parents: 24fb4d9
Author: Nick Wellnhofer <[email protected]>
Authored: Fri Jul 8 13:57:27 2016 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Fri Jul 8 14:25:36 2016 +0200

----------------------------------------------------------------------
 compiler/perl/lib/Clownfish/CFC/Perl/Build.pm | 26 +++++++++-------------
 1 file changed, 11 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a80e405e/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 6d0f584..9c1ff84 100644
--- a/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
+++ b/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
@@ -134,7 +134,7 @@ sub cf_base_path {
 }
 
 sub cf_linker_flags {
-    my $self_or_class = shift;
+    my $self = shift;
 
     my $dlext = $Config{dlext};
     # Only needed on Windows
@@ -152,7 +152,7 @@ sub cf_linker_flags {
         my $lib_file;
         my $found;
 
-        for my $dir (@INC) {
+        for my $dir ( catdir( $self->blib, 'arch' ), @INC ) {
             $lib_file = catfile(
                 $dir, 'auto', @module_parts, "$class_name.$ext",
             );
@@ -503,13 +503,19 @@ sub _compile_custom_xs {
     # .o => .(a|bundle)
     my $lib_file = catfile( $archdir, "$class_name.$Config{dlext}" );
     if ( !$self->up_to_date( [ @objects, $AUTOGEN_DIR ], $lib_file ) ) {
+        my $linker_flags = $self->extra_linker_flags;
+        if ( $module->{xs_prereqs} ) {
+            push @$linker_flags,
+                 $self->cf_linker_flags( @{ $module->{xs_prereqs} } );
+        }
         $cbuilder->link(
             module_name        => $module_name,
             objects            => \@objects,
             lib_file           => $lib_file,
-            extra_linker_flags => $self->extra_linker_flags,
+            extra_linker_flags => $linker_flags,
         );
         # Install .lib file on Windows
+        # TODO: Install .dll.a when building with GCC on Windows?
         my $implib_file = catfile( $libdir, "$class_name.lib" );
         if ( -e $implib_file ) {
             $self->copy_if_modified(
@@ -615,16 +621,12 @@ the Perl bindings for Clownfish modules.
     use File::Spec::Functions qw( catdir );
 
     my @cf_base_path    = Clownfish::CFC::Perl::Build->cf_base_path;
-    my @cf_linker_flags = Clownfish::CFC::Perl::Build->cf_linker_flags(
-        'Other::Module',
-    );
 
     my $builder = Clownfish::CFC::Perl::Build->new(
         module_name        => 'My::Module',
         dist_abstract      => 'Do something with this and that',
         dist_author        => 'The Author <[email protected]>',
         dist_version       => '0.1.0',
-        extra_linker_flags => [ @cf_linker_flags ],
         clownfish_params => {
             source  => [ catdir( @cf_base_path, 'core' ) ],
             modules => [
@@ -632,10 +634,12 @@ the Perl bindings for Clownfish modules.
                     name          => 'My::Module',
                     c_source_dirs => 'xs',
                     parcels       => [ 'MyModule' ],
+                    xs_prereqs    => [ 'Clownfish' ],
                 },
                 {
                     name          => 'My::Module::Test',
                     parcels       => [ 'TestMyModule' ],
+                    xs_prereqs    => [ 'Clownfish', 'My::Module' ],
                 },
             ],
         },
@@ -729,14 +733,6 @@ Clownfish .c files.
 Returns the base path components of the source tree where C<core> was found.
 Currently either C<()> or C<('..')>.
 
-=head2 cf_linker_flags( I<[module_names]> )
-
-    my @flags = Clownfish::CFC::Perl::Build->cf_linker_flags(@module_names);
-
-Returns the linker flags needed to link against all Clownfish modules in
-C<@module_names>. Should be added to C<extra_linker_flags> for all module
-dependencies. Only needed on Windows.
-
 =head1 METHODS
 
 =head2 cf_copy_include_file( I<[path components]> )

Reply via email to