4 use File::Basename qw(basename dirname);
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
12 # to ensure Configure will look for $Config{startperl}.
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.
19 $file = basename($0, '.PL');
20 $file .= '.com' if $^O eq 'VMS';
22 open OUT,">$file" or die "Can't create $file: $!";
24 print "Extracting $file (with variable substitutions)\n";
26 # In this section, perl variables will be expanded during extraction.
27 # You can use $Config{...} to use Configure variables.
29 print OUT <<"!GROK!THIS!";
31 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
32 if \$running_under_some_shell;
35 # In the following, perl variables are not expanded during extraction.
37 print OUT <<'!NO!SUBS!';
42 use File::Path qw(mkpath);
45 # Make sure read permissions for all are set:
46 if (defined umask && (umask() & 0444)) {
47 umask (umask() & ~0444);
51 use vars qw($opt_D $opt_d $opt_r $opt_l $opt_h $opt_a $opt_Q $opt_e);
52 die "-r and -a options are mutually exclusive\n" if ($opt_r and $opt_a);
53 my @inc_dirs = inc_dirs() if $opt_a;
57 my $Dest_dir = $opt_d || $Config{installsitearch};
58 die "Destination directory $Dest_dir doesn't exist or isn't a directory\n"
71 @isatype{@isatype} = (1) x @isatype;
76 @ARGV = ('-') unless @ARGV;
78 build_preamble_if_necessary();
87 my ($t, $tab, %curargs, $new, $eval_index, $dir, $name, $args, $outfile);
88 my ($incl, $incl_type, $incl_quote, $next);
89 while (defined (my $file = next_file())) {
90 if (-l $file and -d $file) {
91 link_if_possible($file) if ($opt_l);
95 # Recover from header files with unbalanced cpp directives
99 # $eval_index goes into '#line' directives, to help locate syntax errors:
106 ($outfile = $file) =~ s/\.h$/.ph/ || next;
107 print "$file -> $outfile\n" unless $opt_Q;
108 if ($file =~ m|^(.*)/|) {
110 mkpath "$Dest_dir/$dir";
113 if ($opt_a) { # automagic mode: locate header file in @inc_dirs
114 foreach (@inc_dirs) {
120 open(IN,"$file") || (($Exit = 1),(warn "Can't open $file: $!\n"),next);
121 open(OUT,">$Dest_dir/$outfile") || die "Can't create $outfile: $!\n";
125 "require '_h2ph_pre.ph';\n\n",
126 "no warnings qw(redefine misc);\n\n";
128 while (defined (local $_ = next_line($file))) {
130 if (s/^define\s+(\w+)//) {
134 s/\(\w+\s*\(\*\)\s*\(\w*\)\)\s*(-?\d+)/$1/; # (int (*)(foo_t))0
135 if (s/^\(([\w,\s]*)\)//) {
140 foreach my $arg (split(/,\s*/,$args)) {
141 $arg =~ s/^\s*([^\s].*[^\s])\s*$/$1/;
144 $args =~ s/\b(\w)/\$$1/g;
145 $args = "my($args) = \@_;\n$t ";
149 $new =~ s/(["\\])/\\$1/g; #"]);
155 $new = 1 if $new eq '';
157 # Shunt around such directives as '#define FOO FOO':
158 next if $new =~ /^\s*&\Q$name\E\s*\z/;
160 $new = reindent($new);
161 $args = reindent($args);
162 $new =~ s/(['\\])/\\$1/g; #']);
164 print OUT $t, 'eval ';
166 print OUT "\"\\n#line $eval_index $outfile\\n\" . ";
169 print OUT "'sub $name () {$new;}' unless defined(&$name);\n";
171 } elsif (/^(include|import|include_next)\s*([<\"])(.*)[>\"]/) {
175 if (($incl_type eq 'include_next') ||
176 ($opt_e && exists($bad_file{$incl}))) {
177 $incl =~ s/\.h$/.ph/;
181 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
182 print OUT ($t, "my(\@REM);\n");
183 if ($incl_type eq 'include_next') {
185 "my(\%INCD) = map { \$INC{\$_} => 1 } ",
186 "(grep { \$_ eq \"$incl\" } ",
189 "\@REM = map { \"\$_/$incl\" } ",
190 "(grep { not exists(\$INCD{\"\$_/$incl\"})",
191 " and -f \"\$_/$incl\" } \@INC);\n");
194 "\@REM = map { \"\$_/$incl\" } ",
195 "(grep {-r \"\$_/$incl\" } \@INC);\n");
198 "require \"\$REM[0]\" if \@REM;\n");
200 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
204 "warn(\$\@) if \$\@;\n");
206 $incl =~ s/\.h$/.ph/;
207 # copy the prefix in the quote syntax (#include "x.h") case
208 if ($incl !~ m|/| && $incl_quote eq q{"} && $file =~ m|^(.*)/|) {
211 print OUT $t,"require '$incl';\n";
213 } elsif (/^ifdef\s+(\w+)/) {
214 print OUT $t,"if(defined(&$1)) {\n";
216 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
217 } elsif (/^ifndef\s+(\w+)/) {
218 print OUT $t,"unless(defined(&$1)) {\n";
220 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
221 } elsif (s/^if\s+//) {
226 print OUT $t,"if($new) {\n";
228 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
229 } elsif (s/^elif\s+//) {
235 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
236 print OUT $t,"}\n elsif($new) {\n";
238 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
241 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
242 print OUT $t,"} else {\n";
244 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
247 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
249 } elsif(/^undef\s+(\w+)/) {
250 print OUT $t, "undef(&$1) if defined(&$1);\n";
251 } elsif(/^error\s+(".*")/) {
252 print OUT $t, "die($1);\n";
253 } elsif(/^error\s+(.*)/) {
254 print OUT $t, "die(\"", quotemeta($1), "\");\n";
255 } elsif(/^warning\s+(.*)/) {
256 print OUT $t, "warn(\"", quotemeta($1), "\");\n";
257 } elsif(/^ident\s+(.*)/) {
258 print OUT $t, "# $1\n";
260 } elsif (/^\s*(typedef\s*)?enum\s*(\s+[a-zA-Z_]\w*\s*)?/) { # { for vi
261 until(/\{[^}]*\}.*;/ || /;/) {
262 last unless defined ($next = next_line($file));
264 # drop "#define FOO FOO" in enums
265 $next =~ s/^\s*#\s*define\s+(\w+)\s+\1\s*$//;
266 # #defines in enums (aliases)
267 $next =~ s/^\s*#\s*define\s+(\w+)\s+(\w+)\s*$/$1 = $2,/;
269 print OUT "# $next\n" if $opt_D;
271 s/#\s*if.*?#\s*endif//g; # drop #ifdefs
274 next unless /^\s?(typedef\s?)?enum\s?([a-zA-Z_]\w*)?\s?\{(.*)\}\s?([a-zA-Z_]\w*)?\s?;/;
275 (my $enum_subs = $3) =~ s/\s//g;
276 my @enum_subs = split(/,/, $enum_subs);
278 foreach my $enum (@enum_subs) {
279 my ($enum_name, $enum_value) = $enum =~ /^([a-zA-Z_]\w*)(=.+)?$/;
281 $enum_value =~ s/^=//;
282 $enum_val = (length($enum_value) ? $enum_value : $enum_val + 1);
285 "eval(\"\\n#line $eval_index $outfile\\n",
286 "sub $enum_name () \{ $enum_val; \}\") ",
287 "unless defined(\&$enum_name);\n");
291 "eval(\"sub $enum_name () \{ $enum_val; \}\") ",
292 "unless defined(\&$enum_name);\n");
295 } elsif (/^(?:__extension__\s+)?(?:extern|static)\s+(?:__)?inline(?:__)?\s+/
296 and !/;\s*$/ and !/{\s*}\s*$/)
298 # This is a hack to parse the inline functions in the glibc headers.
299 # Warning: massive kludge ahead. We suppose inline functions
300 # are mainly constructed like macros.
302 last unless defined ($next = next_line($file));
304 undef $_, last if $next =~ /__THROW\s*;/
305 or $next =~ /^(__extension__|extern|static)\b/;
307 print OUT "# $next\n" if $opt_D;
308 last if $next =~ /^}|^{.*}\s*$/;
310 next if not defined; # because it's only a prototype
311 s/\b(__extension__|extern|static|(?:__)?inline(?:__)?)\b//g;
312 # violently drop #ifdefs
313 s/#\s*if.*?#\s*endif//g
314 and print OUT "# some #ifdef were dropped here -- fill in the blanks\n";
315 if (s/^(?:\w|\s|\*)*\s(\w+)\s*//) {
318 warn "name not found"; next; # shouldn't occur...
321 if (s/^\(([^()]*)\)\s*(\w+\s*)*//) {
322 for my $arg (split /,/, $1) {
323 if ($arg =~ /(\w+)\s*$/) {
331 ? "my(" . (join ',', map "\$$_", @args) . ") = \@_;\n$t "
334 my $proto = @args ? '' : '() ';
336 s/\breturn\b//g; # "return" doesn't occur in macros usually...
338 # try to find and perlify local C variables
339 our @local_variables = (); # needs to be a our(): (?{...}) bug workaround
342 my $typelist = join '|', keys %isatype;
344 (?:(?:__)?const(?:__)?\s+)?
345 (?:(?:un)?signed\s+)?
349 (?{ push @local_variables, $1 })
353 (?:(?:__)?const(?:__)?\s+)?
354 (?:(?:un)?signed\s+)?
358 (?{ push @local_variables, $1 })
362 $new =~ s/&$_\b/\$$_/g for @local_variables;
363 $new =~ s/(["\\])/\\$1/g; #"]);
364 # now that's almost like a macro (we hope)
368 $Is_converted{$file} = 1;
369 if ($opt_e && exists($bad_file{$file})) {
370 unlink($Dest_dir . '/' . $outfile);
374 queue_includes_from($file) if $opt_a;
378 if ($opt_e && (scalar(keys %bad_file) > 0)) {
379 warn "Was unable to convert the following files:\n";
380 warn "\t" . join("\n\t",sort(keys %bad_file)) . "\n";
388 $new = reindent($new);
389 $args = reindent($args);
391 $new =~ s/(['\\])/\\$1/g; #']);
394 "eval \"\\n#line $eval_index $outfile\\n\" . 'sub $name $proto\{\n$t ${args}eval q($new);\n$t}' unless defined(\&$name);\n";
398 "eval 'sub $name $proto\{\n$t ${args}eval q($new);\n$t}' unless defined(\&$name);\n";
401 print OUT "unless(defined(\&$name)) {\n sub $name $proto\{\n\t${args}eval q($new);\n }\n}\n";
408 if (/\b__asm__\b/) { # freak out
409 $new = '"(assembly code)"';
414 $joined_args = join('|', keys(%curargs));
417 s/^\&\&// && do { $new .= " &&"; next;}; # handle && operator
418 s/^\&([\(a-z\)]+)/$1/i; # hack for things that take the address of
419 s/^(\s+)// && do {$new .= ' '; next;};
420 s/^0X([0-9A-F]+)[UL]*//i
423 if (length $hex > 8 && !$Config{use64bitint}) {
424 # Croak if nv_preserves_uv_bits < 64 ?
425 $new .= hex(substr($hex, -8)) +
426 2**32 * hex(substr($hex, 0, -8));
427 # The above will produce "erroneous" code
428 # if the hex constant was e.g. inside UINT64_C
429 # macro, but then again, h2ph is an approximation.
431 $new .= lc("0x$hex");
434 s/^(-?\d+\.\d+E[-+]?\d+)[FL]?//i && do {$new .= $1; next;};
435 s/^(\d+)\s*[LU]*//i && do {$new .= $1; next;};
436 s/^("(\\"|[^"])*")// && do {$new .= $1; next;};
437 s/^'((\\"|[^"])*)'// && do {
439 $new .= "ord('\$$1')";
445 # replace "sizeof(foo)" with "{foo}"
446 # also, remove * (C dereference operator) to avoid perl syntax
447 # problems. Where the %sizeof array comes from is anyone's
448 # guess (c2ph?), but this at least avoids fatal syntax errors.
449 # Behavior is undefined if sizeof() delimiters are unbalanced.
450 # This code was modified to able to handle constructs like this:
451 # sizeof(*(p)), which appear in the HP-UX 10.01 header files.
452 s/^sizeof\s*\(// && do {
454 my $lvl = 1; # already saw one open paren
455 # tack { on the front, and skip it in the loop
458 # find balanced closing paren
459 while ($index <= length($_) && $lvl > 0) {
460 $lvl++ if substr($_, $index, 1) eq "(";
461 $lvl-- if substr($_, $index, 1) eq ")";
464 # tack } on the end, replacing )
465 substr($_, $index - 1, 1) = "}";
466 # remove pesky * operators within the sizeof argument
467 substr($_, 0, $index - 1) =~ s/\*//g;
471 /\(([\w\s]+)[\*\s]*\)\s*[\w\(]/ && do {
473 foreach (split /\s+/, $1) { # Make sure all the words are types,
474 unless($isatype{$_} or $_ eq 'struct' or $_ eq 'union'){
480 s/\([\w\s]+[\*\s]*\)// && next; # then eliminate them.
483 # struct/union member, including arrays:
484 s/^([_A-Z]\w*(\[[^\]]+\])?((\.|->)[_A-Z]\w*(\[[^\]]+\])?)+)//i && do {
486 $id =~ s/(\.|(->))([^\.\-]*)/->\{$3\}/g;
487 $id =~ s/\b([^\$])($joined_args)/$1\$$2/g if length($joined_args);
488 while($id =~ /\[\s*([^\$\&\d\]]+)\]/) {
491 if(exists($curargs{$index})) {
496 $id =~ s/\[\s*([^\$\&\d\]]+)\]/[$index]/;
500 s/^([_a-zA-Z]\w*)// && do {
502 if ($id eq 'struct' || $id eq 'union') {
506 } elsif ($id =~ /^((un)?signed)|(long)|(short)$/) {
507 while (s/^\s+(\w+)//) { $id .= ' ' . $1; }
512 $new .= '->' if /^[\[\{]/;
513 } elsif ($id eq 'defined') {
516 s/^\s*\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i; # cheat
518 } elsif ($isatype{$id}) {
519 if ($new =~ /\{\s*$/) {
521 } elsif ($new =~ /\(\s*$/ && /^[\s*]*\)/) {
525 $new .= q(').$id.q(');
529 if ($new =~ /defined\s*$/) {
530 $new .= '(&' . $id . ')';
531 } elsif ($new =~ /defined\s*\($/) {
534 $new .= '(defined(&' . $id . ') ? &' . $id . ' : undef)';
544 s/^(.)// && do { if ($1 ne '#') { $new .= $1; } next;};
553 my $pre_sub_tri_graphs = 1;
555 READ: while (not eof IN) {
558 next unless length $in;
561 if ($pre_sub_tri_graphs) {
562 # Preprocess all tri-graphs
563 # including things stuck in quoted string constants.
564 $in =~ s/\?\?=/#/g; # | ??=| #|
565 $in =~ s/\?\?\!/|/g; # | ??!| ||
566 $in =~ s/\?\?'/^/g; # | ??'| ^|
567 $in =~ s/\?\?\(/[/g; # | ??(| [|
568 $in =~ s/\?\?\)/]/g; # | ??)| ]|
569 $in =~ s/\?\?\-/~/g; # | ??-| ~|
570 $in =~ s/\?\?\//\\/g; # | ??/| \|
571 $in =~ s/\?\?</{/g; # | ??<| {|
572 $in =~ s/\?\?>/}/g; # | ??>| }|
574 if ($in =~ /^\#ifdef __LANGUAGE_PASCAL__/) {
575 # Tru64 disassembler.h evilness: mixed C and Pascal.
582 if ($in =~ /^extern inline / && # Inlined assembler.
583 $^O eq 'linux' && $file =~ m!(?:^|/)asm/[^/]+\.h$!) {
590 if ($in =~ s/\\$//) { # \-newline
593 } elsif ($in =~ s/^([^"'\\\/]+)//) { # Passthrough
595 } elsif ($in =~ s/^(\\.)//) { # \...
597 } elsif ($in =~ /^'/) { # '...
598 if ($in =~ s/^('(\\.|[^'\\])*')//) {
603 } elsif ($in =~ /^"/) { # "...
604 if ($in =~ s/^("(\\.|[^"\\])*")//) {
609 } elsif ($in =~ s/^\/\/.*//) { # //...
611 } elsif ($in =~ m/^\/\*/) { # /*...
612 # C comment removal adapted from perlfaq6:
613 if ($in =~ s/^\/\*[^*]*\*+([^\/*][^*]*\*+)*\///) {
615 } else { # Incomplete /* */
618 } elsif ($in =~ s/^(\/)//) { # /...
620 } elsif ($in =~ s/^([^\'\"\\\/]+)//) {
622 } elsif ($^O eq 'linux' &&
623 $file =~ m!(?:^|/)linux/byteorder/pdp_endian\.h$! &&
624 $in =~ s!\'T KNOW!!) {
625 $out =~ s!I DON$!I_DO_NOT_KNOW!;
628 warn "Cannot parse $file:\n$in\n";
629 $bad_file{$file} = 1;
634 die "Cannot parse:\n$in\n";
639 last READ if $out =~ /\S/;
646 # Handle recursive subdirectories without getting a grotesquely big stack.
647 # Could this be implemented using File::Find?
655 if ($file eq '-' or -f $file or -l $file) {
661 print STDERR "Skipping directory '$file'\n";
666 print STDERR "Skipping '$file': not a file or directory\n";
674 # Put all the files in $directory into @ARGV for processing.
677 my ($directory) = @_;
679 $directory =~ s:/$::;
681 opendir DIR, $directory;
682 foreach (readdir DIR) {
683 next if ($_ eq '.' or $_ eq '..');
685 # expand_glob() is going to be called until $ARGV[0] isn't a
686 # directory; so push directories, and unshift everything else.
687 if (-d "$directory/$_") { push @ARGV, "$directory/$_" }
688 else { unshift @ARGV, "$directory/$_" }
694 # Given $file, a symbolic link to a directory in the C include directory,
695 # make an equivalent symbolic link in $Dest_dir, if we can figure out how.
696 # Otherwise, just duplicate the file or directory.
700 my $target = eval 'readlink($dirlink)';
702 if ($target =~ m:^\.\./: or $target =~ m:^/:) {
703 # The target of a parent or absolute link could leave the $Dest_dir
704 # hierarchy, so let's put all of the contents of $dirlink (actually,
705 # the contents of $target) into @ARGV; as a side effect down the
706 # line, $dirlink will get created as an _actual_ directory.
707 expand_glob($dirlink);
709 if (-l "$Dest_dir/$dirlink") {
710 unlink "$Dest_dir/$dirlink" or
711 print STDERR "Could not remove link $Dest_dir/$dirlink: $!\n";
714 if (eval 'symlink($target, "$Dest_dir/$dirlink")') {
715 print "Linking $target -> $Dest_dir/$dirlink\n";
717 # Make sure that the link _links_ to something:
718 if (! -e "$Dest_dir/$target") {
719 mkpath("$Dest_dir/$target", 0755) or
720 print STDERR "Could not create $Dest_dir/$target/\n";
723 print STDERR "Could not symlink $target -> $Dest_dir/$dirlink: $!\n";
729 # Push all #included files in $file onto our stack, except for STDIN
730 # and files we've already processed.
731 sub queue_includes_from
736 return if ($file eq "-");
738 open HEADER, $file or return;
739 while (defined($line = <HEADER>)) {
740 while (/\\$/) { # Handle continuation lines
745 if ($line =~ /^#\s*include\s+([<"])(.*?)[>"]/) {
746 my ($delimiter, $new_file) = ($1, $2);
747 # copy the prefix in the quote syntax (#include "x.h") case
748 if ($delimiter eq q{"} && $file =~ m|^(.*)/|) {
749 $new_file = "$1/$new_file";
751 push(@ARGV, $new_file) unless $Is_converted{$new_file};
758 # Determine include directories; $Config{usrinc} should be enough for (all
759 # non-GCC?) C compilers, but gcc uses additional include directories.
762 my $from_gcc = `LC_ALL=C $Config{cc} -v -E - < /dev/null 2>&1 | awk '/^#include/, /^End of search list/' | grep '^ '`;
763 length($from_gcc) ? (split(' ', $from_gcc), $Config{usrinc}) : ($Config{usrinc});
767 # Create "_h2ph_pre.ph", if it doesn't exist or was built by a different
769 sub build_preamble_if_necessary
771 # Increment $VERSION every time this function is modified:
773 my $preamble = "$Dest_dir/_h2ph_pre.ph";
775 # Can we skip building the preamble file?
777 # Extract version number from first line of preamble:
778 open PREAMBLE, $preamble or die "Cannot open $preamble: $!";
779 my $line = <PREAMBLE>;
780 $line =~ /(\b\d+\b)/;
781 close PREAMBLE or die "Cannot close $preamble: $!";
783 # Don't build preamble if a compatible preamble exists:
784 return if $1 == $VERSION;
787 my (%define) = _extract_cc_defines();
789 open PREAMBLE, ">$preamble" or die "Cannot open $preamble: $!";
790 print PREAMBLE "# This file was created by h2ph version $VERSION\n";
791 # Prevent non-portable hex constants from warning.
793 # We still produce an overflow warning if we can't represent
794 # a hex constant as an integer.
795 print PREAMBLE "no warnings qw(portable);\n";
797 foreach (sort keys %define) {
799 print PREAMBLE "# $_=$define{$_}\n";
801 if ($define{$_} =~ /^\((.*)\)$/) {
802 # parenthesized value: d=(v)
805 if (/^(\w+)\((\w)\)$/) {
806 my($macro, $arg) = ($1, $2);
807 my $def = $define{$_};
808 $def =~ s/$arg/\$\{$arg\}/g;
809 print PREAMBLE <<DEFINE;
810 unless (defined &$macro) { sub $macro(\$) { my (\$$arg) = \@_; \"$def\" } }
814 ($define{$_} =~ /^([+-]?(\d+)?\.\d+([eE][+-]?\d+)?)[FL]?$/) {
817 "unless (defined &$_) { sub $_() { $1 } }\n\n";
818 } elsif ($define{$_} =~ /^([+-]?\d+)U?L{0,2}$/i) {
821 "unless (defined &$_) { sub $_() { $1 } }\n\n";
822 } elsif ($define{$_} =~ /^([+-]?0x[\da-f]+)U?L{0,2}$/i) {
824 # Special cased, since perl warns on hex integers
825 # that can't be represented in a UV.
827 # This way we get the warning at time of use, so the user
828 # only gets the warning if they happen to use this
829 # platform-specific definition.
831 $code = "hex('$code')" if length $code > 10;
833 "unless (defined &$_) { sub $_() { $code } }\n\n";
834 } elsif ($define{$_} =~ /^\w+$/) {
835 my $def = $define{$_};
836 if ($isatype{$def}) {
838 "unless (defined &$_) { sub $_() { \"$def\" } }\n\n";
841 "unless (defined &$_) { sub $_() { &$def } }\n\n";
845 "unless (defined &$_) { sub $_() { \"",
846 quotemeta($define{$_}), "\" } }\n\n";
849 print PREAMBLE "\n1;\n"; # avoid 'did not return a true value' when empty
850 close PREAMBLE or die "Cannot close $preamble: $!";
854 # %Config contains information on macros that are pre-defined by the
855 # system's compiler. We need this information to make the .ph files
856 # function with perl as the .h files do with cc.
857 sub _extract_cc_defines
860 my $allsymbols = join " ",
861 @Config{'ccsymbols', 'cppsymbols', 'cppccsymbols'};
863 # Split compiler pre-definitions into 'key=value' pairs:
864 while ($allsymbols =~ /([^\s]+)=((\\\s|[^\s])+)/g) {
867 print STDERR "$_: $1 -> $2\n";
877 ##############################################################################
882 h2ph - convert .h C header files to .ph Perl header files
886 B<h2ph [-d destination directory] [-r | -a] [-l] [-h] [-e] [-D] [-Q]
892 converts any C header files specified to the corresponding Perl header file
894 It is most easily run while in /usr/include:
896 cd /usr/include; h2ph * sys/*
900 cd /usr/include; h2ph * sys/* arpa/* netinet/*
904 cd /usr/include; h2ph -r -l .
906 The output files are placed in the hierarchy rooted at Perl's
907 architecture dependent library directory. You can specify a different
908 hierarchy with a B<-d> switch.
910 If run with no arguments, filters standard input to standard output.
916 =item -d destination_dir
918 Put the resulting B<.ph> files beneath B<destination_dir>, instead of
919 beneath the default Perl library location (C<$Config{'installsitearch'}>).
923 Run recursively; if any of B<headerfiles> are directories, then run I<h2ph>
924 on all files in those directories (and their subdirectories, etc.). B<-r>
925 and B<-a> are mutually exclusive.
929 Run automagically; convert B<headerfiles>, as well as any B<.h> files
930 which they include. This option will search for B<.h> files in all
931 directories which your C compiler ordinarily uses. B<-a> and B<-r> are
936 Symbolic links will be replicated in the destination directory. If B<-l>
937 is not specified, then links are skipped over.
941 Put 'hints' in the .ph files which will help in locating problems with
942 I<h2ph>. In those cases when you B<require> a B<.ph> file containing syntax
943 errors, instead of the cryptic
945 [ some error condition ] at (eval mmm) line nnn
947 you will see the slightly more helpful
949 [ some error condition ] at filename.ph line nnn
951 However, the B<.ph> files almost double in size when built using B<-h>.
955 If an error is encountered during conversion, output file will be removed and
956 a warning emitted instead of terminating the conversion immediately.
960 Include the code from the B<.h> file as a comment in the B<.ph> file.
961 This is primarily used for debugging I<h2ph>.
965 'Quiet' mode; don't print out the names of the files being converted.
971 No environment variables are used.
990 The usual warnings if it can't read or write the files involved.
994 Doesn't construct the %sizeof array for you.
996 It doesn't handle all C constructs, but it does attempt to isolate
997 definitions inside evals so that you can get at the definitions
998 that it can translate.
1000 It's only intended as a rough tool.
1001 You may need to dicker with the files produced.
1003 You have to run this program by hand; it's not run as part of the Perl
1006 Doesn't handle complicated expressions built piecemeal, a la:
1016 Doesn't necessarily locate all of your C compiler's internally-defined
1023 close OUT or die "Can't close $file: $!";
1024 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
1025 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';