/*****************************************************************************\
*                                                                             *
*  Name   : version_stamper                                                   *
*  Author : Chris Koeritz                                                     *
*                                                                             *
*******************************************************************************
* Copyright (c) 1995-$now By Author.  This program is free software; you can  *
* redistribute it and/or modify it under the terms of the GNU General Public  *
* License as published by the Free Software Foundation; either version 2 of   *
* the License or (at your option) any later version.  This is online at:      *
*     http://www.fsf.org/copyleft/gpl.html                                    *
* Please send any updates to: fred@gruntose.com                               *
\*****************************************************************************/

#include "version_stamper.h"

#include <basis/portable.h>
#include <basis/version_record.h>
#include <opsystem/application_shell.h>
#include <opsystem/byte_filer.h>
#include <loggers/console_logger.h>
#include <opsystem/directory.h>
#include <opsystem/filename.h>
#include <data_struct/static_memory_gremlin.h>
#include <opsystem/version_ini.h>

#undef LOG
#define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger(), to_print)

version_stamper::version_stamper()
: application_shell("version_stamper")
{
}

version_stamper::~version_stamper() {}

int version_stamper::execute()
{
  FUNCDEF("execute");
  SET_DEFAULT_CONSOLE_LOGGER;  // override the file_logger from app_shell.
  if (__argc < 2) {
    log("The directory where the 'version.ini' file is located\n"
        "must be specified as the first parameter of this program.  Another\n"
        "version file may optionally be specified as the second parameter of\n"
        "the program; the version contained in this file will be used to set\n"
        "the version of the file specified in the first parameter.\n"
        "Additionally, if the environment variable 'DEBUG' exists, then the\n"
        "generated RC file will be marked as a debug build.  Otherwise it is\n"
        "marked as a release build.  Note that the CLAM system automatically\n"
        "sets this for you.\n\n");
    return 1;
  }

  istring path_name = __argv[1];
  istring source_version_file;  // blank by default.
  if (__argc > 2)
    source_version_file = __argv[2];
  bool ret = version_ini::one_stop_version_stamp(path_name,
      source_version_file, true);
  if (!ret) return 1;  // failure.
  return 0;  // success.
}

HOOPLE_MAIN(version_stamper, )

#ifdef __BUILD_STATIC_APPLICATION__
  // static dependencies found by buildor_gen_deps.sh:
  #include <basis/array.cpp>
  #include <basis/byte_array.cpp>
  #include <basis/callstack_tracker.cpp>
  #include <basis/chaos.cpp>
  #include <basis/convert_utf.cpp>
  #include <basis/definitions.cpp>
  #include <basis/earth_time.cpp>
  #include <basis/guards.cpp>
  #include <basis/istring.cpp>
  #include <basis/log_base.cpp>
  #include <basis/memory_checker.cpp>
  #include <basis/mutex.cpp>
  #include <basis/object_base.cpp>
  #include <basis/outcome.cpp>
  #include <basis/packable.cpp>
  #include <basis/portable.cpp>
  #include <basis/sequence.cpp>
  #include <basis/set.cpp>
  #include <basis/utility.cpp>
  #include <basis/version_checker.cpp>
  #include <basis/version_record.cpp>
  #include <data_struct/amorph.cpp>
  #include <data_struct/bit_vector.cpp>
  #include <data_struct/byte_hasher.cpp>
  #include <data_struct/configurator.cpp>
  #include <data_struct/hash_table.cpp>
  #include <data_struct/pointer_hash.cpp>
  #include <data_struct/stack.cpp>
  #include <data_struct/static_memory_gremlin.cpp>
  #include <data_struct/string_hash.cpp>
  #include <data_struct/string_hasher.cpp>
  #include <data_struct/string_table.cpp>
  #include <data_struct/symbol_table.cpp>
  #include <data_struct/table_configurator.cpp>
  #include <loggers/console_logger.cpp>
  #include <loggers/file_logger.cpp>
  #include <loggers/locked_logger.cpp>
  #include <loggers/null_logger.cpp>
  #include <loggers/program_wide_logger.cpp>
  #include <opsystem/application_base.cpp>
  #include <opsystem/application_shell.cpp>
  #include <opsystem/byte_filer.cpp>
  #include <opsystem/command_line.cpp>
  #include <opsystem/critical_events.cpp>
  #include <opsystem/directory.cpp>
  #include <opsystem/filename.cpp>
  #include <opsystem/ini_config.cpp>
  #include <opsystem/ini_parser.cpp>
  #include <opsystem/path_configuration.cpp>
  #include <opsystem/rendezvous.cpp>
  #include <opsystem/version_ini.cpp>
  #include <textual/byte_format.cpp>
  #include <textual/parser_bits.cpp>
  #include <textual/string_manipulation.cpp>
  #include <textual/tokenizer.cpp>
#endif // __BUILD_STATIC_APPLICATION__

