| 1 | package App::duino::Command::build; | ||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||
| 3 | 1 | $App::duino::Command::build::VERSION = '0.10'; | |||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use App::duino -command; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Text::Template; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use File::Find::Rule; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use IPC::Cmd qw(can_run run); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use File::Path qw(make_path); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | App::duino::Command::build - Build an Arduino sketch | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | version 0.10 | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | # this will find all *.ino, *.c and *.cpp files | ||||||||||||||||||||||||||||||||
| 28 | $ duino build --board uno | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | # explicitly provide the sketch file | ||||||||||||||||||||||||||||||||
| 31 | $ duino build --board uno some_sketch.ino | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | This command can be used to build a sketch for a specific Arduino board. The | ||||||||||||||||||||||||||||||||
| 36 | sketch file is automatically detected in the current working directory. If this | ||||||||||||||||||||||||||||||||
| 37 | doesn't work, the path of the sketch file can be explicitly provided on the | ||||||||||||||||||||||||||||||||
| 38 | command-line. | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub abstract { 'build an Arduino sketch' } | ||||||||||||||||||||||||||||||
|
Subroutine
abstract: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub usage_desc { '%c build %o [sketch.ino]' } | ||||||||||||||||||||||||||||||
|
Subroutine
usage_desc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||||||
|
Subroutine
opt_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 47 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | return ( | ||||||||||||||||||||||||||||||||
| 50 | 0 | [ 'board|b=s', 'specify the board model', | |||||||||||||||||||||||||||||||
| 51 | { default => $self -> default_config('board') } ], | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | [ 'libs|l=s', 'specify the Arduino libraries to build', | ||||||||||||||||||||||||||||||||
| 54 | { default => $self -> default_config('libs') } ], | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | [ 'sketchbook|s=s', 'specify the user sketchbook directory', | ||||||||||||||||||||||||||||||||
| 57 | { default => $self -> default_config('sketchbook') } ], | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | [ 'root|d=s', 'specify the Arduino installation directory', | ||||||||||||||||||||||||||||||||
| 60 | { default => $self -> default_config('root') } ], | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | [ 'hardware|r=s', 'specify the hardware type to build for', | ||||||||||||||||||||||||||||||||
| 63 | { default => $self -> default_config('hardware') } ], | ||||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 68 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | my $make = can_run('make') or die "Can't find command 'make'."; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 0 | my $board_name = $opt -> board; | |||||||||||||||||||||||||||||||
| 73 | 0 | my $makefile_name = ".build/$board_name/Makefile"; | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 0 | make_path(dirname $makefile_name); | |||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | open my $makefile, '>', $makefile_name | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | or die "Can't create Makefile.\n"; | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 0 | my $template = Text::Template -> new( | |||||||||||||||||||||||||||||||
| 81 | TYPE => 'FILEHANDLE', SOURCE => \*DATA | ||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 0 | my ($target, @c_srcs, @cpp_srcs, @ino_srcs); | |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | @c_srcs = File::Find::Rule -> file -> name('*.c') -> in('./'); | |||||||||||||||||||||||||||||||
| 87 | 0 | @cpp_srcs = File::Find::Rule -> file -> name('*.cpp') -> in('./'); | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($args -> [0] and -e $args -> [0]) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$args->[0] and -e $args->[0]
MC/DC0%0/2
$args->[0] and -e $args->[0]
$args->[0]
-e $args->[0]
Truth table0%0/3
A and B
A= $args->[0]B= -e $args->[0]
| |||||||||||||||||||||||||||||||||
| 90 | 0 | $target = '$(notdir $(basename $(LOCAL_INO_SRCS)))'; | |||||||||||||||||||||||||||||||
| 91 | 0 | push @ino_srcs, $args -> [0]; | |||||||||||||||||||||||||||||||
| 92 | } elsif ($args -> [0]) { | ||||||||||||||||||||||||||||||||
| 93 | 0 | die "Can't find file '" . $args -> [0] . "'.\n"; | |||||||||||||||||||||||||||||||
| 94 | } else { | ||||||||||||||||||||||||||||||||
| 95 | 0 | $target = '$(notdir $(CURDIR))'; | |||||||||||||||||||||||||||||||
| 96 | 0 | @ino_srcs = File::Find::Rule -> file | |||||||||||||||||||||||||||||||
| 97 | -> name('*.ino') -> in('./'); | ||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | my $core = $self -> board_config($opt, 'build.core'); | |||||||||||||||||||||||||||||||
| 101 | 0 | my $hardware = $opt -> hardware; | |||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 0 | my $core_path = "$hardware/cores/$core"; | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($core =~ /:/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | 0 | my ($core1, $core2) = split /:/, $core; | |||||||||||||||||||||||||||||||
| 107 | 0 | $core_path = "$core1/cores/$core2"; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | my $makefile_opts = { | |||||||||||||||||||||||||||||||
| 111 | board => $board_name, | ||||||||||||||||||||||||||||||||
| 112 | variant => $self -> board_config($opt, 'build.variant'), | ||||||||||||||||||||||||||||||||
| 113 | mcu => $self -> board_config($opt, 'build.mcu'), | ||||||||||||||||||||||||||||||||
| 114 | f_cpu => $self -> board_config($opt, 'build.f_cpu'), | ||||||||||||||||||||||||||||||||
| 115 | vid => $self -> board_config($opt, 'build.vid'), | ||||||||||||||||||||||||||||||||
| 116 | pid => $self -> board_config($opt, 'build.pid'), | ||||||||||||||||||||||||||||||||
| 117 | core_pth=> $core_path, | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | target => $target, | ||||||||||||||||||||||||||||||||
| 120 | local_c_srcs => join(' ', @c_srcs), | ||||||||||||||||||||||||||||||||
| 121 | local_cpp_srcs => join(' ', @cpp_srcs), | ||||||||||||||||||||||||||||||||
| 122 | local_ino_srcs => join(' ', @ino_srcs), | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | libs => $opt -> libs, | ||||||||||||||||||||||||||||||||
| 125 | root => $opt -> root, | ||||||||||||||||||||||||||||||||
| 126 | sketchbook => $opt -> sketchbook, | ||||||||||||||||||||||||||||||||
| 127 | hardware => $hardware, | ||||||||||||||||||||||||||||||||
| 128 | }; | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 0 | $template -> fill_in( | |||||||||||||||||||||||||||||||
| 131 | OUTPUT => $makefile, HASH => $makefile_opts | ||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | 0 | system 'make', '--silent', '-f', $makefile_name; | |||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | die "Failed to build.\n" unless $? == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | =head1 OPTIONS | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | =over 4 | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | =item B<--board>, B<-b> | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | The Arduino board model. The environment variable C<ARDUINO_BOARD> will be used | ||||||||||||||||||||||||||||||||
| 145 | if present and if the command-line option is not set. If neither of them is set | ||||||||||||||||||||||||||||||||
| 146 | the default value (C<uno>) will be used. | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | =item B<--libs>, B<-l> | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | List of space-separated, non-core Arduino libraries to build. The environment | ||||||||||||||||||||||||||||||||
| 151 | variable C<ARDUINO_LIBS> will be used if present and if the command-line option | ||||||||||||||||||||||||||||||||
| 152 | is not set. If neither of them is set no libraries are built. | ||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | Example: | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | $ duino build --libs "Wire Wire/utility SPI" | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | =item B<--sketchbook>, B<-s> | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | The path to the user's sketchbook directory. The environment variable | ||||||||||||||||||||||||||||||||
| 161 | C<ARDUINO_SKETCHBOOK> will be used if present and if the command-line option is | ||||||||||||||||||||||||||||||||
| 162 | not set. If neither of them is set the default value (C<$HOME/sketchbook>) will | ||||||||||||||||||||||||||||||||
| 163 | be used. | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | =item B<--root>, B<-d> | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | The path to the Arduino installation directory. The environment variable | ||||||||||||||||||||||||||||||||
| 168 | C<ARDUINO_DIR> will be used if present and if the command-line option is not | ||||||||||||||||||||||||||||||||
| 169 | set. If neither of them is set the default value (C</usr/share/arduino>) will | ||||||||||||||||||||||||||||||||
| 170 | be used. | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | =item B<--hardware>, B<-r> | ||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | The "type" of hardware to target. The environment variable C<ARDUINO_HARDWARE> | ||||||||||||||||||||||||||||||||
| 175 | will be used if present and if the command-line option is not set. If neither | ||||||||||||||||||||||||||||||||
| 176 | of them is set the default value (C<arduino>) will be used. | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | This option is only useful when using MCUs not officially supported by the | ||||||||||||||||||||||||||||||||
| 179 | Arduino platform (e.g. L<ATTiny|https://code.google.com/p/arduino-tiny/>). | ||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | =back | ||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | Alessandro Ghedini <alexbio@cpan.org> | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | Copyright 2013 Alessandro Ghedini. | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||
| 192 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||||||
| 193 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 1 | 1; # End of App::duino::Command::build | |||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | __DATA__ | ||||||||||||||||||||||||||||||||