diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index f169e10179..7827a93609 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -188,6 +188,8 @@ class Build # Find and link metafiles formula.prefix.install_metafiles formula.buildpath formula.prefix.install_metafiles formula.libexec if formula.libexec.exist? + + normalize_pod2man_outputs!(formula) end end end @@ -217,6 +219,11 @@ class Build rescue raise "#{formula.opt_prefix} not present or broken\nPlease reinstall #{formula.full_name}. Sorry :(" end + + def normalize_pod2man_outputs!(formula) + keg = Keg.new(formula.prefix) + keg.normalize_pod2man_outputs! + end end begin diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index c5ab91a598..4c6b1cbf8a 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -555,6 +555,31 @@ class Keg path.find { |pn| FileUtils.rm_rf pn if pn.basename.to_s == "__pycache__" } end + def normalize_pod2man_outputs! + manpages = Dir[path/"share/man/*/*"] + generated_regex = /^\.\\"\s*Automatically generated by .*\n/ + manpages.each do |f| + manpage = Pathname.new(f) + next unless manpage.file? + + content = manpage.read + content = content.gsub(generated_regex, "") + content = content.lines.map do |line| + next line unless line.start_with?(".TH") + + # Split the line by spaces, but preserve quoted strings + parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/) + next line if parts.length != 6 + + # pod2man embeds the perl version used into the 5th field of the footer + T.must(parts[4]).gsub!(/^"perl v.*"$/, "\"\"") + "#{parts.join(" ")}\n" + end.join + + manpage.atomic_write(content) + end + end + def binary_executable_or_library_files [] end