string setWhere(string where, string defaultWhere)
{
    if (where == "")
        where = defaultWhere;

    md(where);
    return where;
}

void install(string what, string where)
{
    string path;

    if (what == "program")
    {
        if (where == "")
            where = BINARY;

        path = get_path(where);
        if (path != "")
            md(path);

        printf("  INSTALLING the executable `", where, "'\n");
        run("icmbuild install program " + where);
        exit(0);
    }

    if (what == "skel")
    {
        where = setWhere(where, SKEL);

        printf("  INSTALLING skeleton files at `" + where + "'\n");
        md(where);
        run("cp skeletons/* " + where);
        exit(0);
    }

    if (what == "man")
    {
        where = setWhere(where, MAN);
        printf("  INSTALLING the manual pages below `", where, "'\n");

        md(where + "/man1");
        run("gzip -9 -n < tmp/man/" PROGRAM ".1 > " + where + 
                                            "/man1/" PROGRAM ".1.gz");

        md(where + "/man3");
        run("gzip -9 -n < tmp/man/" PROGRAM "api.3 > " + where + 
                                            "/man3/" PROGRAM "api.3.gz");

        md(where + "/man7");
        run("gzip -9 -n < tmp/man/" PROGRAM "input.7 > " + where + 
                                            "/man7/" PROGRAM "input.7.gz");
        exit(0);
    }

    if (what == "manual")
    {
        where = setWhere(where, MANUAL);

        printf("  INSTALLING the manual at `", where, "'\n");
        run("cp -r tmp/manual " + where);
        exit(0);
    }

    if (what == "std")
    {
        where = setWhere(where, STD);

        printf("  INSTALLING the changelog at `", where, "\n");
        run("gzip -9 -n < changelog > " + where + "/changelog.gz");
    
        printf("  INSTALLING the html-manual pages at `", where, "\n");
        run("cp tmp/manhtml/" PROGRAM ".1.html " + where);
        run("cp tmp/manhtml/" PROGRAM "api.3.html " + where);
        run("cp tmp/manhtml/" PROGRAM "input.7.html " + where);
        exit(0);
    }

    exit(0);
}




