@@ -41,7 +41,8 @@ import (
4141 "arduino.cc/properties"
4242)
4343
44- var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS = map [string ]bool {".a" : true , ".so" : true }
44+ var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC = map [string ]bool {".a" : true }
45+ var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC = map [string ]bool {".so" : true }
4546
4647type LibrariesBuilder struct {}
4748
@@ -67,6 +68,34 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
6768
6869 ctx .LibrariesObjectFiles = objectFiles
6970
71+ // Search for precompiled libraries
72+ fixLDFLAGforPrecompiledLibraries (ctx , libraries )
73+
74+ return nil
75+ }
76+
77+ func fixLDFLAGforPrecompiledLibraries (ctx * types.Context , libraries []* types.Library ) error {
78+
79+ for _ , library := range libraries {
80+ if library .Precompiled {
81+ // add library src path to compiler.c.elf.extra_flags
82+ // use library.Name as lib name and srcPath/{mcpu} as location
83+ mcu := ctx .BuildProperties [constants .BUILD_PROPERTIES_BUILD_MCU ]
84+ path := filepath .Join (library .SrcFolder , mcu )
85+ // find all library names in the folder and prepend -l
86+ filePaths := []string {}
87+ libs_cmd := library .LDflags + " "
88+ extensions := func (ext string ) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC [ext ] }
89+ utils .FindFilesInFolder (& filePaths , path , extensions , true )
90+ for _ , lib := range filePaths {
91+ name := strings .TrimSuffix (filepath .Base (lib ), filepath .Ext (lib ))
92+ // strip "lib" first occurrence
93+ name = strings .Replace (name , "lib" , "" , 1 )
94+ libs_cmd += "-l" + name + " "
95+ }
96+ ctx .BuildProperties [constants .BUILD_PROPERTIES_COMPILER_C_ELF_EXTRAFLAGS ] += "\" -L" + path + "\" " + libs_cmd
97+ }
98+ }
7099 return nil
71100}
72101
@@ -99,7 +128,7 @@ func compileLibrary(library *types.Library, buildPath string, buildProperties pr
99128
100129 if library .Precompiled {
101130 // search for files with PRECOMPILED_LIBRARIES_VALID_EXTENSIONS
102- extensions := func (ext string ) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS [ext ] }
131+ extensions := func (ext string ) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC [ext ] }
103132
104133 filePaths := []string {}
105134 mcu := buildProperties [constants .BUILD_PROPERTIES_BUILD_MCU ]
0 commit comments