Skip to content

Commit

Permalink
arduino/sketches: build sketches as a module
Browse files Browse the repository at this point in the history
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.

This fixes RIOT-OS#5848
  • Loading branch information
cladmi committed Sep 28, 2017
1 parent 2097f68 commit 9a3518e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
24 changes: 0 additions & 24 deletions dist/tools/arduino/pre_build.sh

This file was deleted.

38 changes: 38 additions & 0 deletions sys/arduino/Makefile.arduino_sketches.ink
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Compile together the Arduino sketches of the application
# They are declared a as new module $(SKETCH_MODULE) in $(SKETCH_MOD_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

# Add dependency to create the sketches module
# Use `link` target to execute it before application makefile
link: ..sketches_module

.PHONY: ..sketches_module
..sketches_module: $(SKETCH_MODULE_DIR)/$(SKETCH_CPP) $(SKETCH_MODULE_DIR)/Makefile

# Building the module files
$(SKETCH_MODULE_DIR)/$(SKETCH_CPP): $(SKETCHES_ALL) | $(SKETCH_MODULE_DIR)
@# Do not use $^ as Makefile is also a prerequisite
$(Q)cat $(SKETCHES_ALL) > $@
$(SKETCH_MODULE_DIR)/Makefile: | $(SKETCH_MODULE_DIR)
$(Q)echo 'SRCXX = $(SKETCH_CPP)' > $@
$(Q)echo 'include $$(RIOTBASE)/Makefile.base' >> $@
$(SKETCH_MODULE_DIR):
@mkdir -p $@

# Make everything rebuild if current makefile changes
CURMK = $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(SKETCH_MODULE_DIR)/$(SKETCH_CPP): $(CURMK)
$(SKETCH_MODULE_DIR)/Makefile: $(CURMK)
15 changes: 10 additions & 5 deletions sys/arduino/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# compile together the Arduino sketches of the application
SKETCHES = $(wildcard $(APPDIR)/*.sketch)
SRCDIR = $(RIOTBASE)/sys/arduino
# Add Arduino sketches to the application as a module

# run the Arduino pre-build script
$(shell $(RIOTBASE)/dist/tools/arduino/pre_build.sh $(SRCDIR) $(APPDIR) $(SKETCHES))
# Create sketches module
SKETCH_MODULE ?= arduino_sketches
SKETCH_MOD_DIR ?= $(BINDIR)/$(SKETCH_MODULE)
SKETCHES = $(wildcard $(APPDIR)/*.sketch)
include $(RIOTBASE)/sys/arduino/Makefile.arduino_sketches.ink

# Depends on module
USEMODULE += $(SKETCH_MODULE)
DIRS += $(SKETCH_MODULE_DIR)

# include the Arduino headers
INCLUDES += -I$(RIOTBASE)/sys/arduino/include

0 comments on commit 9a3518e

Please sign in to comment.