From a58062611e44e8f86f3fe07c8d85667ebddb7159 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Thu, 14 Aug 2014 12:14:40 -0400 Subject: [PATCH 1/4] MakefileExample: Fix AVR_TOOLS_DIR default Judging by the default for OS X directly above it and the fact that the current default doesn't work, it seems this should not include the `/bin`. --- examples/MakefileExample/Makefile-example.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MakefileExample/Makefile-example.mk b/examples/MakefileExample/Makefile-example.mk index 964f9de..67e83e3 100644 --- a/examples/MakefileExample/Makefile-example.mk +++ b/examples/MakefileExample/Makefile-example.mk @@ -36,7 +36,7 @@ MONITOR_BAUDRATE = 115200 ### On OS X with `homebrew`: AVR_TOOLS_DIR = /usr/local ### or on Linux: (remove the one you don't want) -AVR_TOOLS_DIR = /usr/bin +AVR_TOOLS_DIR = /usr ### AVRDDUDE ### Path to avrdude directory. From 421a40e2616c17c12061c3263bfb9d56f8523c8e Mon Sep 17 00:00:00 2001 From: Simon John Date: Sat, 16 Aug 2014 19:31:07 +0200 Subject: [PATCH 2/4] allows "make clean" to be extended in the user's local makefile to clean other files out, e.g. backup/git files --- Arduino.mk | 2 +- HISTORY.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Arduino.mk b/Arduino.mk index 9e29e37..60bec1c 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -1333,7 +1333,7 @@ ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST)),) $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST) endif -clean: +clean:: $(REMOVE) $(OBJDIR) size: $(TARGET_HEX) diff --git a/HISTORY.md b/HISTORY.md index 1924534..072e695 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -12,10 +12,10 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it - Add: Add information about overriding system libs (Issue #229). (https://github.com/sej7278) - Add: Add information about reporting bugs to the correct project (Issue #231). (https://github.com/sej7278) - Fix: Allow the use of CFLAGS_STD and CXXFLAGS_STD and set defaults (Issue #234) (https://github.com/ladislas) -- Tweak: Remove \$(EXTRA_XXX) variables (Issue #234) (https://github.com/ladislas) +- Tweak: Remove $(EXTRA_XXX) variables (Issue #234) (https://github.com/ladislas) - Add: Add documentation about CFLAGS_STD and CXXFLAGS_STD (Issue #234) (https://github.com/ladislas) - Tweak: Update Malefile-example.mk with STD flags (https://github.com/ladislas) - +- Add: Allow "make clean" target to be extended (Issue #239). (https://github.com/sej7278) ### 1.3.4 (2014-07-12) - Tweak: Allow spaces in "Serial.begin (....)". (Issue #190) (https://github.com/pdav) From f33b14715bc786f7aba8e9b4969b16c1e0a03ed0 Mon Sep 17 00:00:00 2001 From: ladislas Date: Mon, 18 Aug 2014 23:21:05 +0200 Subject: [PATCH 3/4] Add auto-lib.py python script to add included libraries automatically --- bin/auto-lib.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 bin/auto-lib.py diff --git a/bin/auto-lib.py b/bin/auto-lib.py new file mode 100755 index 0000000..a0a1d4a --- /dev/null +++ b/bin/auto-lib.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +import os +import re +import sys + +# Set variables +USER_LIB_PATH = sys.argv[1] +USER_LIBS = [] ; + +includeRegex = re.compile("(?<=^\#include\s[\<\"])(.*)(?=\.h[\>\"])", re.DOTALL|re.M) + +MAIN_SRCS = [] ; +MAIN_LIBS = [] ; + +LIBS_DEPS = [] ; +LIBS_DEPS_STACK = [] ; + +# Find local sources .ino, .c or .cpp +for file in os.listdir(os.curdir): + if file.endswith((".c", ".cpp", ".ino")): + MAIN_SRCS.append(file) + +# Find all USER_LIBS +for path, dirs, files in os.walk(USER_LIB_PATH): + for d in dirs: + USER_LIBS.append(d) + +# Find MAIN_LIBS included in MAIN_SRCS +for src in MAIN_SRCS: + currentFile = open(src) + includes = [] + + for line in currentFile: + match = includeRegex.search(line) + if match: + if match.group(1) in USER_LIBS: + MAIN_LIBS.append(match.group(1)) + +MAIN_LIBS = list(sorted(MAIN_LIBS)) + +# Find LIBS_DEPS includes in MAIN_LIBS +for lib in MAIN_LIBS: + if lib in USER_LIBS: + currentFile = open(USER_LIB_PATH + "/" + lib + "/" + lib + ".h") + + for line in currentFile: + match = includeRegex.search(line) + if match: + if match.group(1) in USER_LIBS and match.group(1) not in MAIN_LIBS: + LIBS_DEPS_STACK.append(match.group(1)) + +LIBS_DEPS_STACK = sorted(set(LIBS_DEPS_STACK)) + +# Recursively find all dependencies of every libraries in USER_LIB_PATH +while LIBS_DEPS_STACK: + for lib in LIBS_DEPS_STACK: + if lib in USER_LIBS: + currentFile = open(USER_LIB_PATH + "/" + lib + "/" + lib + ".h") + + for line in currentFile: + match = includeRegex.search(line) + if match: + if match.group(1) in USER_LIBS and match.group(1) not in LIBS_DEPS_STACK or match.group(1) in LIBS_DEPS and match.group(1) not in MAIN_LIBS: + LIBS_DEPS_STACK.append(match.group(1)) + + else: + LIBS_DEPS.append(lib) + if lib in 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("") + +print("MAIN_LIBS"), +outputLibs(MAIN_LIBS) + +print("LIBS_DEPS"), +outputLibs(LIBS_DEPS) From f930c1780170f53f81bfe42095c8c161a5802cfc Mon Sep 17 00:00:00 2001 From: ladislas Date: Tue, 19 Aug 2014 00:02:38 +0200 Subject: [PATCH 4/4] 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)