#!/usr/bin/icmake -qt/tmp/bobcat

#include "INSTALL.im"

#define ECHO_COMMANDS       1
#define LIBRARY             "bobcat"
#define DRYRUN              ""

//#define ONLYCLASSES
    // comment out if the additional library requiring classes should also
    // be compiled

string
    g_cwd,              // current WD
    g_file,             // used to store the name of a file from a list
    g_copt,             // compiler options
    g_cxx,              // compiler used
    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
    g_tmpbin,           // Binary target
    g_lcgen,            // bobcat lcgen program name
    g_lcgendefault,     // default max size of the bobcat/lc structs
    g_sharedLibReq;     // libraries required by the shared lib
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/addclasses""
#include "icmake/special"
#include "icmake/man"
#include "icmake/library"
#include "icmake/libraries"
#include "icmake/install"

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

    echo(ECHO_COMMANDS);

    g_cwd = chdir(".");

    g_tmplib = "tmp/lib/";
    g_tmphdr = "tmp/" LIBRARY "/";
    g_tmpbin = "tmp/bin/";

    g_lcgen  = "bobcatlcgen";
    g_lcgendefault = " 10 ";    // KEEP THE BLANKS

    setLocations();     // from INSTALL.im

    g_cxx =  setOpt(CXX, "CXX");
    g_copt = setOpt(CXXFLAGS, "CXXFLAGS");

    option = element(1, argv);

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

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

        if (all == "all")
            strip = element(3, argv);
        else
            strip = all;

        libraries("bobcat", all == "all", strip == "strip");
    }

    if (option == "l")
    {
        system(P_NOCHECK, "tput clear");
        libraries("bobcat", 1, 0);
    }

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

    if (option == "sf")
    {
        special(0, 0);
        exit(0);
    }

    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"
        "   distclean           - same as clean\n"
        "   install <rss dev>   - to install the software in the locations\n"
        "                         defined in the INSTALL.im file,\n"
        "                         optionally below <rss> (run-time package)\n"
        "                         and <dev> (development package)\n"
        "                         By default all is installed. To configure\n"
        "                         update setLocations() in INSTALL.im\n"
        "   man                 - build the manual page (requires Yodl)\n"
        "   libraries [all] [strip] - build the bobcat(-dev) libraries\n"
        "                         (optionally add optional classes,\n"
        "                         optionally strip the libraries)\n"
        "   l                   - same as 'libraries all', but clearing the\n"
        "                         screen before starting the compilation\n"
        "   sf                  - preliminaries required for SourceForge\n"
    );
    exit(1);
}
