diff --git a/tool/mkconfig.rb b/tool/mkconfig.rb
index e6d61c5..1517669 100755
--- a/tool/mkconfig.rb
+++ b/tool/mkconfig.rb
@@ -73,6 +73,7 @@ File.foreach "config.status" do |line|
     when /^sitearch$/; val = '$(arch)' if val.empty?
     when /^DESTDIR$/; next
     when /RUBYGEMS/; next
+    when /^sysconfdir$/; val = '$(kegdir)/etc'
     end
     case val
     when /^\$\(ac_\w+\)$/; next
@@ -191,6 +192,7 @@ module RbConfig
 ]
 print "  # Ruby installed directory.\n"
 print "  TOPDIR = File.dirname(__FILE__).chomp!(#{relative_archdir.dump})\n"
+print "  KEGDIR = TOPDIR ? File.dirname(TOPDIR) : nil\n"
 print "  # DESTDIR on make install.\n"
 print "  DESTDIR = ", (drive ? "TOPDIR && TOPDIR[/\\A[a-z]:/i] || " : ""), "'' unless defined? DESTDIR\n"
 print <<'ARCH' if universal
@@ -293,6 +295,7 @@ print <<EOS
   CONFIG["platform"] = #{platform || '"$(arch)"'}
   CONFIG["archdir"] = "$(rubyarchdir)"
   CONFIG["topdir"] = File.dirname(__FILE__)
+  CONFIG["kegdir"] = KEGDIR || "$(prefix)"
   # Almost same with CONFIG. MAKEFILE_CONFIG has other variable
   # reference like below.
   #
