From f930c1780170f53f81bfe42095c8c161a5802cfc Mon Sep 17 00:00:00 2001 From: ladislas Date: Tue, 19 Aug 2014 00:02:38 +0200 Subject: [PATCH] Add automatic lib detection with python script, enhance lib listing output when compiling --- Arduino.mk | 40 +++++++++++++++++++++++++++++++++------- bin/auto-lib.py | 22 +++++++--------------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Arduino.mk b/Arduino.mk index 60bec1c..e48f097 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -736,7 +736,7 @@ ifeq ($(strip $(CHK_SOURCES)),) $(call show_config_info,No .pde or .ino files found. If you are compiling .c or .cpp files then you need to explicitly include Arduino header files) else #TODO: Support more than one file. https://github.com/sudar/Arduino-Makefile/issues/49 - $(error Need exactly one .pde or .ino file. This makefile doesn't support multiple .ino/.pde files yet) + $(error Need exactly one .pde or .ino file. This makefile doesn\'t support multiple .ino/.pde files yet) endif endif @@ -763,6 +763,19 @@ else $(call show_config_info,NO_CORE set so core library will not be built,[MANUAL]) endif +######################################################################## +# Automatically find the libraries needed to compile the sketch + +ifndef MAIN_LIBS + MAIN_LIBS = $(shell $(ARDMK_DIR)/bin/auto-lib.py $(USER_LIB_PATH) | \ + sed -ne 's/MAIN_LIBS \(.*\) /\1/p') +endif + +ifndef LIBS_DEPS + LIBS_DEPS = $(shell $(ARDMK_DIR)/bin/auto-lib.py $(USER_LIB_PATH) | \ + sed -ne 's/LIBS_DEPS \(.*\) /\1/p') +endif + ######################################################################## # Determine ARDUINO_LIBS automatically @@ -772,8 +785,7 @@ ifndef ARDUINO_LIBS $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(LOCAL_SRCS))) ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_SKETCHBOOK)/libraries/*)), \ $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(LOCAL_SRCS))) - ARDUINO_LIBS += $(filter $(notdir $(wildcard $(USER_LIB_PATH)/*)), \ - $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(LOCAL_SRCS))) + ARDUINO_LIBS += $(MAIN_LIBS) $(LIBS_DEPS) endif ######################################################################## @@ -989,13 +1001,27 @@ else $(call show_config_info,Size utility: Basic (not AVR-aware),[AUTODETECTED]) endif -ifneq (,$(strip $(ARDUINO_LIBS))) +ifneq (,$(strip $(MAIN_LIBS))) $(call arduino_output,-) - $(call show_config_info,ARDUINO_LIBS =) + $(call show_config_info,MAIN_LIBS =) endif -ifneq (,$(strip $(USER_LIB_NAMES))) - $(foreach lib,$(USER_LIB_NAMES),$(call show_config_info, $(lib),[USER])) +ifneq (,$(strip $(MAIN_LIBS))) + $(foreach lib,$(MAIN_LIBS),$(call show_config_info, $(lib),[USER])) +endif + +ifneq (,$(strip $(LIBS_DEPS))) + $(call arduino_output,-) + $(call show_config_info,LIBS_DEPS =) +endif + +ifneq (,$(strip $(LIBS_DEPS))) + $(foreach lib,$(LIBS_DEPS),$(call show_config_info, $(lib),[USER])) +endif + +ifneq (,$(strip $(SYS_LIBS))) + $(call arduino_output,-) + $(call show_config_info,SYS_LIBS =) endif ifneq (,$(strip $(SYS_LIB_NAMES))) diff --git a/bin/auto-lib.py b/bin/auto-lib.py index a0a1d4a..77d69f6 100755 --- a/bin/auto-lib.py +++ b/bin/auto-lib.py @@ -16,6 +16,12 @@ MAIN_LIBS = [] ; LIBS_DEPS = [] ; LIBS_DEPS_STACK = [] ; +# Define functions +def outputLibs(libArray): + for lib in libArray: + print(lib), + print("") + # Find local sources .ino, .c or .cpp for file in os.listdir(os.curdir): if file.endswith((".c", ".cpp", ".ino")): @@ -70,24 +76,10 @@ while LIBS_DEPS_STACK: LIBS_DEPS_STACK.remove(lib) LIBS_DEPS_STACK = sorted(set(LIBS_DEPS_STACK)) - # print(LIBS_DEPS_STACK) LIBS_DEPS = sorted(set(LIBS_DEPS)) -# print("Main libraries: ") -# print(MAIN_LIBS); -# print("") -# print("Dependencies stack: ") -# print(LIBS_DEPS_STACK) -# print("") -# print("Libraries dependencies: ") -# print(LIBS_DEPS); - -def outputLibs(libArray): - for lib in libArray: - print(lib), - print("") - +# Output libraries for the Makefile print("MAIN_LIBS"), outputLibs(MAIN_LIBS)