Eric H. wrote in post #1062725:
On May 28, 2012, at 03:57, Iaki Baz C. wrote:
Hi, depending whether my Ruby C extension is being compiled on *nix or
Windows, I need some #defines (i.e: OS_UNIX or OS_WIN).
I see no way in MKMF documentation to generate a #define (based on
RbConfig[“host_os”] for example).
Do not use host_* values from rbconfig.rb.
Use target_* values from rbconfig.rb.
Using host_* is wrong.
The host_* values come from host that compiled ruby. When ruby is
cross-compiled these values won’t match the target and your gem will
fail to compile.
You should use target_* values as these values match the target ruby was
compiled for.
See: http://sources.redhat.com/autobook/autobook/autobook_261.html
While this definition of host/target appears wrong, it doesn’t matter in
this case.
IIRC, the powerful-but-hellish autotools system gives these meanings to
build/host/target:
build - the type of the system used to configure and build a package.
Defaults to output of config.guess
host - the type of the system on which the built package executes.
Defaults to the same type as the build system and enables cross
compilation mode.
target - used for building compiler tools for cross compiling. The type
of the system for which any compiler tools built from the package
produce code for. Defaults to the same type as the host.
I believe it’s more correct to use RbConfig::CONFIG['host_os']
to
determine *nix v. Windows.
Here’s output from two builds, the first built natively on Windows with
MinGW, and the second built on Arch Linux cross compiled with MinGW for
Windows.
RbConfig::CONFIG.each do |k,v|
| puts “#{k} = #{v}” if k =~ /build|host|target/
| end
MinGW/GCC 4.6.2 native Windows build
target_os = mingw32
target_vendor = pc
target_cpu = i386
target = i386-pc-mingw32
host_os = mingw32
host_vendor = pc
host_cpu = i686
host = i686-pc-mingw32
build_os = mingw32
build_vendor = pc
build_cpu = i686
build = i686-pc-mingw32
target_alias =
host_alias =
build_alias =
Arch 3.3.7 Linux → Windows cross compiled build
…/configure --enable-shared --disable-install-doc --host=i486-mingw32
target_os = mingw32
target_vendor = pc
target_cpu = i386
target = i386-pc-mingw32
host_os = mingw32
host_vendor = pc
host_cpu = i486
host = i486-pc-mingw32
build_os = linux-gnu
build_vendor = pc
build_cpu = i686
build = i686-pc-linux-gnu
target_alias =
host_alias = i486-mingw32
build_alias =
Jon
Fail fast. Fail often. Fail publicly. Learn. Adapt. Repeat.
http://thecodeshop.github.com | http://jonforums.github.com/
twitter: @jonforums