1 #define _POSIX_C_SOURCE 200809L
2 #include "ruby/internal/config.h"
10 #include "ruby-runner.h"
12 #ifdef MAKE_MJIT_BUILD_DIR
13 const char MJIT_HEADER[] = BUILDDIR
"/" MJIT_MIN_HEADER;
16 #define STRINGIZE(expr) STRINGIZE0(expr)
17 #define STRINGIZE0(expr) #expr
20 insert_env_path(
const char *envname,
const char *paths,
size_t size,
int prepend)
22 const char *env = getenv(envname);
27 while ((c = *env) ==
PATH_SEP) ++env;
29 while (n > 0 && env[n-1] ==
PATH_SEP) --n;
32 char *e = malloc(size+n+1);
35 memcpy(e, paths, pos = size-1);
38 memcpy(e+pos, env, n);
42 memcpy(e+pos, paths, size-1);
51 setenv(envname, env, 1);
54 #define EXTOUT_DIR BUILDDIR"/"EXTOUT
56 main(
int argc,
char **argv)
58 static const char builddir[] = BUILDDIR;
59 static const char rubypath[] = BUILDDIR
"/"STRINGIZE(RUBY_INSTALL_NAME);
60 static const char rubylib[] =
68 static const char mjit_build_dir[] = BUILDDIR
"/mjit_build_dir."SOEXT;
71 const size_t dirsize =
sizeof(builddir);
72 const size_t namesize =
sizeof(rubypath) - dirsize;
73 const char *rubyname = rubypath + dirsize;
74 char *arg0 = argv[0], *p;
76 insert_env_path(LIBPATHENV, builddir, dirsize, 1);
77 insert_env_path(
"RUBYLIB", rubylib,
sizeof(rubylib), 0);
79 if (PRELOADENV[0] && stat(mjit_build_dir, &stbuf) == 0) {
80 insert_env_path(PRELOADENV, mjit_build_dir,
sizeof(mjit_build_dir), 1);
81 setenv(
"MJIT_SEARCH_BUILD_DIR",
"true", 0);
85 if (!(p = strrchr(arg0,
'/'))) p = arg0;
else p++;
86 if (strlen(p) < namesize - 1) {
87 argv[0] = malloc(p - arg0 + namesize);
88 memcpy(argv[0], arg0, p - arg0);
89 p = argv[0] + (p - arg0);
91 memcpy(p, rubyname, namesize);
93 execv(rubypath, argv);
#define PATH_SEP
The delimiter of PATH environment variable.