12a6b7db3Sskrll#! /bin/sh 22a6b7db3Sskrll# depcomp - compile a program generating dependencies as side-effects 32a6b7db3Sskrll 4*9573673dSchristosscriptversion=2013-05-30.07; # UTC 52a6b7db3Sskrll 6*9573673dSchristos# Copyright (C) 1999-2014 Free Software Foundation, Inc. 72a6b7db3Sskrll 82a6b7db3Sskrll# This program is free software; you can redistribute it and/or modify 92a6b7db3Sskrll# it under the terms of the GNU General Public License as published by 102a6b7db3Sskrll# the Free Software Foundation; either version 2, or (at your option) 112a6b7db3Sskrll# any later version. 122a6b7db3Sskrll 132a6b7db3Sskrll# This program is distributed in the hope that it will be useful, 142a6b7db3Sskrll# but WITHOUT ANY WARRANTY; without even the implied warranty of 152a6b7db3Sskrll# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 162a6b7db3Sskrll# GNU General Public License for more details. 172a6b7db3Sskrll 182a6b7db3Sskrll# You should have received a copy of the GNU General Public License 19be9ac0eaSchristos# along with this program. If not, see <http://www.gnu.org/licenses/>. 202a6b7db3Sskrll 212a6b7db3Sskrll# As a special exception to the GNU General Public License, if you 222a6b7db3Sskrll# distribute this file as part of a program that contains a 232a6b7db3Sskrll# configuration script generated by Autoconf, you may include it under 242a6b7db3Sskrll# the same distribution terms that you use for the rest of that program. 252a6b7db3Sskrll 262a6b7db3Sskrll# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 272a6b7db3Sskrll 282a6b7db3Sskrllcase $1 in 292a6b7db3Sskrll '') 30*9573673dSchristos echo "$0: No command. Try '$0 --help' for more information." 1>&2 312a6b7db3Sskrll exit 1; 322a6b7db3Sskrll ;; 332a6b7db3Sskrll -h | --h*) 342a6b7db3Sskrll cat <<\EOF 352a6b7db3SskrllUsage: depcomp [--help] [--version] PROGRAM [ARGS] 362a6b7db3Sskrll 372a6b7db3SskrllRun PROGRAMS ARGS to compile a file, generating dependencies 382a6b7db3Sskrllas side-effects. 392a6b7db3Sskrll 402a6b7db3SskrllEnvironment variables: 412a6b7db3Sskrll depmode Dependency tracking mode. 42*9573673dSchristos source Source file read by 'PROGRAMS ARGS'. 43*9573673dSchristos object Object file output by 'PROGRAMS ARGS'. 442a6b7db3Sskrll DEPDIR directory where to store dependencies. 452a6b7db3Sskrll depfile Dependency file to output. 46*9573673dSchristos tmpdepfile Temporary file to use when outputting dependencies. 472a6b7db3Sskrll libtool Whether libtool is used (yes/no). 482a6b7db3Sskrll 492a6b7db3SskrllReport bugs to <bug-automake@gnu.org>. 502a6b7db3SskrllEOF 512a6b7db3Sskrll exit $? 522a6b7db3Sskrll ;; 532a6b7db3Sskrll -v | --v*) 542a6b7db3Sskrll echo "depcomp $scriptversion" 552a6b7db3Sskrll exit $? 562a6b7db3Sskrll ;; 572a6b7db3Sskrllesac 582a6b7db3Sskrll 59*9573673dSchristos# Get the directory component of the given path, and save it in the 60*9573673dSchristos# global variables '$dir'. Note that this directory component will 61*9573673dSchristos# be either empty or ending with a '/' character. This is deliberate. 62*9573673dSchristosset_dir_from () 63*9573673dSchristos{ 64*9573673dSchristos case $1 in 65*9573673dSchristos */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66*9573673dSchristos *) dir=;; 67*9573673dSchristos esac 68*9573673dSchristos} 69*9573673dSchristos 70*9573673dSchristos# Get the suffix-stripped basename of the given path, and save it the 71*9573673dSchristos# global variable '$base'. 72*9573673dSchristosset_base_from () 73*9573673dSchristos{ 74*9573673dSchristos base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75*9573673dSchristos} 76*9573673dSchristos 77*9573673dSchristos# If no dependency file was actually created by the compiler invocation, 78*9573673dSchristos# we still have to create a dummy depfile, to avoid errors with the 79*9573673dSchristos# Makefile "include basename.Plo" scheme. 80*9573673dSchristosmake_dummy_depfile () 81*9573673dSchristos{ 82*9573673dSchristos echo "#dummy" > "$depfile" 83*9573673dSchristos} 84*9573673dSchristos 85*9573673dSchristos# Factor out some common post-processing of the generated depfile. 86*9573673dSchristos# Requires the auxiliary global variable '$tmpdepfile' to be set. 87*9573673dSchristosaix_post_process_depfile () 88*9573673dSchristos{ 89*9573673dSchristos # If the compiler actually managed to produce a dependency file, 90*9573673dSchristos # post-process it. 91*9573673dSchristos if test -f "$tmpdepfile"; then 92*9573673dSchristos # Each line is of the form 'foo.o: dependency.h'. 93*9573673dSchristos # Do two passes, one to just change these to 94*9573673dSchristos # $object: dependency.h 95*9573673dSchristos # and one to simply output 96*9573673dSchristos # dependency.h: 97*9573673dSchristos # which is needed to avoid the deleted-header problem. 98*9573673dSchristos { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99*9573673dSchristos sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100*9573673dSchristos } > "$depfile" 101*9573673dSchristos rm -f "$tmpdepfile" 102*9573673dSchristos else 103*9573673dSchristos make_dummy_depfile 104*9573673dSchristos fi 105*9573673dSchristos} 106*9573673dSchristos 107*9573673dSchristos# A tabulation character. 108*9573673dSchristostab=' ' 109*9573673dSchristos# A newline character. 110*9573673dSchristosnl=' 111*9573673dSchristos' 112*9573673dSchristos# Character ranges might be problematic outside the C locale. 113*9573673dSchristos# These definitions help. 114*9573673dSchristosupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115*9573673dSchristoslower=abcdefghijklmnopqrstuvwxyz 116*9573673dSchristosdigits=0123456789 117*9573673dSchristosalpha=${upper}${lower} 118*9573673dSchristos 1192a6b7db3Sskrllif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1202a6b7db3Sskrll echo "depcomp: Variables source, object and depmode must be set" 1>&2 1212a6b7db3Sskrll exit 1 1222a6b7db3Sskrllfi 1232a6b7db3Sskrll 1242a6b7db3Sskrll# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1252a6b7db3Sskrlldepfile=${depfile-`echo "$object" | 1262a6b7db3Sskrll sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1272a6b7db3Sskrlltmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1282a6b7db3Sskrll 1292a6b7db3Sskrllrm -f "$tmpdepfile" 1302a6b7db3Sskrll 131*9573673dSchristos# Avoid interferences from the environment. 132*9573673dSchristosgccflag= dashmflag= 133*9573673dSchristos 1342a6b7db3Sskrll# Some modes work just like other modes, but use different flags. We 1352a6b7db3Sskrll# parameterize here, but still list the modes in the big case below, 1362a6b7db3Sskrll# to make depend.m4 easier to write. Note that we *cannot* use a case 1372a6b7db3Sskrll# here, because this file can only contain one case statement. 1382a6b7db3Sskrllif test "$depmode" = hp; then 1392a6b7db3Sskrll # HP compiler uses -M and no extra arg. 1402a6b7db3Sskrll gccflag=-M 1412a6b7db3Sskrll depmode=gcc 1422a6b7db3Sskrllfi 1432a6b7db3Sskrll 1442a6b7db3Sskrllif test "$depmode" = dashXmstdout; then 1452a6b7db3Sskrll # This is just like dashmstdout with a different argument. 1462a6b7db3Sskrll dashmflag=-xM 1472a6b7db3Sskrll depmode=dashmstdout 1482a6b7db3Sskrllfi 1492a6b7db3Sskrll 150be9ac0eaSchristoscygpath_u="cygpath -u -f -" 151be9ac0eaSchristosif test "$depmode" = msvcmsys; then 152be9ac0eaSchristos # This is just like msvisualcpp but w/o cygpath translation. 153be9ac0eaSchristos # Just convert the backslash-escaped backslashes to single forward 154be9ac0eaSchristos # slashes to satisfy depend.m4 155*9573673dSchristos cygpath_u='sed s,\\\\,/,g' 156be9ac0eaSchristos depmode=msvisualcpp 157be9ac0eaSchristosfi 158be9ac0eaSchristos 159*9573673dSchristosif test "$depmode" = msvc7msys; then 160*9573673dSchristos # This is just like msvc7 but w/o cygpath translation. 161*9573673dSchristos # Just convert the backslash-escaped backslashes to single forward 162*9573673dSchristos # slashes to satisfy depend.m4 163*9573673dSchristos cygpath_u='sed s,\\\\,/,g' 164*9573673dSchristos depmode=msvc7 165*9573673dSchristosfi 166*9573673dSchristos 167*9573673dSchristosif test "$depmode" = xlc; then 168*9573673dSchristos # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169*9573673dSchristos gccflag=-qmakedep=gcc,-MF 170*9573673dSchristos depmode=gcc 171*9573673dSchristosfi 172*9573673dSchristos 1732a6b7db3Sskrllcase "$depmode" in 1742a6b7db3Sskrllgcc3) 1752a6b7db3Sskrll## gcc 3 implements dependency tracking that does exactly what 1762a6b7db3Sskrll## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1772a6b7db3Sskrll## it if -MD -MP comes after the -MF stuff. Hmm. 178be9ac0eaSchristos## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179be9ac0eaSchristos## the command line argument order; so add the flags where they 180be9ac0eaSchristos## appear in depend2.am. Note that the slowdown incurred here 181be9ac0eaSchristos## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182be9ac0eaSchristos for arg 183be9ac0eaSchristos do 184be9ac0eaSchristos case $arg in 185be9ac0eaSchristos -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186be9ac0eaSchristos *) set fnord "$@" "$arg" ;; 187be9ac0eaSchristos esac 188be9ac0eaSchristos shift # fnord 189be9ac0eaSchristos shift # $arg 190be9ac0eaSchristos done 191be9ac0eaSchristos "$@" 1922a6b7db3Sskrll stat=$? 193*9573673dSchristos if test $stat -ne 0; then 1942a6b7db3Sskrll rm -f "$tmpdepfile" 1952a6b7db3Sskrll exit $stat 1962a6b7db3Sskrll fi 1972a6b7db3Sskrll mv "$tmpdepfile" "$depfile" 1982a6b7db3Sskrll ;; 1992a6b7db3Sskrll 2002a6b7db3Sskrllgcc) 201*9573673dSchristos## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202*9573673dSchristos## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203*9573673dSchristos## (see the conditional assignment to $gccflag above). 2042a6b7db3Sskrll## There are various ways to get dependency output from gcc. Here's 2052a6b7db3Sskrll## why we pick this rather obscure method: 2062a6b7db3Sskrll## - Don't want to use -MD because we'd like the dependencies to end 2072a6b7db3Sskrll## up in a subdir. Having to rename by hand is ugly. 2082a6b7db3Sskrll## (We might end up doing this anyway to support other compilers.) 2092a6b7db3Sskrll## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210*9573673dSchristos## -MM, not -M (despite what the docs say). Also, it might not be 211*9573673dSchristos## supported by the other compilers which use the 'gcc' depmode. 2122a6b7db3Sskrll## - Using -M directly means running the compiler twice (even worse 2132a6b7db3Sskrll## than renaming). 2142a6b7db3Sskrll if test -z "$gccflag"; then 2152a6b7db3Sskrll gccflag=-MD, 2162a6b7db3Sskrll fi 2172a6b7db3Sskrll "$@" -Wp,"$gccflag$tmpdepfile" 2182a6b7db3Sskrll stat=$? 219*9573673dSchristos if test $stat -ne 0; then 2202a6b7db3Sskrll rm -f "$tmpdepfile" 2212a6b7db3Sskrll exit $stat 2222a6b7db3Sskrll fi 2232a6b7db3Sskrll rm -f "$depfile" 2242a6b7db3Sskrll echo "$object : \\" > "$depfile" 225*9573673dSchristos # The second -e expression handles DOS-style file names with drive 226*9573673dSchristos # letters. 2272a6b7db3Sskrll sed -e 's/^[^:]*: / /' \ 2282a6b7db3Sskrll -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229*9573673dSchristos## This next piece of magic avoids the "deleted header file" problem. 2302a6b7db3Sskrll## The problem is that when a header file which appears in a .P file 2312a6b7db3Sskrll## is deleted, the dependency causes make to die (because there is 2322a6b7db3Sskrll## typically no way to rebuild the header). We avoid this by adding 2332a6b7db3Sskrll## dummy dependencies for each header file. Too bad gcc doesn't do 2342a6b7db3Sskrll## this for us directly. 235*9573673dSchristos## Some versions of gcc put a space before the ':'. On the theory 2362a6b7db3Sskrll## that the space means something, we add a space to the output as 237*9573673dSchristos## well. hp depmode also adds that space, but also prefixes the VPATH 238*9573673dSchristos## to the object. Take care to not repeat it in the output. 2392a6b7db3Sskrll## Some versions of the HPUX 10.20 sed can't process this invocation 2402a6b7db3Sskrll## correctly. Breaking it into two sed invocations is a workaround. 241*9573673dSchristos tr ' ' "$nl" < "$tmpdepfile" \ 242*9573673dSchristos | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243*9573673dSchristos | sed -e 's/$/ :/' >> "$depfile" 2442a6b7db3Sskrll rm -f "$tmpdepfile" 2452a6b7db3Sskrll ;; 2462a6b7db3Sskrll 2472a6b7db3Sskrllhp) 2482a6b7db3Sskrll # This case exists only to let depend.m4 do its work. It works by 2492a6b7db3Sskrll # looking at the text of this script. This case will never be run, 2502a6b7db3Sskrll # since it is checked for above. 2512a6b7db3Sskrll exit 1 2522a6b7db3Sskrll ;; 2532a6b7db3Sskrll 254*9573673dSchristosxlc) 255*9573673dSchristos # This case exists only to let depend.m4 do its work. It works by 256*9573673dSchristos # looking at the text of this script. This case will never be run, 257*9573673dSchristos # since it is checked for above. 258*9573673dSchristos exit 1 2592a6b7db3Sskrll ;; 2602a6b7db3Sskrll 2612a6b7db3Sskrllaix) 2622a6b7db3Sskrll # The C for AIX Compiler uses -M and outputs the dependencies 2632a6b7db3Sskrll # in a .u file. In older versions, this file always lives in the 264*9573673dSchristos # current directory. Also, the AIX compiler puts '$object:' at the 2652a6b7db3Sskrll # start of each line; $object doesn't have directory information. 2662a6b7db3Sskrll # Version 6 uses the directory in both cases. 267*9573673dSchristos set_dir_from "$object" 268*9573673dSchristos set_base_from "$object" 2692a6b7db3Sskrll if test "$libtool" = yes; then 270be9ac0eaSchristos tmpdepfile1=$dir$base.u 271be9ac0eaSchristos tmpdepfile2=$base.u 272be9ac0eaSchristos tmpdepfile3=$dir.libs/$base.u 2732a6b7db3Sskrll "$@" -Wc,-M 2742a6b7db3Sskrll else 275be9ac0eaSchristos tmpdepfile1=$dir$base.u 276be9ac0eaSchristos tmpdepfile2=$dir$base.u 277be9ac0eaSchristos tmpdepfile3=$dir$base.u 2782a6b7db3Sskrll "$@" -M 2792a6b7db3Sskrll fi 2802a6b7db3Sskrll stat=$? 281*9573673dSchristos if test $stat -ne 0; then 282be9ac0eaSchristos rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 2832a6b7db3Sskrll exit $stat 2842a6b7db3Sskrll fi 2852a6b7db3Sskrll 286be9ac0eaSchristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 287be9ac0eaSchristos do 288be9ac0eaSchristos test -f "$tmpdepfile" && break 289be9ac0eaSchristos done 290*9573673dSchristos aix_post_process_depfile 291*9573673dSchristos ;; 292*9573673dSchristos 293*9573673dSchristostcc) 294*9573673dSchristos # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 295*9573673dSchristos # FIXME: That version still under development at the moment of writing. 296*9573673dSchristos # Make that this statement remains true also for stable, released 297*9573673dSchristos # versions. 298*9573673dSchristos # It will wrap lines (doesn't matter whether long or short) with a 299*9573673dSchristos # trailing '\', as in: 300*9573673dSchristos # 301*9573673dSchristos # foo.o : \ 302*9573673dSchristos # foo.c \ 303*9573673dSchristos # foo.h \ 304*9573673dSchristos # 305*9573673dSchristos # It will put a trailing '\' even on the last line, and will use leading 306*9573673dSchristos # spaces rather than leading tabs (at least since its commit 0394caf7 307*9573673dSchristos # "Emit spaces for -MD"). 308*9573673dSchristos "$@" -MD -MF "$tmpdepfile" 309*9573673dSchristos stat=$? 310*9573673dSchristos if test $stat -ne 0; then 311*9573673dSchristos rm -f "$tmpdepfile" 312*9573673dSchristos exit $stat 3132a6b7db3Sskrll fi 314*9573673dSchristos rm -f "$depfile" 315*9573673dSchristos # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 316*9573673dSchristos # We have to change lines of the first kind to '$object: \'. 317*9573673dSchristos sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 318*9573673dSchristos # And for each line of the second kind, we have to emit a 'dep.h:' 319*9573673dSchristos # dummy dependency, to avoid the deleted-header problem. 320*9573673dSchristos sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3212a6b7db3Sskrll rm -f "$tmpdepfile" 3222a6b7db3Sskrll ;; 3232a6b7db3Sskrll 324*9573673dSchristos## The order of this option in the case statement is important, since the 325*9573673dSchristos## shell code in configure will try each of these formats in the order 326*9573673dSchristos## listed in this file. A plain '-MD' option would be understood by many 327*9573673dSchristos## compilers, so we must ensure this comes after the gcc and icc options. 328*9573673dSchristospgcc) 329*9573673dSchristos # Portland's C compiler understands '-MD'. 330*9573673dSchristos # Will always output deps to 'file.d' where file is the root name of the 331*9573673dSchristos # source file under compilation, even if file resides in a subdirectory. 332*9573673dSchristos # The object file name does not affect the name of the '.d' file. 333*9573673dSchristos # pgcc 10.2 will output 3342a6b7db3Sskrll # foo.o: sub/foo.c sub/foo.h 335*9573673dSchristos # and will wrap long lines using '\' : 3362a6b7db3Sskrll # foo.o: sub/foo.c ... \ 3372a6b7db3Sskrll # sub/foo.h ... \ 3382a6b7db3Sskrll # ... 339*9573673dSchristos set_dir_from "$object" 340*9573673dSchristos # Use the source, not the object, to determine the base name, since 341*9573673dSchristos # that's sadly what pgcc will do too. 342*9573673dSchristos set_base_from "$source" 343*9573673dSchristos tmpdepfile=$base.d 3442a6b7db3Sskrll 345*9573673dSchristos # For projects that build the same source file twice into different object 346*9573673dSchristos # files, the pgcc approach of using the *source* file root name can cause 347*9573673dSchristos # problems in parallel builds. Use a locking strategy to avoid stomping on 348*9573673dSchristos # the same $tmpdepfile. 349*9573673dSchristos lockdir=$base.d-lock 350*9573673dSchristos trap " 351*9573673dSchristos echo '$0: caught signal, cleaning up...' >&2 352*9573673dSchristos rmdir '$lockdir' 353*9573673dSchristos exit 1 354*9573673dSchristos " 1 2 13 15 355*9573673dSchristos numtries=100 356*9573673dSchristos i=$numtries 357*9573673dSchristos while test $i -gt 0; do 358*9573673dSchristos # mkdir is a portable test-and-set. 359*9573673dSchristos if mkdir "$lockdir" 2>/dev/null; then 360*9573673dSchristos # This process acquired the lock. 361*9573673dSchristos "$@" -MD 3622a6b7db3Sskrll stat=$? 363*9573673dSchristos # Release the lock. 364*9573673dSchristos rmdir "$lockdir" 365*9573673dSchristos break 3662a6b7db3Sskrll else 367*9573673dSchristos # If the lock is being held by a different process, wait 368*9573673dSchristos # until the winning process is done or we timeout. 369*9573673dSchristos while test -d "$lockdir" && test $i -gt 0; do 370*9573673dSchristos sleep 1 371*9573673dSchristos i=`expr $i - 1` 372*9573673dSchristos done 373*9573673dSchristos fi 374*9573673dSchristos i=`expr $i - 1` 375*9573673dSchristos done 376*9573673dSchristos trap - 1 2 13 15 377*9573673dSchristos if test $i -le 0; then 378*9573673dSchristos echo "$0: failed to acquire lock after $numtries attempts" >&2 379*9573673dSchristos echo "$0: check lockdir '$lockdir'" >&2 380*9573673dSchristos exit 1 381*9573673dSchristos fi 382*9573673dSchristos 383*9573673dSchristos if test $stat -ne 0; then 3842a6b7db3Sskrll rm -f "$tmpdepfile" 3852a6b7db3Sskrll exit $stat 3862a6b7db3Sskrll fi 3872a6b7db3Sskrll rm -f "$depfile" 3882a6b7db3Sskrll # Each line is of the form `foo.o: dependent.h', 3892a6b7db3Sskrll # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 3902a6b7db3Sskrll # Do two passes, one to just change these to 3912a6b7db3Sskrll # `$object: dependent.h' and one to simply `dependent.h:'. 3922a6b7db3Sskrll sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 3932a6b7db3Sskrll # Some versions of the HPUX 10.20 sed can't process this invocation 3942a6b7db3Sskrll # correctly. Breaking it into two sed invocations is a workaround. 395*9573673dSchristos sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 396*9573673dSchristos | sed -e 's/$/ :/' >> "$depfile" 3972a6b7db3Sskrll rm -f "$tmpdepfile" 3982a6b7db3Sskrll ;; 3992a6b7db3Sskrll 400be9ac0eaSchristoshp2) 401be9ac0eaSchristos # The "hp" stanza above does not work with aCC (C++) and HP's ia64 402be9ac0eaSchristos # compilers, which have integrated preprocessors. The correct option 403be9ac0eaSchristos # to use with these is +Maked; it writes dependencies to a file named 4042a6b7db3Sskrll # 'foo.d', which lands next to the object file, wherever that 4052a6b7db3Sskrll # happens to be. 406be9ac0eaSchristos # Much of this is similar to the tru64 case; see comments there. 407*9573673dSchristos set_dir_from "$object" 408*9573673dSchristos set_base_from "$object" 409be9ac0eaSchristos if test "$libtool" = yes; then 410be9ac0eaSchristos tmpdepfile1=$dir$base.d 411be9ac0eaSchristos tmpdepfile2=$dir.libs/$base.d 412be9ac0eaSchristos "$@" -Wc,+Maked 413be9ac0eaSchristos else 414be9ac0eaSchristos tmpdepfile1=$dir$base.d 415be9ac0eaSchristos tmpdepfile2=$dir$base.d 4162a6b7db3Sskrll "$@" +Maked 417be9ac0eaSchristos fi 4182a6b7db3Sskrll stat=$? 419*9573673dSchristos if test $stat -ne 0; then 420be9ac0eaSchristos rm -f "$tmpdepfile1" "$tmpdepfile2" 4212a6b7db3Sskrll exit $stat 4222a6b7db3Sskrll fi 4232a6b7db3Sskrll 424be9ac0eaSchristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 425be9ac0eaSchristos do 426be9ac0eaSchristos test -f "$tmpdepfile" && break 427be9ac0eaSchristos done 428be9ac0eaSchristos if test -f "$tmpdepfile"; then 429*9573673dSchristos sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 430*9573673dSchristos # Add 'dependent.h:' lines. 431be9ac0eaSchristos sed -ne '2,${ 432be9ac0eaSchristos s/^ *// 433be9ac0eaSchristos s/ \\*$// 434be9ac0eaSchristos s/$/:/ 435be9ac0eaSchristos p 436be9ac0eaSchristos }' "$tmpdepfile" >> "$depfile" 437be9ac0eaSchristos else 438*9573673dSchristos make_dummy_depfile 439be9ac0eaSchristos fi 440be9ac0eaSchristos rm -f "$tmpdepfile" "$tmpdepfile2" 4412a6b7db3Sskrll ;; 4422a6b7db3Sskrll 4432a6b7db3Sskrlltru64) 4442a6b7db3Sskrll # The Tru64 compiler uses -MD to generate dependencies as a side 445*9573673dSchristos # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4462a6b7db3Sskrll # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 447*9573673dSchristos # dependencies in 'foo.d' instead, so we check for that too. 4482a6b7db3Sskrll # Subdirectories are respected. 449*9573673dSchristos set_dir_from "$object" 450*9573673dSchristos set_base_from "$object" 4512a6b7db3Sskrll 4522a6b7db3Sskrll if test "$libtool" = yes; then 453*9573673dSchristos # Libtool generates 2 separate objects for the 2 libraries. These 454*9573673dSchristos # two compilations output dependencies in $dir.libs/$base.o.d and 4552a6b7db3Sskrll # in $dir$base.o.d. We have to check for both files, because 4562a6b7db3Sskrll # one of the two compilations can be disabled. We should prefer 4572a6b7db3Sskrll # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4582a6b7db3Sskrll # automatically cleaned when .libs/ is deleted, while ignoring 4592a6b7db3Sskrll # the former would cause a distcleancheck panic. 460*9573673dSchristos tmpdepfile1=$dir$base.o.d # libtool 1.5 461*9573673dSchristos tmpdepfile2=$dir.libs/$base.o.d # Likewise. 462*9573673dSchristos tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4632a6b7db3Sskrll "$@" -Wc,-MD 4642a6b7db3Sskrll else 465*9573673dSchristos tmpdepfile1=$dir$base.d 4662a6b7db3Sskrll tmpdepfile2=$dir$base.d 4672a6b7db3Sskrll tmpdepfile3=$dir$base.d 4682a6b7db3Sskrll "$@" -MD 4692a6b7db3Sskrll fi 4702a6b7db3Sskrll 4712a6b7db3Sskrll stat=$? 472*9573673dSchristos if test $stat -ne 0; then 473*9573673dSchristos rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 4742a6b7db3Sskrll exit $stat 4752a6b7db3Sskrll fi 4762a6b7db3Sskrll 477*9573673dSchristos for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 4782a6b7db3Sskrll do 4792a6b7db3Sskrll test -f "$tmpdepfile" && break 4802a6b7db3Sskrll done 481*9573673dSchristos # Same post-processing that is required for AIX mode. 482*9573673dSchristos aix_post_process_depfile 483*9573673dSchristos ;; 484*9573673dSchristos 485*9573673dSchristosmsvc7) 486*9573673dSchristos if test "$libtool" = yes; then 487*9573673dSchristos showIncludes=-Wc,-showIncludes 4882a6b7db3Sskrll else 489*9573673dSchristos showIncludes=-showIncludes 4902a6b7db3Sskrll fi 491*9573673dSchristos "$@" $showIncludes > "$tmpdepfile" 492*9573673dSchristos stat=$? 493*9573673dSchristos grep -v '^Note: including file: ' "$tmpdepfile" 494*9573673dSchristos if test $stat -ne 0; then 4952a6b7db3Sskrll rm -f "$tmpdepfile" 496*9573673dSchristos exit $stat 497*9573673dSchristos fi 498*9573673dSchristos rm -f "$depfile" 499*9573673dSchristos echo "$object : \\" > "$depfile" 500*9573673dSchristos # The first sed program below extracts the file names and escapes 501*9573673dSchristos # backslashes for cygpath. The second sed program outputs the file 502*9573673dSchristos # name when reading, but also accumulates all include files in the 503*9573673dSchristos # hold buffer in order to output them again at the end. This only 504*9573673dSchristos # works with sed implementations that can handle large buffers. 505*9573673dSchristos sed < "$tmpdepfile" -n ' 506*9573673dSchristos/^Note: including file: *\(.*\)/ { 507*9573673dSchristos s//\1/ 508*9573673dSchristos s/\\/\\\\/g 509*9573673dSchristos p 510*9573673dSchristos}' | $cygpath_u | sort -u | sed -n ' 511*9573673dSchristoss/ /\\ /g 512*9573673dSchristoss/\(.*\)/'"$tab"'\1 \\/p 513*9573673dSchristoss/.\(.*\) \\/\1:/ 514*9573673dSchristosH 515*9573673dSchristos$ { 516*9573673dSchristos s/.*/'"$tab"'/ 517*9573673dSchristos G 518*9573673dSchristos p 519*9573673dSchristos}' >> "$depfile" 520*9573673dSchristos echo >> "$depfile" # make sure the fragment doesn't end with a backslash 521*9573673dSchristos rm -f "$tmpdepfile" 522*9573673dSchristos ;; 523*9573673dSchristos 524*9573673dSchristosmsvc7msys) 525*9573673dSchristos # This case exists only to let depend.m4 do its work. It works by 526*9573673dSchristos # looking at the text of this script. This case will never be run, 527*9573673dSchristos # since it is checked for above. 528*9573673dSchristos exit 1 5292a6b7db3Sskrll ;; 5302a6b7db3Sskrll 5312a6b7db3Sskrll#nosideeffect) 5322a6b7db3Sskrll # This comment above is used by automake to tell side-effect 5332a6b7db3Sskrll # dependency tracking mechanisms from slower ones. 5342a6b7db3Sskrll 5352a6b7db3Sskrlldashmstdout) 5362a6b7db3Sskrll # Important note: in order to support this mode, a compiler *must* 5372a6b7db3Sskrll # always write the preprocessed file to stdout, regardless of -o. 5382a6b7db3Sskrll "$@" || exit $? 5392a6b7db3Sskrll 5402a6b7db3Sskrll # Remove the call to Libtool. 5412a6b7db3Sskrll if test "$libtool" = yes; then 542be9ac0eaSchristos while test "X$1" != 'X--mode=compile'; do 5432a6b7db3Sskrll shift 5442a6b7db3Sskrll done 5452a6b7db3Sskrll shift 5462a6b7db3Sskrll fi 5472a6b7db3Sskrll 548*9573673dSchristos # Remove '-o $object'. 5492a6b7db3Sskrll IFS=" " 5502a6b7db3Sskrll for arg 5512a6b7db3Sskrll do 5522a6b7db3Sskrll case $arg in 5532a6b7db3Sskrll -o) 5542a6b7db3Sskrll shift 5552a6b7db3Sskrll ;; 5562a6b7db3Sskrll $object) 5572a6b7db3Sskrll shift 5582a6b7db3Sskrll ;; 5592a6b7db3Sskrll *) 5602a6b7db3Sskrll set fnord "$@" "$arg" 5612a6b7db3Sskrll shift # fnord 5622a6b7db3Sskrll shift # $arg 5632a6b7db3Sskrll ;; 5642a6b7db3Sskrll esac 5652a6b7db3Sskrll done 5662a6b7db3Sskrll 5672a6b7db3Sskrll test -z "$dashmflag" && dashmflag=-M 568*9573673dSchristos # Require at least two characters before searching for ':' 5692a6b7db3Sskrll # in the target name. This is to cope with DOS-style filenames: 570*9573673dSchristos # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 5712a6b7db3Sskrll "$@" $dashmflag | 572*9573673dSchristos sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 5732a6b7db3Sskrll rm -f "$depfile" 5742a6b7db3Sskrll cat < "$tmpdepfile" > "$depfile" 575*9573673dSchristos # Some versions of the HPUX 10.20 sed can't process this sed invocation 576*9573673dSchristos # correctly. Breaking it into two sed invocations is a workaround. 577*9573673dSchristos tr ' ' "$nl" < "$tmpdepfile" \ 578*9573673dSchristos | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 579*9573673dSchristos | sed -e 's/$/ :/' >> "$depfile" 5802a6b7db3Sskrll rm -f "$tmpdepfile" 5812a6b7db3Sskrll ;; 5822a6b7db3Sskrll 5832a6b7db3SskrlldashXmstdout) 5842a6b7db3Sskrll # This case only exists to satisfy depend.m4. It is never actually 5852a6b7db3Sskrll # run, as this mode is specially recognized in the preamble. 5862a6b7db3Sskrll exit 1 5872a6b7db3Sskrll ;; 5882a6b7db3Sskrll 5892a6b7db3Sskrllmakedepend) 5902a6b7db3Sskrll "$@" || exit $? 5912a6b7db3Sskrll # Remove any Libtool call 5922a6b7db3Sskrll if test "$libtool" = yes; then 593be9ac0eaSchristos while test "X$1" != 'X--mode=compile'; do 5942a6b7db3Sskrll shift 5952a6b7db3Sskrll done 5962a6b7db3Sskrll shift 5972a6b7db3Sskrll fi 5982a6b7db3Sskrll # X makedepend 5992a6b7db3Sskrll shift 600be9ac0eaSchristos cleared=no eat=no 601be9ac0eaSchristos for arg 602be9ac0eaSchristos do 6032a6b7db3Sskrll case $cleared in 6042a6b7db3Sskrll no) 6052a6b7db3Sskrll set ""; shift 6062a6b7db3Sskrll cleared=yes ;; 6072a6b7db3Sskrll esac 608be9ac0eaSchristos if test $eat = yes; then 609be9ac0eaSchristos eat=no 610be9ac0eaSchristos continue 611be9ac0eaSchristos fi 6122a6b7db3Sskrll case "$arg" in 6132a6b7db3Sskrll -D*|-I*) 6142a6b7db3Sskrll set fnord "$@" "$arg"; shift ;; 6152a6b7db3Sskrll # Strip any option that makedepend may not understand. Remove 6162a6b7db3Sskrll # the object too, otherwise makedepend will parse it as a source file. 617be9ac0eaSchristos -arch) 618be9ac0eaSchristos eat=yes ;; 6192a6b7db3Sskrll -*|$object) 6202a6b7db3Sskrll ;; 6212a6b7db3Sskrll *) 6222a6b7db3Sskrll set fnord "$@" "$arg"; shift ;; 6232a6b7db3Sskrll esac 6242a6b7db3Sskrll done 625be9ac0eaSchristos obj_suffix=`echo "$object" | sed 's/^.*\././'` 6262a6b7db3Sskrll touch "$tmpdepfile" 6272a6b7db3Sskrll ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6282a6b7db3Sskrll rm -f "$depfile" 629*9573673dSchristos # makedepend may prepend the VPATH from the source file name to the object. 630*9573673dSchristos # No need to regex-escape $object, excess matching of '.' is harmless. 631*9573673dSchristos sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 632*9573673dSchristos # Some versions of the HPUX 10.20 sed can't process the last invocation 633*9573673dSchristos # correctly. Breaking it into two sed invocations is a workaround. 634*9573673dSchristos sed '1,2d' "$tmpdepfile" \ 635*9573673dSchristos | tr ' ' "$nl" \ 636*9573673dSchristos | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 637*9573673dSchristos | sed -e 's/$/ :/' >> "$depfile" 6382a6b7db3Sskrll rm -f "$tmpdepfile" "$tmpdepfile".bak 6392a6b7db3Sskrll ;; 6402a6b7db3Sskrll 6412a6b7db3Sskrllcpp) 6422a6b7db3Sskrll # Important note: in order to support this mode, a compiler *must* 6432a6b7db3Sskrll # always write the preprocessed file to stdout. 6442a6b7db3Sskrll "$@" || exit $? 6452a6b7db3Sskrll 6462a6b7db3Sskrll # Remove the call to Libtool. 6472a6b7db3Sskrll if test "$libtool" = yes; then 648be9ac0eaSchristos while test "X$1" != 'X--mode=compile'; do 6492a6b7db3Sskrll shift 6502a6b7db3Sskrll done 6512a6b7db3Sskrll shift 6522a6b7db3Sskrll fi 6532a6b7db3Sskrll 654*9573673dSchristos # Remove '-o $object'. 6552a6b7db3Sskrll IFS=" " 6562a6b7db3Sskrll for arg 6572a6b7db3Sskrll do 6582a6b7db3Sskrll case $arg in 6592a6b7db3Sskrll -o) 6602a6b7db3Sskrll shift 6612a6b7db3Sskrll ;; 6622a6b7db3Sskrll $object) 6632a6b7db3Sskrll shift 6642a6b7db3Sskrll ;; 6652a6b7db3Sskrll *) 6662a6b7db3Sskrll set fnord "$@" "$arg" 6672a6b7db3Sskrll shift # fnord 6682a6b7db3Sskrll shift # $arg 6692a6b7db3Sskrll ;; 6702a6b7db3Sskrll esac 6712a6b7db3Sskrll done 6722a6b7db3Sskrll 673*9573673dSchristos "$@" -E \ 674*9573673dSchristos | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 675*9573673dSchristos -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 676*9573673dSchristos | sed '$ s: \\$::' > "$tmpdepfile" 6772a6b7db3Sskrll rm -f "$depfile" 6782a6b7db3Sskrll echo "$object : \\" > "$depfile" 6792a6b7db3Sskrll cat < "$tmpdepfile" >> "$depfile" 6802a6b7db3Sskrll sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 6812a6b7db3Sskrll rm -f "$tmpdepfile" 6822a6b7db3Sskrll ;; 6832a6b7db3Sskrll 6842a6b7db3Sskrllmsvisualcpp) 6852a6b7db3Sskrll # Important note: in order to support this mode, a compiler *must* 686be9ac0eaSchristos # always write the preprocessed file to stdout. 6872a6b7db3Sskrll "$@" || exit $? 688be9ac0eaSchristos 689be9ac0eaSchristos # Remove the call to Libtool. 690be9ac0eaSchristos if test "$libtool" = yes; then 691be9ac0eaSchristos while test "X$1" != 'X--mode=compile'; do 692be9ac0eaSchristos shift 693be9ac0eaSchristos done 694be9ac0eaSchristos shift 695be9ac0eaSchristos fi 696be9ac0eaSchristos 6972a6b7db3Sskrll IFS=" " 6982a6b7db3Sskrll for arg 6992a6b7db3Sskrll do 7002a6b7db3Sskrll case "$arg" in 701be9ac0eaSchristos -o) 702be9ac0eaSchristos shift 703be9ac0eaSchristos ;; 704be9ac0eaSchristos $object) 705be9ac0eaSchristos shift 706be9ac0eaSchristos ;; 7072a6b7db3Sskrll "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7082a6b7db3Sskrll set fnord "$@" 7092a6b7db3Sskrll shift 7102a6b7db3Sskrll shift 7112a6b7db3Sskrll ;; 7122a6b7db3Sskrll *) 7132a6b7db3Sskrll set fnord "$@" "$arg" 7142a6b7db3Sskrll shift 7152a6b7db3Sskrll shift 7162a6b7db3Sskrll ;; 7172a6b7db3Sskrll esac 7182a6b7db3Sskrll done 719be9ac0eaSchristos "$@" -E 2>/dev/null | 720be9ac0eaSchristos sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7212a6b7db3Sskrll rm -f "$depfile" 7222a6b7db3Sskrll echo "$object : \\" > "$depfile" 723*9573673dSchristos sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 724*9573673dSchristos echo "$tab" >> "$depfile" 725be9ac0eaSchristos sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7262a6b7db3Sskrll rm -f "$tmpdepfile" 7272a6b7db3Sskrll ;; 7282a6b7db3Sskrll 729be9ac0eaSchristosmsvcmsys) 730be9ac0eaSchristos # This case exists only to let depend.m4 do its work. It works by 731be9ac0eaSchristos # looking at the text of this script. This case will never be run, 732be9ac0eaSchristos # since it is checked for above. 733be9ac0eaSchristos exit 1 734be9ac0eaSchristos ;; 735be9ac0eaSchristos 7362a6b7db3Sskrllnone) 7372a6b7db3Sskrll exec "$@" 7382a6b7db3Sskrll ;; 7392a6b7db3Sskrll 7402a6b7db3Sskrll*) 7412a6b7db3Sskrll echo "Unknown depmode $depmode" 1>&2 7422a6b7db3Sskrll exit 1 7432a6b7db3Sskrll ;; 7442a6b7db3Sskrllesac 7452a6b7db3Sskrll 7462a6b7db3Sskrllexit 0 7472a6b7db3Sskrll 7482a6b7db3Sskrll# Local Variables: 7492a6b7db3Sskrll# mode: shell-script 7502a6b7db3Sskrll# sh-indentation: 2 7512a6b7db3Sskrll# eval: (add-hook 'write-file-hooks 'time-stamp) 7522a6b7db3Sskrll# time-stamp-start: "scriptversion=" 7532a6b7db3Sskrll# time-stamp-format: "%:y-%02m-%02d.%02H" 754be9ac0eaSchristos# time-stamp-time-zone: "UTC" 755be9ac0eaSchristos# time-stamp-end: "; # UTC" 7562a6b7db3Sskrll# End: 757