
void install(string request, string dest)
{
    string target;
    int components = 0;
    list pathsplit;
    string base;
    base = "tmp/install/";

    md(base);

    if (request == "x")
        components = 63;
    else 
    {
        if (strfind(request, "a") != -1)    // additional documentation
            components |= 1;
        if (strfind(request, "b") != -1)    // binary program
            components |= 2;
        if (strfind(request, "d") != -1)    // standard documentation
            components |= 4;
        if (strfind(request, "m") != -1)    // man-pages
            components |= 8;                
        if (strfind(request, "s") != -1)    // skeleton
            components |= 16;
        if (strfind(request, "u") != -1)    // user guide
            components |= 32;
    }

    chdir(g_cwd);                       // determine the destination path
    if (dest == "")
        dest = "/";
    else
        md(dest);

    dest = cutEoln(backtick("readlink -f " + dest)[0]);

    if (g_logPath != "")
        backtick("icmake/log " + dest + " " + g_logPath);


    if (components & 1)
    {
        printf("\n  installing additional documentation\n");

        target = base + "a/" ADD + "/bison-docs/";
        printf("  installing original bison's docs below `", target + "'\n");
        logRecursive("documentation/html", target);

        target = base + "a/" ADD + "/examples/";
        printf("  installing examples below `", target + "'\n");
        logRecursive("documentation/examples", target);

        logRecursive("documentation/man/calculator", target + "/calculator/");

        printf("  installing regression tests below `", target + "'\n");
        logRecursive("documentation/regression", target + "/regression/");

        printf("  installing polymorphic semval demo at `", 
                                                        target + "poly/'\n");
        logRecursive("tmp/manual/poly", target + "poly/");

        printf("  installing polymorphic impl. demo at `", 
                                                    target + "/essence/'\n");
        logRecursive("tmp/manual/essence", target + "/essence/");

        chdir(base);                        // go to the base directory

        destInstall(dest, base + "a");
    }

    if (components & 2)
    {
        target = base + "b/" BINARY;
        pathsplit = path_file(target);

        printf("  installing the executable `", target, "'\n");
        logFile("tmp/bin", "binary", pathsplit[0], pathsplit[1]);

        destInstall(dest, base + "b");
    }


    if (components & (4 | 8))
    {
        target = base + "d/" DOC "/";
        if (components & 4)
        {
            printf("  installing the changelog at `", target, "\n");
            logZip("", "changelog", target );

            destInstall(dest, base + "d");
        }

        if (components & 8)
        {
            printf("  installing the html-manual pages at `", target, "\n");
            logInstall("tmp/manhtml", "", target);

            destInstall(dest, base + "d");
        }
    }


    if (components & 8)
    {
        target = base + "m/" MAN "/";
        printf("  installing the manual pages below `", target, "'\n");
    
        logZip("tmp/man", "bisonc++.1", target);

        destInstall(dest, base + "m");
    }

    if (components & 16)
    {
        target = base + "s/" SKEL "/";
        printf("  installing skeleton files at `" + target + "'\n");
        logInstall("skeletons", "", target);

        destInstall(dest, base + "s");
    }


    if (components & 32)
    {
        target = base + "u/" UGUIDE "/";
        printf("  installing the user-guide at `", target, "'\n");
        logInstall("tmp/manual", "", target);

        destInstall(dest, base + "u");
    }


    printf("\n  Installation completed\n");

    exit(0);
}
