
##############################################################################
#
# Copyright (c) 2003-2026 by the esys.escript Group
# https://github.com/LutzGross/esys-escript.github.io
#
# Primary Business: Queensland, Australia
# Licensed under the Apache License, version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# See CREDITS file for contributors and development history
#
##############################################################################

import os
import subprocess
Import('*')

doxy_dir=os.path.join(release_dir, 'doxygen')
env.Command(doxy_dir, [], [Mkdir(doxy_dir)])

# Check if doxygen is available
have_doxygen = False
try:
    result = subprocess.run(['which', 'doxygen'], capture_output=True, text=True)
    if result.returncode == 0:
        have_doxygen = True
except:
    pass

# Now some magic from the doxygen FAQ to get the global revision number into
# the doxyfile
if have_doxygen:
    if os.name=='posix':
        env.Alias('api_doxygen',[doxy_dir],['(cat doc/doxygen/doxygen_esys; echo "PROJECT_NUMBER=\"`git describe --always --dirty 2>/dev/null || echo "unknown"`\""; echo OUTPUT_DIRECTORY=\"'+doxy_dir+'\" ) | doxygen - '])
    else:
        env.Alias('api_doxygen',[doxy_dir],["doxygen doc/doxygen/doxygen_esys"])

    env.AlwaysBuild('api_doxygen')
else:
    # Create dummy target that does nothing but satisfies dependencies
    print("Note: Skipping doxygen documentation build (doxygen not found)")
    env.Alias('api_doxygen', [], ['@echo "Skipping doxygen (not installed)"'])

