2017-08-20 17:46:57 +00:00
|
|
|
def read_config_file file_name
|
|
|
|
result = Hash[ *IO.readlines(file_name).collect { |line| line.chomp.gsub(/#.*/, "") }.select { |line| !line.empty? }.collect do |line|
|
|
|
|
parts = line.split(/\s*=\s*/, 2).collect { |part| part.gsub(/^\s+/, '').gsub(/\s+$/, '') }
|
|
|
|
key = parts[0].gsub(%r{^export\s+}, '').to_sym
|
|
|
|
value = (parts[1] || '').gsub(%r{^"|"$}, '').gsub(%r{\\"}, '"')
|
|
|
|
[ key, value ]
|
|
|
|
end.flatten ]
|
|
|
|
result.default = ''
|
|
|
|
|
|
|
|
result
|
|
|
|
end
|
2010-07-25 20:43:57 +00:00
|
|
|
|
2017-08-20 17:46:57 +00:00
|
|
|
def read_build_config
|
2021-04-09 16:06:57 +00:00
|
|
|
dir = File.dirname(__FILE__) + '/..'
|
2018-01-22 22:41:32 +00:00
|
|
|
|
2021-04-09 16:06:57 +00:00
|
|
|
fail "build-config not found: please run ./configure" unless File.exists?("#{dir}/build-config")
|
|
|
|
|
|
|
|
config = read_config_file("#{dir}/build-config")
|
|
|
|
config = config.merge(read_config_file("#{dir}/build-config.local")) if File.exists?("#{dir}/build-config.local")
|
2018-01-22 22:41:32 +00:00
|
|
|
|
|
|
|
config
|
2010-07-25 20:43:57 +00:00
|
|
|
end
|
|
|
|
|
2015-11-21 10:56:27 +00:00
|
|
|
def c(idx, default = '')
|
2010-07-25 20:43:57 +00:00
|
|
|
idx_s = idx.to_s
|
|
|
|
var = (ENV[idx_s].nil? ? $config[idx.to_sym] : ENV[idx_s]).to_s
|
2015-11-21 10:56:27 +00:00
|
|
|
var = var.gsub(/\$[\({](.*?)[\)}]/) { c($1) }.gsub(/^\s+/, '').gsub(/\s+$/, '')
|
|
|
|
|
|
|
|
var.empty? ? default : var
|
2010-07-25 20:43:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def c?(idx)
|
|
|
|
c(idx).to_bool
|
|
|
|
end
|