#!/usr/bin/perl
# -*- perl -*-

# Automated build script for rapid development
# To use first do a manual build in a directory other than
# foomatic-db-engine-test-build
# then run this script. 

use Foomatic::Defaults;
use File::Basename;
use strict;
use warnings;
use Getopt::Long;

my $now = time;
my $parent = '../';
my $source = 'foomatic-db-engine/';
my $dest = "foomatic-db-engine-test-build/";
my $show_help = 0;

GetOptions('help' => \$show_help,
           'source' => \$source,
           'destination' => \$dest);

if ($show_help) {
	print STDERR "
Usage: foomatic-test-build.pl [ -s source_directory -d build_destination ]

	source_directory: The directory with the source code we want
	  to build. Defaults to foomatic-db-engine

	build_destination: The destination directory for the test
	  build. Relative to the parent of foomatic-db-engine 
	  source folder.
	
Example:
	foomatic-test-build.pl -s 'foomatic-db-engine/' -d 'foomatic-db-engine-test-build/'
";
exit(1);
}

# Let's make our soup #
print(`(cd $parent
mkdir $dest
cp -R $source/* $dest 
cd $dest
./make_configure
./configure
make inplace) 2>&1`);


# Print buildtime #
$now = time - $now;
printf("\n-------------\nBuild time: %02d:%02d:%02d\n\n", 
                     int($now / 3600), int(($now % 3600) / 60), 
                                                 int($now % 60));
