--- a/lib/OpenGuides/Build.pm	(revision 1448)
+++ b/lib/OpenGuides/Build.pm	(working copy)
@@ -7,6 +7,7 @@
 
 use Module::Build;
 use OpenGuides::Config;
+use File::Path;
 use base 'Module::Build';
 
 sub ACTION_install {
@@ -20,7 +21,13 @@
     my $config = OpenGuides::Config->new( file => "wiki.conf" );
 
     # Initialise the database if necessary.
-    my $dbname = $config->dbname;
+    # Using destdir here is a bit far-fetched, unless we expect
+    # packagers to ship pre-initialised databases. However, it is
+    # better than ignoring it. A better solution would be to allow
+    # more control over whether the database is initialised here.
+    my $dbname = ( $config->dbtype eq 'sqlite' && defined $self->destdir ) ?
+        File::Spec->catdir($self->destdir, $config->dbname) :
+        $config->dbname;
     my $dbuser = $config->dbuser;
     my $dbpass = $config->dbpass;
     my $dbhost = $config->dbhost;
@@ -58,12 +65,12 @@
     my $config = OpenGuides::Config->new( file => "wiki.conf" );
 
     # Install the scripts where we were told to.
-    my $install_directory    = $config->install_directory;
+    my $install_directory    = defined $self->destdir ? File::Spec->catdir( $self->destdir, $config->install_directory ) : $config->install_directory;
     my $script_name          = $config->script_name;
-    my $template_path        = $config->template_path;
-    my $custom_template_path = $config->custom_template_path;
+    my $template_path        = defined $self->destdir ? File::Spec->catdir( $self->destdir, $config->template_path ) : $config->template_path;
+    my $custom_template_path = defined $self->destdir ? File::Spec->catdir( $self->destdir, $config->custom_template_path ) : $config->custom_template_path;
     my $custom_lib_path      = $config->custom_lib_path;
-    my $static_path          = $config->static_path;
+    my $static_path          = defined $self->destdir ? File::Spec->catdir( $self->destdir, $config->static_path ) : $config->static_path;
     my @extra_scripts        = @{ $self->config_data( "__extra_scripts" ) };
     my @templates            = @{ $self->config_data( "__templates" ) };
     my @static_files         = @{ $self->config_data( "__static_files" ) };
@@ -155,7 +162,7 @@
     } else {
         unless (-d $custom_template_path) {
             print "Creating directory $custom_template_path.\n";
-            mkdir $custom_template_path or warn "Could not make $custom_template_path";
+            File::Path::mkpath $custom_template_path or warn "Could not make $custom_template_path";
         }
     }
 
