/
cross_compile.rb
132 lines (115 loc) · 3.72 KB
/
cross_compile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
gem 'rake-compiler'
require 'rake/extensioncompiler'
HOST = Rake::ExtensionCompiler.mingw_host
require 'mini_portile'
dependencies = YAML.load_file("dependencies.yml")
$recipes = {}
%w[zlib libiconv libxml2 libxslt].each do |lib|
$recipes[lib] = MiniPortile.new lib, dependencies[lib]
end
$recipes.each { |_, recipe| recipe.host = HOST }
file "lib/nokogiri/nokogiri.rb" do
File.open("lib/nokogiri/nokogiri.rb", 'wb') do |f|
f.write %Q{require "nokogiri/\#{RUBY_VERSION.sub(/\\.\\d+$/, '')}/nokogiri"\n}
end
end
namespace :cross do
task :zlib do
recipe = $recipes["zlib"]
recipe.files = ["http://zlib.net/#{recipe.name}-#{recipe.version}.tar.gz"]
class << recipe
def configure
Dir.chdir work_path do
mk = File.read 'win32/Makefile.gcc'
File.open 'win32/Makefile.gcc', 'wb' do |f|
f.puts "BINARY_PATH = #{CROSS_DIR}/bin"
f.puts "LIBRARY_PATH = #{CROSS_DIR}/lib"
f.puts "INCLUDE_PATH = #{CROSS_DIR}/include"
f.puts mk.sub(/^PREFIX\s*=\s*$/, "PREFIX = #{HOST}-")
end
end
end
def configured?
Dir.chdir work_path do
!! (File.read('win32/Makefile.gcc') =~ /^BINARY_PATH/)
end
end
def compile
execute "compile", "make -f win32/Makefile.gcc"
end
def install
execute "install", "make -f win32/Makefile.gcc install"
end
end
checkpoint = "#{CROSS_DIR}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
unless File.exist?(checkpoint)
recipe.cook
touch checkpoint
end
recipe.activate
end
task :libiconv do
recipe = $recipes["libiconv"]
recipe.files = ["http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz"]
recipe.configure_options = [
"--host=#{HOST}",
"--enable-static",
"--disable-shared",
"CPPFLAGS='-mno-cygwin -Wall'",
"CFLAGS='-mno-cygwin -O2 -g'",
"CXXFLAGS='-mno-cygwin -O2 -g'",
"LDFLAGS=-mno-cygwin"
]
checkpoint = "#{CROSS_DIR}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
unless File.exist?(checkpoint)
recipe.cook
touch checkpoint
end
recipe.activate
end
task :libxml2 => ["cross:zlib", "cross:libiconv"] do
recipe = $recipes["libxml2"]
recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]
recipe.configure_options = [
"--host=#{HOST}",
"--enable-static",
"--disable-shared",
"--with-zlib=#{CROSS_DIR}",
"--with-iconv=#{$recipes["libiconv"].path}",
"--without-python",
"--without-readline",
"CFLAGS='-DIN_LIBXML'"
]
checkpoint = "#{CROSS_DIR}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
unless File.exist?(checkpoint)
recipe.cook
touch checkpoint
end
recipe.activate
end
task :libxslt => ['cross:libxml2'] do
recipe = $recipes["libxslt"]
recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]
recipe.configure_options = [
"--host=#{HOST}",
"--enable-static",
"--disable-shared",
"--with-libxml-prefix=#{$recipes["libxml2"].path}",
"--without-python",
"--without-crypto",
"CFLAGS='-DIN_LIBXML'"
]
checkpoint = "#{CROSS_DIR}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
unless File.exist?(checkpoint)
recipe.cook
touch checkpoint
end
recipe.activate
end
task :file_list do
add_file_to_gem "lib/nokogiri/nokogiri.rb"
end
end
require 'rake/clean'
CLOBBER.include("#{CROSS_DIR}/*.installed", "#{CROSS_DIR}/#{HOST}", "tmp/#{HOST}")
task :cross2 => ["cross:libxslt", "lib/nokogiri/nokogiri.rb", "cross", "cross:file_list"]