The problem I am addressing is that of writing and building a Perl module in such a way that it builds and installs using both CPAN and Debian packaging.

The wrinkles occur because CPAN and Debian handle configuration files differently. I assume that the configuration files are goiing to be installed in /etc/$ProjectName.

Add the following at the end of your Makefile.PL

package MY;
 
sub postamble {
     return << "EOF";
INST_ETC        = blib/etc
DESTINSTALLETC = \$(DESTDIR)/etc
# This target is used by both CPAN and Debian builds
config::
\t\$(MKPATH) \$(INST_ETC)
 
# This target is used by both CPAN and Debian builds
pure_all::
\t\$(CP) -r etc/* \$(INST_ETC)
 
# This target is used only by CPAN builds; Debian uses debian/conffiles
pure_install:: all
\t\$(MKPATH) \$(DESTINSTALLETC)/\$(NAME)
\t\$(CP) -r \$(INST_ETC)/* \$(DESTINSTALLETC)/\$(NAME)
 
EOF
}

This will deal with installing things correctly when you do a 'make install'. In this fragment the DESTINSTALLETC macro defines where you ultimately want things installed.

Unfortunately, the Debian system does not use 'make install', not even with a fake root or over-rides to DESTDIR. To deal with Debian packaging you need a debian/conffiles in the project directory. This should list the source files, normally living in the etc directory, e.g

etc/log4perl.conf
etc/sessiontimewatcher.conf
etc/sql/schema.sql
etc/sql/test.sql

Now, the following script, run from one level above the project directory will build a Debian package for you

#!/bin/bash -xe

# Script to build a Perl module for Debian.
# Before running this script you must have created debian/control
# and debian/conffiles in the module's directory. debian/control
# will get created automatically the first time that you run this
# script, you can then edit it to suit. debian/conffiles you have
# to create yourself.

export DEB_BUILD_OPTIONS=nocheck
cd $1
make distclean
perl Makefile.PL
cd ..
dh-make-perl --notest --noinstall --version 7 --verbose $1
cd $1
debuild -d -us -uc


Last updated: 1 Dec 2011