summaryrefslogtreecommitdiff
path: root/ext/zlib/extconf.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/zlib/extconf.rb')
-rw-r--r--ext/zlib/extconf.rb34
1 files changed, 33 insertions, 1 deletions
diff --git a/ext/zlib/extconf.rb b/ext/zlib/extconf.rb
index 8bbede63b2..71bcc577d1 100644
--- a/ext/zlib/extconf.rb
+++ b/ext/zlib/extconf.rb
@@ -13,7 +13,24 @@ dir_config 'zlib'
if %w'z libz zlib1 zlib zdll zlibwapi'.find {|z| have_library(z, 'deflateReset')} and
have_header('zlib.h') then
+ have_zlib = true
+else
+ unless File.directory?(zsrc = "#{$srcdir}/zlib")
+ dirs = Dir.open($srcdir) {|z| z.grep(/\Azlib-\d+[.\d]*\z/) {|x|"#{$srcdir}/#{x}"}}
+ dirs.delete_if {|x| !File.directory?(x)}
+ zsrc = dirs.max_by {|x| x.scan(/\d+/).map(&:to_i)}
+ end
+ if zsrc
+ $INCFLAGS << " -I$(ZSRC)"
+ if $mswin or $mingw
+ $libs = append_library($libs, "zdll")
+ dll = "zlib1.dll"
+ end
+ have_zlib = true
+ end
+end
+if have_zlib
defines = []
Logging::message 'checking for kind of operating system... '
@@ -57,6 +74,21 @@ if %w'z libz zlib1 zlib zdll zlibwapi'.find {|z| have_library(z, 'deflateReset')
have_func('adler32_combine', 'zlib.h')
have_type('z_crc_t', 'zlib.h')
- create_makefile('zlib')
+ create_makefile('zlib') {|conf|
+ if zsrc
+ conf << "ZSRC = $(srcdir)/#{File.basename(zsrc)}\n"
+ conf << "all:\n"
+ if $mingw or $mswin
+ conf << "ZIMPLIB = zdll.lib\n"
+ conf << "$(TARGET_SO): $(ZIMPLIB)\n"
+ conf << "$(ZIMPLIB):\n"
+ conf << "\t$(MAKE) -f $(ZSRC)/win32/Makefile.#{$nmake ? 'msc' : 'gcc'} TOP=$(ZSRC) $@\n"
+ conf << "install-so: $(topdir)/#{dll}"
+ conf << "$(topdir)/#{dll}: $(ZIMPLIB)\n"
+ conf << "\t$(Q) $(COPY) #{dll} $(BINDIR)\n"
+ end
+ end
+ conf
+ }
end