add_rules("mode.debug", "mode.release")

if is_subhost("windows") then
    add_requires("strawberry-perl")
    add_packages("strawberry-perl")
end
add_requires("gperf")
add_packages("gperf")

add_requires("libparserutils")
add_packages("libparserutils")
if is_plat("windows") then
    add_requires("strings_h")
    add_packages("strings_h")
end

target("hubbub")
    set_kind("$(kind)")
    add_files("src/**.c")
    add_includedirs("include", "src")
    add_headerfiles("include/(hubbub/*.h)")

    if is_plat("windows") and is_kind("shared") then
        add_rules("utils.symbols.export_all")
    end

    before_build(function (target)
        local perl, gperf
        if is_subhost("windows") then
            perl = path.join(target:pkg("strawberry-perl"):installdir(), "perl/bin/perl.exe")
            gperf = path.join(target:pkg("gperf"):installdir(), "bin/gperf.exe")
        else
            perl = "perl"
            gperf = "gperf"
        end
        os.vrunv(perl, {"build/make-entities.pl"})
        os.vrunv(gperf, {"src/treebuilder/element-type.gperf", "--output-file=src/treebuilder/autogenerated-element-type.c"})
    end)
