I have a top level defines.mk file which lists certain directories and C libraries to include depending on the project like so.
KERNEL_LIB = -lkdev
DRIVER_LIB = -ldriver -lutil -linit $(KERNEL_LIB)
DRIVER_INCLUDE = -I../../include
I use XS to allow perl scripts to access these libraries and MakeMaker to generate the Makefile which will link these libraries in. I want to make it such that when the Makefile is generated, it pulls in these defines.
Given a WriteMakefile like this
WriteMakefile(
NAME => 'generic_scripts',
VERSION_FROM => 'generic_scripts.pm',
LIBS => ['-L/usr/local/app/lib -lkdev -lpthread -lrt -ldriver -lutil -linit'],
DEFINE => '',
INC => '-I../../include',
clean => {FILES=>"*.o"},
);
I want to achieve this
WriteMakefile(
NAME => 'generic_scripts',
VERSION_FROM => 'generic_scripts.pm',
LIBS => ['-L/usr/local/dx/lib $(KERNEL_LIB) -lpthread -lrt $(DRIVER_LIB)'],
DEFINE => '',
INC => '$(DRIVER_INCLUDE)',
clean => {FILES=>"*.o"},
);
From @mobrule I now have this Makefile.PL
use 5.008008;
use ExtUtils::MakeMaker;
use ExtUtils::MM_Unix;
use ExtUtils::MM;
sub MY::post_initialize {
open my $defs, '<', 'defines.mk';
my $extra_defines = join '', <$defs>;
close $defs;
return $extra_defines;
}
sub MM::init_others {
my $self = shift;
$self->ExtUtils::MM_Unix::init_others(@_);
$self->{EXTRALIBS} = '-L/usr/local/app/lib $(DRIVER_LIB) -lpthread -lrt';
$self->{BSLOADLIBS} = $self->{LDLOADLIBS} = $self->{EXTRALIBS};
}
WriteMakefile(
NAME => 'generic_scripts',
VERSION_FROM => 'generic_scripts.pm',
DEFINE => '',
INC => '$(DRIVER_INCLUDE)',
clean => {FILES=>"*.o"},
);
Which looks like it does what I want. Thanks!