1*0Sstevel@tonic-gate# $Id: Embed.pm,v 1.1.1.1 2002/01/16 19:27:19 schwern Exp $ 2*0Sstevel@tonic-gaterequire 5.002; 3*0Sstevel@tonic-gate 4*0Sstevel@tonic-gatepackage ExtUtils::Embed; 5*0Sstevel@tonic-gaterequire Exporter; 6*0Sstevel@tonic-gaterequire FileHandle; 7*0Sstevel@tonic-gateuse Config; 8*0Sstevel@tonic-gateuse Getopt::Std; 9*0Sstevel@tonic-gateuse File::Spec; 10*0Sstevel@tonic-gate 11*0Sstevel@tonic-gate#Only when we need them 12*0Sstevel@tonic-gate#require ExtUtils::MakeMaker; 13*0Sstevel@tonic-gate#require ExtUtils::Liblist; 14*0Sstevel@tonic-gate 15*0Sstevel@tonic-gateuse vars qw(@ISA @EXPORT $VERSION 16*0Sstevel@tonic-gate @Extensions $Verbose $lib_ext 17*0Sstevel@tonic-gate $opt_o $opt_s 18*0Sstevel@tonic-gate ); 19*0Sstevel@tonic-gateuse strict; 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gate$VERSION = 1.2506_01; 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gate@ISA = qw(Exporter); 24*0Sstevel@tonic-gate@EXPORT = qw(&xsinit &ldopts 25*0Sstevel@tonic-gate &ccopts &ccflags &ccdlflags &perl_inc 26*0Sstevel@tonic-gate &xsi_header &xsi_protos &xsi_body); 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate#let's have Miniperl borrow from us instead 29*0Sstevel@tonic-gate#require ExtUtils::Miniperl; 30*0Sstevel@tonic-gate#*canon = \&ExtUtils::Miniperl::canon; 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate$Verbose = 0; 33*0Sstevel@tonic-gate$lib_ext = $Config{lib_ext} || '.a'; 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gatesub is_cmd { $0 eq '-e' } 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gatesub my_return { 38*0Sstevel@tonic-gate my $val = shift; 39*0Sstevel@tonic-gate if(is_cmd) { 40*0Sstevel@tonic-gate print $val; 41*0Sstevel@tonic-gate } 42*0Sstevel@tonic-gate else { 43*0Sstevel@tonic-gate return $val; 44*0Sstevel@tonic-gate } 45*0Sstevel@tonic-gate} 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gatesub xsinit { 48*0Sstevel@tonic-gate my($file, $std, $mods) = @_; 49*0Sstevel@tonic-gate my($fh,@mods,%seen); 50*0Sstevel@tonic-gate $file ||= "perlxsi.c"; 51*0Sstevel@tonic-gate my $xsinit_proto = "pTHX"; 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate if (@_) { 54*0Sstevel@tonic-gate @mods = @$mods if $mods; 55*0Sstevel@tonic-gate } 56*0Sstevel@tonic-gate else { 57*0Sstevel@tonic-gate getopts('o:s:'); 58*0Sstevel@tonic-gate $file = $opt_o if defined $opt_o; 59*0Sstevel@tonic-gate $std = $opt_s if defined $opt_s; 60*0Sstevel@tonic-gate @mods = @ARGV; 61*0Sstevel@tonic-gate } 62*0Sstevel@tonic-gate $std = 1 unless scalar @mods; 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate if ($file eq "STDOUT") { 65*0Sstevel@tonic-gate $fh = \*STDOUT; 66*0Sstevel@tonic-gate } 67*0Sstevel@tonic-gate else { 68*0Sstevel@tonic-gate $fh = new FileHandle "> $file"; 69*0Sstevel@tonic-gate } 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate push(@mods, static_ext()) if defined $std; 72*0Sstevel@tonic-gate @mods = grep(!$seen{$_}++, @mods); 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate print $fh &xsi_header(); 75*0Sstevel@tonic-gate print $fh "EXTERN_C void xs_init ($xsinit_proto);\n\n"; 76*0Sstevel@tonic-gate print $fh &xsi_protos(@mods); 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate print $fh "\nEXTERN_C void\nxs_init($xsinit_proto)\n{\n"; 79*0Sstevel@tonic-gate print $fh &xsi_body(@mods); 80*0Sstevel@tonic-gate print $fh "}\n"; 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate} 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gatesub xsi_header { 85*0Sstevel@tonic-gate return <<EOF; 86*0Sstevel@tonic-gate#include <EXTERN.h> 87*0Sstevel@tonic-gate#include <perl.h> 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gateEOF 90*0Sstevel@tonic-gate} 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gatesub xsi_protos { 93*0Sstevel@tonic-gate my(@exts) = @_; 94*0Sstevel@tonic-gate my(@retval,%seen); 95*0Sstevel@tonic-gate my $boot_proto = "pTHX_ CV* cv"; 96*0Sstevel@tonic-gate foreach $_ (@exts){ 97*0Sstevel@tonic-gate my($pname) = canon('/', $_); 98*0Sstevel@tonic-gate my($mname, $cname); 99*0Sstevel@tonic-gate ($mname = $pname) =~ s!/!::!g; 100*0Sstevel@tonic-gate ($cname = $pname) =~ s!/!__!g; 101*0Sstevel@tonic-gate my($ccode) = "EXTERN_C void boot_${cname} ($boot_proto);\n"; 102*0Sstevel@tonic-gate next if $seen{$ccode}++; 103*0Sstevel@tonic-gate push(@retval, $ccode); 104*0Sstevel@tonic-gate } 105*0Sstevel@tonic-gate return join '', @retval; 106*0Sstevel@tonic-gate} 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gatesub xsi_body { 109*0Sstevel@tonic-gate my(@exts) = @_; 110*0Sstevel@tonic-gate my($pname,@retval,%seen); 111*0Sstevel@tonic-gate my($dl) = canon('/','DynaLoader'); 112*0Sstevel@tonic-gate push(@retval, "\tchar *file = __FILE__;\n"); 113*0Sstevel@tonic-gate push(@retval, "\tdXSUB_SYS;\n") if $] > 5.002; 114*0Sstevel@tonic-gate push(@retval, "\n"); 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate foreach $_ (@exts){ 117*0Sstevel@tonic-gate my($pname) = canon('/', $_); 118*0Sstevel@tonic-gate my($mname, $cname, $ccode); 119*0Sstevel@tonic-gate ($mname = $pname) =~ s!/!::!g; 120*0Sstevel@tonic-gate ($cname = $pname) =~ s!/!__!g; 121*0Sstevel@tonic-gate if ($pname eq $dl){ 122*0Sstevel@tonic-gate # Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'! 123*0Sstevel@tonic-gate # boot_DynaLoader is called directly in DynaLoader.pm 124*0Sstevel@tonic-gate $ccode = "\t/* DynaLoader is a special case */\n\tnewXS(\"${mname}::boot_${cname}\", boot_${cname}, file);\n"; 125*0Sstevel@tonic-gate push(@retval, $ccode) unless $seen{$ccode}++; 126*0Sstevel@tonic-gate } else { 127*0Sstevel@tonic-gate $ccode = "\tnewXS(\"${mname}::bootstrap\", boot_${cname}, file);\n"; 128*0Sstevel@tonic-gate push(@retval, $ccode) unless $seen{$ccode}++; 129*0Sstevel@tonic-gate } 130*0Sstevel@tonic-gate } 131*0Sstevel@tonic-gate return join '', @retval; 132*0Sstevel@tonic-gate} 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gatesub static_ext { 135*0Sstevel@tonic-gate unless (scalar @Extensions) { 136*0Sstevel@tonic-gate @Extensions = sort split /\s+/, $Config{static_ext}; 137*0Sstevel@tonic-gate unshift @Extensions, qw(DynaLoader); 138*0Sstevel@tonic-gate } 139*0Sstevel@tonic-gate @Extensions; 140*0Sstevel@tonic-gate} 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gatesub _escape { 143*0Sstevel@tonic-gate my $arg = shift; 144*0Sstevel@tonic-gate $$arg =~ s/([\(\)])/\\$1/g; 145*0Sstevel@tonic-gate} 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gatesub _ldflags { 148*0Sstevel@tonic-gate my $ldflags = $Config{ldflags}; 149*0Sstevel@tonic-gate _escape(\$ldflags); 150*0Sstevel@tonic-gate return $ldflags; 151*0Sstevel@tonic-gate} 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gatesub _ccflags { 154*0Sstevel@tonic-gate my $ccflags = $Config{ccflags}; 155*0Sstevel@tonic-gate _escape(\$ccflags); 156*0Sstevel@tonic-gate return $ccflags; 157*0Sstevel@tonic-gate} 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gatesub _ccdlflags { 160*0Sstevel@tonic-gate my $ccdlflags = $Config{ccdlflags}; 161*0Sstevel@tonic-gate _escape(\$ccdlflags); 162*0Sstevel@tonic-gate return $ccdlflags; 163*0Sstevel@tonic-gate} 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gatesub ldopts { 166*0Sstevel@tonic-gate require ExtUtils::MakeMaker; 167*0Sstevel@tonic-gate require ExtUtils::Liblist; 168*0Sstevel@tonic-gate my($std,$mods,$link_args,$path) = @_; 169*0Sstevel@tonic-gate my(@mods,@link_args,@argv); 170*0Sstevel@tonic-gate my($dllib,$config_libs,@potential_libs,@path); 171*0Sstevel@tonic-gate local($") = ' ' unless $" eq ' '; 172*0Sstevel@tonic-gate if (scalar @_) { 173*0Sstevel@tonic-gate @link_args = @$link_args if $link_args; 174*0Sstevel@tonic-gate @mods = @$mods if $mods; 175*0Sstevel@tonic-gate } 176*0Sstevel@tonic-gate else { 177*0Sstevel@tonic-gate @argv = @ARGV; 178*0Sstevel@tonic-gate #hmm 179*0Sstevel@tonic-gate while($_ = shift @argv) { 180*0Sstevel@tonic-gate /^-std$/ && do { $std = 1; next; }; 181*0Sstevel@tonic-gate /^--$/ && do { @link_args = @argv; last; }; 182*0Sstevel@tonic-gate /^-I(.*)/ && do { $path = $1 || shift @argv; next; }; 183*0Sstevel@tonic-gate push(@mods, $_); 184*0Sstevel@tonic-gate } 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate $std = 1 unless scalar @link_args; 187*0Sstevel@tonic-gate my $sep = $Config{path_sep} || ':'; 188*0Sstevel@tonic-gate @path = $path ? split(/\Q$sep/, $path) : @INC; 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate push(@potential_libs, @link_args) if scalar @link_args; 191*0Sstevel@tonic-gate # makemaker includes std libs on windows by default 192*0Sstevel@tonic-gate if ($^O ne 'MSWin32' and defined($std)) { 193*0Sstevel@tonic-gate push(@potential_libs, $Config{perllibs}); 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate push(@mods, static_ext()) if $std; 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate my($mod,@ns,$root,$sub,$extra,$archive,@archives); 199*0Sstevel@tonic-gate print STDERR "Searching (@path) for archives\n" if $Verbose; 200*0Sstevel@tonic-gate foreach $mod (@mods) { 201*0Sstevel@tonic-gate @ns = split(/::|\/|\\/, $mod); 202*0Sstevel@tonic-gate $sub = $ns[-1]; 203*0Sstevel@tonic-gate $root = File::Spec->catdir(@ns); 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate print STDERR "searching for '$sub${lib_ext}'\n" if $Verbose; 206*0Sstevel@tonic-gate foreach (@path) { 207*0Sstevel@tonic-gate next unless -e ($archive = File::Spec->catdir($_,"auto",$root,"$sub$lib_ext")); 208*0Sstevel@tonic-gate push @archives, $archive; 209*0Sstevel@tonic-gate if(-e ($extra = File::Spec->catdir($_,"auto",$root,"extralibs.ld"))) { 210*0Sstevel@tonic-gate local(*FH); 211*0Sstevel@tonic-gate if(open(FH, $extra)) { 212*0Sstevel@tonic-gate my($libs) = <FH>; chomp $libs; 213*0Sstevel@tonic-gate push @potential_libs, split /\s+/, $libs; 214*0Sstevel@tonic-gate } 215*0Sstevel@tonic-gate else { 216*0Sstevel@tonic-gate warn "Couldn't open '$extra'"; 217*0Sstevel@tonic-gate } 218*0Sstevel@tonic-gate } 219*0Sstevel@tonic-gate last; 220*0Sstevel@tonic-gate } 221*0Sstevel@tonic-gate } 222*0Sstevel@tonic-gate #print STDERR "\@potential_libs = @potential_libs\n"; 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate my $libperl; 225*0Sstevel@tonic-gate if ($^O eq 'MSWin32') { 226*0Sstevel@tonic-gate $libperl = $Config{libperl}; 227*0Sstevel@tonic-gate } 228*0Sstevel@tonic-gate else { 229*0Sstevel@tonic-gate $libperl = (grep(/^-l\w*perl\w*$/, @link_args))[0] || "-lperl"; 230*0Sstevel@tonic-gate } 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate my $lpath = File::Spec->catdir($Config{archlibexp}, 'CORE'); 233*0Sstevel@tonic-gate $lpath = qq["$lpath"] if $^O eq 'MSWin32'; 234*0Sstevel@tonic-gate my($extralibs, $bsloadlibs, $ldloadlibs, $ld_run_path) = 235*0Sstevel@tonic-gate MM->ext(join ' ', "-L$lpath", $libperl, @potential_libs); 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate my $ld_or_bs = $bsloadlibs || $ldloadlibs; 238*0Sstevel@tonic-gate print STDERR "bs: $bsloadlibs ** ld: $ldloadlibs" if $Verbose; 239*0Sstevel@tonic-gate my $ccdlflags = _ccdlflags(); 240*0Sstevel@tonic-gate my $ldflags = _ldflags(); 241*0Sstevel@tonic-gate my $linkage = "$ccdlflags $ldflags @archives $ld_or_bs"; 242*0Sstevel@tonic-gate print STDERR "ldopts: '$linkage'\n" if $Verbose; 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gate return $linkage if scalar @_; 245*0Sstevel@tonic-gate my_return("$linkage\n"); 246*0Sstevel@tonic-gate} 247*0Sstevel@tonic-gate 248*0Sstevel@tonic-gatesub ccflags { 249*0Sstevel@tonic-gate my $ccflags = _ccflags(); 250*0Sstevel@tonic-gate my_return(" $ccflags "); 251*0Sstevel@tonic-gate} 252*0Sstevel@tonic-gate 253*0Sstevel@tonic-gatesub ccdlflags { 254*0Sstevel@tonic-gate my $ccdlflags = _ccdlflags(); 255*0Sstevel@tonic-gate my_return(" $ccdlflags "); 256*0Sstevel@tonic-gate} 257*0Sstevel@tonic-gate 258*0Sstevel@tonic-gatesub perl_inc { 259*0Sstevel@tonic-gate my $dir = File::Spec->catdir($Config{archlibexp}, 'CORE'); 260*0Sstevel@tonic-gate $dir = qq["$dir"] if $^O eq 'MSWin32'; 261*0Sstevel@tonic-gate my_return(" -I$dir "); 262*0Sstevel@tonic-gate} 263*0Sstevel@tonic-gate 264*0Sstevel@tonic-gatesub ccopts { 265*0Sstevel@tonic-gate ccflags . perl_inc; 266*0Sstevel@tonic-gate} 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gatesub canon { 269*0Sstevel@tonic-gate my($as, @ext) = @_; 270*0Sstevel@tonic-gate foreach(@ext) { 271*0Sstevel@tonic-gate # might be X::Y or lib/auto/X/Y/Y.a 272*0Sstevel@tonic-gate next if s!::!/!g; 273*0Sstevel@tonic-gate s:^(lib|ext)/(auto/)?::; 274*0Sstevel@tonic-gate s:/\w+\.\w+$::; 275*0Sstevel@tonic-gate } 276*0Sstevel@tonic-gate grep(s:/:$as:, @ext) if ($as ne '/'); 277*0Sstevel@tonic-gate @ext; 278*0Sstevel@tonic-gate} 279*0Sstevel@tonic-gate 280*0Sstevel@tonic-gate__END__ 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gate=head1 NAME 283*0Sstevel@tonic-gate 284*0Sstevel@tonic-gateExtUtils::Embed - Utilities for embedding Perl in C/C++ applications 285*0Sstevel@tonic-gate 286*0Sstevel@tonic-gate=head1 SYNOPSIS 287*0Sstevel@tonic-gate 288*0Sstevel@tonic-gate 289*0Sstevel@tonic-gate perl -MExtUtils::Embed -e xsinit 290*0Sstevel@tonic-gate perl -MExtUtils::Embed -e ccopts 291*0Sstevel@tonic-gate perl -MExtUtils::Embed -e ldopts 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gate=head1 DESCRIPTION 294*0Sstevel@tonic-gate 295*0Sstevel@tonic-gateExtUtils::Embed provides utility functions for embedding a Perl interpreter 296*0Sstevel@tonic-gateand extensions in your C/C++ applications. 297*0Sstevel@tonic-gateTypically, an application B<Makefile> will invoke ExtUtils::Embed 298*0Sstevel@tonic-gatefunctions while building your application. 299*0Sstevel@tonic-gate 300*0Sstevel@tonic-gate=head1 @EXPORT 301*0Sstevel@tonic-gate 302*0Sstevel@tonic-gateExtUtils::Embed exports the following functions: 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gatexsinit(), ldopts(), ccopts(), perl_inc(), ccflags(), 305*0Sstevel@tonic-gateccdlflags(), xsi_header(), xsi_protos(), xsi_body() 306*0Sstevel@tonic-gate 307*0Sstevel@tonic-gate=head1 FUNCTIONS 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gate=over 4 310*0Sstevel@tonic-gate 311*0Sstevel@tonic-gate=item xsinit() 312*0Sstevel@tonic-gate 313*0Sstevel@tonic-gateGenerate C/C++ code for the XS initializer function. 314*0Sstevel@tonic-gate 315*0Sstevel@tonic-gateWhen invoked as C<`perl -MExtUtils::Embed -e xsinit --`> 316*0Sstevel@tonic-gatethe following options are recognized: 317*0Sstevel@tonic-gate 318*0Sstevel@tonic-gateB<-o> E<lt>output filenameE<gt> (Defaults to B<perlxsi.c>) 319*0Sstevel@tonic-gate 320*0Sstevel@tonic-gateB<-o STDOUT> will print to STDOUT. 321*0Sstevel@tonic-gate 322*0Sstevel@tonic-gateB<-std> (Write code for extensions that are linked with the current Perl.) 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gateAny additional arguments are expected to be names of modules 325*0Sstevel@tonic-gateto generate code for. 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gateWhen invoked with parameters the following are accepted and optional: 328*0Sstevel@tonic-gate 329*0Sstevel@tonic-gateC<xsinit($filename,$std,[@modules])> 330*0Sstevel@tonic-gate 331*0Sstevel@tonic-gateWhere, 332*0Sstevel@tonic-gate 333*0Sstevel@tonic-gateB<$filename> is equivalent to the B<-o> option. 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gateB<$std> is boolean, equivalent to the B<-std> option. 336*0Sstevel@tonic-gate 337*0Sstevel@tonic-gateB<[@modules]> is an array ref, same as additional arguments mentioned above. 338*0Sstevel@tonic-gate 339*0Sstevel@tonic-gate=item Examples 340*0Sstevel@tonic-gate 341*0Sstevel@tonic-gate 342*0Sstevel@tonic-gate perl -MExtUtils::Embed -e xsinit -- -o xsinit.c Socket 343*0Sstevel@tonic-gate 344*0Sstevel@tonic-gate 345*0Sstevel@tonic-gateThis will generate code with an B<xs_init> function that glues the perl B<Socket::bootstrap> function 346*0Sstevel@tonic-gateto the C B<boot_Socket> function and writes it to a file named F<xsinit.c>. 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gateNote that B<DynaLoader> is a special case where it must call B<boot_DynaLoader> directly. 349*0Sstevel@tonic-gate 350*0Sstevel@tonic-gate perl -MExtUtils::Embed -e xsinit 351*0Sstevel@tonic-gate 352*0Sstevel@tonic-gate 353*0Sstevel@tonic-gateThis will generate code for linking with B<DynaLoader> and 354*0Sstevel@tonic-gateeach static extension found in B<$Config{static_ext}>. 355*0Sstevel@tonic-gateThe code is written to the default file name B<perlxsi.c>. 356*0Sstevel@tonic-gate 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate perl -MExtUtils::Embed -e xsinit -- -o xsinit.c -std DBI DBD::Oracle 359*0Sstevel@tonic-gate 360*0Sstevel@tonic-gate 361*0Sstevel@tonic-gateHere, code is written for all the currently linked extensions along with code 362*0Sstevel@tonic-gatefor B<DBI> and B<DBD::Oracle>. 363*0Sstevel@tonic-gate 364*0Sstevel@tonic-gateIf you have a working B<DynaLoader> then there is rarely any need to statically link in any 365*0Sstevel@tonic-gateother extensions. 366*0Sstevel@tonic-gate 367*0Sstevel@tonic-gate=item ldopts() 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gateOutput arguments for linking the Perl library and extensions to your 370*0Sstevel@tonic-gateapplication. 371*0Sstevel@tonic-gate 372*0Sstevel@tonic-gateWhen invoked as C<`perl -MExtUtils::Embed -e ldopts --`> 373*0Sstevel@tonic-gatethe following options are recognized: 374*0Sstevel@tonic-gate 375*0Sstevel@tonic-gateB<-std> 376*0Sstevel@tonic-gate 377*0Sstevel@tonic-gateOutput arguments for linking the Perl library and any extensions linked 378*0Sstevel@tonic-gatewith the current Perl. 379*0Sstevel@tonic-gate 380*0Sstevel@tonic-gateB<-I> E<lt>path1:path2E<gt> 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gateSearch path for ModuleName.a archives. 383*0Sstevel@tonic-gateDefault path is B<@INC>. 384*0Sstevel@tonic-gateLibrary archives are expected to be found as 385*0Sstevel@tonic-gateB</some/path/auto/ModuleName/ModuleName.a> 386*0Sstevel@tonic-gateFor example, when looking for B<Socket.a> relative to a search path, 387*0Sstevel@tonic-gatewe should find B<auto/Socket/Socket.a> 388*0Sstevel@tonic-gate 389*0Sstevel@tonic-gateWhen looking for B<DBD::Oracle> relative to a search path, 390*0Sstevel@tonic-gatewe should find B<auto/DBD/Oracle/Oracle.a> 391*0Sstevel@tonic-gate 392*0Sstevel@tonic-gateKeep in mind that you can always supply B</my/own/path/ModuleName.a> 393*0Sstevel@tonic-gateas an additional linker argument. 394*0Sstevel@tonic-gate 395*0Sstevel@tonic-gateB<--> E<lt>list of linker argsE<gt> 396*0Sstevel@tonic-gate 397*0Sstevel@tonic-gateAdditional linker arguments to be considered. 398*0Sstevel@tonic-gate 399*0Sstevel@tonic-gateAny additional arguments found before the B<--> token 400*0Sstevel@tonic-gateare expected to be names of modules to generate code for. 401*0Sstevel@tonic-gate 402*0Sstevel@tonic-gateWhen invoked with parameters the following are accepted and optional: 403*0Sstevel@tonic-gate 404*0Sstevel@tonic-gateC<ldopts($std,[@modules],[@link_args],$path)> 405*0Sstevel@tonic-gate 406*0Sstevel@tonic-gateWhere: 407*0Sstevel@tonic-gate 408*0Sstevel@tonic-gateB<$std> is boolean, equivalent to the B<-std> option. 409*0Sstevel@tonic-gate 410*0Sstevel@tonic-gateB<[@modules]> is equivalent to additional arguments found before the B<--> token. 411*0Sstevel@tonic-gate 412*0Sstevel@tonic-gateB<[@link_args]> is equivalent to arguments found after the B<--> token. 413*0Sstevel@tonic-gate 414*0Sstevel@tonic-gateB<$path> is equivalent to the B<-I> option. 415*0Sstevel@tonic-gate 416*0Sstevel@tonic-gateIn addition, when ldopts is called with parameters, it will return the argument string 417*0Sstevel@tonic-gaterather than print it to STDOUT. 418*0Sstevel@tonic-gate 419*0Sstevel@tonic-gate=item Examples 420*0Sstevel@tonic-gate 421*0Sstevel@tonic-gate 422*0Sstevel@tonic-gate perl -MExtUtils::Embed -e ldopts 423*0Sstevel@tonic-gate 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gateThis will print arguments for linking with B<libperl.a>, B<DynaLoader> and 426*0Sstevel@tonic-gateextensions found in B<$Config{static_ext}>. This includes libraries 427*0Sstevel@tonic-gatefound in B<$Config{libs}> and the first ModuleName.a library 428*0Sstevel@tonic-gatefor each extension that is found by searching B<@INC> or the path 429*0Sstevel@tonic-gatespecified by the B<-I> option. 430*0Sstevel@tonic-gateIn addition, when ModuleName.a is found, additional linker arguments 431*0Sstevel@tonic-gateare picked up from the B<extralibs.ld> file in the same directory. 432*0Sstevel@tonic-gate 433*0Sstevel@tonic-gate 434*0Sstevel@tonic-gate perl -MExtUtils::Embed -e ldopts -- -std Socket 435*0Sstevel@tonic-gate 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gateThis will do the same as the above example, along with printing additional arguments for linking with the B<Socket> extension. 438*0Sstevel@tonic-gate 439*0Sstevel@tonic-gate 440*0Sstevel@tonic-gate perl -MExtUtils::Embed -e ldopts -- DynaLoader 441*0Sstevel@tonic-gate 442*0Sstevel@tonic-gate 443*0Sstevel@tonic-gateThis will print arguments for linking with just the B<DynaLoader> extension 444*0Sstevel@tonic-gateand B<libperl.a>. 445*0Sstevel@tonic-gate 446*0Sstevel@tonic-gate 447*0Sstevel@tonic-gate perl -MExtUtils::Embed -e ldopts -- -std Msql -- -L/usr/msql/lib -lmsql 448*0Sstevel@tonic-gate 449*0Sstevel@tonic-gate 450*0Sstevel@tonic-gateAny arguments after the second '--' token are additional linker 451*0Sstevel@tonic-gatearguments that will be examined for potential conflict. If there is no 452*0Sstevel@tonic-gateconflict, the additional arguments will be part of the output. 453*0Sstevel@tonic-gate 454*0Sstevel@tonic-gate 455*0Sstevel@tonic-gate=item perl_inc() 456*0Sstevel@tonic-gate 457*0Sstevel@tonic-gateFor including perl header files this function simply prints: 458*0Sstevel@tonic-gate 459*0Sstevel@tonic-gate -I$Config{archlibexp}/CORE 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gateSo, rather than having to say: 462*0Sstevel@tonic-gate 463*0Sstevel@tonic-gate perl -MConfig -e 'print "-I$Config{archlibexp}/CORE"' 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gateJust say: 466*0Sstevel@tonic-gate 467*0Sstevel@tonic-gate perl -MExtUtils::Embed -e perl_inc 468*0Sstevel@tonic-gate 469*0Sstevel@tonic-gate=item ccflags(), ccdlflags() 470*0Sstevel@tonic-gate 471*0Sstevel@tonic-gateThese functions simply print $Config{ccflags} and $Config{ccdlflags} 472*0Sstevel@tonic-gate 473*0Sstevel@tonic-gate=item ccopts() 474*0Sstevel@tonic-gate 475*0Sstevel@tonic-gateThis function combines perl_inc(), ccflags() and ccdlflags() into one. 476*0Sstevel@tonic-gate 477*0Sstevel@tonic-gate=item xsi_header() 478*0Sstevel@tonic-gate 479*0Sstevel@tonic-gateThis function simply returns a string defining the same B<EXTERN_C> macro as 480*0Sstevel@tonic-gateB<perlmain.c> along with #including B<perl.h> and B<EXTERN.h>. 481*0Sstevel@tonic-gate 482*0Sstevel@tonic-gate=item xsi_protos(@modules) 483*0Sstevel@tonic-gate 484*0Sstevel@tonic-gateThis function returns a string of B<boot_$ModuleName> prototypes for each @modules. 485*0Sstevel@tonic-gate 486*0Sstevel@tonic-gate=item xsi_body(@modules) 487*0Sstevel@tonic-gate 488*0Sstevel@tonic-gateThis function returns a string of calls to B<newXS()> that glue the module B<bootstrap> 489*0Sstevel@tonic-gatefunction to B<boot_ModuleName> for each @modules. 490*0Sstevel@tonic-gate 491*0Sstevel@tonic-gateB<xsinit()> uses the xsi_* functions to generate most of its code. 492*0Sstevel@tonic-gate 493*0Sstevel@tonic-gate=back 494*0Sstevel@tonic-gate 495*0Sstevel@tonic-gate=head1 EXAMPLES 496*0Sstevel@tonic-gate 497*0Sstevel@tonic-gateFor examples on how to use B<ExtUtils::Embed> for building C/C++ applications 498*0Sstevel@tonic-gatewith embedded perl, see L<perlembed>. 499*0Sstevel@tonic-gate 500*0Sstevel@tonic-gate=head1 SEE ALSO 501*0Sstevel@tonic-gate 502*0Sstevel@tonic-gateL<perlembed> 503*0Sstevel@tonic-gate 504*0Sstevel@tonic-gate=head1 AUTHOR 505*0Sstevel@tonic-gate 506*0Sstevel@tonic-gateDoug MacEachern E<lt>F<dougm@osf.org>E<gt> 507*0Sstevel@tonic-gate 508*0Sstevel@tonic-gateBased on ideas from Tim Bunce E<lt>F<Tim.Bunce@ig.co.uk>E<gt> and 509*0Sstevel@tonic-gateB<minimod.pl> by Andreas Koenig E<lt>F<k@anna.in-berlin.de>E<gt> and Tim Bunce. 510*0Sstevel@tonic-gate 511*0Sstevel@tonic-gate=cut 512*0Sstevel@tonic-gate 513