perlcc.PL 37 KB

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