summaryrefslogtreecommitdiffstats
path: root/ext/configsub.rb
blob: 47689d7ec0c8fb1e3285ed00cbee474b28ebc23f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!./miniruby -ps

BEGIN {
  CONFIG = {}

  RUBY_VERSION.scan(/(\d+)\.(\d+)\.(\d+)/) do
    # overridden if config.status has version
    CONFIG['MAJOR'] = $1
    CONFIG['MINOR'] = $2
    CONFIG['TEENY'] = $3
  end

  File.foreach($config || "config.status") do |line|
    next if /^#/ =~ line
    if /^s[%,]@(\w+)@[%,](.*)[%,][g;]/ =~ line
      name = $1
      val = $2 || ""
      next if /^(INSTALL|DEFS|configure_input|srcdir)$/ =~ name
      val.gsub!(/\$\{([^{}]+)\}/) { "$(#{$1})" }
      CONFIG[name] = val
    end
  end

  CONFIG['top_srcdir'] = File.expand_path($srcdir || ".")
  CONFIG['RUBY_INSTALL_NAME'] = $install_name if $install_name
  CONFIG['RUBY_SO_NAME'] = $so_name if $so_name
  $defout = open($output, 'w') if $output
}

gsub!(/@(\w+)@/) {CONFIG[$1] || $&}

# vi:set sw=2: