diff options
Diffstat (limited to 'arduino-mk')
| -rw-r--r-- | arduino-mk/Arduino.mk | 171 | ||||
| -rwxr-xr-x | arduino-mk/ard-parse-boards | 261 |
2 files changed, 134 insertions, 298 deletions
diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 26fd3bb..5261afa 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -72,7 +72,62 @@ # defined (ex Peplin) # - Added a monitor target which talks to the # Arduino serial port (Peplin's suggestion) -# +# - Rejigged PATH calculations for general +# tidiness (ex Peplin) +# - Moved the reset target to Perl for +# clarity and better error handling (ex +# Daniele Vergini) +# +######################################################################## +# +# PATHS YOU NEED TO SET UP +# +# I've reworked the way paths to executables are constructed in this +# version (0.9) of the Makefile. +# +# We need to worry about three different sorts of file: +# +# 1. Things which are included in this distribution e.g. ard-parse-boards +# => ARDMK_DIR +# +# 2. Things which are always in the Arduino distribution e.g. +# boards.txt, libraries, &c. +# => ARDUINO_DIR +# +# 3. Things which might be bundled with the Arduino distribution, but +# might come from the system. Most of the toolchain is like this: +# on Linux it's supplied by the system. +# => AVR_TOOLS_DIR +# +# Having set these three variables, we can work out the rest assuming +# that things are canonically arranged beneath the directories defined +# above. +# +# On the Mac you might want to set: +# +# ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java +# ARDMK_DIR = /usr/local +# +# On Linux, you might prefer: +# +# ARDUINO_DIR = /usr/share/arduino +# ARDMK_DIR = /usr/local +# AVR_TOOLS_DIR = /usr +# +# You can either set these up in the Makefile, or put them in your +# environment e.g. in your .bashrc +# +# If you don't install the ard-... binaries to /usr/local/bin, but +# instead copy them to e.g. /home/mjo/arduino.mk/bin then set +# ARDML_DIR = /home/mjo/arduino.mk +# +######################################################################## +# +# DEPENDENCIES +# +# The Perl programs need a couple of libraries: +# YAML +# Device::SerialPort # ######################################################################## # @@ -83,11 +138,7 @@ # # For example: # -# ARDUINO_DIR = /Applications/arduino-0013 -# -# TARGET = CLItest # ARDUINO_LIBS = Ethernet Ethernet/utility SPI -# # BOARD_TAG = uno # ARDUINO_PORT = /dev/cu.usb* # @@ -95,12 +146,6 @@ # # Hopefully these will be self-explanatory but in case they're not: # -# ARDUINO_DIR - Where the Arduino software has been unpacked -# -# TARGET - The basename used for the final files. Canonically -# this would match the .pde file, but it's not needed -# here: you could always set it to xx if you wanted! -# # ARDUINO_LIBS - A list of any libraries used by the sketch (we # assume these are in # $(ARDUINO_DIR)/hardware/libraries @@ -111,11 +156,6 @@ # BOARD_TAG - The ard-parse-boards tag for the board e.g. uno or mega # 'make show_boards' shows a list # -# You might also want to specify these, but normally they'll be read from the -# boards.txt file i.e. implied by BOARD_TAG -# -# MCU,F_CPU - The target processor description -# # Once this file has been created the typical workflow is just # # $ make upload @@ -157,13 +197,42 @@ # ######################################################################## # -# ARDUINO WITH OTHER TOOLS +# PATHS +# +# I've reworked the way paths to executables are constructed in this +# version of Makefile. +# +# We need to worry about three different sorts of file: +# +# 1. Things which are included in this distribution e.g. ard-parse-boards +# => ARDMK_DIR +# +# 2. Things which are always in the Arduino distribution e.g. +# boards.txt, libraries, &c. +# => ARDUINO_DIR +# +# 3. Things which might be bundled with the Arduino distribution, but +# might come from the system. Most of the toolchain is like this: +# on Linux it's supplied by the system. +# => AVR_TOOLS_DIR +# +# Having set these three variables, we can work out the rest assuming +# that things are canonically arranged beneath the directories defined +# above. +# +# So, on the Mac you might want to set: # -# If the tools aren't in the Arduino distribution, then you need to -# specify their location: +# ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java +# ARDMK_DIR = /usr/local # -# AVR_TOOLS_PATH = /usr/bin -# AVRDUDE_CONF = /etc/avrdude/avrdude.conf +# On Linux, you might prefer: +# +# ARDUINO_DIR = /usr/share/arduino +# ARDMK_DIR = /usr/local +# AVR_TOOLS_DIR = /usr +# +# +# # ######################################################################## # @@ -209,28 +278,49 @@ ifndef ARDUINO_VERSION ARDUINO_VERSION = 100 endif +######################################################################## +# Arduino and system paths # -# Some paths -# +ifdef ARDUINO_DIR -ifneq (ARDUINO_DIR,) +ifndef AVR_TOOLS_DIR +AVR_TOOLS_DIR = $(ARDUINO_DIR)/hardware/tools/avr +# The avrdude bundled with Arduino can't find it's config +AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf +endif ifndef AVR_TOOLS_PATH -AVR_TOOLS_PATH = $(ARDUINO_DIR)/hardware/tools/avr/bin +AVR_TOOLS_PATH = $(AVR_TOOLS_DIR)/bin endif -ifndef ARDUINO_ETC_PATH -ARDUINO_ETC_PATH = $(ARDUINO_DIR)/hardware/tools/avr/etc +ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries +ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino +ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/arduino/variants + +else + +echo $(error "ARDUINO_DIR is not defined") + endif -ifndef AVRDUDE_CONF -AVRDUDE_CONF = $(ARDUINO_ETC_PATH)/avrdude.conf +######################################################################## +# Makefile distribution path +# +ifdef ARDMK_DIR + +ifndef ARDMK_PATH +ARDMK_PATH = $(ARDMK_DIR)/bin endif -ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries -ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino -ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/arduino/variants +else + +echo $(error "ARDMK_DIR is not defined") + +endif +######################################################################## +# Miscellanea +# ifndef ARDUINO_SKETCHBOOK ARDUINO_SKETCHBOOK = $(HOME)/sketchbook endif @@ -239,8 +329,6 @@ ifndef USER_LIB_PATH USER_LIB_PATH = $(ARDUINO_SKETCHBOOK)/libraries endif -endif - ######################################################################## # Serial monitor (just a screen wrapper) # @@ -257,6 +345,12 @@ MONITOR_CMD = screen endif ######################################################################## +# Reset +ifndef RESET_CMD +RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino $(ARD_RESET_OPTS) +endif + +######################################################################## # boards.txt parsing # ifndef BOARD_TAG @@ -268,7 +362,7 @@ BOARDS_TXT = $(ARDUINO_DIR)/hardware/arduino/boards.txt endif ifndef PARSE_BOARD -PARSE_BOARD = ard-parse-boards +PARSE_BOARD = $(ARDMK_PATH)/ard-parse-boards endif ifndef PARSE_BOARD_OPTS @@ -554,10 +648,13 @@ raw_upload: $(TARGET_HEX) $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \ -U flash:w:$(TARGET_HEX):i +reset: + $(RESET_CMD) $(ARD_PORT) + # stty on MacOS likes -F, but on Debian it likes -f redirecting # stdin/out appears to work but generates a spurious error on MacOS at # least. Perhaps it would be better to just do it in perl ? -reset: +reset_stty: for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \ do $$STTYF /dev/tty >/dev/null 2>/dev/null && break ; \ done ;\ @@ -591,6 +688,6 @@ show_boards: monitor: $(MONITOR_CMD) $(ARD_PORT) $(MONITOR_BAUDRATE) -.PHONY: all clean depends upload raw_upload reset size show_boards monitor +.PHONY: all clean depends upload raw_upload reset reset_stty size show_boards monitor include $(DEP_FILE) diff --git a/arduino-mk/ard-parse-boards b/arduino-mk/ard-parse-boards deleted file mode 100755 index e2de71b..0000000 --- a/arduino-mk/ard-parse-boards +++ /dev/null @@ -1,261 +0,0 @@ -#! /usr/bin/perl - -use strict; -use warnings; - -use Getopt::Long; -use Pod::Usage; -use YAML; - -my %Opt = - ( - boards_txt => '/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/boards.txt', - ); - -GetOptions(\%Opt, - "boards_txt=s", # filename of the boards.txt file - "find!", # search for data - "dump!", # dump the whole database - "boards!", # dump a list of boards - "help!", - "info!", - ); - -if ($Opt{help} || $Opt{info}) - { - usage(); - } - -my $db = parse_boards($Opt{boards_txt}); - -if ($Opt{dump}) - { - dump_data("$Opt{boards_txt} contains:", $db); - } -elsif ($Opt{find}) - { - my @terms = @ARGV or usage(); - find_data($db, \@terms); - } -elsif ($Opt{boards}) - { - dump_boards($db); - } -else - { - my $tag = shift @ARGV or usage(); - - if (my $key = shift @ARGV) - { - die "$key isn't defined for the $tag board, " - unless $db->{$tag} && exists $db->{$tag}->{$key}; - - print $db->{$tag}->{$key}, "\n"; - } - else - { - die "The $tag board isn't defined, " - unless $db->{$tag}; - - dump_data("The $tag board:", $db->{$tag}); - } - } - -## here endeth the main - -sub usage - { - pod2usage(-verbose => 2); - } - -# return HoH: {board}->{field} = value -sub parse_boards - { - my $filename = shift; - - my %b; - - open(my $fh, '<', $filename) - or die "Can't open $filename, "; - - while(<$fh>) - { - my ($board, $key, $value) = /^\s*(\S+?)\.(\S+?)\s*=\s*(.+?)\s*$/ - or next; - - $b{$board}->{$key} = $value; - } - - return \%b; - } - -# A rudimentary search engine -sub find_data - { - my ($db, $term_list) = @_; - - my @q = map { qr/$_/i } @$term_list; - my $q = join(' && ', map { "/$_/i" } @$term_list); - - my %hit; - foreach my $b (keys %$db) - { - foreach my $k (keys %{$db->{$b}}) - { - my $v = $db->{$b}->{$k}; - $hit{$b}->{$k} = $v if !grep { $v !~ /$_/i } @q; - } - } - - dump_data("Matches for $q:", \%hit); - } - -# The list of boards... -sub dump_boards - { - my $db = shift or return; - - my %name; - my $max_l = 0; - foreach my $b (keys %$db) - { - $name{$b} = $db->{$b}->{name} || 'Anonymous'; - $max_l = length($b) if $max_l < length($b); - } - - my $fmt = sprintf("%%-%ds %%s\n", $max_l + 2); - - printf $fmt, "Tag", "Board Name"; - foreach my $b (sort keys %name) - { - printf $fmt, $b, $name{$b}; - } - } - - -# dump arbitrary data with a title -sub dump_data - { - my ($title, $data) = @_; - - print "# $title\n", Dump($data); - } - -__END__ - -=head1 NAME - -ard-parse-boards - Read data from the Arduino boards.txt file - -=head1 USAGE - - Dump all the data in the file: - $ ard-parse-boards --dump - - See which boards we know about: - $ ard-parse-boards --boards - - Look for a particular board... - $ ard-parse-boards --find uno - - ...multiple terms are implicitly ANDed: - $ ard-parse-boards --find duemil 328 - - Dump all the data for a particular board: - $ ard-parse-boards atmega328 - - Extract a particular field: - $ ard-parse-boards atmega328 build.f_cpu - -=head1 DESCRIPTION - -The Arduino software package ships with a boards.txt file which tells -the Arduino IDE details about particular hardware. So when the user -says he's got a shiny new Arduino Uno, boards.txt knows that it has a -16MHz ATmega328 on it. It would be nice to access these data from the -command line too. - -In normal operation you simply specify the tag given to the board in -the boards.txt file, and optionally a field name. This program then -extracts the data to STDOUT. - -Most boards have names which are quite unwieldy, so we always refer to -a board by a tag, not its name. Strictly the tag is the bit before the -first dot in the boards.txt key. You can see a list of board tags and -names with the C<--boards> option. - -=head1 OPTIONS - -=over - -=item --boards_txt=[file] - -Specify the full path to the boards.txt file. - -=back - -The following options all disable the normal 'lookup' operation. - -=over - -=item --dump - -Dump the complete database in YAML format. - -=item ---boards - -Print a list of the tag and name of every board in the file. - -=item --find [query] <query> ... - -Find matching data. Strictly, return a list of values which match all -of the query terms, treating each term as a case-insensitive regexp. - -For example: - -=over - -=item --find 328 - -List data containing 328 (anywhere in the value). - -=item --find due - -List data containing 'due' (e.g. duemilanove). - -=item --find 328 due - -List data containing both 328 and due. - -=back - -=back - -=head1 BUGS AND LIMITATIONS - -There are no known bugs in this application. - -Please report problems to the author. - -Patches are welcome. - -=head1 AUTHOR - -Martin Oldfield, ex-atelier@mjo.tc - -Thanks to Mark Sproul who suggested doing something like this to me ages ago. - -=head1 LICENCE AND COPYRIGHT - -Copyright (c) 2011, Martin Oldfield. All rights reserved. - -This file is free software; you can redistribute it and/or modify it -under the terms of the GNU Lesser General Public License as published -by the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - - |
