summaryrefslogtreecommitdiffhomepage
path: root/doc
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-01-25 10:29:56 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-01-25 10:45:57 +0900
commit73ce5db1700cbb3a73c964bd4b49d8cd144d1b03 (patch)
tree86671e67c963487f3ccf8691516e44d34d3b06fe /doc
parent05a8cc44cc8fef84158f5d00eb8b6ead2c552eff (diff)
downloadmruby-73ce5db1700cbb3a73c964bd4b49d8cd144d1b03.tar.gz
mruby-73ce5db1700cbb3a73c964bd4b49d8cd144d1b03.zip
Add description for `mruby-config` in `compile.md`. [ci skip]
For easier compiling and linking of the application embedding `mruby`
Diffstat (limited to 'doc')
-rw-r--r--doc/guides/compile.md49
1 files changed, 41 insertions, 8 deletions
diff --git a/doc/guides/compile.md b/doc/guides/compile.md
index 6776719eb..3a6551f53 100644
--- a/doc/guides/compile.md
+++ b/doc/guides/compile.md
@@ -10,7 +10,7 @@ To compile mruby out of the source code you need the following tools:
* C Compiler (e.g. `gcc` or `clang`)
* Linker (e.g. `gcc` or `clang`)
* Archive utility (e.g. `ar`)
-* Parser generator (e.g. `bison`)
+* Parser generator (`bison`)
* Ruby 2.0 or later (e.g. `ruby` or `jruby`)
Note that `bison` bundled with MacOS is too old to compile `mruby`.
@@ -22,7 +22,6 @@ Optional:
* git (to update mruby source and integrate mrbgems easier)
* C++ compiler (to use GEMs which include \*.cpp, \*.cxx, \*.cc)
-* Assembler (to use GEMs which include \*.asm)
## Build
@@ -41,7 +40,7 @@ example:
```ruby
MRuby::Build.new do |conf|
- toolchain :gcc
+ conf.toolchain :gcc
end
```
@@ -65,7 +64,7 @@ configure the build environment for specific compiler infrastructures.
Toolchain configuration for the GNU C Compiler.
```ruby
-toolchain :gcc
+conf.toolchain :gcc
```
#### clang
@@ -74,7 +73,7 @@ Toolchain configuration for the LLVM C Compiler clang. Mainly equal to the
GCC toolchain.
```ruby
-toolchain :clang
+conf.toolchain :clang
```
#### Visual Studio 2010, 2012 and 2013
@@ -84,7 +83,7 @@ Toolchain configuration for Visual Studio on Windows. If you use the
you normally do not have to specify this manually, since it gets automatically detected by our build process.
```ruby
-toolchain :visualcpp
+conf.toolchain :visualcpp
```
#### Android
@@ -92,7 +91,7 @@ toolchain :visualcpp
Toolchain configuration for Android.
```ruby
-toolchain :android
+conf.toolchain :android
```
Requires the custom standalone Android NDK and the toolchain path
@@ -338,7 +337,7 @@ for the target platform. An example could look like this:
```ruby
MRuby::CrossBuild.new('32bit') do |conf|
- toolchain :gcc
+ conf.toolchain :gcc
conf.cc.flags << "-m32"
conf.linker.flags << "-m32"
@@ -537,3 +536,37 @@ of mruby, a native binary called `mrbtest` will be generated and executed.
This binary contains all test cases which are defined under *test/t*. In case
of a cross-compilation an additional cross-compiled *mrbtest* binary is
generated. You can copy this binary and run on your target system.
+
+## Embedding `mruby` in Your Application
+
+After the build, you will get `libmruby.a`. You can link it to your application.
+
+For compiler options and library path, you can use `mruby-config` command for
+convenience. `mruby-config` command prints the configuration used for `libmruby.a`.
+
+```
+$ mruby-config --help
+Usage: mruby-config [switches]
+ switches:
+ --cflags print flags passed to compiler
+ --ldflags print flags passed to linker
+ --ldflags-before-libs print flags passed to linker before linked libraries
+ --libs print linked libraries
+ --libmruby-path print libmruby path
+```
+
+For example, when you have a C source file (`c.c`) and try to
+compile and link it with `libmruby.a`, you can run the following command,
+
+```
+gcc `mruby-config --cflags` c.c `mruby-config --ldflags` `mruby-config --libs`
+```
+
+When you use `make`, add following lines in `Makefile`
+
+```
+MRB_CONFIG = <path-to-mruby-config>
+CFLAGS = `$(MRB_CONFIG) --cflags`
+LDFLAGS = `$(MRB_CONFIG) --ldflags`
+LIBS = `$(MRB_CONFIG) --libs`
+```