libk  Diff

Differences From Artifact [b795aa8a1c]:

To Artifact [790e90297c]:


     2      2   (test -d global && test -f build.sh) || {
     3      3   	echo >&2 "($0) run $me from root of libk source directory"
     4      4   	exit 1
     5      5   }
     6      6   
     7      7   . global/common.sh
     8      8   reqpack cmark "generate documentation"
     9         -
            9  +check gen "a directory for generated build dependencies"
    10     10   
    11     11   file="$1"
    12     12   filename="$(basename "$file")"
    13     13   stem=${filename%%.md}
    14         -mandest="$out/doc/man"
    15         -section=${section:-4}
    16         -out="$mandest/$stem.$section"
           14  +
           15  +mandest=${out_manpage:-"$out/doc/man"}
           16  +htmldest=${out_html:-"$out/doc/html"}
           17  +pdfdest=${out_pdf:-"$out/doc/pdf"}
           18  +
           19  +section=${manual_section:-4}
           20  +man="$mandest/$stem.$section"
           21  +html="$htmldest/$stem.html"
           22  +pdf="$pdfdest/$stem.pdf"
           23  +fmt="$gen/$stem.tmp"
           24  +
    17     25   desc_rec="$(grep -m1 "^$stem:" global/modules)"
    18     26   if test "$desc_rec" != ""; then
    19     27   	desc=" - $(echo $desc_rec | cut -d: -f4)"
    20     28   else
    21     29   	desc=""
    22     30   fi
    23     31   date="$(date -r"$file" "+%d %A %Y")"
    24     32   
    25         -mkdir -p "$mandest"
    26     33   
    27         -echo  >"$out" ".TH ${stem^^} \"$section\" \"$date\" \"hale.su libk [r$build]\" \"modules\""
           34  +echo  >"$fmt" ".TH ${stem^^} \"$section\" \"$date\" \"hale.su libk [r$build]\" \"modules\""
    28     35   
    29         -echo >>"$out" ".SH NAME"
    30         -echo >>"$out" "$stem$desc"
    31         -echo >>"$out" ".SH SYNOPSIS" 
           36  +echo >>"$fmt" ".SH NAME"
           37  +echo >>"$fmt" "$stem$desc"
           38  +echo >>"$fmt" ".SH SYNOPSIS" 
    32     39   
    33     40   dhead=$(grep -m1 -n "^# description$" "$file")
    34     41   if test $? -eq 0; then
    35     42   	descline=$(echo "$dhead" | cut -d: -f1)
    36     43   	offset=1
    37     44   else
    38     45   	descline=$(grep -m2 -n "^#" "$file" | tail -n1 | cut -d: -f1)
    39     46   	offset=0
    40     47   fi
    41     48   
    42         -tail -n+2 $file | head -n$(expr $descline - 2) | cmark -t man >>"$out"
           49  +tail -n+2 $file | head -n$(expr $descline - 2) | cmark -t man >>"$fmt"
           50  +
           51  +echo >>"$fmt" ".SH DESCRIPTION"
           52  +
           53  +tail -n+$(expr $descline + $offset) "$file"  | cmark -t man >> "$fmt"
           54  +
           55  +test "$doc_html" = "yes" && {
           56  +	mkdir -p "$htmldest"
           57  +	groff -Thtml -Kutf8 -m man "$fmt" > "$html"
           58  +	say "wrote html page for $stem to $html"
           59  +}
    43     60   
    44         -echo >>"$out" ".SH DESCRIPTION"
           61  +test "$doc_pdf" = "yes" && {
           62  +	mkdir -p "$pdfdest"
           63  +	groff -Tpdf  -Kutf8 -m man "$fmt" > "$pdf"
           64  +	say "wrote pdf for $stem to $pdf"
           65  +}
    45     66   
    46         -tail -n+$(expr $descline + $offset) "$file"  | cmark -t man >> "$out"
           67  +test "$doc_man" = "yes" && {
           68  +	mkdir -p "$mandest"
    47     69   
    48         -if has gzip; then
    49         -	gzip -f "$out"
    50         -	out="$out.gz"
    51         -fi
           70  +	if has gzip; then
           71  +		man="$man.gz"
           72  +		gzip -c -f "$fmt" > "$man"
           73  +	else
           74  +		mv "$fmt" "$man"
           75  +	fi
    52     76   
    53         -say "wrote manpage for $stem to $out"
           77  +	say "wrote manpage for $stem to $man"
           78  +}