SlideShare a Scribd company logo
1 of 34
�
foreign import ccall ”math.h sin”
  sin :: CDouble -> CDouble




foreign export ccall ”fact”
  fact :: CInt -> CInt
�
== factorial.hs ==
Module Factorial where
import Foreign.C.Types
foreign export ccall ”factorial”
  factorial :: CInt -> Cint
factorial 0 = 1
factorial x = x * factorial(x-1)
== main.c ==
#include <stdio.h>
#include “factorial_stub.h”
int main(int argc, char* argv[])
{
  hs_init(&argc, &argv);
  printf(“%dn”, fact(5));
  hs_exit();
  return 0;
}
$ ghc -shared -dynamic
...                  (   )
#include <ruby.h>
#include "factorial_stub.h"
static VALUE rb_factorial(VALUE self, VALUE val)
{
  return UINT2NUM(factorial(NUM2UINT(val)));
}
void Init_factorial(void)
{
  hs_init(NULL, NULL);//        Haskell          ..
    rb_define_module_function(rb_mMath, "factorial",
      RUBY_METHOD_FUNC(rb_factorial), 1);
}
(gem install         )

$ irb -r factorial/factorial
irb(main):001:0> Math.factorial 4
=> 24
foreign export ccall ”factorial”
factorial :: CInt -> CInt
CInt   -229   +229-1

  9               362,880
 10              3,628,800
 15            1.30767E+12
$ cd `ghc --print-libdir`




     �
require 'rbconfig'
TARGET = 'factorial'
C_SRC = %w{ main.c }
HS_SRC = %w{ factorial.hs }
HS_LIBS = %w{ base integer-gmp ghc-prim }
CONF = RbConfig::MAKEFILE_CONFIG
VALS = %w{prefix includedir RUBY_BASE_NAME ruby_version
rubyhdrdir arch MKDIR_P INSTALL INSTALL_PROGRAM}.map{|k|
          "#{k}=#{CONF[k]}"
        }.join("n")
GHC_LIBDIR=`ghc --print-libdir`.strip
FLAGS = "FLAGS=-I$(rubyhdrdir) -I$(rubyhdrdir)/$(arch) -
shared -dynamic -no-hs-main -lHSrts -lffin" 
       + "FLAGS+=-no-auto-link-packages -I#{GHC_LIBDIR}/
include -L#{GHC_LIBDIR}n" 
       + HS_LIBS.map{|l|
          'FLAGS+=' + `ghc-pkg describe #{l}|sed -ne 's/
library-dirs: /-L/p;s/hs-libraries: /-l/p;'`.gsub(/n/, ' ')
         }.join("n") 
       + "nFLAGS+=-lgmpn"
File.open("Makefile", "w") {|f|
  f.puts <<__MAKEFILE__
TARGET=#{TARGET}.#{CONF['DLEXT']}
HS_SRC=#{HS_SRC.join(' ')}
C_SRC=#{C_SRC.join(' ')}
#{VALS}
#{FLAGS}
STUB=$(HS_SRC:.hs=_stub.o)

all : $(TARGET)

$(STUB) : $(HS_SRC)
   ghc $<

$(TARGET) : $(C_SRC) $(STUB) $(HS_SRC:.hs=.o)
   ghc -o $@ $^ $(FLAGS)

install:
   $(MKDIR_P) ../lib/#{TARGET}/
   $(INSTALL_PROGRAM) $(TARGET) ../lib/#{TARGET}/

clean:
   rm -f $(TARGET) $(C_SRC:.c=.o) $(HS_SRC:.hs=.hi) $
(HS_SRC:.hs=.o) $(HS_SRC:.hs=_stub.)*
__MAKEFILE__
}
�




�
�
Ruby haskell extension
Ruby haskell extension
Ruby haskell extension
Ruby haskell extension

More Related Content

What's hot (20)

Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Include
IncludeInclude
Include
 
C++ programs
C++ programsC++ programs
C++ programs
 
Bankers Algo Implementation
Bankers Algo ImplementationBankers Algo Implementation
Bankers Algo Implementation
 
Oops in c++
Oops in c++Oops in c++
Oops in c++
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
 
Code
CodeCode
Code
 
A Shiny Example-- R
A Shiny Example-- RA Shiny Example-- R
A Shiny Example-- R
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
Modificacion del programa
Modificacion del programaModificacion del programa
Modificacion del programa
 
PROGRAM FOR INSERTION SORTING IN ARRAY
PROGRAM FOR INSERTION SORTING IN ARRAY PROGRAM FOR INSERTION SORTING IN ARRAY
PROGRAM FOR INSERTION SORTING IN ARRAY
 
Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2
 
ECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScriptECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScript
 
Introduction to cron queue
Introduction to cron queueIntroduction to cron queue
Introduction to cron queue
 
week-5x
week-5xweek-5x
week-5x
 
Document
DocumentDocument
Document
 
cosc 281 hw2
cosc 281 hw2cosc 281 hw2
cosc 281 hw2
 

Viewers also liked

Viewers also liked (11)

Frank-afcproxy
Frank-afcproxyFrank-afcproxy
Frank-afcproxy
 
Amazon aws 20110611
Amazon aws 20110611Amazon aws 20110611
Amazon aws 20110611
 
Castoro sequense
Castoro sequenseCastoro sequense
Castoro sequense
 
Apache mod authまわりとか
Apache mod authまわりとかApache mod authまわりとか
Apache mod authまわりとか
 
Ruby2.0 - refinements - 鳥取Ruby会 第11回
Ruby2.0 - refinements - 鳥取Ruby会 第11回Ruby2.0 - refinements - 鳥取Ruby会 第11回
Ruby2.0 - refinements - 鳥取Ruby会 第11回
 
とっとるびー(2回目)発表資料
とっとるびー(2回目)発表資料とっとるびー(2回目)発表資料
とっとるびー(2回目)発表資料
 
Castoro / RubyKaigi2010
Castoro / RubyKaigi2010Castoro / RubyKaigi2010
Castoro / RubyKaigi2010
 
Apache2.3 探訪
Apache2.3 探訪Apache2.3 探訪
Apache2.3 探訪
 
Tottoruby 20130119
Tottoruby 20130119Tottoruby 20130119
Tottoruby 20130119
 
Bazaar
BazaarBazaar
Bazaar
 
Web Server - Internet Applications
Web Server - Internet ApplicationsWeb Server - Internet Applications
Web Server - Internet Applications
 

Similar to Ruby haskell extension

C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2Koshy Geoji
 
IR Journal (itscholar.codegency.co.in).pdf
IR Journal (itscholar.codegency.co.in).pdfIR Journal (itscholar.codegency.co.in).pdf
IR Journal (itscholar.codegency.co.in).pdfRahulRoy130127
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたAkira Maruoka
 
Basicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationBasicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationDinesh Manajipet
 
C basics
C basicsC basics
C basicsMSc CST
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)Ashishchinu
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2ytoshima
 
ISCA Final Presentaiton - Compilations
ISCA Final Presentaiton -  CompilationsISCA Final Presentaiton -  Compilations
ISCA Final Presentaiton - CompilationsHSA Foundation
 
R (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemR (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemMaithreya Chakravarthula
 
Billing in a supermarket c++
Billing in a supermarket c++Billing in a supermarket c++
Billing in a supermarket c++varun arora
 

Similar to Ruby haskell extension (20)

C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
IR Journal (itscholar.codegency.co.in).pdf
IR Journal (itscholar.codegency.co.in).pdfIR Journal (itscholar.codegency.co.in).pdf
IR Journal (itscholar.codegency.co.in).pdf
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
C Programming
C ProgrammingC Programming
C Programming
 
Basicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationBasicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt application
 
C basics
C basicsC basics
C basics
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
ISCA Final Presentaiton - Compilations
ISCA Final Presentaiton -  CompilationsISCA Final Presentaiton -  Compilations
ISCA Final Presentaiton - Compilations
 
R (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemR (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support System
 
Billing in a supermarket c++
Billing in a supermarket c++Billing in a supermarket c++
Billing in a supermarket c++
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 

Recently uploaded

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Ruby haskell extension

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. foreign import ccall ”math.h sin” sin :: CDouble -> CDouble foreign export ccall ”fact” fact :: CInt -> CInt
  • 10.
  • 11. == factorial.hs == Module Factorial where import Foreign.C.Types foreign export ccall ”factorial” factorial :: CInt -> Cint factorial 0 = 1 factorial x = x * factorial(x-1)
  • 12.
  • 13. == main.c == #include <stdio.h> #include “factorial_stub.h” int main(int argc, char* argv[]) { hs_init(&argc, &argv); printf(“%dn”, fact(5)); hs_exit(); return 0; }
  • 14. $ ghc -shared -dynamic ... ( )
  • 15. #include <ruby.h> #include "factorial_stub.h" static VALUE rb_factorial(VALUE self, VALUE val) { return UINT2NUM(factorial(NUM2UINT(val))); } void Init_factorial(void) { hs_init(NULL, NULL);// Haskell .. rb_define_module_function(rb_mMath, "factorial", RUBY_METHOD_FUNC(rb_factorial), 1); }
  • 16. (gem install ) $ irb -r factorial/factorial irb(main):001:0> Math.factorial 4 => 24
  • 17. foreign export ccall ”factorial” factorial :: CInt -> CInt CInt -229 +229-1 9 362,880 10 3,628,800 15 1.30767E+12
  • 18.
  • 19.
  • 20.
  • 21. $ cd `ghc --print-libdir` �
  • 22.
  • 23.
  • 24. require 'rbconfig' TARGET = 'factorial' C_SRC = %w{ main.c } HS_SRC = %w{ factorial.hs } HS_LIBS = %w{ base integer-gmp ghc-prim } CONF = RbConfig::MAKEFILE_CONFIG VALS = %w{prefix includedir RUBY_BASE_NAME ruby_version rubyhdrdir arch MKDIR_P INSTALL INSTALL_PROGRAM}.map{|k| "#{k}=#{CONF[k]}" }.join("n") GHC_LIBDIR=`ghc --print-libdir`.strip FLAGS = "FLAGS=-I$(rubyhdrdir) -I$(rubyhdrdir)/$(arch) - shared -dynamic -no-hs-main -lHSrts -lffin" + "FLAGS+=-no-auto-link-packages -I#{GHC_LIBDIR}/ include -L#{GHC_LIBDIR}n" + HS_LIBS.map{|l| 'FLAGS+=' + `ghc-pkg describe #{l}|sed -ne 's/ library-dirs: /-L/p;s/hs-libraries: /-l/p;'`.gsub(/n/, ' ') }.join("n") + "nFLAGS+=-lgmpn"
  • 25. File.open("Makefile", "w") {|f| f.puts <<__MAKEFILE__ TARGET=#{TARGET}.#{CONF['DLEXT']} HS_SRC=#{HS_SRC.join(' ')} C_SRC=#{C_SRC.join(' ')} #{VALS} #{FLAGS} STUB=$(HS_SRC:.hs=_stub.o) all : $(TARGET) $(STUB) : $(HS_SRC) ghc $< $(TARGET) : $(C_SRC) $(STUB) $(HS_SRC:.hs=.o) ghc -o $@ $^ $(FLAGS) install: $(MKDIR_P) ../lib/#{TARGET}/ $(INSTALL_PROGRAM) $(TARGET) ../lib/#{TARGET}/ clean: rm -f $(TARGET) $(C_SRC:.c=.o) $(HS_SRC:.hs=.hi) $ (HS_SRC:.hs=.o) $(HS_SRC:.hs=_stub.)* __MAKEFILE__ }
  • 26.
  • 27.
  • 28.
  • 30.

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n