automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

msvisualcpp-cpp: New depmode


From: Ryan T. Sammartino
Subject: msvisualcpp-cpp: New depmode
Date: Sat, 23 Mar 2002 20:09:42 -0800
User-agent: Mutt/1.3.27i

This patch adds a new depmode called "msvisualcpp-cpp".
This depmode uses Cygwin/GNU's /usr/bin/cpp to compute dependencies
while cl.exe does the compiling.  This is way faster than running
cygpath -u on cl.exe -E's output, and avoids the problems outlined
in http://sources.redhat.com/ml/automake/2001-12/msg00012.html.

However, I'm doing a few things that perhaps aren't so cool... some
input is requested.

As you can see, I test to see if cpp fails by checking if $tmpdepfile
actually got created; if not, I dump the output from cpp's stderr.
Is the 2>cppstderr ok?  Is there a better way to do this?

You will also note that I pass -w -D_WIN32 -D_M_IX86 to cpp.
Is there anything else I need to pass?  I thought I might have needed to
set _MSC_VER, but in my (limited) testing it didn't seem to make a
difference.  Is -w (inhibit warnings) a good idea?  MS Visual Studio
header files produce so many preprocessor warnings that it is impossible
to wade through them all to find the errors, so I just turn off the
warnings.

Another thing to note is that I create the "missing header file" section
a little differently than the gcc) depmod does.  The "tr ' ' '
'" thing does not work correctly for lines that look like (e.g.):

   c:/Program\ Files/Microsoft\ Visual\ Studio/.... \

so instead I use a sed script to break on spaces that aren't followed by
\.

Anyways, look it over and let me know what you think.

CC:'s on replies appreciated.


23-03-2002 Ryan T. Sammartino <address@hidden>
        * lib/depcomp (msvisualcpp-cpp): new depmode that uses Cygwin cpp
        to compute dependencies instead of cl.exe -E



Index: lib/depcomp
===================================================================
RCS file: /cvs/automake/automake/lib/depcomp,v
retrieving revision 1.31
diff -u -3 -b -r1.31 depcomp
--- depcomp     2002/02/19 19:11:50     1.31
+++ depcomp     2002/03/24 04:02:11
@@ -422,6 +422,71 @@
   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> 
"$depfile"
   rm -f "$tmpdepfile"
   ;;
+
+msvisualcpp-cpp)
+  # Use Cygwin cpp to compute dependencies, cl.exe to compile.
+  (
+    shift
+    cleared=no
+    for arg in "$@" ; do
+      case $cleared in no)
+        set ""; shift
+        cleared=yes
+      esac
+      case "$arg" in
+        -D*|-I*)
+          set fnord "$@" "$arg" ; shift ;;
+        /D*|/I*)
+          # Change /D and /I to -D and -I
+          foo=$(echo $arg | sed 's/\/\([DI]\)/-\1/')
+          set fnord "$@" "$foo" ; shift ;;
+        -*|/*|"$object"|"$source")
+          # Delete these from list of arguments
+          ;;
+        *)
+          set fnord "$@" "$arg" ; shift ;;
+      esac
+    done
+    rm -f "$tmpdepfile"
+    ${CPP-cpp} "$@" "-w" "-D_WIN32" "-D_M_IX86" "-Wp,-MD,$tmpdepfile" 
"$source" 2>cppstderr >/dev/null
+    if test -e "$tmpdepfile" ; then
+      rm -f "$depfile"
+      echo "$object : \\" > "$depfile"
+      alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
+      ## The second -e expression handles DOS-style file names with
+      ## drive letters.
+      sed -e 's/^[^:]*: / /' \
+          -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
+      ## This next piece of magic avoids the `deleted header file' problem.
+      ## The problem is that when a header file which appears in a .P file
+      ## is deleted, the dependency causes make to die (because there is
+      ## typically no way to rebuild the header).  We avoid this by adding
+      ## dummy dependencies for each header file.  Too bad cpp doesn't do
+      ## this for us directly.
+      sed -e 's/\([^\\] \)/\1\
+/' -e 's/^ \+//' -e 's/\\$//' < "$tmpdepfile" |
+      ## Some versions of gcc put a space before the `:'.  On the theory
+      ## that the space means something, we add a space to the output as
+      ## well.
+      ## Some versions of the HPUX 10.20 sed can't process this invocation
+      ## correctly.  Breaking it into two sed invocations is a workaround.
+      sed -e 's/^\\$//' -e '/^$/d' -e '/: *$/d' -e 's/ \+$//' | sed -e 
's/$/:/' >> "$depfile"
+      rm -f "$tmpdepfile"
+    else
+      rm -f "$depfile"
+      echo "$object : $source" > "$depfile"
+      echo "${CPP-cpp}: warning: failed to compute dependencies for $object"
+      echo "${CPP-cpp}: $(cat cppstderr)"
+    fi
+    rm -f cppstderr
+  ) &
+  proc=$!
+  "$@"
+  stat=$?
+  wait "$proc"
+  if test "$stat" != 0 ; then exit $stat; fi
+  ;;
+
 
 none)
   exec "$@"


-- 
Ryan T. Sammartino
http://members.shaw.ca/ryants/
The human brain is a wonderful thing.  It starts working the moment
you are born, and never stops until you stand up to speak in public.
                -- Sir George Jessel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]