# vi: syntax=python
import os

# Build documentation

Import(["normalBuildDir"])

BUILDDIR = "#" + os.path.join(normalBuildDir, "makedoc")

env = Environment(ENV = os.environ)
env.BuildDir(BUILDDIR, '#docs/src/makedoc', duplicate = 0)
makeDocFiles = Split("""
   makechm.c
   makedevh.c
   makedoc.c
   makehtml.c
   makeman.c
   makemisc.c
   makertf.c
   makesci.c
   maketexi.c
   maketxt.c
    """);

docs = [] 
docs.append(env.Program('#docs/makedoc', [os.path.join(BUILDDIR, x) for x in makeDocFiles]))

makeHTML = Builder(action = 'docs/makedoc -html $TARGETS $SOURCES', 
           suffix = '.html', 
           src_suffix = '._tx');

makeScite = Builder(action = 'docs/makedoc -scite $TARGETS $SOURCES', 
           suffix = '.api', 
           src_suffix = '._tx');

makeTexi = Builder(action = 'docs/makedoc -texi $TARGETS $SOURCES', 
           suffix = '.texi', 
           src_suffix = '._tx');

makeRTF = Builder(action = 'docs/makedoc -rtf $TARGETS $SOURCES', 
           suffix = '.rtf', 
           src_suffix = '._tx');

makeInfo = Builder(action = 'makeinfo --no-split -o $TARGETS $SOURCES', 
           suffix = '.info', 
           src_suffix = '.texi');

makeMan = Builder(action = 'docs/makedoc -man $TARGETS $SOURCES', 
           src_suffix = '._tx');

makeASCII = Builder(action = 'docs/makedoc -ascii $TARGETS $SOURCES', 
           suffix = '.txt', 
           src_suffix = '._tx');

env.Append(BUILDERS = {'DocHTML' : makeHTML,
              'DocRTF' : makeRTF,
              'DocTexi' : makeTexi,
              'DocMan' : makeMan,
              'DocInfo' : makeInfo,
              'DocScite' : makeScite,
              'DocASCII' : makeASCII})

def addRTF(source, target):
    docs.append(env.DocRTF(target,source))

def addHTML(source, target):
    docs.append(env.DocHTML(target,source))

def addTexi(source, target):
    docs.append(env.DocTexi(target,source))

def addInfo(source, target):
    docs.append(env.DocInfo(target,source))

def addMan(source, target):
    docs.append(env.DocMan(target,source))

def addScite(source, target):
    docs.append(env.DocScite(target,source))

def addASCII(source, target):
    docs.append(env.DocASCII(target,source))

addHTML('#docs/src/changes._tx', '#docs/html/changes')
addHTML('#docs/src/allegro._tx', '#docs/html/allegro.html')
addHTML('#docs/src/readme._tx', '#docs/html/readme.html')
addTexi('#docs/src/allegro._tx', '#docs/texi/allegro.texi')
addRTF('#docs/src/changes._tx', '#docs/rtf/changes.rtf')
addRTF('#docs/src/allegro._tx', '#docs/rtf/allegro.rtf')
addRTF('#docs/src/readme._tx', '#docs/rtf/readme.rtf')
addMan('#docs/src/allegro._tx', '#docs/man/dummyname.3')
addASCII('#docs/src/changes._tx', '#docs/txt/changes.txt')
addASCII('#docs/src/allegro._tx', '#docs/txt/allegro.txt')
addASCII('#docs/src/readme._tx', '#docs/txt/readme.txt')
addScite('#docs/src/allegro._tx', '#docs/scite/allegro.api')
addInfo('#docs/texi/allegro.texi', '#docs/info/allegro.info')
docs.append(env.Command('#CHANGES', '#docs/txt/changes.txt', Copy('$TARGET', '$SOURCE')))
docs.append(env.Command('#readme.txt', '#docs/txt/readme.txt', Copy('$TARGET', '$SOURCE')))

Return("docs")
