On Sat, Feb 13, 2010 at 09:16:44PM +0000, Alberto Simões wrote: > My main problem is that I lack knowledge on building the xs code myself.
Take a look at the ACTION_compile_custom_xs method. It's basically a manual override for compiling and linking a multi-module C library into a single XS shared object. Working within the constraints imposed by Module::Build's stock options is a bit tough. For example, when we were using c_source, I had to copy a bunch of files around because M::B wanted all C files under a single tree. Once we got our own CBuilder object, that wasn't necessary any more: # Compile C source files. my $c_files = $self->rscan_dir( $CORE_SOURCE_DIR, qr/\.c$/ ); push @$c_files, @{ $self->rscan_dir( $XS_SOURCE_DIR, qr/\.c$/ ) }; push @$c_files, @{ $self->rscan_dir( $CHARMONIZER_SRC_DIR, qr/\.c$/ ) }; push @$c_files, @{ $self->rscan_dir( $AUTOGEN_DIR, qr/\.c$/ ) }; for my $c_file (@$c_files) { my $o_file = $c_file; $o_file =~ s/\.c/$Config{_o}/; push @objects, $o_file; next if $self->up_to_date( $c_file, $o_file ); $self->add_to_cleanup($o_file); $cbuilder->compile( source => $c_file, extra_compiler_flags => $self->extra_ccflags, include_dirs => \...@include_dirs, object_file => $o_file, ); } A couple fragile hacks were necessary. Maybe we can work out some patches to M::B so those won't be needed any more. # .c => .o my $version = $self->dist_version; my $perl_binding_o_file = catfile( 'lib', "KinoSearch$Config{_o}" ); unshift @objects, $perl_binding_o_file; $self->add_to_cleanup($perl_binding_o_file); if ( !$self->up_to_date( $perl_binding_c_file, $perl_binding_o_file ) ) { $cbuilder->compile( source => $perl_binding_c_file, extra_compiler_flags => $self->extra_ccflags, include_dirs => \...@include_dirs, object_file => $perl_binding_o_file, # 'defines' is an undocumented parameter to compile(), so we # should officially roll our own variant and generate compiler # flags. However, that involves writing a bunch of # platform-dependent code, so we'll just take the chance that this # will break. defines => { VERSION => qq|"$version"|, XS_VERSION => qq|"$version"|, }, ); } > With luck I can take same of your code and learn... I guarantee you're not going to need to do all the crazy stuff we're doing in the other actions (we generate the XS file on the fly), but you should find it useful to look at how actions allow us to run things in a particular order. Marvin Humphrey