Skip to content

Commit 5318a48

Browse files
committed
Compress manpages automatically
1 parent 022ab41 commit 5318a48

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

tool/rbinstall.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ def $mflags.defined?(var)
173173
end
174174
end
175175

176+
Compressors = {".gz"=>"gzip", ".bz2"=>"bzip2"}
177+
def Compressors.for(type)
178+
ext = File.extname(type)
179+
if compress = fetch(ext, nil)
180+
[type.chomp(ext), ext, compress]
181+
else
182+
[type, *find {|_, z| system(z, in: IO::NULL, out: IO::NULL)}]
183+
end
184+
end
185+
176186
$install_procs = Hash.new {[]}
177187
def install?(*types, &block)
178188
unless types.delete(:nodefault)
@@ -993,14 +1003,10 @@ def (bins = []).add(name)
9931003
mdocs = Dir["#{srcdir}/man/*.[1-9]"]
9941004
prepare "manpages", mandir, ([] | mdocs.collect {|mdoc| mdoc[/\d+$/]}).sort.collect {|sec| "man#{sec}"}
9951005

996-
case $mantype
997-
when /\.(?:(gz)|bz2)\z/
998-
compress = $1 ? "gzip" : "bzip2"
999-
suffix = $&
1000-
end
1006+
mantype, suffix, compress = Compressors.for($mantype)
10011007
mandir = File.join(mandir, "man")
10021008
has_goruby = File.exist?(goruby_install_name+exeext)
1003-
require File.join(srcdir, "tool/mdoc2man.rb") if /\Adoc\b/ !~ $mantype
1009+
require File.join(srcdir, "tool/mdoc2man.rb") if /\Adoc\b/ !~ mantype
10041010
mdocs.each do |mdoc|
10051011
next unless File.file?(mdoc) and File.read(mdoc, 1) == '.'
10061012
base = File.basename(mdoc)
@@ -1012,7 +1018,7 @@ def (bins = []).add(name)
10121018
destname = ruby_install_name.sub(/ruby/, base.chomp(".#{section}"))
10131019
destfile = File.join(destdir, "#{destname}.#{section}")
10141020

1015-
if /\Adoc\b/ =~ $mantype
1021+
if /\Adoc\b/ =~ mantype
10161022
if compress
10171023
begin
10181024
w = IO.popen(compress, "rb", in: mdoc, &:read)

0 commit comments

Comments
 (0)