#!/usr/bin/perl

use strict;
use warnings;

require Make::Build::Convert;

my $params = parse_switches() if @ARGV;
convert($params);

sub parse_switches {
    use Getopt::Long qw(:config no_ignore_case);
    my %opts;
    GetOptions(\%opts,'h','l=i','n','rc','v','vv','V') or usage();
    if ($opts{v} && $opts{vv}) {
        print "Can't use both -v and -vv switches\n";
	usage();
    }
    usage()   if $opts{h};
    version() if $opts{V};
    return { Path             => $ARGV[0],
             Len_Indent       => $opts{l},
	     Use_native_order => $opts{n},
	     Create_RC        => $opts{rc},
	     Verbose          => $opts{v} ? 1 : $opts{vv} ? 2 : undef };
}

sub usage {
    print <<USAGE;
Usage: $0 [switches] [path-to-distribution]
  -h           help screen
  -l length    indentation length
  -n           native ordering of build args
  -rc          create RC-file in homedir
  -v(v)        verbosity level
  -V           version
USAGE
    exit;
}

sub version {
    my ($name) = $0 =~ /.*\/(.*)\..*/o;
    $name = 'make2build' unless $name;
    print "  $name $Make::Build::Convert::VERSION\n";
    exit;
}

sub convert {
    my $make = Make::Build::Convert->new(%{$_[0]});
    $make->convert;
}

=head1 NAME

make2build - frontend to Make::Build::Convert

=head1 SYNOPSIS 

 make2build         # In the root directory of an 
                    # ExtUtils::MakeMaker based distribution
		    
 Usage: /usr/local/bin/make2build [switches] [path-to-distribution]
   -h           help screen
   -l length    indentation length
   -n           native ordering of build args
   -rc          create RC-file in homedir
   -v(v)        verbosity level
   -V           version

=head1 AUTHOR

Steven Schubiger C<< <schubiger@cpan.org> >>	    

=cut
