Skip to content

Instantly share code, notes, and snippets.

@thegedge
Last active June 16, 2016 19:17
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 thegedge/d1297263cd0858a838a5db3e2a4950c7 to your computer and use it in GitHub Desktop.
Save thegedge/d1297263cd0858a838a5db3e2a4950c7 to your computer and use it in GitHub Desktop.
Read -l flags from Makefiles for gems with native extensions
require 'set'
libs = Set.new
Gem::Specification.reject { |spec| spec.extensions.empty? }.each do |spec|
spec.extensions.each do |ext_path|
extconf_rb_path = Pathname.new(spec.gem_dir).join(ext_path)
makefile_path = extconf_rb_path.dirname.join('Makefile')
if makefile_path.readable?
last_was_lib_flag = false
makefile_path.readlines.map(&:strip).each do |line|
next unless line.start_with?('LIBS =')
line.gsub(/\s+/, ' ').sub('LIBS =', '').split.each do |lib|
next if lib.start_with?('-L')
lib = lib[2..-1] if lib.start_with?('-l')
lib = Pathname.new(lib).basename.to_s.split('.').first if lib.include?('/')
libs << lib
end
end
end
end
end
puts libs.to_a.sort.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment