@@ -41,7 +41,8 @@ import (
41
41
"arduino.cc/properties"
42
42
)
43
43
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 }
45
46
46
47
type LibrariesBuilder struct {}
47
48
@@ -67,6 +68,34 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
67
68
68
69
ctx .LibrariesObjectFiles = objectFiles
69
70
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
+ }
70
99
return nil
71
100
}
72
101
@@ -99,7 +128,7 @@ func compileLibrary(library *types.Library, buildPath string, buildProperties pr
99
128
100
129
if library .Precompiled {
101
130
// 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 ] }
103
132
104
133
filePaths := []string {}
105
134
mcu := buildProperties [constants .BUILD_PROPERTIES_BUILD_MCU ]
0 commit comments