#!/usr/bin/icmake -t.

void yodl(string dest, string src)
{
    system("yodl2man --no-warnings -o " + dest + " " + src);
}

string release = "release.yo";

void rmrelease()
{
    echo(OFF);
    system("rm -f " + release);
    echo(ON);
}

void main(int argc, list argv)
{
    rmrelease();

    string versionFile = "../../VERSION";
    list line;
    while (listlen(line = fgets(versionFile, line)))
    {
        list cut = strtok(line[0], "= \t\n");
        string key = cut[0];
        string value = cut[1];

        if (key == "VERSION")
            fprintf("release.yo", "SUBST(_CurVers_)(", value, ")\n");
        else if (key == "YEARS")
            fprintf("release.yo", "SUBST(_CurYrs_)(", value, ")\n");
    }

    yodl("../icmake.1", "-r 20000 icmake.yo");
    yodl("../icmstart.1", "icmstart.yo");
    yodl("../icmbuild.1", "icmbuild.yo");
    yodl("../icmstart.rc.7", "icmstart.rc.yo");
    yodl("../icmconf.7", "icmconf.yo");

    rmrelease();
}
