Permalink
Browse files

allow poppler to be built as a gem

  • Loading branch information...
1 parent e69de17 commit baec3576555c4c615b010884f74fa214c03167d5 Todd Fisher committed Jul 11, 2010
Showing with 143 additions and 8 deletions.
  1. +72 −0 poppler/Rakefile
  2. +28 −8 poppler/extconf.rb
  3. +38 −0 poppler/src/poppler.gemspec.erb
  4. +5 −0 poppler/src/rbpoppler.h
View
@@ -0,0 +1,72 @@
+require 'rake/clean'
+CLEAN.include '**/*.o'
+CLEAN.include "**/*.#{Config::MAKEFILE_CONFIG['DLEXT']}"
+CLOBBER.include 'doc'
+CLOBBER.include '**/*.log'
+CLOBBER.include '**/Makefile'
+CLOBBER.include '**/extconf.h'
+
+# Determine the current version of the software
+def ruby_poppler_version
+ require 'glib2'
+ GLib::BINDING_VERSION.join('.')
+end
+
+CURRENT_VERSION = ruby_poppler_version
+
+desc "Default Task (Test project)"
+task :default => :test
+
+# Make tasks -----------------------------------------------------
+make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
+MAKECMD = ENV['MAKE_CMD'] || make_program
+MAKEOPTS = ENV['MAKE_OPTS'] || ''
+
+POPPLER_SO = "src/poppler.#{Config::MAKEFILE_CONFIG['DLEXT']}"
+
+file 'Makefile' => 'extconf.rb' do
+ sh "ruby extconf.rb #{ENV['EXTCONF_OPTS']}"
+end
+
+def make(target = '')
+ pid = system("#{MAKECMD} #{MAKEOPTS} #{target}")
+ $?.exitstatus
+end
+
+# Let make handle dependencies between c/o/so - we'll just run it.
+file POPPLER_SO => (['Makefile'] + Dir['src/*.c'] + Dir['src/*.h']) do
+ m = make
+ fail "Make failed (status #{m})" unless m == 0
+end
+
+desc "Configure poppler"
+task :configure => ['Makefile']
+
+desc "Compile the shared object"
+task :compile => [POPPLER_SO]
+
+desc "Run poppler tests"
+task :test => :compile do
+ sh "ruby test/run-test.rb"
+end
+
+desc 'Generate gem specification'
+task :gemspec do
+ require 'erb'
+ tspec = ERB.new(File.read(File.join(File.dirname(__FILE__),'src','poppler.gemspec.erb')))
+ File.open(File.join(File.dirname(__FILE__),'poppler.gemspec'),'wb') do|f|
+ f << tspec.result
+ end
+end
+
+desc 'Build gem'
+task :package => :gemspec do
+ require 'rubygems/specification'
+ spec_source = File.read File.join(File.dirname(__FILE__),'poppler.gemspec')
+ spec = nil
+ # see: http://gist.github.com/16215
+ Thread.new { spec = eval("$SAFE = 3\n#{spec_source}") }.join
+ spec.validate
+ Gem::Builder.new(spec).build
+end
+
View
@@ -5,22 +5,42 @@
PACKAGE_NAME = "poppler"
PACKAGE_ID = "poppler-glib"
-TOPDIR = File.expand_path(File.dirname(__FILE__) + '/..')
-MKMF_GNOME2_DIR = TOPDIR + '/glib/src/lib'
-SRCDIR = TOPDIR + '/poppler/src'
+begin
+ require 'mkmf-gnome2'
+ USE_GLIB_GEM = true
+ TOPDIR = File.expand_path(File.dirname(__FILE__) )
+ SRCDIR = TOPDIR + '/src'
+ require 'glib2'
+ require 'gdk_pixbuf2'
+ require 'gtk2/base'
-$LOAD_PATH.unshift MKMF_GNOME2_DIR
+rescue LoadError => e
+ TOPDIR = File.expand_path(File.dirname(__FILE__) + '/..')
+ MKMF_GNOME2_DIR = TOPDIR + '/glib/src/lib'
+ SRCDIR = TOPDIR + '/poppler/src'
-require 'mkmf-gnome2'
+ $LOAD_PATH.unshift MKMF_GNOME2_DIR
+
+ require 'mkmf-gnome2'
+end
PKGConfig.have_package(PACKAGE_ID, 0, 8, 0) or exit 1
setup_win32(PACKAGE_NAME)
check_cairo
-add_depend_package("glib2", "glib/src", TOPDIR)
-add_depend_package("gtk2", "gtk/src", TOPDIR)
-add_depend_package("gdk_pixbuf2", "gdkpixbuf", TOPDIR)
+if USE_GLIB_GEM
+ path = File.expand_path(ENV['GEM_HOME'] + "/gems/glib2-#{GLib::BINDING_VERSION.join('.')}/src")
+ add_depend_package("glib2", path, '/')
+ path = File.expand_path(ENV['GEM_HOME'] + "/gems/gdkpixbuf-#{GLib::BINDING_VERSION.join('.')}/src")
+ add_depend_package("gdk_pixbuf2", path, '/')
+ path = File.expand_path(ENV['GEM_HOME'] + "/gems/gtk2-#{GLib::BINDING_VERSION.join('.')}/src")
+ add_depend_package("gtk2", path, '/')
+else
+ add_depend_package("glib2", "glib/src", TOPDIR)
+ add_depend_package("gtk2", "gtk/src", TOPDIR)
+ add_depend_package("gdk_pixbuf2", "gdkpixbuf", TOPDIR)
+end
make_version_header("POPPLER", PACKAGE_ID)
@@ -0,0 +1,38 @@
+Gem::Specification.new do |s|
+ s.name = "poppler"
+ s.authors = ["ruby-gnome2/AUTHORS"]
+ s.version = '<%= CURRENT_VERSION %>'
+ s.date = '<%= Time.now.strftime("%Y-%m-%d") %>'
+ s.description = %q{Ruby/Poppler is a Ruby binding of poppler-glib.}
+ s.email = 'todd.fisher@gmail.com'
+ s.extra_rdoc_files = ['README']
+ <%
+ files = ['ChangeLog', 'README', 'Rakefile', 'extconf.rb'] +
+ Dir["src/**/**.rb"] + Dir["src/**/**.c"] + Dir["src/**/**.h"] + Dir["sample/**"]
+
+ if ENV['BINARY_PACKAGE']
+ files += Dir['src/**/*.{o,so,bundle}']
+ end
+ %>
+ s.files = <%= files.inspect %>
+ s.require_paths = ['src']
+ s.rubyforge_project = 'poppler'
+ s.summary = %q{Ruby poppler bindings}
+ s.test_files = <%= Dir['test/**/**.rb'].inspect %>
+ s.add_dependency('glib2')
+ s.add_dependency('cairo')
+ <% unless ENV['BINARY_PACKAGE'] %>
+ s.extensions << 'extconf.rb'
+ <% end %>
+
+ #### Documentation and testing.
+ s.has_rdoc = true
+ s.homepage = 'http://ruby-gnome2.sourceforge.jp/'
+ s.rdoc_options = ['--main', 'README']
+
+ <% if ENV['BINARY_PACKAGE'] %>
+ s.platform = Gem::Platform::CURRENT
+ <% else %>
+ s.platform = Gem::Platform::RUBY
+ <% end %>
+end
@@ -9,6 +9,11 @@
#include <rbgobject.h>
#include <poppler.h>
+#include "rbglib.h"
+
+#define RBPOPPLER_MAJOR_VERSION RBGLIB_MAJOR_VERSION
+#define RBPOPPLER_MINOR_VERSION RBGLIB_MINOR_VERSION
+#define RBPOPPLER_MICRO_VERSION RBGLIB_MICRO_VERSION
#ifndef POPPLER_TYPE_INDEX_ITER
# define POPPLER_TYPE_INDEX_ITER (poppler_index_iter_get_type ())

0 comments on commit baec357

Please sign in to comment.