@@ -46,11 +46,12 @@ function _find_package_from_list(list, name, pacman, opt)
46
46
end
47
47
48
48
-- iterate over each file path inside the pacman package
49
- local result = {includedirs = {}, linkdirs = {}, links = {} }
49
+ local result = {}
50
50
for _ , line in ipairs (list :split (' \n ' , {plain = true })) do -- on msys cygpath should be used to convert local path to windows path
51
51
line = line :trim ():split (' %s+' )[2 ]
52
52
if line :find (" /include/" , 1 , true ) and (line :endswith (" .h" ) or line :endswith (" .hpp" )) then
53
53
if not line :startswith (" /usr/include/" ) then
54
+ result .includedirs = result .includedirs or {}
54
55
local hpath = line
55
56
if is_subhost (" msys" ) and opt .plat == " mingw" then
56
57
hpath = path .join (pathtomsys , line )
@@ -63,12 +64,18 @@ function _find_package_from_list(list, name, pacman, opt)
63
64
elseif line :endswith (" .dll.a" ) then -- only for mingw
64
65
local apath = path .join (pathtomsys , line )
65
66
apath = apath :trim ()
67
+ result .linkdirs = result .linkdirs or {}
68
+ result .links = result .links or {}
66
69
table.insert (result .linkdirs , path .directory (apath ))
67
70
table.insert (result .links , target .linkname (path .filename (apath ), {plat = opt .plat }))
68
71
elseif line :endswith (" .so" ) then
72
+ result .linkdirs = result .linkdirs or {}
73
+ result .links = result .links or {}
69
74
table.insert (result .linkdirs , path .directory (line ))
70
75
table.insert (result .links , target .linkname (path .filename (line ), {plat = opt .plat }))
71
76
elseif line :endswith (" .a" ) then
77
+ result .linkdirs = result .linkdirs or {}
78
+ result .links = result .links or {}
72
79
local apath = line
73
80
if is_subhost (" msys" ) and opt .plat == " mingw" then
74
81
apath = path .join (pathtomsys , line )
@@ -78,9 +85,15 @@ function _find_package_from_list(list, name, pacman, opt)
78
85
table.insert (result .links , target .linkname (path .filename (apath ), {plat = opt .plat }))
79
86
end
80
87
end
81
- result .includedirs = table .unique (result .includedirs )
82
- result .linkdirs = table .unique (result .linkdirs )
83
- result .links = table .reverse_unique (result .links )
88
+ if result .includedirs then
89
+ result .includedirs = table .unique (result .includedirs )
90
+ end
91
+ if result .linkdirs then
92
+ result .linkdirs = table .unique (result .linkdirs )
93
+ end
94
+ if result .links then
95
+ result .links = table .reverse_unique (result .links )
96
+ end
84
97
85
98
-- use pacman package version as version
86
99
local version = try { function () return os .iorunv (pacman .program , {" -Q" , name }) end }
@@ -192,7 +205,7 @@ function main(name, opt)
192
205
193
206
-- we iterate over each pkgconfig file to extract the required data
194
207
local foundpc = false
195
- local result = {includedirs = {}, linkdirs = {}, links = {} }
208
+ local result = {}
196
209
for _ , pkgconfig_file in ipairs (pkgconfig_files ) do
197
210
local pkgconfig_dir = path .directory (pkgconfig_file )
198
211
local pkgconfig_name = path .basename (pkgconfig_file )
@@ -201,43 +214,55 @@ function main(name, opt)
201
214
-- the pkgconfig file has been parse successfully
202
215
if pcresult then
203
216
for _ , includedir in ipairs (pcresult .includedirs ) do
217
+ result .includedirs = result .includedirs or {}
204
218
table.insert (result .includedirs , includedir )
205
219
end
206
220
for _ , linkdir in ipairs (pcresult .linkdirs ) do
221
+ result .linkdirs = result .linkdirs or {}
207
222
table.insert (result .linkdirs , linkdir )
208
223
end
209
224
for _ , link in ipairs (pcresult .links ) do
225
+ result .links = result .links or {}
210
226
table.insert (result .links , link )
211
227
end
228
+ for _ , libfile in ipairs (pcresult .libfiles ) do
229
+ result .libfiles = result .libfiles or {}
230
+ table.insert (result .libfiles , libfile )
231
+ end
212
232
-- version should be the same if a pacman package contains multiples .pc
213
233
result .version = pcresult .version
234
+ result .shared = pcresult .shared
235
+ result .static = pcresult .static
214
236
foundpc = true
215
237
end
216
238
end
217
239
218
240
if foundpc == true then
219
- result .includedirs = table .unique (result .includedirs )
220
- result .linkdirs = table .unique (result .linkdirs )
221
- result .links = table .reverse_unique (result .links )
241
+ if result .includedirs then
242
+ result .includedirs = table .unique (result .includedirs )
243
+ end
244
+ if result .linkdirs then
245
+ result .linkdirs = table .unique (result .linkdirs )
246
+ end
247
+ if result .libfiles then
248
+ result .libfiles = table .unique (result .libfiles )
249
+ end
250
+ if result .links then
251
+ result .links = table .reverse_unique (result .links )
252
+ end
222
253
else
223
254
-- if there is no .pc, we parse the package content to obtain the data we want
224
255
result = _find_package_from_list (list , name , pacman , opt )
225
256
end
226
257
if result then
227
- if result .linkdirs and # result .linkdirs == 0 then
228
- result .linkdirs = nil
229
- end
230
- if result .includedirs and # result .includedirs == 0 then
231
- result .includedirs = nil
232
- end
233
258
if not result .libfiles then
234
- result .libfiles = _find_libfiles_from_list (list , name , pacman , opt )
235
- end
236
- for _ , libfile in ipairs ( result . libfiles ) do
237
- if libfile : endswith ( " .so " ) then
238
- result . shared = true
239
- elseif libfile : endswith ( " .a " ) then
240
- result . static = true
259
+ result .libfiles = _find_libfiles_from_list (list , name , pacman , opt )
260
+ for _ , libfile in ipairs ( result . libfiles ) do
261
+ if libfile : endswith ( " .so " ) then
262
+ result . shared = true
263
+ elseif libfile : endswith ( " .a " ) then
264
+ result . static = true
265
+ end
241
266
end
242
267
end
243
268
end
0 commit comments