#!/bin/bash

# Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
# at the Lawrence Livermore National Laboratory. All Rights reserved. See files
# LICENSE and NOTICE for details. LLNL-CODE-806117.
#
# This file is part of the MFEM library. For more information and source code
# availability visit https://mfem.org.
#
# MFEM is free software; you can redistribute it and/or modify it under the
# terms of the BSD-3 license. We welcome feedback and contributions, see file
# CONTRIBUTING.md for details.

# Print usage information
case $1 in
   -h|-help)
      cat <<EOF

   $0 [-h|-help] {mfem_dir}

   where: {mfem_dir}  is the MFEM source directory [default value: ../..]
          -h|-help    prints this usage information and exits

   This script runs documentation-related tests in mfem_dir. It checks in
   particular the Doxygen formatting used in the source comments.

   Example usage: $0 ../..

EOF
      exit
      ;;
esac

# Setup
cur_dir=`pwd`
mfem_dir=$1
if [ "$mfem_dir" = "" ]; then
    mfem_dir="../.."
fi
shift
cd $mfem_dir

# Test the documentation of some make targets
make help
make distclean
# make config MFEM_USE_MPI=YES
# make status

# Test the build of the Doxygen documentation
cd doc; make clean; make

# Return to the original directory
cd $cur_dir

# Tell users what to do if the script fails
test_name="$(basename "$0")"
if [ -s "$test_name.err" ]; then
    cat >  $test_name.msg <<EOF

To correct this error, make sure that the Doxygen comments in the code use
correct syntax.

See the Doxygen documentation for specific syntax (e.g. @a, @brief, etc.),
and the 'makefile' and 'CodeDocumentation.conf.in' files in the 'doc/' directory
for additional details.

Please contact a member of the MFEM team if you have questions.

EOF
fi
