App-duino
view release on metacpan or search on metacpan
lib/App/duino/Command/build.pm view on Meta::CPAN
my $board_name = $opt -> board;
my $makefile_name = ".build/$board_name/Makefile";
make_path(dirname $makefile_name);
open my $makefile, '>', $makefile_name
or die "Can't create Makefile.\n";
my $template = Text::Template -> new(
TYPE => 'FILEHANDLE', SOURCE => \*DATA
);
my ($target, @c_srcs, @cpp_srcs, @ino_srcs);
@c_srcs = File::Find::Rule -> file -> name('*.c') -> in('./');
@cpp_srcs = File::Find::Rule -> file -> name('*.cpp') -> in('./');
if ($args -> [0] and -e $args -> [0]) {
$target = '$(notdir $(basename $(LOCAL_INO_SRCS)))';
push @ino_srcs, $args -> [0];
} elsif ($args -> [0]) {
die "Can't find file '" . $args -> [0] . "'.\n";
} else {
$target = '$(notdir $(CURDIR))';
@ino_srcs = File::Find::Rule -> file
-> name('*.ino') -> in('./');
}
my $core = $self -> board_config($opt, 'build.core');
my $hardware = $opt -> hardware;
my $core_path = "$hardware/cores/$core";
if ($core =~ /:/) {
my ($core1, $core2) = split /:/, $core;
$core_path = "$core1/cores/$core2";
}
my $makefile_opts = {
board => $board_name,
variant => $self -> board_config($opt, 'build.variant'),
mcu => $self -> board_config($opt, 'build.mcu'),
f_cpu => $self -> board_config($opt, 'build.f_cpu'),
vid => $self -> board_config($opt, 'build.vid'),
pid => $self -> board_config($opt, 'build.pid'),
core_pth=> $core_path,
target => $target,
local_c_srcs => join(' ', @c_srcs),
local_cpp_srcs => join(' ', @cpp_srcs),
local_ino_srcs => join(' ', @ino_srcs),
libs => $opt -> libs,
root => $opt -> root,
sketchbook => $opt -> sketchbook,
hardware => $hardware,
};
$template -> fill_in(
OUTPUT => $makefile, HASH => $makefile_opts
);
system 'make', '--silent', '-f', $makefile_name;
die "Failed to build.\n" unless $? == 0;
}
=head1 OPTIONS
=over 4
=item B<--board>, B<-b>
The Arduino board model. The environment variable C<ARDUINO_BOARD> will be used
if present and if the command-line option is not set. If neither of them is set
the default value (C<uno>) will be used.
=item B<--libs>, B<-l>
List of space-separated, non-core Arduino libraries to build. The environment
variable C<ARDUINO_LIBS> will be used if present and if the command-line option
is not set. If neither of them is set no libraries are built.
Example:
$ duino build --libs "Wire Wire/utility SPI"
=item B<--sketchbook>, B<-s>
The path to the user's sketchbook directory. The environment variable
C<ARDUINO_SKETCHBOOK> will be used if present and if the command-line option is
not set. If neither of them is set the default value (C<$HOME/sketchbook>) will
be used.
=item B<--root>, B<-d>
The path to the Arduino installation directory. The environment variable
C<ARDUINO_DIR> will be used if present and if the command-line option is not
set. If neither of them is set the default value (C</usr/share/arduino>) will
be used.
=item B<--hardware>, B<-r>
The "type" of hardware to target. The environment variable C<ARDUINO_HARDWARE>
will be used if present and if the command-line option is not set. If neither
of them is set the default value (C<arduino>) will be used.
This option is only useful when using MCUs not officially supported by the
Arduino platform (e.g. L<ATTiny|https://code.google.com/p/arduino-tiny/>).
=back
=head1 AUTHOR
Alessandro Ghedini <alexbio@cpan.org>
=head1 LICENSE AND COPYRIGHT
Copyright 2013 Alessandro Ghedini.
This program is free software; you can redistribute it and/or modify it
( run in 1.410 second using v1.01-cache-2.11-cpan-5b529ec07f3 )