summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena of Valhalla'' Grandi <valhalla.trueelena.org>2013-05-05 16:15:24 +0200
committerElena of Valhalla'' Grandi <valhalla.trueelena.org>2013-05-05 16:15:24 +0200
commit088b92b2f850fad7340b0bcecb5d46456d46c93d (patch)
tree749bc882360f68260a0d5070682b8f97f3509e31
parent94a0d2ab8073f58fb856ea7f3c57014a7f3338ae (diff)
arscons: updated to version ca36ae (19 Feb 2013)HEADmaster
-rw-r--r--arduino_sketch/rfc4824/SConstruct462
1 files changed, 278 insertions, 184 deletions
diff --git a/arduino_sketch/rfc4824/SConstruct b/arduino_sketch/rfc4824/SConstruct
index 5e6e968..b0e2702 100644
--- a/arduino_sketch/rfc4824/SConstruct
+++ b/arduino_sketch/rfc4824/SConstruct
@@ -1,9 +1,9 @@
#!/usr/bin/python
-# scons script for the Arduino sketch
-# http://code.google.com/p/arscons/
+# arscons: scons script for the Arduino sketch
+# http://github.com/suapapa/arscons
#
-# Copyright (C) 2010 by Homin Lee <ff4500@gmail.com>
+# Copyright (C) 2010-2013 by Homin Lee <homin.lee@suapapa.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -13,7 +13,7 @@
# You'll need the serial module: http://pypi.python.org/pypi/pyserial
# Basic Usage:
-# 1. make a folder which have same name of the sketch (ex. Blink/ for Blik.pde)
+# 1. make a folder which have same name of the sketch (ex. Blink/ for Blink.pde)
# 2. put the sketch and SConstruct(this file) under the folder.
# 3. to make the HEX. do following in the folder.
# $ scons
@@ -36,262 +36,361 @@
#
# $ scons EXTRA_LIB=<my-extra-library-dir>
#
+
from glob import glob
-import sys
-import re
+from itertools import ifilter, imap
+from os import path
+from subprocess import check_call, CalledProcessError
+import json
import os
-pathJoin = os.path.join
+import re
+import sys
+
+# arscons version
+__version__ = "1.0.0"
env = Environment()
platform = env['PLATFORM']
+VARTAB = {}
+
+try:
+ config = json.load(open('arscons.json'))
+except IOError:
+ config = None
+
+def config_get(varname, returns):
+ if config:
+ result = config.get(varname, returns)
+ else:
+ result = returns
+
+ return result
+
+def resolve_var(varname, default_value):
+ global VARTAB
+ # precedence: scons argument -> env. variable -> json config -> default value
+ ret = ARGUMENTS.get(varname, None)
+ VARTAB[varname] = ('arg', ret)
+ if ret == None:
+ ret = os.environ.get(varname, None)
+ VARTAB[varname] = ('env', ret)
+ if ret == None:
+ ret = config_get(varname, None)
+ VARTAB[varname] = ('cnf', ret)
+ if ret == None:
+ ret = default_value
+ VARTAB[varname] = ('dfl', ret)
+ return ret
+
def getUsbTty(rx):
usb_ttys = glob(rx)
- if len(usb_ttys) == 1: return usb_ttys[0]
- else: return None
+ return usb_ttys[0] if len(usb_ttys) == 1 else None
AVR_BIN_PREFIX = None
AVRDUDE_CONF = None
if platform == 'darwin':
# For MacOS X, pick up the AVR tools from within Arduino.app
- ARDUINO_HOME_DEFAULT = '/Applications/Arduino.app/Contents/Resources/Java'
- ARDUINO_PORT_DEFAULT = getUsbTty('/dev/tty.usbserial*')
- SKETCHBOOK_HOME_DEFAULT = ''
+ ARDUINO_HOME = resolve_var('ARDUINO_HOME',
+ '/Applications/Arduino.app/Contents/Resources/Java')
+ ARDUINO_PORT = resolve_var('ARDUINO_PORT', getUsbTty('/dev/tty.usbserial*'))
+ SKETCHBOOK_HOME = resolve_var('SKETCHBOOK_HOME', '')
+ AVR_HOME = resolve_var('AVR_HOME',
+ path.join(ARDUINO_HOME, 'hardware/tools/avr/bin'))
elif platform == 'win32':
# For Windows, use environment variables.
- ARDUINO_HOME_DEFAULT = os.environ.get('ARDUINO_HOME')
- ARDUINO_PORT_DEFAULT = os.environ.get('ARDUINO_PORT')
- SKETCHBOOK_HOME_DEFAULT = ''
+ ARDUINO_HOME = resolve_var('ARDUINO_HOME', None)
+ ARDUINO_PORT = resolve_var('ARDUINO_PORT', '')
+ SKETCHBOOK_HOME = resolve_var('SKETCHBOOK_HOME', '')
+ if ARDUINO_HOME:
+ AVR_HOME = resolve_var('AVR_HOME',
+ path.join(ARDUINO_HOME, 'hardware/tools/avr/bin'))
else:
# For Ubuntu Linux (9.10 or higher)
- ARDUINO_HOME_DEFAULT = os.environ.get('ARDUINO_HOME','/usr/share/arduino/') #'/home/YOU/apps/arduino-00XX/'
- ARDUINO_PORT_DEFAULT = getUsbTty('/dev/ttyUSB*')
- AVR_BIN_PREFIX = 'avr-'
- SKETCHBOOK_HOME_DEFAULT = os.path.realpath('~/share/arduino/sketchbook/')
+ ARDUINO_HOME = resolve_var('ARDUINO_HOME', '/usr/share/arduino/')
+ ARDUINO_PORT = resolve_var('ARDUINO_PORT', getUsbTty('/dev/ttyUSB*'))
+ SKETCHBOOK_HOME = resolve_var('SKETCHBOOK_HOME',
+ path.expanduser('~/share/arduino/sketchbook/'))
+ AVR_HOME = resolve_var('AVR_HOME', '')
-ARDUINO_BOARD_DEFAULT = os.environ.get('ARDUINO_BOARD', 'atmega328')
-ARDUINO_HOME = ARGUMENTS.get('ARDUINO_HOME', ARDUINO_HOME_DEFAULT)
-ARDUINO_PORT = ARGUMENTS.get('ARDUINO_PORT', ARDUINO_PORT_DEFAULT)
-ARDUINO_BOARD = ARGUMENTS.get('ARDUINO_BOARD', ARDUINO_BOARD_DEFAULT)
-ARDUINO_VER = ARGUMENTS.get('ARDUINO_VER', 0) # Default to 0 if nothing is specified
-RST_TRIGGER = ARGUMENTS.get('RST_TRIGGER', None) # use built-in pulseDTR() by default
-EXTRA_LIB = ARGUMENTS.get('EXTRA_LIB', None) # handy for adding another arduino-lib dir
-SKETCHBOOK_HOME = ARGUMENTS.get('SKETCHBOOK_HOME', SKETCHBOOK_HOME_DEFAULT) # If set will add the libraries dir from the sketchbook
+ARDUINO_BOARD = resolve_var('ARDUINO_BOARD', 'atmega328')
+ARDUINO_VER = resolve_var('ARDUINO_VER', 0) # Default to 0 if nothing is specified
+RST_TRIGGER = resolve_var('RST_TRIGGER', None) # use built-in pulseDTR() by default
+EXTRA_LIB = resolve_var('EXTRA_LIB', None) # handy for adding another arduino-lib dir
if not ARDUINO_HOME:
print 'ARDUINO_HOME must be defined.'
raise KeyError('ARDUINO_HOME')
-ARDUINO_CORE = pathJoin(ARDUINO_HOME, 'hardware/arduino/cores/arduino')
-ARDUINO_SKEL = pathJoin(ARDUINO_CORE, 'main.cpp')
-ARDUINO_CONF = pathJoin(ARDUINO_HOME, 'hardware/arduino/boards.txt')
+ARDUINO_CONF = path.join(ARDUINO_HOME, 'hardware/arduino/boards.txt')
+# check given board name, ARDUINO_BOARD is valid one
+arduino_boards = path.join(ARDUINO_HOME,'hardware/*/boards.txt')
+custom_boards = path.join(SKETCHBOOK_HOME,'hardware/*/boards.txt')
+board_files = glob(arduino_boards) + glob(custom_boards)
+ptnBoard = re.compile(r'^([^#]*)\.name=(.*)')
+boards = {}
+for bf in board_files:
+ for line in open(bf):
+ result = ptnBoard.match(line)
+ if result:
+ boards[result.group(1)] = (result.group(2), bf)
+
+if ARDUINO_BOARD not in boards:
+ print "ERROR! the given board name, %s is not in the supported board list:" % ARDUINO_BOARD
+ print "all available board names are:"
+ for name, description in boards.iteritems():
+ print "\t%s for %s" % (name.ljust(14), description[0])
+ #print "however, you may edit %s to add a new board." % ARDUINO_CONF
+ sys.exit(-1)
+
+ARDUINO_CONF = boards[ARDUINO_BOARD][1]
+
+def getBoardConf(conf, default = None):
+ for line in open(ARDUINO_CONF):
+ line = line.strip()
+ if '=' in line:
+ key, value = line.split('=')
+ if key == '.'.join([ARDUINO_BOARD, conf]):
+ return value
+ ret = default
+ if ret == None:
+ print "ERROR! can't find %s in %s" % (conf, ARDUINO_CONF)
+ assert(False)
+ return ret
+
+ARDUINO_CORE = path.join(ARDUINO_HOME, path.dirname(ARDUINO_CONF),
+ 'cores/', getBoardConf('build.core', 'arduino'))
+ARDUINO_SKEL = path.join(ARDUINO_CORE, 'main.cpp')
-arduino_file_path = pathJoin(ARDUINO_CORE, 'Arduino.h')
if ARDUINO_VER == 0:
- print "No Arduino version specified. Discovered version",
- if os.path.exists(arduino_file_path):
- print "100 or above"
- ARDUINO_VER = 100
- else:
- print "0023 or below"
- ARDUINO_VER = 23
+ arduinoHeader = path.join(ARDUINO_CORE, 'Arduino.h')
+ #print "No Arduino version specified. Discovered version",
+ if path.exists(arduinoHeader):
+ #print "100 or above"
+ ARDUINO_VER = 100
+ else:
+ #print "0023 or below"
+ ARDUINO_VER = 23
else:
- print "Arduino version " + ARDUINO_VER + " specified"
-
-if ARDUINO_VER < 100: FILE_EXTENSION = ".pde"
-if ARDUINO_VER >= 100: FILE_EXTENSION = ".ino"
+ print "Arduino version " + ARDUINO_VER + " specified"
# Some OSs need bundle with IDE tool-chain
-if platform == 'darwin' or platform == 'win32':
- AVR_BIN_PREFIX = pathJoin(ARDUINO_HOME, 'hardware/tools/avr/bin', 'avr-')
- AVRDUDE_CONF = pathJoin(ARDUINO_HOME, 'hardware/tools/avr/etc/avrdude.conf')
+if platform == 'darwin' or platform == 'win32':
+ AVRDUDE_CONF = path.join(ARDUINO_HOME, 'hardware/tools/avr/etc/avrdude.conf')
+
+AVR_BIN_PREFIX = path.join(AVR_HOME, 'avr-')
-ARDUINO_LIBS = [pathJoin(ARDUINO_HOME, 'libraries')]
+ARDUINO_LIBS = [path.join(ARDUINO_HOME, 'libraries')]
if EXTRA_LIB:
- ARDUINO_LIBS += [EXTRA_LIB]
+ ARDUINO_LIBS.append(EXTRA_LIB)
if SKETCHBOOK_HOME:
- ARDUINO_LIBS += [pathJoin(SKETCHBOOK_HOME, 'libraries')]
+ ARDUINO_LIBS.append(path.join(SKETCHBOOK_HOME, 'libraries'))
-# check given board name, ARDUINO_BOARD is valid one
-ptnBoard = re.compile(r'^(.*)\.name=(.*)')
-boards = {}
-for line in open(ARDUINO_CONF):
- result = ptnBoard.findall(line)
- if result:
- boards[result[0][0]] = result[0][1]
-if not ARDUINO_BOARD in boards.keys():
- print ("ERROR! the given board name, %s is not in the supported board list:"%ARDUINO_BOARD)
- print ("all available board names are:")
- for name in boards.keys():
- print ("\t%s for %s"%(name.ljust(14), boards[name]))
- print ("however, you may edit %s to add a new board."%ARDUINO_CONF)
- sys.exit(-1)
-
-def getBoardConf(strPtn):
- ptn = re.compile(strPtn)
- for line in open(ARDUINO_CONF):
- result = ptn.findall(line)
- if result:
- return result[0]
- assert(False)
-MCU = getBoardConf(r'^%s\.build\.mcu=(.*)'%ARDUINO_BOARD)
-MCU = ARGUMENTS.get('MCU', MCU)
-F_CPU = getBoardConf(r'^%s\.build\.f_cpu=(.*)'%ARDUINO_BOARD)
-F_CPU = ARGUMENTS.get('F_CPU', F_CPU)
+# Override MCU and F_CPU
+MCU = ARGUMENTS.get('MCU', getBoardConf('build.mcu'))
+F_CPU = ARGUMENTS.get('F_CPU', getBoardConf('build.f_cpu'))
-# There should be a file with the same name as the folder and with the extension .pde
-TARGET = os.path.basename(os.path.realpath(os.curdir))
-assert(os.path.exists(TARGET+FILE_EXTENSION))
+# There should be a file with the same name as the folder and
+# with the extension .pde or .ino
+# Or, one can specify it via the ARSCONS_TARGET environment
+# variable..
-cFlags = ['-ffunction-sections', '-fdata-sections', '-fno-exceptions',
- '-funsigned-char', '-funsigned-bitfields', '-fpack-struct', '-fshort-enums',
- '-Os', '-mmcu=%s'%MCU]
-envArduino = Environment(CC = AVR_BIN_PREFIX+'gcc', CXX = AVR_BIN_PREFIX+'g++', AS=AVR_BIN_PREFIX+'gcc',
- CPPPATH = ['build/core'], CPPDEFINES = {'F_CPU':F_CPU, 'ARDUINO':ARDUINO_VER},
- CFLAGS = cFlags+['-std=gnu99'], CCFLAGS = cFlags, ASFLAGS=['-assembler-with-cpp','-mmcu=%s'%MCU],
- TOOLS = ['gcc','g++', 'as'])
+TARGET = resolve_var('ARSCONS_TARGET', None)
+if TARGET is None:
+ TARGET = path.basename(path.realpath(os.curdir))
+assert(path.exists(TARGET + '.ino') or path.exists(TARGET + '.pde'))
+sketchExt = '.ino' if path.exists(TARGET + '.ino') else '.pde'
-if ARDUINO_VER >= 100:
- if ARDUINO_BOARD == 'nano328': envArduino.Append(CPPPATH = pathJoin(ARDUINO_HOME, 'hardware/arduino/variants/eightanaloginputs/'))
- elif ARDUINO_BOARD == 'leonardo': envArduino.Append(CPPPATH = pathJoin(ARDUINO_HOME, 'hardware/arduino/variants/leonardo/'))
- elif ARDUINO_BOARD == 'mega2560': envArduino.Append(CPPPATH = pathJoin(ARDUINO_HOME, 'hardware/arduino/variants/mega/'))
- elif ARDUINO_BOARD == 'micro': envArduino.Append(CPPPATH = pathJoin(ARDUINO_HOME, 'hardware/arduino/variants/micro/'))
- else: envArduino.Append(CPPPATH = pathJoin(ARDUINO_HOME, 'hardware/arduino/variants/standard/'))
+cFlags = ['-ffunction-sections', '-fdata-sections', '-fno-exceptions',
+ '-funsigned-char', '-funsigned-bitfields', '-fpack-struct',
+ '-fshort-enums', '-Os', '-Wall', '-mmcu=%s' % MCU]
+
+# Add some missing paths to CFLAGS
+# Workaround for /usr/libexec/gcc/avr/ld: cannot open linker script file ldscripts/avr5.x: No such file or directory
+# Workaround for /usr/libexec/gcc/avr/ld: crtm168.o: No such file: No such file or directory
+extra_cflags = [
+ '-L/usr/x86_64-pc-linux-gnu/avr/lib/',
+ '-B/usr/avr/lib/avr5/',
+ ]
+cFlags += extra_cflags
+
+if ARDUINO_BOARD == "leonardo":
+ cFlags += ["-DUSB_VID="+getBoardConf('build.vid')]
+ cFlags += ["-DUSB_PID="+getBoardConf('build.pid')]
+
+envArduino = Environment(CC = AVR_BIN_PREFIX + 'gcc',
+ CXX = AVR_BIN_PREFIX + 'g++',
+ AS = AVR_BIN_PREFIX + 'gcc',
+ CPPPATH = ['build/core'],
+ CPPDEFINES = {'F_CPU': F_CPU, 'ARDUINO': ARDUINO_VER},
+ CFLAGS = cFlags + ['-std=gnu99'],
+ CCFLAGS = cFlags,
+ ASFLAGS = ['-assembler-with-cpp','-mmcu=%s' % MCU],
+ TOOLS = ['gcc','g++', 'as'])
+
+hwVariant = path.join(ARDUINO_HOME, 'hardware/arduino/variants',
+ getBoardConf("build.variant", ""))
+if hwVariant:
+ envArduino.Append(CPPPATH = hwVariant)
+
+# Show version
+def printVersion(target, source, env):
+ print "arscons v%s"%__version__
+
+version = envArduino.Alias('version', None, [printVersion])
+AlwaysBuild(version)
def run(cmd):
"""Run a command and decipher the return code. Exit by default."""
- import SCons.Script
- print cmd
- res = os.system(cmd)
- # Assumes that if a process doesn't call exit, it was successful
- if (os.WIFEXITED(res)):
- code = os.WEXITSTATUS(res)
- if code != 0:
- print "Error: return code: " + str(code)
- if SCons.Script.keep_going_on_error == 0:
- sys.exit(code)
-
-def fnCompressCore(target, source, env):
- core_files = filter(lambda x: str(x).startswith('build/core/'), source)
- for file in core_files:
- run(AVR_BIN_PREFIX+'ar rcs %s %s'%(target[0], file))
-
+ # print ' '.join(cmd)
+ try:
+ check_call(cmd)
+ except CalledProcessError as cpe:
+ print "Error: return code: " + str(cpe.returncode)
+ sys.exit(cpe.returncode)
+
+# WindowXP not supported path.samefile
+def sameFile(p1, p2):
+ if platform == 'win32':
+ ap1 = path.abspath(p1)
+ ap2 = path.abspath(p2)
+ return ap1 == ap2
+ return path.samefile(p1, p2)
def fnProcessing(target, source, env):
- wp = open ('%s'%target[0], 'wb')
+ wp = open(str(target[0]), 'wb')
wp.write(open(ARDUINO_SKEL).read())
- types='''void
- int char word long
- float double byte long
- boolean
- uint8_t uint16_t uint32_t
- int8_t int16_t int32_t
- '''
+ types='''void
+ int char word long
+ float double byte long
+ boolean
+ uint8_t uint16_t uint32_t
+ int8_t int16_t int32_t'''
types=' | '.join(types.split())
- re_signature=re.compile(r"""^\s* (
+ re_signature = re.compile(r"""^\s* (
(?: (%s) \s+ )?
\w+ \s*
\( \s* ((%s) \s+ \*? \w+ (?:\s*,\s*)? )* \)
- ) \s* {? \s* $""" % (types,types), re.MULTILINE|re.VERBOSE)
+ ) \s* {? \s* $""" % (types, types), re.MULTILINE | re.VERBOSE)
prototypes = {}
- for file in glob(os.path.realpath(os.curdir) + "/*" + FILE_EXTENSION):
+ for file in glob(path.realpath(os.curdir) + "/*" + sketchExt):
for line in open(file):
- result = re_signature.findall(line)
+ result = re_signature.search(line)
if result:
- prototypes[result[0][0]] = result[0][1]
+ prototypes[result.group(1)] = result.group(2)
- for name in prototypes.keys():
- print ("%s;"%(name))
- wp.write("%s;\n"%name)
+ for name in prototypes.iterkeys():
+ print "%s;" % name
+ wp.write("%s;\n" % name)
- for file in glob(os.path.realpath(os.curdir) + "/*" + FILE_EXTENSION):
+ for file in glob(path.realpath(os.curdir) + "/*" + sketchExt):
print file, TARGET
- if not os.path.samefile(file, TARGET+FILE_EXTENSION):
- wp.write('#line 1 "%s"\r\n' % file)
- wp.write(open(file).read())
+ if not sameFile(file, TARGET + sketchExt):
+ wp.write('#line 1 "%s"\r\n' % file)
+ wp.write(open(file).read())
# Add this preprocessor directive to localize the errors.
- sourcePath = str(source[0]).replace('\\', '\\\\');
+ sourcePath = str(source[0]).replace('\\', '\\\\')
wp.write('#line 1 "%s"\r\n' % sourcePath)
- wp.write(open('%s'%source[0]).read())
+ wp.write(open(str(source[0])).read())
-envArduino.Append(BUILDERS = {'Processing':Builder(action = fnProcessing,
- suffix = '.cpp', src_suffix = FILE_EXTENSION)})
-envArduino.Append(BUILDERS = {'CompressCore':Builder(action = fnCompressCore) })
-envArduino.Append(BUILDERS={'Elf':Builder(action=AVR_BIN_PREFIX+'gcc '+
- '-mmcu=%s -Os -Wl,--gc-sections -o $TARGET $SOURCES -lm'%MCU)})
-envArduino.Append(BUILDERS={'Hex':Builder(action=AVR_BIN_PREFIX+'objcopy '+
- '-O ihex -R .eeprom $SOURCES $TARGET')})
-
-gatherSources = lambda x: glob(pathJoin(x, '*.c'))+\
- glob(pathJoin(x, '*.cpp'))+\
- glob(pathJoin(x, '*.S'))
+def fnCompressCore(target, source, env):
+ core_prefix = 'build/core/'.replace('/', os.path.sep)
+ core_files = (x for x in imap(str, source)
+ if x.startswith(core_prefix))
+ for file in core_files:
+ run([AVR_BIN_PREFIX + 'ar', 'rcs', str(target[0]), file])
+
+def fnPrintInfo(target, source, env):
+ for k in VARTAB:
+ cameFrom, value = VARTAB[k]
+ print "* %s: %s (%s)"%(k, value, cameFrom)
+ print "* avr-size:"
+ run([AVR_BIN_PREFIX + 'size', '--target=ihex', str(source[0])])
+ # TODO: check binary size
+ print "* maximum size for hex file: %s bytes" % getBoardConf('upload.maximum_size')
+
+
+bldProcessing = Builder(action = fnProcessing) #, suffix = '.cpp', src_suffix = sketchExt)
+bldCompressCore = Builder(action = fnCompressCore)
+bldELF = Builder(action = AVR_BIN_PREFIX + 'gcc -mmcu=%s ' % MCU +
+ '-Os -Wl,--gc-sections -lm %s -o $TARGET $SOURCES -lc' % ' '.join(extra_cflags))
+bldHEX = Builder(action = AVR_BIN_PREFIX + 'objcopy -O ihex -R .eeprom $SOURCES $TARGET')
+bldInfo = Builder(action = fnPrintInfo)
+
+envArduino.Append(BUILDERS = {'Processing' : bldProcessing})
+envArduino.Append(BUILDERS = {'CompressCore': bldCompressCore})
+envArduino.Append(BUILDERS = {'Elf' : bldELF})
+envArduino.Append(BUILDERS = {'Hex' : bldHEX})
+envArduino.Append(BUILDERS = {'BuildInfo' : bldInfo})
+
+ptnSource = re.compile(r'\.(?:c(?:pp)?|S)$')
+def gatherSources(srcpath):
+ return [path.join(srcpath, f) for f
+ in os.listdir(srcpath) if ptnSource.search(f)]
# add arduino core sources
VariantDir('build/core', ARDUINO_CORE)
core_sources = gatherSources(ARDUINO_CORE)
-core_sources = filter(lambda x: not (os.path.basename(x) == 'main.cpp'), core_sources)
-core_sources = map(lambda x: x.replace(ARDUINO_CORE, 'build/core/'), core_sources)
+core_sources = [x.replace(ARDUINO_CORE, 'build/core/') for x
+ in core_sources if path.basename(x) != 'main.cpp']
# add libraries
libCandidates = []
ptnLib = re.compile(r'^[ ]*#[ ]*include [<"](.*)\.h[>"]')
-for line in open (TARGET+FILE_EXTENSION):
- result = ptnLib.findall(line)
- if result:
- # Look for the library directory that contains the header.
- filename=result[0]+'.h'
- for libdir in ARDUINO_LIBS:
- for root, dirs, files in os.walk(libdir, followlinks=True):
- for f in files:
- if f == filename:
- libCandidates += [os.path.basename(root)]
+for line in open(TARGET + sketchExt):
+ result = ptnLib.search(line)
+ if not result:
+ continue
+ # Look for the library directory that contains the header.
+ filename = result.group(1) + '.h'
+ for libdir in ARDUINO_LIBS:
+ for root, dirs, files in os.walk(libdir, followlinks=True):
+ if filename in files:
+ libCandidates.append(path.basename(root))
# Hack. In version 20 of the Arduino IDE, the Ethernet library depends
# implicitly on the SPI library.
if ARDUINO_VER >= 20 and 'Ethernet' in libCandidates:
- libCandidates += ['SPI']
+ libCandidates.append('SPI')
all_libs_sources = []
-index = 0
-for orig_lib_dir in ARDUINO_LIBS:
- lib_sources = []
- lib_dir = 'build/lib_%02d'%index
+for index, orig_lib_dir in enumerate(ARDUINO_LIBS):
+ lib_dir = 'build/lib_%02d' % index
VariantDir(lib_dir, orig_lib_dir)
- for libPath in filter(os.path.isdir, glob(pathJoin(orig_lib_dir, '*'))):
- libName = os.path.basename(libPath)
+ for libPath in ifilter(path.isdir, glob(path.join(orig_lib_dir, '*'))):
+ libName = path.basename(libPath)
if not libName in libCandidates:
continue
envArduino.Append(CPPPATH = libPath.replace(orig_lib_dir, lib_dir))
lib_sources = gatherSources(libPath)
- utilDir = pathJoin(libPath, 'utility')
- if os.path.exists(utilDir) and os.path.isdir(utilDir):
+ utilDir = path.join(libPath, 'utility')
+ if path.exists(utilDir) and path.isdir(utilDir):
lib_sources += gatherSources(utilDir)
envArduino.Append(CPPPATH = utilDir.replace(orig_lib_dir, lib_dir))
- lib_sources = map(lambda x: x.replace(orig_lib_dir, lib_dir), lib_sources)
- all_libs_sources += lib_sources
- index += 1
+ lib_sources = (x.replace(orig_lib_dir, lib_dir) for x in lib_sources)
+ all_libs_sources.extend(lib_sources)
# Add raw sources which live in sketch dir.
-build_top = os.path.realpath('.')
+build_top = path.realpath('.')
VariantDir('build/local/', build_top)
local_sources = gatherSources(build_top)
-local_sources = map(lambda x: x.replace(build_top, 'build/local/'), local_sources)
+local_sources = [x.replace(build_top, 'build/local/') for x in local_sources]
if local_sources:
envArduino.Append(CPPPATH = 'build/local')
# Convert sketch(.pde) to cpp
-envArduino.Processing('build/'+TARGET+'.cpp', 'build/'+TARGET+FILE_EXTENSION)
+envArduino.Processing('build/' + TARGET + '.cpp', 'build/' + TARGET + sketchExt)
VariantDir('build', '.')
-sources = ['build/'+TARGET+'.cpp']
+sources = ['build/' + TARGET + '.cpp']
#sources += core_sources
sources += local_sources
sources += all_libs_sources
@@ -300,14 +399,9 @@ sources += all_libs_sources
core_objs = envArduino.Object(core_sources)
objs = envArduino.Object(sources) #, LIBS=libs, LIBPATH='.')
objs = objs + envArduino.CompressCore('build/core.a', core_objs)
-envArduino.Elf(TARGET+'.elf', objs)
-envArduino.Hex(TARGET+'.hex', TARGET+'.elf')
-
-# Print Size
-# TODO: check binary size
-MAX_SIZE = getBoardConf(r'^%s\.upload.maximum_size=(.*)'%ARDUINO_BOARD)
-print ("maximum size for hex file: %s bytes"%MAX_SIZE)
-envArduino.Command(None, TARGET+'.hex', AVR_BIN_PREFIX+'size --target=ihex $SOURCE')
+envArduino.Elf(TARGET + '.elf', objs)
+envArduino.Hex(TARGET + '.hex', TARGET + '.elf')
+envArduino.BuildInfo(None, TARGET + '.hex')
# Reset
def pulseDTR(target, source, env):
@@ -320,27 +414,27 @@ def pulseDTR(target, source, env):
ser.close()
if RST_TRIGGER:
- reset_cmd = '%s %s'%(RST_TRIGGER, ARDUINO_PORT)
+ reset_cmd = '%s %s' % (RST_TRIGGER, ARDUINO_PORT)
else:
reset_cmd = pulseDTR
# Upload
-UPLOAD_PROTOCOL = getBoardConf(r'^%s\.upload\.protocol=(.*)'%ARDUINO_BOARD)
-UPLOAD_SPEED = getBoardConf(r'^%s\.upload\.speed=(.*)'%ARDUINO_BOARD)
+UPLOAD_PROTOCOL = getBoardConf('upload.protocol')
+UPLOAD_SPEED = getBoardConf('upload.speed')
if UPLOAD_PROTOCOL == 'stk500':
UPLOAD_PROTOCOL = 'stk500v1'
-avrdudeOpts = ['-V', '-F', '-c %s'%UPLOAD_PROTOCOL, '-b %s'%UPLOAD_SPEED,
- '-p %s'%MCU, '-P %s'%ARDUINO_PORT, '-U flash:w:$SOURCES']
+avrdudeOpts = ['-V', '-F', '-c %s' % UPLOAD_PROTOCOL, '-b %s' % UPLOAD_SPEED,
+ '-p %s' % MCU, '-P %s' % ARDUINO_PORT, '-U flash:w:$SOURCES']
if AVRDUDE_CONF:
- avrdudeOpts += ['-C %s'%AVRDUDE_CONF]
+ avrdudeOpts.append('-C %s' % AVRDUDE_CONF)
-fuse_cmd = '%s %s'%(pathJoin(os.path.dirname(AVR_BIN_PREFIX), 'avrdude'),
- ' '.join(avrdudeOpts))
+fuse_cmd = '%s %s' % (path.join(path.dirname(AVR_BIN_PREFIX), 'avrdude'),
+ ' '.join(avrdudeOpts))
-upload = envArduino.Alias('upload', TARGET+'.hex', [reset_cmd, fuse_cmd]);
+upload = envArduino.Alias('upload', TARGET + '.hex', [reset_cmd, fuse_cmd])
AlwaysBuild(upload)
# Clean build directory