Newer
Older
# -*- coding: utf-8 -*-
# -*- ruby -*-
require 'rubygems'
require 'hoe'
require 'rake/extensiontask'
require 'rake/extensioncompiler'
require 'uri'
ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.3:2.0.0'
NUM_CPUS = if File.exist?('/proc/cpuinfo')
File.read('/proc/cpuinfo').scan('processor').length
elsif RUBY_PLATFORM.include?( 'darwin' )
`system_profiler SPHardwareDataType | grep 'Cores' | awk '{print $5}'`.chomp
else
1
end
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
class CrossLibrary < OpenStruct
include Rake::DSL
def initialize(ruby_platform)
super()
self.ruby_platform = ruby_platform
# Cross-compilation constants
self.compile_home = Pathname( "build" ).expand_path
self.static_sourcesdir = compile_home + 'sources'
self.static_builddir = compile_home + 'builds' + ruby_platform
self.static_installdir = compile_home + 'install' + ruby_platform
self.ruby_build = RbConfig::CONFIG["host"]
# Use rake-compilers config.yml to determine the toolchain that was used
# to build Ruby for this platform.
self.host_platform = begin
config_file = YAML.load_file(File.expand_path("~/.rake-compiler/config.yml"))
_, rbfile = config_file.find{|key, fname| key.start_with?("rbconfig-#{ruby_platform}-") }
IO.read(rbfile).match(/CONFIG\["host"\] = "(.*)"/)[1]
rescue
nil
end
# Fetch zlib tarball
self.libz_version = ENV['libz_version'] || '1.2.7'
self.libz_source_uri = URI( "http://downloads.sourceforge.net/project/libpng/zlib/#{libz_version}/zlib-#{libz_version}.tar.bz2" )
self.libz_tarball = static_sourcesdir + File.basename( libz_source_uri.path )
self.static_libz_builddir = static_builddir + libz_tarball.basename(".tar.bz2")
self.libz_makefile = static_libz_builddir + 'Makefile'
self.libz_a = static_libz_builddir + 'libz.a'
# Fetch libpng tarball
self.libpng_version = ENV['libpng_version'] || '1.5.13'
self.libpng_source_uri = URI( "http://prdownloads.sourceforge.net/libpng/libpng-#{libpng_version}.tar.gz?download" )
self.libpng_tarball = static_sourcesdir + File.basename( libpng_source_uri.path )
self.static_libpng_builddir = static_builddir + libpng_tarball.basename(".tar.gz")
self.libpng_makefile = static_libpng_builddir + 'Makefile'
self.libpng_a = static_libpng_builddir + '.libs' + 'libpng15.a'
# Fetch libjpeg tarball
self.libjpeg_version = ENV['libjpeg_version'] || '8d'
self.libjpeg_source_uri = URI( "http://www.ijg.org/files/jpegsrc.v#{libjpeg_version}.tar.gz" )
self.libjpeg_tarball = static_sourcesdir + File.basename( libjpeg_source_uri.path )
self.static_libjpeg_builddir = static_builddir + "jpeg-#{libjpeg_version}"
self.libjpeg_makefile = static_libjpeg_builddir + 'Makefile'
self.libjpeg_a = static_libjpeg_builddir + '.libs' + 'libjpeg.a'
# Fetch libtiff tarball
self.libtiff_version = ENV['libtiff_version'] || '4.0.3'
self.libtiff_source_uri = URI( "http://download.osgeo.org/libtiff/tiff-#{libtiff_version}.tar.gz" )
self.libtiff_tarball = static_sourcesdir + File.basename( libtiff_source_uri.path )
self.static_libtiff_builddir = static_builddir + libtiff_tarball.basename(".tar.gz")
self.libtiff_makefile = static_libtiff_builddir + 'Makefile'
self.libtiff_a = static_libtiff_builddir + 'libtiff' + '.libs' + 'libtiff.a'
# Fetch libfox tarball
self.libfox_version = ENV['libfox_version'] || '1.6.49'
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
self.libfox_source_uri = URI( "http://ftp.fox-toolkit.org/pub/fox-#{libfox_version}.tar.gz" )
self.libfox_tarball = static_sourcesdir + File.basename( libfox_source_uri.path )
self.static_libfox_builddir = static_builddir + libfox_tarball.basename(".tar.gz")
self.libfox_makefile = static_libfox_builddir + 'Makefile'
self.libfox_a = static_libfox_builddir + 'src' + '.libs' + 'libFOX-1.6.a'
# Fetch fxscintilla tarball
self.libfxscintilla_version = ENV['libfxscintilla_version'] || '2.28.0'
self.libfxscintilla_source_uri = URI( "http://download.savannah.gnu.org/releases/fxscintilla/fxscintilla-#{libfxscintilla_version}.tar.gz" )
self.libfxscintilla_tarball = static_sourcesdir + File.basename( libfxscintilla_source_uri.path )
self.static_libfxscintilla_builddir = static_builddir + libfxscintilla_tarball.basename(".tar.gz")
self.libfxscintilla_makefile = static_libfxscintilla_builddir + 'Makefile'
self.libfxscintilla_a = static_libfxscintilla_builddir + 'fox' + '.libs' + 'libfxscintilla.a'
# clean intermediate files and folders
CLEAN.include( static_builddir.to_s )
#####################################################################
### C R O S S - C O M P I L A T I O N - T A S K S
#####################################################################
directory static_sourcesdir.to_s
#
# Static libz build tasks
#
directory static_libz_builddir.to_s
# libz source file should be stored there
file libz_tarball => static_sourcesdir do |t|
# download the source file using wget or curl
chdir File.dirname(t.name) do
sh "wget '#{libz_source_uri}' -O #{libz_tarball}"
end
end
# Extract the libz builds
file static_libz_builddir => libz_tarball do |t|
sh 'tar', '-xjf', libz_tarball.to_s, '-C', static_libz_builddir.parent.to_s
rm libz_makefile
end
self.libz_env = [
"CC=#{host_platform}-gcc",
"AR=#{host_platform}-ar",
"RANLIB=#{host_platform}-ranlib",
]
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# generate the makefile in a clean build location
file libz_makefile => [static_libz_builddir] do |t|
chdir( static_libz_builddir ) do
options = [
"--prefix=#{static_installdir}",
]
configure_path = static_libz_builddir + 'configure'
sh "env #{[libz_env, configure_path.to_s, *options].join(" ")}"
end
end
# generate the makefile in a clean build location
task libz_a => libz_makefile do |t|
chdir( static_libz_builddir ) do
sh "make -j#{NUM_CPUS} install 'LDSHAREDLIBC=-lmsvcrt'"
end
end
#
# Static libpng build tasks
#
directory static_libpng_builddir.to_s
# libpng source file should be stored there
file libpng_tarball => static_sourcesdir do |t|
# download the source file using wget or curl
chdir File.dirname(t.name) do
sh "wget '#{libpng_source_uri}' -O #{libpng_tarball}"
end
end
# Extract the libpng builds
file static_libpng_builddir => libpng_tarball do |t|
sh 'tar', '-xzf', libpng_tarball.to_s, '-C', static_libpng_builddir.parent.to_s
end
self.libpng_env = [
# Use build directory instead of install, to avoid unnecessary rebuilds of libpng
"'CPPFLAGS=-I#{static_libz_builddir}'",
"'LDFLAGS=-L#{static_libz_builddir}'",
]
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# generate the makefile in a clean build location
file libpng_makefile => [static_libpng_builddir, libz_a] do |t|
chdir( static_libpng_builddir ) do
options = [
"--target=#{host_platform}",
"--host=#{host_platform}",
"--build=#{ruby_build}",
"--prefix=#{static_installdir}",
"--disable-shared",
]
configure_path = static_libpng_builddir + 'configure'
sh "env #{[libpng_env, configure_path.to_s, *options].join(" ")}"
end
end
# generate the makefile in a clean build location
task libpng_a => [libpng_makefile, libz_a] do |t|
chdir( static_libpng_builddir ) do
sh "make -j#{NUM_CPUS} install"
end
end
#
# Static libjpeg build tasks
#
directory static_libjpeg_builddir.to_s
# libjpeg source file should be stored there
file libjpeg_tarball => static_sourcesdir do |t|
# download the source file using wget or curl
chdir File.dirname(t.name) do
sh "wget '#{libjpeg_source_uri}' -O #{libjpeg_tarball}"
end
end
# Extract the libjpeg builds
file static_libjpeg_builddir => libjpeg_tarball do |t|
sh 'tar', '-xzf', libjpeg_tarball.to_s, '-C', static_libjpeg_builddir.parent.to_s
end
# generate the makefile in a clean build location
file libjpeg_makefile => static_libjpeg_builddir do |t|
chdir( static_libjpeg_builddir ) do
options = [
"--target=#{host_platform}",
"--host=#{host_platform}",
"--build=#{ruby_build}",
"--prefix=#{static_installdir}",
"--disable-shared",
]
configure_path = static_libjpeg_builddir + 'configure'
cmd = [ configure_path.to_s, *options ]
sh *cmd
end
end
# build libjpeg.a
task libjpeg_a => [libjpeg_makefile] do |t|
chdir( static_libjpeg_builddir ) do
sh "make -j#{NUM_CPUS} install"
end
end
#
# Static libtiff build tasks
#
directory static_libtiff_builddir.to_s
# libtiff source file should be stored there
file libtiff_tarball => static_sourcesdir do |t|
# download the source file using wget or curl
chdir File.dirname(t.name) do
sh "wget '#{libtiff_source_uri}' -O #{libtiff_tarball}"
end
end
# Extract the libtiff builds
file static_libtiff_builddir => libtiff_tarball do |t|
sh 'tar', '-xzf', libtiff_tarball.to_s, '-C', static_libtiff_builddir.parent.to_s
end
self.libtiff_env = [
"'CPPFLAGS=-I#{static_installdir}/include'",
"'LDFLAGS=-L#{static_installdir}/lib'",
]
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# generate the makefile in a clean build location
file libtiff_makefile => [static_libtiff_builddir, libjpeg_a, libz_a] do |t|
chdir( static_libtiff_builddir ) do
options = [
"--target=#{host_platform}",
"--host=#{host_platform}",
"--build=#{ruby_build}",
"--prefix=#{static_installdir}",
"--disable-shared",
"--with-zlib-include-dir=#{static_libz_builddir}",
"--with-zlib-lib-dir=#{File.dirname(libz_a)}",
"--with-jpeg-include-dir=#{static_libjpeg_builddir}",
"--with-jpeg-lib-dir=#{File.dirname(libjpeg_a)}",
]
configure_path = static_libtiff_builddir + 'configure'
sh "env #{[libtiff_env, configure_path.to_s, *options].join(" ")}"
end
end
# build libtiff.a
task libtiff_a => [libtiff_makefile] do |t|
chdir( static_libtiff_builddir ) do
sh "make -j#{NUM_CPUS} install"
end
end
#
# Static libfox build tasks
#
directory static_libfox_builddir.to_s
# libfox source file should be stored there
file libfox_tarball => static_sourcesdir do |t|
# download the source file using wget or curl
chdir File.dirname(t.name) do
sh "wget '#{libfox_source_uri}' -O #{libfox_tarball}"
end
end
# Extract the libfox builds
file static_libfox_builddir => libfox_tarball do |t|
sh 'tar', '-xzf', libfox_tarball.to_s, '-C', static_libfox_builddir.parent.to_s
end
self.libfox_env = [
"'CPPFLAGS=-I#{static_installdir}/include'",
"'LDFLAGS=-L#{static_installdir}/lib'",
]
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# generate the makefile in a clean build location
file libfox_makefile => [static_libfox_builddir, libjpeg_a, libz_a] do |t|
chdir( static_libfox_builddir ) do
options = [
"--target=#{host_platform}",
"--host=#{host_platform}",
"--build=#{ruby_build}",
"--prefix=#{static_installdir}",
"--disable-shared",
"--without-xft",
"--without-x",
]
configure_path = static_libfox_builddir + 'configure'
sh "env #{[libfox_env, configure_path.to_s, *options].join(" ")}"
end
end
# build libfox.a
task libfox_a => [libfox_makefile] do |t|
chdir( static_libfox_builddir ) do
sh "make -j#{NUM_CPUS} #{fox_env.join(" ")} install"
end
end
#
# Static libfxscintilla build tasks
#
directory static_libfxscintilla_builddir.to_s
# libfxscintilla source file should be stored there
file libfxscintilla_tarball => static_sourcesdir do |t|
# download the source file using wget or curl
chdir File.dirname(t.name) do
sh "wget '#{libfxscintilla_source_uri}' -O #{libfxscintilla_tarball}"
end
end
# Extract the libfxscintilla builds
file static_libfxscintilla_builddir => libfxscintilla_tarball do |t|
sh 'tar', '-xzf', libfxscintilla_tarball.to_s, '-C', static_libfxscintilla_builddir.parent.to_s
end
self.fox_env = [
"'CFLAGS=-I#{static_installdir}/include'",
"'CPPFLAGS=-I#{static_installdir}/include'",
"'LDFLAGS=-L#{static_installdir}/lib'",
"'FOX_CFLAGS=-I#{static_installdir}/include/fox-1.6 -DFOX_1_6'",
"'FOX_LIBS=-L#{static_installdir}/lib -lFOX-1.6'",
]
# generate the makefile in a clean build location
file libfxscintilla_makefile => [static_libfxscintilla_builddir, libfox_a] do |t|
chdir( static_libfxscintilla_builddir ) do
options = [
"--target=#{host_platform}",
"--host=#{host_platform}",
"--build=#{ruby_build}",
"--prefix=#{static_installdir}",
"--disable-shared",
]
configure_path = static_libfxscintilla_builddir + 'configure'
sh "env #{[fox_env, configure_path.to_s, *options].join(" ")}"
end
end
# build libfxscintilla.a
task libfxscintilla_a => [libfxscintilla_makefile] do |t|
chdir( static_libfxscintilla_builddir ) do
sh "make -j#{NUM_CPUS} #{fox_env.join(" ")} install"
end
end
desc "compile static libz libraries"
task :static_libs => [ libz_a, libpng_a, libjpeg_a, libtiff_a, libfox_a, libfxscintilla_a ]
end
end
if File.exist?(File.expand_path("~/.rake-compiler/config.yml"))
CrossLibraries = [
'i386-mingw32',
'x64-mingw32',
].map do |platform|
CrossLibrary.new platform
end
else
$stderr.puts "Cross-compilation disabled -- rake-compiler not properly installed"
CrossLibraries = []
end
desc 'cross compile required libs for win32'
task :cross => [ :mingw32, :static_libs ]
task :mingw32 do
# Use Rake::ExtensionCompiler helpers to find the proper host
unless Rake::ExtensionCompiler.mingw_host then
warn "You need to install mingw32 cross compile functionality to be able to continue."
warn "Please refer to your distribution/package manager documentation about installation."
fail
end
end
# vim: syntax=ruby