Skip to content

Commit

Permalink
Rework external sqlite3 dependency and use MiniPortile
Browse files Browse the repository at this point in the history
  • Loading branch information
luislavena committed Apr 11, 2011
1 parent 4f7a968 commit bff5bff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ doc/faq/faq.html
*.swp
test/test.db
tmp
vendor
ports
*.log
*.o
.config
Expand Down
115 changes: 26 additions & 89 deletions tasks/vendor_sqlite3.rake
Original file line number Diff line number Diff line change
@@ -1,104 +1,41 @@
require 'rake/clean'
require 'rake/extensioncompiler'
require "rake/clean"
require "rake/extensioncompiler"
require "mini_portile"

# download sqlite3 library and headers
$recipes = {}

# only on Windows or cross platform compilation
def dlltool(dllname, deffile, libfile)
# define if we are using GCC or not
if Rake::ExtensionCompiler.mingw_gcc_executable then
dir = File.dirname(Rake::ExtensionCompiler.mingw_gcc_executable)
tool = case RUBY_PLATFORM
when /mingw/
File.join(dir, 'dlltool.exe')
when /linux|darwin/
File.join(dir, "#{Rake::ExtensionCompiler.mingw_host}-dlltool")
end
return "#{tool} --dllname #{dllname} --def #{deffile} --output-lib #{libfile}"
else
if RUBY_PLATFORM =~ /mswin/ then
tool = 'lib.exe'
else
fail "Unsupported platform for cross-compilation (please, contribute some patches)."
end
return "#{tool} /DEF:#{deffile} /OUT:#{libfile}"
end
end
$recipes[:sqlite3] = MiniPortile.new "sqlite3", BINARY_VERSION
$recipes[:sqlite3].files << "http://sqlite.org/sqlite-autoconf-#{URL_VERSION}.tar.gz"

# required folder structure for --with-sqlite3-dir (include + lib)
directory "vendor/sqlite3/lib"
directory "vendor/sqlite3/include"
namespace :ports do
directory "ports"

# download amalgamation version (for include files)
file "vendor/sqlite-amalgamation-#{URL_VERSION}.zip" => ['vendor'] do |t|
url = "http://www.sqlite.org/#{File.basename(t.name)}"
when_writing "downloading #{t.name}" do
cd File.dirname(t.name) do
system "wget -c #{url} || curl -C - -O #{url}"
end
end
end
desc "Install port sqlite3 #{$recipes[:sqlite3].version}"
task :sqlite3 => ["ports"] do |t|
recipe = $recipes[:sqlite3]
checkpoint = "ports/.#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"

# download dll binaries
file "vendor/sqlitedll-#{URL_VERSION}.zip" => ['vendor'] do |t|
url = "http://www.sqlite.org/#{File.basename(t.name)}"
when_writing "downloading #{t.name}" do
cd File.dirname(t.name) do
system "wget -c #{url} || curl -C - -O #{url}"
unless File.exist?(checkpoint)
recipe.cook
touch checkpoint
end
end
end

# extract header files into include folder
file "vendor/sqlite3/include/sqlite3.h" => ['vendor/sqlite3/include', "vendor/sqlite-amalgamation-#{URL_VERSION}.zip"] do |t|
full_file = File.expand_path(t.prerequisites.last)
when_writing "creating #{t.name}" do
cd File.dirname(t.name) do
sh "unzip #{full_file}"
# update file timestamp to avoid Rake perform this extraction again.
touch File.basename(t.name)
end
recipe.activate
end
end

# extract dll files into lib folder
file "vendor/sqlite3/lib/sqlite3.dll" => ['vendor/sqlite3/lib', "vendor/sqlitedll-#{URL_VERSION}.zip"] do |t|
full_file = File.expand_path(t.prerequisites.last)
when_writing "creating #{t.name}" do
cd File.dirname(t.name) do
sh "unzip #{full_file}"
# update file timestamp to avoid Rake perform this extraction again.
touch File.basename(t.name)
end
end
unless ENV["SKIP_PORTILE"]
Rake::Task['compile'].prerequisites.unshift "ports:sqlite3"
end

# generate import library from definition and dll file
file "vendor/sqlite3/lib/sqlite3.lib" => ["vendor/sqlite3/lib/sqlite3.dll"] do |t|
libfile = t.name
dllname = libfile.ext('dll')
deffile = libfile.ext('def')

when_writing "creating #{t.name}" do
sh dlltool(dllname, deffile, libfile)
task :cross do
host = ENV.fetch("HOST", Rake::ExtensionCompiler.mingw_host)
$recipes.each do |_, recipe|
recipe.host = host
end
end

# clean and clobber actions
# All the uncompressed files must be removed at clean
CLEAN.include('vendor/sqlite3')

# clobber vendored packages
CLOBBER.include('vendor')

# vendor:sqlite3
task 'vendor:sqlite3' => ["vendor/sqlite3/lib/sqlite3.lib", "vendor/sqlite3/include/sqlite3.h"]

# hook into cross compilation vendored sqlite3 dependency
if RUBY_PLATFORM =~ /mingw|mswin/ then
Rake::Task['compile'].prerequisites.unshift 'vendor:sqlite3'
else
if Rake::Task.task_defined?(:cross)
Rake::Task['cross'].prerequisites.unshift 'vendor:sqlite3'
end
# hook compile task with dependencies
Rake::Task["compile"].prerequisites.unshift "ports:freetds"
end

CLOBBER.include("ports")

0 comments on commit bff5bff

Please sign in to comment.