#!/usr/bin/perl
use strict; use warnings; # Copyright 2008-2010, 2012-2013, Michael Allan.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.

=pod

=head1 NAME

build - build Votorola

=head1 SYNOPSIS

votorola/b/build clean

votorola/b/build [--verbose] I<argument>*

votorola/b/build --help | --man

=head1 ARGUMENTS

=over 8

=item B<clean>

Deletes all build files.

=item B<doc>

Builds the documentation files. Almost all of the source is output, with only lightly
filtering to exclude a few unwanted files.

=item B<javadoc>

Builds the Java API docs.

=item B<release>

Builds the whole of Votorola for release. This is the default.  It is equivalent to 'build
doc x xgwt javadoc'.

=item B<x>

Builds the executables.

=item B<xgwt>

Builds the executables for Google Web Tookit clients.

=back

=cut

    sub _shift_options();
      #
      # Shifts command line options into %votorola::b::Build::option.
      #


{
    _shift_options;
    scalar @ARGV == 0 && push( @ARGV, 'release' );

    for my $target( @ARGV )
    {
        my $sub_name = 'votorola::b::Build::build__target_' . $target;
        {
            no strict 'refs';
            use votorola::b::Build();
            &$sub_name();
        }
    }
}


=pod

=head1 OPTIONS

=cut

sub _shift_options()
{
    use Getopt::Long qw( GetOptions );
    use Pod::Usage qw( pod2usage );
    use votorola::b::Build qw( %option );
    use votorola::b::Console qw( $verbosity );

    my @specification;
    push @specification, 'help|?';

=pod

=over 8

=item --B<help>

Outputs a brief help message and exits.

=cut

    push @specification, 'man';

=pod

=item --B<man>

Outputs the full manual page and exits.

=cut

    push @specification, 'module:s';

=pod

=item --B<module>

The name of a GWT module to build for the 'xgwt' target.  An example is
votorola.s.gwt.stage.StageInDev.  The default includes all *In modules, but not *InDev.

=cut

    push @specification, 'optimizeCSS';

=pod

=item --B<optimizeCSS>

Optimizes CSS files for a production deployment.  Currently the only optimization is to
inline the CSS imports of votorola/a/web/context/stage/module.css.

=cut

    push @specification, 'verbose';

=pod

=item --B<verbose>

Increases the level of console output.

=cut

    Getopt::Long::GetOptions( \%option, @specification ) or pod2usage( -verbose => 0 ); # and exits

    defined $option{'help'} and pod2usage( -verbose => 1 ); # and exits
    defined $option{'man'} and pod2usage( -verbose => 2 ); # and exits

    defined $option{'verbose'} and $verbosity = 1;
}

=pod

=back

=cut