@@ -2,17 +2,17 @@ require "rake/clean"
22require "rake/extensioncompiler"
33require "mini_portile"
44
5- $recipes = { }
5+ CLOBBER . include ( "ports" )
66
7- $recipes[ :sqlite3 ] = MiniPortile . new "sqlite3" , BINARY_VERSION
8- $recipes[ :sqlite3 ] . files << "http://sqlite.org/sqlite-autoconf-#{ URL_VERSION } .tar.gz"
7+ directory "ports"
98
10- namespace :ports do
11- directory "ports"
9+ def define_sqlite_task ( platform , host )
10+ recipe = MiniPortile . new "sqlite3" , BINARY_VERSION
11+ recipe . files << "http://sqlite.org#{ URL_PATH } /sqlite-autoconf-#{ URL_VERSION } .tar.gz"
12+ recipe . host = host
1213
13- desc "Install port sqlite3 #{ $recipes[ :sqlite3 ] . version } "
14- task :sqlite3 => [ "ports" ] do
15- recipe = $recipes[ :sqlite3 ]
14+ desc "Compile sqlite3 for #{ platform } (#{ host } )"
15+ task "ports:sqlite3:#{ platform } " => [ "ports" ] do |t |
1616 checkpoint = "ports/.#{ recipe . name } -#{ recipe . version } -#{ recipe . host } .installed"
1717
1818 unless File . exist? ( checkpoint )
@@ -22,30 +22,66 @@ namespace :ports do
2222 recipe . cook
2323 touch checkpoint
2424 end
25-
26- recipe . activate
2725 end
26+
27+ recipe
2828end
2929
30+ # native sqlite3 compilation
31+ define_sqlite_task RUBY_PLATFORM , RbConfig ::CONFIG [ "host" ]
32+
33+ # trick to test local compilation of sqlite3
34+ if ENV [ "USE_MINI_PORTILE" ] == "true"
35+ # fake recipe so we can build a directory to it
36+ recipe = MiniPortile . new "sqlite3" , BINARY_VERSION
37+ recipe . host = RbConfig ::CONFIG [ "host" ]
38+
39+ RUBY_EXTENSION . config_options << "--with-opt-dir=#{ recipe . path } "
40+
41+ # compile sqlite3 first
42+ Rake ::Task [ "compile" ] . prerequisites . unshift "ports:sqlite3:#{ RUBY_PLATFORM } "
43+ end
44+
45+ # force compilation of sqlite3 when working natively under MinGW
3046if RUBY_PLATFORM =~ /mingw/
31- Rake ::Task [ 'compile' ] . prerequisites . unshift "ports:sqlite3"
47+ Rake ::Task [ 'compile' ] . prerequisites . unshift "ports:sqlite3: #{ RUBY_PLATFORM } "
3248end
3349
34- if ENV [ "USE_MINI_PORTILE" ] == "true"
35- Rake ::Task [ "compile" ] . prerequisites . unshift "ports:sqlite3"
50+ # iterate over all cross-compilation platforms and define the proper
51+ # sqlite3 recipe for it.
52+ if RUBY_EXTENSION . cross_compile
53+ config_path = File . expand_path ( "~/.rake-compiler/config.yml" )
54+ if File . exist? ( config_path )
55+ # obtains platforms from rake-compiler's config.yml
56+ config_file = YAML . load_file ( config_path )
57+
58+ Array ( RUBY_EXTENSION . cross_platform ) . each do |platform |
59+ # obtain platform from rbconfig file
60+ config_key = config_file . keys . sort . find { |key |
61+ key . start_with? ( "rbconfig-#{ platform } -" )
62+ }
63+ rbfile = config_file [ config_key ]
64+
65+ # skip if rbconfig cannot be read
66+ next unless File . exist? ( rbfile )
67+
68+ host = IO . read ( rbfile ) . match ( /CONFIG\[ "CC"\] = "(.*)"/ ) [ 1 ] . sub ( /\- gcc/ , '' )
69+ recipe = define_sqlite_task ( platform , host )
70+
71+ RUBY_EXTENSION . cross_config_options << {
72+ platform => "--with-opt-dir=#{ recipe . path } "
73+ }
74+
75+ # pre-compile sqlite3 port when cross-compiling
76+ task :cross => "ports:sqlite3:#{ platform } "
77+ end
78+ else
79+ warn "rake-compiler configuration doesn't exist, but is required for ports"
80+ end
3681end
3782
3883task :cross do
3984 [ "CC" , "CXX" , "LDFLAGS" , "CPPFLAGS" , "RUBYOPT" ] . each do |var |
4085 ENV . delete ( var )
4186 end
42- host = ENV . fetch ( "HOST" , Rake ::ExtensionCompiler . mingw_host )
43- $recipes. each do |_ , recipe |
44- recipe . host = host
45- end
46-
47- # hook compile task with dependencies
48- Rake ::Task [ "compile" ] . prerequisites . unshift "ports:sqlite3"
4987end
50-
51- CLOBBER . include ( "ports" )
0 commit comments