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 "internal/parse.h"
14 #include "internal/gc.h"
15 #include "ruby/ruby.h"
22 #define EXIT_SUCCESS 0
26 # if RUBY_PATCHLEVEL == -1
27 # ifndef RUBY_BRANCH_NAME
28 # define RUBY_BRANCH_NAME "master"
30 # define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "RUBY_REVISION
32 # define RUBY_REVISION_STR " revision "RUBY_REVISION
35 # define RUBY_REVISION "HEAD"
36 # define RUBY_REVISION_STR ""
38 #if !defined RUBY_RELEASE_DATETIME || RUBY_PATCHLEVEL != -1
39 # undef RUBY_RELEASE_DATETIME
40 # define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
43 #define PRINT(type) puts(ruby_##type)
44 #define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
45 #define MKINT(name) INT2FIX(ruby_##name)
47 const int ruby_api_version
[] = {
48 RUBY_API_VERSION_MAJOR
,
49 RUBY_API_VERSION_MINOR
,
50 RUBY_API_VERSION_TEENY
,
52 #define RUBY_VERSION \
53 STRINGIZE(RUBY_VERSION_MAJOR) "." \
54 STRINGIZE(RUBY_VERSION_MINOR) "." \
55 STRINGIZE(RUBY_VERSION_TEENY) ""
56 #ifndef RUBY_FULL_REVISION
57 # define RUBY_FULL_REVISION RUBY_REVISION
60 #define YJIT_DESCRIPTION " +YJIT " STRINGIZE(YJIT_SUPPORT)
62 #define YJIT_DESCRIPTION " +YJIT"
65 #define ZJIT_DESCRIPTION " +ZJIT " STRINGIZE(ZJIT_SUPPORT)
67 #define ZJIT_DESCRIPTION " +ZJIT"
70 #define JIT_DESCRIPTION ZJIT_DESCRIPTION
72 #define JIT_DESCRIPTION YJIT_DESCRIPTION
75 #define GC_DESCRIPTION " +GC"
77 #define GC_DESCRIPTION ""
79 const char ruby_version
[] = RUBY_VERSION
;
80 const char ruby_revision
[] = RUBY_FULL_REVISION
;
81 const char ruby_release_date
[] = RUBY_RELEASE_DATE
;
82 const char ruby_platform
[] = RUBY_PLATFORM
;
83 const int ruby_patchlevel
= RUBY_PATCHLEVEL
;
84 const char ruby_description
[] =
85 "ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR
" "
86 "(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR
") "
87 "[" RUBY_PLATFORM
"]";
88 static const int ruby_description_opt_point
=
89 (int)(sizeof(ruby_description
) - sizeof(" [" RUBY_PLATFORM
"]"));
91 const char ruby_copyright
[] = "ruby - Copyright (C) "
92 RUBY_BIRTH_YEAR_STR
"-" RUBY_RELEASE_YEAR_STR
" "
94 const char ruby_engine
[] = "ruby";
96 // Might change after initialization
97 const char *rb_dynamic_description
= ruby_description
;
100 define_ruby_const(VALUE mod
, const char *name
, VALUE value
, bool toplevel
)
103 rb_define_global_const(name
, value
);
104 name
+= rb_strlen_lit("RUBY_");
106 rb_define_const(mod
, name
, value
);
109 /* RDoc needs rb_define_const */
110 #define rb_define_const(mod, name, value) \
111 define_ruby_const(mod, (mod == mRuby ? "RUBY_" name : name), value, (mod == mRuby))
113 /*! Defines platform-depended Ruby-level constants */
118 * The Ruby[rdoc-ref:Ruby] module that contains portable information among
121 * The constants defined here are aliased in the toplevel with
124 VALUE mRuby
= rb_define_module("Ruby");
126 enum {ruby_patchlevel
= RUBY_PATCHLEVEL
};
127 VALUE version
= MKSTR(version
);
128 VALUE ruby_engine_name
= MKSTR(engine
);
129 // MKSTR macro is a marker for fake.rb
132 * The running version of ruby
134 rb_define_const(mRuby
, "VERSION", /* MKSTR(version) */ version
);
136 * The date this ruby was released
138 rb_define_const(mRuby
, "RELEASE_DATE", MKSTR(release_date
));
140 * The platform for this ruby
142 rb_define_const(mRuby
, "PLATFORM", MKSTR(platform
));
144 * The patchlevel for this ruby. If this is a development build of ruby
145 * the patchlevel will be -1
147 rb_define_const(mRuby
, "PATCHLEVEL", MKINT(patchlevel
));
149 * The GIT commit hash for this ruby.
151 rb_define_const(mRuby
, "REVISION", MKSTR(revision
));
153 * The copyright string for ruby
155 rb_define_const(mRuby
, "COPYRIGHT", MKSTR(copyright
));
157 * The engine or interpreter this ruby uses.
159 rb_define_const(mRuby
, "ENGINE", /* MKSTR(engine) */ ruby_engine_name
);
160 ruby_set_script_name(ruby_engine_name
);
162 * The version of the engine or interpreter this ruby uses.
164 rb_define_const(mRuby
, "ENGINE_VERSION", /* MKSTR(version) */ version
);
166 rb_provide("ruby2_keywords.rb");
170 #define YJIT_OPTS_ON opt->yjit
172 #define YJIT_OPTS_ON 0