Hi,

At Wed, 26 Oct 2005 07:42:03 +0900,
Daniel Berger wrote in [ruby-talk:162622]:
> Ok, but you can generate a .lib file from a .def, and you can generate
> a .def from a .dll.  Here's a script I cobbled together that did the
> trick:

Of course you can, but I don't think it should be done
silently by mkmf.rb.  It belongs to setting up of a particular
library, not building an extension for it.

> # Create a .def file from the results of a 'link -dump -exports'

Actually, it calls dumpbin.exe.

> # Create a .lib file from a .def file.  Note that the lib command doesn't
> # seem to like long path names, so we'll shorten them.

Really?

  $ lib -machine:x86 -def:../stable-build/i686-mswin32/msvcrt-ruby18.def -out:../stable-build/i686-mswin32/msvcrt-ruby18.lib
  Microsoft (R) Library Manager Version 7.10.2240.8
  Copyright (C) Microsoft Corporation.  All rights reserved.

     Creating library ../stable-build/i686-mswin32/msvcrt-ruby18.lib and object ../stable-build/i686-mswin32/msvcrt-ruby18.exp

It's possible to tweak win32/mkexports.rb to accept DLL files
as well as object files.


Index: win32/mkexports.rb =================================================================== RCS file: /cvs/ruby/src/ruby/win32/mkexports.rb,v retrieving revision 1.4 diff -U2 -p -u -r1.4 mkexports.rb --- win32/mkexports.rb 18 Jun 2002 10:23:31 -0000 1.4 +++ win32/mkexports.rb 26 Oct 2005 02:19:04 -0000 @@ -4,13 +4,21 @@ SYM = {} objs = ARGV.collect {|s| s.tr('/', '\\')} -IO.foreach("|dumpbin -symbols " + objs.join(' ')) do |l| - next if /^[0-9A-F]+ 0+ UNDEF / =~ l - next unless l.sub!(/.*\sExternal\s+\|\s+/, '') - if l.sub!(/^_/, '') - next if /@.*@/ =~ l || /@[0-9a-f]{16}$/ =~ l - elsif !l.sub!(/^(\S+) \([^@?\`\']*\)$/, '\1') - next +filetype = nil +IO.foreach("|dumpbin -symbols -exports " + objs.join(' ')) do |l| + if (filetype = l[/^File Type: (.+)/, 1])..(/^\f/ =~ l) + case filetype + when /OBJECT/ + next if /^[0-9A-F]+ 0+ UNDEF / =~ l + next unless l.sub!(/.*\sExternal\s+\|\s+/, '') + if l.sub!(/^_/, '') + next if /@.*@/ =~ l || /@[0-9a-f]{16}$/ =~ l + elsif !l.sub!(/^(\S+) \([^@?\`\']*\)$/, '\1') + next + end + when /DLL/ + next unless l.sub!(/^\s*\d+\s+[[:xdigit:]]+\s+[[:xdigit:]]+\s+/, '') + end + SYM[l.strip] = true end - SYM[l.strip] = true end
-- Nobu Nakada