diff --git a/Rakefile b/Rakefile index 67b32ec..fde1756 100644 --- a/Rakefile +++ b/Rakefile @@ -5,13 +5,27 @@ require 'rake/clean' require 'bundler/gem_tasks' require 'rspec/core/rake_task' require 'ffi-compiler/compile_task' +require 'mini_portile2' + +WEBP = MiniPortile.new('libwebp', '1.2.4') +WEBP.files = ['https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.2.4.tar.gz'] +WEBP.configure_options << '--disable-gl' << '--disable-sdl' desc "compiler tasks" namespace "ffi-compiler" do + task :libs do + old_cflags = ENV['CFLAGS'] + ENV['CFLAGS'] = (ENV['CFLAGS'].to_s + ' -fPIC').strip + WEBP.cook + ENV['CFLAGS'] = old_cflags + WEBP.activate + end FFI::Compiler::CompileTask.new('ext/webp_ffi/webp_ffi') do |c| c.have_header?('stdio.h', '/usr/local/include') c.have_func?('puts') c.have_library?('z') + c.ldflags << '-L' + File.join(WEBP.path, 'lib') + c.cflags << '-I' + File.join(WEBP.path, 'include') c.have_header?('decode.h', '/usr/local/include') c.have_header?('encode.h', '/usr/local/include') c.have_func?('WebPDecoderConfig') @@ -24,7 +38,7 @@ namespace "ffi-compiler" do c.cflags << ENV['C_FLAGS'] if ENV['C_FLAGS'] end end -task :compile => ["ffi-compiler:default"] +task :compile => ["ffi-compiler:libs", "ffi-compiler:default"] desc "run specs" task :spec do diff --git a/ext/webp_ffi/Rakefile b/ext/webp_ffi/Rakefile index 22e2e98..b386275 100644 --- a/ext/webp_ffi/Rakefile +++ b/ext/webp_ffi/Rakefile @@ -1,6 +1,22 @@ require 'ffi-compiler/compile_task' +require 'mini_portile2' + +WEBP = MiniPortile.new('libwebp', '1.2.4') +WEBP.files = ['https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.2.4.tar.gz'] +WEBP.configure_options << '--disable-gl' << '--disable-sdl' +task :libwebp do + old_cflags = ENV['CFLAGS'] + ENV['CFLAGS'] = (ENV['CFLAGS'].to_s + ' -fPIC').strip + WEBP.cook + ENV['CFLAGS'] = old_cflags + WEBP.activate +end +task default: :libwebp FFI::Compiler::CompileTask.new('webp_ffi') do |c| + c.ldflags << '-L' + File.join(WEBP.path, 'lib') + c.cflags << '-I' + File.join(WEBP.path, 'include') + c.have_header?('stdio.h', '/usr/local/include') c.have_func?('puts') c.have_library?('z') diff --git a/webp-ffi.gemspec b/webp-ffi.gemspec index ba81650..18532a5 100644 --- a/webp-ffi.gemspec +++ b/webp-ffi.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "ffi", ">= 1.9.0" spec.add_runtime_dependency "ffi-compiler", ">= 0.1.2" + spec.add_dependency("mini_portile2", "~> 2.8.0") spec.add_development_dependency "bundler", ">= 1.2" spec.add_development_dependency "rake"