Bug #9213

mkmf.rb emits invalid destination directory name for mswin32/64

Added by arton (Akio Tajima) over 6 years ago. Updated 10 months ago.

Target version:
ruby -v:
ruby 2.0.0p353 (2013-11-22) [i386-mswin32_100]


The install process of traditional extended library (=non gem) uses extconf.rb for creating Makefile and install the library by (n)make install.
However it does not work correctly because of FileUtil.mkdir met bad directory name as 'c:c:/...'.

This is caused by DESTDIR and prefix combination.
When one does not specify DESTDIR, rbconfig.rb create it as 'DESTDIR = TOPDIR && TOPDIR[/\A[a-z]:/i] || '' unless defined? DESTDIR' #=> 'C:' or 'D:'.
By the other hand CONFIG['prefix'] is (TOPDIR || DESTDIR + '/usr') so the prefixdir also contains 'c:' or 'd:' ...

The definition for install directories in mkmf.rb is defined as both DESTDIR and CONFIG['prefix'] directory for example '$(DESTDIR)$(vendorarchdir)$(target_prefix)'.
It causes the double drive letter name 'c:c:...'.

While there are some workarounds as using setup.rb or gem, it's harmful for the testing phase of extended libraries.

Updated by arton (Akio Tajima) over 6 years ago

I think the DESTDIR setting is for DOS like prefix.
So this is the patch.

--- 2013-12-05 02:38:38.508908700 +0900
+++ mkmf.rb 2013-12-05 02:38:59.788774499 +0900
@@ -1849,6 +1849,7 @@ VPATH = #{vpath.join(CONFIG['PATH_SEPARA
     prefix = mkintpath(CONFIG["prefix"])
     if destdir = prefix[$dest_prefix_pattern, 1]
       mk << "\nDESTDIR = #{destdir}\n"
+      prefix = prefix[destdir.size..-1]
     mk << "prefix = #{with_destdir(prefix).unspace}\n"
     CONFIG.each do |key, var|

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r44019.
Akio, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

mkmf.rb: strip destdir from prefix

  • lib/mkmf.rb (configuration): strip destdir part from prefix to get rid of duplication. a patch by arton at [ruby-core:58859]. [ruby-core:58856] [Bug #9213]

Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: UNKNOWN, 2.0.0: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: REQUIRED to 1.9.3: UNKNOWN, 2.0.0: DONE

r44019 was backported to ruby_2_0_0 at r44367.

Updated by katonbo (Masahiro Kitajima) over 6 years ago


Sample code


void Init_Sample() {


require "mkmf"


    C:\TMP>ruby -v
 1: ruby 2.0.0p451 (2014-02-24) [i386-mswin32]
    C:\TMP>ruby extconf.rb
 1: creating Makefile
    C:\TMP>nmake /N
 2: Microsoft (R) Program Maintenance Utility   Version 6.00.9782.0
 3: Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
 5:     echo generating Sample-i386-mswin32.def
 6:      \ruby200\bin\ruby -e "puts 'EXPORTS', 'Init_Sample'"  > Sample-i386-mswin32.def
 7:     echo compiling sample.c
 8:      cl -nologo -I. -Ic:/ruby200/include/ruby-2.0.0/i386-mswin32 -Ic:/ruby200/include/ruby-2.0.0/ruby/backward -Ic:/ruby200/include/ruby-2.0.0 -I.  -MD -Zi -W2 -O2b2xg- -G6 -Zm600   -Fosample.obj -c -Tcsample.c
 9:     echo linking shared-object
10:     \ruby200\bin\ruby -run -e rm -- -f
11:      cl -nologo -LD sample.obj msvcrt-ruby200.lib  oldnames.lib user32.lib advapi32.lib shell32.lib ws2_32.lib imagehlp.lib shlwapi.lib  -link -incremental:no -debug -opt:ref -opt:icf -incremental:no -debug -opt:ref -opt:icf -dll -libpath:. -libpath:/ruby200/lib  -implib:Sample-i386-mswin32.lib -pdb:Sample-i386-mswin32.pdb -def:Sample-i386-mswin32.def

6行目と 10行目、$(RUBY) の展開結果にドライブ名が付いていません。

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Status changed from Closed to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)
  • Target version changed from 2.1.0 to 2.2.0

memo: 2.0.0 has not backported r41648 and r41756.


Updated by naruse (Yui NARUSE) over 2 years ago

  • Target version deleted (2.2.0)

Updated by jeremyevans0 (Jeremy Evans) 10 months ago

  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: DONE)
  • Status changed from Assigned to Closed

Also available in: Atom PDF