Permalink
Browse files

Import SWIG interface from FreeLing API for Python

Modify extconf.rb for this to work. It seems SWIG 2.0+ is required...
  • Loading branch information...
1 parent 0026826 commit b79761dd575e5acffeb616e84f33d84541452253 @munshkr committed Sep 15, 2011
Showing with 610 additions and 83 deletions.
  1. +1 −0 .gitignore
  2. +6 −5 Rakefile
  3. +0 −40 ext/freeling/extconf.rb
  4. +0 −23 ext/freeling/freeling.cc
  5. +0 −14 ext/freeling/freeling.i
  6. +55 −0 ext/libmorfo/extconf.rb
  7. +546 −0 ext/libmorfo/libmorfo_ruby.i
  8. +2 −1 freeling-ruby.gemspec
View
@@ -7,3 +7,4 @@ ext/**/mkmf.log
ext/**/*.o
ext/**/*.so
ext/**/*_wrap.cxx
+tmp
View
@@ -1,11 +1,12 @@
-require 'bundler/gem_tasks'
+require 'rake/dsl_definition'
require 'rake/extensiontask'
+require 'bundler/gem_tasks'
# Remove SWIG wrappers
-CLOBBER.include 'ext/**/*_wrap.cxx',
- 'ext/**/Makefile',
- 'ext/**/mkmf.log'
+CLOBBER.include 'ext/libmorfo/*_wrap.cxx',
+ 'ext/libmorfo/Makefile',
+ 'ext/libmorfo/mkmf.log'
-Rake::ExtensionTask.new('freeling') do |ext|
+Rake::ExtensionTask.new('libmorfo') do |ext|
ext.source_pattern = '*.{c,cpp,i}'
end
View
@@ -1,40 +0,0 @@
-require 'mkmf'
-
-def error(msg)
- message(msg + "\n")
- abort
-end
-
-
-default_opt_dirs = ['/usr/local', '/opt/local']
-opt_dir = "--with-opt-dir=#{default_opt_dirs.join(':')}"
-#ENV['CONFIGURE_ARGS'] = "#{opt_dir} #{ENV['CONFIGURE_ARGS']}"
-
-
-$libs = append_library($libs, "supc++")
-
-
-unless have_library('stdc++')
- error('You must have libstdc++ installed.')
-end
-
-# TODO write error messages and abort for each of these dependencies
-have_library('db_cxx')
-have_library('pcre')
-have_library('omlet')
-have_library('fries')
-have_library('boost_filesystem')
-have_library('morfo')
-
-#error ':(' unless have_header('freeling.h')
-
-
-# Run SWIG on each interface file
-Dir.glob(File.join(File.dirname(__FILE__), '*.i')).each do |file|
- swig_command = "swig -c++ -ruby #{file}"
- message("running `#{swig_command}`\n")
- system(swig_command)
-end
-
-# Finally, create Makefile
-create_makefile('freeling')
View
@@ -1,23 +0,0 @@
-#include <time.h>
-double My_variable = 3.0;
-
-class A {
- public:
- int n;
-};
-
-int fact(int n) {
- if (n <= 1) return 1;
- else return n*fact(n-1);
-}
-
-int my_mod(int x, int y) {
- return (x%y);
-}
-
-char *get_time()
-{
- time_t ltime;
- time(&ltime);
- return ctime(&ltime);
-}
View
@@ -1,14 +0,0 @@
-/* freeling.i */
-%module freeling
-%{
-/* Put header files here or function declarations like below */
-extern double My_variable;
-extern int fact(int n);
-extern int my_mod(int x, int y);
-extern char *get_time();
-%}
-
-extern double My_variable;
-extern int fact(int n);
-extern int my_mod(int x, int y);
-extern char *get_time();
View
@@ -0,0 +1,55 @@
+#!/usr/bin/env ruby
+require 'mkmf'
+
+def error(msg)
+ message(msg + "\n")
+ abort
+end
+
+SWIG_BIN_PATH = ENV['SWIG_BIN_PATH'] || '/usr/bin/swig'
+
+# Check if SWIG_BIN_PATH points to SWIG binary
+unless File.exists?(SWIG_BIN_PATH)
+ error("#{SWIG_BIN_PATH}: No such file or directory.\n" \
+ "Either install SWIG 2.0+, or set SWIG_BIN_PATH to the correct SWIG path.")
+end
+
+# Check if it's SWIG 2.0+
+ver = `#{SWIG_BIN_PATH} -version`.scan(/Version ([\d.]+)/).flatten.first
+unless ver >= '2.0'
+ error("#{SWIG_BIN_PATH} version is #{ver}. You need SWIG 2.0.")
+end
+
+unless have_library('db_cxx')
+ error("You must have Berkeley DB library (libdb) installed.\n")
+end
+
+unless have_library('pcre')
+ error("You must have Perl C Regular Expressions library (libpcre) installed.\n")
+end
+
+unless have_library('omlet')
+ error("You must have libomlet installed.\n")
+end
+
+unless have_library('fries')
+ error("You must have libfries installed.\n")
+end
+
+unless have_library('boost_filesystem')
+ error("You must have libboost_filesystem installed.\n")
+end
+
+unless have_library('morfo')
+ error("You must have libmorfo installed.\n")
+end
+
+# Run SWIG on each interface file
+Dir.glob(File.join(File.dirname(__FILE__), '*.i')).each do |file|
+ swig_command = "#{SWIG_BIN_PATH} -autorename -c++ -ruby #{file}"
+ message("running `#{swig_command}`\n")
+ system(swig_command)
+end
+
+# Finally, create Makefile
+create_makefile('libmorfo_ruby')
Oops, something went wrong.

0 comments on commit b79761d

Please sign in to comment.