Windows下编译Ruby源代码

为了在Windows下粘合Ruby扩展到应用程序,需要重新编译Ruby源代码,以便使用Visual Studio进行扩展的开发。使用第三方一键安装的版本开发工具使用的是Mingw下的GCC,无法满足需要。


源代码使用官网提供的源码包,直接从源代码库下载的源码需要额外的工具,代码包中有相关说明。


由于是用VS进行编译,缺省的Native包中gdbm和readline无法找到VS能编译的包,所以弃用。前者自己没用到,后者IRB会使用,缺少readline支持的IRB是比较蛋疼的。


把编译过程的命令行贴上,其中包括了自己常用的扩展,用以备忘


#openssl
cd E:\Projects\BuildRuby231\external\openssl-1.0.2
set PATH=d:\nasm-2.12.02\win32;%PATH%
d:\Strawberry\perl\bin\perl.exe Configure VC-WIN32 enable-static-engine --prefix=D:\Ruby23-x86\src\external
ms\do_nasm.bat
nmake -f ms\ntdll.mak
nmake -f ms\ntdll.mak install

#qdbm edit vcpath
cd E:\Projects\BuildRuby231\external\qdbm-1.8.78
nmake -f VCmakefile

#tcl
cd E:\Projects\BuildRuby231\external\tcl8.5.19\win
nmake -f makefile.vc
nmake -f makefile.vc install-libraries INSTALLDIR=D:\Ruby23-x86\src\external
nmake -f makefile.vc install-binaries INSTALLDIR=D:\Ruby23-x86\src\external

#tk
cd E:\Projects\BuildRuby231\external\tk8.5.19\win
nmake -f makefile.vc TCLDIR=D:\Ruby23-x86\src\external
nmake -f makefile.vc TCLDIR=E:\Projects\BuildRuby231\external\tcl8.5.19
nmake -f makefile.vc install-libraries INSTALLDIR=D:\Ruby23-x86\src\external
nmake -f makefile.vc install-binaries INSTALLDIR=D:\Ruby23-x86\src\external

#zlib
cd E:\Projects\BuildRuby231\external\zlib-1.2.8
nmake -f win32/Makefile.msc

#config ruby source
set INCLUDE=D:\Ruby23-x86\src\external\include;D:\Ruby23-x86\src\external\include\libxml2;E:\Projects\BuildRuby231\external\qdbm-1.8.78;E:\Projects\BuildRuby231\external\zlib-1.2.8;%INCLUDE%
set LIB=D:\Ruby23-x86\src\external\lib;E:\Projects\BuildRuby231\external\qdbm-1.8.78;E:\Projects\BuildRuby231\external\zlib-1.2.8;%LIB%
cd E:\Projects\BuildRuby231
d:\Ruby23-x86\src\win32\configure.bat --prefix=/Ruby23-x86 --disable-install-doc
nmake
##退出再进入,有bug,路径会乱
cd E:\Projects\BuildRuby231
set PATH=D:\Ruby23-x86\src\external\bin;%PATH%
nmake install DESTDIR=D:

#libiconv msvc-2008
cd E:\Projects\BuildRuby231\external\libiconv-1.11.1
nmake -f Makefile.msvc  DLL=1  MFLAGS=-MT  NO_NLS=1  PREFIX=D:\Ruby23-x86\src\external
nmake -f Makefile.msvc install  DLL=1  MFLAGS=-MT  NO_NLS=1  PREFIX=D:\Ruby23-x86\src\external

#libxml2
cd E:\Projects\BuildRuby231\external\libxml2-2.9.4\win32
cscript configure.js prefix=D:\Ruby23-x86\src\external include=D:\Ruby23-x86\src\external\include;D:\Ruby23-x86\src\external\include\libxml2 lib=D:\Ruby23-x86\src\external\lib
nmake /f Makefile.msvc clean
nmake /f Makefile.msvc
nmake /f Makefile.msvc install

#libxslt
cd E:\Projects\BuildRuby231\external\libxslt-1.1.29\win32
cscript configure.js prefix=D:\Ruby23-x86\src\external include=D:\Ruby23-x86\src\external\include;D:\Ruby23-x86\src\external\include\libxml2 lib=D:\Ruby23-x86\src\external\lib
nmake /f Makefile.msvc clean
nmake /f Makefile.msvc
nmake /f Makefile.msvc install

#nokogiri
set PATH=D:\Ruby23-x86\src\external\bin;D:\Ruby23-x86\src\external\lib;%PATH%
cd d:\Ruby23-x86\bin
d:
gem update --system
gem install nokogiri -- --use-system-libraries --with-opt-include=D:\Ruby23-x86\src\external\include;D:\Ruby23-x86\src\external\include\libxml2 --with-opt-lib=D:\Ruby23-x86\src\external\lib

#sqlite3
cd E:\Projects\BuildRuby231\external\sqlite-dll-win32-x86-3140100
e:
lib /def:sqlite3.def /out:sqlite3.lib /machine:x86
cd d:\Ruby23-x86\bin
d:
gem install sqlite3 -- --with-opt-include=E:\Projects\BuildRuby231\external\sqlite-autoconf-3140100 --with-opt-lib=E:\Projects\BuildRuby231\external\sqlite-dll-win32-x86-3140100

#oracle dbi
cd d:\Ruby23-x86\bin
d:
gem install dbi
set ORACLE_HOME=D:\oracle\instantclient-nt-12.1.0.2.0
set PATH=D:\oracle\instantclient-nt-12.1.0.2.0;%PATH%
gem install ruby-oci8 -- --with-opt-include=D:\oracle\instantclient-nt-12.1.0.2.0\sdk\include --with-opt-lib=D:\oracle\instantclient-nt-12.1.0.2.0\sdk\lib\msvc

猜你喜欢

转载自blog.csdn.net/mscf/article/details/52799712