
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, "b") != -1)
            components |= 2;
        if (strfind(request, "d") != -1)
            components |= 4;
        if (strfind(request, "m") != -1)
            components |= 8;                
        if (strfind(request, "s") != -1)
            components |= 16;
        if (strfind(request, "u") != -1)
            components |= 32;
    }

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

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


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

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


    if (components & 8)
    {
        target = base + MAN;
        printf("  installing the man pages below `", target, "'\n");
        
        logZip("tmp/man", "flexc++.1", target + "/man1/");
        logZip("tmp/man", "flexc++api.3", target + "/man3/");
        logZip("tmp/man", "flexc++input.7", target + "/man7/");
    }

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


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


    chdir(g_cwd);
    if (dest == "")
        dest = "/";
    else
        md(dest);

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

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

    chdir(base);
    run("../../icmake/installer " + dest + "/");

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

    exit(0);
}
