Skip to content
Browse files

[enhance] manpages: now builds manpages in standard build directory

  • Loading branch information...
1 parent 198e099 commit babea9c0438099df628c90e59e93a501b7d94b88 Mathieu Baudet committed Jan 5, 2012
Showing with 36 additions and 22 deletions.
  1. +20 −10 manpages/Makefile
  2. +4 −0 manpages/README
  3. +12 −12 manpages/genman.ml
View
30 manpages/Makefile
@@ -1,16 +1,17 @@
-.PHONY: all clean help
+.PHONY: all clean help view
# --
# build the list of target binaries to be documented:
# bin/* and lib/opa/bin/* together with inclusions and exclusions
# --
-BLDDIR=../_build
+BLDDIR ?= ../_build
BINDIR=$(BLDDIR)/bin
EXCLUDE=opa-bin mlstate_platform genproto ocamlbase.top ppdebug-opa ppjs
INCLUDE=opa
BINS=$(INCLUDE) $(filter-out $(EXCLUDE), $(notdir $(wildcard $(BLDDIR)/bin/* $(BLDDIR)/lib/opa/bin/*)))
-TARGETS=$(BINS:=.1)
+TARGETDIR=$(BLDDIR)/man/man1
+TARGETS=$(addprefix $(TARGETDIR)/, $(addsuffix .1, $(BINS)))
all: $(TARGETS)
@@ -20,10 +21,14 @@ help: $(TARGETS:.1=.help)
clean:
rm -f $(TARGETS) $(TARGETS:.1=.help)
+view: $(TARGETS)
+ man $(TARGETS)
+
# --
# first check if a manpage has been written by hand
# --
-%.1: %.man
+$(TARGETDIR)/%.1: %.man
+ @mkdir -p $(TARGETDIR)
cp $< $@
# --
@@ -32,13 +37,15 @@ clean:
$(BLDDIR)/opa/gen_opa_manpage.native: ../opa/gen_opa_manpage.ml
cd ..; bld opa/gen_opa_manpage.native
-opa.1: $(BLDDIR)/opa/gen_opa_manpage.native
+$(TARGETDIR)/opa.1: $(BLDDIR)/opa/gen_opa_manpage.native
+ @mkdir -p $(TARGETDIR)
$< > $@
$(BLDDIR)/opatop/gen_opatop_manpage.native: ../opatop/gen_opatop_manpage.ml
cd ..; bld opatop/gen_opatop_manpage.native
-opatop.1: $(BLDDIR)/opatop/gen_opatop_manpage.native
+$(TARGETDIR)/opatop.1: $(BLDDIR)/opatop/gen_opatop_manpage.native
+ @mkdir -p $(TARGETDIR)
$< > $@
# --
@@ -49,11 +56,14 @@ GENMAN=$(BLDDIR)/manpages/genman.native
$(GENMAN): genman.ml
cd ..; bld -cflags "-w -14" manpages/genman.native
-%.help: $(BLDDIR)/bin/%
+$(TARGETDIR)/%.help: $(BLDDIR)/bin/%
+ @mkdir -p $(TARGETDIR)
$< --help >$@ 2>&1 ||true
-%.help: $(BLDDIR)/lib/opa/bin/%
+$(TARGETDIR)/%.help: $(BLDDIR)/lib/opa/bin/%
+ @mkdir -p $(TARGETDIR)
$< --help >$@ 2>&1 ||true
-%.1: %.help $(GENMAN)
- $(GENMAN) $* > $@
+$(TARGETDIR)/%.1: $(TARGETDIR)/%.help $(GENMAN)
+ @mkdir -p $(TARGETDIR)
+ $(GENMAN) $* $(TARGETDIR)/$* > $@
View
4 manpages/README
@@ -19,6 +19,10 @@ use it (e.g. this is the case for the compiler 'opa')
- XX.options
and the output of 'XX --help' to build a default manpage.
+.Directories
+
+The given Makefile will try to output files in $(BLDDIR)/man/man1
+where BLDDIR evals to ../_build (unless otherwise specified).
.How to live with the default manpage generation
View
24 manpages/genman.ml
@@ -22,9 +22,15 @@ let cmdname =
try
Sys.argv.(1)
with
- _ -> (Printf.eprintf ("Usage: genman %s <cmdname> [summary]\n") Sys.argv.(0); exit 1)
+ _ -> (Printf.eprintf ("Usage: %s <cmdname> [sectionbasename]\n") Sys.argv.(0); exit 1)
-let read_section name = File.content_opt (cmdname ^ "." ^ name)
+let sectionbasename =
+ try
+ Sys.argv.(2)
+ with
+ _ -> cmdname
+
+let read_section name = File.content_opt (sectionbasename ^ "." ^ name)
let help_summary, help_synopsis, help_description, help_options =
match read_section "help" with
@@ -84,21 +90,15 @@ let help_summary, help_synopsis, help_description, help_options =
in
summary, synopsis, description, options
-let summary = try
- Some(Sys.argv.(2))
- with _ ->
- begin match read_section "summary", help_summary with
- None, s when s <> "" -> Some(s)
- | x, _ -> x
- end
+let summary =
+ match read_section "summary", help_summary with
+ None, s when s <> "" -> Some(s)
+ | x, _ -> x
let synopsis =
match read_section "synopsis", help_synopsis with
| None, s when s <> "" -> Some(s)
| x, _ -> x
-(* | Some(s), _ -> Some(s)
- | _, _ -> Some(Printf.sprintf "%s [options]" cmdname)
-*)
let description =
match read_section "description", help_description with

0 comments on commit babea9c

Please sign in to comment.
Something went wrong with that request. Please try again.