@@ -151,6 +151,7 @@ def write_cache(local_fn, data):
151151# matplotlib build options, which can be altered using setup.cfg
152152options = {
153153 'backend' : None ,
154+ 'staticbuild' : False ,
154155 }
155156
156157
@@ -164,12 +165,18 @@ def write_cache(local_fn, data):
164165
165166 if config .has_option ('test' , 'local_freetype' ):
166167 options ['local_freetype' ] = config .getboolean ("test" , "local_freetype" )
168+
169+ if config .has_option ('build' , 'staticbuild' ):
170+ options ['staticbuild' ] = config .getboolean ("build" , "staticbuild" )
167171else :
168172 config = None
169173
170174lft = bool (os .environ .get ('MPLLOCALFREETYPE' , False ))
171175options ['local_freetype' ] = lft or options .get ('local_freetype' , False )
172176
177+ staticbuild = bool (os .environ .get ('MPLSTATICBUILD' , os .name == 'nt' ))
178+ options ['staticbuild' ] = staticbuild or options .get ('staticbuild' , False )
179+
173180
174181if '-q' in sys .argv or '--quiet' in sys .argv :
175182 def print_raw (* args , ** kwargs ): pass # Suppress our own output.
@@ -195,6 +202,23 @@ def get_buffer_hash(fd):
195202 return hasher .hexdigest ()
196203
197204
205+ def deplib (libname ):
206+ if sys .platform != 'win32' :
207+ return libname
208+
209+ known_libs = {
210+ # TODO: support versioned libpng on build system rewrite
211+ 'libpng16' : ('libpng16' , '_static' ),
212+ 'z' : ('zlib' , 'static' ),
213+ }
214+
215+ libname , static_postfix = known_libs [libname ]
216+ if options ['staticbuild' ]:
217+ libname += static_postfix
218+
219+ return libname
220+
221+
198222@functools .lru_cache (1 ) # We only need to compute this once.
199223def get_pkg_config ():
200224 """
@@ -501,7 +525,7 @@ def add_flags(self, ext):
501525 ext , 'freetype2' ,
502526 atleast_version = '9.11.3' ,
503527 alt_exec = ['freetype-config' ],
504- default_libraries = ['freetype' , 'z' ])
528+ default_libraries = ['freetype' , deplib ( 'z' ) ])
505529 ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'system' ))
506530
507531 def do_custom_build (self ):
@@ -635,7 +659,7 @@ def get_extension(self):
635659 default_libraries = (
636660 ['png' , 'z' ] if os .name == 'posix' else
637661 # libpng upstream names their lib libpng16.lib, not png.lib.
638- ['libpng16' ] if os .name == 'nt' else
662+ [deplib ( 'libpng16' ), deplib ( 'z' ) ] if os .name == 'nt' else
639663 []
640664 ))
641665 add_numpy_flags (ext )
0 commit comments