#!/bin/bash
#
#******************************************************************************
# make_dox (generic)
#------------------------------------------------------------------------------
##
# \file       	make_dox
# \library    	generic
# \author     	Chris Ahlstrom
# \date       	2015-08-08
# \update     	2019-05-05
# \version    	$Revision$
# \license    	$XPC_SUITE_GPL_LICENSE$
#
#     This file creates the doxygen documentation desired, by changing to
#     the original directory, running doxygen, and moving the results back
#     to the original directory.
#
#     This is our way of handling out-of-source builds of documentation,
#     without getting into the complexities of GNU Autotools method of
#     supporting Doxygen.
#
#     Apart from the complexity of this work, another reason for using a
#     script, instead of putting the code in Makefile.am, is that we need
#     some bash features (e.g. pushd/popd), and also need to be able to run
#     only one instance of bash -- 'make' runs each line of code on its own
#     instance.
#
# \param $1
#     Provides the directory where the Doxygen files are stored.
#
# \param $2
#
#     This parameter will be named for one of the libraries provided by Seq66.
#
# \usage
#     The normal usage occurs in the Makefile.am file:
#
#        $(srcdir)/make_dox $(srcdir) docs
#
#     The usage of $(srcdir) is necessary because we did not try to set up
#     support for having automake copy this script and the *.dox documents
#     to the out-of-source directory.  We really don't want to do Doxygen
#     the in the GNU Autotools way.
#
#------------------------------------------------------------------------------

#******************************************************************************
# To copy files or not?
#------------------------------------------------------------------------------
#
#     This file should support in-source builds or out-of-source builds.
#
#     For in-source builds, we cannot copy the results to the previous
#     directory, because they are the same directory, and an error will
#     occur.  So, for an in-source build, where $(srcdir) == ".", we will
#     not try to copy files.
#
#     For the out-of-source build, we will copy the files back to the
#     previous directory.
#
#------------------------------------------------------------------------------

DOCOPY="yes"
NEWDIR="$1"
TARGET="$2"
ACTION="$3"
LASTDIR="`pwd`"

if [ "$1" == "help" ] || [ "$1" == "--help" ]; then

cat << E_O_F

Usage: ./make_dox srcdir dirname [ clean ]

   where TARGET is 'libseq66', 'libsessions', 'seq_portmidi',
   or 'seq_rtmidi'.

E_O_F

   exit 0

fi

if [ "$ACTION" == "clean" ] ; then
   pushd "$NEWDIR"
   pushd "$TARGET"
   rm -f *.log
   rm -rf latex/
   popd
   popd
   exit 0
fi

if [ "$TARGET" == "" ] ; then
   NEWDIR="."
   TARGET="$1"
   echo "Using current directory for target '$TARGET'..."
fi

if [ $NEWDIR == "." ] ; then
   DOCOPY="no"
fi

pushd $NEWDIR
pushd $TARGET
../make-helper $TARGET
popd
popd

#******************************************************************************
# make_dox (generic)
#------------------------------------------------------------------------------
# vim: ts=3 sw=3 et ft=sh
#------------------------------------------------------------------------------
