diff options
author | Nicholas Clark <nick@ccl4.org> | 2008-01-04 18:18:02 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2008-01-04 18:18:02 +0000 |
commit | d1f3479f8c62266471eafb582091197ae2cf4cad (patch) | |
tree | 78a7b88892c6eb9d62919aa38e08e9fa18186bf9 /Porting/expand-macro.pl | |
parent | 553688848e7546a541b923ffc9973e898bf5d8aa (diff) | |
download | perl-d1f3479f8c62266471eafb582091197ae2cf4cad.tar.gz |
Add a small program that gets the C pre-processor to expand the macro
passed on the command line.
p4raw-id: //depot/perl@32833
Diffstat (limited to 'Porting/expand-macro.pl')
-rw-r--r-- | Porting/expand-macro.pl | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Porting/expand-macro.pl b/Porting/expand-macro.pl new file mode 100644 index 0000000000..624e7dcdb4 --- /dev/null +++ b/Porting/expand-macro.pl @@ -0,0 +1,58 @@ +#!perl -w +use strict; + +use vars qw($trysource $tryout $sentinel); +$trysource = "try.c"; +$tryout = "try.i"; + +my $macro = shift; +die "$0 macro [headers]" unless defined $macro; + +$sentinel = "$macro expands to"; + +foreach($trysource, $tryout) { + die "You already have a $_" if -e $_; +} + +if (!@ARGV) { + open my $fh, '<', 'MANIFEST' or die "Can't open MANIFEST: $!"; + while (<$fh>) { + push @ARGV, $1 if m!^([^/]+\.h)\t!; + } +} + +my $args = ''; + +while (<>) { + next unless /^#\s*define\s+$macro/; + my ($def_args) = /^#\s*define\s+$macro\(([^)]*)\)/; + if (defined $def_args) { + my @args = split ',', $def_args; + my $argname = "A0"; + $args = '(' . join (', ', map {$argname++} 1..@args) . ')'; + } + last; +} + +open my $out, '>', $trysource or die "Can't open $trysource: $!"; + +print $out <<"EOF"; +#include "EXTERN.h" +#include "perl.h" +#line 3 "$sentinel" +$macro$args +EOF + +close $out or die "Can't close $trysource: $!"; + +system "make $tryout" and die; + +open my $fh, '<', $tryout or die "Can't open $tryout: $!"; + +while (<$fh>) { + print if /$sentinel/o .. 1; +} + +foreach($trysource, $tryout) { + die "Can't unlink $_" unless unlink $_; +} |