Merge branch 'release-2.140.116'
[feisty_meow.git] / nucleus / tools / clam_tools / version_stamper.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : version_stamper                                                   *
4 *  Author : Chris Koeritz                                                     *
5 *                                                                             *
6 *******************************************************************************
7 * Copyright (c) 1995-$now By Author.  This program is free software; you can  *
8 * redistribute it and/or modify it under the terms of the GNU General Public  *
9 * License as published by the Free Software Foundation; either version 2 of   *
10 * the License or (at your option) any later version.  This is online at:      *
11 *     http://www.fsf.org/copyleft/gpl.html                                    *
12 * Please send any updates to: fred@gruntose.com                               *
13 \*****************************************************************************/
14
15 #include <application/application_shell.h>
16 #include <application/command_line.h>
17 #include <application/hoople_main.h>
18 #include <application/windoze_helper.h>
19 #include <loggers/program_wide_logger.h>
20 #include <basis/astring.h>
21 #include <basis/enhance_cpp.h>
22 #include <filesystem/byte_filer.h>
23 #include <filesystem/directory.h>
24 #include <filesystem/filename.h>
25 #include <loggers/console_logger.h>
26 #include <structures/static_memory_gremlin.h>
27 #include <structures/version_record.h>
28 #include <versions/version_ini.h>
29
30 #undef LOG
31 #define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger(), to_print)
32
33 using namespace application;
34 using namespace basis;
35 using namespace filesystem;
36 using namespace loggers;
37 using namespace structures;
38 using namespace versions;
39
40 //! This class creates resource information for applications and libraries to be version stamped.
41 /*!
42   This creates a resource (.rc) file and a C++ header (.h) file when given the directory where
43   a version information file (version.ini) resides.  It creates the files in that directory.
44 */
45
46 class version_stamper : public application_shell
47 {
48 public:
49   version_stamper();
50   ~version_stamper();
51
52   DEFINE_CLASS_NAME("version_stamper");
53
54   int execute();
55     // performs the main action of creating resource and code files.
56 };
57
58 //////////////
59
60 version_stamper::version_stamper() : application_shell()
61 {
62 }
63
64 version_stamper::~version_stamper() {}
65
66 int version_stamper::execute()
67 {
68   FUNCDEF("execute");
69   SETUP_CONSOLE_LOGGER;  // override the file_logger from app_shell.
70   if (application::_global_argc < 3) {
71     log(astring(
72 "The directory where the 'version.ini' file is located must be specified as the\n"
73 "first parameter of this program.  The second parameter must provide the\n"
74 "storage location where the version header will be written.  Another version\n"
75 "file may optionally be specified as the third parameter of the program; the\n"
76 "version contained in this file will be used to set the version of the file\n"
77 "specified in the first parameter.\n"
78 "Additionally, if the environment variable 'DEBUG' exists, then the\n"
79 "generated RC file will be marked as a debug build.  Otherwise it is\n"
80 "marked as a release build.  Note that the CLAM system automatically\n"
81 "sets this for you.\n\n"), ALWAYS_PRINT);
82     return 1;
83   }
84
85   astring path_name = application::_global_argv[1];
86   astring storage_name = application::_global_argv[2];
87   astring source_version_file;  // blank by default.
88   if (application::_global_argc > 3)
89     source_version_file = application::_global_argv[3];
90   bool ret = version_ini::one_stop_version_stamp(path_name, storage_name, source_version_file, true);
91   if (!ret) return 1;  // failure.
92   return 0;  // success.
93 }
94
95 HOOPLE_MAIN(version_stamper, )
96
97 #ifdef __BUILD_STATIC_APPLICATION__
98   // static dependencies found by buildor_gen_deps.sh:
99   #include <application/application_shell.cpp>
100   #include <application/command_line.cpp>
101   #include <application/windoze_helper.cpp>
102   #include <basis/astring.cpp>
103   #include <basis/common_outcomes.cpp>
104   #include <basis/environment.cpp>
105   #include <basis/guards.cpp>
106   #include <basis/mutex.cpp>
107   #include <basis/utf_conversion.cpp>
108   #include <configuration/application_configuration.cpp>
109   #include <configuration/configurator.cpp>
110   #include <configuration/ini_configurator.cpp>
111   #include <configuration/ini_parser.cpp>
112   #include <configuration/table_configurator.cpp>
113   #include <configuration/variable_tokenizer.cpp>
114   #include <filesystem/byte_filer.cpp>
115   #include <filesystem/directory.cpp>
116   #include <filesystem/filename.cpp>
117   #include <loggers/combo_logger.cpp>
118   #include <loggers/console_logger.cpp>
119   #include <loggers/critical_events.cpp>
120   #include <loggers/file_logger.cpp>
121   #include <loggers/program_wide_logger.cpp>
122   #include <structures/bit_vector.cpp>
123   #include <structures/checksums.cpp>
124   #include <structures/object_packers.cpp>
125   #include <structures/static_memory_gremlin.cpp>
126   #include <structures/string_hasher.cpp>
127   #include <structures/string_table.cpp>
128   #include <structures/version_record.cpp>
129   #include <textual/byte_formatter.cpp>
130   #include <textual/parser_bits.cpp>
131   #include <textual/string_manipulation.cpp>
132   #include <timely/earth_time.cpp>
133   #include <timely/time_stamp.cpp>
134   #include <versions/version_ini.cpp>
135 #endif // __BUILD_STATIC_APPLICATION__
136