@@ -286,18 +286,19 @@ def setup_extension(
286286 if self .pkg_config and atleast_version :
287287 subprocess .check_call (
288288 [* 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" ])))
291297 except (OSError , subprocess .CalledProcessError ):
292298 pass
293299 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 )
301302 return
302303
303304 # If that fails, fall back on the defaults.
@@ -713,7 +714,7 @@ def add_flags(self, ext):
713714 # table in docs/VERSIONS.txt in the FreeType source tree.
714715 ext , 'freetype2' ,
715716 atleast_version = '9.11.3' ,
716- alt_exec = ['freetype-config' , '--cflags' , '--libs' ],
717+ alt_exec = ['freetype-config' ],
717718 default_libraries = ['freetype' , 'z' ])
718719 ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'system' ))
719720
@@ -858,7 +859,7 @@ def get_extension(self):
858859 pkg_config .setup_extension (
859860 ext , 'libpng' ,
860861 atleast_version = '1.2' ,
861- alt_exec = ['libpng-config' , '--cflags' , '-- ldflags' ],
862+ alt_exec = ['libpng-config' , '--ldflags' ],
862863 default_libraries = ['png' , 'z' ])
863864 Numpy ().add_flags (ext )
864865 return ext
0 commit comments