Index: devel/arduino-bsd-mk/Makefile =================================================================== --- /dev/null +++ devel/arduino-bsd-mk/Makefile @@ -0,0 +1,64 @@ +# Created by: Craig Leres +# $FreeBSD$ + +PORTNAME= arduino-bsd-mk +PORTVERSION= 1.0 +CATEGORIES= devel +DISTFILES= + +MAINTAINER= leres@FreeBSD.org +COMMENT= Build Arduino sketches from the command line on FreeBSD + +LICENSE= BSD2CLAUSE + +RUN_DEPENDS= arduino:devel/arduino \ + avr-gcc:devel/avr-gcc + +NO_BUILD= yes +NO_MTREE= yes + +USES= python:run + +SUB_FILES= bsd.arduino.mk.7 + +PORTEXAMPLES= * + +PYLINT= pylint --reports=no -d C0103,C0302,C0330,R0902,R0903,R0911,R0912,R0913,R0914,R0915,W0141,W0312,W0511,W0603 "--dummy-variables-rgx=(_[a-z_][a-z0-9_]*)" + +ALL_FILES= arduino-bsd-mk/bsd.arduino.mk + +ALL_SCRIPTS= arduino-bsd-mk/scripts/arduino-boards.py \ + arduino-bsd-mk/scripts/arduino-version.sh \ + arduino-bsd-mk/scripts/gcc-version.sh + +PLIST_FILES= ${ALL_FILES} ${ALL_SCRIPTS:R} man/man7/bsd.arduino.mk.7.gz + +PY_SCRIPTS= ${ALL_SCRIPTS:T:M*.py} + +OPTIONS_DEFINE+= EXAMPLES + +do-extract: + ${MKDIR} ${WRKSRC} + +stage-dir: +.for F in ${ALL_SCRIPTS:H:u} + ${MKDIR} ${STAGEDIR}${PREFIX}/${F} +.endfor + ${MKDIR} ${STAGEDIR}${PREFIX}/man/man7 + +do-install: +.for F in ${ALL_FILES} + ${INSTALL_SCRIPT} ${FILESDIR}/${F:T} ${STAGEDIR}${PREFIX}/${F:H} +.endfor +.for F in ${ALL_SCRIPTS} + ${INSTALL_SCRIPT} ${FILESDIR}/${F:T} ${STAGEDIR}${PREFIX}/${F:R} +.endfor + ${INSTALL_MAN} ${WRKDIR}/bsd.arduino.mk.7 ${STAGEDIR}${MANPREFIX}/man/man7 + (cd ${FILESDIR}/examples && ${COPYTREE_SHARE} "*" ${STAGEDIR}$/${EXAMPLESDIR}) + +lint: +.for F in ${PY_SCRIPTS} + @${PYLINT} ${FILESDIR}/${F} || true +.endfor + +.include Index: devel/arduino-bsd-mk/files/arduino-boards.py =================================================================== --- /dev/null +++ devel/arduino-bsd-mk/files/arduino-boards.py @@ -0,0 +1,129 @@ +#!/usr/local/bin/python +# $FreeBSD$ +"""Parse the Arduino boards.txt file + http://code.google.com/p/arduino/wiki/Platforms""" + +from __future__ import print_function + +import argparse +import os +import sys + +OPTS = None +PROG = '?' + +DEFAULT_BOARDS = '/usr/local/arduino/hardware/arduino/boards.txt' + +def parse(f, fn): + """Parse the boards.txt file, return a dictonary and an optional + error message""" + target = None + board = None + boards = {} + n = 0 + for line in f.readlines(): + n += 1 + line = line.strip() + if not line: + continue + if line.startswith('#'): + continue + tup = line.split('=', 1) + if len(tup) != 2: + return (boards, '%s:%d: malformed line (1)' % (fn, n)) + line2 = tup[0] + val = tup[1] + tup2 = line2.split('.', 1) + if len(tup2) != 2: + return (boards, '%s:%d: malformed line (2)' % (fn, n)) + if target != tup2[0]: + if target: + boards[target] = board + target = tup2[0] + board = {} + board[tup2[1]] = val + + if target: + boards[target] = board + return (boards, None) + +def main(argv=None): + """Parse options and execute""" + global OPTS + global PROG + + if not argv: + argv = sys.argv + + PROG = os.path.basename(argv[0]) + version = '$Revision: 43 $'.strip('$').rstrip() + + parser = argparse.ArgumentParser() + parser.add_argument('--version', action='version', version=version) + parser.add_argument('-d', dest='debug', action='count', default=0, + help='turn on debugging') + parser.add_argument('-v', dest='verbose', action='count', default=0, + help='verbose messages') + parser.add_argument('-e', dest='emptyok', action='store_true', + help='empty result is ok') + parser.add_argument('-f', dest='boards', + default=DEFAULT_BOARDS, + help='boards.txt (default: %(default)s)') + parser.add_argument('--debugger', action='store_true', + help=argparse.SUPPRESS) + + parser.add_argument('variant', metavar='VARIANT', + help='variant') + parser.add_argument('what', metavar='WHAT', + help='what') + + OPTS = parser.parse_args() + + # argparse debugging + if OPTS.debug > 1: + for key in dir(OPTS): + if not key.startswith('_'): + print('# %s=%s' % (key, getattr(OPTS, key)), file=sys.stderr) + + # Interactive debugging + if OPTS.debugger: + import pdb + pdb.set_trace() + + boards = None + errmsg = None + try: + with open(OPTS.boards) as f: + boards, errmsg = parse(f, OPTS.boards) + except (IOError, OSError) as e: + print('%s: %s: %s' % (PROG, OPTS.boards, e.strerror), file=sys.stderr) + return 1 + if errmsg: + print('%s: %s' % (PROG, errmsg), file=sys.stderr) + return 1 + board = boards.get(OPTS.variant) + if not board: + print("%s: Can't find %s" % (PROG, OPTS.variant), file=sys.stderr) + return 1 + + val = board.get(OPTS.what) + if not val: + if OPTS.emptyok: + return 0 + print("%s: Can't find %s.%s" % (PROG, OPTS.variant, OPTS.what), + file=sys.stderr) + return 1 + print('%s' % val) + +# XXX add dump() +# keys = board.keys() +# keys.sort() +# for key in keys: +# display = [OPTS.variant, key] +# val = board.get(key) +# print('%s=%s' % ('.'.join(display), val)) + + return 0 + +if __name__ == "__main__": + sys.exit(main()) Index: devel/arduino-bsd-mk/files/arduino-version.sh =================================================================== --- /dev/null +++ devel/arduino-bsd-mk/files/arduino-version.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# $FreeBSD$ +# +# The ARDUINO version.txt should really: +# +# (a) be in an include file and +# (b) should (at a minimum) be cpp friendly +# +# Meanwhile this helper script tries return something usable. +# + +if [ $# -ne 1 ]; then + echo "usage: $0 version.txt" 1>&2 + exit 1 +fi + +version="`cat $1`" || exit 1 + +case "${version}" in + +0*) + echo "${version}" + ;; + +*.*.*) + echo "${version}" | /usr/bin/sed -e 's/\.//g' + ;; + +*.*) + echo "${version}" | /usr/bin/awk '{ print 100 * $0 }' + ;; + +*) + echo "${version}" + ;; +esac Index: devel/arduino-bsd-mk/files/bsd.arduino.mk =================================================================== --- /dev/null +++ devel/arduino-bsd-mk/files/bsd.arduino.mk @@ -0,0 +1,428 @@ +# +# bsd.arduino.mk -- build Arduino sketches with make(1) +# +# +# Copyright (c) 2017 +# Craig Leres +# All rights reserved +# +# Author: Craig Leres +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# +++ variables +++ +# +# These must be set: +# +# TARGET Name of the sketch +# ARDUINO_BOARD Board name +# ARDUINO_MK_DIR Path to arduino-bsd-mk installation +# +# It's frequently useful to set these: +# +# SRCS List of .ino, .cpp and .c sources +# ARDUINO_LIBS List of Arduino libraries +# +# Programming options: +# +# boards.txt is parsed to populate the defaults for avrdude options +# Thse can be overiden in your Makefile or Makefile.inc +# +# AVRDUDE_PROGRAMMER avrdude programmer id string +# +# When the programmer is "arduino" AVRDUDE_PORT must using one of these: +# +# - In your shell environment before running "make flash" +# - With the make command line, e.g. "make flash AVRDUDE_PORT=/dev/ttyU3" +# - In Makefile.inc, e.g. "AVRDUDE_PORT=/dev/ttyU3" +# +# When the programmer is one that uses USB, AVRDUDE_PORT can +# optionally specify the usb port. See the -P option in the avrdude(1) +# man page for more details. +# +# AVRDUDE_PORT avrdude programmer port +# +# AVRDUDE_SPEED avrdude programmer serial speed (programmer: arduino) +# +# These can be set: +# +# ARDUINO_DIR Top level of arduino installation +# AVR_LIBC_DIR Top level of arv-libc installation +# +# F_CPU Speed of processor +# ARDUINO_CFLAGS Additional CFLAGS for sketch modules +# HFILES Includes files (used for tags) +# +# Debugging: +# +# WITH_CPPCHECK_XML Run cppcheck with XML output enabled +# WITH_CPPCHECK_CHECKCONFIG Run cppcheck with --check-config +# + +.if !defined(TARGET) +.error Please define TARGET +.endif + +.if !defined(ARDUINO_BOARD) +.error Please define ARDUINO_BOARD +.endif + +.if exists(${.CURDIR}/Makefile.inc) +.include "${.CURDIR}/Makefile.inc" +.endif + +PROG= ${TARGET}.elf + +all: ${TARGET}.hex + +.if !defined(SRCS) +SRCS= ${TARGET}.cpp +.endif + +# No man page by default +MAN?= + +PREFIX?= /usr/local +ARDUINO_PREFIX?= ${PREFIX} + +ARDUINO_DIR?= ${ARDUINO_PREFIX}/arduino +ARDUINO_LIBRARIES_DIR?= ${ARDUINO_DIR}/libraries + +ARDUINO_SRC_DIR?= ${ARDUINO_DIR}/hardware/arduino/cores/arduino +ARDUINO_VAR_DIR?= ${ARDUINO_DIR}/hardware/arduino/variants/${ARDUINO_VARIANT} + +AVR_LIBC_DIR?= ${PREFIX}/avr +AVR_PREFIX?= /usr/local + +LIBDIR?= ${AVR_LIBC_DIR}/lib + +CC= avr-gcc +CXX= avr-g++ +AR= avr-ar +OBJCOPY= avr-objcopy + +SIZE?= avr-size +AVRDUDE?= avrdude +CPPCHECK?= cppcheck +ARDUINO_BOARDS?= ${ARDUINO_MK_DIR}/scripts/arduino-boards + +INCLS?= -I. -I${.CURDIR} + +COPT?= -Os +CWFLAGS?= -fno-exceptions -ffunction-sections -fdata-sections +DEFS?= -DF_CPU=${F_CPU} -DARDUINO=${ARDUINO_VERSION} + +# +# Things we determine at run time +# +ARDUINO_VERSION?= ${:!${ARDUINO_MK_DIR}/scripts/arduino-version ${ARDUINO_DIR}/lib/version.txt!} + +ARDUINO_CORE?= ${:!${ARDUINO_BOARDS} ${ARDUINO_BOARD} build.core!} +ARDUINO_VARIANT?= ${:!${ARDUINO_BOARDS} ${ARDUINO_BOARD} build.variant!} +F_CPU?= ${:!${ARDUINO_BOARDS} ${ARDUINO_BOARD} build.f_cpu!} +MCU?= ${:!${ARDUINO_BOARDS} ${ARDUINO_BOARD} build.mcu!} + +USB_PID?= ${:!${ARDUINO_BOARDS} -e ${ARDUINO_BOARD} build.pid!} +.if !empty(USB_PID) +DEFS+= -DUSB_PID=${USB_PID} +.endif + +USB_VID?= ${:!${ARDUINO_BOARDS} -e ${ARDUINO_BOARD} build.vid!} +.if !empty(USB_VID) +DEFS+= -DUSB_VID=${USB_VID} +.endif + +GCC_VER= ${:!${ARDUINO_MK_DIR}/scripts/gcc-version!} + +CFLAGS= -mmcu=${MCU} -g -std=gnu99 ${COPT} ${CWFLAGS} ${DEFS} ${ARDUINO_CFLAGS} ${INCLS} + +LDFLAGS= -mmcu=${MCU} -Wl,--gc-sections ${COPT} + +# Build a library arduino modules +ARDUINO_LIB= libarduino.a + +.PATH: ${ARDUINO_SRC_DIR} +INCLS+= -I${ARDUINO_SRC_DIR} \ + -I${ARDUINO_VAR_DIR} + +LIB_SRCS= ${:!ls ${ARDUINO_SRC_DIR} | egrep '\.(c|cpp)\$' || true!:T} + +LIB_OBJS= ${LIB_SRCS:R:S/$/.o/g} +CLEANFILES+= ${LIB_OBJS} + +${TARGET}.elf: ${ARDUINO_LIB} + +LDADD+= ${ARDUINO_LIB} +CLEANFILES+= ${ARDUINO_LIB} + +# Add in the sources and directories for any Arduino libraries +.for _LIB in ${ARDUINO_LIBS} + +# Try local library first +.if exists(${.CURDIR}/${_LIB}) +.for _DN in ${.CURDIR}/${_LIB} +.PATH.cpp: ${_DN} +.PATH.c: ${_DN} +LIB_SRCS+= ${:!ls ${_DN} | egrep '\.(c|cpp)\$' || true!:T} +INCLS+= -I${_DN} + +# Add the utility subdirectory if it exists +.if exists(${_DN}/utility) +.PATH.cpp: ${_DN}/utility +.PATH.c: ${_DN}/utility +LIB_SRCS+= ${:!ls ${_DN}/utility | egrep '\.(c|cpp)\$' || true!:T} +INCLS+= -I${_DN}/utility +.endif +.endfor + +# Try arduino libraries version +.elif exists(${ARDUINO_LIBRARIES_DIR}/${_LIB}) +.for _DN in ${ARDUINO_LIBRARIES_DIR}/${_LIB} +.PATH.cpp: ${_DN} +.PATH.c: ${_DN} +LIB_SRCS+= ${:!ls ${_DN} | egrep '\.(c|cpp)\$' || true!:T} +INCLS+= -I${_DN} + +# Add the utility subdirectory if it exists +.if exists(${_DN}/utility) +.PATH.cpp: ${_DN}/utility +.PATH.c: ${_DN}/utility +LIB_SRCS+= ${:!ls ${_DN}/utility | egrep '\.(c|cpp)\$' || true!:T} +INCLS+= -I${_DN}/utility +.endif +.endfor + +.else +.error ${_LIB} doesn't exist +.endif + +.endfor + +# Build Arduino modules with -w (inhibit all warnings messages) +# Remove objs after building .a +${ARDUINO_LIB}: ${LIB_SRCS} + cd ${.CURDIR} && ${MAKE} CFLAGS="-w ${CFLAGS}" ${LIB_OBJS} + rm -f ${.TARGET} + ${AR} ${ARFLAGS} ${.TARGET} ${LIB_OBJS} + rm -f ${LIB_OBJS} + +# elf to hex transformation +.SUFFIXES: .elf .hex + +CLEANFILES+= ${TARGET}.hex + +.elf.hex: + ${OBJCOPY} -O ihex -R .eeprom ${.IMPSRC} ${.TARGET} + +# .ino cleanup +.SUFFIXES: .ino + +# Disallow .cpp when .ino exists +.for _INOSRC in ${SRCS:M*.ino:N*/*} +.for _CPPSRC in ${_INOSRC:R}.cpp +# cleanup +CLEANFILES+= ${.OBJDIR}/${_CPPSRC} +.if exists(${.CURDIR}/${_INOSRC}) && exists(${.CURDIR}/${_CPPSRC}) +.error Both ${_INOSRC} and ${_CPPSRC} exist +.endif +.endfor +.endfor + +# Disallow .ino when .cpp exists +.for _CPPSRC in ${SRCS:M*.cpp:N*/*} +.for _INOSRC in ${_CPPSRC:R}.ino +.if exists(${.CURDIR}/${_INOSRC}) && exists(${.CURDIR}/${_CPPSRC}) +.error Both ${_CPPSRC} and ${_INOSRC} exist +.endif +.endfor +.endfor + +# ino to cpp transformation +.ino.cpp: + ${ECHO} rm -f ${.IMPSRC:T:R}.cpp + ${ECHO} '#include ' > ${.IMPSRC:T:R}.cpp + ${ECHO} '#line 1 "${.IMPSRC:T:R}.ino"' >> ${.IMPSRC:T:R}.cpp + cat ${.IMPSRC} >> ${.IMPSRC:T:R}.cpp + +# +# assembler +# +.SUFFIXES: .s + +.cpp.s: + ${CXX} ${CXXFLAGS} -S ${.IMPSRC} -o ${.TARGET} + +# +# depend +# +MKDEPCMD= CC='${CXX} -mmcu=${MCU}' mkdep + +# +# tags +# +CTAGS= ctags +CTAGSFLAGS= -wtd + +tags: ${SRCS} ${HFILES} + @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \ + ${.ALLSRC:N*.tags} | sed "s;${.CURDIR}/;;" > ${.TARGET} + @test -h ${.CURDIR}/obj -a ! -h ${.CURDIR}/tags && \ + ln -s obj/tags ${.CURDIR}/tags || true + +# +# defines: dump out the board specifc ones +# +defines: + ${CC} -mmcu=${MCU} -dM -E - < /dev/null | sort + +# +# lint +# + +LINT_INCLS= \ + -I${PREFIX}/lib/gcc/avr/${GCC_VER}/include \ + -I${PREFIX}/lib/gcc/avr/${GCC_VER}/include-fixed \ + -I${AVR_LIBC_DIR}/include \ + ${INCLS} + +CPPCHECK_FLAGS= \ + -q \ + --enable=all \ + -Dlint \ + -DTCNT0=1 \ + -DF_CPU=${F_CPU} \ + -DARDUINO=${ARDUINO_VERSION} + +AVR_DEF?= __AVR_${MCU:tu:S/MEGA/mega/}__ +CPPCHECK_FLAGS+= -D${AVR_DEF}=1 + +.if defined(WITH_CPPCHECK_XML) +CPPCHECK_FLAGS+= --xml --xml-version=2 +.endif + +.if defined(WITH_CPPCHECK_CHECKCONFIG) +CPPCHECK_FLAGS+= --check-config +.endif + +# The scope of the variable '%s' can be reduced +CPPCHECK_FLAGS+= --suppress=variableScope + +# Noise reduction +CPPCHECK_FLAGS+= --suppress=noExplicitConstructor:${ARDUINO_SRC_DIR}/IPAddress.h +CPPCHECK_FLAGS+= --suppress=noExplicitConstructor:${ARDUINO_SRC_DIR}/WString.h +CPPCHECK_FLAGS+= --suppress=preprocessorErrorDirective:${ARDUINO_SRC_DIR}/WInterrupts.c +CPPCHECK_FLAGS+= --suppress=preprocessorErrorDirective:${ARDUINO_SRC_DIR}/wiring.c +CPPCHECK_FLAGS+= --suppress=uninitMemberVar:${ARDUINO_SRC_DIR}/HardwareSerial.cpp +CPPCHECK_FLAGS+= --suppress=uninitMemberVar:${ARDUINO_SRC_DIR}/Stream.h +CPPCHECK_FLAGS+= --suppress=unsignedLessThanZero:${ARDUINO_SRC_DIR}/WString.cpp +CPPCHECK_FLAGS+= --suppress=unusedFunction:${ARDUINO_SRC_DIR}/Stream.cpp +CPPCHECK_FLAGS+= --suppress=unusedFunction:${ARDUINO_SRC_DIR}/Tone.cpp +CPPCHECK_FLAGS+= --suppress=unusedFunction:${ARDUINO_SRC_DIR}/WMath.cpp +CPPCHECK_FLAGS+= --suppress=unusedFunction:${ARDUINO_SRC_DIR}/WString.cpp +CPPCHECK_FLAGS+= --suppress=unusedFunction:${ARDUINO_SRC_DIR}/main.cpp +CPPCHECK_FLAGS+= --suppress=unusedFunction:${ARDUINO_SRC_DIR}/new.cpp +CPPCHECK_FLAGS+= --suppress=unusedFunction:${ARDUINO_SRC_DIR}/wiring_analog.c +CPPCHECK_FLAGS+= --suppress=unusedFunction:${ARDUINO_SRC_DIR}/wiring_pulse.c +CPPCHECK_FLAGS+= --suppress=unusedFunction:${ARDUINO_SRC_DIR}/wiring_shift.c + +lint: ${SRCS} ${LIB_SRCS} +.for _INCL in ${LIT_INCLS} +.if !exists(${_INCL}) +.error ${_INCL} doesn't exist +.endfi +.endfor + cd ${.OBJDIR} && ${CPPCHECK} ${CPPCHECK_FLAGS} ${LINT_INCLS} ${.ALLSRC} + +# +# Programming +# +AVRDUDE_PROGRAMMER?= ${:!${ARDUINO_BOARDS} ${ARDUINO_BOARD} upload.protocol!} +.if ${AVRDUDE_PROGRAMMER} == "arduino" +AVRDUDE_SPEED?= ${:!${ARDUINO_BOARDS} ${ARDUINO_BOARD} upload.speed!} +.if !defined(AVRDUDE_PORT) +.error Please define AVRDUDE_PORT when ${AVRDUDE_PROGRAMMER} is "arduino" +.endif +AVRDUDE_FLAGS?= -b ${AVRDUDE_SPEED} -P ${AVRDUDE_PORT} +.else +.if defined(AVRDUDE_PORT) +AVRDUDE_FLAGS?= -P ${AVRDUDE_PORT} +.endif +.endif + +install flash: ${TARGET}.hex + ${AVRDUDE} \ + -V \ + -p ${MCU} \ + -c ${AVRDUDE_PROGRAMMER} \ + ${AVRDUDE_FLAGS} \ + -U flash:w:${.OBJDIR}/${TARGET}.hex:i + +# Report the fuse settings +report: + @${ECHO} ">> Using ${AVRDUDE} to query ${MCU} via ${AVRDUDE_PROGRAMMER}" + @${AVRDUDE} \ + -V \ + -p ${MCU} \ + -c ${AVRDUDE_PROGRAMMER} \ + -qq \ + -U lfuse:r:/dev/stdout:h \ + -U hfuse:r:/dev/stdout:h \ + -U efuse:r:/dev/stdout:h \ + -U lock:r:/dev/stdout:h | awk -v part="${MCU}" ' \ + BEGIN { \ + n = 1; \ + url = "http://eleccelerator.com/fusecalc/fusecalc.php"; \ + } \ + { \ + input[n] = $$0; \ + ++n; \ + } \ + END { \ + if (n < 4) { \ + printf "Missing output from avrdude (%d)\n", n; \ + exit 1; \ + } \ + i = 1; \ + lfuse = 0 + input[i++]; \ + hfuse = 0 + input[i++]; \ + efuse = 0 + input[i++]; \ + lock = 0 + input[i++]; \ + printf "lfuse: 0x%02X\n", lfuse; \ + printf "hfuse: 0x%02X\n", hfuse; \ + printf "efuse: 0x%02X\n", efuse; \ + printf " lock: 0x%02X\n", lock; \ + printf " url: %s?chip=%s&LOW=%x&HIGH=%x&EXTENDED=%x&LOCKBIT=%x\n", url, part, lfuse, hfuse, efuse, lock; \ + } \ + ' + +size: + ${SIZE} -B ${TARGET}.elf + +# Add these last +LDADD+= -lc -lm + +# XXX prevent ssp junk from kicking in +MACHINE_CPUARCH= arm +.include Index: devel/arduino-bsd-mk/files/bsd.arduino.mk.7.in =================================================================== --- /dev/null +++ devel/arduino-bsd-mk/files/bsd.arduino.mk.7.in @@ -0,0 +1,307 @@ +.\" +.\" Copyright (c) 2017 +.\" Craig Leres +.\" All rights reserved +.\" +.\" Author: Craig Leres +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.Dd November, 26 2017 +.Dt BSD.ARDUINO.MK 7 +.Os +.Sh NAME +.Nm bsd.arduino.mk +.Nd build Arduino sketches with +.Xr make 1 +.Sh SYNOPSIS +.Fd "ARDUINO_MK_DIR=%%PREFIX%%/arduino-bsd-mk" +.Fd ... +.Fd .include\ "${ARDUINO_MK_DIR}/bsd.arduino.mk" +.Sh DESCRIPTION +The file +.Pa bsd.arduino.mk +is used to build Arduino sketches from the command line using +.Xr make 1 . +The goal is to efficiently build potentially complicated projects +with simple Makefiles and completely bypass the Arduino graphical +user interface. +.Pp +Modules that are part of the standard Arduino distribution along with +modules that are part of referenced Arduino libraries (specified +with the +.Va ARDUINO_LIBS +variable) are compiled once and stored in a library. Sketch modules +are built as determined by +.Xr make 1 . +.Sh TARGETS +.Bl -tag -width 12345678 +.It defines +Dump out the defines specific to +.Va ARDUINO_BOARD . +.It flash +Compile, link and run +.Xr avrdude 1 +to program the target board. +.It install +An alias for flash. +.It lint +Run +.Xr cppcheck 1 +on all of the source files. +.It obj +Create a build directory. +.It objlink +Create a symlink to the build directory. +.It report +Use +.Xr avrdude 1 +to report the fuse settings. +.It size +Use +.Xr avr-size 1 +to list section sizes and total size. +.It tags +Create or update a tags file by running +.Xr ctags 1 +on +.Va SRCS +and +.Va HFILES . +.El +.Sh REQUIRED VARIABLES +These variables must be set: +.Bl -tag -width 12345678 +.It Va TARGET +The name of the sketch. If +.Va SRCS +is not defined then the sketch is built from +.Va ${TARGET}.cpp +or +.Va ${TARGET}.ino . +.It Va ARDUINO_BOARD +The name of the board. This is important as the +.Pa arduino-boards +script uses it to set the defaults for +.Va ARDUINO_CORE , +.Va ARDUINO_VARIANT , +.Va F_CPU +and +.Va MCU +from the Arduino +.Pa boards.txt +file. +.It Va ARDUINO_MK_DIR +The path to the arduino-bsd-mk installation directory. +.El +.Sh USEFUL VARIABLES +It's frequently useful to set these variables: +.Bl -tag -width 12345678 +.It Va SRCS +A list of .ino, .cpp and .c sources. This is used when +the name of the module does not match +.Va TARGET +and when more than one source is used. +.It Va ARDUINO_LIBS +A list of Arduino libraries. Since these are searched by first +looking in +.Va .CURDIR +and then in the Arduino tree +.Pa ( %%PREFIX%%/arduino/libraries ) +it's possible to use local libraries and to override standard Arduino +libraries. +.El +.Sh PROGRAMMING OPTIONS +.Bl -tag -width 12345678 +.It Va AVRDUDE_PORT +The +.Xr avrdude 1 +programmer port when the programmer is "arduino". +This is passed with the +.Fl P +flag. +.It Va AVRDUDE_PROGRAMMER +An +.Xr avrdude 1 +programmer id string. The default this is set using +.Pa boards.txt . +.Pp +When +.Va AVRDUDE_PROGRAMMER +is "arduino" +.Va AVRDUDE_PORT +must be set using one of these methods: +.Bl -bullet -offset indent -compact +.It +In your shell environment before running "make flash" +.It +With the make command line, e.g. "make flash \%AVRDUDE_PORT=/dev/ttyU3" +.It +In Makefile.inc, e.g. "AVRDUDE_PORT=/dev/ttyU3" +.El +.Pp +When +.Va AVRDUDE_PROGRAMMER +is one that uses USB, +.Va AVRDUDE_PORT +can optionally specify the usb port. See the +.Fl P +option in the +.Xr avrdude 1 +man page for more details. +.It Va AVRDUDE_SPEED +The +.Xr avrdude 1 +programmer speed when the programmer is "arduino". +This is passed with the +.Fl b +flag. +.El +.Sh PROCESSOR OPTIONS +These options for these variables default those found in the Arduino +.Pa boards.txt +file by the +.Pa arduino-boards +script for +.Va ARDUINO_BOARD . +.Bl -tag -width 12345678 +.It Va ARDUINO_CORE +This is the location of the core to link sketches against when compiling. +.It Va ARDUINO_VARIANT +This is the variant of +.VA ARDUINO_CORE . +.It Va F_CPU +The the clock speed at which the microcontroller operates at. This +is useful when under or overclocking. +.It Va MCU +The microcontroller on the board. +.El +.Sh OTHER OPTIONS +.Bl -tag -width 12345678 +.It Va ARDUINO_DIR +Top level of Arduino installation. This defaults to +.Pa %%PREFIX%%/arduino . +.It Va ARDUINO_CFLAGS +Additional compile C flags. +.It Va AVR_LIBC_DIR +Top level of the avr-libc installation. This defaults to +.Pa %%PREFIX%%/avr . +.It Va CPPCHECK_FLAGS +Additional +.Xr cppcheck 1 +flags to be used with "make lint" +.It Va HFILES +Specify include files that should also be processed by +.Xr ctags 1 +for "make tags". +.It Va WITH_CPPCHECK_XML +When set, "make lint" runs +.Xr cppcheck 1 +with XML output enabled using the +.Fl -xml +and +.Fl -xml-version=2 +flags. +.It Va WITH_CPPCHECK_CHECKCONFIG +When set, make lint" runs +.Xr cppcheck 1 +with the +.Fl -check-config +flag. +.El +.Sh NOTES +It's important to do a "make clean" if +.Va ARDUINO_BOARD +or any other +.Ic "PROCESSOR OPTIONS" +options are changed. +.Pp +To allow use of the +.Xr avr-gcc 1 +.Fl Werror +flag, standard and local Arduino library modules are compiled +using the +.Fl w +flag which inhibits warning messages. This makes it possible to add +the +.Fl Wall , +.Fl Werror +and +.Fl Wstrict-prototypes +flags to +.Va ARDUINO_CFLAGS +(which is recommended). +.Sh FILES +.Bl -tag -width 12345678 -compact +.It Pa %%PREFIX%%/arduino/hardware/arduino/boards.txt +The Arduino boards database. +.It Pa %%PREFIX%%/arduino/lib/version.txt +The Arduino version file. +.It Pa %%PREFIX%%/arduino/libraries +The location of standard Arduino libraries. +.It Pa %%PREFIX%%/arduino-bsd-mk +The default location of +.Pa bsd.arduino.mk +and the scripts directory. +.It Pa %%PREFIX%%/arduino-bsd-mk/scripts/arduino-boards +Script used to parse +.Pa boards.txt +to determine various hardware related options. +.It Pa %%PREFIX%%/arduino-bsd-mk/scripts/arduino-version +Script used to parse +.Pa version.txt +file. +.It Pa %%PREFIX%%/arduino-bsd-mk/scripts/gcc-version +Script used to determine the version of +.Xr avr-gcc 1 . +.It Pa %%PREFIX%%/avr +The default top level of the avr-libc installation. +.El +.Sh EXAMPLES +Here's a sample Makefile: +.Bd -literal -offset indent +TARGET= blink2 +ARDUINO_BOARD= atmega328 +ARDUINO_MK_DIR= %%PREFIX%%/arduino-bsd-mk +MAKEOBJDIRPREFIX=/usr/obj +ARDUINO_CFLAGS+= -Wall -Werror -Wstrict-prototypes +\&.include "${ARDUINO_MK_DIR}/bsd.arduino.mk" +.Ed +.Pp +There is one source named +.Pa blink2.ino +or +.Pa blink2.cpp . +The board is a atmega328. Additional compiler flags are specified. +.Sh SEE ALSO +.Xr avr-gcc 1 , +.Xr avrdude 1 , +.Xr make 1 +.Sh HISTORY +.Nm bsd.arduino.mk +was inspired by a +.Xr gmake 1 +makefile originally written by Martin Oldfield and described in his +blog titled, "Arduino from the command line." +.Sh AUTHORS +.An "Craig leres" Aq leres@FreeBSD.org Index: devel/arduino-bsd-mk/files/examples/blink2/Makefile =================================================================== --- /dev/null +++ devel/arduino-bsd-mk/files/examples/blink2/Makefile @@ -0,0 +1,13 @@ +# $FreeBSD$ + +TARGET= blink2 + +ARDUINO_BOARD= atmega328 + +ARDUINO_MK_DIR= /usr/local/arduino-bsd-mk + +MAKEOBJDIRPREFIX=/usr/obj + +ARDUINO_CFLAGS+= -Wall -Werror -Wstrict-prototypes + +.include "${ARDUINO_MK_DIR}/bsd.arduino.mk" Index: devel/arduino-bsd-mk/files/examples/blink2/blink2.ino =================================================================== --- /dev/null +++ devel/arduino-bsd-mk/files/examples/blink2/blink2.ino @@ -0,0 +1,39 @@ +/* @(#) $Id: blink2.ino 34 2017-03-19 17:51:19Z leres $ (XSE) */ + +/* + * This is a example sketch that blinks the LED like a heartbeat + */ + +#ifndef PIN_LED_OUT +#define PIN_LED_OUT LED_BUILTIN +#endif + +#ifndef LED_ON +#define LED_ON HIGH +#endif + +#ifndef LED_OFF +#define LED_OFF LOW +#endif + +void +setup() +{ + pinMode(PIN_LED_OUT, OUTPUT); +} + +void +loop() +{ + digitalWrite(PIN_LED_OUT, LED_ON); + delay(25); + + digitalWrite(PIN_LED_OUT, LED_OFF); + delay(50); + + digitalWrite(PIN_LED_OUT, LED_ON); + delay(25); + + digitalWrite(PIN_LED_OUT, LED_OFF); + delay(900); +} Index: devel/arduino-bsd-mk/files/gcc-version.sh =================================================================== --- /dev/null +++ devel/arduino-bsd-mk/files/gcc-version.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# $FreeBSD$ +# +# Report avr-gcc version +# + +prog="`basename $0`" + +PATH=/usr/local/bin:${PATH} +export PATH + +gcc=avr-gcc +if [ $# -gt 0 ]; then + gcc="$1" + shift +fi + +if [ $# -ne 0 ]; then + echo "usage: ${prog} [gcc]" 1>&2 + exit 1 +fi + +${gcc} --version | fmt -1 | egrep '^[0-9]+\.[0-9]+\.[0-9]+$' +if [ $? -ne 0 ]; then + echo "${prog}: Can't determine version for ${gcc}" 1>&2 + exit 1 +fi +exit 0 Index: devel/arduino-bsd-mk/pkg-descr =================================================================== --- /dev/null +++ devel/arduino-bsd-mk/pkg-descr @@ -0,0 +1,8 @@ +Arduino from the command line on FreeBSD + +This is a makefile written by Craig Leres that makes it possible +to build Arduino sketches with FreeBSD make from the command line. +It includes an example sketch and Makefile which is optionally +installed in share/examples/arduino-bsd-mk + +WWW: https://xse.com/leres/software/arduino/arduino-bsd-mk.html