From: Michael Still this patch adds two new targets to the 2.5 makefiles -- mandocs, and mandocs_install. 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. Note that the two scripts (makeman and split-man) need executable permissions, and I couldn't work out how to make this happen in a mere diff. Also 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/ 25-akpm/CREDITS | 8 ++ 25-akpm/Documentation/DocBook/Makefile | 15 +++ 25-akpm/Documentation/DocBook/man/Makefile | 3 25-akpm/Makefile | 12 ++- 25-akpm/scripts/makeman | 46 +++++++++++ 25-akpm/scripts/split-man | 112 +++++++++++++++++++++++++++++ 6 files changed, 191 insertions(+), 5 deletions(-) diff -puN CREDITS~add-mandocs-target CREDITS --- 25/CREDITS~add-mandocs-target Mon Jul 28 13:24:55 2003 +++ 25-akpm/CREDITS Mon Jul 28 13:24:55 2003 @@ -2981,6 +2981,14 @@ S: #102, 686 W. Maude Ave S: Sunyvale, CA 94086 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 E: storner@image.dk W: http://www.image.dk/~storner/ diff -puN Documentation/DocBook/Makefile~add-mandocs-target Documentation/DocBook/Makefile --- 25/Documentation/DocBook/Makefile~add-mandocs-target Mon Jul 28 13:24:55 2003 +++ 25-akpm/Documentation/DocBook/Makefile Mon Jul 28 13:25:34 2003 @@ -20,10 +20,11 @@ DOCBOOKS := wanbook.sgml z8530book.sgml # file.tmpl --> file.sgml +--> file.ps (psdocs) # +--> file.pdf (pdfdocs) # +--> DIR=file (htmldocs) +# +--> man/ (mandocs) ### # The targets that may be used. -.PHONY: sgmldocs psdocs pdfdocs htmldocs clean mrproper +.PHONY: sgmldocs psdocs pdfdocs htmldocs mandocs clean mrproper BOOKS := $(addprefix $(obj)/,$(DOCBOOKS)) sgmldocs: $(BOOKS) @@ -37,10 +38,15 @@ pdfdocs: $(PDF) HTML := $(patsubst %.sgml, %.html, $(BOOKS)) htmldocs: $(HTML) +MAN := $(patsubst %.sgml, %.9, $(BOOKS)) +mandocs: $(MAN) + ### #External programs used KERNELDOC = scripts/kernel-doc DOCPROC = scripts/docproc +SPLITMAN=$(objtree)/scripts/split-man +MAKEMAN=$(objtree)/scripts/makeman ### # DOCPROC is used for two purposes: @@ -127,6 +133,10 @@ quiet_cmd_db2html = DB2HTML $@ @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \ cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi +%.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 quiet_cmd_fig2eps = FIG2EPS $@ @@ -157,7 +167,7 @@ quiet_cmd_fig2png = FIG2PNG $@ # Help targets as used by the top-level makefile dochelp: @echo ' Linux kernel internal documentation in different formats:' - @echo ' sgmldocs (SGML), psdocs (Postscript), pdfdocs (PDF), htmldocs (HTML)' + @echo ' sgmldocs (SGML), psdocs (Postscript), pdfdocs (PDF), htmldocs (HTML), mandocs (man pages, use mandocs_install to install)' ### # clean and mrproper as used by the top-level makefile @@ -171,6 +181,7 @@ clean-files := $(DOCBOOKS) \ $(patsubst %.sgml, %.ps, $(DOCBOOKS)) \ $(patsubst %.sgml, %.pdf, $(DOCBOOKS)) \ $(patsubst %.sgml, %.html, $(DOCBOOKS)) \ + $(patsubst %.sgml, %.9, $(DOCBOOKS)) \ $(patsubst %.fig,%.eps, $(IMG-parportbook)) \ $(patsubst %.fig,%.png, $(IMG-parportbook)) \ $(C-procfs-example) diff -puN /dev/null Documentation/DocBook/man/Makefile --- /dev/null Thu Apr 11 07:25:15 2002 +++ 25-akpm/Documentation/DocBook/man/Makefile Mon Jul 28 13:24:56 2003 @@ -0,0 +1,3 @@ +.PHONY: clean + +clean-files := *.9.gz *.sgml manpage.links manpage.refs diff -puN Makefile~add-mandocs-target Makefile --- 25/Makefile~add-mandocs-target Mon Jul 28 13:24:55 2003 +++ 25-akpm/Makefile Mon Jul 28 13:24:56 2003 @@ -209,6 +209,7 @@ AFLAGS_MODULE = $(MODFLAGS) LDFLAGS_MODULE = -r CFLAGS_KERNEL = AFLAGS_KERNEL = +MAKEMAN = scripts/makeman NOSTDINC_FLAGS = -nostdinc -iwithprefix include @@ -237,7 +238,7 @@ noconfig_targets := xconfig gconfig menu defconfig allyesconfig allnoconfig allmodconfig \ clean mrproper distclean rpm \ help tags TAGS cscope sgmldocs psdocs pdfdocs htmldocs \ - checkconfig checkhelp checkincludes + mandocs mandocs_install checkconfig checkhelp checkincludes RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \) -prune -o RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS @@ -687,7 +688,9 @@ MRPROPER_DIRS += \ # clean - Delete all intermediate files # -clean-dirs += $(addprefix _clean_,$(ALL_SUBDIRS) Documentation/DocBook scripts) +clean-dirs += $(addprefix _clean_,$(ALL_SUBDIRS) \ + Documentation/DocBook Documentation/DocBook/man \ + scripts) .PHONY: $(clean-dirs) clean archclean mrproper archmrproper distclean $(clean-dirs): $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) @@ -830,9 +833,12 @@ help: # Documentation targets # --------------------------------------------------------------------------- -sgmldocs psdocs pdfdocs htmldocs: scripts/docproc FORCE +sgmldocs psdocs pdfdocs htmldocs mandocs: scripts/docproc FORCE $(Q)$(MAKE) $(build)=Documentation/DocBook $@ +mandocs_install: mandocs + $(MAKEMAN) install Documentation/DocBook/man + # Scripts to check various things for consistency # --------------------------------------------------------------------------- diff -puN /dev/null scripts/makeman --- /dev/null Thu Apr 11 07:25:15 2002 +++ 25-akpm/scripts/makeman Mon Jul 28 13:24:56 2003 @@ -0,0 +1,46 @@ +#!/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] \n"; +} + +if( ! -d "$ARGV[1]" ){ + die "Output directory \"$ARGV[1]\" does not exist\n"; +} + +if($ARGV[0] eq "convert"){ + open LISTING, "grep \"\" $ARGV[2] |"; + while(){ + 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] \n"; +} + +print "Done\n"; diff -puN /dev/null scripts/split-man --- /dev/null Thu Apr 11 07:25:15 2002 +++ 25-akpm/scripts/split-man Mon Jul 28 13:24:56 2003 @@ -0,0 +1,112 @@ +#!/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 \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(){ + # Starting modes + if(//){ + $mode = 1; + } + elsif(//){ + $mode = 2; + } + elsif(/]*>([^<]*)<.*$/){ + $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 "\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 "9\n"; + } + if(/<\/refentry>/){ + $front =~ s///; + $front =~ s/<\/legalnotice>//; + print REF <About this document +$front + +If you have comments on the formatting of this manpage, then please contact +Michael Still (mikal\@stillhq.com). + + + +This documentation was generated with kernel version $ARGV[2]. + + +EOF + } + + # For some reason, we title the synopsis twice in the main DocBook + if(! /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]`; _