From a977810779813388908daa6dbe57d9d1a05baaa3 Mon Sep 17 00:00:00 2001
From: simonmar <unknown>
Date: Wed, 14 Jul 1999 13:26:52 +0000
Subject: [PATCH] [project @ 1999-07-14 13:26:48 by simonmar] Don't attempt to
 discover the exact location of cpp, instead use 'gcc -E'.  With the right
 combination of flags, it seems we can get the same behaviour as calling cpp
 directly.

---
 aclocal.m4                          | 32 +-----------------
 configure.in                        |  1 -
 ghc/utils/hscpp/Makefile            |  8 +----
 ghc/utils/hscpp/hscpp.prl           | 52 ++++++++++++-----------------
 ghc/utils/mkdependHS/Makefile       |  3 +-
 ghc/utils/mkdependHS/mkdependHS.prl |  2 +-
 6 files changed, 26 insertions(+), 72 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index c79cef4c414e..9ae64495b7ec 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,4 +1,4 @@
-dnl $Id: aclocal.m4,v 1.42 1999/06/07 10:12:52 simonmar Exp $
+dnl $Id: aclocal.m4,v 1.43 1999/07/14 13:26:48 simonmar Exp $
 dnl 
 dnl Extra autoconf macros for the Glasgow fptools
 dnl
@@ -303,36 +303,6 @@ HaveGcc=`echo $fptools_cv_have_gcc | sed 'y/yesno/YESNO/'`
 AC_SUBST(HaveGcc)
 ])
 
-dnl
-dnl FPTOOLS_PROG_GNUCPP gathers the path to the cpp that the
-dnl gcc driver calls upon.
-dnl
-dnl Substitutes: GNUCPP and RAWCPP (latter is 'GNUCPP -traditional')
-dnl
-AC_DEFUN(FPTOOLS_PROG_GNUCPP,
-[AC_CACHE_CHECK([how to invoke GNU cpp directly], fptools_cv_gnu_cpp,
-[if test "$HaveGcc" = "YES"; then
-	echo > conftest.c
-	$CC -v -E conftest.c >/dev/null 2>conftest.out
-	# \x5c = backslash
-	echo 'tr/\x5c/\//; /(\S+\/)cpp/ && print "[$]{1}cpp -iprefix [$]1";' > conftest.pl
-	fptools_cv_gnu_cpp="`eval $PerlCmd -n conftest.pl conftest.out`"
-	rm -fr conftest*
- else
-	# We need to be able to invoke CPP directly, preferably
-	# with input from stdin (mkdependHS and hscpp depend on
-	# this at the moment).
-	# Take a guess at what to use, this probably won't work.
-	echo Warning: GNU cpp not found, using $CPP
-	fptools_cv_gnu_cpp = $CPP
- fi
-])
-GNUCPP=$fptools_cv_gnu_cpp
-RAWCPP="$GNUCPP -traditional"
-AC_SUBST(GNUCPP)
-AC_SUBST(RAWCPP)
-])
-
 dnl Small feature test for perl version. Assumes PerlCmd
 dnl contains path to perl binary
 dnl
diff --git a/configure.in b/configure.in
index 71730250582f..e9a6e18ef6bd 100644
--- a/configure.in
+++ b/configure.in
@@ -402,7 +402,6 @@ FPTOOLS_HAVE_GCC
 
 dnl ** figure out how to invoke cpp directly (gcc -E is no good)
 AC_PROG_CPP
-FPTOOLS_PROG_GNUCPP
 
 dnl ** figure out how to do context diffs
 FPTOOLS_PROG_DIFF
diff --git a/ghc/utils/hscpp/Makefile b/ghc/utils/hscpp/Makefile
index e4af0ed35d37..d9191865a7c5 100644
--- a/ghc/utils/hscpp/Makefile
+++ b/ghc/utils/hscpp/Makefile
@@ -3,17 +3,11 @@ include $(TOP)/mk/boilerplate.mk
 
 SCRIPT_PROG=hscpp
 SCRIPT_OBJS=hscpp.prl
-SCRIPT_SUBST_VARS=
-
-ifneq "$(BIN_DIST)" "1"
-SCRIPT_SUBST_VARS += RAWCPP
-endif
+SCRIPT_SUBST_VARS= RAWCPP
 
 # Note: might be overridden from cmd-line (see install rule below)
 INSTALLING=0
 
-# no INTERP: do *not* want #! script stuck on the front
-# what's the deal? I'll add it for now  -- SOF
 INTERP=perl
 
 #
diff --git a/ghc/utils/hscpp/hscpp.prl b/ghc/utils/hscpp/hscpp.prl
index 12d4038126ad..8d753e5553d6 100644
--- a/ghc/utils/hscpp/hscpp.prl
+++ b/ghc/utils/hscpp/hscpp.prl
@@ -10,46 +10,36 @@
 #
 
 $Verbose = 0;
+$file = '';
+@args = ();
 
-while ( $#ARGV >= 0 &&  $ARGV[0] eq '-v' ) {
-    if ($ARGV[0] eq '-v') {
-	$Verbose = 1;
-    } else {
-	die "hscpp: unrecognised argument: $$ARGV[0]\n";
-    }
-    shift(@ARGV);
-}
-#ToDo: print a version number ?
-
-$OrigCpp = ${RAWCPP};
-
-if ( $OrigCpp =~ /(\S+)\s+(.*)/ ) {
-    $cmd  = $1;
-    $rest = $2;
-    if ( -x $cmd ) { # cool
-	$Cpp = $OrigCpp;
-    } else { # oops; try to guess
-	$GccV = `gcc -v 2>&1`;
-	if ( $GccV =~ /Reading specs from (.*)\/specs/ ) {
-	    $Cpp = "$1/cpp $rest";
+$Cpp = ${RAWCPP};
+
+foreach (@ARGV) {
+    /^-v$/ && do { $Verbose = 1; next; };
+
+    /^[^-]/ && do { 
+	if ($file ne '') { 
+	    die "usage: hscpp [arg...] file";
 	} else {
-	    die "hscpp: don't know how to run cpp: $OrigCpp\n";
-	}
-    }
-} else {
-    $Cpp = $OrigCpp;
-}
+	    $file = $_; 
+	};
+	next;
+    };
 
-print STDERR "hscpp:CPP invoked: $Cpp @ARGV\n" if $Verbose;
+    push @args, $_;
+}
 
-open(INPIPE, "$Cpp @ARGV |") || die "Can't open C pre-processor pipe\n";
+print STDERR "hscpp:CPP invoked: $Cpp @args - <$file\n" if $Verbose;
+open(INPIPE, "$Cpp @args - <$file |") 
+	|| die "Can't open C pre-processor pipe\n";
 
 while (<INPIPE>) {
 
 # line directives come in flavo[u]rs:
 #   s/^#\s*line\s+\d+$/\{\-# LINE \-\}/;   IGNORE THIS ONE FOR NOW
-    s/^#\s*line\s+(\d+)\s+(\".+\")$/\{\-# LINE \1 \2 \-\}/;
-    s/^#\s*(\d+)\s+(\".*\").*/\{\-# LINE \1 \2 \-\}/;
+    s/^#\s*line\s+(\d+)\s+(\".+\")$/\{\-# LINE \1 \"$file\" \-\}/;
+    s/^#\s*(\d+)\s+(\".*\").*/\{\-# LINE \1 \"$file\" \-\}/;
 
     print $_;
 }
diff --git a/ghc/utils/mkdependHS/Makefile b/ghc/utils/mkdependHS/Makefile
index 61042ccc56f6..6f8fe79c051a 100644
--- a/ghc/utils/mkdependHS/Makefile
+++ b/ghc/utils/mkdependHS/Makefile
@@ -10,6 +10,7 @@ SCRIPT_OBJS=mkdependHS.prl
 SCRIPT_SUBST_VARS= \
  TOP_PWD \
  INSTALLING \
+ RAWCPP \
  HscIfaceFileVersion
 
 INTERP=perl
@@ -20,7 +21,7 @@ INTERP=perl
 INSTALL_LIB_SCRIPTS += $(SCRIPT_PROG)
 
 ifneq "$(BIN_DIST)" "1"
-SCRIPT_SUBST_VARS += libdir datadir RAWCPP TMPDIR SED
+SCRIPT_SUBST_VARS += libdir datadir TMPDIR SED
 endif
 
 
diff --git a/ghc/utils/mkdependHS/mkdependHS.prl b/ghc/utils/mkdependHS/mkdependHS.prl
index cb3769559250..3cd94bdbffbe 100644
--- a/ghc/utils/mkdependHS/mkdependHS.prl
+++ b/ghc/utils/mkdependHS/mkdependHS.prl
@@ -390,7 +390,7 @@ sub slurp_file_for_imports {
     local ($open_cmd);
     if ($Cpp_flag_set) {
 #       $open_cmd = "${SED} -e '/^# *include/{p;s/^# *include/!include/;};s/'\\''//g;s/\"//g' $file_to_read | $Cpp $Include_dirs -I$last_seen_dir @Defines |";
-       &run_something("${SED} -e '/^# *include/{p;s/^# *include/!include/;};s/'\\''//g;s/\"//g' $file_to_read | $Cpp $Include_dirs -I$last_seen_dir @Defines 2>&1 > ${file_to_read}.i", $orig_src_file, 'cpp');
+       &run_something("${SED} -e '/^# *include/{p;s/^# *include/!include/;};s/'\\''//g;s/\"//g' $file_to_read | $Cpp $Include_dirs -I$last_seen_dir @Defines - 2>&1 > ${file_to_read}.i", $orig_src_file, 'cpp');
        $read_from_file="${file_to_read}.i";
        $cleanup=1;
     } else {
-- 
GitLab