Import('env')

build_appendix = Builder(action='docs/build-appendix.sh $SOURCES > $TARGET')
concat_sections = Builder(action='docs/concat-sections.sh $SOURCES > $TARGET')
pandoc = Builder(action='pandoc $PDFLAGS $SOURCES -o $TARGET')

env.Append(BUILDERS = {'Pandoc': pandoc,
                       'Appendix': build_appendix,
                       'Concat': concat_sections})
env.Append(PDFLAGS = '-V "geometry=margin=1in"')

compiler_source_files = ['scanner.mll', 'parser.mly', 'ast.ml', 'symgen.ml',
                         'environment.ml', 'detect.ml', 'generator.ml']
rtlib_source_files = ['libvector.hpp', 'vector_array.hpp',
                      'vector_utils.hpp', 'vector_iter.hpp']
test_cases = ['arrays', 'control_flow', 'float', 'hello', 'length', 'map',
              'reduce', 'time', 'complex', 'dotprod', 'functions', 'inline',
              'logic', 'pfor', 'strings']
benchmarks = ['mandelbrot-bench', 'mandelbrot-cpu', 'mandelbrot-gpu']
sconscripts = ['compiler', 'test', 'bench']

source_file_paths = ['../compiler/' + sf for sf in compiler_source_files] + [
                     '../rtlib/' + sf for sf in rtlib_source_files] + [
                     '../test/' + tc + '.vec' for tc in test_cases] + [
                     '../bench/' + bm + '.vec' for bm in benchmarks] + [
                     '../' + ss + '/SConscript' for ss in sconscripts] + [
                     '../SConstruct']

env.Appendix('appendix-a.md', source_file_paths)
env.Concat('final-report.md',
        ['introduction.md', 'language-tutorial.md', 'language-ref.md',
         'project-plan.md', 'architectural-design.md', 'test-plan.md',
         'lessons-learned.md', 'appendix-a.md'])
env.Pandoc('final-report.pdf', 'final-report.md')
