From 7b74e100ced3b269c1ff027a9d2212ab90a1ff55 Mon Sep 17 00:00:00 2001 From: Lukasz Engel Date: Sat, 11 Oct 2014 23:14:32 +0200 Subject: [PATCH 1/4] Arduino 1.5.x - support new library layout and plaform specific system libs - Add support for 1.5.x library layout. (https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification) - Allow using Arduino 1.5.x platform specific system libraries. Arduino 1.5.x has additional directories for platform (vendor/architecture) specific libraries - look there when searching for libraries. --- Arduino.mk | 118 +++++++++++++++++++++++++++++++++++++-------- arduino-mk-vars.md | 17 +++++++ 2 files changed, 115 insertions(+), 20 deletions(-) diff --git a/Arduino.mk b/Arduino.mk index c1981d0..c7198a4 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -317,6 +317,7 @@ ifndef ARCHITECTURE ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1) # default to avr for 1.5 ARCHITECTURE = avr + ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR else # unset for 1.0 ARCHITECTURE = @@ -324,6 +325,17 @@ ifndef ARCHITECTURE $(call show_config_variable,ARCHITECTURE,[DEFAULT]) else $(call show_config_variable,ARCHITECTURE,[USER]) + + #avoid using shell for known architectures + ifeq ($(ARCHITECTURE),avr) + ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR + else + ifeq ($(ARCHITECTURE),sam) + ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_SAM + else + ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_$(shell echo $(ARCHITECTURE) | tr '[:lower:]' '[:upper:]') + endif + endif endif ######################################################################## @@ -467,6 +479,17 @@ else $(call show_config_variable,ARDUINO_CORE_PATH,[USER]) endif +# 1.5.x platform dependent libs path +ifndef ARDUINO_PLATFORM_LIB_PATH + ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1) + # only for 1.5 + ARDUINO_PLATFORM_LIB_PATH = $(ARDUINO_DIR)/hardware/$(VENDOR)/$(ARCHITECTURE)/libraries + endif + $(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[COMPUTED],(from ARDUINO_DIR)) +else + $(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[USER]) +endif + # Third party hardware and core like ATtiny or ATmega 16 ifdef ALTERNATE_CORE $(call show_config_variable,ALTERNATE_CORE,[USER]) @@ -847,6 +870,30 @@ CAT = cat ECHO = printf MKDIR = mkdir -p +# recursive wildcard function, call with params: +# - start directory (finished with /) or empty string for current dir +# - glob pattern +# (taken from http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html) +rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) + +# functions used to determine various properties of library +# called with library path. Needed because of differences between library +# layouts in arduino 1.0.x and 1.5.x. +# Assuming new 1.5.x layout when there is "src" subdirectory in main directory +# and library.properties file + +# Gets include flags for library +get_library_includes = $(if $(and $(wildcard $(1)/src), $(wildcard $(1)/library.properties)), \ + -I$(1)/src, \ + $(addprefix -I,$(1) $(wildcard $(1)/utility))) + +# Gets all sources with given extension (param2) for library (path = param1) +# for old (1.0.x) layout looks in . and "utility" directories +# for new (1.5.x) layout looks in src and recursively its subdirectories +get_library_files = $(if $(and $(wildcard $(1)/src), $(wildcard $(1)/library.properties)), \ + $(call rwildcard,$(1)/src/,*.$(2)), \ + $(wildcard $(1)/*.$(2) $(1)/utility/*.$(2))) + # General arguments USER_LIBS = $(wildcard $(patsubst %,$(USER_LIB_PATH)/%,$(ARDUINO_LIBS))) USER_LIB_NAMES = $(patsubst $(USER_LIB_PATH)/%,%,$(USER_LIBS)) @@ -855,22 +902,30 @@ USER_LIB_NAMES = $(patsubst $(USER_LIB_PATH)/%,%,$(USER_LIBS)) SYS_LIBS = $(wildcard $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(filter-out $(USER_LIB_NAMES),$(ARDUINO_LIBS)))) SYS_LIB_NAMES = $(patsubst $(ARDUINO_LIB_PATH)/%,%,$(SYS_LIBS)) -# Error here if any are missing. -LIBS_NOT_FOUND = $(filter-out $(USER_LIB_NAMES) $(SYS_LIB_NAMES),$(ARDUINO_LIBS)) -ifneq (,$(strip $(LIBS_NOT_FOUND))) - $(error The following libraries specified in ARDUINO_LIBS could not be found (searched USER_LIB_PATH and ARDUINO_LIB_PATH): $(LIBS_NOT_FOUND)) +ifdef ARDUINO_PLATFORM_LIB_PATH + PLATFORM_LIBS = $(wildcard $(patsubst %,$(ARDUINO_PLATFORM_LIB_PATH)/%,$(filter-out $(USER_LIB_NAMES),$(ARDUINO_LIBS)))) + PLATFORM_LIB_NAMES = $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%,%,$(PLATFORM_LIBS)) endif -SYS_LIBS := $(wildcard $(SYS_LIBS) $(addsuffix /utility,$(SYS_LIBS))) -USER_LIBS := $(wildcard $(USER_LIBS) $(addsuffix /utility,$(USER_LIBS))) -SYS_INCLUDES = $(patsubst %,-I%,$(SYS_LIBS)) -USER_INCLUDES = $(patsubst %,-I%,$(USER_LIBS)) -LIB_C_SRCS = $(wildcard $(patsubst %,%/*.c,$(SYS_LIBS))) -LIB_CPP_SRCS = $(wildcard $(patsubst %,%/*.cpp,$(SYS_LIBS))) -LIB_AS_SRCS = $(wildcard $(patsubst %,%/*.S,$(SYS_LIBS))) -USER_LIB_CPP_SRCS = $(wildcard $(patsubst %,%/*.cpp,$(USER_LIBS))) -USER_LIB_C_SRCS = $(wildcard $(patsubst %,%/*.c,$(USER_LIBS))) -USER_LIB_AS_SRCS = $(wildcard $(patsubst %,%/*.S,$(USER_LIBS))) + +# Error here if any are missing. +LIBS_NOT_FOUND = $(filter-out $(USER_LIB_NAMES) $(SYS_LIB_NAMES) $(PLATFORM_LIB_NAMES),$(ARDUINO_LIBS)) +ifneq (,$(strip $(LIBS_NOT_FOUND))) + ifdef ARDUINO_PLATFORM_LIB_PATH + $(error The following libraries specified in ARDUINO_LIBS could not be found (searched USER_LIB_PATH, ARDUINO_LIB_PATH and ARDUINO_PLATFORM_LIB_PATH): $(LIBS_NOT_FOUND)) + else + $(error The following libraries specified in ARDUINO_LIBS could not be found (searched USER_LIB_PATH and ARDUINO_LIB_PATH): $(LIBS_NOT_FOUND)) + endif +endif + +SYS_INCLUDES = $(foreach lib, $(SYS_LIBS), $(call get_library_includes,$(lib))) +USER_INCLUDES = $(foreach lib, $(USER_LIBS), $(call get_library_includes,$(lib))) +LIB_C_SRCS = $(foreach lib, $(SYS_LIBS), $(call get_library_files,$(lib),c)) +LIB_CPP_SRCS = $(foreach lib, $(SYS_LIBS), $(call get_library_files,$(lib),cpp)) +LIB_AS_SRCS = $(foreach lib, $(SYS_LIBS), $(call get_library_files,$(lib),S)) +USER_LIB_CPP_SRCS = $(foreach lib, $(USER_LIBS), $(call get_library_files,$(lib),cpp)) +USER_LIB_C_SRCS = $(foreach lib, $(USER_LIBS), $(call get_library_files,$(lib),c)) +USER_LIB_AS_SRCS = $(foreach lib, $(USER_LIBS), $(call get_library_files,$(lib),S)) LIB_OBJS = $(patsubst $(ARDUINO_LIB_PATH)/%.c,$(OBJDIR)/libs/%.o,$(LIB_C_SRCS)) \ $(patsubst $(ARDUINO_LIB_PATH)/%.cpp,$(OBJDIR)/libs/%.o,$(LIB_CPP_SRCS)) \ $(patsubst $(ARDUINO_LIB_PATH)/%.S,$(OBJDIR)/libs/%.o,$(LIB_AS_SRCS)) @@ -878,8 +933,19 @@ USER_LIB_OBJS = $(patsubst $(USER_LIB_PATH)/%.cpp,$(OBJDIR)/userlibs/%.o,$ $(patsubst $(USER_LIB_PATH)/%.c,$(OBJDIR)/userlibs/%.o,$(USER_LIB_C_SRCS)) \ $(patsubst $(USER_LIB_PATH)/%.S,$(OBJDIR)/userlibs/%.o,$(USER_LIB_AS_SRCS)) +ifdef ARDUINO_PLATFORM_LIB_PATH + PLATFORM_INCLUDES = $(foreach lib, $(PLATFORM_LIBS), $(call get_library_includes,$(lib))) + PLATFORM_LIB_CPP_SRCS = $(foreach lib, $(PLATFORM_LIBS), $(call get_library_files,$(lib),cpp)) + PLATFORM_LIB_C_SRCS = $(foreach lib, $(PLATFORM_LIBS), $(call get_library_files,$(lib),c)) + PLATFORM_LIB_AS_SRCS = $(foreach lib, $(PLATFORM_LIBS), $(call get_library_files,$(lib),S)) + PLATFORM_LIB_OBJS = $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%.cpp,$(OBJDIR)/platformlibs/%.o,$(PLATFORM_LIB_CPP_SRCS)) \ + $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%.c,$(OBJDIR)/platformlibs/%.o,$(PLATFORM_LIB_C_SRCS)) \ + $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%.S,$(OBJDIR)/platformlibs/%.o,$(PLATFORM_LIB_AS_SRCS)) + +endif + # Dependency files -DEPS = $(LOCAL_OBJS:.o=.d) $(LIB_OBJS:.o=.d) $(USER_LIB_OBJS:.o=.d) $(CORE_OBJS:.o=.d) +DEPS = $(LOCAL_OBJS:.o=.d) $(LIB_OBJS:.o=.d) $(PLATFORM_OBJS:.o=.d) $(USER_LIB_OBJS:.o=.d) $(CORE_OBJS:.o=.d) # Optimization level for the compiler. # You can get the list of options at http://www.nongnu.org/avr-libc/user-manual/using_tools.html#gcc_optO @@ -906,9 +972,9 @@ else endif # Using += instead of =, so that CPPFLAGS can be set per sketch level -CPPFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERSION) -D__PROG_TYPES_COMPAT__ \ +CPPFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERSION) $(ARDUINO_ARCH_FLAG) -D__PROG_TYPES_COMPAT__ \ -I. -I$(ARDUINO_CORE_PATH) -I$(ARDUINO_VAR_PATH)/$(VARIANT) \ - $(SYS_INCLUDES) $(USER_INCLUDES) -Wall -ffunction-sections \ + $(SYS_INCLUDES) $(PLATFORM_INCLUDES) $(USER_INCLUDES) -Wall -ffunction-sections \ -fdata-sections ifdef DEBUG @@ -998,7 +1064,7 @@ ifneq (,$(strip $(USER_LIB_NAMES))) $(foreach lib,$(USER_LIB_NAMES),$(call show_config_info, $(lib),[USER])) endif -ifneq (,$(strip $(SYS_LIB_NAMES))) +ifneq (,$(strip $(SYS_LIB_NAMES) $(PLATFORM_LIB_NAMES))) $(foreach lib,$(SYS_LIB_NAMES),$(call show_config_info, $(lib),[SYSTEM])) endif @@ -1034,6 +1100,18 @@ $(OBJDIR)/libs/%.o: $(ARDUINO_LIB_PATH)/%.S @$(MKDIR) $(dir $@) $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@ +$(OBJDIR)/platformlibs/%.o: $(ARDUINO_PLATFORM_LIB_PATH)/%.c + @$(MKDIR) $(dir $@) + $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + +$(OBJDIR)/platformlibs/%.o: $(ARDUINO_PLATFORM_LIB_PATH)/%.cpp + @$(MKDIR) $(dir $@) + $(CC) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ + +$(OBJDIR)/platformlibs/%.o: $(ARDUINO_PLATFORM_LIB_PATH)/%.S + @$(MKDIR) $(dir $@) + $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@ + $(OBJDIR)/userlibs/%.o: $(USER_LIB_PATH)/%.cpp @$(MKDIR) $(dir $@) $(CC) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ @@ -1263,8 +1341,8 @@ pre-build: $(TARGET_ELF): $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) $(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) -lc -lm -$(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(USER_LIB_OBJS) - $(AR) rcs $@ $(CORE_OBJS) $(LIB_OBJS) $(USER_LIB_OBJS) +$(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(USER_LIB_OBJS) + $(AR) rcs $@ $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(USER_LIB_OBJS) error_on_caterina: $(ERROR_ON_CATERINA) diff --git a/arduino-mk-vars.md b/arduino-mk-vars.md index 1e8de64..f6f001b 100644 --- a/arduino-mk-vars.md +++ b/arduino-mk-vars.md @@ -111,6 +111,23 @@ ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java ---- +### ARDUINO_PLATFORM_LIB_PATH + +**Description:** + +Directory where the Arduino platform dependent libraries are stored. +(Used only for Arduino 1.5.x) + +**Example:** + +```Makefile +ARDUINO_PLATFORM_LIB_PATH = /usr/share/arduino/hardware/arduino/avr/libraries +``` + +**Requirement:** *Optional* + +---- + ### ARDUINO_VERSION **Description:** From 58c94f3d1144010a4e6d28ef792ae3d76a3d93ff Mon Sep 17 00:00:00 2001 From: Lukasz Engel Date: Sun, 12 Oct 2014 16:48:54 +0200 Subject: [PATCH 2/4] Add changelog entry for #275 and #276 --- HISTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 3717bea..732ac63 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,8 @@ The following is the rough list of changes that went into different versions. I tried to give credit whenever possible. If I have missed anyone, kindly add it to the list. ### In development +- New: Add support for new 1.5.x library layout (Issue #275) (https://github.com/lukasz-e) +- New: Add support for 1.5.x vendor/hardware architecture library location (Issue #276) (https://github.com/lukasz-e) - New: Added test suite and integration with travis CI. (https://github.com/peplin) - New: Add information about `Bare-Arduino–Project` in README. (https://github.com/ladislas) - New: Add information about reporting bugs to the correct project (Issue #231). (https://github.com/sej7278) From c7219a12b955723facb1902d7412afe15bb1accf Mon Sep 17 00:00:00 2001 From: Lukasz Engel Date: Sun, 12 Oct 2014 19:32:55 +0200 Subject: [PATCH 3/4] remove unwanted TABs --- Arduino.mk | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Arduino.mk b/Arduino.mk index c7198a4..7641847 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -315,13 +315,13 @@ endif # 1.5.x architecture - avr or sam for arduino vendor ifndef ARCHITECTURE ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1) - # default to avr for 1.5 - ARCHITECTURE = avr + # default to avr for 1.5 + ARCHITECTURE = avr ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR - else - # unset for 1.0 - ARCHITECTURE = - endif + else + # unset for 1.0 + ARCHITECTURE = + endif $(call show_config_variable,ARCHITECTURE,[DEFAULT]) else $(call show_config_variable,ARCHITECTURE,[USER]) @@ -482,9 +482,9 @@ endif # 1.5.x platform dependent libs path ifndef ARDUINO_PLATFORM_LIB_PATH ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1) - # only for 1.5 - ARDUINO_PLATFORM_LIB_PATH = $(ARDUINO_DIR)/hardware/$(VENDOR)/$(ARCHITECTURE)/libraries - endif + # only for 1.5 + ARDUINO_PLATFORM_LIB_PATH = $(ARDUINO_DIR)/hardware/$(VENDOR)/$(ARCHITECTURE)/libraries + endif $(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[COMPUTED],(from ARDUINO_DIR)) else $(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[USER]) From 922a8d59bd96e2d5163d9b20b8c1d6638d3ee55c Mon Sep 17 00:00:00 2001 From: Lukasz Engel Date: Mon, 13 Oct 2014 21:36:29 +0200 Subject: [PATCH 4/4] do not print default (empty) ARDUINO_PLATFORM_LIB_PATH value for arduino 1.0.x --- Arduino.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Arduino.mk b/Arduino.mk index 7641847..116d1a2 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -484,8 +484,8 @@ ifndef ARDUINO_PLATFORM_LIB_PATH ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1) # only for 1.5 ARDUINO_PLATFORM_LIB_PATH = $(ARDUINO_DIR)/hardware/$(VENDOR)/$(ARCHITECTURE)/libraries + $(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[COMPUTED],(from ARDUINO_DIR)) endif - $(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[COMPUTED],(from ARDUINO_DIR)) else $(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[USER]) endif