
##############################################################################
#
# Copyright (c) 2012-2018 by The University of Queensland
# http://www.uq.edu.au
#
# Primary Business: Queensland, Australia
# Licensed under the Apache License, version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Development until 2012 by Earth Systems Science Computational Center (ESSCC)
# Development 2012-2013 by School of Earth Sciences
# Development from 2014 by Centre for Geoscience Computing (GeoComp)
#
##############################################################################

import os
Import('*')

local=env.Clone()

epy_dir=os.path.join(release_dir, 'sphinx_api')
local.Command(epy_dir, [], [Mkdir(epy_dir)])

int_dir=os.path.join(env['BUILD_DIR'], 'sphinx_int')
local.Command(int_dir, [], [Mkdir(int_dir)])
local['ENV']['LD_LIBRARY_PATH']+=(os.path.pathsep+os.path.join(local['prefix'],'lib'))

#env.Alias(os.path.join(int_dir,'index.rst'),[env['pyinstall'], int_dir],'doc/sphinx_api/genrst.py ./esys esys '+int_dir)

mjpath=''
if env['mathjax_path']!='default':
    mjpath='-D mathjax_path='+env['mathjax_path']

sphinxstuff=local.Command('stuff', [epy_dir, int_dir, env['pyinstall']], env['pythoncmd'] + ' doc/sphinx_api/genrst.py '+env['prefix']+' esys '+int_dir+" && sphinx-build -v -E --color -b html -d "+int_dir+"/tree -c doc/sphinx_api "+mjpath+" "+int_dir+" "+epy_dir)

env.Alias('sphinxdoc', sphinxstuff)
#env.Alias('sphinxdoc', [epy_dir, int_dir], 'doc/sphinx_api/genrst.py '+env['prefix']+' esys '+int_dir+" && sphinx-build -b html -d "+int_dir+"/tree -c doc/sphinx_api "+int_dir+" "+epy_dir)

# This will need to be here at least until the output of api_epydoc properly
# depends on the libraries it uses as input
env.AlwaysBuild('sphinxdoc')

