On Fri, Apr 01, 2011 at 09:15:53PM +0200, Leon Timmermans wrote:
> On Fri, Apr 1, 2011 at 7:15 PM, Simon Ruderich wrote:
>> I'm trying to install custom files to a specific location which
>> should be relative to the given prefix/install_base/.. In this
>> case into share/locale. So e.g. if --prefix=/usr/local then it
>> should install into /usr/local/share/locale/.
>
> How do you call your Build/Build.PL exactly? Do you call your example
> with --install_base?

Hi Leon,

Thanks for your quick response.

Yes, I tried --install_base and --prefix, both have the same
problem. It looks like --destdir also doesn't work with ./Build,
just with perl Build.PL. I'm not sure if this is expected or a
bug.

>> I'm using Module::Build 0.340201 on Debian Squeeze.

> You might want to upgrade to a more recent version of Module::Build.
> «apt-get install libmodule-build-perl» should upgrade it to 0.3607.
> CPAN will upgrade it to 0.38. It might solve your problems.

Retried with 0.38, same problem.

>>    $build->add_build_element('locale');
>>    $build->install_base_relpaths(locale => 'locale');
>
> The general solution looks something like this:
>
>   use File::Spec 'catdir';
>   …
>   $build->add_build_element('locale');
>   $build->install_base_relpaths(locale => catdir('share', 'locale'));
>   $build->prefix_relpaths($_, locale => catdir('share', 'locale')) for
> qw/core vendor site/;
>   $build->install_sets($_, 'locale',
> catdir($build->original_prefix($_)), 'share', 'locale')) for qw/core
> vendor site/;

Hm, looks really complicated for such a simple task :-/

But it works fine, thanks for your help.

> Yeah, you need all of that for all options to work as you expect them
> to. Also, you then have to figure out a way for your program to know
> where to find the files, but that's a different discussion.

Yeah, at the moment I rewrite the files to point to the right
place. My current solution feels really like a hack:

    # Fix some paths so custom installation paths work.
    sub ACTION_build {
        my $self = shift;

        $self->SUPER::ACTION_build;

        $self->sed('blib/script/pabook',
                   'LIBDIR', $self->install_destination('lib'));
        $self->sed('blib/lib/Pabook/Util.pm',
                   'LOCALEDIR', $self->install_destination('locale'));
    }
    sub sed {
        my $self = shift;
        my ($file, $search, $replacement) = @_;

        $replacement =~ s/\//\\\//g;
        $self->do_system('perl', '-pi', '-e',
                         "s/$search/$replacement/g", $file);
    }

Is there a simple way for text replacements like this in
Module::Build (or maybe a better way to do it)? One known problem
with my solution is that a --prefix/--install_base change doesn't
case an update to the file, so it points to the wrong path.

> A much simpler solution in your case would be to use the sharedir
> functionality of Module::Build (available since 0.36). It doesn't
> sound like you need something sharedir can't provide.

I had a look at it, but I want a path like /usr/share/locale, and
it gives me something like /usr/share/perl/5.10.1/auto/<package-name>.

But the solution you gave me above works fine.

>> It seems to work, but doesn't look like a good solution. Is there
>> a variable which returns the absolute installation prefix? I
>> couldn't find any in the documentation.
>
> No, that's not how it works on the inside: an absolute installation
> prefix is only well-defined in a limited set of circumstances (when
> using --prefix and --install_base).

I see the problem now - I'm only used to --prefix so I didn't
think of that.

> Leon

Regards,
Simon
-- 
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9

Attachment: pgpLpyFB8ceU4.pgp
Description: PGP signature

Reply via email to