Skip to content

Commit f930c17

Browse files
author
ladislas
committed
Add automatic lib detection with python script, enhance lib listing output when compiling
1 parent 58f303a commit f930c17

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

Arduino.mk

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ ifeq ($(strip $(CHK_SOURCES)),)
736736
$(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)
737737
else
738738
#TODO: Support more than one file. https://github.com/sudar/Arduino-Makefile/issues/49
739-
$(error Need exactly one .pde or .ino file. This makefile doesn't support multiple .ino/.pde files yet)
739+
$(error Need exactly one .pde or .ino file. This makefile doesn\'t support multiple .ino/.pde files yet)
740740
endif
741741
endif
742742

@@ -763,6 +763,19 @@ else
763763
$(call show_config_info,NO_CORE set so core library will not be built,[MANUAL])
764764
endif
765765

766+
########################################################################
767+
# Automatically find the libraries needed to compile the sketch
768+
769+
ifndef MAIN_LIBS
770+
MAIN_LIBS = $(shell $(ARDMK_DIR)/bin/auto-lib.py $(USER_LIB_PATH) | \
771+
sed -ne 's/MAIN_LIBS \(.*\) /\1/p')
772+
endif
773+
774+
ifndef LIBS_DEPS
775+
LIBS_DEPS = $(shell $(ARDMK_DIR)/bin/auto-lib.py $(USER_LIB_PATH) | \
776+
sed -ne 's/LIBS_DEPS \(.*\) /\1/p')
777+
endif
778+
766779
########################################################################
767780
# Determine ARDUINO_LIBS automatically
768781

@@ -772,8 +785,7 @@ ifndef ARDUINO_LIBS
772785
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(LOCAL_SRCS)))
773786
ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_SKETCHBOOK)/libraries/*)), \
774787
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(LOCAL_SRCS)))
775-
ARDUINO_LIBS += $(filter $(notdir $(wildcard $(USER_LIB_PATH)/*)), \
776-
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(LOCAL_SRCS)))
788+
ARDUINO_LIBS += $(MAIN_LIBS) $(LIBS_DEPS)
777789
endif
778790

779791
########################################################################
@@ -989,13 +1001,27 @@ else
9891001
$(call show_config_info,Size utility: Basic (not AVR-aware),[AUTODETECTED])
9901002
endif
9911003

992-
ifneq (,$(strip $(ARDUINO_LIBS)))
1004+
ifneq (,$(strip $(MAIN_LIBS)))
9931005
$(call arduino_output,-)
994-
$(call show_config_info,ARDUINO_LIBS =)
1006+
$(call show_config_info,MAIN_LIBS =)
9951007
endif
9961008

997-
ifneq (,$(strip $(USER_LIB_NAMES)))
998-
$(foreach lib,$(USER_LIB_NAMES),$(call show_config_info, $(lib),[USER]))
1009+
ifneq (,$(strip $(MAIN_LIBS)))
1010+
$(foreach lib,$(MAIN_LIBS),$(call show_config_info, $(lib),[USER]))
1011+
endif
1012+
1013+
ifneq (,$(strip $(LIBS_DEPS)))
1014+
$(call arduino_output,-)
1015+
$(call show_config_info,LIBS_DEPS =)
1016+
endif
1017+
1018+
ifneq (,$(strip $(LIBS_DEPS)))
1019+
$(foreach lib,$(LIBS_DEPS),$(call show_config_info, $(lib),[USER]))
1020+
endif
1021+
1022+
ifneq (,$(strip $(SYS_LIBS)))
1023+
$(call arduino_output,-)
1024+
$(call show_config_info,SYS_LIBS =)
9991025
endif
10001026

10011027
ifneq (,$(strip $(SYS_LIB_NAMES)))

bin/auto-lib.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
LIBS_DEPS = [] ;
1717
LIBS_DEPS_STACK = [] ;
1818

19+
# Define functions
20+
def outputLibs(libArray):
21+
for lib in libArray:
22+
print(lib),
23+
print("")
24+
1925
# Find local sources .ino, .c or .cpp
2026
for file in os.listdir(os.curdir):
2127
if file.endswith((".c", ".cpp", ".ino")):
@@ -70,24 +76,10 @@
7076
LIBS_DEPS_STACK.remove(lib)
7177

7278
LIBS_DEPS_STACK = sorted(set(LIBS_DEPS_STACK))
73-
# print(LIBS_DEPS_STACK)
7479

7580
LIBS_DEPS = sorted(set(LIBS_DEPS))
7681

77-
# print("Main libraries: ")
78-
# print(MAIN_LIBS);
79-
# print("")
80-
# print("Dependencies stack: ")
81-
# print(LIBS_DEPS_STACK)
82-
# print("")
83-
# print("Libraries dependencies: ")
84-
# print(LIBS_DEPS);
85-
86-
def outputLibs(libArray):
87-
for lib in libArray:
88-
print(lib),
89-
print("")
90-
82+
# Output libraries for the Makefile
9183
print("MAIN_LIBS"),
9284
outputLibs(MAIN_LIBS)
9385

0 commit comments

Comments
 (0)