#!/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 newReleaseYo()
{
                    // Std version file in icmake's root dir
    string versionFile = "../../VERSION";

    list line;      // get the VERSION and YEARS, and write 'release.yo'
    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");
    }
}

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

    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("../icmscript.7", "icmscript.yo");
    yodl("../icmconf.7", "icmconf.yo");

    rmrelease();
}



