1N/A# $Id: Embed.pm,v 1.1.1.1 2002/01/16 19:27:19 schwern Exp $ 1N/A#Only when we need them 1N/A#require ExtUtils::MakeMaker; 1N/A#require ExtUtils::Liblist; 1N/A#let's have Miniperl borrow from us instead 1N/A#require ExtUtils::Miniperl; 1N/A#*canon = \&ExtUtils::Miniperl::canon; 1N/A print $
fh "EXTERN_C void xs_init ($xsinit_proto);\n\n";
1N/A print $
fh "\nEXTERN_C void\nxs_init($xsinit_proto)\n{\n";
1N/A my($
ccode) =
"EXTERN_C void boot_${cname} ($boot_proto);\n";
1N/A push(@
retval,
"\tdXSUB_SYS;\n")
if $] >
5.002;
1N/A # Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'! 1N/A $
ccode =
"\t/* DynaLoader is a special case */\n\tnewXS(\"${mname}::boot_${cname}\", boot_${cname}, file);\n";
1N/A $
ccode =
"\tnewXS(\"${mname}::bootstrap\", boot_${cname}, file);\n";
1N/A local($
") = ' ' unless $" eq ' ';
1N/A # makemaker includes std libs on windows by default 1N/A if ($^O
ne 'MSWin32' and defined($
std)) {
1N/A warn "Couldn't open '$extra'";
1N/A #print STDERR "\@potential_libs = @potential_libs\n"; 1N/A if ($^O
eq 'MSWin32') {
1N/A $
lpath =
qq[
"$lpath"]
if $^O
eq 'MSWin32';
1N/A my $
linkage =
"$ccdlflags $ldflags @archives $ld_or_bs";
1N/A $
dir =
qq[
"$dir"]
if $^O
eq 'MSWin32';
1N/AExtUtils::Embed - Utilities for embedding Perl in C/C++ applications 1N/A perl -MExtUtils::Embed -e xsinit 1N/A perl -MExtUtils::Embed -e ccopts 1N/A perl -MExtUtils::Embed -e ldopts 1N/AExtUtils::Embed provides utility functions for embedding a Perl interpreter 1N/Aand extensions in your C/C++ applications. 1N/ATypically, an application B<Makefile> will invoke ExtUtils::Embed 1N/Afunctions while building your application. 1N/AExtUtils::Embed exports the following functions: 1N/Axsinit(), ldopts(), ccopts(), perl_inc(), ccflags(), 1N/Accdlflags(), xsi_header(), xsi_protos(), xsi_body() 1N/AGenerate C/C++ code for the XS initializer function. 1N/AWhen invoked as C<`perl -MExtUtils::Embed -e xsinit --`> 1N/Athe following options are recognized: 1N/AB<-o> E<lt>output filenameE<gt> (Defaults to B<perlxsi.c>) 1N/AB<-o STDOUT> will print to STDOUT. 1N/AB<-std> (Write code for extensions that are linked with the current Perl.) 1N/AAny additional arguments are expected to be names of modules 1N/Ato generate code for. 1N/AWhen invoked with parameters the following are accepted and optional: 1N/AC<xsinit($filename,$std,[@modules])> 1N/AB<$filename> is equivalent to the B<-o> option. 1N/AB<$std> is boolean, equivalent to the B<-std> option. 1N/AB<[@modules]> is an array ref, same as additional arguments mentioned above. 1N/A perl -MExtUtils::Embed -e xsinit -- -o xsinit.c Socket 1N/AThis will generate code with an B<xs_init> function that glues the perl B<Socket::bootstrap> function 1N/Ato the C B<boot_Socket> function and writes it to a file named F<xsinit.c>. 1N/ANote that B<DynaLoader> is a special case where it must call B<boot_DynaLoader> directly. 1N/A perl -MExtUtils::Embed -e xsinit 1N/AThis will generate code for linking with B<DynaLoader> and 1N/Aeach static extension found in B<$Config{static_ext}>. 1N/AThe code is written to the default file name B<perlxsi.c>. 1N/A perl -MExtUtils::Embed -e xsinit -- -o xsinit.c -std DBI DBD::Oracle 1N/AHere, code is written for all the currently linked extensions along with code 1N/Afor B<DBI> and B<DBD::Oracle>. 1N/AIf you have a working B<DynaLoader> then there is rarely any need to statically link in any 1N/AOutput arguments for linking the Perl library and extensions to your 1N/AWhen invoked as C<`perl -MExtUtils::Embed -e ldopts --`> 1N/Athe following options are recognized: 1N/AOutput arguments for linking the Perl library and any extensions linked 1N/Awith the current Perl. 1N/AB<-I> E<lt>path1:path2E<gt> 1N/ASearch path for ModuleName.a archives. 1N/ADefault path is B<@INC>. 1N/ALibrary archives are expected to be found as 1N/AFor example, when looking for B<Socket.a> relative to a search path, 1N/AWhen looking for B<DBD::Oracle> relative to a search path, 1N/Aas an additional linker argument. 1N/AB<--> E<lt>list of linker argsE<gt> 1N/AAdditional linker arguments to be considered. 1N/AAny additional arguments found before the B<--> token 1N/Aare expected to be names of modules to generate code for. 1N/AWhen invoked with parameters the following are accepted and optional: 1N/AC<ldopts($std,[@modules],[@link_args],$path)> 1N/AB<$std> is boolean, equivalent to the B<-std> option. 1N/AB<[@modules]> is equivalent to additional arguments found before the B<--> token. 1N/AB<[@link_args]> is equivalent to arguments found after the B<--> token. 1N/AB<$path> is equivalent to the B<-I> option. 1N/AIn addition, when ldopts is called with parameters, it will return the argument string 1N/Arather than print it to STDOUT. 1N/A perl -MExtUtils::Embed -e ldopts 1N/AThis will print arguments for linking with B<libperl.a>, B<DynaLoader> and 1N/Aextensions found in B<$Config{static_ext}>. This includes libraries 1N/Afound in B<$Config{libs}> and the first ModuleName.a library 1N/Afor each extension that is found by searching B<@INC> or the path 1N/Aspecified by the B<-I> option. 1N/AIn addition, when ModuleName.a is found, additional linker arguments 1N/Aare picked up from the B<extralibs.ld> file in the same directory. 1N/A perl -MExtUtils::Embed -e ldopts -- -std Socket 1N/AThis will do the same as the above example, along with printing additional arguments for linking with the B<Socket> extension. 1N/A perl -MExtUtils::Embed -e ldopts -- DynaLoader 1N/AThis will print arguments for linking with just the B<DynaLoader> extension 1N/A perl -MExtUtils::Embed -e ldopts -- -std Msql -- -L/usr/msql/lib -lmsql 1N/AAny arguments after the second '--' token are additional linker 1N/Aarguments that will be examined for potential conflict. If there is no 1N/Aconflict, the additional arguments will be part of the output. 1N/AFor including perl header files this function simply prints: 1N/A -I$Config{archlibexp}/CORE 1N/ASo, rather than having to say: 1N/A perl -MConfig -e 'print "-I$Config{archlibexp}/CORE"' 1N/A perl -MExtUtils::Embed -e perl_inc 1N/A=item ccflags(), ccdlflags() 1N/AThese functions simply print $Config{ccflags} and $Config{ccdlflags} 1N/AThis function combines perl_inc(), ccflags() and ccdlflags() into one. 1N/AThis function simply returns a string defining the same B<EXTERN_C> macro as 1N/AB<perlmain.c> along with #including B<perl.h> and B<EXTERN.h>. 1N/A=item xsi_protos(@modules) 1N/AThis function returns a string of B<boot_$ModuleName> prototypes for each @modules. 1N/A=item xsi_body(@modules) 1N/AThis function returns a string of calls to B<newXS()> that glue the module B<bootstrap> 1N/Afunction to B<boot_ModuleName> for each @modules. 1N/AB<xsinit()> uses the xsi_* functions to generate most of its code. 1N/AFor examples on how to use B<ExtUtils::Embed> for building C/C++ applications 1N/Awith embedded perl, see L<perlembed>. 1N/ADoug MacEachern E<lt>F<dougm@osf.org>E<gt> 1N/ABased on ideas from Tim Bunce E<lt>F<Tim.Bunce@ig.co.uk>E<gt> and 1N/AB<minimod.pl> by Andreas Koenig E<lt>F<k@anna.in-berlin.de>E<gt> and Tim Bunce.