
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 docs
            components |= 1;
        if (strfind(request, "b") != -1)    // binary program
            components |= 2;
        if (strfind(request, "d") != -1)    // std. documentation
            components |= 4;
        if (strfind(request, "m") != -1)    // man-pages
            components |= 8;                
        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)                     // additional docs
    {
        target = base + "a/" ADD "/";

        printf("\n  installing additional documentation\n");

        printf("  installing README files and ACKNOWLEDGEMENTS at `", 
                                                            target, "\n");
        logZip("", "README", target);
        logZip("", "README.3.00.00", target);
        logZip("", "ACKNOWLEDGEMENTS", target);

        printf("  installing cross-reference at `", target, "'\n");
        logZip("", "stealth.xref", target);
 

        target += "examples/";
        printf("  installing examples at `", target, "'\n");
        logZip("documentation/example-policies/", "demo.pol", target);
        logZip("documentation/example-policies/", "localhost.pol", target);
        logZip("documentation/example-policies/", "simple.pol", target);

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

    if (components & 2)                     // binary program
    {
        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))           // 4: std docs, 8: man-pages
    {
        target = base + "d/" DOC "/";

        if (components & 4)
        {
            printf("  installing the changelog at `", target, "\n");
            logZip("", "changelog", target );

            printf("  installing the logrotate mold  as `", 
                    target, "/scripts/logrotate.gz'\n");
            logZip("share/", "logrotate", target + "scripts/");

            printf("  installing the cleanup script as `", 
                            target, "/scripts/cleanup.rc.gz'\n");
            logZip("share/", "cleanup.rc", target + "scripts/");

            printf("  installing additional scripts at `", 
                            target, "/scripts/additional\n");

            logZip("share/additional/", "", target + "scripts/");

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

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

            printf("  installing ", dest, " at `", base, "d'\n");
            destInstall(dest, base + "d");
        }
    }


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

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

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

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

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

    exit(0);
}
