Is there any way to install man pages using gem specification?
For example, gem install XXX-1.0.0.gem
should install the man page to the 开发者_运维百科system.
Rubygems currently doesn't support installing manpages for gems.
A patch was submitted to Rubygems a while ago to add support for manpages, but it was rejected.
You can use the gem-man gem to install manpages for gems.
They also offer a "cheating switch" to use the global man: alias man="gem man -s"
I think i have found a solution:
At first, you have to add a native extension to the gem:
my_gem.gemspec:
s.extensions << 'manpage/extconf.rb'
s.files << 'manpage/my_gem.1'
Then gem install
will execute the extconf.rb
and wants to call a Makefile.
make clean
make
make install
So the extconf.rb
can be used to create the Makefile.
You also have to make sure, that there must be at least a dummy Makefile or else the installation will fail.
makefile = "make:\n" \
"\t%s\n" \
"install:\n" \
"\t%s\n" \
"clean:\n" \
"\t%s\n"
if RUBY_PLATFORM =~ /linux/
clean = 'sudo rm -f /usr/local/share/man/man1/my_gem.1.gz'
make = 'gzip my_gem.1'
install = 'sudo cp -r my_gem.1.gz /usr/local/share/man/man1/'
puts
puts 'You need super user privileges to install the manpage for my_gem.'
puts 'Do you want to proceed? (y/n)'
puts 'The gem will be installed anyways.'
input = STDIN.gets.chomp.strip.downcase
if input == 'y' or input == 'yes'
File.write('Makefile', makefile % [make, install, clean])
else
File.write('Makefile', makefile % [':', ':', ':']) # dummy makefile
end
else
File.write('Makefile', makefile % [':', ':', ':']) # dummy makefile
end
精彩评论