#!/usr/bin/perl -w

# Pragma ------------------------------

use 5.006;
use strict;

# Utility -----------------------------

use File::Basename             qw( basename );
use File::Spec::Functions      qw( catfile );
use Getopt::Long          2.19 qw( GetOptions );

# Constants ------------------------------------------------------------------

use constant MOD_REQS =>
  [
  ];

use constant EXEC_REQS =>
  [
  ];

use constant RAW_COMPS    => map(join('.', basename($_, '.m'), 'pm'),
                                 glob(catfile qw(components *.m)));
use constant NAME         => 'Class-MethodMaker';
use constant VERSION_FROM => catfile(qw( lib Class MethodMaker Engine.pm ));
use constant AUTHOR       => 'Martyn J. Pearce';
use constant ABSTRACT     => 'Create generic methods for OO Perl';

use constant OPTEXT       => catfile qw( lib Class MethodMaker OptExt.pm );

use constant COMPONENTS   =>
  +{map {catfile('components', join('.',basename($_,'.pm'),'m')) =>
         catfile(qw(Class MethodMaker), $_)} RAW_COMPS};
use constant DEPENDS      => [
                              map(+{target=>catfile (lib => COMPONENTS->{$_}),
                                    reqs  => ['cmmg.pl', $_, OPTEXT],
                                    rules => [join ' ',
                                              '$(PERL)', 'cmmg.pl', $_,
                                              '>', '$@'],},
                                  keys %{COMPONENTS()}),
                              +{ target => 'html/%.html',
                                 reqs   => ['lib/%.pm'],
                                 rules  => [
                                            join(' ',
                                                 'mkdir', '-p', '`dirname $@`',
                                                 '&&',
                                                 'pod2html',
                                                 '--htmlroot=`pwd`/html',
                                                 '$<', '>', '$@')],
                               },
                              +{ target => 'html/.done',
                                 reqs   => ['$(patsubst lib/%.pm,html/%.html,$(TO_INST_PM))' ],
                                 rules  => ['touch $@'],
                               },
                              +{ target => 'html',
                                 reqs   => ['html/.done'],
                                 rules  => ['true'],
                               },
                             ];
use constant DERIVED_PM   => [values %{COMPONENTS()}];
use constant EXTRA_CLEAN  => [map(catfile(qw(lib Class MethodMaker), $_),
                                  RAW_COMPS)];

# Globals -----------------------------

my $prefix;
my $DEBUG;

sub          PREFIX       {   $prefix }

# ----------------------------------------------------------------------------

use FindBin 1.42 qw( $Bin );
use lib $Bin, '.';

GetOptions ('debug'    => \$DEBUG,
            'prefix=s' => \$prefix,)
  or die "Options parsing failed";

warn "Building with perl: $^X\n";

require 'make-pm';
