Reading the documentation provided here:

  <http://www.pgroup.com/doc/pgiref.pdf>
I see that the the '-MD' option should also accept an argument:

  -MD,filename  (pgcpp only) Generate make dependence lists and print
                             them to file filename.

maybe we could we use this to get rid of the need of the horrid file-locking
hack -- explained in this comments from depcomp:

  # For projects that build the same source file twice into different object
  # files, the pgcc approach of using the *source* file root name can cause
  # problems in parallel builds.  Use a locking strategy to avoid stomping on
  # the same $tmpdepfile.

In particular, I propose the attached patch.  Can you give it a try to check
whether it works?

Thanks,
  Stefano
>From d847fe2011811a1f924ac4bb0502d4802ab94c5e Mon Sep 17 00:00:00 2001
Message-Id: <d847fe2011811a1f924ac4bb0502d4802ab94c5e.1342125705.git.stefano.lattar...@gmail.com>
From: Stefano Lattarini <stefano.lattar...@gmail.com>
Date: Thu, 12 Jul 2012 22:37:24 +0200
Subject: [PATCH] depcomp: get rid of file-lock hack for Portland Group
 Compilers

* lib/depcomp (pgcc): The modern pgcc compilers seems to accept an
argument for the '-MD' option (as in "-MD,depfile"), according to
<http://www.pgroup.com/doc/pgiref.pdf>, and we can use this feature
to greatly simplify our code, in particular getting rid of a brittle
hack based on file locks.

Signed-off-by: Stefano Lattarini <stefano.lattar...@gmail.com>
---
 lib/depcomp |   54 ++++++------------------------------------------------
 1 file changed, 6 insertions(+), 48 deletions(-)

diff --git a/lib/depcomp b/lib/depcomp
index 0544c68..7adbeab 100755
--- a/lib/depcomp
+++ b/lib/depcomp
@@ -334,62 +334,20 @@ icc)
   rm -f "$tmpdepfile"
   ;;
 
-## The order of this option in the case statement is important, since the
-## shell code in configure will try each of these formats in the order
-## listed in this file.  A plain '-MD' option would be understood by many
+## The order of this option in the case statement might important, since
+## the shell code in configure will try each of these formats in the order
+## listed in this file.  The '-MD' below might be understood by many
 ## compilers, so we must ensure this comes after the gcc and icc options.
 pgcc)
-  # Portland's C compiler understands '-MD'.
-  # Will always output deps to 'file.d' where file is the root name of the
-  # source file under compilation, even if file resides in a subdirectory.
-  # The object file name does not affect the name of the '.d' file.
+  # Portland's C compiler understands '-MF,depfile'.
   # pgcc 10.2 will output
   #    foo.o: sub/foo.c sub/foo.h
   # and will wrap long lines using '\' :
   #    foo.o: sub/foo.c ... \
   #     sub/foo.h ... \
   #     ...
-  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
-  test "x$dir" = "x$object" && dir=
-  # Use the source, not the object, to determine the base name, since
-  # that's sadly what pgcc will do too.
-  base=`echo "$source" | sed -e 's|^.*/||' -e 's/\.[-_a-zA-Z0-9]*$//'`
-  tmpdepfile="$base.d"
-
-  # For projects that build the same source file twice into different object
-  # files, the pgcc approach of using the *source* file root name can cause
-  # problems in parallel builds.  Use a locking strategy to avoid stomping on
-  # the same $tmpdepfile.
-  lockdir="$base.d-lock"
-  trap "echo '$0: caught signal, cleaning up...' >&2; rm -rf $lockdir" 1 2 13 15
-  numtries=100
-  i=$numtries
-  while test $i -gt 0 ; do
-    # mkdir is a portable test-and-set.
-    if mkdir $lockdir 2>/dev/null; then
-      # This process acquired the lock.
-      "$@" -MD
-      stat=$?
-      # Release the lock.
-      rm -rf $lockdir
-      break
-    else
-      ## the lock is being held by a different process,
-      ## wait until the winning process is done or we timeout
-      while test -d $lockdir && test $i -gt 0; do
-        sleep 1
-        i=`expr $i - 1`
-      done
-    fi
-    i=`expr $i - 1`
-  done
-  trap - 1 2 13 15
-  if test $i -le 0; then
-    echo "$0: failed to acquire lock after $numtries attempts" >&2
-    echo "$0: check lockdir '$lockdir'" >&2
-    exit 1
-  fi
-
+  "$@" -MD,"$tempfile"
+  stat=$?
   if test $stat -ne 0; then
     rm -f "$tmpdepfile"
     exit $stat
-- 
1.7.9.5

Reply via email to