Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Last active October 12, 2015 02:27
Show Gist options
  • Save kou1okada/3956838 to your computer and use it in GitHub Desktop.
Save kou1okada/3956838 to your computer and use it in GitHub Desktop.
Patch for compiling ruby on some platforms.
#!/usr/bin/env bash
TARGET_URL=http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz
PATCH_URL=https://gist.github.com/kou1okada/3956838/raw/ruby-2.1.5.cygwin64.patch
HASH="$(cat <<EOD
df4c1b23f624a50513c7a78cb51a13dc *ruby-2.1.5.tar.gz
feba105b7393c36df66eb34daf937974 *ruby-2.1.5.cygwin64.patch
EOD
)"
TARGET_ARCHIVE="${TARGET_URL##*/}"
TARGET_DIR="${TARGET_ARCHIVE%.tar.*}"
TARGET_VERSION="${TARGET_DIR#ruby-}"
PATCH="${PATCH_URL##*/}"
cd /tmp
wget -Nc "${TARGET_URL}"
wget -Nc "${PATCH_URL}"
echo "$HASH" | md5sum -c || exit
tar xvf "${TARGET_ARCHIVE}"
cd "${TARGET_DIR}"
if [ "${PATCH}" != "" ]; then patch -p1 < "../${PATCH}"; fi
./configure --prefix="$HOME/.rbenv/versions/${TARGET_VERSION}"
make install
rbenv rehash
diff -rc ruby-1.8.7-p371.orig/eval.c ruby-1.8.7-p371/eval.c
*** ruby-1.8.7-p371.orig/eval.c 2012-06-29 21:31:25.000000000 +0900
--- ruby-1.8.7-p371/eval.c 2012-10-26 12:46:15.550694800 +0900
***************
*** 217,225 ****
# define ruby_setjmp(extra_save, env) \
((extra_save), RUBY_SETJMP(env))
# define ruby_longjmp(env,val) RUBY_LONGJMP(env,val)
- # ifdef __CYGWIN__
- int _setjmp(), _longjmp();
- # endif
#endif
#include <sys/types.h>
--- 217,222 ----
diff -rc ruby-1.8.7-p371.orig/gc.c ruby-1.8.7-p371/gc.c
*** ruby-1.8.7-p371.orig/gc.c 2009-12-24 17:28:08.000000000 +0900
--- ruby-1.8.7-p371/gc.c 2012-10-26 12:46:34.356770400 +0900
***************
*** 39,47 ****
#define rb_setjmp(env) RUBY_SETJMP(env)
#define rb_jmp_buf rb_jmpbuf_t
- #ifdef __CYGWIN__
- int _setjmp(), _longjmp();
- #endif
/* Make alloca work the best possible way. */
#ifdef __GNUC__
--- 39,44 ----
diff -crN ruby-2.1.1.orig/ext/readline/readline.c ruby-2.1.1/ext/readline/readline.c
*** ruby-2.1.1.orig/ext/readline/readline.c 2013-10-29 12:09:00.000000000 +0900
--- ruby-2.1.1/ext/readline/readline.c 2014-04-21 19:34:52.735455111 +0900
***************
*** 1974,1980 ****
rl_attempted_completion_function = readline_attempted_completion_function;
#if defined(HAVE_RL_PRE_INPUT_HOOK)
! rl_pre_input_hook = (Function *)readline_pre_input_hook;
#endif
#ifdef HAVE_RL_CATCH_SIGNALS
rl_catch_signals = 0;
--- 1974,1980 ----
rl_attempted_completion_function = readline_attempted_completion_function;
#if defined(HAVE_RL_PRE_INPUT_HOOK)
! rl_pre_input_hook = (rl_hook_func_t *)readline_pre_input_hook;
#endif
#ifdef HAVE_RL_CATCH_SIGNALS
rl_catch_signals = 0;
diff -crN ruby-2.1.5.orig/ext/-test-/printf/printf.c ruby-2.1.5/ext/-test-/printf/printf.c
*** ruby-2.1.5.orig/ext/-test-/printf/printf.c 2014-06-30 02:17:20.000000000 +0900
--- ruby-2.1.5/ext/-test-/printf/printf.c 2015-02-15 19:52:35.209994800 +0900
***************
*** 28,34 ****
}
static char *
! utoa(char *p, char *e, unsigned int x)
{
char *e0 = e;
if (e <= p) return p;
--- 28,34 ----
}
static char *
! my_utoa(char *p, char *e, unsigned int x)
{
char *e0 = e;
if (e <= p) return p;
***************
*** 79,90 ****
*p++ = '0';
}
if (!NIL_P(v = rb_hash_aref(opt, ID2SYM(rb_intern("width"))))) {
! p = utoa(p, format + sizeof(format), NUM2UINT(v));
}
if (!NIL_P(v = rb_hash_aref(opt, ID2SYM(rb_intern("prec"))))) {
*p++ = '.';
if (FIXNUM_P(v))
! p = utoa(p, format + sizeof(format), NUM2UINT(v));
}
}
*p++ = cnv;
--- 79,90 ----
*p++ = '0';
}
if (!NIL_P(v = rb_hash_aref(opt, ID2SYM(rb_intern("width"))))) {
! p = my_utoa(p, format + sizeof(format), NUM2UINT(v));
}
if (!NIL_P(v = rb_hash_aref(opt, ID2SYM(rb_intern("prec"))))) {
*p++ = '.';
if (FIXNUM_P(v))
! p = my_utoa(p, format + sizeof(format), NUM2UINT(v));
}
}
*p++ = cnv;
#!/usr/bin/env bash
TARGET_URL=http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz
PATCH_URL=https://gist.github.com/kou1okada/3956838/raw/da95ee34f9c8f8289a9081ad8cadfa1df7dc9b79/ruby-2.1.1.ubuntu14.04.patch
HASH="$(cat <<EOD
e57fdbb8ed56e70c43f39c79da1654b2 ruby-2.1.1.tar.gz
c1139e4d4361fbc92ad824270fb75c5b ruby-2.1.1.ubuntu14.04.patch
EOD
)"
TARGET_ARCHIVE="${TARGET_URL##*/}"
TARGET_DIR="${TARGET_ARCHIVE%.tar.*}"
TARGET_VERSION="${TARGET_DIR#ruby-}"
PATCH="${PATCH_URL##*/}"
cd /tmp
wget -Nc "${TARGET_URL}"
wget -Nc "${PATCH_URL}"
echo "$HASH" | md5sum -c || exit
tar xvf "${TARGET_ARCHIVE}"
cd "${TARGET_DIR}"
if [ "${PATCH}" != "" ]; then patch -p1 < "../${PATCH}"; fi
./configure --prefix="$HOME/.rbenv/versions/${TARGET_VERSION}"
make install
rbenv rehash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment