2012-12-28 09:31:13 +08:00
#!/bin/sh
# This script is run as part of the build process
2013-01-04 07:17:48 +08:00
if test $# -eq 0
then
# Use fish's defaults
DOXYFILE = Doxyfile.help
INPUTDIR = doc_src
OUTPUTDIR = share
echo " Using defaults: $0 ${ DOXYFILE } ${ INPUTDIR } ${ OUTPUTDIR } "
elif test $# -eq 3
then
DOXYFILE = " $1 "
INPUTDIR = " $2 "
OUTPUTDIR = " $3 "
else
echo " Usage: $0 doxygen_file input_directory output_directory "
exit 1
2012-12-28 09:31:13 +08:00
fi
2013-02-17 05:35:30 +08:00
# Determine which man pages we don't want to generate.
# on OS X, don't make a man page for open, since we defeat fish's open function on OS X.
2016-12-02 20:25:54 +08:00
# This is also done in the Makefile, but the Xcode build doesn't use that
2013-09-09 20:01:38 +08:00
CONDEMNED_PAGES =
2013-02-17 05:35:30 +08:00
if test ` uname` = 'Darwin' ; then
CONDEMNED_PAGES = " $CONDEMNED_PAGES open.1 "
fi
2013-01-04 07:17:48 +08:00
# Helper function to turn a relative path into an absolute path
resolve_path( )
{
D = ` command dirname " $1 " `
B = ` command basename " $1 " `
echo " `cd \" $D \" 2>/dev/null && pwd || echo \" $D \"`/ $B "
}
# Expand relative paths
DOXYFILE = ` resolve_path " $DOXYFILE " `
INPUTDIR = ` resolve_path " $INPUTDIR " `
2014-08-03 09:25:47 +08:00
INPUTFILTER = ` resolve_path " $INPUT_FILTER " `
2013-01-04 07:17:48 +08:00
OUTPUTDIR = ` resolve_path " $OUTPUTDIR " `
2013-01-04 07:26:29 +08:00
echo " doxygen file: $DOXYFILE "
echo " input directory: $INPUTDIR "
2014-08-03 09:25:47 +08:00
echo " input filter: $INPUTFILTER "
2013-01-04 07:26:29 +08:00
echo " output directory: $OUTPUTDIR "
2013-02-17 05:35:30 +08:00
echo " skipping: $CONDEMNED_PAGES "
2013-01-04 07:17:48 +08:00
2016-08-09 10:31:02 +08:00
#Until now the makefile likely has been affecting our output, reset for upcoming warnings
tput sgr0
2013-01-04 07:17:48 +08:00
# Make sure INPUTDIR is found
if test ! -d " $INPUTDIR " ; then
echo >& 2 " Could not find input directory ' ${ INPUTDIR } ' "
2012-12-28 09:31:13 +08:00
exit 1
fi
# Make sure doxygen is found
DOXYGENPATH = ` command -v doxygen`
if test -z " $DOXYGENPATH " ; then
2013-01-08 11:29:33 +08:00
for i in /usr/local/bin/doxygen /opt/bin/doxygen /Applications/Doxygen.app/Contents/Resources/doxygen ~/Applications/Doxygen.app/Contents/Resources/doxygen ; do
2012-12-28 09:31:13 +08:00
if test -f " $i " ; then
DOXYGENPATH = " $i "
break
fi
done
fi
if test -z " $DOXYGENPATH " ; then
echo >& 2 "doxygen is not installed, so documentation will not be built."
exit 0
fi
2014-08-06 02:28:03 +08:00
# Check we have the lexicon filter
if test -z " $INPUT_FILTER " ; then
echo >& 2 "Lexicon filter is not available. Continuing without."
INPUTFILTER = ''
fi
2012-12-28 09:31:13 +08:00
# Determine where our output should go
2013-01-04 07:17:48 +08:00
if ! mkdir -p " ${ OUTPUTDIR } " ; then
echo " Could not create output directory ' ${ OUTPUTDIR } ' "
2012-12-28 09:31:13 +08:00
fi
# Make a temporary directory
2012-12-28 13:12:22 +08:00
TMPLOC = ` mktemp -d -t fish_doc_build_XXXXXX` || { echo >& 2 "Could not build documentation because mktemp failed" ; exit 1; }
2012-12-28 09:31:13 +08:00
# Copy stuff to the temp directory
2013-01-04 07:17:48 +08:00
for i in " $INPUTDIR " /*.txt; do
2017-11-12 23:04:44 +08:00
BASENAME = ` basename $i .txt`
INPUTFILE = $TMPLOC /$BASENAME .doxygen
2017-12-14 22:52:34 +08:00
echo "/** \\page" $BASENAME > $INPUTFILE
cat $i | sed " s/\\\section $BASENAME $BASENAME /\\\section $BASENAME -man $BASENAME / " >> $INPUTFILE
echo "*/" >> $INPUTFILE
2012-12-28 09:31:13 +08:00
done
# Make some extra stuff to pass to doxygen
# Input is kept as . because we cd to the input directory beforehand
# This prevents doxygen from generating "documentation" for intermediate directories
2017-10-05 12:30:20 +08:00
PROJECT_NUMBER = $( echo " $FISH_BUILD_VERSION " | env sed "s/-.*//" )
echo " PROJECT_NUMBER: $FISH_BUILD_VERSION "
2012-12-28 13:39:11 +08:00
DOXYPARAMS = $( cat <<EOF
2017-10-05 12:30:20 +08:00
PROJECT_NUMBER = ${ PROJECT_NUMBER }
2014-08-03 09:25:47 +08:00
INPUT_FILTER = $INPUTFILTER
2012-12-28 09:31:13 +08:00
INPUT = .
OUTPUT_DIRECTORY = $OUTPUTDIR
QUIET = YES
EOF
2012-12-28 13:39:11 +08:00
) ;
2012-12-28 09:31:13 +08:00
# echo "$DOXYPARAMS"
# Clear out the output directory first
find " ${ OUTPUTDIR } " -name "*.1" -delete
# Run doxygen
cd " $TMPLOC "
2014-08-03 09:25:47 +08:00
( cat " ${ DOXYFILE } " ; echo " $DOXYPARAMS " ; ) | " $DOXYGENPATH " -
2012-12-28 09:31:13 +08:00
# Remember errors
RESULT = $?
2012-12-28 13:39:11 +08:00
cd " ${ OUTPUTDIR } /man/man1/ "
if test " $RESULT " = 0 ; then
2013-02-17 05:35:30 +08:00
2012-12-28 09:31:13 +08:00
# Postprocess the files
2013-01-04 07:17:48 +08:00
for i in " $INPUTDIR " /*.txt; do
2017-12-14 22:52:34 +08:00
# This command turns the following weirdness from Doxygen:
# abbr \-
# .SH "abbr - manage fish abbreviations"
# into
# \fBabbr\fP - manage fish abbreviations
2014-08-03 09:25:47 +08:00
# It would be nice to use -i here for edit in place, but that is not portable
2012-12-28 09:31:13 +08:00
CMD_NAME = ` basename " $i " .txt` ;
2017-12-14 22:52:34 +08:00
sed -E < ${ CMD_NAME } .1 > ${ CMD_NAME } .1.tmp \
-e " /^.SH NAME/{
2017-12-15 09:53:15 +08:00
N; N
s/${ CMD_NAME } \\ \\ - \n .SH \" ${ CMD_NAME } ( - .*) \" /\\ \f B${ CMD_NAME } \\ \f P \1 /g
} "
2017-12-14 22:52:34 +08:00
mv " ${ CMD_NAME } .1.tmp " " ${ CMD_NAME } .1 "
2012-12-28 09:31:13 +08:00
done
2014-08-03 09:25:47 +08:00
2013-02-17 05:35:30 +08:00
# Erase condemned pages
rm -f $CONDEMNED_PAGES
2012-12-28 09:31:13 +08:00
fi
# Destroy TMPLOC
2016-07-17 02:48:11 +08:00
if test " $RESULT " -ne 0; then
echo " Cleaning up ' $TMPLOC ' "
fi
2012-12-28 12:33:13 +08:00
rm -Rf " $TMPLOC "
2012-12-28 09:31:13 +08:00
2016-07-17 02:48:11 +08:00
if test " $RESULT " -ne 0; then
tput smso 2> /dev/null || true
echo "Doxygen failed creating manpages. See the output log for details."
tput sgr0 2> /dev/null || true
2012-12-28 09:31:13 +08:00
else
2016-07-17 02:48:11 +08:00
tput bold 2> /dev/null || true
echo Built manpages
tput sgr0 2> /dev/null || true
2012-12-28 09:31:13 +08:00
fi
exit $RESULT