/** @file psastroVersion.c
 *
 *  @brief
 *
 *  @ingroup libpsastro
 *
 *  Copyright 2009 Institute for Astronomy, University of Hawaii
 */

#include "psastroInternal.h"

psString psastroVersion(void)
{
#ifndef PSASTRO_VERSION
#error "PSASTRO_VERSION is not set"
#endif
#ifndef PSASTRO_BRANCH
#error "PSASTRO_BRANCH is not set"
#endif
    return psStringCopy(PSASTRO_BRANCH "@" PSASTRO_VERSION);
}

psString psastroSource(void)
{
#ifndef PSASTRO_SOURCE
#error "PSASTRO_SOURCE is not set"
#endif
    return psStringCopy(PSASTRO_SOURCE);
}

psString psastroVersionLong(void)
{
    psString version = psastroVersion();  // Version, to return
    psString source = psastroSource();    // Source

    psStringPrepend(&version, "psastro ");
    psStringAppend(&version, " from %s, built %s, %s", source, __DATE__, __TIME__);
    psFree(source);

#ifdef __OPTIMIZE__
    psStringAppend(&version, " optimised");
#else
    psStringAppend(&version, " unoptimised");
#endif

    return version;
};

bool psastroVersionHeader(psMetadata *header)
{
    PS_ASSERT_METADATA_NON_NULL(header, false);

    psString version = psastroVersion(); // Software version
    psString source = psastroSource();   // Software source

    psMetadataAddStr(header, PS_LIST_TAIL, "IPP.PSASTRO.VERSION", PS_META_REPLACE,
                     "psastro software version", version);
    psMetadataAddStr(header, PS_LIST_TAIL, "IPP.PSASTRO.SOURCE", PS_META_REPLACE,
                     "psastro software source", source);

    psFree(version);
    psFree(source);

    return true;
}
