#!/usr/bin/icmake -qt/tmp/bisonc++

#include "INSTALL.im"

#define ECHO_COMMANDS       1
#define COPT                "-Itmp -Wall -O3"
#define PROJECT             "BOBCAT"
#define DESTINATION         "tmp"
#define LIBRARY             "bobcat"

string
    g_compiler,         // actual compiler to use
    g_cwd,              // current WD
    g_file,             // used to store the name of a file from a list
    g_copt,             // compiler options
    g_sources,          // sources to be used
    g_version,          // The library's version from the file VERSION
    g_tmplib,           // Library compilation target
    g_tmphdr;           // Class header target
int
    g_nClasses;         // number of classes/subdirectories
list
    g_classes;          // list of classes/directories, listed in CLASSES

#include "icmake/run"
#include "icmake/getenv"
#include "icmake/clean"
#include "icmake/special"
#include "icmake/man"
#include "icmake/library"
#include "icmake/libraries"
#include "icmake/install"

void main(int argc, list argv, list envp)
{
    string option;

    echo(ECHO_COMMANDS);

    g_env = envp;

    g_cwd = chdir(".");

    g_tmplib = DESTINATION "/lib/";
    g_tmphdr = DESTINATION "/" LIBRARY "/";

    setLocations();     // from INSTALL.im

    getenvSF("DRYRUN");
    g_dryrun = g_envvar;

    option = element(1, argv);

    if (option == "clean")
        clean();

    if (option == "libraries")
        libraries("bobcat", element(2, argv) == "all");

    if (option == "man")
        man();

    if (option == "install")
        install(element(2, argv), element(3, argv));

    printf("Usage: build what\n"
        "Where `what' is one of:\n"
        "   clean             - clean up remnants of previous compilations\n"
        "   install <rss dev> - to install the software in the locations\n"
        "                       defined in the INSTALL.im file, optionally\n"
        "                       below <rss> (run-time package) and\n"
        "                       <dev> (development package)\n"
        "   man             - build the manual page (requires Yodl)\n"
        "   libraries       - build the bobcat(-dev) libraries\n"
        "\n"
        "If the environment variable DRYRUN is defined, no commands are\n"
        "actually executed\n"
    );
    exit(1);
}
