use 5.008008; use strict; use warnings; use ExtUtils::MakeMaker; # Now care for our 'conf' files and others our $additional = { # In toplevel directory 'conf', take these 'files', install into 'target' # and eventually set permission for them. conf => { files => [qw( conf/foo.ini conf/bar.conf conf/template.txt )], target => '$(INSTALLSITELIB)/../conf', # Relative to site lib perms => 644, }, }; # Then the WriteMakefile call WriteMakefile( NAME => 'Foo::Bar', AUTHOR => 'Me ', ABSTRACT_FROM => 'lib/Foo/Bar.pm', VERSION_FROM => 'bin/footsie', # finds $VERSION PREREQ_PM => { 'Carp' => 0, 'Cwd' => 0, 'Data::Dumper' => 0, ... }; package MY; #------------------------- # I use the $additional hashref to write the values. # By overriding post_constants I create my own variables into the makefile. # These are (e.g. if we use files of toplevel directory 'key'): # INSTALL_KEY_DIR = target_stanza_of_$additional_for_key # KEY_FILES = files_stanza_of_$additional_for_key sub MY::post_constants { my $return_string; foreach my $add_dir ( keys %$additional ){ my @files = @{ $additional->{$add_dir}->{'files'} }; my $target = $additional->{$add_dir}->{'target'}; $return_string .= 'INSTALL_' . uc($add_dir) . '_DIR = ' . $target . "\n" . uc($add_dir) . "_FILES = @files\n"; }; return $return_string; }; #------------------------- # The postamble stores for each toplevel directory 'key' mentioned as key # in variable $additional the following entry: # install :: install.keyfiles # # install.keyfiles :: $(KEY_FILES) # $(MKPATH) $(INSTALL_KEY_DIR) # $(CP) $(KEY_FILES) $(INSTALL_KEY_DIR) # $(CHMOD) 644 $(INSTALL_KEY_DIR)/* sub MY::postamble { my $self = shift; my $return_string; foreach my $add_dir ( keys %$additional ){ my $identifyer = 'install.' . lc $add_dir . 'files'; # Like install.conffiles my $target_dir = 'INSTALL_' . uc($add_dir) . '_DIR'; # Like INSTALL_CONF_DIR my $files = uc($add_dir) . "_FILES"; # Like CONF_FILES $return_string .= "install :: $identifyer\n\n" . $identifyer . ' :: $(' . $files . ')' . "\n" . "\t\$(MKPATH) \$($target_dir)\n" . "\t\$(CP) \$($files) \$($target_dir)\n"; # If we find a permission to set => do it. if ( exists $additional->{$add_dir}->{'perms'} ){ my $perm = $additional->{$add_dir}->{'perms'}; $return_string .= "\t\$(CHMOD) $perm \$($target_dir)/*\n"; }; }; return $return_string; }; #### # --- MakeMaker post_constants section: INSTALL_CONF_DIR = $(INSTALLSITELIB)/../conf CONF_FILES = conf/foo.ini conf/bar.conf conf/template.txt # --- MakeMaker postamble section: install :: install.conffiles install.conffiles :: $(CONF_FILES) $(MKPATH) $(INSTALL_CONF_DIR) $(CP) $(CONF_FILES) $(INSTALL_CONF_DIR) $(CHMOD) 644 $(INSTALL_CONF_DIR)/*