# SPDX-FileCopyrightText: Copyright The SCons Foundation (https://scons.org)
# SPDX-License-Identifier: MIT

"""
SConstruct file for building SCons Reference Manual.

This is mostly a stub, and is not built as part of the doc build.

If invoked directly, can add SKIP_PDF=1 to avoid pdf and epub generation.
"""

import os

env = Environment(
    ENV={'PATH': os.environ['PATH']},
    tools=['docbook'],
    toolpath=['../../SCons/Tool'],
    # DOCBOOK_XSLTPROCFLAGS="--stringparam fop.extensions 1",
    DOCBOOK_DEFAULT_XSL_HTML='html.xsl',
    DOCBOOK_DEFAULT_XSL_HTMLCHUNKED='chtml.xsl',
    DOCBOOK_DEFAULT_XSL_PDF='pdf.xsl',
)

skip_pdf = ARGUMENTS.get('SKIP_PDF', False)
has_pdf = False
if not skip_pdf and any((env.WhereIs('fop'), env.WhereIs('xep'))):
    has_pdf = True

env.DocbookXInclude('reference_xi.xml', 'main.xml')
env.DocbookXslt('reference.xml', 'reference_xi.xml',
                xsl='../xslt/to_docbook.xslt')
env.DocbookHtml('index.html','reference.xml')
env.DocbookHtmlChunked('index.html', 'reference.xml', base_dir='scons-reference/')
if has_pdf:
    env.DocbookPdf('scons-reference.pdf','reference.xml')
