mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
mjit.c: build dir prefix
* mjit.c (init_header_filename): prepend basedir to header build dir too, so that the header can be found when running not in the build directory. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
427b2ac250
commit
4917aef04e
1 changed files with 34 additions and 20 deletions
54
mjit.c
54
mjit.c
|
@ -1043,12 +1043,32 @@ mjit_get_iseq_func(const struct rb_iseq_constant_body *body)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A name of the header file included in any C file generated by MJIT for iseqs. */
|
/* A name of the header file included in any C file generated by MJIT for iseqs. */
|
||||||
#define RUBY_MJIT_HEADER_FILE ("rb_mjit_min_header-" RUBY_VERSION ".h")
|
#define RUBY_MJIT_HEADER_FILE "rb_mjit_min_header-" RUBY_VERSION ".h"
|
||||||
/* GCC and CLANG executable paths. TODO: The paths should absolute
|
/* GCC and CLANG executable paths. TODO: The paths should absolute
|
||||||
ones to prevent changing C compiler for security reasons. */
|
ones to prevent changing C compiler for security reasons. */
|
||||||
#define GCC_PATH "gcc"
|
#define GCC_PATH "gcc"
|
||||||
#define CLANG_PATH "clang"
|
#define CLANG_PATH "clang"
|
||||||
|
|
||||||
|
#define append_str2(p, str, len) ((char *)memcpy((p), str, (len))+(len))
|
||||||
|
#define append_str(p, str) append_str2(p, str, sizeof(str)-1)
|
||||||
|
|
||||||
|
static char *
|
||||||
|
build_header_path(const char *basedir, size_t baselen, const char *dir, size_t dirlen)
|
||||||
|
{
|
||||||
|
static const char header_basename[] = "/" RUBY_MJIT_HEADER_FILE;
|
||||||
|
char *p, *path = xmalloc(baselen + dirlen + sizeof(header_basename));
|
||||||
|
if (path == NULL)
|
||||||
|
return NULL;
|
||||||
|
p = path;
|
||||||
|
p = append_str2(p, basedir, baselen);
|
||||||
|
p = append_str2(p, dir, dirlen);
|
||||||
|
append_str2(p, header_basename, sizeof(header_basename));
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BUILD_HEADER_PATH(basedir, baselen, dir) \
|
||||||
|
build_header_path(basedir, baselen, dir, rb_strlen_lit(dir))
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_header_filename(void)
|
init_header_filename(void)
|
||||||
{
|
{
|
||||||
|
@ -1056,27 +1076,20 @@ init_header_filename(void)
|
||||||
/* Root path of the running ruby process. Equal to RbConfig::TOPDIR. */
|
/* Root path of the running ruby process. Equal to RbConfig::TOPDIR. */
|
||||||
VALUE basedir_val;
|
VALUE basedir_val;
|
||||||
char *basedir;
|
char *basedir;
|
||||||
|
size_t baselen;
|
||||||
|
|
||||||
basedir_val = rb_const_get(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"));
|
basedir_val = rb_const_get(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"));
|
||||||
basedir = StringValueCStr(basedir_val);
|
basedir = StringValuePtr(basedir_val);
|
||||||
|
baselen = RSTRING_LEN(basedir_val);
|
||||||
|
|
||||||
header_file = xmalloc(strlen(MJIT_HEADER_BUILD_DIR) + 2 + strlen(RUBY_MJIT_HEADER_FILE));
|
header_file = BUILD_HEADER_PATH(basedir, baselen, "/"MJIT_HEADER_BUILD_DIR);
|
||||||
if (header_file == NULL)
|
if (header_file == NULL)
|
||||||
return;
|
return;
|
||||||
strcpy(header_file, MJIT_HEADER_BUILD_DIR);
|
|
||||||
strcat(header_file, "/");
|
|
||||||
strcat(header_file, RUBY_MJIT_HEADER_FILE);
|
|
||||||
|
|
||||||
if ((f = fopen(header_file, "r")) == NULL) {
|
if ((f = fopen(header_file, "r")) == NULL) {
|
||||||
xfree(header_file);
|
xfree(header_file);
|
||||||
header_file = xmalloc(strlen(basedir) + 1 + strlen(MJIT_HEADER_INSTALL_DIR) + 1 + strlen(RUBY_MJIT_HEADER_FILE) + 1);
|
header_file = BUILD_HEADER_PATH(basedir, baselen, "/"MJIT_HEADER_INSTALL_DIR);
|
||||||
if (header_file == NULL)
|
if (header_file == NULL)
|
||||||
return;
|
return;
|
||||||
strcpy(header_file, basedir);
|
|
||||||
strcat(header_file, "/");
|
|
||||||
strcat(header_file, MJIT_HEADER_INSTALL_DIR);
|
|
||||||
strcat(header_file, "/");
|
|
||||||
strcat(header_file, RUBY_MJIT_HEADER_FILE);
|
|
||||||
if ((f = fopen(header_file, "r")) == NULL) {
|
if ((f = fopen(header_file, "r")) == NULL) {
|
||||||
xfree(header_file);
|
xfree(header_file);
|
||||||
header_file = NULL;
|
header_file = NULL;
|
||||||
|
@ -1086,13 +1099,14 @@ init_header_filename(void)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
libruby_build = xmalloc(2 + strlen(basedir) + 1);
|
p = libruby_build = xmalloc(2 + baselen + 1);
|
||||||
strcpy(libruby_build, "-L");
|
p = append_str(p, "-L");
|
||||||
strcat(libruby_build, basedir);
|
p = append_str2(p, basedir, baselen);
|
||||||
libruby_installed = xmalloc(2 + strlen(basedir) + 4 + 1);
|
*p = '\0';
|
||||||
strcpy(libruby_installed, "-L");
|
libruby_installed = xmalloc(2 + baselen + 4 + 1);
|
||||||
strcat(libruby_installed, basedir);
|
p = append_str2(libruby_installed, libruby_build, p - libruby_build);
|
||||||
strcat(libruby_installed, "/lib");
|
p = append_str(p, "/lib");
|
||||||
|
*p = '\0';
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue