1 /**********************************************************************
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"
21 #define EXIT_SUCCESS 0
25 # if RUBY_PATCHLEVEL == -1
26 # ifndef RUBY_BRANCH_NAME
27 # define RUBY_BRANCH_NAME "master"
29 # define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "RUBY_REVISION
31 # define RUBY_REVISION_STR " revision "RUBY_REVISION
34 # define RUBY_REVISION "HEAD"
35 # define RUBY_REVISION_STR ""
37 #if !defined RUBY_RELEASE_DATETIME || RUBY_PATCHLEVEL != -1
38 # undef RUBY_RELEASE_DATETIME
39 # define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
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
59 #define YJIT_DESCRIPTION " +YJIT " STRINGIZE(YJIT_SUPPORT)
61 #define YJIT_DESCRIPTION " +YJIT"
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
" "
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 */
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");
131 #define RJIT_OPTS_ON opt->rjit.on
133 #define RJIT_OPTS_ON 0
137 #define YJIT_OPTS_ON opt->yjit
139 #define YJIT_OPTS_ON 0
142 int ruby_mn_threads_enabled
;
144 bool * rb_ruby_prism_ptr(void);
147 define_ruby_description(const char *const jit_opt
)
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
),
164 ruby_description_opt_point
, ruby_description
,
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
);
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
);
190 ruby_set_yjit_description(void)
192 rb_const_remove(rb_cObject
, rb_intern("RUBY_DESCRIPTION"));
193 define_ruby_description(YJIT_DESCRIPTION
);
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
);
204 #ifdef HAVE_MALLOC_CONF
205 if (malloc_conf
) printf("malloc_conf=%s\n", malloc_conf
);
211 ruby_show_copyright(void)