# Copyright: 2018-2020 Paul Obermeier (obermeier@poSoft.de)
# Distributed under BSD license.

set docDir   [pwd]
set mawtDir  [file join $docDir ".."]
set finalDir [file join $docDir "Final"]

set auto_path [linsert $auto_path 0 $mawtDir]

# Possible targets: all, ref, user, clean, distclean
set option "all"
if { $argc > 0 } {
    set option [lindex $argv 0]
}

if { $option eq "clean" || $option eq "distclean" } {
    file delete -force $finalDir
    exit 0
}

if { ! [file isdirectory $finalDir] } {
    file mkdir $finalDir
}

set retVal [catch {package require mawt} pkgVersion]

puts [format "%-25s: %s" "Tcl version" [info patchlevel]]
puts [format "%-25s: %s" "Mawt version" $pkgVersion]
puts [format "%-25s: %s" "FFMPEG version" [mawt GetFfmpegVersion]]

if { $option eq "ref" || $option eq "all" } {
    cd $mawtDir

    package require ruff

    puts "Generating reference documentation from source code ..."
    ::ruff::document \
        [list ::mawt] \
        -title "MAWT $pkgVersion Reference Manual" \
        -includesource true \
        -sortnamespaces false \
        -compact true \
        -excludeprocs {^_} \
        -output [file join $finalDir "MawtReference.html"] \
        -preamble $::mawt::_MawtIntro
    cd $docDir
}

if { $option eq "user" || $option eq "all" } {
    # No user manual yet.
}

puts "Done."
exit 0
