def append_env(name, value)
  env_name = name.to_s.upcase
  sane_value = value.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
  old_value = ENV[env_name] || ''
  unless old_value.include?(sane_value)
    ENV[env_name] = "#{sane_value};" + old_value
  end
end

def activate(path)
  vars = {
    :path => File.join(RubyInstaller::ROOT, path, 'bin'),
    :cpath => File.join(RubyInstaller::ROOT, path, 'include'),
    :library_path => File.join(RubyInstaller::ROOT, path, 'lib')
  }

  vars.delete_if { |k, v| !File.directory?(v) }
  vars.each do |k, v|
    append_env(k, v)
  end
end

def append_env(name, value, delim=';')
  env_name = name.to_s.upcase
  sane_value = value.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
  old_value = ENV[env_name] || ''
  unless old_value.include?(sane_value)
    ENV[env_name] = "#{sane_value}#{delim}" + old_value
  end
end

def activate(path)
  vars = {
    :path => File.join(RubyInstaller::ROOT, path, 'bin'),
    :cpath => File.join(RubyInstaller::ROOT, path, 'include'),
    :ldflags => File.join(RubyInstaller::ROOT, path, 'lib')
  }.reject { |k, v| !File.directory?(v) }

  vars.each do |k, v|
    case k
    when :ldflags
      append_env(k, "-L#{v}", ' ')
    else
      append_env(k, v)
    end
  end
end

Use LDFLAGS rather than LIBRARY_PATH.
Use LDFLAGS rather than LIBRARY_PATH.

The MinGW-w64 toolchain currently ignores LIBRARY_PATH, causing
build failures because the autotools aren't able to find the
required libraries. This patch explicitly sets the library search
paths via -L options in the LDFLAGS env var.
