cross compile

mingw版的gem通常是扩展c或者c++的,直接包含编译好的so,so对应ruby版本,如支持ruby1.8和1.9,则分别在lib/1.8和lib/1.9里有,现在要支持2.0,我在archlinux上编译了几个对应2.0的so,nokogiri、eventmachine、mysql2、yajl-ruby、bcrypt-ruby,给windows用。

# archlinux上装mingw

pacman -S mingw32-gcc


# rake-compiler

gem i rake-compiler
rake-compiler cross-ruby VERSION=2.0.0-p0 HOST=i486-mingw32

#=> --host=i486-mingw32 --target=i486-mingw32 --build=x86_64-unknown-linux-gnu --enable-shared --disable-install-doc --without-tk --without-tcl --prefix=/root/.rake-compiler/ruby/ruby-2.0.0-p0 build_alias=x86_64-unknown-linux-gnu host_alias=i486-mingw32 target_alias=i486-mingw32


# 得到对应mingw的so

gem i nokogiri -v 1.5.6
cd /usr/local/lib/ruby/gems/2.0.0/gems/nokogiri-1.5.6/

rake cross compile # 出错,假设过了这步

i486-mingw32-strip nokogiri.so # 瘦身


# 得到mingw版gem

rake cross native gem


编译mingw版nokogiri的前提是安装mingw版的libiconv,libxml2,libxslt,zlib,写一个要考虑这么多依赖的脚本难免出错,不如就写个HOW_TO

# nokogiri 1.5.6

依赖

## libiconv 1.13.1

wget http://mirror.anl.gov/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar xzvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1

./configure --host=i486-mingw32 --enable-static --disable-shared --prefix=/usr/i486-mingw32/libiconv/1.13.1
make && make install


## libxml2 2.8.0
wget ftp://xmlsoft.org/libxml2/libxml2-2.8.0.tar.gz
tar xzvf libxml2-2.8.0.tar.gz
cd libxml2-2.8.0/

./configure --host=i486-mingw32 --enable-static --disable-shared --prefix=/usr/i486-mingw32/libxml2/2.8.0
make && make install


## libxslt 1.1.26

wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
tar xzvf libxslt-1.1.26.tar.gz
cd libxslt-1.1.26


in xsltproc/testThreads.c line 203 and 245:
tid[i]=(pthread_t)-1;

should be
tid[i].p= NULL;
tid[i].x=-1;


./configure --host=i486-mingw32 --enable-static --disable-shared --with-libxml-prefix=/usr/i486-mingw32/libxml2/2.8.0 --without-python --without-crypto CFLAGS=-DIN_LIBXML --prefix=/usr/i486-mingw32/libxslt/1.1.26
make && make install


## zlib 1.2.7

on win32/Makefile.gcc line 44
  
PREFIX =

should be
  
PREFIX = i486-mingw32-


make -f win32/Makefile.gcc BINARY_PATH=/usr/i486-mingw32/zlib/1.2.7/bin INCLUDE_PATH=/usr/i486-mingw32/zlib/1.2.7/include LIBRARY_PATH=/usr/i486-mingw32/zlib/1.2.7/lib install


## ext

gem i nokogiri -v 1.5.6

cd /usr/local/lib/ruby/gems/2.0.0/gems/nokogiri-1.5.6/


in tasks/cross_compile.rb line 97 and 127:
  
sh 

should be
  
system


in Rakefile line 103 change to:
ext.cross_platform = ["x86-mingw32"]


touch ports/libiconv-1.13.1.installed && touch ports/libxml2-2.7.7.installed && touch ports/libxslt-1.1.26.installed && touch ports/zlib-1.2.7.installed

cd ext/nokogiri && make clean
cd ../../

rake cross compile


报错(tmp/x86-mingw32/nokogiri/2.0.0已经生成出来了)

cd /usr/local/lib/ruby/gems/2.0.0/gems/nokogiri-1.5.6/tmp/x86-mingw32/nokogiri/2.0.0

export ports_dir=/usr/i486-mingw32
/usr/local/bin/ruby -I. -rfake ../../../../ext/nokogiri/extconf.rb --with-iconv-include=$ports_dir/libiconv/1.13.1/include --with-iconv-lib=$ports_dir/libiconv/1.13.1/lib --with-xml2-include=$ports_dir/libxml2/2.8.0/include --with-xml2-lib=$ports_dir/libxml2/2.8.0/lib --with-xslt-include=$ports_dir/libxslt/1.1.26/include --with-xslt-lib=$ports_dir/libxslt/1.1.26/lib --with-zlib-include=$ports_dir/zlib/1.2.7/include --with-zlib-lib=$ports_dir/zlib/1.2.7/lib
make clean && make




# eventmachine 1.0.1

依赖

## openssl 1.0.1e

./Configure --prefix=/usr/i486-mingw32 no-asm mingw
make CC=i486-mingw32-gcc AR="i486-mingw32-ar r" RANLIB=i486-mingw32-ranlib && make install


## ext

gem i eventmachine -v 1.0.1
cd /usr/local/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.1/

cd ext && make clean
cd fastfilereader && make clean
cd ../../

rake cross compile

## rubyeventmachine

# cd tmp/x86-mingw32/rubyeventmachine/2.0.0
# /usr/local/bin/ruby -I. -rfake ../../../../ext/extconf.rb --with-ssl-dir=/usr/i486-mingw32

## fastfilereader

# cd tmp/x86-mingw32/fastfilereaderext/2.0.0
# /usr/local/bin/ruby -I. -rfake ../../../../ext/fastfilereader/extconf.rb




# mysql2

# copy mysql-connector-c-noinstall-6.0.2-win32.zip to /usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/vendor/

cd /usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11

cd ext/mysql2 && make clean
cd ../../

rake cross compile 

# cd tmp/x86-mingw32/mysql2/2.0.0
# /usr/local/bin/ruby -I. -rfake ../../../../ext/mysql2/extconf.rb --with-mysql-include=/usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/vendor/mysql-connector-c-noinstall-6.0.2-win32/include --with-mysql-lib=/usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/vendor/mysql-connector-c-noinstall-6.0.2-win32/lib




# yajl-ruby

gem i yajl-ruby -v 1.1.0
cd /usr/local/lib/ruby/gems/2.0.0/gems/yajl-ruby-1.1.0/

cd ext/yajl && make clean
cd ../../

rake cross compile

# cd tmp/x86-mingw32/yajl/2.0.0
# /usr/local/bin/ruby -I. -rfake ../../../../ext/yajl/extconf.rb




# bcrypt-ruby

gem i bcrypt-ruby -v 3.0.1
cd /usr/local/lib/ruby/gems/2.0.0/gems/bcrypt-ruby-3.0.1/


in Rakefile line 2 should be
require 'rubygems/package_task'


line 7 should be
require 'rdoc/task'


line 40 should be
rd = RDoc::Task.new do |rdoc|


line 47 should be
Gem::PackageTask.new(GEMSPEC) do |pkg|


cd ext/mri && make clean
cd ../../

rake cross compile

# cd tmp/x86-mingw32/bcrypt_ext/2.0.0
# /usr/local/bin/ruby -I. -rfake ../../../../ext/mri/extconf.rb




64位的操作系统可以装mingw-w64。

wget https://aur.archlinux.org/packages/mi/mingw-w64-binutils/mingw-w64-binutils.tar.gz
wget https://aur.archlinux.org/packages/mi/mingw-w64-headers/mingw-w64-headers.tar.gz
wget https://aur.archlinux.org/packages/mi/mingw-w64-headers-bootstrap/mingw-w64-headers-bootstrap.tar.gz
wget https://aur.archlinux.org/packages/mi/mingw-w64-gcc-base/mingw-w64-gcc-base.tar.gz
wget https://aur.archlinux.org/packages/mi/mingw-w64-crt/mingw-w64-crt.tar.gz
wget https://aur.archlinux.org/packages/mi/mingw-w64-winpthreads/mingw-w64-winpthreads.tar.gz
wget https://aur.archlinux.org/packages/mi/mingw-w64-gcc/mingw-w64-gcc.tar.gz

1. mingw-w64-binutils
tar xzvf mingw-w64-binutils.tar.gz
cd mingw-w64-binutils
makepkg -s --asroot
pacman -U mingw-w64-binutils-2.23.1-1-x86_64.pkg.tar.xz

2. mingw-w64-headers
3. mingw-w64-headers-bootstrap
4. mingw-w64-gcc-base
5. mingw-w64-crt
6. mingw-w64-winpthreads (replace mingw-w64-headers-bootstrap)
7. mingw-w64-gcc (replace mingw-w64-gcc-base)


mingw-w64系列包在aur里,依赖有点耦合还没解决,mingw-w64-gcc的PKGBUILD含有会出错的ada,用不到就去掉:
build() --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada \ 去掉ada;
package() strip ${pkgdir}/usr/libexec/gcc/${_target}/${pkgver}/{cc1*,collect2,gnat1,f951,lto*} 去掉gnat1。

make mingw-w64-gcc-base 和 mingw-w64-gcc 报错 gcc/doc/cppopts.texi:806: @itemx must follow @item 要打个补丁 http://gcc.gnu.org/ml/gcc-patches/2012-10/msg02505.html
invoke.texi 还漏一处
@itemx -fdump-rtl-pro_and_epilogue

should be
@item -fdump-rtl-pro_and_epilogue


diff -au a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi

md5sum gcc-4.7.2-itemx_must_follow_item.patch


in PKGBUILD,source和md5sums里加进这个补丁,build()段里加
patch -Np1 -i ${srcdir}/gcc-4.7.2-itemx_must_follow_item.patch


gcc-4.7.2-itemx_must_follow_item.patch
diff -au a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
--- a/gcc/doc/invoke.texi 2013-03-05 12:08:45 +0800
+++ b/gcc/doc/invoke.texi 2013-03-05 14:16:27 +0800
@@ -1592,7 +1592,7 @@
 this will become the default.  The name @samp{gnu9x} is deprecated.
 
 @item gnu11
-@item gnu1x
+@itemx gnu1x
 GNU dialect of ISO C11.  Support is incomplete and experimental.  The
 name @samp{gnu1x} is deprecated.
 
@@ -5179,7 +5179,7 @@
 e.g. With -fdbg-cnt=dce:10,tail_call:0
 dbg_cnt(dce) will return true only for first 10 invocations
 
-@itemx -fenable-@var{kind}-@var{pass}
+@item -fenable-@var{kind}-@var{pass}
 @itemx -fdisable-@var{kind}-@var{pass}=@var{range-list}
 @opindex fdisable-
 @opindex fenable-
@@ -5327,11 +5327,11 @@
 @option{-fdump-rtl-ce3} enable dumping after the three
 if conversion passes.
 
-@itemx -fdump-rtl-cprop_hardreg
+@item -fdump-rtl-cprop_hardreg
 @opindex fdump-rtl-cprop_hardreg
 Dump after hard register copy propagation.
 
-@itemx -fdump-rtl-csa
+@item -fdump-rtl-csa
 @opindex fdump-rtl-csa
 Dump after combining stack adjustments.
 
@@ -5342,11 +5342,11 @@
 @option{-fdump-rtl-cse1} and @option{-fdump-rtl-cse2} enable dumping after
 the two common sub-expression elimination passes.
 
-@itemx -fdump-rtl-dce
+@item -fdump-rtl-dce
 @opindex fdump-rtl-dce
 Dump after the standalone dead code elimination passes.
 
-@itemx -fdump-rtl-dbr
+@item -fdump-rtl-dbr
 @opindex fdump-rtl-dbr
 Dump after delayed branch scheduling.
 
@@ -5391,7 +5391,7 @@
 @opindex fdump-rtl-initvals
 Dump after the computation of the initial value sets.
 
-@itemx -fdump-rtl-into_cfglayout
+@item -fdump-rtl-into_cfglayout
 @opindex fdump-rtl-into_cfglayout
 Dump after converting to cfglayout mode.
 
@@ -5421,7 +5421,7 @@
 @opindex fdump-rtl-rnreg
 Dump after register renumbering.
 
-@itemx -fdump-rtl-outof_cfglayout
+@item -fdump-rtl-outof_cfglayout
 @opindex fdump-rtl-outof_cfglayout
 Dump after converting from cfglayout mode.
 
@@ -5433,7 +5433,7 @@
 @opindex fdump-rtl-postreload
 Dump after post-reload optimizations.
 
-@itemx -fdump-rtl-pro_and_epilogue
+@item -fdump-rtl-pro_and_epilogue
 @opindex fdump-rtl-pro_and_epilogue
 Dump after generating the function prologues and epilogues.
 
@@ -10494,10 +10494,10 @@
 The default is @option{-mfp-mode=caller}
 
 @item -mnosplit-lohi
+@itemx -mno-postinc
+@itemx -mno-postmodify
 @opindex mnosplit-lohi
-@item -mno-postinc
 @opindex mno-postinc
-@item -mno-postmodify
 @opindex mno-postmodify
 Code generation tweaks that disable, respectively, splitting of 32-bit
 loads, generation of post-increment addresses, and generation of
@@ -11409,7 +11409,7 @@
 memory and if @code{-mshort-calls} is not set.
 
 @item __AVR_HAVE_EIJMP_EICALL__
-@item __AVR_3_BYTE_PC__
+@itemx __AVR_3_BYTE_PC__
 The device has the @code{EIJMP} and @code{EICALL} instructions.
 This is the case for devices with more than 128@tie{}KiB of program memory.
 This also means that the program counter
@@ -11420,13 +11420,13 @@
 with up to 128@tie{}KiB of program memory.
 
 @item __AVR_HAVE_8BIT_SP__
-@item __AVR_HAVE_16BIT_SP__
+@itemx __AVR_HAVE_16BIT_SP__
 The stack pointer (SP) register is treated as 8-bit respectively
 16-bit register by the compiler.
 The definition of these macros is affected by @code{-mtiny-stack}.
 
 @item __AVR_HAVE_SPH__
-@item __AVR_SP8__
+@itemx __AVR_SP8__
 The device has the SPH (high part of stack pointer) special function
 register or has an 8-bit stack pointer, respectively.
 The definition of these macros is affected by @code{-mmcu=} and
@@ -11434,9 +11434,9 @@
 by @code{-msp8}.
 
 @item __AVR_HAVE_RAMPD__
-@item __AVR_HAVE_RAMPX__
-@item __AVR_HAVE_RAMPY__
-@item __AVR_HAVE_RAMPZ__
+@itemx __AVR_HAVE_RAMPX__
+@itemx __AVR_HAVE_RAMPY__
+@itemx __AVR_HAVE_RAMPZ__
 The device has the @code{RAMPD}, @code{RAMPX}, @code{RAMPY},
 @code{RAMPZ} special function register, respectively.
 
@@ -11444,7 +11444,7 @@
 This macro reflects the @code{-mno-interrupts} command line option.
 
 @item __AVR_ERRATA_SKIP__
-@item __AVR_ERRATA_SKIP_JMP_CALL__
+@itemx __AVR_ERRATA_SKIP_JMP_CALL__
 Some AVR devices (AT90S8515, ATmega103) must not skip 32-bit
 instructions because of a hardware erratum.  Skip instructions are
 @code{SBRS}, @code{SBRC}, @code{SBIS}, @code{SBIC} and @code{CPSE}.
@@ -17971,7 +17971,7 @@
 @option{-mhitachi} is given.
 
 @item -mieee
-@item -mno-ieee
+@itemx -mno-ieee
 @opindex mieee
 @opindex mnoieee
 Control the IEEE compliance of floating-point comparisons, which affects the
diff --git a/gcc/doc/cppopts.texi b/gcc/doc/cppopts.texi
index 27b1095..a2eb79d 100644
--- a/gcc/doc/cppopts.texi
+++ b/gcc/doc/cppopts.texi
@@ -1,5 +1,5 @@
 @c Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-@c 2010, Free Software Foundation, Inc.
+@c 2010, 2012, Free Software Foundation, Inc.
 @c This is part of the CPP and GCC manuals.
 @c For copying conditions, see the file gcc.texi.
 
@@ -805,7 +805,7 @@ Replacement:      [    ]    @{    @}    #    \    ^    |    ~
 Enable special code to work around file systems which only permit very
 short file names, such as MS-DOS@.
 
-@itemx --help
+@item --help
 @itemx --target-help
 @opindex help
 @opindex target-help
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index fb1becb..5c4f8fd 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -1251,10 +1251,10 @@ The @code{__flash} qualifier will locate data in the
 instruction. Pointers to this address space are 16 bits wide.
 
 @item __flash1
-@item __flash2
-@item __flash3
-@item __flash4
-@item __flash5
+@itemx __flash2
+@itemx __flash3
+@itemx __flash4
+@itemx __flash5
 @cindex @code{__flash1} AVR Named Address Spaces
 @cindex @code{__flash2} AVR Named Address Spaces
 @cindex @code{__flash3} AVR Named Address Spaces
diff --git a/gcc/doc/generic.texi b/gcc/doc/generic.texi
index c739731..e878811 100644
--- a/gcc/doc/generic.texi
+++ b/gcc/doc/generic.texi
@@ -1,4 +1,4 @@
-@c Copyright (c) 2004, 2005, 2007, 2008, 2010 Free Software Foundation, Inc.
+@c Copyright (c) 2004, 2005, 2007, 2008, 2010, 2012 Free Software Foundation, Inc.
 @c Free Software Foundation, Inc.
 @c This is part of the GCC manual.
 @c For copying conditions, see the file gcc.texi.
@@ -1417,13 +1417,13 @@ generate these expressions anyhow, if it can tell that strictness does
 not matter.  The type of the operands and that of the result are
 always of @code{BOOLEAN_TYPE} or @code{INTEGER_TYPE}.
 
-@itemx POINTER_PLUS_EXPR
+@item POINTER_PLUS_EXPR
 This node represents pointer arithmetic.  The first operand is always
 a pointer/reference type.  The second operand is always an unsigned
 integer type compatible with sizetype.  This is the only binary
 arithmetic operand that can operate on pointer types.
 
-@itemx PLUS_EXPR
+@item PLUS_EXPR
 @itemx MINUS_EXPR
 @itemx MULT_EXPR
 These nodes represent various binary arithmetic operations.
diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index dfbdc4c..bca0d8f 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -4483,8 +4483,8 @@ means of constraints requiring operands 1 and 0 to be the same location.
 @cindex @code{ior@var{m}3} instruction pattern
 @cindex @code{xor@var{m}3} instruction pattern
 @item @samp{ssadd@var{m}3}, @samp{usadd@var{m}3}
-@item @samp{sub@var{m}3}, @samp{sssub@var{m}3}, @samp{ussub@var{m}3}
-@item @samp{mul@var{m}3}, @samp{ssmul@var{m}3}, @samp{usmul@var{m}3}
+@itemx @samp{sub@var{m}3}, @samp{sssub@var{m}3}, @samp{ussub@var{m}3}
+@itemx @samp{mul@var{m}3}, @samp{ssmul@var{m}3}, @samp{usmul@var{m}3}
 @itemx @samp{div@var{m}3}, @samp{ssdiv@var{m}3}
 @itemx @samp{udiv@var{m}3}, @samp{usdiv@var{m}3}
 @itemx @samp{mod@var{m}3}, @samp{umod@var{m}3}
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 89e7712..ec8263f 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -691,7 +691,7 @@ standard rule in @file{gcc/Makefile.in} to the variable
 @code{lang_checks}.
 
 @table @code
-@itemx all.cross
+@item all.cross
 @itemx start.encap
 @itemx rest.encap
 FIXME: exactly what goes in each of these targets?


install eventmachine x64
https://github.com/eventmachine/eventmachine/pull/411

你可能感兴趣的:(compile)