| 1 |
#!/bin/sh |
| 2 |
#emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- |
| 3 |
#ex: set sts=4 ts=4 sw=4 noet: |
| 4 |
#-------------------------- =+- Shell script -+= -------------------------- |
| 5 |
# |
| 6 |
# @file gen_manpage.sh |
| 7 |
# @date Thu Nov 3 21:46:15 2011 |
| 8 |
# @brief |
| 9 |
# |
| 10 |
# |
| 11 |
# Yaroslav Halchenko Dartmouth |
| 12 |
# web: http://www.onerussian.com College |
| 13 |
# e-mail: [email protected] ICQ#: 60653192 |
| 14 |
# |
| 15 |
# DESCRIPTION (NOTES): |
| 16 |
# |
| 17 |
# A little helper to generate all needed manpages for CMTK |
| 18 |
# |
| 19 |
# COPYRIGHT: Yaroslav Halchenko 2011 |
| 20 |
# |
| 21 |
# LICENSE: MIT |
| 22 |
# |
| 23 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 24 |
# of this software and associated documentation files (the "Software"), to deal |
| 25 |
# in the Software without restriction, including without limitation the rights |
| 26 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 27 |
# copies of the Software, and to permit persons to whom the Software is |
| 28 |
# furnished to do so, subject to the following conditions: |
| 29 |
# |
| 30 |
# The above copyright notice and this permission notice shall be included in |
| 31 |
# all copies or substantial portions of the Software. |
| 32 |
# |
| 33 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 34 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 35 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 36 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 37 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 38 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 39 |
# THE SOFTWARE. |
| 40 |
# |
| 41 |
#-----------------\____________________________________/------------------ |
| 42 |
|
| 43 |
set -eu |
| 44 |
|
| 45 |
MANDIR=$PWD/debian/manpages |
| 46 |
CMTK_LIBDIR=$PWD/debian/cmtk/usr/lib/cmtk |
| 47 |
CMTK_BINDIR=$CMTK_LIBDIR/bin |
| 48 |
export CMTK_LIBDIR CMTK_BINDIR MANDIR |
| 49 |
|
| 50 |
# Generate manpages for all tools |
| 51 |
mkdir -p $MANDIR |
| 52 |
|
| 53 |
/bin/ls $CMTK_BINDIR/* \ |
| 54 |
| grep -v triplanar \ |
| 55 |
| while read b; do |
| 56 |
LD_LIBRARY_PATH=$CMTK_LIBDIR \ |
| 57 |
$b --man >| $MANDIR/cmtk-$(basename $b).1 \ |
| 58 |
|| echo "Manpage for $b -- FAILED"; |
| 59 |
done |
| 60 |
|
| 61 |
# Some didn't generate ;) |
| 62 |
find $MANDIR -size 0 -delete |
| 63 |
|
| 64 |
# Generate the ultimate manpage giving a brief description for all of |
| 65 |
# the tools |
| 66 |
rm -f $MANDIR/cmtk.1 |
| 67 |
{ |
| 68 |
head -1 $MANDIR/cmtk-warp.1 | sed -e 's,warp,CMTK,g' |
| 69 |
cat <<EOF |
| 70 |
.SH NAME |
| 71 |
cmtk \- the Computational Morphometry Toolkit |
| 72 |
.SH SYNOPSIS |
| 73 |
\fBcmtk\fR <command> [options] |
| 74 |
.SH DESCRIPTION |
| 75 |
This helper script provides a unified access to all command line tools provided by CMTK. Please specify CMTK's command to run and its options. See \fBcmtk-<command>(1)\fR manpage or output of \fBcmtk <command> --help\fR for <command> specific options |
| 76 |
.SH COMMANDS |
| 77 |
EOF |
| •78 |
/bin/ls $MANDIR/*.1 | grep -v -e 'cmtk\.1' | LC_ALL=C sort | while read f; do |
| 79 |
descr="$(grep -a -A1 '.SH DESCRIPTION' $f| tail -n 1)" |
| 80 |
cmd=${f%.*} |
| 81 |
cmd=${cmd##*cmtk-} |
| 82 |
cat <<EOF |
| 83 |
.TP 5 |
| 84 |
\fB$cmd\fR |
| 85 |
$descr |
| 86 |
EOF |
| 87 |
done |
| 88 |
# Trailer |
| 89 |
sed -ne '/.SH AUTHORS/,$p' $MANDIR/cmtk-warp.1 |
| 90 |
|
| 91 |
} >| $MANDIR/cmtk.1 |