SlideShare una empresa de Scribd logo
1 de 24
Descargar para leer sin conexión
Building C/C++ libraries with Perl

    Alberto Manuel Brand˜o Sim˜es
                        a     o
            ambs@perl.pt



           YAPC::EU::2012




        Alberto Sim˜es
                   o     Building C/C++ libraries with Perl
Disclaimer



                              This is my point of view;

                              This is not the best approach. . .
                                    . . . surely . . .
                                    . . . just not sure what it is!

                              This is the way I decided to go. . .

                              And it is working (so far!)




             Alberto Sim˜es
                        o      Building C/C++ libraries with Perl
Standard Source Packaging




                             Perl modules are not a problem.

                             C/C++ libraries or apps are usually:
                                   bundled with a autoconf script;
                                   bundled with a cmake;




                  Alberto Sim˜es
                             o     Building C/C++ libraries with Perl
AutoTools


                       The autotools are the most used, but:
                             not portable (check Windows);
                             a mess:
                             Perl script that processes a DSL that
                             includes references to M4 macros,
                             and Shell snippets, and generate a
                             shell script. It also interpolates
                             makefiles, and other crazy stuff.

                       Most macros are copy & paste from
                       other projects

                       Few people really understand them



            Alberto Sim˜es
                       o     Building C/C++ libraries with Perl
AutoTools Dependencies

     To use AutoTools we need:
         AutoConf;
         AutoMake;
         LibTool;
         Perl;
         shell;
     I know end-users should only require sh. Is that really true?




                       Alberto Sim˜es
                                  o     Building C/C++ libraries with Perl
Hey, u said Perl?
Use Perl as a Build System


                              Use Perl as a Build System.
                              What are the (my) options?
                                         ExtUtils::MakeMaker;
                                         Module::Build;

      ExtUtils::MakeMaker is not suitable:
          Constructing a Makefile string is error prone;
          Most system detection needs to be defined at configure time;
      Module::Build is easy to subclass:
          Gives all the power of Perl (that can be bad);
          Easier to develop and debug.




                        Alberto Sim˜es
                                   o        Building C/C++ libraries with Perl
Use Perl as a Build System


                              Use Perl as a Build System.
                              What are the (my) options?
                                         ExtUtils::MakeMaker;
                                         Module::Build;

      ExtUtils::MakeMaker is not suitable:
          Constructing a Makefile string is error prone;
          Most system detection needs to be defined at configure time;
      Module::Build is easy to subclass:
          Gives all the power of Perl (that can be bad);
          Easier to develop and debug.




                        Alberto Sim˜es
                                   o        Building C/C++ libraries with Perl
What more do I need?

                   ExtUtils::CBuilder
                   Something that helps compiling C/C++ code
                   ExtUtils::ParseXS
                   Something that helps me parse XS files
                   ExtUtils::Mkbootstrap
                   Something to create DynaLoader bootstrap
                   files
                   ExtUtils::PkgConfig or PkgConfig
                   Something to detect libs that ship a .pc file
                   Config::AutoConf
                   Something that helps me detecting other
                   libraries. . .
                   ExtUtils::LibBuilder
                   Something that knows how to link a standard
                   library
                  Alberto Sim˜es
                             o     Building C/C++ libraries with Perl
The Nuts and Bolts




                     Alberto Sim˜es
                                o     Building C/C++ libraries with Perl
Case Study 1

  Lingua::Jspell
      A Morphological Analyzer for NLP;
      It is a standard C app based on ispell code;
      It includes Perl bindings (through Open3 atm);
      There is no real reason to bundle the app with the Perl
      module.
  The build chain uses:
      Module::Build;
      ExtUtils::CBuilder;
      ExtUtils::LibBuilder;
      Config::AutoConf;


                          Alberto Sim˜es
                                     o     Building C/C++ libraries with Perl
Case Study 1

  Lingua::Jspell
      A Morphological Analyzer for NLP;
      It is a standard C app based on ispell code;
      It includes Perl bindings (through Open3 atm);
      There is no real reason to bundle the app with the Perl
      module.
  The build chain uses:
      Module::Build;
      ExtUtils::CBuilder;
      ExtUtils::LibBuilder;
      Config::AutoConf;


                          Alberto Sim˜es
                                     o     Building C/C++ libraries with Perl
Case Study 1


  Config::AutoConf is used to:


       Detect libraries and headers (in Build.PL):
      §                                                                             ¤
          Config : : AutoConf−>check_header ( ” n c u r s e s . h ” ) ;
          Config : : AutoConf−>check_lib ( ” n c u r s e s ” , ”t g o t o ” ) ;
      ¦                                                                             ¥




  More details on the Build.PL script in the article.



                              Alberto Sim˜es
                                         o     Building C/C++ libraries with Perl
Case Study 1
  I subclass Builder redefining methods:
 §                                                                                     ¤
  sub ACTION_code {
    my $self = s h i f t ;

      # c r e a t e t h e L i b B u i l d e r o b j e c t and c a c h e i t
      $self−>notes ( libbuilder => ExtUtils : : LibBuilder−>new ) ;

      # d i s p a t c h e v e r y needed a c t i o n
      $self−>dispatch ( ” c r e a t e b l i b f o l d e r s ” ) ;
      $self−>dispatch ( ”c r e a t e m a n p a g e s ” ) ;
      $self−>dispatch ( ” c r e a t e y a c c ” ) ;
      $self−>dispatch ( ” c r e a t e o b j e c t s ” ) ;
      $self−>dispatch ( ” c r e a t e l i b r a r y ” ) ;
      $self−>dispatch ( ” c r e a t e b i n a r i e s ” ) ;

      # and now , c a l l s u p e r c l a s s .
      $self−>SUPER : : ACTION_code ;
  }
 ¦                                                                                     ¥

                               Alberto Sim˜es
                                          o       Building C/C++ libraries with Perl
Case Study 1

  The create yacc action also uses Config::AutoConf
 §                                                                                    ¤
  sub ACTION_create_yacc {
    my $self = s h i f t ;

      my $ytabc = ’ s r c / y . t a b . c ’ ;
      my $parsey = ’ s r c / p a r s e . y ’ ;

      r e t u r n i f $self−>up_to_date ( $parsey , $ytabc ) ;

      my $yacc = Config : : AutoConf−>check_prog ( ”y a c c ” ,
                                                   ”b i s o n ” ) ;
      i f ( $yacc ) {
         ‘ $yacc −o $ytabc $parsey ‘ ;
      }
  }
 ¦                                                                                    ¥



                               Alberto Sim˜es
                                          o      Building C/C++ libraries with Perl
Case Study 1
  Build object files (plain ExtUtils::CBuilder usage):
 §                                                                               ¤
  sub ACTION_create_objects {
    my $self = s h i f t ;

      my $cbuilder = $self−>cbuilder ;
      my $c_files = $self−>rscan_dir ( ’ s r c ’ , qr /  . c$ / ) ;
      my $xtr_comp_flags = ”−g ” . $self−>notes ( ’ c c u r s e s ’ ) ;

      f o r my $file ( @$c_files ) {
           my $object = $file =˜ s /  . c / . o/r ;
           n e x t i f $self−>up_to_date ( $file , $object ) ;

          $cbuilder−>compile ( object_file => $object ,
                               source       => $file ,
                               include_dirs => [ ” s r c ” ] ,
                               extra_compiler_flags =>
                                        $xtr_comp_flags ) ;
      }
  }
 ¦                                                                               ¥
                           Alberto Sim˜es
                                      o     Building C/C++ libraries with Perl
Case Study 1
  And the main stuff, build a standard library
 §                                                                                 ¤
  sub ACTION_create_library {
    my $self = s h i f t ;
    my $libbuilder = $self−>notes ( ’ l i b b u i l d e r ’ ) ;
    ...
    # d e f i n e the l i n k e r f l a g s
    my $xlinkerflags = $self−>notes ( ’ l c u r s e s ’ )
                              . $self−>notes ( ’ c c u r s e s ’ ) ;
    i f ( $ˆO =˜ / darwin / ) {
       $xlinkerflags .= ” − i n s t a l l n a m e $ l i b p a t h ” }

     # l i n k i f t h e l i b r a r y i s n o t up t o d a t e
     i f ( ! $self−>up_to_date (  @objs , $libfile ) ) {
        $libbuilder−>l i n k ( module_name => ’ l i b j s p e l l ’ ,
                       extra_linker_flags => $xlinkerflags ,
                       objects =>  @objects ,
                       lib_file => $libfile ) ;
     }
     ...
 ¦                                                                                 ¥
                             Alberto Sim˜es
                                        o     Building C/C++ libraries with Perl
Case Study 1
  And build the C binaries.
 §                                                                                         ¤
     sub ACTION_create_binaries {
       my $self = s h i f t ;
       my $libbuilder = $self−>notes ( ’ l i b b u i l d e r ’ ) ;
       ...
       # define flags
       my $extralinkerflags = $self−>notes ( ’ l c u r s e s ’ )
                                   . $self−>notes ( ’ c c u r s e s ’ ) ;
       ...
       # i f needed , l i n k t h e e x e c u t a b l e
       i f ( ! $self−>up_to_date ( $object , $exe_file ) ) {
             $libbuilder−>link_executable (
                  exe_file => $exe_file ,
                  objects => [ $object ] ,
                  extra_linker_flags =>
                       ”−L s r c − l j s p e l l $ e x t r a l i n k e r f l a g s ” ) ;
       }
       ...
 ¦                                                                                         ¥

                                Alberto Sim˜es
                                           o     Building C/C++ libraries with Perl
Case Study 1
  Work out a testing environment.
 §                                                                                      ¤
  sub ACTION_test {
    my $self = s h i f t ;

      i f ( $ˆO =˜ / mswin32 /i ) {
          $ENV { PATH } = $self−>blib . ”/ u s r l i b ; $ENV{PATH} ” ;
      }
      e l s i f ( $ˆO =˜ / darwin /i ) {
          $ENV { DYLD_LIBRARY_PATH } = $self−>blib . ”/ u s r l i b ” ;
      }
      e l s i f ( $ˆO =˜/linux | bsd | sun | sol | dragon | hpux | irix /i ) {
          $ENV { LD_LIBRARY_PATH } = $self−>blib . ”/ u s r l i b ” ;
      }
      e l s i f ( $ˆO =˜ / aix /i ) {
         my $oldlibpath = $ENV { LIBPATH } | | ’ / l i b : / u s r / l i b ’ ;
          $ENV { LIBPATH } = $self−>blib . ”/ u s r l i b : $ o l d l i b p a t h ” ;
      }
      $self−>SUPER : : ACTION_test
  }
 ¦                                                                                      ¥
                               Alberto Sim˜es
                                          o     Building C/C++ libraries with Perl
Case Study 2

  Lingua::Identify::CLD
      Interface to Google’s Compact Language Detector;
      It bundles a standard C++ library;
      It includes Perl bindings (through XS);
  The build chain uses:
      Module::Build;
      ExtUtils::CBuilder;
      ExtUtils::LibBuilder;
      Config::AutoConf;
      ExtUtils::ParseXS;
      ExtUtils::Mkbootstrap;


                          Alberto Sim˜es
                                     o     Building C/C++ libraries with Perl
Case Study 2

  Lingua::Identify::CLD
      Interface to Google’s Compact Language Detector;
      It bundles a standard C++ library;
      It includes Perl bindings (through XS);
  The build chain uses:
      Module::Build;
      ExtUtils::CBuilder;
      ExtUtils::LibBuilder;
      Config::AutoConf;
      ExtUtils::ParseXS;
      ExtUtils::Mkbootstrap;


                          Alberto Sim˜es
                                     o     Building C/C++ libraries with Perl
Case Study 2
  Compiling XS code as... standard XS code (mostly)
 §                                                                                          ¤
  sub ACTION_compile_xscode {
    ...
    # c r e a t e CLD . c c from CLD . x s
    ExtUtils : : ParseXS : : process_file ( . . . ) ;

     # c r e a t e CLD . o from CLD . c c
     $cbuilder−>compile ( . . . ) ;

     # C r e a t e . b s b o o t s t r a p f i l e , n e e d e d by D y n a l o a d e r .
     ExtUtils : : Mkbootstrap : : Mkbootstrap ( . . . ) ;

     # set linker flags
     my $xlinkerflags = ”−L c l d −s r c − l c l d − l s t d c++” ;
     $xlinkerflags .= ” − l g c c s ” i f $ˆO eq ’ n e t b s d ’ ;

     # link
     $cbuilder−>l i n k ( . . . ) ;
 ¦                                                                                          ¥

                                 Alberto Sim˜es
                                            o      Building C/C++ libraries with Perl
Concluding




     It works!
     The process is similar for all modules;
     Then, this can be generalized in a module;
     Works on UNIX systems;
     Works on Strawberry Win32;




                       Alberto Sim˜es
                                  o     Building C/C++ libraries with Perl
Thank you!




             Alberto Sim˜es
                        o     Building C/C++ libraries with Perl

Más contenido relacionado

La actualidad más candente

DEF CON 27 - workshop - DINO COVOTSOS - hack to basics
DEF CON 27 - workshop - DINO COVOTSOS - hack to basicsDEF CON 27 - workshop - DINO COVOTSOS - hack to basics
DEF CON 27 - workshop - DINO COVOTSOS - hack to basicsFelipe Prado
 
Aprendendo solid com exemplos
Aprendendo solid com exemplosAprendendo solid com exemplos
Aprendendo solid com exemplosvinibaggio
 
Bug fix sharing : where does bug come from
Bug fix sharing : where does bug come fromBug fix sharing : where does bug come from
Bug fix sharing : where does bug come from宇 申
 
A bridge between php and ruby
A bridge between php and ruby A bridge between php and ruby
A bridge between php and ruby do_aki
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio
 
ShaREing Is Caring
ShaREing Is CaringShaREing Is Caring
ShaREing Is Caringsporst
 
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)Alex Balhatchet
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experimentAmos Wenger
 
Safer JS Codebases with Flow
Safer JS Codebases with FlowSafer JS Codebases with Flow
Safer JS Codebases with FlowValentin Agachi
 
How to really obfuscate your pdf malware
How to really obfuscate your pdf malwareHow to really obfuscate your pdf malware
How to really obfuscate your pdf malwarezynamics GmbH
 
Command Line Applications with Ruby
Command Line Applications with RubyCommand Line Applications with Ruby
Command Line Applications with RubyAlexander Merkulov
 
100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects 100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects Andrey Karpov
 
Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into JavascriptMassimo Franciosa
 
Connecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with EmbindConnecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with EmbindChad Austin
 

La actualidad más candente (19)

In Vogue Dynamic
In Vogue DynamicIn Vogue Dynamic
In Vogue Dynamic
 
DEF CON 27 - workshop - DINO COVOTSOS - hack to basics
DEF CON 27 - workshop - DINO COVOTSOS - hack to basicsDEF CON 27 - workshop - DINO COVOTSOS - hack to basics
DEF CON 27 - workshop - DINO COVOTSOS - hack to basics
 
Aprendendo solid com exemplos
Aprendendo solid com exemplosAprendendo solid com exemplos
Aprendendo solid com exemplos
 
PHP 5.3
PHP 5.3PHP 5.3
PHP 5.3
 
Bug fix sharing : where does bug come from
Bug fix sharing : where does bug come fromBug fix sharing : where does bug come from
Bug fix sharing : where does bug come from
 
A bridge between php and ruby
A bridge between php and ruby A bridge between php and ruby
A bridge between php and ruby
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's code
 
ShaREing Is Caring
ShaREing Is CaringShaREing Is Caring
ShaREing Is Caring
 
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experiment
 
Safer JS Codebases with Flow
Safer JS Codebases with FlowSafer JS Codebases with Flow
Safer JS Codebases with Flow
 
Um2010
Um2010Um2010
Um2010
 
How to really obfuscate your pdf malware
How to really obfuscate your pdf malwareHow to really obfuscate your pdf malware
How to really obfuscate your pdf malware
 
Java vs. C/C++
Java vs. C/C++Java vs. C/C++
Java vs. C/C++
 
Command Line Applications with Ruby
Command Line Applications with RubyCommand Line Applications with Ruby
Command Line Applications with Ruby
 
100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects 100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects
 
Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into Javascript
 
Connecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with EmbindConnecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with Embind
 
March2004-CPerlRun
March2004-CPerlRunMarch2004-CPerlRun
March2004-CPerlRun
 

Similar a Building C/C++ libs with Perl

Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projectsMpho Mphego
 
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneWhen Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneDavid Glick
 
Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compilerovidlivi91
 
please use only these Part 1 Organize the code 85 Fo.pdf
please use only these   Part 1 Organize the code 85  Fo.pdfplease use only these   Part 1 Organize the code 85  Fo.pdf
please use only these Part 1 Organize the code 85 Fo.pdfableelectronics
 
Writing a Gem with native extensions
Writing a Gem with native extensionsWriting a Gem with native extensions
Writing a Gem with native extensionsTristan Penman
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVMJung Kim
 
CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013Spyros Ioakeimidis
 
Raising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code QualityRaising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code QualityThomas Moulard
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone CivettaCocoaHeads France
 
The End of the world as we know it - AKA your last NullPointerException $1B b...
The End of the world as we know it - AKA your last NullPointerException $1B b...The End of the world as we know it - AKA your last NullPointerException $1B b...
The End of the world as we know it - AKA your last NullPointerException $1B b...Michael Vorburger
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfAnassElHousni
 
Working with NIM - By Jordan Hrycaj
Working with NIM - By Jordan HrycajWorking with NIM - By Jordan Hrycaj
Working with NIM - By Jordan Hrycajcamsec
 
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the CoreNSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the CoreNoSuchCon
 

Similar a Building C/C++ libs with Perl (20)

Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
 
Php on Windows
Php on WindowsPhp on Windows
Php on Windows
 
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneWhen Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
 
C# tutorial
C# tutorialC# tutorial
C# tutorial
 
Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compiler
 
MattsonTutorialSC14.pdf
MattsonTutorialSC14.pdfMattsonTutorialSC14.pdf
MattsonTutorialSC14.pdf
 
please use only these Part 1 Organize the code 85 Fo.pdf
please use only these   Part 1 Organize the code 85  Fo.pdfplease use only these   Part 1 Organize the code 85  Fo.pdf
please use only these Part 1 Organize the code 85 Fo.pdf
 
Writing a Gem with native extensions
Writing a Gem with native extensionsWriting a Gem with native extensions
Writing a Gem with native extensions
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013
 
Intro to .NET and Core C#
Intro to .NET and Core C#Intro to .NET and Core C#
Intro to .NET and Core C#
 
Raising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code QualityRaising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code Quality
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone Civetta
 
.NET for hackers
.NET for hackers.NET for hackers
.NET for hackers
 
The End of the world as we know it - AKA your last NullPointerException $1B b...
The End of the world as we know it - AKA your last NullPointerException $1B b...The End of the world as we know it - AKA your last NullPointerException $1B b...
The End of the world as we know it - AKA your last NullPointerException $1B b...
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
Working with NIM - By Jordan Hrycaj
Working with NIM - By Jordan HrycajWorking with NIM - By Jordan Hrycaj
Working with NIM - By Jordan Hrycaj
 
C++ Training
C++ TrainingC++ Training
C++ Training
 
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the CoreNSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
 

Más de Alberto Simões

Language Identification: A neural network approach
Language Identification: A neural network approachLanguage Identification: A neural network approach
Language Identification: A neural network approachAlberto Simões
 
Making the most of a 100-year-old dictionary
Making the most of a 100-year-old dictionaryMaking the most of a 100-year-old dictionary
Making the most of a 100-year-old dictionaryAlberto Simões
 
Dictionary Alignment by Rewrite-based Entry Translation
Dictionary Alignment by Rewrite-based Entry TranslationDictionary Alignment by Rewrite-based Entry Translation
Dictionary Alignment by Rewrite-based Entry TranslationAlberto Simões
 
EMLex-A5: Specialized Dictionaries
EMLex-A5: Specialized DictionariesEMLex-A5: Specialized Dictionaries
EMLex-A5: Specialized DictionariesAlberto Simões
 
Aula 04 - Introdução aos Diagramas de Sequência
Aula 04 - Introdução aos Diagramas de SequênciaAula 04 - Introdução aos Diagramas de Sequência
Aula 04 - Introdução aos Diagramas de SequênciaAlberto Simões
 
Aula 03 - Introdução aos Diagramas de Atividade
Aula 03 - Introdução aos Diagramas de AtividadeAula 03 - Introdução aos Diagramas de Atividade
Aula 03 - Introdução aos Diagramas de AtividadeAlberto Simões
 
Aula 02 - Engenharia de Requisitos
Aula 02 - Engenharia de RequisitosAula 02 - Engenharia de Requisitos
Aula 02 - Engenharia de RequisitosAlberto Simões
 
Aula 01 - Planeamento de Sistemas de Informação
Aula 01 - Planeamento de Sistemas de InformaçãoAula 01 - Planeamento de Sistemas de Informação
Aula 01 - Planeamento de Sistemas de InformaçãoAlberto Simões
 
Processing XML: a rewriting system approach
Processing XML: a rewriting system approachProcessing XML: a rewriting system approach
Processing XML: a rewriting system approachAlberto Simões
 
Arquitecturas de Tradução Automática
Arquitecturas de Tradução AutomáticaArquitecturas de Tradução Automática
Arquitecturas de Tradução AutomáticaAlberto Simões
 
Extracção de Recursos para Tradução Automática
Extracção de Recursos para Tradução AutomáticaExtracção de Recursos para Tradução Automática
Extracção de Recursos para Tradução AutomáticaAlberto Simões
 

Más de Alberto Simões (20)

Source Code Quality
Source Code QualitySource Code Quality
Source Code Quality
 
Language Identification: A neural network approach
Language Identification: A neural network approachLanguage Identification: A neural network approach
Language Identification: A neural network approach
 
Google Maps JS API
Google Maps JS APIGoogle Maps JS API
Google Maps JS API
 
Making the most of a 100-year-old dictionary
Making the most of a 100-year-old dictionaryMaking the most of a 100-year-old dictionary
Making the most of a 100-year-old dictionary
 
Dictionary Alignment by Rewrite-based Entry Translation
Dictionary Alignment by Rewrite-based Entry TranslationDictionary Alignment by Rewrite-based Entry Translation
Dictionary Alignment by Rewrite-based Entry Translation
 
EMLex-A5: Specialized Dictionaries
EMLex-A5: Specialized DictionariesEMLex-A5: Specialized Dictionaries
EMLex-A5: Specialized Dictionaries
 
Modelação de Dados
Modelação de DadosModelação de Dados
Modelação de Dados
 
Aula 04 - Introdução aos Diagramas de Sequência
Aula 04 - Introdução aos Diagramas de SequênciaAula 04 - Introdução aos Diagramas de Sequência
Aula 04 - Introdução aos Diagramas de Sequência
 
Aula 03 - Introdução aos Diagramas de Atividade
Aula 03 - Introdução aos Diagramas de AtividadeAula 03 - Introdução aos Diagramas de Atividade
Aula 03 - Introdução aos Diagramas de Atividade
 
Aula 02 - Engenharia de Requisitos
Aula 02 - Engenharia de RequisitosAula 02 - Engenharia de Requisitos
Aula 02 - Engenharia de Requisitos
 
Aula 01 - Planeamento de Sistemas de Informação
Aula 01 - Planeamento de Sistemas de InformaçãoAula 01 - Planeamento de Sistemas de Informação
Aula 01 - Planeamento de Sistemas de Informação
 
PLN em Perl
PLN em PerlPLN em Perl
PLN em Perl
 
Classification Systems
Classification SystemsClassification Systems
Classification Systems
 
Redes de Pert
Redes de PertRedes de Pert
Redes de Pert
 
Dancing Tutorial
Dancing TutorialDancing Tutorial
Dancing Tutorial
 
Processing XML: a rewriting system approach
Processing XML: a rewriting system approachProcessing XML: a rewriting system approach
Processing XML: a rewriting system approach
 
Sistemas de Numeração
Sistemas de NumeraçãoSistemas de Numeração
Sistemas de Numeração
 
Álgebra de Boole
Álgebra de BooleÁlgebra de Boole
Álgebra de Boole
 
Arquitecturas de Tradução Automática
Arquitecturas de Tradução AutomáticaArquitecturas de Tradução Automática
Arquitecturas de Tradução Automática
 
Extracção de Recursos para Tradução Automática
Extracção de Recursos para Tradução AutomáticaExtracção de Recursos para Tradução Automática
Extracção de Recursos para Tradução Automática
 

Último

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Último (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Building C/C++ libs with Perl

  • 1. Building C/C++ libraries with Perl Alberto Manuel Brand˜o Sim˜es a o ambs@perl.pt YAPC::EU::2012 Alberto Sim˜es o Building C/C++ libraries with Perl
  • 2. Disclaimer This is my point of view; This is not the best approach. . . . . . surely . . . . . . just not sure what it is! This is the way I decided to go. . . And it is working (so far!) Alberto Sim˜es o Building C/C++ libraries with Perl
  • 3. Standard Source Packaging Perl modules are not a problem. C/C++ libraries or apps are usually: bundled with a autoconf script; bundled with a cmake; Alberto Sim˜es o Building C/C++ libraries with Perl
  • 4. AutoTools The autotools are the most used, but: not portable (check Windows); a mess: Perl script that processes a DSL that includes references to M4 macros, and Shell snippets, and generate a shell script. It also interpolates makefiles, and other crazy stuff. Most macros are copy & paste from other projects Few people really understand them Alberto Sim˜es o Building C/C++ libraries with Perl
  • 5. AutoTools Dependencies To use AutoTools we need: AutoConf; AutoMake; LibTool; Perl; shell; I know end-users should only require sh. Is that really true? Alberto Sim˜es o Building C/C++ libraries with Perl
  • 6. Hey, u said Perl?
  • 7. Use Perl as a Build System Use Perl as a Build System. What are the (my) options? ExtUtils::MakeMaker; Module::Build; ExtUtils::MakeMaker is not suitable: Constructing a Makefile string is error prone; Most system detection needs to be defined at configure time; Module::Build is easy to subclass: Gives all the power of Perl (that can be bad); Easier to develop and debug. Alberto Sim˜es o Building C/C++ libraries with Perl
  • 8. Use Perl as a Build System Use Perl as a Build System. What are the (my) options? ExtUtils::MakeMaker; Module::Build; ExtUtils::MakeMaker is not suitable: Constructing a Makefile string is error prone; Most system detection needs to be defined at configure time; Module::Build is easy to subclass: Gives all the power of Perl (that can be bad); Easier to develop and debug. Alberto Sim˜es o Building C/C++ libraries with Perl
  • 9. What more do I need? ExtUtils::CBuilder Something that helps compiling C/C++ code ExtUtils::ParseXS Something that helps me parse XS files ExtUtils::Mkbootstrap Something to create DynaLoader bootstrap files ExtUtils::PkgConfig or PkgConfig Something to detect libs that ship a .pc file Config::AutoConf Something that helps me detecting other libraries. . . ExtUtils::LibBuilder Something that knows how to link a standard library Alberto Sim˜es o Building C/C++ libraries with Perl
  • 10. The Nuts and Bolts Alberto Sim˜es o Building C/C++ libraries with Perl
  • 11. Case Study 1 Lingua::Jspell A Morphological Analyzer for NLP; It is a standard C app based on ispell code; It includes Perl bindings (through Open3 atm); There is no real reason to bundle the app with the Perl module. The build chain uses: Module::Build; ExtUtils::CBuilder; ExtUtils::LibBuilder; Config::AutoConf; Alberto Sim˜es o Building C/C++ libraries with Perl
  • 12. Case Study 1 Lingua::Jspell A Morphological Analyzer for NLP; It is a standard C app based on ispell code; It includes Perl bindings (through Open3 atm); There is no real reason to bundle the app with the Perl module. The build chain uses: Module::Build; ExtUtils::CBuilder; ExtUtils::LibBuilder; Config::AutoConf; Alberto Sim˜es o Building C/C++ libraries with Perl
  • 13. Case Study 1 Config::AutoConf is used to: Detect libraries and headers (in Build.PL): § ¤ Config : : AutoConf−>check_header ( ” n c u r s e s . h ” ) ; Config : : AutoConf−>check_lib ( ” n c u r s e s ” , ”t g o t o ” ) ; ¦ ¥ More details on the Build.PL script in the article. Alberto Sim˜es o Building C/C++ libraries with Perl
  • 14. Case Study 1 I subclass Builder redefining methods: § ¤ sub ACTION_code { my $self = s h i f t ; # c r e a t e t h e L i b B u i l d e r o b j e c t and c a c h e i t $self−>notes ( libbuilder => ExtUtils : : LibBuilder−>new ) ; # d i s p a t c h e v e r y needed a c t i o n $self−>dispatch ( ” c r e a t e b l i b f o l d e r s ” ) ; $self−>dispatch ( ”c r e a t e m a n p a g e s ” ) ; $self−>dispatch ( ” c r e a t e y a c c ” ) ; $self−>dispatch ( ” c r e a t e o b j e c t s ” ) ; $self−>dispatch ( ” c r e a t e l i b r a r y ” ) ; $self−>dispatch ( ” c r e a t e b i n a r i e s ” ) ; # and now , c a l l s u p e r c l a s s . $self−>SUPER : : ACTION_code ; } ¦ ¥ Alberto Sim˜es o Building C/C++ libraries with Perl
  • 15. Case Study 1 The create yacc action also uses Config::AutoConf § ¤ sub ACTION_create_yacc { my $self = s h i f t ; my $ytabc = ’ s r c / y . t a b . c ’ ; my $parsey = ’ s r c / p a r s e . y ’ ; r e t u r n i f $self−>up_to_date ( $parsey , $ytabc ) ; my $yacc = Config : : AutoConf−>check_prog ( ”y a c c ” , ”b i s o n ” ) ; i f ( $yacc ) { ‘ $yacc −o $ytabc $parsey ‘ ; } } ¦ ¥ Alberto Sim˜es o Building C/C++ libraries with Perl
  • 16. Case Study 1 Build object files (plain ExtUtils::CBuilder usage): § ¤ sub ACTION_create_objects { my $self = s h i f t ; my $cbuilder = $self−>cbuilder ; my $c_files = $self−>rscan_dir ( ’ s r c ’ , qr / . c$ / ) ; my $xtr_comp_flags = ”−g ” . $self−>notes ( ’ c c u r s e s ’ ) ; f o r my $file ( @$c_files ) { my $object = $file =˜ s / . c / . o/r ; n e x t i f $self−>up_to_date ( $file , $object ) ; $cbuilder−>compile ( object_file => $object , source => $file , include_dirs => [ ” s r c ” ] , extra_compiler_flags => $xtr_comp_flags ) ; } } ¦ ¥ Alberto Sim˜es o Building C/C++ libraries with Perl
  • 17. Case Study 1 And the main stuff, build a standard library § ¤ sub ACTION_create_library { my $self = s h i f t ; my $libbuilder = $self−>notes ( ’ l i b b u i l d e r ’ ) ; ... # d e f i n e the l i n k e r f l a g s my $xlinkerflags = $self−>notes ( ’ l c u r s e s ’ ) . $self−>notes ( ’ c c u r s e s ’ ) ; i f ( $ˆO =˜ / darwin / ) { $xlinkerflags .= ” − i n s t a l l n a m e $ l i b p a t h ” } # l i n k i f t h e l i b r a r y i s n o t up t o d a t e i f ( ! $self−>up_to_date ( @objs , $libfile ) ) { $libbuilder−>l i n k ( module_name => ’ l i b j s p e l l ’ , extra_linker_flags => $xlinkerflags , objects => @objects , lib_file => $libfile ) ; } ... ¦ ¥ Alberto Sim˜es o Building C/C++ libraries with Perl
  • 18. Case Study 1 And build the C binaries. § ¤ sub ACTION_create_binaries { my $self = s h i f t ; my $libbuilder = $self−>notes ( ’ l i b b u i l d e r ’ ) ; ... # define flags my $extralinkerflags = $self−>notes ( ’ l c u r s e s ’ ) . $self−>notes ( ’ c c u r s e s ’ ) ; ... # i f needed , l i n k t h e e x e c u t a b l e i f ( ! $self−>up_to_date ( $object , $exe_file ) ) { $libbuilder−>link_executable ( exe_file => $exe_file , objects => [ $object ] , extra_linker_flags => ”−L s r c − l j s p e l l $ e x t r a l i n k e r f l a g s ” ) ; } ... ¦ ¥ Alberto Sim˜es o Building C/C++ libraries with Perl
  • 19. Case Study 1 Work out a testing environment. § ¤ sub ACTION_test { my $self = s h i f t ; i f ( $ˆO =˜ / mswin32 /i ) { $ENV { PATH } = $self−>blib . ”/ u s r l i b ; $ENV{PATH} ” ; } e l s i f ( $ˆO =˜ / darwin /i ) { $ENV { DYLD_LIBRARY_PATH } = $self−>blib . ”/ u s r l i b ” ; } e l s i f ( $ˆO =˜/linux | bsd | sun | sol | dragon | hpux | irix /i ) { $ENV { LD_LIBRARY_PATH } = $self−>blib . ”/ u s r l i b ” ; } e l s i f ( $ˆO =˜ / aix /i ) { my $oldlibpath = $ENV { LIBPATH } | | ’ / l i b : / u s r / l i b ’ ; $ENV { LIBPATH } = $self−>blib . ”/ u s r l i b : $ o l d l i b p a t h ” ; } $self−>SUPER : : ACTION_test } ¦ ¥ Alberto Sim˜es o Building C/C++ libraries with Perl
  • 20. Case Study 2 Lingua::Identify::CLD Interface to Google’s Compact Language Detector; It bundles a standard C++ library; It includes Perl bindings (through XS); The build chain uses: Module::Build; ExtUtils::CBuilder; ExtUtils::LibBuilder; Config::AutoConf; ExtUtils::ParseXS; ExtUtils::Mkbootstrap; Alberto Sim˜es o Building C/C++ libraries with Perl
  • 21. Case Study 2 Lingua::Identify::CLD Interface to Google’s Compact Language Detector; It bundles a standard C++ library; It includes Perl bindings (through XS); The build chain uses: Module::Build; ExtUtils::CBuilder; ExtUtils::LibBuilder; Config::AutoConf; ExtUtils::ParseXS; ExtUtils::Mkbootstrap; Alberto Sim˜es o Building C/C++ libraries with Perl
  • 22. Case Study 2 Compiling XS code as... standard XS code (mostly) § ¤ sub ACTION_compile_xscode { ... # c r e a t e CLD . c c from CLD . x s ExtUtils : : ParseXS : : process_file ( . . . ) ; # c r e a t e CLD . o from CLD . c c $cbuilder−>compile ( . . . ) ; # C r e a t e . b s b o o t s t r a p f i l e , n e e d e d by D y n a l o a d e r . ExtUtils : : Mkbootstrap : : Mkbootstrap ( . . . ) ; # set linker flags my $xlinkerflags = ”−L c l d −s r c − l c l d − l s t d c++” ; $xlinkerflags .= ” − l g c c s ” i f $ˆO eq ’ n e t b s d ’ ; # link $cbuilder−>l i n k ( . . . ) ; ¦ ¥ Alberto Sim˜es o Building C/C++ libraries with Perl
  • 23. Concluding It works! The process is similar for all modules; Then, this can be generalized in a module; Works on UNIX systems; Works on Strawberry Win32; Alberto Sim˜es o Building C/C++ libraries with Perl
  • 24. Thank you! Alberto Sim˜es o Building C/C++ libraries with Perl