path: root/README.EXT
diff options
Diffstat (limited to 'README.EXT')
1 files changed, 53 insertions, 51 deletions
diff --git a/README.EXT b/README.EXT
index 9a56bd9..97b5b1d 100644
@@ -1,6 +1,6 @@
.\" README.EXT - -*- Text -*- created at: Mon Aug 7 16:45:54 JST 1995
-This document explains how to make extention modules for Ruby.
+This document explains how to make extention libraries for Ruby.
1.Basic knowledge
@@ -184,11 +184,6 @@ interpreter. Useful functions are listed below (not all):
2. Extend Ruby with C
2.1 Add new features to Ruby
You can add new features (classes, methods, etc.) to the Ruby
@@ -422,7 +417,7 @@ The pointer to the structure will be assigned to the variable sval.
See example below for detail.
-4.Example - Create dbm module
+4.Example - Creating dbm extension
OK, here's the example to make extension library. This is the
extension to access dbm. The full source is included in ext/
@@ -448,17 +443,17 @@ You need to design the library features, before making it.
(4) write C code.
+You need to write C code for your extension library. If your library
+has only one source file, choosing ``LIBRARY.c'' as a file name is
+preferred. On the other hand, in case your library has prural source
+files, avoid chooing ``LIBRARY.c'' for a file name. It may conflict
+with intermediate file ``LIBRARY.o'' on some platforms.
+Ruby will execute the initializing function named ``Init_LIBRARY'' in
+the library. For exapmle, ``Init_dbm()'' will be executed when loading
+the library.
+Here's the example of an initializing function.
@@ -480,11 +475,7 @@ Init_dbm()
+The dbm extension wrap dbm struct in C world using Data_Make_Struct.
struct dbmdata {
@@ -593,23 +584,27 @@ If there exists the file named extconf.rb, it will be executed to
generate Makefile. If not, compilation scheme try to generate
Makefile anyway.
+The extconf.rb is the file to check compilation condition etc. You
+need to put
- have_library(lib, func): ライブラリの存在チェック
- have_func(func): 関数の存在チェック
- have_header(header): ヘッダファイルの存在チェック
- create_makefile(target): Makefileの生成
+ require 'mkmf'
+at the top of the file. You can use the funcitons below to check the
- $CFLAGS: コンパイル時に追加的に指定するフラグ(-Iなど)
- $LDFLAGS: リンク時に追加的に指定するフラグ(-Lなど)
+ have_library(lib, func): check whether library containing function exists.
+ have_func(func): check whether function exists
+ have_header(header): check whether header file exists
+ create_makefile(target): generate Makefile
+The value of variables below will affect Makefile.
+ $CFLAGS: included in CFLAGS make variable (such as -I)
+ $LDFLAGS: included in LDFLAGS make variable (such as -L)
+If compilation condition is not fulfilled, you do not call
+``create_makefile''. Makefile will not generated, compilation will
+not be done.
(6) prepare depend (optional)
@@ -620,7 +615,7 @@ check dependency. You can make this file by invoking
It's no harm. Prepare it.
-(7) MANIFESTファイルにファイル名を入れる
+(7) put file names into MANIFEST (optional)
% find * -type f -print > MANIFEST
@@ -629,18 +624,30 @@ Append file names into MANIFEST. The compilation scheme requires
MANIFEST only to be exist. But, you'd better take this step to
distinguish required files.
-(8) make
+(8) generate Makefile
+Try generate Makefile by:
+ ruby extconf.rb
+You don't need this step, if you put extension library under ext
+directory of the ruby source tree. In that case, compilation of the
+interpreter will do this step for you.
+(9) make
+ make
+to compile your extension. You don't need this step neither, if you
+put extension library under ext directory of the ruby source tree.
(9) debug
-You may need to rb_debug the module. The modules can be linked
-statically by adding directory name in the ext/Setup file,
-so that you can inspect the module by the debugger.
+You may need to rb_debug the extension. The extensions can be linked
+statically by adding directory name in the ext/Setup file, so that you
+can inspect the extension with the debugger.
(10) done, now you have the extension library
@@ -648,12 +655,7 @@ You can do anything you want with your library. The author of Ruby
will not claim any restriction about your code depending Ruby API.
Feel free to use, modify, distribute or sell your program.
-Appendix A. Rubyのソースコードの分類
+Appendix A. Ruby source files overview
ruby language core
@@ -865,7 +867,7 @@ argc,argv形式で与えられた引数を分解する.fmtは必須引数の数,
-** Rubyメソッド呼び出し
+** Invoking Ruby method
VALUE rb_funcall(VALUE recv, ID mid, int narg, ...)