Skip to content

Instantly share code, notes, and snippets.

@kostya
Last active April 29, 2017 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kostya/cf691c9ac0a3dc4056102091f71f7f4e to your computer and use it in GitHub Desktop.
Save kostya/cf691c9ac0a3dc4056102091f71f7f4e to your computer and use it in GitHub Desktop.
require "c/dlfcn"
require "find_lib" # shard kostya/find_lib
def libicu_files
{% if flag?(:darwin) %}
FindLib.find("icucore")
{% elsif flag?(:windows) %}
FindLib.find(["icuuc", "icuin"])
{% else %}
FindLib.find(["icui18n", "icutu"])
{% end %}
end
TESTFUNC = "u_init"
def suffixes(path)
res = [""]
match = path.match(/(\d\d)\.#{FindLib::PLATFORM_SUFFIX}/) || path.match(/#{FindLib::PLATFORM_SUFFIX}\.(\d\d)/)
if match
version = match[1]
res << "_#{version}"
res << "_#{version[0]}_#{version[1]}"
res << "_#{version.split('.')[0]}"
end
res
end
def detect_suffix(path)
handle = LibC.dlopen(path, LibC::RTLD_LAZY)
return if handle.null?
suffixes(path).each do |suffix|
return suffix unless LibC.dlsym(handle, "#{TESTFUNC}#{suffix}").null?
end
nil
ensure
LibC.dlclose(handle)
end
puts "files - #{libicu_files.inspect}"
libicu_files.each do |path|
suffix = detect_suffix(path)
if suffix
puts "suffix - #{suffix.inspect}"
exit 0
end
end
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment