sys/arduino/sketches: build sketches as a module
Generate a module for arduino sketches in a subfolder of BINDIR. This prevents issues when doing concurrent builds or out of tree build with readonly sources. Declare all generated files as `BUILDDEPS` to be re-created after `clean` on parrallel `clean all`.
This commit is contained in:
parent
700b121936
commit
be30f072e2
24
dist/tools/arduino/pre_build.sh
vendored
24
dist/tools/arduino/pre_build.sh
vendored
@ -1,24 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# check if at least the application dir and one sketch is given
|
|
||||||
if [ $# -lt 2 ]
|
|
||||||
then
|
|
||||||
echo "[Arduino pre-build] Error: not enough arguments given"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 'consume' the application and arduino directories (first argument)
|
|
||||||
SRCDIR=$1
|
|
||||||
shift
|
|
||||||
APPDIR=$1
|
|
||||||
shift
|
|
||||||
|
|
||||||
# create temporary file and put in the file header
|
|
||||||
cat ${SRCDIR}/pre.snip > ${APPDIR}/_sketches.cpp
|
|
||||||
# loop through the given sketches and include them into the temp file
|
|
||||||
for sketch in $@
|
|
||||||
do
|
|
||||||
cat ${sketch} >> ${APPDIR}/_sketches.cpp
|
|
||||||
done
|
|
||||||
# and prepend the file with the arduino bootstrapping code
|
|
||||||
cat ${SRCDIR}/post.snip >> ${APPDIR}/_sketches.cpp
|
|
||||||
@ -1,9 +1,15 @@
|
|||||||
# compile together the Arduino sketches of the application
|
# Add Arduino sketches to the application as a module
|
||||||
SKETCHES = $(wildcard $(APPDIR)/*.sketch)
|
|
||||||
SRCDIR = $(RIOTBASE)/sys/arduino
|
|
||||||
|
|
||||||
# run the Arduino pre-build script
|
# Define application sketches module, it will be generated into $(BINDIR)
|
||||||
$(shell $(RIOTTOOLS)/arduino/pre_build.sh $(SRCDIR) $(APPDIR) $(SKETCHES))
|
SKETCH_MODULE ?= arduino_sketches
|
||||||
|
SKETCH_MODULE_DIR ?= $(BINDIR)/$(SKETCH_MODULE)
|
||||||
|
SKETCHES = $(wildcard $(APPDIR)/*.sketch)
|
||||||
|
include $(RIOTBASE)/sys/arduino/sketches.inc.mk
|
||||||
|
|
||||||
|
# Depends on module
|
||||||
|
USEMODULE += $(SKETCH_MODULE)
|
||||||
|
DIRS += $(SKETCH_MODULE_DIR)
|
||||||
|
BUILDDEPS += $(SKETCH_GENERATED_FILES)
|
||||||
|
|
||||||
# include the Arduino headers
|
# include the Arduino headers
|
||||||
INCLUDES += -I$(RIOTBASE)/sys/arduino/include
|
INCLUDES += -I$(RIOTBASE)/sys/arduino/include
|
||||||
|
|||||||
@ -56,24 +56,28 @@
|
|||||||
*
|
*
|
||||||
* @subsection sec_concept_build Extension of the build system
|
* @subsection sec_concept_build Extension of the build system
|
||||||
*
|
*
|
||||||
* Building Arduino sketches in RIOT is done in a two step process.
|
* Building Arduino sketches in RIOT is done in a three step process.
|
||||||
*
|
*
|
||||||
* First, the make system calls a dedicated
|
* First, the make system defines a generated `arduino_sketches` module placed
|
||||||
* [Arduino build script](https://github.com/RIOT-OS/RIOT/tree/master/dist/tools/arduino/pre_build.sh),
|
* into `$(BINDIR)`
|
||||||
* which is called from the
|
* [Arduino sketches makefile](https://github.com/RIOT-OS/RIOT/tree/master/sys/arduino/sketches.inc.mk),
|
||||||
|
* which is included from the
|
||||||
* [Makefile.include](https://github.com/RIOT-OS/RIOT/tree/master/sys/arduino/Makefile.include)
|
* [Makefile.include](https://github.com/RIOT-OS/RIOT/tree/master/sys/arduino/Makefile.include)
|
||||||
* of the RIOT Arduino module.
|
* of the RIOT Arduino module.
|
||||||
|
* The generated module is added to used modules and build directories.
|
||||||
*
|
*
|
||||||
* This script creates a temporary file called '_sketches.cpp' inside the
|
* Second, as prerequisites for the `link` target, the make system will create
|
||||||
* application folder. Into this file, the script copies some Arduino glue code (
|
* the module into `$(BINDIR)/arduino_sketches` with an `arduino_sketches.cpp`
|
||||||
|
* source file.
|
||||||
|
* Into this file, it copies some Arduino glue code (
|
||||||
* [pre.snip](https://github.com/RIOT-OS/RIOT/blob/master/sys/arduino/pre.snip)
|
* [pre.snip](https://github.com/RIOT-OS/RIOT/blob/master/sys/arduino/pre.snip)
|
||||||
* and
|
* and
|
||||||
* [post.snip](https://github.com/RIOT-OS/RIOT/blob/master/sys/arduino/post.snip))
|
* [post.snip](https://github.com/RIOT-OS/RIOT/blob/master/sys/arduino/post.snip))
|
||||||
* together with the contents of all `*.sketch` files contained in the
|
* together with the contents of all `*.sketch` files contained in the
|
||||||
* application folder.
|
* application folder.
|
||||||
*
|
*
|
||||||
* Second, the RIOT make system is called as usual, processing the temporary
|
* Third, the RIOT make system is called as usual, building the generated
|
||||||
* file containing all the Arduino code. Simple :-)
|
* library with the Arduino code and including it in the final firmware.
|
||||||
*
|
*
|
||||||
* @subsection sec_conecpt_api Implementation of the Arduino API
|
* @subsection sec_conecpt_api Implementation of the Arduino API
|
||||||
*
|
*
|
||||||
|
|||||||
34
sys/arduino/sketches.inc.mk
Normal file
34
sys/arduino/sketches.inc.mk
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Compile together the Arduino sketches of the application
|
||||||
|
# They are declared a as new module $(SKETCH_MODULE) in $(SKETCH_MODULE_DIR)
|
||||||
|
|
||||||
|
ifndef SKETCH_MODULE
|
||||||
|
$(error SKETCH_MODULE undefined. It should be defined to the sketches module name)
|
||||||
|
endif
|
||||||
|
ifndef SKETCH_MODULE_DIR
|
||||||
|
$(error SKETCH_MODULE_DIR undefined. It should be defined to the sketches module directory)
|
||||||
|
endif
|
||||||
|
ifndef SKETCHES
|
||||||
|
$(error SKETCHES undefined. It should be defined to the list of sketches files)
|
||||||
|
endif
|
||||||
|
|
||||||
|
SNIPDIR = $(RIOTBASE)/sys/arduino
|
||||||
|
SKETCHES_ALL = $(SNIPDIR)/pre.snip $(SKETCHES) $(SNIPDIR)/post.snip
|
||||||
|
SKETCH_CPP ?= arduino_sketches.cpp
|
||||||
|
SKETCH_GENERATED_FILES = $(SKETCH_MODULE_DIR)/Makefile $(SKETCH_MODULE_DIR)/$(SKETCH_CPP)
|
||||||
|
|
||||||
|
# Building the module files
|
||||||
|
# Do not use $^ in receipes as Makefile is also a prerequisite
|
||||||
|
$(SKETCH_MODULE_DIR)/Makefile: $(SKETCH_MODULE_DIR)/$(SKETCH_CPP)
|
||||||
|
$(Q)echo 'SRCXX = $(SKETCH_CPP)' > $@
|
||||||
|
$(Q)echo 'include $$(RIOTBASE)/Makefile.base' >> $@
|
||||||
|
$(SKETCH_MODULE_DIR)/$(SKETCH_CPP): $(SKETCHES_ALL)
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
$(Q)cat $(SKETCHES_ALL) > $@
|
||||||
|
|
||||||
|
# Make everything rebuild if current makefile changes
|
||||||
|
_ARDUINO_SKETCHES_MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
||||||
|
$(SKETCH_MODULE_DIR)/$(SKETCH_CPP): $(_ARDUINO_SKETCHES_MAKEFILE)
|
||||||
|
$(SKETCH_MODULE_DIR)/Makefile: $(_ARDUINO_SKETCHES_MAKEFILE)
|
||||||
|
|
||||||
|
# HACK Rebuild cpp files everytime in case one of the `SKETCHES` is deleted
|
||||||
|
$(SKETCH_MODULE_DIR)/$(SKETCH_CPP): FORCE
|
||||||
Loading…
x
Reference in New Issue
Block a user