Last active
June 16, 2016 19:17
-
-
Save thegedge/d1297263cd0858a838a5db3e2a4950c7 to your computer and use it in GitHub Desktop.
Read -l flags from Makefiles for gems with native extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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