@@ -30,8 +30,6 @@ import (
30
30
"github.com/pkg/errors"
31
31
)
32
32
33
- var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC = map [string ]bool {".a" : true }
34
- var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC = map [string ]bool {".so" : true }
35
33
var FLOAT_ABI_CFLAG = "float-abi"
36
34
var FPU_CFLAG = "fpu"
37
35
@@ -105,33 +103,6 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib
105
103
return nil
106
104
}
107
105
108
- func fixLDFLAG (ctx * types.Context , library * libraries.Library , path * paths.Path ) {
109
- // find all library names in the folder and prepend -l
110
- filePaths := []string {}
111
- libsCmd := library .LDflags + " "
112
- extensions := func (ext string ) bool {
113
- return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC [ext ] || PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC [ext ]
114
- }
115
- utils .FindFilesInFolder (& filePaths , path .String (), extensions , false )
116
- for _ , lib := range filePaths {
117
- name := strings .TrimSuffix (filepath .Base (lib ), filepath .Ext (lib ))
118
- // strip "lib" first occurrence
119
- if strings .HasPrefix (name , "lib" ) {
120
- name = strings .Replace (name , "lib" , "" , 1 )
121
- libsCmd += "-l" + name + " "
122
- }
123
- }
124
-
125
- key := "compiler.libraries.ldflags"
126
- if ! ctx .BuildProperties .ContainsKey (key ) {
127
- logger := ctx .GetLogger ()
128
- logger .Fprintln (os .Stdout , constants .LOG_LEVEL_INFO , "The plaform doesn't support 'compiler.libraries.ldflags' for precompiled libraries... trying with 'compiler.ldflags'." )
129
- key = "compiler.ldflags"
130
- }
131
- currLDFlags := ctx .BuildProperties .Get (key )
132
- ctx .BuildProperties .Set (key , currLDFlags + " \" -L" + path .String ()+ "\" " + libsCmd + " " )
133
- }
134
-
135
106
func compileLibraries (ctx * types.Context , libraries libraries.List , buildPath * paths.Path , buildProperties * properties.Map , includes []string ) (paths.PathList , error ) {
136
107
ctx .Progress .AddSubSteps (len (libraries ))
137
108
defer ctx .Progress .RemoveSubSteps ()
@@ -166,19 +137,45 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
166
137
167
138
if library .Precompiled {
168
139
if precompiledPath := findExpectedPrecompiledLibFolder (ctx , library ); precompiledPath != nil {
140
+ var staticLibExts = map [string ]bool {".a" : true }
141
+ var dynamixLibExts = map [string ]bool {".so" : true }
142
+ dynAndStatic := func (ext string ) bool { return dynamixLibExts [ext ] || staticLibExts [ext ] }
143
+ staticOnly := func (ext string ) bool { return staticLibExts [ext ] }
144
+
169
145
// Add required LD flags
170
- fixLDFLAG (ctx , library , precompiledPath )
146
+
147
+ // find all library names in the folder and prepend -l
148
+ dynAndStaticLibs := []string {}
149
+ libsCmd := library .LDflags + " "
150
+ if err := utils .FindFilesInFolder (& dynAndStaticLibs , precompiledPath .String (), dynAndStatic , false ); err != nil {
151
+ return nil , errors .WithStack (err )
152
+ }
153
+ for _ , lib := range dynAndStaticLibs {
154
+ name := strings .TrimSuffix (filepath .Base (lib ), filepath .Ext (lib ))
155
+ // strip "lib" first occurrence
156
+ if strings .HasPrefix (name , "lib" ) {
157
+ name = strings .Replace (name , "lib" , "" , 1 )
158
+ libsCmd += "-l" + name + " "
159
+ }
160
+ }
161
+
162
+ key := "compiler.libraries.ldflags"
163
+ if ! ctx .BuildProperties .ContainsKey (key ) {
164
+ logger := ctx .GetLogger ()
165
+ logger .Fprintln (os .Stdout , constants .LOG_LEVEL_INFO , "The plaform doesn't support 'compiler.libraries.ldflags' for precompiled libraries... trying with 'compiler.ldflags'." )
166
+ key = "compiler.ldflags"
167
+ }
168
+ currLDFlags := ctx .BuildProperties .Get (key )
169
+ ctx .BuildProperties .Set (key , currLDFlags + " \" -L" + precompiledPath .String ()+ "\" " + libsCmd + " " )
171
170
172
171
// TODO: This codepath is just taken for .a with unusual names that would
173
172
// be ignored by -L / -l methods.
174
173
// Should we force precompiled libraries to start with "lib" ?
175
- extensions := func (ext string ) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC [ext ] }
176
- filePaths := []string {}
177
- err := utils .FindFilesInFolder (& filePaths , precompiledPath .String (), extensions , false )
178
- if err != nil {
174
+ staticLibs := []string {}
175
+ if err := utils .FindFilesInFolder (& staticLibs , precompiledPath .String (), staticOnly , false ); err != nil {
179
176
return nil , errors .WithStack (err )
180
177
}
181
- for _ , path := range filePaths {
178
+ for _ , path := range staticLibs {
182
179
if ! strings .HasPrefix (filepath .Base (path ), "lib" ) {
183
180
objectFiles .Add (paths .New (path ))
184
181
}
0 commit comments