#   Copyright (c) 2007 Axel Wachtler
#   All rights reserved.
#
#   Redistribution and use in source and binary forms, with or without
#   modification, are permitted provided that the following conditions
#   are met:
#
#   * Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#   * Neither the name of the authors nor the names of its contributors
#     may be used to endorse or promote products derived from this software
#     without specific prior written permission.
#
#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
#   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
#   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#   POSSIBILITY OF SUCH DAMAGE.

# $Id$

#=== modules ==================================================================
import os, glob
import boardcfg
from pprint import pprint as pp
Import("doc")

#=== setup build environment ==================================================

doc['dox_install_dir'] = doc.Dir("$dir_install/doc")


def create_board_dox(target, source, env):
    target = str(target[0])
    sources = map(str,source)
    f = open(target,"w")
    f.write(boardcfg.boards_to_dox())
    f.close()


#=== Main Doc. Setup ==========================================================
alldoc = doc.Clone()
alldoc['BUILDERS']['BoardDoxWriter'] = Builder(action = create_board_dox)
alldoc['dir_build'] = alldoc.Dir(".")
alldoc['dox_title'] = "Documentation"
alldoc['dox_source_browser'] = "NO"
#alldoc["dox_source_browser"] = "YES"
alldoc['dox_generate_tagfile'] = "alldoc.tag"
alldoc["dox_example_path"] = ["Src/Xmpl", "Src/App", "Doc/Dev",
                              "Contrib/Arduino/examples/Radio/HelloRadio/" ]
alldoc["dox_enabled_sections"] = "NEWDOC"

tmp = "${dir_src_doc}/main.dox  "\
      "${dir_src_doc}/trx.dox "\
      "${dir_src_doc}/misc.dox "\
      "${dir_src_doc}/Usr/main.dox "\
      "${dir_src_doc}/Usr/usr.dox "\
      "${dir_src_doc}/Usr/libradio.dox "\
      "${dir_src_doc}/Usr/libioutil.dox "\
      "${dir_src_doc}/Usr/xmpl.dox "\
      "${dir_src_doc}/App/main.dox "\
      "${dir_src_doc}/App/app.dox "\
      "${dir_src_doc}/App/radio.dox "\
      "${dir_src_doc}/App/transceiver.dox "\
      "${dir_src_doc}/Dev/main.dox "\
      "${dir_src_doc}/Dev/dev.dox "\
      "${dir_src_doc}/Dev/wintools.dox "\
      "${dir_src_doc}/Contrib/contrib.dox "\
      "${dir_src_doc}/Contrib/main.dox "\
      "${dir_src_doc}/Contrib/packetcapture.dox "\
      "${dir_src_doc}/Contrib/arduino.dox "\
      "${dir_src_doc}/gettingstarted.dox "\
      "${dir_build}/boards.dox "\
      "${dir_top}/Src/Lib/Inc "\
      "${dir_top}/Src/Lib/Inc/boards "\
      "${dir_top}/install/inc/at86rf212.h "\
      "${dir_top}/install/inc/at86rf230a.h "\
      "${dir_top}/install/inc/at86rf230b.h "\
      "${dir_top}/install/inc/at86rf231.h "\
      "${dir_top}/install/inc/atmega_rfa1.h "\
      "${dir_top}/Src/App "\
      "${dir_top}/Src/App/Sniffer "

alldoc["dox_input_files"] = tmp.split()
alldoc["images_files"] = "${dir_src_img}/l1.png \
                        ${dir_src_img}/l2.png \
                        ${dir_src_img}/l3.png \
                        ${dir_src_img}/l4.png \
                        ${dir_src_img}/l5.png \
                        ${dir_src_img}/l1tiny.png \
                        ${dir_src_img}/scrn_xmpl_hif.png \
                        ${dir_src_img}/atmel_rb.jpg \
                        ${dir_src_img}/radio23x_scheme.png \
                        ${dir_src_img}/wireshark-linux.png \
                        ${dir_src_img}/baustelle1.jpg"
alldoc["dox_exclude_files"] = "${dir_top}/Src/Lib/Lw_mesh "\
                              "${dir_top}/Src/Lib/Inc/lw_mesh.h "\
                              "${dir_top}/Src/Xmpl/xmpl_lw_mesh.h "\
                              "${dir_top}/Src/Xmpl/xmpl_lw_mesh_route.c "\
                              "${dir_top}/Src/Xmpl/xmpl_lw_mesh_rx.c "\
                              "${dir_top}/Src/Xmpl/xmpl_lw_mesh_tx.c "\
                              "".split()

#=== targets ==========================================================
boardfile = alldoc.BoardDoxWriter("boards.dox", "#$BOARD_CFG_FILE")
doxyfile = alldoc.DoxyfileTransformer("Doxyfile","Doxyfile.in")
htmlfile = alldoc.Command("${dox_install_dir}/index.html",
                         [doxyfile, "${dir_src_doc}/uracoli.css",
                         "${dir_src_doc}/header.html",
                         "${dir_src_doc}/footer.html",
                         boardfile],
                         ["doxygen $SOURCE"])
alldoc.Depends(htmlfile, alldoc.Split("$dox_input_files ${dir_top}/LICENSE"))
alldoc.Depends(htmlfile, alldoc.Split("${images_files}"))

