2
2
# depcomp - compile a program generating dependencies as side-effects
4
scriptversion=2012-03-27.16; # UTC
4
scriptversion=2012-07-12.20; # UTC
6
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
7
# 2011, 2012 Free Software Foundation, Inc.
6
# Copyright (C) 1999-2012 Free Software Foundation, Inc.
9
8
# This program is free software; you can redistribute it and/or modify
10
9
# it under the terms of the GNU General Public License as published by
148
## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
149
## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
150
## (see the conditional assignment to $gccflag above).
146
151
## There are various ways to get dependency output from gcc. Here's
147
152
## why we pick this rather obscure method:
148
153
## - Don't want to use -MD because we'd like the dependencies to end
149
154
## up in a subdir. Having to rename by hand is ugly.
150
155
## (We might end up doing this anyway to support other compilers.)
151
156
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
152
## -MM, not -M (despite what the docs say).
157
## -MM, not -M (despite what the docs say). Also, it might not be
158
## supported by the other compilers which use the 'gcc' depmode.
153
159
## - Using -M directly means running the compiler twice (even worse
154
160
## than renaming).
155
161
if test -z "$gccflag"; then
335
341
rm -f "$tmpdepfile"
344
## The order of this option in the case statement is important, since the
345
## shell code in configure will try each of these formats in the order
346
## listed in this file. A plain '-MD' option would be understood by many
347
## compilers, so we must ensure this comes after the gcc and icc options.
349
# Portland's C compiler understands '-MD'.
350
# Will always output deps to 'file.d' where file is the root name of the
351
# source file under compilation, even if file resides in a subdirectory.
352
# The object file name does not affect the name of the '.d' file.
353
# pgcc 10.2 will output
354
# foo.o: sub/foo.c sub/foo.h
355
# and will wrap long lines using '\' :
356
# foo.o: sub/foo.c ... \
359
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
360
test "x$dir" = "x$object" && dir=
361
# Use the source, not the object, to determine the base name, since
362
# that's sadly what pgcc will do too.
363
base=`echo "$source" | sed -e 's|^.*/||' -e 's/\.[-_a-zA-Z0-9]*$//'`
366
# For projects that build the same source file twice into different object
367
# files, the pgcc approach of using the *source* file root name can cause
368
# problems in parallel builds. Use a locking strategy to avoid stomping on
369
# the same $tmpdepfile.
370
lockdir="$base.d-lock"
371
trap "echo '$0: caught signal, cleaning up...' >&2; rm -rf $lockdir" 1 2 13 15
374
while test $i -gt 0 ; do
375
# mkdir is a portable test-and-set.
376
if mkdir $lockdir 2>/dev/null; then
377
# This process acquired the lock.
384
## the lock is being held by a different process,
385
## wait until the winning process is done or we timeout
386
while test -d $lockdir && test $i -gt 0; do
394
if test $i -le 0; then
395
echo "$0: failed to acquire lock after $numtries attempts" >&2
396
echo "$0: check lockdir '$lockdir'" >&2
400
if test $stat -ne 0; then
405
# Each line is of the form `foo.o: dependent.h',
406
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
407
# Do two passes, one to just change these to
408
# `$object: dependent.h' and one to simply `dependent.h:'.
409
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
410
# Some versions of the HPUX 10.20 sed can't process this invocation
411
# correctly. Breaking it into two sed invocations is a workaround.
412
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
413
sed -e 's/$/ :/' >> "$depfile"
339
418
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
340
419
# compilers, which have integrated preprocessors. The correct option