Skip to content

Commit 03c5c69

Browse files
committed
setup.py: link external libs also when compiling _psutil_posix.c ext
1 parent 49b56c2 commit 03c5c69

1 file changed

Lines changed: 39 additions & 27 deletions

File tree

setup.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@
113113
"wheel",
114114
]
115115

116+
# External libraries to link against.
117+
libraries = []
118+
119+
# The pre-processor macros that are passed to the C compiler when
120+
# building the extension.
116121
macros = []
122+
117123
if POSIX:
118124
macros.append(("PSUTIL_POSIX", 1))
119125
if BSD:
@@ -278,6 +284,17 @@ def get_winver():
278284
msg += "2000, XP and 2003 server"
279285
raise RuntimeError(msg)
280286

287+
libraries.extend([
288+
"advapi32",
289+
"kernel32",
290+
"netapi32",
291+
"pdh",
292+
"PowrProf",
293+
"psapi",
294+
"shell32",
295+
"ws2_32",
296+
])
297+
281298
macros.append(("PSUTIL_WINDOWS", 1))
282299
macros.extend([
283300
# be nice to mingw, see:
@@ -300,16 +317,7 @@ def get_winver():
300317
+ glob.glob("psutil/arch/windows/*.c")
301318
),
302319
define_macros=macros,
303-
libraries=[
304-
"psapi",
305-
"kernel32",
306-
"advapi32",
307-
"shell32",
308-
"netapi32",
309-
"ws2_32",
310-
"PowrProf",
311-
"pdh",
312-
],
320+
libraries=libraries,
313321
# extra_compile_args=["/W 4"],
314322
# extra_link_args=["/DEBUG"],
315323
# fmt: off
@@ -341,7 +349,9 @@ def get_winver():
341349
)
342350

343351
elif FREEBSD:
352+
libraries.extend(["devstat"])
344353
macros.append(("PSUTIL_FREEBSD", 1))
354+
345355
ext = Extension(
346356
'psutil._psutil_bsd',
347357
sources=(
@@ -351,15 +361,17 @@ def get_winver():
351361
+ glob.glob("psutil/arch/freebsd/*.c")
352362
),
353363
define_macros=macros,
354-
libraries=["devstat"],
364+
libraries=libraries,
355365
# fmt: off
356366
# python 2.7 compatibility requires no comma
357367
**py_limited_api
358368
# fmt: on
359369
)
360370

361371
elif OPENBSD:
372+
libraries.extend(["kvm"])
362373
macros.append(("PSUTIL_OPENBSD", 1))
374+
363375
ext = Extension(
364376
'psutil._psutil_bsd',
365377
sources=(
@@ -369,15 +381,17 @@ def get_winver():
369381
+ glob.glob("psutil/arch/openbsd/*.c")
370382
),
371383
define_macros=macros,
372-
libraries=["kvm"],
384+
libraries=libraries,
373385
# fmt: off
374386
# python 2.7 compatibility requires no comma
375387
**py_limited_api
376388
# fmt: on
377389
)
378390

379391
elif NETBSD:
392+
libraries.extend(["kvm"])
380393
macros.append(("PSUTIL_NETBSD", 1))
394+
381395
ext = Extension(
382396
'psutil._psutil_bsd',
383397
sources=(
@@ -387,7 +401,7 @@ def get_winver():
387401
+ glob.glob("psutil/arch/netbsd/*.c")
388402
),
389403
define_macros=macros,
390-
libraries=["kvm"],
404+
libraries=libraries,
391405
# fmt: off
392406
# python 2.7 compatibility requires no comma
393407
**py_limited_api
@@ -415,7 +429,9 @@ def get_winver():
415429
)
416430

417431
elif SUNOS:
432+
libraries.extend(["kstat", "nsl", "socket"])
418433
macros.append(("PSUTIL_SUNOS", 1))
434+
419435
ext = Extension(
420436
'psutil._psutil_sunos',
421437
sources=(
@@ -424,25 +440,25 @@ def get_winver():
424440
+ glob.glob("psutil/arch/sunos/*.c")
425441
),
426442
define_macros=macros,
427-
libraries=['kstat', 'nsl', 'socket'],
443+
libraries=libraries,
428444
# fmt: off
429445
# python 2.7 compatibility requires no comma
430446
**py_limited_api
431447
# fmt: on
432448
)
433449

434450
elif AIX:
451+
libraries.extend(["perfstat"])
435452
macros.append(("PSUTIL_AIX", 1))
453+
436454
ext = Extension(
437455
'psutil._psutil_aix',
438-
sources=sources
439-
+ [
440-
'psutil/_psutil_aix.c',
441-
'psutil/arch/aix/net_connections.c',
442-
'psutil/arch/aix/common.c',
443-
'psutil/arch/aix/ifaddrs.c',
444-
],
445-
libraries=['perfstat'],
456+
sources=(
457+
sources
458+
+ ["psutil/_psutil_aix.c"]
459+
+ glob.glob("psutil/arch/aix/*.c")
460+
),
461+
libraries=libraries,
446462
define_macros=macros,
447463
# fmt: off
448464
# python 2.7 compatibility requires no comma
@@ -457,18 +473,14 @@ def get_winver():
457473
if POSIX:
458474
posix_extension = Extension(
459475
'psutil._psutil_posix',
476+
libraries=libraries,
460477
define_macros=macros,
461478
sources=sources,
462479
# fmt: off
463480
# python 2.7 compatibility requires no comma
464481
**py_limited_api
465482
# fmt: on
466483
)
467-
if SUNOS:
468-
posix_extension.libraries.append('socket')
469-
elif AIX:
470-
posix_extension.sources.append('psutil/arch/aix/ifaddrs.c')
471-
472484
extensions = [ext, posix_extension]
473485
else:
474486
extensions = [ext]

0 commit comments

Comments
 (0)