Linux – How to install data in a custom directory using ExtUtils::MakeMaker

How to install data in a custom directory using ExtUtils::MakeMaker… here is a solution to the problem.

How to install data in a custom directory using ExtUtils::MakeMaker

I need to install my main script (as an executable) in /usr/bin (depending on INSTALL_BASE). The section is complete.

The next one is to install to the directory /usr/share/project_name/data options.txt, this one is hard for me, see my code :

list file:

data/options.txt
script/joel-perl
Makefile.PL

Generate a file .PL

use ExtUtils::MakeMaker;

WriteMakefile (
    NAME => 'joelperl',
    VERSION_FROM => 'script/joel-perl',
     PREREQ_PM => {
        'Switch' => 0
     },
    EXE_FILES => ['script/joel-perl'],
    PM => {
        'data/options.txt' => '$(INSTALL_BASE)/share/project_name/data'
    }
);

Runtime:

perl Makefile.PL INSTALL_BASE="/usr"
make

I’m getting “Error: Unable to create ‘/usr/share/project_name'”, so my question is:

How do I add/copy files to a specific location, as in my case?

Solution

See also File::ShareDir::InstallModule:

use ExtUtils::MakeMaker;
use File::ShareDir::Install;

install_share 'data';

WriteMakefile(...);

package MY;
use File::ShareDir::Install qw(postamble);

Related Problems and Solutions