@@ -286,18 +286,19 @@ def setup_extension(
286
286
if self .pkg_config and atleast_version :
287
287
subprocess .check_call (
288
288
[* cmd , f"--atleast-version={ atleast_version } " ])
289
- flags = shlex .split (subprocess .check_output (
290
- [* cmd , "--cflags" , "--libs" ], universal_newlines = True ))
289
+ # Use sys.getfilesystemencoding() to allow round-tripping
290
+ # when passed back to later subprocess calls; do not use
291
+ # locale.getpreferredencoding() which universal_newlines=True
292
+ # would do.
293
+ cflags = shlex .split (
294
+ os .fsdecode (subprocess .check_output ([* cmd , "--cflags" ])))
295
+ libs = shlex .split (
296
+ os .fsdecode (subprocess .check_output ([* cmd , "--libs" ])))
291
297
except (OSError , subprocess .CalledProcessError ):
292
298
pass
293
299
else :
294
- # In theory, one could call pkg-config separately with --cflags
295
- # and --libs and use them to fill extra_compile_args and
296
- # extra_link_args respectively, but keeping all the flags
297
- # together works as well and makes it simpler to handle
298
- # libpng-config, which has --ldflags instead of --libs.
299
- ext .extra_compile_args .extend (flags )
300
- ext .extra_link_args .extend (flags )
300
+ ext .extra_compile_args .extend (cflags )
301
+ ext .extra_link_args .extend (libs )
301
302
return
302
303
303
304
# If that fails, fall back on the defaults.
@@ -713,7 +714,7 @@ def add_flags(self, ext):
713
714
# table in docs/VERSIONS.txt in the FreeType source tree.
714
715
ext , 'freetype2' ,
715
716
atleast_version = '9.11.3' ,
716
- alt_exec = ['freetype-config' , '--cflags' , '--libs' ],
717
+ alt_exec = ['freetype-config' ],
717
718
default_libraries = ['freetype' , 'z' ])
718
719
ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'system' ))
719
720
@@ -858,7 +859,7 @@ def get_extension(self):
858
859
pkg_config .setup_extension (
859
860
ext , 'libpng' ,
860
861
atleast_version = '1.2' ,
861
- alt_exec = ['libpng-config' , '--cflags' , '-- ldflags' ],
862
+ alt_exec = ['libpng-config' , '--ldflags' ],
862
863
default_libraries = ['png' , 'z' ])
863
864
Numpy ().add_flags (ext )
864
865
return ext
0 commit comments