Jun's Blog

Output, activities, memo and etc.

Read Ruby source - 1. Install Ruby from source code

Install Ruby from source code

I wrote the blog about reading the ruby source code 5 years ago.
http://junaruga.hatenablog.com/entry/20091025/1256442339

And I will try it again.
Following Ruby Kaigi's presentation is my tutorial.
http://rubykaigi.org/2014/presentation/S-YUKITORII

There are great books to explore Ruby.
There are ebook versions for both English and Japanese version.

Japanese version has additional contents added by Matz and Sasada (Yarv's auther).
I am proud of that I am Japanese :)

Today install ruby (version 2.3.0dev) from source code as a first step to check the entire source code.

$ cd $GIT_DIR
$ git clone https://github.com/ruby/ruby

master branch's HEAD is "51cb462f428298458a49d526d299a20ebc8d83ef" in this case.

Check README.

$ view README.md

Compile

configure file is created by autoconf command.

$ autoconf

$ ls -l configure
-rwxr-xr-x  1 jun.aruga  staff  668339 Dec  8 21:41 configure*


GNUmakefile is created from template/GNUmakefile.in,
and Makefile is created from Makefile.in by configure script.
Do not forget prefix of configure not to stain /usr/local (default install path).
If compiled OS is Mac, it should be put with "--with-openssl-dir" option.
When I did not put its option, "make test-all" had errors.

$ ./configure --help

$ ./configure --prefix=/usr/local/ruby-2.3.0 --with-openssl-dir=`brew --prefix openssl`

Let's check what files were created.

$ ls -rlt
...

# following files are created by autoconf
-rwxr-xr-x    1 jun.aruga  staff   668339 Dec  8 21:41 configure*
drwxr-xr-x    5 jun.aruga  staff      170 Dec  8 21:41 autom4te.cache/
drwxr-xr-x   53 jun.aruga  staff     1802 Dec  8 21:41 tool/


# following files are created by ./configure
-rw-r--r--    1 jun.aruga  staff        0 Dec  8 21:42 verconf.h
-rw-r--r--    1 jun.aruga  staff    80750 Dec  8 21:42 uncommon.mk
-rw-r--r--    1 jun.aruga  staff     1804 Dec  8 21:42 ruby-2.3.pc
-rwxr-xr-x    1 jun.aruga  staff    32844 Dec  8 21:42 config.status*
-rw-r--r--    1 jun.aruga  staff  1111592 Dec  8 21:42 config.log
-rw-r--r--    1 jun.aruga  staff    17306 Dec  8 21:42 Makefile
-rw-r--r--    1 jun.aruga  staff      165 Dec  8 21:42 GNUmakefile
drwxr-xr-x    3 jun.aruga  staff      102 Dec  8 21:42 .ext/

Please note there are GNUmakefile and Makefile on this directory.
The specification of GNU make, GNUmakefile is run in this case, when make command is run.
http://www.gnu.org/software/make/manual/make.html

And GNUmakefile calls, Makefile, uncommon.mk, and gmake.mk

$ view GNUmakefile
override MFLAGS := $(filter-out -j%,$(MFLAGS))
include Makefile
-include uncommon.mk
include $(srcdir)/defs/gmake.mk

GNUmakefile: $(srcdir)/template/GNUmakefile.in


Check DESTDIR and prefix just in case, which are used for "make install".

$ view Makefile
...
prefix = /usr/local/ruby-2.3.0
...
DESTDIR       = 
...

Check defines.h just in case.

$ view ./include/ruby/defines.h

Check Setup file. There are list of modules. If you want to do static compile for one module, you have to remove # of the line (do comment out).

$ vi ext/Setup

Do make to compile.
It takes time about 2 minutes on my Mac pc.

$ make
...
  Files:        944

  Classes:     1401 ( 583 undocumented)
  Modules:      280 ( 111 undocumented)
  Constants:   2171 ( 603 undocumented)
  Attributes:  1144 ( 255 undocumented)
  Methods:    10499 (2228 undocumented)

  Total:      15495 (3780 undocumented)
   75.61% documented

  Elapsed: 110.3s

Do "make install".

$ make install

$ ls -l /usr/local/ruby-2.3.0
total 0
drwxr-xr-x  8 jun.aruga  admin  272 Dec  8 22:48 bin/
drwxr-xr-x  3 jun.aruga  admin  102 Dec  8 22:48 include/
drwxr-xr-x  5 jun.aruga  admin  170 Dec  8 22:48 lib/
drwxr-xr-x  5 jun.aruga  admin  170 Dec  8 22:49 share/
$ /usr/local/ruby-2.3.0/bin/ruby -v
ruby 2.3.0dev (2015-12-06 trunk 52910) [x86_64-darwin13]