2017-02-07 07:49:57 -05:00
|
|
|
# frozen_string_literal: true
|
2003-03-28 12:21:24 -05:00
|
|
|
#
|
|
|
|
# extconf.rb
|
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'mkmf'
|
|
|
|
require 'rbconfig'
|
|
|
|
|
2012-07-09 20:04:47 -04:00
|
|
|
dir_config 'zlib'
|
2003-03-28 12:21:24 -05:00
|
|
|
|
2012-07-09 23:51:25 -04:00
|
|
|
|
2012-11-06 13:50:53 -05:00
|
|
|
if %w'z libz zlib1 zlib zdll zlibwapi'.find {|z| have_library(z, 'deflateReset')} and
|
2003-03-28 12:21:24 -05:00
|
|
|
have_header('zlib.h') then
|
2016-09-22 02:35:28 -04:00
|
|
|
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
|
2016-09-24 09:26:21 -04:00
|
|
|
addconf = [
|
|
|
|
"ZSRC = $(srcdir)/#{File.basename(zsrc)}\n",
|
|
|
|
"all:\n",
|
|
|
|
]
|
2016-09-22 02:35:28 -04:00
|
|
|
$INCFLAGS << " -I$(ZSRC)"
|
|
|
|
if $mswin or $mingw
|
|
|
|
dll = "zlib1.dll"
|
2016-09-24 09:26:21 -04:00
|
|
|
$extso << dll
|
2017-03-01 00:44:37 -05:00
|
|
|
$cleanfiles << "$(topdir)/#{dll}" << "$(ZIMPLIB)"
|
2017-03-03 04:27:27 -05:00
|
|
|
zmk = "\t$(MAKE) -f $(ZMKFILE) TOP=$(ZSRC)"
|
|
|
|
if $nmake
|
|
|
|
zmkfile = "$(ZSRC)/win32/Makefile.msc"
|
|
|
|
m = "#{zsrc}/win32/Makefile.msc"
|
|
|
|
else
|
|
|
|
zmkfile = "$(ZSRC)/win32/Makefile.gcc"
|
|
|
|
m = "#{zsrc}/win32/Makefile.gcc"
|
|
|
|
zmk += " PREFIX="
|
|
|
|
zmk << CONFIG['CC'][/(.*-)gcc([^\/]*)\z/, 1]
|
|
|
|
zmk << " CC=$(CC)" if $2
|
|
|
|
end
|
|
|
|
m = File.read(m)
|
|
|
|
zimplib = m[/^IMPLIB[ \t]*=[ \t]*(\S+)/, 1]
|
|
|
|
$LOCAL_LIBS << " " << zimplib
|
|
|
|
unless $nmake or /^TOP[ \t]/ =~ m
|
|
|
|
m.gsub!(/win32\/zlib\.def/, '$(TOP)/\&')
|
|
|
|
m.gsub!(/^(\t.*[ \t])(\S+\.rc)/, '\1-I$(<D) $<')
|
|
|
|
m = "TOP = .\n""VPATH=$(TOP)\n" + m
|
|
|
|
zmkfile = File.basename(zmkfile)
|
|
|
|
File.rename(zmkfile, zmkfile+".orig") if File.exist?(zmkfile)
|
|
|
|
File.write(zmkfile, m)
|
|
|
|
end
|
2016-09-24 09:26:21 -04:00
|
|
|
addconf.push(
|
2017-03-03 04:27:27 -05:00
|
|
|
"ZMKFILE = #{zmkfile}\n",
|
|
|
|
"ZIMPLIB = #{zimplib}\n",
|
2016-09-24 09:26:21 -04:00
|
|
|
"$(TARGET_SO): $(ZIMPLIB)\n",
|
|
|
|
"$(ZIMPLIB):\n",
|
2017-03-01 00:44:37 -05:00
|
|
|
"#{zmk} $@\n",
|
2016-09-24 09:26:21 -04:00
|
|
|
"install-so: $(topdir)/#{dll}",
|
|
|
|
"$(topdir)/#{dll}: $(ZIMPLIB)\n",
|
|
|
|
"\t$(Q) $(COPY) #{dll} $(@D)\n",
|
2017-03-01 00:44:37 -05:00
|
|
|
"clean: clean-zsrc\n",
|
|
|
|
"clean-zsrc:\n",
|
|
|
|
"#{zmk} clean\n",
|
2016-09-24 09:26:21 -04:00
|
|
|
)
|
2016-09-22 02:35:28 -04:00
|
|
|
end
|
2016-09-24 09:26:21 -04:00
|
|
|
Logging.message "using zlib in #{zsrc}\n"
|
|
|
|
$defs << "-DHAVE_ZLIB_H"
|
2016-09-22 02:35:28 -04:00
|
|
|
have_zlib = true
|
|
|
|
end
|
|
|
|
end
|
2003-03-28 12:21:24 -05:00
|
|
|
|
2016-09-22 02:35:28 -04:00
|
|
|
if have_zlib
|
2003-03-28 12:21:24 -05:00
|
|
|
defines = []
|
|
|
|
|
2012-05-18 15:51:58 -04:00
|
|
|
Logging::message 'checking for kind of operating system... '
|
2003-03-28 12:21:24 -05:00
|
|
|
os_code = with_config('os-code') ||
|
|
|
|
case RUBY_PLATFORM.split('-',2)[1]
|
|
|
|
when 'amigaos' then
|
|
|
|
os_code = 'AMIGA'
|
2008-05-29 04:52:31 -04:00
|
|
|
when /mswin|mingw|bccwin/ then
|
2003-03-28 12:21:24 -05:00
|
|
|
# NOTE: cygwin should be regarded as Unix.
|
|
|
|
os_code = 'WIN32'
|
|
|
|
else
|
|
|
|
os_code = 'UNIX'
|
|
|
|
end
|
|
|
|
os_code = 'OS_' + os_code.upcase
|
|
|
|
|
|
|
|
OS_NAMES = {
|
|
|
|
'OS_MSDOS' => 'MS-DOS',
|
|
|
|
'OS_AMIGA' => 'Amiga',
|
|
|
|
'OS_VMS' => 'VMS',
|
|
|
|
'OS_UNIX' => 'Unix',
|
|
|
|
'OS_ATARI' => 'Atari',
|
|
|
|
'OS_MACOS' => 'MacOS',
|
|
|
|
'OS_TOPS20' => 'TOPS20',
|
|
|
|
'OS_WIN32' => 'Win32',
|
|
|
|
'OS_VMCMS' => 'VM/CMS',
|
|
|
|
'OS_ZSYSTEM' => 'Z-System',
|
|
|
|
'OS_CPM' => 'CP/M',
|
|
|
|
'OS_QDOS' => 'QDOS',
|
|
|
|
'OS_RISCOS' => 'RISCOS',
|
|
|
|
'OS_UNKNOWN' => 'Unknown',
|
|
|
|
}
|
|
|
|
unless OS_NAMES.key? os_code then
|
2012-05-18 03:02:56 -04:00
|
|
|
raise "invalid OS_CODE `#{os_code}'"
|
2003-03-28 12:21:24 -05:00
|
|
|
end
|
2012-05-18 15:51:58 -04:00
|
|
|
Logging::message "#{OS_NAMES[os_code]}\n"
|
2003-03-28 12:21:24 -05:00
|
|
|
defines << "OS_CODE=#{os_code}"
|
|
|
|
|
2006-05-25 19:44:08 -04:00
|
|
|
$defs.concat(defines.collect{|d|' -D'+d})
|
2003-03-28 12:21:24 -05:00
|
|
|
|
2016-09-23 10:18:41 -04:00
|
|
|
if zsrc
|
|
|
|
$defs << "-DHAVE_CRC32_COMBINE"
|
|
|
|
$defs << "-DHAVE_ADLER32_COMBINE"
|
|
|
|
$defs << "-DHAVE_TYPE_Z_CRC_T"
|
|
|
|
else
|
|
|
|
have_func('crc32_combine', 'zlib.h')
|
|
|
|
have_func('adler32_combine', 'zlib.h')
|
|
|
|
have_type('z_crc_t', 'zlib.h')
|
|
|
|
end
|
2010-01-19 00:14:29 -05:00
|
|
|
|
2016-09-22 02:35:28 -04:00
|
|
|
create_makefile('zlib') {|conf|
|
|
|
|
if zsrc
|
2016-09-24 09:26:21 -04:00
|
|
|
conf.concat addconf if addconf
|
2016-09-22 02:35:28 -04:00
|
|
|
end
|
|
|
|
conf
|
|
|
|
}
|
2003-03-28 12:21:24 -05:00
|
|
|
|
|
|
|
end
|