2 # reads CPP output and turns #line things into appropriate Haskell
5 # considered to be GHC-project specific
8 # NOTE: this script needs RAWCPP set in order to do something
14 while ( $#ARGV >= 0 && $ARGV[0] eq '-v' ) {
15 if ($ARGV[0] eq '-v') {
18 die "hscpp: unrecognised argument: $$ARGV[0]\n";
22 #ToDo: print a version number ?
26 if ( $OrigCpp =~ /(\S+)\s+(.*)/ ) {
29 if ( -x $cmd ) { # cool
31 } else { # oops; try to guess
32 $GccV = `gcc -v 2>&1`;
33 if ( $GccV =~ /Reading specs from (.*)\/specs/ ) {
34 $Cpp = "$1/cpp $rest";
36 die "hscpp: don't know how to run cpp: $OrigCpp\n";
43 print STDERR "hscpp:CPP invoked: $Cpp @ARGV\n" if $Verbose;
45 open(INPIPE, "$Cpp @ARGV |") || die "Can't open C pre-processor pipe\n";
49 # line directives come in flavo[u]rs:
50 # s/^#\s*line\s+\d+$/\{\-# LINE \-\}/; IGNORE THIS ONE FOR NOW
51 s/^#\s*line\s+(\d+)\s+(\".+\")$/\{\-# LINE \1 \2 \-\}/;
52 s/^#\s*(\d+)\s+(\".*\").*/\{\-# LINE \1 \2 \-\}/;
57 close(INPIPE) || exit(1); # exit is so we reflect any errors.