aboutsummaryrefslogtreecommitdiff
path: root/Arduino.mk
diff options
context:
space:
mode:
authorLukasz Engel <lukasz-e.github@lengel.pl>2014-10-11 23:14:32 +0200
committerLukasz Engel <lukasz-e.github@lengel.pl>2014-10-11 23:56:02 +0200
commit7b74e100ced3b269c1ff027a9d2212ab90a1ff55 (patch)
tree8b3e5dfbf6ad6563827862dd86c9991bf07de8c8 /Arduino.mk
parent6f46722abb40c60dcaa0e40292342d015906c8bf (diff)
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.
Diffstat (limited to 'Arduino.mk')
-rw-r--r--Arduino.mk118
1 files changed, 98 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))
+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
+
+
# Error here if any are missing.
-LIBS_NOT_FOUND = $(filter-out $(USER_LIB_NAMES) $(SYS_LIB_NAMES),$(ARDUINO_LIBS))
+LIBS_NOT_FOUND = $(filter-out $(USER_LIB_NAMES) $(SYS_LIB_NAMES) $(PLATFORM_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))
-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)))
+ 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)