Commit cc79cb64 authored by Sam Ravnborg's avatar Sam Ravnborg

docbook: Added support for generating man files

Originally by Michael Still <mikal@stillhq.com>

This patch adds two new targets to the docbook makefile -- mandocs, and
installmandocs. The targets require two new perl scripts in the scripts/
directory, but in return we get a series of man pages for kernel
functions, which are installed in man section 9. This is a good thing, as
many programmers expect documentation to be available with man, and
hunting through various PS or PDF documents to find the documentation for
the function you want can be quite frustrating.

The man pages are just extracted from the various existing DocBook SGML
documents, which are generated by kernel-doc. You also need to have
docbook2man installed on your machine.

Please note the formatting is not perfect, but I will tweak
other stuff later with further patches -- this is just an initial
implementation.

Sample output (HTMLised) can be found at
http://www.stillhq.com/linux/mandocs/2.5.68/ and
http://www.stillhq.com/linux/mandocs/2.5.70/
parent ee598ace
...@@ -2981,6 +2981,14 @@ S: #102, 686 W. Maude Ave ...@@ -2981,6 +2981,14 @@ S: #102, 686 W. Maude Ave
S: Sunyvale, CA 94086 S: Sunyvale, CA 94086
S: USA S: USA
N: Michael Still
E: mikal@stillhq.com
W: http://www.stillhq.com
D: Various janitorial patches
D: mandocs and mandocs_install build targets
S: (Email me and ask)
S: Australia
N: Henrik Storner N: Henrik Storner
E: storner@image.dk E: storner@image.dk
W: http://www.image.dk/~storner/ W: http://www.image.dk/~storner/
......
...@@ -20,10 +20,11 @@ DOCBOOKS := wanbook.sgml z8530book.sgml mcabook.sgml videobook.sgml \ ...@@ -20,10 +20,11 @@ DOCBOOKS := wanbook.sgml z8530book.sgml mcabook.sgml videobook.sgml \
# file.tmpl --> file.sgml +--> file.ps (psdocs) # file.tmpl --> file.sgml +--> file.ps (psdocs)
# +--> file.pdf (pdfdocs) # +--> file.pdf (pdfdocs)
# +--> DIR=file (htmldocs) # +--> DIR=file (htmldocs)
# +--> man/ (mandocs)
### ###
# The targets that may be used. # The targets that may be used.
.PHONY: sgmldocs psdocs pdfdocs htmldocs clean mrproper .PHONY: sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs
BOOKS := $(addprefix $(obj)/,$(DOCBOOKS)) BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
sgmldocs: $(BOOKS) sgmldocs: $(BOOKS)
...@@ -37,10 +38,18 @@ pdfdocs: $(PDF) ...@@ -37,10 +38,18 @@ pdfdocs: $(PDF)
HTML := $(patsubst %.sgml, %.html, $(BOOKS)) HTML := $(patsubst %.sgml, %.html, $(BOOKS))
htmldocs: $(HTML) htmldocs: $(HTML)
MAN := $(patsubst %.sgml, %.9, $(BOOKS))
mandocs: $(MAN)
installmandocs: mandocs
$(MAKEMAN) install Documentation/DocBook/man
### ###
#External programs used #External programs used
KERNELDOC = scripts/kernel-doc KERNELDOC = scripts/kernel-doc
DOCPROC = scripts/docproc DOCPROC = scripts/docproc
SPLITMAN = $(PERL) $(srctree)/scripts/split-man
MAKEMAN = $(PERL) $(srctree)/scripts/makeman
### ###
# DOCPROC is used for two purposes: # DOCPROC is used for two purposes:
...@@ -127,6 +136,13 @@ quiet_cmd_db2html = DB2HTML $@ ...@@ -127,6 +136,13 @@ quiet_cmd_db2html = DB2HTML $@
@if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \ @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
###
# Rule to generate man files - output is placed in the man subdirectory
%.9: %.sgml
$(SPLITMAN) $< $(objtree)/Documentation/DocBook/man "$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)"
$(MAKEMAN) convert $(objtree)/Documentation/DocBook/man $<
### ###
# Rules to generate postscripts and PNG imgages from .fig format files # Rules to generate postscripts and PNG imgages from .fig format files
quiet_cmd_fig2eps = FIG2EPS $@ quiet_cmd_fig2eps = FIG2EPS $@
...@@ -157,10 +173,10 @@ quiet_cmd_fig2png = FIG2PNG $@ ...@@ -157,10 +173,10 @@ quiet_cmd_fig2png = FIG2PNG $@
# Help targets as used by the top-level makefile # Help targets as used by the top-level makefile
dochelp: dochelp:
@echo ' Linux kernel internal documentation in different formats:' @echo ' Linux kernel internal documentation in different formats:'
@echo ' sgmldocs (SGML), psdocs (Postscript), pdfdocs (PDF), htmldocs (HTML)' @echo ' sgmldocs (SGML), psdocs (Postscript), pdfdocs (PDF)'
@echo ' htmldocs (HTML), mandocs (man pages, use installmandocs to install)'
### ###
# clean and mrproper as used by the top-level makefile
# Temporary files left by various tools # Temporary files left by various tools
clean-files := $(DOCBOOKS) \ clean-files := $(DOCBOOKS) \
$(patsubst %.sgml, %.dvi, $(DOCBOOKS)) \ $(patsubst %.sgml, %.dvi, $(DOCBOOKS)) \
...@@ -171,6 +187,7 @@ clean-files := $(DOCBOOKS) \ ...@@ -171,6 +187,7 @@ clean-files := $(DOCBOOKS) \
$(patsubst %.sgml, %.ps, $(DOCBOOKS)) \ $(patsubst %.sgml, %.ps, $(DOCBOOKS)) \
$(patsubst %.sgml, %.pdf, $(DOCBOOKS)) \ $(patsubst %.sgml, %.pdf, $(DOCBOOKS)) \
$(patsubst %.sgml, %.html, $(DOCBOOKS)) \ $(patsubst %.sgml, %.html, $(DOCBOOKS)) \
$(patsubst %.sgml, %.9, $(DOCBOOKS)) \
$(patsubst %.fig,%.eps, $(IMG-parportbook)) \ $(patsubst %.fig,%.eps, $(IMG-parportbook)) \
$(patsubst %.fig,%.png, $(IMG-parportbook)) \ $(patsubst %.fig,%.png, $(IMG-parportbook)) \
$(C-procfs-example) $(C-procfs-example)
...@@ -178,3 +195,6 @@ clean-files := $(DOCBOOKS) \ ...@@ -178,3 +195,6 @@ clean-files := $(DOCBOOKS) \
ifneq ($(wildcard $(patsubst %.html,%,$(HTML))),) ifneq ($(wildcard $(patsubst %.html,%,$(HTML))),)
clean-rule := rm -rf $(wildcard $(patsubst %.html,%,$(HTML))) clean-rule := rm -rf $(wildcard $(patsubst %.html,%,$(HTML)))
endif endif
#man put files in man subdir - traverse down
subdir- := man/
# Rules are put in Documentation/DocBook
clean-files := *.9.gz *.sgml manpage.links manpage.refs
...@@ -236,7 +236,7 @@ depfile = $(subst $(comma),_,$(@D)/.$(@F).d) ...@@ -236,7 +236,7 @@ depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
noconfig_targets := xconfig gconfig menuconfig config oldconfig randconfig \ noconfig_targets := xconfig gconfig menuconfig config oldconfig randconfig \
defconfig allyesconfig allnoconfig allmodconfig \ defconfig allyesconfig allnoconfig allmodconfig \
clean mrproper distclean rpm \ clean mrproper distclean rpm \
help tags TAGS cscope sgmldocs psdocs pdfdocs htmldocs \ help tags TAGS cscope %docs \
checkconfig checkhelp checkincludes checkconfig checkhelp checkincludes
RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \) -prune -o RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \) -prune -o
...@@ -833,7 +833,7 @@ help: ...@@ -833,7 +833,7 @@ help:
# Documentation targets # Documentation targets
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
sgmldocs psdocs pdfdocs htmldocs: scripts/docproc FORCE %docs: scripts/docproc FORCE
$(Q)$(MAKE) $(build)=Documentation/DocBook $@ $(Q)$(MAKE) $(build)=Documentation/DocBook $@
# Scripts to check various things for consistency # Scripts to check various things for consistency
......
#!/usr/bin/perl
use strict;
## Copyright (C) Michael Still (mikal@stillhq.com)
## Released under the terms of the GNU GPL
##
## A script to make or install the manpages extracted by split-man
##
## Arguements: $1 -- the word "convert" or "install"
## $2 -- the directory containing the SGML files for the manpages
## $3 -- the filename which contained the sgmldoc output
## (I need this so I know which manpages to convert)
my($LISTING);
if($ARGV[0] eq ""){
die "Usage: makeman [convert | install] <dir> <file>\n";
}
if( ! -d "$ARGV[1]" ){
die "Output directory \"$ARGV[1]\" does not exist\n";
}
if($ARGV[0] eq "convert"){
open LISTING, "grep \"<refentrytitle>\" $ARGV[2] |";
while(<LISTING>){
s/<\/.*$//;
s/^.*>//;
s/\.sgml//;
s/struct //;
s/typedef //;
chomp;
print "Processing $_\n";
system("cd $ARGV[1]; docbook2man $_.sgml; gzip -f $_.9\n");
}
}
elsif($ARGV[0] eq "install"){
system("mkdir -p /usr/local/man/man9/; install $ARGV[1]/*.9.gz /usr/local/man/man9/");
}
else{
die "Usage: makeman [convert | install] <dir> <file>\n";
}
print "Done\n";
#!/usr/bin/perl
use strict;
## Copyright (C) Michael Still (mikal@stillhq.com)
## Released under the terms of the GNU GPL
##
## Hoon through the specified DocBook SGML file, and split out the
## man pages. These can then be processed into groff format, and
## installed if desired...
##
## Arguements: $1 -- the name of the sgml file
## $2 -- the directory to put the generated SGML files in
## $3 -- kernel version
my($SGML, $REF, $front, $refdata, $mode, $filename);
if(($ARGV[0] eq "") || ($ARGV[1] eq "") || ($ARGV[2] eq "")){
die "Usage: split-man <sgml file> <output dir> <kernel version>\n";
}
open SGML, "< $ARGV[0]" or die "Could not open input file \"$ARGV[0]\"\n";
if( ! -d "$ARGV[1]" ){
die "Output directory \"$ARGV[1]\" does not exist\n";
}
# Possible modes:
# 0: Looking for input I care about
# 1: Inside book front matter
# 2: Inside a refentry
# 3: Inside a refentry, and we know the filename
$mode = 0;
$refdata = "";
$front = "";
while(<SGML>){
# Starting modes
if(/<legalnotice>/){
$mode = 1;
}
elsif(/<refentry>/){
$mode = 2;
}
elsif(/<refentrytitle><phrase[^>]*>([^<]*)<.*$/){
$mode = 3;
$filename = $1;
$filename =~ s/struct //;
$filename =~ s/typedef //;
print "Found manpage for $filename\n";
open REF, "> $ARGV[1]/$filename.sgml" or
die "Couldn't open output file \"$ARGV[1]/$filename.sgml\": $!\n";
print REF "<!DOCTYPE refentry PUBLIC \"-//Davenport//DTD DocBook V3.0//EN\">\n\n";
print REF "$refdata";
$refdata = "";
}
# Extraction
if($mode == 1){
$front = "$front$_";
}
elsif($mode == 2){
$refdata = "$refdata$_";
}
elsif($mode == 3){
# There are some fixups which need to be applied
if(/<\/refmeta>/){
print REF "<manvolnum>9</manvolnum>\n";
}
if(/<\/refentry>/){
$front =~ s/<legalnotice>//;
$front =~ s/<\/legalnotice>//;
print REF <<EOF;
<refsect1><title>About this document</title>
$front
<para>
If you have comments on the formatting of this manpage, then please contact
Michael Still (mikal\@stillhq.com).
</para>
<para>
This documentation was generated with kernel version $ARGV[2].
</para>
</refsect1>
EOF
}
# For some reason, we title the synopsis twice in the main DocBook
if(! /<title>Synopsis<\/title>/){
if(/<refentrytitle>/){
s/struct //;
s/typedef //;
}
print REF "$_";
}
}
# Ending modes
if(/<\/legalnotice>/){
$mode = 0;
}
elsif(/<\/refentry>/){
$mode = 0;
close REF;
}
}
# And make sure we don't process this unnessesarily
$ARGV[0] =~ s/\.sgml/.9/;
`touch $ARGV[0]`;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment