Commit | Line | Data |
52cebf5e |
1 | #!/usr/local/bin/perl |
2 | |
3 | use Config; |
4 | use File::Basename qw(&basename &dirname); |
8a5546a1 |
5 | use Cwd; |
52cebf5e |
6 | |
7 | # List explicitly here the variables you want Configure to |
8 | # generate. Metaconfig only looks for shell variables, so you |
9 | # have to mention them as if they were shell variables, not |
10 | # %Config entries. Thus you write |
11 | # $startperl |
12 | # to ensure Configure will look for $Config{startperl}. |
13 | # Wanted: $archlibexp |
14 | |
15 | # This forces PL files to create target in same directory as PL file. |
16 | # This is so that make depend always knows where to find PL derivatives. |
8a5546a1 |
17 | $origdir = cwd; |
52cebf5e |
18 | chdir dirname($0); |
19 | $file = basename($0, '.PL'); |
20 | $file .= '.com' if $^O eq 'VMS'; |
21 | |
22 | open OUT,">$file" or die "Can't create $file: $!"; |
23 | |
24 | print "Extracting $file (with variable substitutions)\n"; |
25 | |
26 | # In this section, perl variables will be expanded during extraction. |
27 | # You can use $Config{...} to use Configure variables. |
28 | |
29 | print OUT <<"!GROK!THIS!"; |
30 | $Config{startperl} |
31 | eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}' |
32 | if \$running_under_some_shell; |
33 | !GROK!THIS! |
34 | |
35 | # In the following, perl variables are not expanded during extraction. |
36 | |
37 | print OUT <<'!NO!SUBS!'; |
38 | |
39 | use Config; |
40 | use strict; |
41 | use FileHandle; |
42 | use File::Basename qw(&basename &dirname); |
8a5546a1 |
43 | use Cwd; |
52cebf5e |
44 | |
45 | use Getopt::Long; |
46 | |
47 | $Getopt::Long::bundling_override = 1; |
48 | $Getopt::Long::passthrough = 0; |
49 | $Getopt::Long::ignore_case = 0; |
50 | |
51 | my $options = {}; |
52 | my $_fh; |
53 | |
54 | main(); |
55 | |
56 | sub main |
57 | { |
58 | |
59 | GetOptions |
60 | ( |
61 | $options, "L:s", |
62 | "I:s", |
63 | "C:s", |
64 | "o:s", |
65 | "e:s", |
66 | "regex:s", |
67 | "verbose:s", |
68 | "log:s", |
69 | "argv:s", |
70 | "gen", |
71 | "sav", |
72 | "run", |
73 | "prog", |
74 | "mod" |
75 | ); |
76 | |
77 | |
78 | my $key; |
79 | |
80 | local($") = "|"; |
81 | |
82 | _usage() if (!_checkopts()); |
83 | push(@ARGV, _maketempfile()) if ($options->{'e'}); |
84 | |
85 | _usage() if (!@ARGV); |
86 | |
87 | my $file; |
88 | foreach $file (@ARGV) |
89 | { |
90 | _print(" |
91 | -------------------------------------------------------------------------------- |
92 | Compiling $file: |
93 | -------------------------------------------------------------------------------- |
94 | ", 36 ); |
95 | _doit($file); |
96 | } |
97 | } |
98 | |
99 | sub _doit |
100 | { |
101 | my ($file) = @_; |
102 | |
103 | my ($program_ext, $module_ext) = _getRegexps(); |
104 | my ($obj, $objfile, $so, $type); |
105 | |
106 | if ( |
107 | (($file =~ m"@$program_ext") && ($file !~ m"@$module_ext")) |
108 | || (defined($options->{'prog'}) || defined($options->{'run'})) |
109 | ) |
110 | { |
111 | $objfile = ($options->{'C'}) ? $options->{'C'} : "$file.c"; |
112 | $type = 'program'; |
113 | |
114 | $obj = ($options->{'o'})? $options->{'o'} : |
115 | _getExecutable( $file,$program_ext); |
116 | |
117 | return() if (!$obj); |
118 | |
119 | } |
120 | elsif (($file =~ m"@$module_ext") || ($options->{'mod'})) |
121 | { |
122 | die "Shared objects are not supported on Win32 yet!!!!\n" |
123 | if ($Config{'osname'} eq 'MSWin32'); |
124 | |
125 | $obj = ($options->{'o'})? $options->{'o'} : |
126 | _getExecutable($file, $module_ext); |
127 | $so = "$obj.so"; |
128 | $type = 'sharedlib'; |
129 | return() if (!$obj); |
130 | } |
131 | else |
132 | { |
133 | _error("noextension", $file, $program_ext, $module_ext); |
134 | return(); |
135 | } |
136 | |
137 | if ($type eq 'program') |
138 | { |
139 | _print("Making C($objfile) for $file!\n", 36 ); |
140 | |
141 | my $errcode = _createCode($objfile, $file); |
142 | (_print( "ERROR: In generating code for $file!\n", -1), return()) |
143 | if ($errcode); |
144 | |
145 | _print("Compiling C($obj) for $file!\n", 36 ) if (!$options->{'gen'}); |
146 | my $errcode = _compileCode($file, $objfile, $obj) |
147 | if (!$options->{'gen'}); |
148 | |
149 | if ($errcode) |
150 | { |
151 | _print( "ERROR: In compiling code for $objfile !\n", -1); |
152 | my $ofile = File::Basename::basename($objfile); |
153 | $ofile =~ s"\.c$"\.o"s; |
154 | |
155 | _removeCode("$ofile"); |
156 | return() |
157 | } |
158 | |
159 | _runCode($obj) if ($options->{'run'}); |
160 | |
161 | _removeCode($objfile) if (!$options->{'sav'} || |
162 | ($options->{'e'} && !$options->{'C'})); |
163 | |
164 | _removeCode($file) if ($options->{'e'}); |
165 | |
166 | _removeCode($obj) if (($options->{'e'} && |
167 | ((!$options->{'sav'}) || !$options->{'o'})) || |
168 | ($options->{'run'} && (!$options->{'sav'}))); |
169 | } |
170 | else |
171 | { |
172 | _print( "Making C($objfile) for $file!\n", 36 ); |
173 | my $errcode = _createCode($objfile, $file, $obj); |
174 | (_print( "ERROR: In generating code for $file!\n", -1), return()) |
175 | if ($errcode); |
176 | |
177 | _print( "Compiling C($obj) for $file!\n", 36 ) if (!$options->{'gen'}); |
178 | |
179 | my $errorcode = |
180 | _compileCode($file, $objfile, $obj, $so ) if (!$options->{'gen'}); |
181 | |
182 | (_print( "ERROR: In compiling code for $objfile!\n", -1), return()) |
183 | if ($errcode); |
184 | } |
185 | } |
186 | |
187 | sub _getExecutable |
188 | { |
189 | my ($sourceprog, $ext) = @_; |
190 | my ($obj); |
191 | |
192 | if (defined($options->{'regex'})) |
193 | { |
194 | eval("(\$obj = \$sourceprog) =~ $options->{'regex'}"); |
195 | return(0) if (_error('badeval', $@)); |
196 | return(0) if (_error('equal', $obj, $sourceprog)); |
197 | } |
198 | elsif (defined ($options->{'ext'})) |
199 | { |
200 | ($obj = $sourceprog) =~ s"@$ext"$options->{ext}"g; |
201 | return(0) if (_error('equal', $obj, $sourceprog)); |
202 | } |
203 | elsif (defined ($options->{'run'})) |
204 | { |
205 | $obj = "perlc$$"; |
206 | } |
207 | else |
208 | { |
209 | ($obj = $sourceprog) =~ s"@$ext""g; |
210 | return(0) if (_error('equal', $obj, $sourceprog)); |
211 | } |
212 | return($obj); |
213 | } |
214 | |
215 | sub _createCode |
216 | { |
217 | my ( $generated_cfile, $file, $final_output ) = @_; |
218 | my $return; |
219 | |
220 | local($") = " -I"; |
221 | |
222 | if (@_ == 2) # compiling a program |
223 | { |
224 | _print( "$^X -I@INC -MO=CC,-o$generated_cfile $file\n", 36); |
225 | $return = _run("$\18 -I@INC -MO=CC,-o$generated_cfile $file", 9); |
226 | $return; |
227 | } |
228 | else # compiling a shared object |
229 | { |
230 | _print( |
231 | "$\18 -I@INC -MO=CC,-m$final_output,-o$generated_cfile $file\n", 36); |
232 | $return = |
233 | _run("$\18 -I@INC -MO=CC,-m$final_output,-o$generated_cfile $file", 9); |
234 | $return; |
235 | } |
236 | } |
237 | |
238 | sub _compileCode |
239 | { |
240 | my ($sourceprog, $generated_cfile, $output_executable, $shared_object) = @_; |
241 | my @return; |
242 | |
243 | if (@_ == 3) # just compiling a program |
244 | { |
245 | $return[0] = |
246 | _ccharness($sourceprog, "-o", $output_executable, $generated_cfile); |
247 | $return[0]; |
248 | } |
249 | else |
250 | { |
251 | my $object_file = $generated_cfile; |
252 | $object_file =~ s"\.c$"\.o"; |
253 | |
254 | $return[0] = _ccharness($sourceprog, "-c", $generated_cfile); |
255 | $return[1] = _ccharness |
256 | ( |
257 | $sourceprog, "-shared","-o", |
258 | $shared_object, $object_file |
259 | ); |
260 | return(1) if (grep ($_, @return)); |
261 | return(0); |
262 | } |
263 | } |
264 | |
265 | sub _runCode |
266 | { |
267 | my ($executable) = @_; |
268 | _print("$executable $options->{'argv'}\n", 36); |
269 | _run("$executable $options->{'argv'}", -1 ); |
270 | } |
271 | |
272 | sub _removeCode |
273 | { |
274 | my ($file) = @_; |
275 | unlink($file) if (-e $file); |
276 | } |
277 | |
278 | sub _ccharness |
279 | { |
280 | my (@args) = @_; |
281 | local($") = " "; |
282 | |
283 | my $sourceprog = shift(@args); |
284 | my ($libdir, $incdir); |
285 | |
286 | if (-d "$Config{installarchlib}/CORE") |
287 | { |
288 | $libdir = "-L$Config{installarchlib}/CORE"; |
289 | $incdir = "-I$Config{installarchlib}/CORE"; |
290 | } |
291 | else |
292 | { |
293 | $libdir = "-L.."; |
294 | $incdir = "-I.."; |
295 | } |
296 | |
297 | $libdir .= " -L$options->{L}" if (defined($options->{L})); |
298 | $incdir .= " -I$options->{L}" if (defined($options->{L})); |
299 | |
300 | my $linkargs; |
301 | |
302 | if (!grep(/^-[cS]$/, @ARGV)) |
303 | { |
304 | $linkargs = sprintf("%s $libdir -lperl %s",@Config{qw(ldflags libs)}); |
305 | } |
306 | |
307 | my @sharedobjects = _getSharedObjects($sourceprog); |
308 | |
309 | my $cccmd = |
310 | "$Config{cc} $Config{ccflags} $incdir @sharedobjects @args $linkargs"; |
311 | |
312 | |
313 | _print ("$cccmd\n", 36); |
314 | _run("$cccmd", 18 ); |
315 | } |
316 | |
317 | sub _getSharedObjects |
318 | { |
319 | my ($sourceprog) = @_; |
320 | my ($tmpfile, $incfile); |
321 | my (@return); |
322 | local($") = " -I"; |
323 | |
324 | if ($Config{'osname'} eq 'MSWin32') |
325 | { |
326 | # _addstuff; |
327 | } |
328 | else |
329 | { |
330 | my ($tmpprog); |
331 | ($tmpprog = $sourceprog) =~ s"(.*)[\/\\](.*)"$2"; |
332 | $tmpfile = "/tmp/$tmpprog.tst"; |
333 | $incfile = "/tmp/$tmpprog.val"; |
334 | } |
335 | |
336 | my $fd = new FileHandle("> $tmpfile") || die "Couldn't open $tmpfile!\n"; |
337 | my $fd2 = |
338 | new FileHandle("$sourceprog") || die "Couldn't open $sourceprog!\n"; |
339 | |
340 | my $perl = <$fd2>; # strip off header; |
341 | |
342 | print $fd |
343 | <<"EOF"; |
344 | use FileHandle; |
345 | my \$fh3 = new FileHandle("> $incfile") |
346 | || die "Couldn't open $incfile\\n"; |
347 | |
348 | my \$key; |
349 | foreach \$key (keys(\%INC)) { print \$fh3 "\$key:\$INC{\$key}\\n"; } |
350 | close(\$fh3); |
351 | exit(); |
352 | EOF |
353 | |
354 | print $fd ( <$fd2> ); |
355 | close($fd); |
356 | |
357 | _print("$\18 -I@INC $tmpfile\n", 36); |
358 | _run("$\18 -I@INC $tmpfile", 9 ); |
359 | |
360 | my $fd = new FileHandle ("$incfile"); |
361 | my @lines = <$fd>; |
362 | |
363 | unlink($tmpfile); |
364 | unlink($incfile); |
365 | |
366 | my $line; |
367 | my $autolib; |
368 | |
369 | foreach $line (@lines) |
370 | { |
371 | chomp($line); |
372 | my ($modname, $modpath) = split(':', $line); |
373 | my ($dir, $file) = ($modpath=~ m"(.*)[\\/]($modname)"); |
374 | |
375 | if ($autolib = _lookforAuto($dir, $file)) |
376 | { |
377 | push(@return, $autolib); |
378 | } |
379 | } |
380 | |
381 | return(@return); |
382 | } |
383 | |
384 | sub _maketempfile |
385 | { |
386 | my $return; |
387 | |
388 | # if ($Config{'osname'} eq 'MSWin32') |
389 | # { $return = "C:\\TEMP\\comp$$.p"; } |
390 | # else |
391 | # { $return = "/tmp/comp$$.p"; } |
392 | |
393 | $return = "comp$$.p"; |
394 | |
395 | my $fd = new FileHandle( "> $return") || die "Couldn't open $return!\n"; |
396 | print $fd $options->{'e'}; |
397 | close($fd); |
398 | |
399 | return($return); |
400 | } |
401 | |
402 | |
403 | sub _lookforAuto |
404 | { |
405 | my ($dir, $file) = @_; |
406 | |
407 | my $relshared; |
408 | my $return; |
409 | |
410 | ($relshared = $file) =~ s"(.*)\.pm"$1"; |
411 | |
412 | my ($tmp, $modname) = ($relshared =~ m"(?:(.*)[\\/]){0,1}(.*)"s); |
413 | |
414 | $relshared .= |
415 | ($Config{'osname'} eq 'MSWin32')? "\\$modname.dll" : "/$modname.so"; |
416 | |
417 | |
418 | |
419 | if (-e ($return = "$Config{'installarchlib'}/auto/$relshared") ) |
420 | { |
421 | return($return); |
422 | } |
423 | elsif (-e ($return = "$Config{'installsitearch'}/auto/$relshared")) |
424 | { |
425 | return($return); |
426 | } |
427 | elsif (-e ($return = "$dir/arch/auto/$relshared")) |
428 | { |
429 | return($return); |
430 | } |
431 | else |
432 | { |
433 | return(undef); |
434 | } |
435 | } |
436 | |
437 | sub _getRegexps # make the appropriate regexps for making executables, |
438 | { # shared libs |
439 | |
440 | my ($program_ext, $module_ext) = ([],[]); |
441 | |
442 | |
443 | @$program_ext = ($ENV{PERL_SCRIPT_EXT})? split(':', $ENV{PERL_SCRIPT_EXT}) : |
444 | ('.p$', '.pl$', '.bat$'); |
445 | |
446 | |
447 | @$module_ext = ($ENV{PERL_MODULE_EXT})? split(':', $ENV{PERL_MODULE_EXT}) : |
448 | ('.pm$'); |
449 | |
450 | |
451 | _mungeRegexp( $program_ext ); |
452 | _mungeRegexp( $module_ext ); |
453 | |
454 | return($program_ext, $module_ext); |
455 | } |
456 | |
457 | sub _mungeRegexp |
458 | { |
459 | my ($regexp) = @_; |
460 | |
461 | grep(s"(^|[^\\])\."$1\x0\\."g, @$regexp); |
462 | grep(s"(^|[^\x0])\\\."$1\."g, @$regexp); |
463 | grep(s"\x0""g, @$regexp); |
464 | } |
465 | |
466 | |
467 | sub _error |
468 | { |
469 | my ($type, @args) = @_; |
470 | |
471 | if ($type eq 'equal') |
472 | { |
473 | |
474 | if ($args[0] eq $args[1]) |
475 | { |
476 | _print ("ERROR: The object file '$args[0]' does not generate a legitimate executable file! Skipping!\n", -1); |
477 | return(1); |
478 | } |
479 | } |
480 | elsif ($type eq 'badeval') |
481 | { |
482 | if ($args[0]) |
483 | { |
484 | _print ("ERROR: $args[0]\n", -1); |
485 | return(1); |
486 | } |
487 | } |
488 | elsif ($type eq 'noextension') |
489 | { |
490 | my $progext = join(',', @{$args[1]}); |
491 | my $modext = join(',', @{$args[2]}); |
492 | |
493 | $progext =~ s"\\""g; |
494 | $modext =~ s"\\""g; |
495 | |
496 | $progext =~ s"\$""g; |
497 | $modext =~ s"\$""g; |
498 | |
499 | _print |
500 | ( |
501 | " |
502 | ERROR: '$args[0]' does not have a proper extension! Proper extensions are: |
503 | |
504 | PROGRAM: $progext |
505 | SHARED OBJECT: $modext |
506 | |
507 | Use the '-prog' flag to force your files to be interpreted as programs. |
508 | Use the '-mod' flag to force your files to be interpreted as modules. |
509 | ", -1 |
510 | ); |
511 | return(1); |
512 | } |
513 | |
514 | return(0); |
515 | } |
516 | |
517 | sub _checkopts |
518 | { |
519 | my @errors; |
520 | local($") = "\n"; |
521 | |
522 | if ($options->{'log'}) |
523 | { |
524 | $_fh = new FileHandle(">> $options->{'log'}") || push(@errors, "ERROR: Couldn't open $options->{'log'}\n"); |
525 | } |
526 | |
527 | if (($options->{'c'}) && (@ARGV > 1) && ($options->{'sav'} )) |
528 | { |
529 | push(@errors, |
530 | "ERROR: The '-sav' and '-C' options are incompatible when you have more than |
531 | one input file! ('-C' explicitly names resulting C code, '-sav' saves it, |
532 | and hence, with more than one file, the c code will be overwritten for |
533 | each file that you compile)\n"); |
534 | } |
535 | if (($options->{'o'}) && (@ARGV > 1)) |
536 | { |
537 | push(@errors, |
538 | "ERROR: The '-o' option is incompatible when you have more than one input file! |
539 | (-o explicitly names the resulting executable, hence, with more than |
540 | one file the names clash)\n"); |
541 | } |
542 | |
543 | if ($options->{'e'} && $options->{'sav'} && !$options->{'o'} && |
544 | !$options->{'C'}) |
545 | { |
546 | push(@errors, |
547 | "ERROR: You need to specify where you are going to save the resulting |
548 | executable or C code, when using '-sav' and '-e'. Use '-o' or '-C'.\n"); |
549 | } |
550 | |
551 | if (($options->{'regex'} || $options->{'run'} || $options->{'o'}) |
552 | && $options->{'gen'}) |
553 | { |
554 | push(@errors, |
555 | "ERROR: The options '-regex', '-run', and '-o' are incompatible with '-gen'. |
556 | '-gen' says to stop at C generation, and the other three modify the |
557 | compilation and/or running process!\n"); |
558 | } |
559 | |
560 | if ($options->{'run'} && $options->{'mod'}) |
561 | { |
562 | push(@errors, |
563 | "ERROR: Can't run modules that you are compiling! '-run' and '-mod' are |
564 | incompatible!\n"); |
565 | } |
566 | |
567 | if ($options->{'e'} && @ARGV) |
568 | { |
569 | push (@errors, |
570 | "ERROR: The option '-e' needs to be all by itself without any other |
571 | file arguments!\n"); |
572 | } |
573 | if ($options->{'e'} && !($options->{'o'} || $options->{'run'})) |
574 | { |
575 | $options->{'run'} = 1; |
576 | } |
577 | |
578 | if (!defined($options->{'verbose'})) |
579 | { |
580 | $options->{'verbose'} = ($options->{'log'})? 64 : 7; |
581 | } |
582 | |
583 | my $verbose_error; |
584 | |
585 | if ($options->{'verbose'} =~ m"[^tagfcd]" && |
586 | !( $options->{'verbose'} eq '0' || |
587 | ($options->{'verbose'} < 64 && $options->{'verbose'} > 0))) |
588 | { |
589 | $verbose_error = 1; |
590 | push(@errors, |
591 | "ERROR: Illegal verbosity level. Needs to have either the letters |
592 | 't','a','g','f','c', or 'd' in it or be between 0 and 63, inclusive.\n"); |
593 | } |
594 | |
595 | $options->{'verbose'} = ($options->{'verbose'} =~ m"[tagfcd]")? |
596 | ($options->{'verbose'} =~ m"d") * 32 + |
597 | ($options->{'verbose'} =~ m"c") * 16 + |
598 | ($options->{'verbose'} =~ m"f") * 8 + |
599 | ($options->{'verbose'} =~ m"t") * 4 + |
600 | ($options->{'verbose'} =~ m"a") * 2 + |
601 | ($options->{'verbose'} =~ m"g") * 1 |
602 | : $options->{'verbose'}; |
603 | |
604 | if (!$verbose_error && ( $options->{'log'} && |
605 | !( |
606 | ($options->{'verbose'} & 8) || |
607 | ($options->{'verbose'} & 16) || |
608 | ($options->{'verbose'} & 32 ) |
609 | ) |
610 | ) |
611 | ) |
612 | { |
613 | push(@errors, |
614 | "ERROR: The verbosity level '$options->{'verbose'}' does not output anything |
615 | to a logfile, and you specified '-log'!\n"); |
616 | } # } |
617 | |
618 | if (!$verbose_error && ( !$options->{'log'} && |
619 | ( |
620 | ($options->{'verbose'} & 8) || |
621 | ($options->{'verbose'} & 16) || |
622 | ($options->{'verbose'} & 32) || |
623 | ($options->{'verbose'} & 64) |
624 | ) |
625 | ) |
626 | ) |
627 | { |
628 | push(@errors, |
629 | "ERROR: The verbosity level '$options->{'verbose'}' requires that you also |
630 | specify a logfile via '-log'\n"); |
631 | } # } |
632 | |
633 | |
634 | (_print( "\n". join("\n", @errors), -1), return(0)) if (@errors); |
635 | return(1); |
636 | } |
637 | |
638 | sub _print |
639 | { |
640 | my ($text, $flag ) = @_; |
641 | |
642 | my $logflag = int($flag/8) * 8; |
643 | my $regflag = $flag % 8; |
644 | |
645 | if ($flag == -1 || ($flag & $options->{'verbose'})) |
646 | { |
647 | my $dolog = ((($logflag & $options->{'verbose'}) || $flag == -1) |
648 | && $options->{'log'}); |
649 | |
650 | my $doreg = (($regflag & $options->{'verbose'}) || $flag == -1); |
651 | |
652 | if ($doreg) { print( STDERR $text ); } |
653 | if ($dolog) { print $_fh $text; } |
654 | } |
655 | } |
656 | |
657 | sub _run |
658 | { |
659 | my ($command, $flag) = @_; |
660 | |
661 | my $logflag = ($flag != -1)? int($flag/8) * 8 : 0; |
662 | my $regflag = $flag % 8; |
663 | |
664 | if ($flag == -1 || ($flag & $options->{'verbose'})) |
665 | { |
666 | my $dolog = ($logflag & $options->{'verbose'} && $options->{'log'}); |
667 | my $doreg = (($regflag & $options->{'verbose'}) || $flag == -1); |
668 | |
669 | if ($doreg && !$dolog) |
670 | { system("$command"); } |
671 | |
672 | elsif ($doreg && $dolog) |
673 | { my $text = `$command 2>&1`; print $_fh $text; print STDERR $text;} |
674 | else |
675 | { my $text = `$command 2>&1`; print $_fh $text; } |
676 | } |
677 | else |
678 | { |
679 | `$command 2>&1`; |
680 | } |
681 | return($?); |
682 | } |
683 | |
684 | sub _usage |
685 | { |
686 | _print |
687 | ( |
688 | <<"EOF" |
689 | |
690 | Usage: $0 <file_list> |
691 | |
692 | Flags with arguments |
693 | -L < extra library dirs for installation (form of 'dir1:dir2') > |
694 | -I < extra include dirs for installation (form of 'dir1:dir2') > |
695 | -C < explicit name of resulting C code > |
696 | -o < explicit name of resulting executable > |
697 | -e < to compile 'one liners'. Need executable name (-o) or '-run'> |
698 | -regex < rename regex, -regex 's/\.p/\.exe/' compiles a.p to a.exe > |
699 | -verbose < verbose level (1-63, or following letters 'gatfcd' > |
700 | -argv < arguments for the executables to be run via '-run' or '-e' > |
701 | |
702 | Boolean flags |
703 | -gen ( to just generate the c code. Implies '-sav' ) |
704 | -sav ( to save intermediate c code, (and executables with '-run')) |
705 | -run ( to run the compiled program on the fly, as were interpreted.) |
706 | -prog ( to indicate that the files on command line are programs ) |
707 | -mod ( to indicate that the files on command line are modules ) |
708 | |
709 | EOF |
710 | , -1 |
711 | |
712 | ); |
713 | exit(255); |
714 | } |
715 | |
716 | |
717 | __END__ |
718 | |
719 | =head1 NAME |
720 | |
721 | perlcc - frontend for perl compiler |
722 | |
723 | =head1 SYNOPSIS |
724 | |
725 | %prompt perlcc a.p # compiles into executable 'a' |
726 | |
727 | %prompt perlcc A.pm # compile into 'A.so' |
728 | |
729 | %prompt perlcc a.p -o execute # compiles 'a.p' into 'execute'. |
730 | |
731 | %prompt perlcc a.p -o execute -run # compiles 'a.p' into execute, runs on |
732 | # the fly |
733 | |
734 | %prompt perlcc a.p -o execute -run -argv 'arg1 arg2 arg3' |
735 | # compiles into execute, runs with |
736 | # arg1 arg2 arg3 as @ARGV |
737 | |
738 | %prompt perlcc a.p b.p c.p -regex 's/\.p/\.exe' |
739 | # compiles into 'a.exe','b.exe','c.exe'. |
740 | |
741 | %prompt perlcc a.p -log compilelog # compiles into 'a', saves compilation |
742 | # info into compilelog, as well |
743 | # as mirroring to screen |
744 | |
745 | %prompt perlcc a.p -log compilelog -verbose cdf |
746 | # compiles into 'a', saves compilation |
747 | # info into compilelog, being silent |
748 | # on screen. |
749 | |
750 | %prompt perlcc a.p -C a.c -gen # generates C code (into a.c) and |
751 | # stops without compile. |
752 | |
753 | %prompt perlcc a.p -L ../lib a.c |
754 | # Compiles with the perl libraries |
755 | # inside ../lib included. |
756 | |
757 | =head1 DESCRIPTION |
758 | |
759 | 'perlcc' is the frontend into the perl compiler. Typing 'perlcc a.p' |
760 | compiles the code inside a.p into a standalone executable, and |
761 | perlcc A.pm will compile into a shared object, A.so, suitable for inclusion |
762 | into a perl program via "use A". |
763 | |
764 | There are quite a few flags to perlcc which help with such issues as compiling |
765 | programs in bulk, testing compiled programs for compatibility with the |
766 | interpreter, and controlling. |
767 | |
768 | =head1 OPTIONS |
769 | |
770 | =over 4 |
771 | |
772 | =item -L < library_directories > |
773 | |
774 | Adds directories in B<library_directories> to the compilation command. |
775 | |
776 | =item -I < include_directories > |
777 | |
778 | Adds directories inside B<include_directories> to the compilation command. |
779 | |
780 | =item -C < c_code_name > |
781 | |
782 | Explicitly gives the name B<c_code_name> to the generated c code which is to |
783 | be compiled. Can only be used if compiling one file on the command line. |
784 | |
785 | =item -o < executable_name > |
786 | |
787 | Explicitly gives the name B<executable_name> to the executable which is to be |
788 | compiled. Can only be used if compiling one file on the command line. |
789 | |
790 | =item -e < perl_line_to_execute> |
791 | |
792 | Compiles 'one liners', in the same way that B<perl -e> runs text strings at |
793 | the command line. Default is to have the 'one liner' be compiled, and run all |
794 | in one go (see B<-run>); giving the B<-o> flag saves the resultant executable, |
795 | rather than throwing it away. Use '-argv' to pass arguments to the executable |
796 | created. |
797 | |
798 | =item -regex <rename_regex> |
799 | |
800 | Gives a rule B<rename_regex> - which is a legal perl regular expression - to |
801 | create executable file names. |
802 | |
803 | =item -verbose <verbose_level> |
804 | |
805 | Show exactly what steps perlcc is taking to compile your code. You can change |
806 | the verbosity level B<verbose_level> much in the same way that the '-D' switch |
807 | changes perl's debugging level, by giving either a number which is the sum of |
808 | bits you want or a list of letters representing what you wish to see. Here are |
809 | the verbosity levels so far : |
810 | |
811 | Bit 1(g): Code Generation Errors to STDERR |
812 | Bit 2(a): Compilation Errors to STDERR |
813 | Bit 4(t): Descriptive text to STDERR |
814 | Bit 8(f): Code Generation Errors to file (B<-log> flag needed) |
815 | Bit 16(c): Compilation Errors to file (B<-log> flag needed) |
816 | Bit 32(d): Descriptive text to file (B<-log> flag needed) |
817 | |
818 | If the B<-log> tag is given, the default verbose level is 63 (ie: mirroring |
819 | all of perlcc's output to both the screen and to a log file). If no B<-log> |
820 | tag is given, then the default verbose level is 7 (ie: outputting all of |
821 | perlcc's output to STDERR). |
822 | |
823 | NOTE: Because of buffering concerns, you CANNOT shadow the output of '-run' to |
824 | both a file, and to the screen! Suggestions are welcome on how to overcome this |
825 | difficulty, but for now it simply does not work properly, and hence will only go |
826 | to the screen. |
827 | |
828 | =item -log <logname> |
829 | |
830 | Opens, for append, a logfile to save some or all of the text for a given |
831 | compile command. No rewrite version is available, so this needs to be done |
832 | manually. |
833 | |
834 | =item -argv <arguments> |
835 | |
836 | In combination with '-run' or '-e', tells perlcc to run the resulting |
837 | executable with the string B<arguments> as @ARGV. |
838 | |
839 | =item -sav |
840 | |
841 | Tells perl to save the intermediate C code. Usually, this C code is the name |
842 | of the perl code, plus '.c'; 'perlcode.p' gets generated in 'perlcode.p.c', |
843 | for example. If used with the '-e' operator, you need to tell perlcc where to |
844 | save resulting executables. |
845 | |
846 | =item -gen |
847 | |
848 | Tells perlcc to only create the intermediate C code, and not compile the |
849 | results. Does an implicit B<-sav>, saving the C code rather than deleting it. |
850 | |
851 | =item -run |
852 | |
853 | Immediately run the perl code that has been generated. NOTE: IF YOU GIVE THE |
854 | B<-run> FLAG TO B<perlcc>, THEN THE REST OF @ARGV WILL BE INTERPRETED AS |
855 | ARGUMENTS TO THE PROGRAM THAT YOU ARE COMPILING. |
856 | |
857 | =item -prog |
858 | |
859 | Indicate that the programs at the command line are programs, and should be |
860 | compiled as such. B<perlcc> will automatically determine files to be |
861 | programs if they have B<.p>, B<.pl>, B<.bat> extensions. |
862 | |
863 | =item -mod |
864 | |
865 | Indicate that the programs at the command line are modules, and should be |
866 | compiled as such. B<perlcc> will automatically determine files to be |
867 | modules if they have the extension B<.pm>. |
868 | |
869 | =back |
870 | |
871 | =head1 ENVIRONMENT |
872 | |
873 | Most of the work of B<perlcc> is done at the command line. However, you can |
874 | change the heuristic which determines what is a module and what is a program. |
875 | As indicated above, B<perlcc> assumes that the extensions: |
876 | |
877 | .p$, .pl$, and .bat$ |
878 | |
879 | indicate a perl program, and: |
880 | |
881 | .pm$ |
882 | |
883 | indicate a library, for the purposes of creating executables. And furthermore, |
884 | by default, these extensions will be replaced (and dropped ) in the process of |
885 | creating an executable. |
886 | |
887 | To change the extensions which are programs, and which are modules, set the |
888 | environmental variables: |
889 | |
890 | PERL_SCRIPT_EXT |
891 | PERL_MODULE_EXT |
892 | |
893 | These two environmental variables take colon-separated, legal perl regular |
894 | expressions, and are used by perlcc to decide which objects are which. |
895 | For example: |
896 | |
897 | setenv PERL_SCRIPT_EXT '.prl$:.perl$' |
898 | prompt% perlcc sample.perl |
899 | |
900 | will compile the script 'sample.perl' into the executable 'sample', and |
901 | |
902 | setenv PERL_MODULE_EXT '.perlmod$:.perlmodule$' |
903 | |
904 | prompt% perlcc sample.perlmod |
905 | |
906 | will compile the module 'sample.perlmod' into the shared object |
907 | 'sample.so' |
908 | |
909 | NOTE: the '.' in the regular expressions for PERL_SCRIPT_EXT and PERL_MODULE_EXT |
910 | is a literal '.', and not a wild-card. To get a true wild-card, you need to |
911 | backslash the '.'; as in: |
912 | |
913 | setenv PERL_SCRIPT_EXT '\.\.\.\.\.' |
914 | |
915 | which would have the effect of compiling ANYTHING (except what is in |
916 | PERL_MODULE_EXT) into an executable with 5 less characters in its name. |
917 | |
918 | =head1 FILES |
919 | |
920 | 'perlcc' uses a temporary file when you use the B<-e> option to evaluate |
921 | text and compile it. This temporary file is 'perlc$$.p'. The temporary C code is |
922 | perlc$$.p.c, and the temporary executable is perlc$$. |
923 | |
924 | When you use '-run' and don't save your executable, the temporary executable is |
925 | perlc$$ |
926 | |
927 | =head1 BUGS |
928 | |
929 | perlcc currently cannot compile shared objects on Win32. This should be fixed |
930 | by perl5.005. |
931 | |
932 | =cut |
933 | |
934 | !NO!SUBS! |
935 | |
936 | close OUT or die "Can't close $file: $!"; |
937 | chmod 0755, $file or die "Can't reset permissions for $file: $!\n"; |
938 | exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':'; |
8a5546a1 |
939 | chdir $origdir; |