Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
|
0d2c9661c3 | ||
|
f930c17801 | ||
|
58f303a5d3 | ||
|
f33b14715b |
2 changed files with 120 additions and 7 deletions
40
Arduino.mk
40
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)))
|
||||
|
|
87
bin/auto-lib.py
Executable file
87
bin/auto-lib.py
Executable file
|
@ -0,0 +1,87 @@
|
|||
#!/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 = [] ;
|
||||
|
||||
# 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")):
|
||||
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))
|
||||
|
||||
LIBS_DEPS = sorted(set(LIBS_DEPS))
|
||||
|
||||
# Output libraries for the Makefile
|
||||
print("MAIN_LIBS"),
|
||||
outputLibs(MAIN_LIBS)
|
||||
|
||||
print("LIBS_DEPS"),
|
||||
outputLibs(LIBS_DEPS)
|
Loading…
Reference in a new issue