[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / version.c
blobe719a59da26ad117eae99019bed3079ecaaf54a9
1 /**********************************************************************
3 version.c -
5 $Author$
6 created at: Thu Sep 30 20:08:01 JST 1993
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
10 **********************************************************************/
12 #include "internal/cmdlineopt.h"
13 #include "ruby/ruby.h"
14 #include "version.h"
15 #include "vm_core.h"
16 #include "rjit.h"
17 #include "yjit.h"
18 #include <stdio.h>
20 #ifndef EXIT_SUCCESS
21 #define EXIT_SUCCESS 0
22 #endif
24 #ifdef RUBY_REVISION
25 # if RUBY_PATCHLEVEL == -1
26 # ifndef RUBY_BRANCH_NAME
27 # define RUBY_BRANCH_NAME "master"
28 # endif
29 # define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "RUBY_REVISION
30 # else
31 # define RUBY_REVISION_STR " revision "RUBY_REVISION
32 # endif
33 #else
34 # define RUBY_REVISION "HEAD"
35 # define RUBY_REVISION_STR ""
36 #endif
37 #if !defined RUBY_RELEASE_DATETIME || RUBY_PATCHLEVEL != -1
38 # undef RUBY_RELEASE_DATETIME
39 # define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
40 #endif
42 #define PRINT(type) puts(ruby_##type)
43 #define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
44 #define MKINT(name) INT2FIX(ruby_##name)
46 const int ruby_api_version[] = {
47 RUBY_API_VERSION_MAJOR,
48 RUBY_API_VERSION_MINOR,
49 RUBY_API_VERSION_TEENY,
51 #define RUBY_VERSION \
52 STRINGIZE(RUBY_VERSION_MAJOR) "." \
53 STRINGIZE(RUBY_VERSION_MINOR) "." \
54 STRINGIZE(RUBY_VERSION_TEENY) ""
55 #ifndef RUBY_FULL_REVISION
56 # define RUBY_FULL_REVISION RUBY_REVISION
57 #endif
58 #ifdef YJIT_SUPPORT
59 #define YJIT_DESCRIPTION " +YJIT " STRINGIZE(YJIT_SUPPORT)
60 #else
61 #define YJIT_DESCRIPTION " +YJIT"
62 #endif
63 const char ruby_version[] = RUBY_VERSION;
64 const char ruby_revision[] = RUBY_FULL_REVISION;
65 const char ruby_release_date[] = RUBY_RELEASE_DATE;
66 const char ruby_platform[] = RUBY_PLATFORM;
67 const int ruby_patchlevel = RUBY_PATCHLEVEL;
68 const char ruby_description[] =
69 "ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR " "
70 "(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR ") "
71 "[" RUBY_PLATFORM "]";
72 static const int ruby_description_opt_point =
73 (int)(sizeof(ruby_description) - sizeof(" [" RUBY_PLATFORM "]"));
75 const char ruby_copyright[] = "ruby - Copyright (C) "
76 RUBY_BIRTH_YEAR_STR "-" RUBY_RELEASE_YEAR_STR " "
77 RUBY_AUTHOR;
78 const char ruby_engine[] = "ruby";
80 // Might change after initialization
81 const char *rb_dynamic_description = ruby_description;
83 /*! Defines platform-depended Ruby-level constants */
84 void
85 Init_version(void)
87 enum {ruby_patchlevel = RUBY_PATCHLEVEL};
88 VALUE version = MKSTR(version);
89 VALUE ruby_engine_name = MKSTR(engine);
90 // MKSTR macro is a marker for fake.rb
93 * The running version of ruby
95 rb_define_global_const("RUBY_VERSION", /* MKSTR(version) */ version);
97 * The date this ruby was released
99 rb_define_global_const("RUBY_RELEASE_DATE", MKSTR(release_date));
101 * The platform for this ruby
103 rb_define_global_const("RUBY_PLATFORM", MKSTR(platform));
105 * The patchlevel for this ruby. If this is a development build of ruby
106 * the patchlevel will be -1
108 rb_define_global_const("RUBY_PATCHLEVEL", MKINT(patchlevel));
110 * The GIT commit hash for this ruby.
112 rb_define_global_const("RUBY_REVISION", MKSTR(revision));
114 * The copyright string for ruby
116 rb_define_global_const("RUBY_COPYRIGHT", MKSTR(copyright));
118 * The engine or interpreter this ruby uses.
120 rb_define_global_const("RUBY_ENGINE", /* MKSTR(engine) */ ruby_engine_name);
121 ruby_set_script_name(ruby_engine_name);
123 * The version of the engine or interpreter this ruby uses.
125 rb_define_global_const("RUBY_ENGINE_VERSION", /* MKSTR(version) */ version);
127 rb_provide("ruby2_keywords.rb");
130 #if USE_RJIT
131 #define RJIT_OPTS_ON opt->rjit.on
132 #else
133 #define RJIT_OPTS_ON 0
134 #endif
136 #if USE_YJIT
137 #define YJIT_OPTS_ON opt->yjit
138 #else
139 #define YJIT_OPTS_ON 0
140 #endif
142 int ruby_mn_threads_enabled;
144 bool * rb_ruby_prism_ptr(void);
146 static void
147 define_ruby_description(const char *const jit_opt)
149 static char desc[
150 sizeof(ruby_description)
151 + rb_strlen_lit(YJIT_DESCRIPTION)
152 + rb_strlen_lit(" +MN")
155 const char *const threads_opt = ruby_mn_threads_enabled ? " +MN" : "";
156 const char *const parser_opt = (*rb_ruby_prism_ptr()) ? " +PRISM" : "";
158 int n = snprintf(desc, sizeof(desc),
159 "%.*s"
160 "%s" // jit_opt
161 "%s" // threads_opts
162 "%s" // parser_opt
163 "%s",
164 ruby_description_opt_point, ruby_description,
165 jit_opt,
166 threads_opt,
167 parser_opt,
168 ruby_description + ruby_description_opt_point);
170 VALUE description = rb_obj_freeze(rb_usascii_str_new_static(desc, n));
171 rb_dynamic_description = desc;
174 * The full ruby version string, like <tt>ruby -v</tt> prints
176 rb_define_global_const("RUBY_DESCRIPTION", /* MKSTR(description) */ description);
179 void
180 Init_ruby_description(ruby_cmdline_options_t *opt)
182 const char *const jit_opt =
183 RJIT_OPTS_ON ? " +RJIT" :
184 YJIT_OPTS_ON ? YJIT_DESCRIPTION :
186 define_ruby_description(jit_opt);
189 void
190 ruby_set_yjit_description(void)
192 rb_const_remove(rb_cObject, rb_intern("RUBY_DESCRIPTION"));
193 define_ruby_description(YJIT_DESCRIPTION);
196 void
197 ruby_show_version(void)
199 puts(rb_dynamic_description);
201 #ifdef RUBY_LAST_COMMIT_TITLE
202 fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
203 #endif
204 #ifdef HAVE_MALLOC_CONF
205 if (malloc_conf) printf("malloc_conf=%s\n", malloc_conf);
206 #endif
207 fflush(stdout);
210 void
211 ruby_show_copyright(void)
213 PRINT(copyright);
214 fflush(stdout);