perlcc.PL 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. #! perl
  2. use Config;
  3. use File::Basename qw(&basename &dirname);
  4. use File::Spec;
  5. use Cwd;
  6. # List explicitly here the variables you want Configure to
  7. # generate. Metaconfig only looks for shell variables, so you
  8. # have to mention them as if they were shell variables, not
  9. # %Config entries. Thus you write
  10. # $startperl
  11. # to ensure Configure will look for $Config{startperl}.
  12. # Wanted: $archlibexp
  13. # This forces PL files to create target in same directory as PL file.
  14. # This is so that make depend always knows where to find PL derivatives.
  15. $origdir = cwd;
  16. chdir dirname($0);
  17. $file = basename($0, '.PL');
  18. $file .= '.com' if $^O eq 'VMS';
  19. open OUT,">$file" or die "Can't create $file: $!";
  20. print "Extracting $file (with variable substitutions)\n";
  21. # In this section, perl variables will be expanded during extraction.
  22. # You can use $Config{...} to use Configure variables.
  23. print OUT <<"!GROK!THIS!";
  24. $Config{startperl}
  25. eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
  26. if \$running_under_some_shell;
  27. --\$running_under_some_shell;
  28. !GROK!THIS!
  29. # In the following, perl variables are not expanded during extraction.
  30. print OUT <<'!NO!SUBS!';
  31. # Version 2.0, Simon Cozens, Thu Mar 30 17:52:45 JST 2000
  32. # Version 2.01, Tom Christiansen, Thu Mar 30 08:25:14 MST 2000
  33. # Version 2.02, Simon Cozens, Sun Apr 16 01:53:36 JST 2000
  34. # Version 2.03, Edward Peschko, Mon Feb 26 12:04:17 PST 2001
  35. # Version 2.04, Enache Adrian, Fri, 18 Jul 2003 23:15:37 +0300
  36. # Version 2.05, Reini Urban, 2009-12-01 00:00:13
  37. # Version 2.06, Reini Urban, 2009-12-28 21:56:15
  38. # Version 2.07, Reini Urban, 2010-06-30 22:32:20
  39. # Version 2.08, Reini Urban, 2010-07-30 21:30:33
  40. # Version 2.09, Reini Urban, 2010-10-11 13:54:52
  41. # Version 2.10, Reini Urban, 2011-02-11 22:58:37
  42. # Version 2.11, Reini Urban, 2011-04-11 20:16:00
  43. # Version 2.12, Reini Urban, 2011-10-02 05:19:00
  44. # Version 2.13, Reini Urban, 2012-01-10 13:03:00
  45. # Version 2.14, Reini Urban, 2012-02-28 09:04:07
  46. # Version 2.15, Reini Urban, 2013-02-01 10:41:54
  47. # Version 2.16, Reini Urban, 2013-11-27 11:36:13
  48. # Version 2.17, Reini Urban, Thu Feb 6 14:04:29 2014 -0600
  49. # Version 2.18, Reini Urban, 2014-05-28
  50. # Version 2.19, Reini Urban, 2014-07-09
  51. # Version 2.20, Reini Urban, 2014-07-23
  52. use strict;
  53. use warnings;
  54. use 5.006_000;
  55. use FileHandle;
  56. use Config;
  57. use Fcntl qw(:DEFAULT :flock);
  58. use File::Temp qw(tempfile);
  59. use File::Basename qw(basename dirname);
  60. # use Cwd;
  61. use Pod::Usage;
  62. # Time::HiRes does not work with 5.6
  63. # use Time::HiRes qw(gettimeofday tv_interval);
  64. our $VERSION = 2.20;
  65. $| = 1;
  66. eval { require B::C::Flags; };
  67. $SIG{INT} = sub { exit(); } if exists $SIG{INT}; # exit gracefully and clean up after ourselves.
  68. use subs qw{
  69. cc_harness check_read check_write checkopts_byte choose_backend
  70. compile_byte compile_cstyle compile_module generate_code
  71. grab_stash parse_argv sanity_check vprint yclept spawnit
  72. gettimeofday tv_interval vsystem
  73. };
  74. sub opt(*); # imal quoting
  75. sub is_win32();
  76. sub is_msvc();
  77. our ($Options, $BinPerl, $Backend);
  78. our ($Input => $Output);
  79. our ($logfh);
  80. our ($cfile);
  81. our (@begin_output); # output from BEGIN {}, for testsuite
  82. our ($extra_libs);
  83. # eval { main(); 1 } or die;
  84. main();
  85. sub main {
  86. parse_argv();
  87. check_write($Output);
  88. choose_backend();
  89. generate_code();
  90. run_code();
  91. _die("Not reached?");
  92. }
  93. #######################################################################
  94. sub choose_backend {
  95. # Choose the backend.
  96. $Backend = 'C';
  97. if (opt('B')) {
  98. checkopts_byte();
  99. $Backend = 'Bytecode';
  100. }
  101. if (opt('S') && opt('c')) {
  102. # die "$0: Do you want me to compile this or not?\n";
  103. delete $Options->{S};
  104. }
  105. $Backend = 'CC' if opt('O');
  106. }
  107. sub generate_code {
  108. vprint 4, "Compiling $Input";
  109. $BinPerl = yclept(); # Calling convention for perl.
  110. if (exists $Options->{m}) {
  111. compile_module();
  112. } else {
  113. if ($Backend eq 'Bytecode') {
  114. compile_byte();
  115. } else {
  116. compile_cstyle();
  117. }
  118. }
  119. exit(0) if (!opt('r'));
  120. }
  121. sub run_code {
  122. if ($Backend eq 'Bytecode') {
  123. if ($] < 5.007) {
  124. $Output = "$BinPerl -MByteLoader $Output";
  125. } else {
  126. $Output = "$BinPerl $Output";
  127. }
  128. }
  129. if (opt('staticxs') and $extra_libs) {
  130. my $path = '';
  131. my $PATHSEP = $^O eq 'MSWin32' ? ';' : ':';
  132. for (split / /, $extra_libs) {
  133. s{/[^/]+$}{};
  134. # XXX qx quote?
  135. $path .= $PATHSEP.$_ if $_;
  136. }
  137. if ($^O =~ /^MSWin32|msys|cygwin$/) {
  138. $ENV{PATH} .= $path;
  139. vprint 0, "PATH=\$PATH$path";
  140. } elsif ($^O ne 'darwin') {
  141. $ENV{LD_LIBRARY_PATH} .= $path;
  142. vprint 0, "LD_LIBRARY_PATH=\$LD_LIBRARY_PATH$path";
  143. }
  144. }
  145. vprint 0, "Running code $Output @ARGV";
  146. system(join(" ",$Output,@ARGV));
  147. exit(0);
  148. }
  149. # usage: vprint [level] msg args
  150. sub vprint {
  151. my $level;
  152. if (@_ == 1) {
  153. $level = 1;
  154. } elsif ($_[0] =~ /^-?\d$/) {
  155. $level = shift;
  156. } else {
  157. # well, they forgot to use a number; means >0
  158. $level = 0;
  159. }
  160. my $msg = "@_";
  161. $msg .= "\n" unless substr($msg, -1) eq "\n";
  162. if (opt('v') > $level)
  163. {
  164. if (opt('log')) {
  165. print $logfh "$0: $msg" ;
  166. } else {
  167. print "$0: $msg";
  168. }
  169. }
  170. }
  171. sub vsystem {
  172. if (opt('dryrun')) {
  173. print "@_\n";
  174. } else {
  175. system(@_);
  176. }
  177. }
  178. sub parse_argv {
  179. use Getopt::Long;
  180. # disallows using long arguments
  181. Getopt::Long::Configure("bundling");
  182. Getopt::Long::Configure("no_ignore_case");
  183. # no difference in exists and defined for %ENV; also, a "0"
  184. # argument or a "" would not help cc, so skip
  185. unshift @ARGV, split ' ', $ENV{PERLCC_OPTS} if $ENV{PERLCC_OPTS};
  186. $Options = {};
  187. # support single dash -Wb. GetOptions requires --Wb with bundling enabled.
  188. if (my ($wb) = grep /^-Wb=.+/, @ARGV) {
  189. $Options->{Wb} = $Options->{Wb} ? $Options->{Wb}.",".substr($wb,4) : substr($wb,4);
  190. @ARGV = grep !/^-Wb=(.+)/, @ARGV;
  191. }
  192. # -O2 i.e. -Wb=-O1 (new since 2.13)
  193. if (my ($o1) = grep /^-O(\d)$/, @ARGV) {
  194. $Options->{Wb} = $Options->{Wb} ? $Options->{Wb}.",$o1" : $o1;
  195. @ARGV = grep !/^-O\d$/, @ARGV;
  196. }
  197. if (my ($v) = grep /^-v\d$/, @ARGV) {
  198. $Options->{v} = 0+substr($v,2);
  199. @ARGV = grep !/^-v\d$/, @ARGV;
  200. }
  201. if (grep /^-stash$/, @ARGV) {
  202. $Options->{stash}++;
  203. @ARGV = grep !/^-stash$/, @ARGV;
  204. }
  205. $Options->{spawn} = 1 unless $^O eq 'MSWin32';
  206. Getopt::Long::GetOptions( $Options,
  207. 'L=s', # lib directory
  208. 'I=s', # include directories (FOR C, NOT FOR PERL)
  209. 'o=s', # Output executable
  210. 'v:i', # Verbosity level
  211. 'e=s', # One-liner
  212. 'm|sharedlib:s',# as Module [name] (new since 2.11, not yet tested)
  213. 'r', # run resulting executable
  214. 'B', # Byte compiler backend
  215. 'O', # Optimised C backend B::CC
  216. #'O1-4' # alias for -Wb=-O1 (new since 2.13)
  217. 'dryrun|n', # only print commands, do not execute
  218. 'c', # Compile to C only, no linking
  219. 'check', # pass -c to B::C and exit
  220. 'help|h', # Help me
  221. 'S', # Keep generated C file
  222. 'T', # run the backend using perl -T
  223. 't', # run the backend using perl -t
  224. 'A', # -DALLOW_PERL_OPTIONS like -D?
  225. 'u=s@', # use packages (new since 2.13)
  226. 'U=s@', # skip packages (new since 2.13)
  227. 'static', # Link to static libperl (default, new since 2.11)
  228. 'shared', # Link to shared libperl (new since 2.07)
  229. 'staticxs', # Link static XSUBs (new since 2.07)
  230. 'sharedxs', # Link shared XSUBs (default, new since 2.07))
  231. 'stash', # Detect external packages via B::Stash
  232. 'log:s', # where to log compilation process information
  233. 'Wb=s', # pass (comma-seperated) options to backend
  234. 'f=s@', # pass compiler option(s) to backend (new since 2.14)
  235. 'Wc=s', # pass (comma-seperated) options to cc (new since 2.13)
  236. 'Wl=s', # pass (comma-seperated) options to ld (new since 2.13)
  237. 'testsuite', # try to be nice to testsuite modules (STDOUT, STDERR handles)
  238. 'spawn!', # --no-spawn (new since 2.12)
  239. 'time', # print benchmark timings (new since 2.08)
  240. 'version', # (new since 2.13)
  241. );
  242. $Options->{v} += 0;
  243. if( opt('t') && opt('T') ) {
  244. warn "Can't specify both -T and -t, -t ignored";
  245. $Options->{t} = 0;
  246. }
  247. helpme() if opt('help'); # And exit
  248. if (opt('version')) {
  249. die version();
  250. }
  251. # $Options->{Wb} .= ",-O1" if opt('O1');
  252. # $Options->{Wb} .= ",-O2" if opt('O2');
  253. # $Options->{Wb} .= ",-O3" if opt('O3');
  254. # $Options->{Wb} .= ",-O4" if opt('O4');
  255. $Options->{Wc} .= " -DALLOW_PERL_OPTIONS" if opt('A');
  256. if( $Options->{time} or $Options->{spawn} ) {
  257. eval { require Time::HiRes; }; # 5.6 has no Time::HiRes
  258. if ($@) {
  259. warn "--time ignored. No Time::HiRes\n" if $Options->{time};
  260. $Options->{time} = 0;
  261. } else {
  262. *gettimeofday = *Time::HiRes::gettimeofday;
  263. Time::HiRes::gettimeofday();
  264. Time::HiRes->import('gettimeofday','tv_interval','sleep');
  265. }
  266. }
  267. $logfh = new FileHandle(">> " . opt('log')) if (opt('log'));
  268. if (opt('e')) {
  269. warn "$0: using -e 'code' as input file, ignoring @ARGV\n" if @ARGV;
  270. # We don't use a temporary file here; why bother?
  271. # XXX: this is not bullet proof -- spaces or quotes in name!
  272. $Input = is_win32() ? # Quotes eaten by shell
  273. '-e "'.opt('e').'"' :
  274. "-e '".opt('e')."'";
  275. } else {
  276. $Input = shift @ARGV; # XXX: more files?
  277. _usage_and_die("No input file specified\n") unless $Input;
  278. # DWIM modules. This is bad but necessary.
  279. $Options->{m} = '' if $Input =~ /\.pm\z/ and !opt('m');
  280. vprint 1, "$0: using $Input as input file, ignoring @ARGV\n" if @ARGV;
  281. check_read($Input);
  282. check_perl($Input);
  283. }
  284. if (opt('o')) {
  285. $Output = opt('o');
  286. } elsif (opt('B')) {
  287. if (opt('e')) {
  288. my $suffix = '.plc';
  289. $suffix = '.pmc' if exists $Options->{m};
  290. (undef, $Output) = tempfile("plcXXXXX", SUFFIX => $suffix);
  291. } else {
  292. $Output = basename($Input) . "c";
  293. }
  294. } else {
  295. $Output = opt('e') ? 'a.out' : $Input;
  296. $Output =~ s/\.(p[lm]|t)$//;
  297. if (is_win32() or $^O eq 'cygwin') {
  298. if ($Output eq 'a.out') {
  299. $Output = 'a.exe';
  300. } else {
  301. $Output .= 'exe';
  302. }
  303. }
  304. }
  305. $Output = relativize($Output) unless is_win32();
  306. sanity_check();
  307. }
  308. sub opt(*) {
  309. my $opt = shift;
  310. return exists($Options->{$opt}) && ($Options->{$opt} || 0);
  311. }
  312. sub compile_module {
  313. if ($Backend eq 'Bytecode') {
  314. compile_byte('-m'.$Options->{m});
  315. } else {
  316. compile_cstyle("-m".$Options->{m});
  317. }
  318. }
  319. sub compile_byte {
  320. vprint 3, "Writing B on $Output";
  321. my $opts = $] < 5.007 ? "" : "-H,-s,";
  322. if ($] >= 5.007 and $Input =~ /^-e/) {
  323. $opts = "-H,";
  324. }
  325. if (@_ == 1) {
  326. $opts .= $_[0].",";
  327. }
  328. my $addoptions = opt('Wb');
  329. if( $addoptions ) {
  330. $opts .= '-v,' if opt('v') > 4;
  331. $opts .= '-DM,-DG,-DA,-DComment,' if opt('v') > 5;
  332. $opts .= "$addoptions,";
  333. } elsif (opt('v') > 4) {
  334. $opts .= '-v,';
  335. $opts .= '-DM,-DG,-DA,-DComment,' if opt('v') > 5;
  336. }
  337. my $command = "$BinPerl -MO=Bytecode,$opts-o$Output $Input";
  338. $Input =~ s/^-e.*$/-e/;
  339. vprint 5, "Compiling...";
  340. vprint 0, "Calling $command";
  341. my $t0 = [gettimeofday] if opt('time');
  342. my ($output_r, $error_r, $errcode) = spawnit($command);
  343. my $elapsed = tv_interval ( $t0 ) if opt('time');
  344. vprint -1, "c time: $elapsed" if opt('time');
  345. if (@$error_r && $errcode != 0) {
  346. _die("$Input did not compile $errcode:\n@$error_r\n");
  347. } else {
  348. my @error = grep { !/^$Input syntax OK$/o } @$error_r;
  349. @error = grep { !/^No package specified for compilation, assuming main::$/o } @error;
  350. warn "$0: Unexpected compiler output\n@error" if @error and opt('v')<5;
  351. warn "@error" if @error and opt('v')>4;
  352. }
  353. unless (opt('dryrun')) {
  354. chmod 0777 & ~umask, $Output or _die("can't chmod $Output: $!\n");
  355. }
  356. }
  357. sub compile_cstyle {
  358. my $stash = opt('stash') ? grab_stash() : "";
  359. $stash .= "," if $stash; #stash can be empty
  360. $stash .= "-u$_," for @{$Options->{u}};
  361. $stash .= "-U$_," for @{$Options->{U}};
  362. my $taint = opt('T') ? ' -T' :
  363. opt('t') ? ' -t' : '';
  364. # What are we going to call our output C file?
  365. my $lose = 0;
  366. my ($cfh);
  367. my $testsuite = '';
  368. my $addoptions = '';
  369. if (@_ == 1) {
  370. $addoptions .= $_[0].",";
  371. }
  372. $addoptions .= opt('Wb');
  373. if( $addoptions ) {
  374. $addoptions .= ',-Dfull' if opt('v') >= 6;
  375. $addoptions .= ',-Dsp,-v' if opt('v') == 5;
  376. $addoptions .= ',';
  377. } elsif (opt('v') > 4) {
  378. $addoptions = '-Dsp,-v,';
  379. $addoptions = '-Dfull,-v,' if opt('v') >= 6;
  380. }
  381. if (opt('f')) {
  382. $addoptions .= "-f$_," for @{$Options->{f}};
  383. }
  384. if (opt('check')) {
  385. $addoptions .= "-c,";
  386. }
  387. my $staticxs = opt('staticxs') ? "-staticxs," : '';
  388. warn "Warning: --staticxs on darwin is very experimental\n"
  389. if $staticxs and $^O eq 'darwin';
  390. if (opt('testsuite')) {
  391. my $bo = join '', @begin_output;
  392. $bo =~ s/\\/\\\\\\\\/gs;
  393. $bo =~ s/\n/\\n/gs;
  394. $bo =~ s/,/\\054/gs;
  395. # don't look at that: it hurts
  396. $testsuite = q{-fuse-script-name,-fsave-data,-fsave-sig-hash,}.
  397. qq[-e"print q{$bo}",] .
  398. q{-e"open(Test::Builder::TESTOUT\054 '>&STDOUT') or die $!",} .
  399. q{-e"open(Test::Builder::TESTERR\054 '>&STDERR') or die $!",};
  400. }
  401. if (opt('check')) {
  402. $cfile = "";
  403. $staticxs = "";
  404. } elsif (opt('o')) {
  405. $cfile = opt('o').".c";
  406. if ((is_win32() or $^O eq 'cygwin') and $Output =~ /\.exe.c$/) {
  407. $cfile =~ s/\.exe\.c$/.c/,
  408. }
  409. } elsif (opt('S') || opt('c')) { # We need to keep it
  410. if (opt('e')) {
  411. $cfile = $Output;
  412. if ((is_win32() or $^O eq 'cygwin') and $Output =~ /\.exe$/) {
  413. $cfile =~ s/\.exe$//,
  414. }
  415. $cfile .= '.c';
  416. } else {
  417. $cfile = basename($Input);
  418. # File off extension if present
  419. # hold on: plx is executable; also, careful of ordering!
  420. $cfile =~ s/\.(?:p(?:lx|l|h)|m)\z//i;
  421. $cfile .= ".c";
  422. $cfile = $Output if opt('c') && $Output =~ /\.c\z/i;
  423. }
  424. check_write($cfile);
  425. } else { # Do not keep tempfiles (no -S nor -c nor -o)
  426. $lose = 1;
  427. ($cfh, $cfile) = tempfile("pccXXXXX", SUFFIX => ".c");
  428. close $cfh; # See comment just below
  429. }
  430. vprint 3, "Writing C on $cfile" unless opt('check');
  431. my $max_line_len = '';
  432. if ($^O eq 'MSWin32' && $Config{cc} =~ /^cl/i) {
  433. $max_line_len = '-l2000,';
  434. }
  435. my $options = "$addoptions$testsuite$max_line_len$staticxs$stash";
  436. $options .= "-o$cfile" unless opt('check');
  437. $options = substr($options,0,-1) if substr($options,-1,1) eq ",";
  438. # This has to do the write itself, so we can't keep a lock. Life
  439. # sucks.
  440. my $command = "$BinPerl$taint -MO=$Backend,$options $Input";
  441. vprint 5, "Compiling...";
  442. vprint 0, "Calling $command";
  443. my $t0 = [gettimeofday] if opt('time');
  444. my ($output_r, $error_r, $errcode) = spawnit($command);
  445. my $elapsed = tv_interval ( $t0 ) if opt('time');
  446. my @output = @$output_r;
  447. my @error = @$error_r;
  448. if (@error && $errcode != 0) {
  449. _die("$Input did not compile, which can't happen $errcode:\n@error\n");
  450. } else {
  451. my $i = substr($Input,0,2) eq '-e' ? '-e' : $Input;
  452. @error = grep { !/^$i syntax OK$/o } @error;
  453. if (opt('check')) {
  454. print "@error" if @error;
  455. } else {
  456. warn "$0: Unexpected compiler output\n@error" if @error and opt('v')<5;
  457. warn "@error" if @error and opt('v')>4;
  458. }
  459. }
  460. vprint -1, "c time: $elapsed" if opt('time');
  461. $extra_libs = '';
  462. my %rpath;
  463. if ($staticxs and open(XS, "<", $cfile.".lst")) {
  464. while (<XS>) {
  465. my ($s, $l) = m/^([^\t]+)(.*)$/;
  466. next if grep { $s eq $_ } @{$Options->{U}};
  467. $stash .= ",-u$s";
  468. if ($l) {
  469. $l = substr($l,1);
  470. if ($^O eq 'darwin' and $l =~/\.bundle$/) {
  471. my $ofile = $l;
  472. $ofile =~ s/\.bundle$/.o/;
  473. $ofile =~ s{^.*/auto/}{};
  474. $ofile =~ s{(.*)/[^/]+\.o}{$1.o};
  475. $ofile =~ s{/}{_}g;
  476. $ofile = 'pcc'.$ofile;
  477. if (-e $ofile) {
  478. vprint 3, "Using ".$ofile;
  479. } else {
  480. vprint 3, "Creating ".$ofile;
  481. # This fails sometimes
  482. my $cmd = "otool -tv $l | \"$^X\" -pe "
  483. . q{'s{^/}{# .file /};s/^00[0-9a-f]+\s/\t/;s/^\(__(\w+)(,__.*?)?\) section/q(.).lc($1)/e'}
  484. . " | as -o \"$ofile\"";
  485. vprint 3, $cmd;
  486. vsystem($cmd);
  487. }
  488. $extra_libs .= " ".$l if -e $ofile;
  489. } else {
  490. $extra_libs .= " ".$l;
  491. $rpath{dirname($l)}++;
  492. }
  493. }
  494. }
  495. close XS;
  496. my ($rpath) = $Config{ccdlflags} =~ /^(.+rpath,)/;
  497. ($rpath) = $Config{ccdlflags} =~ m{^(.+-R,)/} unless $rpath;
  498. if (!$rpath and $Config{gccversion}) {
  499. $rpath = '-Wl,-rpath,';
  500. }
  501. $rpath =~ s/^-Wl,-E// if $rpath; # already done via ccdlflags
  502. # $extra_libs .= " $rpath".join(" ".$rpath,keys %rpath) if $rpath and %rpath;
  503. vprint 4, "staticxs: $stash $extra_libs";
  504. }
  505. exit if opt('check');
  506. $t0 = [gettimeofday] if opt('time');
  507. is_msvc ?
  508. cc_harness_msvc($cfile, $stash, $extra_libs) :
  509. cc_harness($cfile, $stash, $extra_libs) unless opt('c');
  510. $elapsed = tv_interval ( $t0 ) if opt('time');
  511. vprint -1, "cc time: $elapsed" if opt('time');
  512. if ($lose and -s $Output) {
  513. vprint 3, "Unlinking $cfile";
  514. unlink $cfile or _die("can't unlink $cfile: $!\n");
  515. }
  516. }
  517. sub cc_harness_msvc {
  518. my ($cfile, $stash, $extra_libs) = @_;
  519. use ExtUtils::Embed ();
  520. my $obj = "${Output}.obj";
  521. my $compile = ExtUtils::Embed::ccopts." -c -Fo$obj $cfile ";
  522. my $link = "-out:$Output $obj";
  523. $compile .= " -DHAVE_INDEPENDENT_COMALLOC" if $B::C::Flags::have_independent_comalloc;
  524. $compile .= $B::C::Flags::extra_cflags;
  525. $compile .= " -I".$_ for split /\s+/, opt('I');
  526. $compile .= " -DSTATICXS" if opt('staticxs');
  527. $compile .= " ".opt('Wc') if opt('Wc');
  528. $link .= " -libpath:".$_ for split /\s+/, opt('L');
  529. # TODO: -shared,-static,-sharedxs
  530. if ($stash) {
  531. my @mods = split /,?-?u/, $stash; # XXX -U stashes
  532. $link .= " ".ExtUtils::Embed::ldopts("-std", \@mods);
  533. # XXX staticxs need to check if the last mods for staticxs found a static lib.
  534. # XXX only if not use the extra_libs
  535. } else {
  536. $link .= " ".ExtUtils::Embed::ldopts("-std");
  537. }
  538. if ($Config{ccversion} eq '12.0.8804') {
  539. $link =~ s/ -opt:ref,icf//;
  540. }
  541. $link .= " ".opt('Wl') if opt('Wl');
  542. if (opt('staticxs')) { # TODO: can msvc link to dll's directly? otherwise use dlltool
  543. $extra_libs =~ s/^\s+|\s+$//g; # code by stengcode@gmail.com
  544. foreach (split /\.dll(?:\s+|$)/, $extra_libs) {
  545. $_ .= '.lib';
  546. if (!-e $_) {
  547. die "--staticxs requires $_, you should copy it from build area";
  548. }
  549. else {
  550. $link .= ' ' . $_;
  551. }
  552. }
  553. } else {
  554. $link .= $extra_libs;
  555. }
  556. $link .= " perl5$Config{PERL_VERSION}.lib kernel32.lib msvcrt.lib";
  557. $link .= $B::C::Flags::extra_libs;
  558. vprint 3, "Calling $Config{cc} $compile";
  559. vsystem("$Config{cc} $compile");
  560. vprint 3, "Calling $Config{ld} $link";
  561. vsystem("$Config{ld} $link");
  562. }
  563. sub cc_harness {
  564. my ($cfile, $stash, $extra_libs) = @_;
  565. use ExtUtils::Embed ();
  566. my $command = ExtUtils::Embed::ccopts." -o $Output $cfile ";
  567. $command .= " -DHAVE_INDEPENDENT_COMALLOC" if $B::C::Flags::have_independent_comalloc;
  568. $command .= $B::C::Flags::extra_cflags if $B::C::Flags::extra_cflags;
  569. $command .= " -I".$_ for split /\s+/, opt('I');
  570. $command .= " -L".$_ for split /\s+/, opt('L');
  571. $command .= " -DSTATICXS" if opt('staticxs');
  572. $command .= " ".opt('Wc') if opt('Wc');
  573. my $ccflags = $command;
  574. my $useshrplib = $Config{useshrplib};
  575. _die("--sharedxs with useshrplib=false\n") if !$useshrplib and opt('sharedxs');
  576. my $ldopts;
  577. if ($stash) {
  578. my @mods = split /,?-?u/, $stash; # XXX -U stashes
  579. $ldopts = ExtUtils::Embed::ldopts("-std", \@mods);
  580. } else {
  581. $ldopts = ExtUtils::Embed::ldopts("-std");
  582. }
  583. $ldopts .= " ".opt('Wl') if opt('Wl');
  584. # gcc crashes with this duplicate -fstack-protector arg
  585. my $ldflags = $Config{ldflags};
  586. if ($^O eq 'cygwin' and $ccflags =~ /-fstack-protector\b/ and $ldopts =~ /-fstack-protector\b/) {
  587. $ldopts =~ s/-fstack-protector\b//;
  588. $ldflags =~ s/-fstack-protector\b// if $extra_libs;
  589. }
  590. my $libperl = $Config{libperl};
  591. my $libdir = $Config{prefix} . "/lib";
  592. my $coredir = $ENV{PERL_SRC} || $Config{archlib}."/CORE";
  593. if ($extra_libs) {
  594. # splice extra_libs after $Config{ldopts} before @archives
  595. my $i_ldopts = index($ldopts, $ldflags);
  596. if ($ldflags and $i_ldopts >= 0) {
  597. my $l = $i_ldopts + length($ldflags);
  598. $ldopts = substr($ldopts,0,$l).$extra_libs." ".substr($ldopts,$l);
  599. } else {
  600. $ldopts = $extra_libs." ".$ldopts;
  601. }
  602. }
  603. if (opt('shared')) {
  604. warn "--shared with useshrplib=false might not work\n" unless $useshrplib;
  605. my @plibs = ($libperl, "$coredir/$libperl", "$libdir/$libperl");
  606. if ($libperl !~ /$Config{dlext}$/) {
  607. $libperl = "libperl.".$Config{dlext};
  608. @plibs = ($libperl, "$coredir/$libperl", "$libdir/$libperl");
  609. push @plibs, glob "$coredir/*perl5*".$Config{dlext};
  610. push @plibs, glob "$coredir/*perl.".$Config{dlext};
  611. push @plibs, glob $libdir."/*perl5*.".$Config{dlext};
  612. push @plibs, glob $libdir."/*perl.".$Config{dlext};
  613. push @plibs, glob $Config{bin}."/perl*.".$Config{dlext};
  614. }
  615. for my $lib (@plibs) {
  616. if (-e $lib) {
  617. $ldopts =~ s|-lperl |$lib |;
  618. $ldopts =~ s|\s+\S+libperl\w+\.a | $lib |;
  619. $ldopts = "$coredir/DynaLoader.o $ldopts" if -e "$coredir/DynaLoader.o";
  620. last;
  621. }
  622. }
  623. } elsif (opt('static')) {
  624. for my $lib ($libperl, "$coredir/$libperl", "$coredir/$libperl",
  625. "$coredir/libperl.a", "$libdir/libperl.a") {
  626. if (-e $lib) {
  627. $ldopts =~ s|-lperl |$lib |;
  628. $ldopts = "$coredir/DynaLoader.o $ldopts" if -e "$coredir/DynaLoader.o";
  629. last;
  630. }
  631. }
  632. } else {
  633. if ( $useshrplib and -e $libdir."/".$Config{libperl}) {
  634. # debian: only /usr/lib/libperl.so.5.10.1 and broken ExtUtils::Embed::ldopts
  635. $ldopts =~ s|-lperl |$libdir/$Config{libperl} |;
  636. }
  637. if ( $useshrplib and -e $coredir."/".$Config{libperl}) {
  638. # help cygwin debugging, and workaround wrong debian linker prefs (/usr/lib before given -L)
  639. $ldopts =~ s|-lperl |$coredir/$Config{libperl} |;
  640. }
  641. }
  642. $ldopts .= " -lperl" unless $command =~ /perl/;
  643. $command .= " ".$ldopts;
  644. $command .= $B::C::Flags::extra_libs if $B::C::Flags::extra_libs;
  645. vprint 3, "Calling $Config{cc} $command";
  646. vsystem("$Config{cc} $command");
  647. }
  648. # Where Perl is, and which include path to give it.
  649. sub yclept {
  650. my $command = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  651. # DWIM the -I to be Perl, not C, include directories.
  652. if (opt('I') && $Backend eq "Bytecode") {
  653. for (split /\s+/, opt('I')) {
  654. if (-d $_) {
  655. push @INC, $_;
  656. } else {
  657. warn "$0: Include directory $_ not found, skipping\n";
  658. }
  659. }
  660. }
  661. my %OINC;
  662. $OINC{$Config{$_}}++ for (qw(privlib archlib sitelib sitearch vendorlib vendorarch));
  663. $OINC{'.'}++ unless ${^TAINT};
  664. $OINC{$_}++ for split ':', $Config{otherlibdirs};
  665. if (my $incver = $Config{inc_version_list}) {
  666. my $incpre = dirname($Config{sitelib});
  667. $OINC{$_}++ for map { File::Spec->catdir($incpre,$_) } split(' ',$incver);
  668. $OINC{$incpre}++;
  669. }
  670. for my $i (@INC) {
  671. my $inc = $i =~ m/\s/ ? qq{"$i"} : $i;
  672. $command .= " -I$inc" unless $OINC{$i}; # omit internal @INC dirs
  673. }
  674. return $command;
  675. }
  676. # Use B::Stash to find additional modules and stuff.
  677. {
  678. my $_stash;
  679. sub grab_stash {
  680. warn "already called grab_stash once" if $_stash;
  681. my $taint = opt('T') ? ' -T' :
  682. opt('t') ? ' -t' : '';
  683. my $command = "$BinPerl$taint -MB::Stash -c $Input";
  684. # Filename here is perfectly sanitised.
  685. vprint 3, "Calling $command\n";
  686. my ($stash_r, $error_r, $errcode) = spawnit($command);
  687. my @stash = @$stash_r;
  688. my @error = @$error_r;
  689. if (@error && $errcode != 0) {
  690. _die("$Input did not compile $errcode:\n@error\n");
  691. }
  692. # band-aid for modules with noisy BEGIN {}
  693. foreach my $i ( @stash ) {
  694. $i =~ m/-[ux](?:[\w:]+|\<none\>)$/ and $stash[0] = $i and next;
  695. push @begin_output, $i;
  696. }
  697. chomp $stash[0];
  698. $stash[0] =~ s/,-[ux]\<none\>//;
  699. $stash[0] =~ s/^.*?-([ux])/-$1/s;
  700. vprint 2, "Stash: ", join " ", split /,?-[ux]/, $stash[0];
  701. chomp $stash[0];
  702. return $_stash = $stash[0];
  703. }
  704. }
  705. # Check the consistency of options if -B is selected.
  706. # To wit, (-B|-O) ==> no -shared, no -S, no -c
  707. sub checkopts_byte {
  708. _die("Please choose one of either -B and -O.\n") if opt('O');
  709. for my $o ( qw[shared sharedxs static staticxs] ) {
  710. if (exists($Options->{$o}) && $Options->{$o}) {
  711. warn "$0: --$o incompatible with -B\n";
  712. delete $Options->{$o};
  713. }
  714. }
  715. # TODO make -S produce an .asm also?
  716. for my $o ( qw[c S] ) {
  717. if (exists($Options->{$o}) && $Options->{$o}) {
  718. warn "$0: Compiling to bytecode is a one-pass process. ",
  719. "-$o ignored\n";
  720. delete $Options->{$o};
  721. }
  722. }
  723. }
  724. # Check the input and output files make sense, are read/writeable.
  725. sub sanity_check {
  726. if ($Input eq $Output) {
  727. if ($Input eq 'a.out') {
  728. _die("Compiling a.out is probably not what you want to do.\n");
  729. # You fully deserve what you get now. No you *don't*. typos happen.
  730. } else {
  731. my $suffix = (is_win32() or $^O eq 'cygwin') ? '.exe' : '';
  732. (undef, $Output) = tempfile("plcXXXXX", SUFFIX => $suffix);
  733. warn "$0: Will not write output on top of input file, ",
  734. "compiling to $Output instead\n";
  735. }
  736. }
  737. }
  738. sub check_read {
  739. my $file = shift;
  740. unless (-r $file) {
  741. _die("Input file $file is a directory, not a file\n") if -d _;
  742. unless (-e _) {
  743. _die("Input file $file was not found\n");
  744. } else {
  745. _die("Cannot read input file $file: $!\n");
  746. }
  747. }
  748. unless (-f _) {
  749. # XXX: die? don't try this on /dev/tty
  750. warn "$0: WARNING: input $file is not a plain file\n";
  751. }
  752. }
  753. sub check_write {
  754. my $file = shift;
  755. if (-d $file) {
  756. _die("Cannot write on $file, is a directory\n");
  757. }
  758. if (-e _) {
  759. _die("Cannot write on $file: $!\n") unless -w _;
  760. }
  761. unless (-w '.') {
  762. _die("Cannot write in this directory: $!\n");
  763. }
  764. }
  765. sub check_perl {
  766. my $file = shift;
  767. unless (-T $file) {
  768. warn "$0: Binary `$file' sure doesn't smell like perl source!\n";
  769. print "Checking file type... ";
  770. vsystem("file", $file);
  771. _die("Please try a perlier file!\n");
  772. }
  773. open(my $handle, "<", $file) or _die("Can't open $file: $!\n");
  774. local $_ = <$handle>;
  775. if (/^#!/ && !/perl/) {
  776. _die("$file is a ", /^#!\s*(\S+)/, " script, not perl\n");
  777. }
  778. }
  779. # File spawning and error collecting
  780. sub spawnit {
  781. my $command = shift;
  782. my (@error,@output,$errname,$errcode);
  783. if (opt('dryrun')) {
  784. print "$command\n";;
  785. }
  786. elsif ($Options->{spawn}) {
  787. (undef, $errname) = tempfile("pccXXXXX");
  788. {
  789. my $pid = open (S_OUT, "$command 2>$errname |")
  790. or _die("Couldn't spawn the compiler.\n");
  791. $errcode = $?;
  792. my $kid;
  793. do {
  794. $kid = waitpid($pid, 0);
  795. } while $kid > 0;
  796. @output = <S_OUT>;
  797. }
  798. open (S_ERROR, $errname) or _die("Couldn't read the error file.\n");
  799. @error = <S_ERROR>;
  800. close S_ERROR;
  801. close S_OUT;
  802. unlink $errname or _die("Can't unlink error file $errname\n");
  803. } else {
  804. @output = split /\n/, `$command`;
  805. }
  806. return (\@output, \@error, $errcode);
  807. }
  808. sub version {
  809. require B::C::Flags;
  810. no warnings 'once';
  811. my $BC_VERSION = $B::C::Flags::VERSION . $B::C::REVISION;
  812. return "perlcc $VERSION, B-C-${BC_VERSION} built for $Config{perlpath} $Config{archname}\n";
  813. }
  814. sub helpme {
  815. print version(),"\n";
  816. if (opt('v')) {
  817. pod2usage( -verbose => opt('v') );
  818. } else {
  819. pod2usage( -verbose => 0 );
  820. }
  821. }
  822. sub relativize {
  823. my ($args) = @_;
  824. return("./".basename($args)) if ($args =~ m"^[/\\]");
  825. return("./$args");
  826. }
  827. sub _die {
  828. my @args = ("$0: ", @_);
  829. $logfh->print(@args) if opt('log');
  830. print STDERR @args;
  831. exit(); # should die eventually. However, needed so that a 'make compile'
  832. # can compile all the way through to the end for standard dist.
  833. }
  834. sub _usage_and_die {
  835. _die(<<EOU);
  836. Usage:
  837. $0 [-o executable] [-h][-r] [-O|-B|-c|-S] [-I /foo] [-L /foo] [--log log] [source[.pl] | -e code]
  838. More options (see perldoc perlcc)
  839. -v[1-4]
  840. --stash --staticxs --shared --static
  841. --testsuite --time
  842. EOU
  843. }
  844. sub run {
  845. my (@commands) = @_;
  846. my $t0 = [gettimeofday] if opt('time');
  847. if (!opt('log')) {
  848. print interruptrun(@commands);
  849. } else {
  850. $logfh->print(interruptrun(@commands));
  851. }
  852. my $elapsed = tv_interval ( $t0 ) if opt('time');
  853. vprint -1, "r time: $elapsed" if opt('time');
  854. }
  855. sub interruptrun {
  856. my (@commands) = @_;
  857. my $command = join('', @commands);
  858. local(*FD);
  859. my $pid = open(FD, "$command |");
  860. my $text;
  861. local($SIG{HUP}, $SIG{INT}) if exists $SIG{HUP};
  862. $SIG{HUP} = $SIG{INT} = sub { kill 9, $pid; exit } if exists $SIG{HUP};
  863. my $needalarm =
  864. ($ENV{PERLCC_TIMEOUT} &&
  865. exists $SIG{ALRM} &&
  866. $Config{'osname'} ne 'MSWin32' &&
  867. $command =~ m"(^|\s)perlcc\s");
  868. eval {
  869. local($SIG{ALRM}) = sub { die "INFINITE LOOP"; } if exists $SIG{ALRM};
  870. alarm($ENV{PERLCC_TIMEOUT}) if $needalarm;
  871. $text = join('', <FD>);
  872. alarm(0) if $needalarm;
  873. };
  874. if ($@) {
  875. eval { kill 'HUP', $pid };
  876. vprint 0, "SYSTEM TIMEOUT (infinite loop?)\n";
  877. }
  878. close(FD);
  879. return($text);
  880. }
  881. sub is_win32() { $^O =~ m/^(MSWin32|msys)/ }
  882. sub is_msvc() { is_win32 && $Config{cc} =~ m/^cl/i }
  883. END {
  884. if ($cfile && !opt('S') && !opt('c') && -e $cfile) {
  885. vprint 4, "Unlinking $cfile";
  886. unlink $cfile;
  887. }
  888. if (opt('staticxs') and !opt('S')) {
  889. vprint 4, "Unlinking $cfile.lst";
  890. unlink "$cfile.lst";
  891. }
  892. }
  893. __END__
  894. =head1 NAME
  895. perlcc - generate executables from Perl programs
  896. =head1 SYNOPSIS
  897. perlcc hello.pl # Compiles into executable 'a.out'
  898. perlcc -o hello hello.pl # Compiles into executable 'hello'
  899. perlcc -O file.pl # Compiles using the optimised CC backend
  900. perlcc -O3 file.pl # Compiles with C, using -O3 optimizations
  901. perlcc -B file.pl # Compiles using the bytecode backend
  902. perlcc -B -m file.pm # Compiles a module to file.pmc
  903. perlcc -c file.pl # Creates a C file, 'file.c'
  904. perlcc -S -o hello file.pl # Keep C file
  905. perlcc -c out.c file.pl # Creates a C file, 'out.c' from 'file'
  906. perlcc --staticxs -r -o hello hello.pl # Compiles,links and runs with
  907. # XS modules static/dynaloaded
  908. perlcc -e 'print q//' # Compiles a one-liner into 'a.out'
  909. perlcc -c -e 'print q//' # Creates a C file 'a.out.c'
  910. perlcc -I /foo hello # extra headers for C
  911. perlcc -L /foo hello # extra libraries for C
  912. perlcc --Wb=-Dsp # extra perl compiler options
  913. perlcc -fno-delete-pkg # extra perl compiler options
  914. perlcc --Wc=-fno-openmp # extra C compiler options
  915. perlcc --Wl=-s # extra C linker options
  916. perlcc -uIO::Socket # force saving IO::Socket
  917. perlcc -UB # "unuse" B, compile without any B symbols
  918. perlcc -r hello # compiles 'hello' into 'a.out', runs 'a.out'
  919. perlcc -r hello a b c # compiles 'hello' into 'a.out', runs 'a.out'
  920. # with arguments 'a b c'
  921. perlcc hello -log c.log # compiles 'hello' into 'a.out', log into 'c.log'
  922. perlcc -h # help, only SYNOPSIS
  923. perlcc -v2 -h # verbose help, also DESCRIPTION and OPTIONS
  924. perlcc --version # prints internal perlcc and the B-C release version
  925. =head1 DESCRIPTION
  926. F<perlcc> creates standalone executables from Perl programs, using the
  927. code generators provided by the L<B> module. At present, you may
  928. either create executable Perl bytecode, using the C<-B> option, or
  929. generate and compile C files using the standard and 'optimised' C
  930. backends.
  931. The code generated in this way is not guaranteed to work. The whole
  932. codegen suite (C<perlcc> included) should be considered B<very>
  933. experimental. Use for production purposes is strongly discouraged.
  934. =head1 OPTIONS
  935. =over 4
  936. =item -LI<C library directories>
  937. Adds the given directories to the library search path when C code is
  938. passed to your C compiler.
  939. =item -II<C include directories>
  940. Adds the given directories to the include file search path when C code is
  941. passed to your C compiler; when using the Perl bytecode option, adds the
  942. given directories to Perl's include path.
  943. =item -o I<output file name>
  944. Specifies the file name for the final compiled executable.
  945. Without given output file name we use the base of the input file,
  946. or with C<-e> F<a.out> resp. F<a.exe> and a randomized intermediate
  947. C filename.
  948. If the input file is an absolute path on a non-windows system use
  949. the basename.
  950. =item -c I<C file name>
  951. Create C file only; do not compile and link to a standalone binary.
  952. =item -e I<perl code>
  953. Compile a one-liner, much the same as C<perl -e '...'>
  954. =item --check
  955. Pass -c flag to the backend, prints all backend warnings to STDOUT
  956. and exits before generating and compiling code. Similar to perl -c.
  957. =item -S
  958. "Keep source".
  959. Do not delete generated C code after compilation.
  960. =item -B
  961. Use the Perl bytecode code generator.
  962. =item -O
  963. Use the 'optimised' C code generator B::CC. This is more experimental than
  964. everything else put together, and the code created is not guaranteed to
  965. compile in finite time and memory, or indeed, at all.
  966. =item -OI<1-4>
  967. Pass the numeric optimisation option to the compiler backend.
  968. Shortcut for C<-Wb=-On>.
  969. This does not enforce B::CC.
  970. =item -v I<0-6>
  971. Set verbosity of output from 0 to max. 6.
  972. =item -r
  973. Run the resulting compiled script after compiling it.
  974. =item --log I<logfile>
  975. Log the output of compiling to a file rather than to stdout.
  976. =item -f<option> or --f=<option>
  977. Pass the options to the compiler backend, such as
  978. C<-fstash> or C<-fno-delete-pkg>.
  979. =item --Wb=I<options>
  980. Pass the options to the compiler backend, such as C<--Wb=-O2,-v>
  981. =item --Wc=I<options>
  982. Pass comma-seperated options to cc.
  983. =item --Wl=I<options>
  984. Pass comma-seperated options to ld.
  985. =item -T or -t
  986. run the backend using perl -T or -t
  987. =item -A
  988. Allow perl options to be passed to the executable first,
  989. like -D...
  990. Adds C<-DALLOW_PERL_OPTIONS> which omits C<--> from being added
  991. to the options handler.
  992. =item -u package
  993. Add package(s) to compiler and force linking to it.
  994. =item -U package
  995. Skip package(s). Do not compile and link the package and its sole dependencies.
  996. =item --stash
  997. Detect external packages automatically via B::Stash
  998. =item --static
  999. Link to static libperl.a
  1000. =item --staticxs
  1001. Link to static XS if available.
  1002. If the XS libs are only available as shared libs link to those ("prelink").
  1003. Systems without rpath (windows, cygwin) must be extend LD_LIBRARY_PATH/PATH at run-time.
  1004. Together with -static, purely static modules and no run-time eval or
  1005. require this will gain no external dependencies.
  1006. =item --shared
  1007. Link to shared libperl
  1008. =item --sharedxs
  1009. Link shared XSUBs if the linker supports it. No DynaLoader needed.
  1010. This will still require the shared XSUB libraries to be installed
  1011. at the client, modification of @INC in the source is probably required.
  1012. (Not yet implemented)
  1013. =item -m|--sharedlib [Modulename]
  1014. Create a module, resp. a shared library.
  1015. Currently only enabled for Bytecode and CC. I<(not yet tested)>
  1016. =item --testsuite
  1017. Tries be nice to Test:: modules, like preallocating the file
  1018. handles 4 and 5, and munge the output of BEGIN.
  1019. perlcc -r --testsuite t/harness
  1020. =item --time
  1021. Benchmark the different phases B<c> I<(B::* compilation)>,
  1022. B<cc> I<(cc compile + link)>, and B<r> (runtime).
  1023. =item --no-spawn
  1024. Do not spawn subprocesses for compilation, because broken
  1025. shells might not be able to kill its children.
  1026. =back
  1027. =cut
  1028. # Local Variables:
  1029. # mode: cperl
  1030. # cperl-indent-level: 4
  1031. # fill-column: 100
  1032. # End:
  1033. # vim: expandtab shiftwidth=4:
  1034. !NO!SUBS!
  1035. close OUT or die "Can't close $file: $!";
  1036. chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
  1037. exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
  1038. chdir $origdir;