@@ -31,6 +31,7 @@ package phases
31
31
32
32
import (
33
33
"path/filepath"
34
+ "strings"
34
35
35
36
"arduino.cc/builder/builder_utils"
36
37
"arduino.cc/builder/constants"
@@ -40,6 +41,9 @@ import (
40
41
"arduino.cc/properties"
41
42
)
42
43
44
+ var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC = map [string ]bool {".a" : true }
45
+ var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC = map [string ]bool {".so" : true }
46
+
43
47
type LibrariesBuilder struct {}
44
48
45
49
func (s * LibrariesBuilder ) Run (ctx * types.Context ) error {
@@ -64,6 +68,34 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
64
68
65
69
ctx .LibrariesObjectFiles = objectFiles
66
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
+ }
67
99
return nil
68
100
}
69
101
@@ -93,6 +125,24 @@ func compileLibrary(library *types.Library, buildPath string, buildProperties pr
93
125
}
94
126
95
127
objectFiles := []string {}
128
+
129
+ if library .Precompiled {
130
+ // search for files with PRECOMPILED_LIBRARIES_VALID_EXTENSIONS
131
+ extensions := func (ext string ) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC [ext ] }
132
+
133
+ filePaths := []string {}
134
+ mcu := buildProperties [constants .BUILD_PROPERTIES_BUILD_MCU ]
135
+ err := utils .FindFilesInFolder (& filePaths , filepath .Join (library .SrcFolder , mcu ), extensions , true )
136
+ if err != nil {
137
+ return nil , i18n .WrapError (err )
138
+ }
139
+ for _ , path := range filePaths {
140
+ if strings .Contains (filepath .Base (path ), library .RealName ) {
141
+ objectFiles = append (objectFiles , path )
142
+ }
143
+ }
144
+ }
145
+
96
146
if library .Layout == types .LIBRARY_RECURSIVE {
97
147
objectFiles , err = builder_utils .CompileFilesRecursive (objectFiles , library .SrcFolder , libraryBuildPath , buildProperties , includes , verbose , warningsLevel , logger )
98
148
if err != nil {
0 commit comments