1ff559fabSmrg#! /bin/sh 2ff559fabSmrg# depcomp - compile a program generating dependencies as side-effects 3ff559fabSmrg 4515ec619Smrgscriptversion=2018-03-07.03; # UTC 5ff559fabSmrg 6515ec619Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7ff559fabSmrg 8ff559fabSmrg# This program is free software; you can redistribute it and/or modify 9ff559fabSmrg# it under the terms of the GNU General Public License as published by 10ff559fabSmrg# the Free Software Foundation; either version 2, or (at your option) 11ff559fabSmrg# any later version. 12ff559fabSmrg 13ff559fabSmrg# This program is distributed in the hope that it will be useful, 14ff559fabSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15ff559fabSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16ff559fabSmrg# GNU General Public License for more details. 17ff559fabSmrg 18ff559fabSmrg# You should have received a copy of the GNU General Public License 19515ec619Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20ff559fabSmrg 21ff559fabSmrg# As a special exception to the GNU General Public License, if you 22ff559fabSmrg# distribute this file as part of a program that contains a 23ff559fabSmrg# configuration script generated by Autoconf, you may include it under 24ff559fabSmrg# the same distribution terms that you use for the rest of that program. 25ff559fabSmrg 26ff559fabSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27ff559fabSmrg 28ff559fabSmrgcase $1 in 29ff559fabSmrg '') 30fc544a13Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31fc544a13Smrg exit 1; 32fc544a13Smrg ;; 33ff559fabSmrg -h | --h*) 34ff559fabSmrg cat <<\EOF 35ff559fabSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36ff559fabSmrg 37ff559fabSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38ff559fabSmrgas side-effects. 39ff559fabSmrg 40ff559fabSmrgEnvironment variables: 41ff559fabSmrg depmode Dependency tracking mode. 42fc544a13Smrg source Source file read by 'PROGRAMS ARGS'. 43fc544a13Smrg object Object file output by 'PROGRAMS ARGS'. 44ff559fabSmrg DEPDIR directory where to store dependencies. 45ff559fabSmrg depfile Dependency file to output. 46fc544a13Smrg tmpdepfile Temporary file to use when outputting dependencies. 47ff559fabSmrg libtool Whether libtool is used (yes/no). 48ff559fabSmrg 49ff559fabSmrgReport bugs to <bug-automake@gnu.org>. 50ff559fabSmrgEOF 51ff559fabSmrg exit $? 52ff559fabSmrg ;; 53ff559fabSmrg -v | --v*) 54ff559fabSmrg echo "depcomp $scriptversion" 55ff559fabSmrg exit $? 56ff559fabSmrg ;; 57ff559fabSmrgesac 58ff559fabSmrg 59fc544a13Smrg# Get the directory component of the given path, and save it in the 60fc544a13Smrg# global variables '$dir'. Note that this directory component will 61fc544a13Smrg# be either empty or ending with a '/' character. This is deliberate. 62fc544a13Smrgset_dir_from () 63fc544a13Smrg{ 64fc544a13Smrg case $1 in 65fc544a13Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66fc544a13Smrg *) dir=;; 67fc544a13Smrg esac 68fc544a13Smrg} 69fc544a13Smrg 70fc544a13Smrg# Get the suffix-stripped basename of the given path, and save it the 71fc544a13Smrg# global variable '$base'. 72fc544a13Smrgset_base_from () 73fc544a13Smrg{ 74fc544a13Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75fc544a13Smrg} 76fc544a13Smrg 77fc544a13Smrg# If no dependency file was actually created by the compiler invocation, 78fc544a13Smrg# we still have to create a dummy depfile, to avoid errors with the 79fc544a13Smrg# Makefile "include basename.Plo" scheme. 80fc544a13Smrgmake_dummy_depfile () 81fc544a13Smrg{ 82fc544a13Smrg echo "#dummy" > "$depfile" 83fc544a13Smrg} 84fc544a13Smrg 85fc544a13Smrg# Factor out some common post-processing of the generated depfile. 86fc544a13Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87fc544a13Smrgaix_post_process_depfile () 88fc544a13Smrg{ 89fc544a13Smrg # If the compiler actually managed to produce a dependency file, 90fc544a13Smrg # post-process it. 91fc544a13Smrg if test -f "$tmpdepfile"; then 92fc544a13Smrg # Each line is of the form 'foo.o: dependency.h'. 93fc544a13Smrg # Do two passes, one to just change these to 94fc544a13Smrg # $object: dependency.h 95fc544a13Smrg # and one to simply output 96fc544a13Smrg # dependency.h: 97fc544a13Smrg # which is needed to avoid the deleted-header problem. 98fc544a13Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99fc544a13Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100fc544a13Smrg } > "$depfile" 101fc544a13Smrg rm -f "$tmpdepfile" 102fc544a13Smrg else 103fc544a13Smrg make_dummy_depfile 104fc544a13Smrg fi 105fc544a13Smrg} 106fc544a13Smrg 107fc544a13Smrg# A tabulation character. 108fc544a13Smrgtab=' ' 109fc544a13Smrg# A newline character. 110fc544a13Smrgnl=' 111fc544a13Smrg' 112fc544a13Smrg# Character ranges might be problematic outside the C locale. 113fc544a13Smrg# These definitions help. 114fc544a13Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115fc544a13Smrglower=abcdefghijklmnopqrstuvwxyz 116fc544a13Smrgdigits=0123456789 117fc544a13Smrgalpha=${upper}${lower} 118fc544a13Smrg 119ff559fabSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120ff559fabSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121ff559fabSmrg exit 1 122ff559fabSmrgfi 123ff559fabSmrg 124ff559fabSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125ff559fabSmrgdepfile=${depfile-`echo "$object" | 126ff559fabSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127ff559fabSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128ff559fabSmrg 129ff559fabSmrgrm -f "$tmpdepfile" 130ff559fabSmrg 131fc544a13Smrg# Avoid interferences from the environment. 132fc544a13Smrggccflag= dashmflag= 133fc544a13Smrg 134ff559fabSmrg# Some modes work just like other modes, but use different flags. We 135ff559fabSmrg# parameterize here, but still list the modes in the big case below, 136ff559fabSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137ff559fabSmrg# here, because this file can only contain one case statement. 138ff559fabSmrgif test "$depmode" = hp; then 139ff559fabSmrg # HP compiler uses -M and no extra arg. 140ff559fabSmrg gccflag=-M 141ff559fabSmrg depmode=gcc 142ff559fabSmrgfi 143ff559fabSmrg 144ff559fabSmrgif test "$depmode" = dashXmstdout; then 145fc544a13Smrg # This is just like dashmstdout with a different argument. 146fc544a13Smrg dashmflag=-xM 147fc544a13Smrg depmode=dashmstdout 148ff559fabSmrgfi 149ff559fabSmrg 15044dda7b2Smrgcygpath_u="cygpath -u -f -" 15144dda7b2Smrgif test "$depmode" = msvcmsys; then 152fc544a13Smrg # This is just like msvisualcpp but w/o cygpath translation. 153fc544a13Smrg # Just convert the backslash-escaped backslashes to single forward 154fc544a13Smrg # slashes to satisfy depend.m4 155fc544a13Smrg cygpath_u='sed s,\\\\,/,g' 156fc544a13Smrg depmode=msvisualcpp 157fc544a13Smrgfi 158fc544a13Smrg 159fc544a13Smrgif test "$depmode" = msvc7msys; then 160fc544a13Smrg # This is just like msvc7 but w/o cygpath translation. 161fc544a13Smrg # Just convert the backslash-escaped backslashes to single forward 162fc544a13Smrg # slashes to satisfy depend.m4 163fc544a13Smrg cygpath_u='sed s,\\\\,/,g' 164fc544a13Smrg depmode=msvc7 165fc544a13Smrgfi 166fc544a13Smrg 167fc544a13Smrgif test "$depmode" = xlc; then 168fc544a13Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169fc544a13Smrg gccflag=-qmakedep=gcc,-MF 170fc544a13Smrg depmode=gcc 17144dda7b2Smrgfi 17244dda7b2Smrg 173ff559fabSmrgcase "$depmode" in 174ff559fabSmrggcc3) 175ff559fabSmrg## gcc 3 implements dependency tracking that does exactly what 176ff559fabSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177ff559fabSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 1787a3b38f7Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1797a3b38f7Smrg## the command line argument order; so add the flags where they 1807a3b38f7Smrg## appear in depend2.am. Note that the slowdown incurred here 1817a3b38f7Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1827a3b38f7Smrg for arg 1837a3b38f7Smrg do 1847a3b38f7Smrg case $arg in 1857a3b38f7Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1867a3b38f7Smrg *) set fnord "$@" "$arg" ;; 1877a3b38f7Smrg esac 1887a3b38f7Smrg shift # fnord 1897a3b38f7Smrg shift # $arg 1907a3b38f7Smrg done 1917a3b38f7Smrg "$@" 192ff559fabSmrg stat=$? 193fc544a13Smrg if test $stat -ne 0; then 194ff559fabSmrg rm -f "$tmpdepfile" 195ff559fabSmrg exit $stat 196ff559fabSmrg fi 197ff559fabSmrg mv "$tmpdepfile" "$depfile" 198ff559fabSmrg ;; 199ff559fabSmrg 200ff559fabSmrggcc) 201fc544a13Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202fc544a13Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203fc544a13Smrg## (see the conditional assignment to $gccflag above). 204ff559fabSmrg## There are various ways to get dependency output from gcc. Here's 205ff559fabSmrg## why we pick this rather obscure method: 206ff559fabSmrg## - Don't want to use -MD because we'd like the dependencies to end 207ff559fabSmrg## up in a subdir. Having to rename by hand is ugly. 208ff559fabSmrg## (We might end up doing this anyway to support other compilers.) 209ff559fabSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210fc544a13Smrg## -MM, not -M (despite what the docs say). Also, it might not be 211fc544a13Smrg## supported by the other compilers which use the 'gcc' depmode. 212ff559fabSmrg## - Using -M directly means running the compiler twice (even worse 213ff559fabSmrg## than renaming). 214ff559fabSmrg if test -z "$gccflag"; then 215ff559fabSmrg gccflag=-MD, 216ff559fabSmrg fi 217ff559fabSmrg "$@" -Wp,"$gccflag$tmpdepfile" 218ff559fabSmrg stat=$? 219fc544a13Smrg if test $stat -ne 0; then 220ff559fabSmrg rm -f "$tmpdepfile" 221ff559fabSmrg exit $stat 222ff559fabSmrg fi 223ff559fabSmrg rm -f "$depfile" 224ff559fabSmrg echo "$object : \\" > "$depfile" 225fc544a13Smrg # The second -e expression handles DOS-style file names with drive 226fc544a13Smrg # letters. 227ff559fabSmrg sed -e 's/^[^:]*: / /' \ 228ff559fabSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229fc544a13Smrg## This next piece of magic avoids the "deleted header file" problem. 230ff559fabSmrg## The problem is that when a header file which appears in a .P file 231ff559fabSmrg## is deleted, the dependency causes make to die (because there is 232ff559fabSmrg## typically no way to rebuild the header). We avoid this by adding 233ff559fabSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 234ff559fabSmrg## this for us directly. 235fc544a13Smrg## Some versions of gcc put a space before the ':'. On the theory 236ff559fabSmrg## that the space means something, we add a space to the output as 237fc544a13Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238fc544a13Smrg## to the object. Take care to not repeat it in the output. 239ff559fabSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 240ff559fabSmrg## correctly. Breaking it into two sed invocations is a workaround. 241fc544a13Smrg tr ' ' "$nl" < "$tmpdepfile" \ 242fc544a13Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243fc544a13Smrg | sed -e 's/$/ :/' >> "$depfile" 244ff559fabSmrg rm -f "$tmpdepfile" 245ff559fabSmrg ;; 246ff559fabSmrg 247ff559fabSmrghp) 248ff559fabSmrg # This case exists only to let depend.m4 do its work. It works by 249ff559fabSmrg # looking at the text of this script. This case will never be run, 250ff559fabSmrg # since it is checked for above. 251ff559fabSmrg exit 1 252ff559fabSmrg ;; 253ff559fabSmrg 254ff559fabSmrgsgi) 255ff559fabSmrg if test "$libtool" = yes; then 256ff559fabSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257ff559fabSmrg else 258ff559fabSmrg "$@" -MDupdate "$tmpdepfile" 259ff559fabSmrg fi 260ff559fabSmrg stat=$? 261fc544a13Smrg if test $stat -ne 0; then 262ff559fabSmrg rm -f "$tmpdepfile" 263ff559fabSmrg exit $stat 264ff559fabSmrg fi 265ff559fabSmrg rm -f "$depfile" 266ff559fabSmrg 267ff559fabSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268ff559fabSmrg echo "$object : \\" > "$depfile" 269ff559fabSmrg # Clip off the initial element (the dependent). Don't try to be 270ff559fabSmrg # clever and replace this with sed code, as IRIX sed won't handle 271ff559fabSmrg # lines with more than a fixed number of characters (4096 in 272ff559fabSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273fc544a13Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274ff559fabSmrg # dependency line. 275fc544a13Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276fc544a13Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277fc544a13Smrg | tr "$nl" ' ' >> "$depfile" 27844dda7b2Smrg echo >> "$depfile" 279ff559fabSmrg # The second pass generates a dummy entry for each header file. 280fc544a13Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281fc544a13Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282fc544a13Smrg >> "$depfile" 283ff559fabSmrg else 284fc544a13Smrg make_dummy_depfile 285ff559fabSmrg fi 286ff559fabSmrg rm -f "$tmpdepfile" 287ff559fabSmrg ;; 288ff559fabSmrg 289fc544a13Smrgxlc) 290fc544a13Smrg # This case exists only to let depend.m4 do its work. It works by 291fc544a13Smrg # looking at the text of this script. This case will never be run, 292fc544a13Smrg # since it is checked for above. 293fc544a13Smrg exit 1 294fc544a13Smrg ;; 295fc544a13Smrg 296ff559fabSmrgaix) 297ff559fabSmrg # The C for AIX Compiler uses -M and outputs the dependencies 298ff559fabSmrg # in a .u file. In older versions, this file always lives in the 299fc544a13Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300ff559fabSmrg # start of each line; $object doesn't have directory information. 301ff559fabSmrg # Version 6 uses the directory in both cases. 302fc544a13Smrg set_dir_from "$object" 303fc544a13Smrg set_base_from "$object" 304ff559fabSmrg if test "$libtool" = yes; then 3057a3b38f7Smrg tmpdepfile1=$dir$base.u 3067a3b38f7Smrg tmpdepfile2=$base.u 3077a3b38f7Smrg tmpdepfile3=$dir.libs/$base.u 308ff559fabSmrg "$@" -Wc,-M 309ff559fabSmrg else 3107a3b38f7Smrg tmpdepfile1=$dir$base.u 3117a3b38f7Smrg tmpdepfile2=$dir$base.u 3127a3b38f7Smrg tmpdepfile3=$dir$base.u 313ff559fabSmrg "$@" -M 314ff559fabSmrg fi 315ff559fabSmrg stat=$? 316fc544a13Smrg if test $stat -ne 0; then 3177a3b38f7Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318ff559fabSmrg exit $stat 319ff559fabSmrg fi 320ff559fabSmrg 3217a3b38f7Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3227a3b38f7Smrg do 3237a3b38f7Smrg test -f "$tmpdepfile" && break 3247a3b38f7Smrg done 325fc544a13Smrg aix_post_process_depfile 326fc544a13Smrg ;; 327fc544a13Smrg 328fc544a13Smrgtcc) 329fc544a13Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330fc544a13Smrg # FIXME: That version still under development at the moment of writing. 331fc544a13Smrg # Make that this statement remains true also for stable, released 332fc544a13Smrg # versions. 333fc544a13Smrg # It will wrap lines (doesn't matter whether long or short) with a 334fc544a13Smrg # trailing '\', as in: 335fc544a13Smrg # 336fc544a13Smrg # foo.o : \ 337fc544a13Smrg # foo.c \ 338fc544a13Smrg # foo.h \ 339fc544a13Smrg # 340fc544a13Smrg # It will put a trailing '\' even on the last line, and will use leading 341fc544a13Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 342fc544a13Smrg # "Emit spaces for -MD"). 343fc544a13Smrg "$@" -MD -MF "$tmpdepfile" 344fc544a13Smrg stat=$? 345fc544a13Smrg if test $stat -ne 0; then 346fc544a13Smrg rm -f "$tmpdepfile" 347fc544a13Smrg exit $stat 348ff559fabSmrg fi 349fc544a13Smrg rm -f "$depfile" 350fc544a13Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351fc544a13Smrg # We have to change lines of the first kind to '$object: \'. 352fc544a13Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353fc544a13Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 354fc544a13Smrg # dummy dependency, to avoid the deleted-header problem. 355fc544a13Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356ff559fabSmrg rm -f "$tmpdepfile" 357ff559fabSmrg ;; 358ff559fabSmrg 359fc544a13Smrg## The order of this option in the case statement is important, since the 360fc544a13Smrg## shell code in configure will try each of these formats in the order 361fc544a13Smrg## listed in this file. A plain '-MD' option would be understood by many 362fc544a13Smrg## compilers, so we must ensure this comes after the gcc and icc options. 363fc544a13Smrgpgcc) 364fc544a13Smrg # Portland's C compiler understands '-MD'. 365fc544a13Smrg # Will always output deps to 'file.d' where file is the root name of the 366fc544a13Smrg # source file under compilation, even if file resides in a subdirectory. 367fc544a13Smrg # The object file name does not affect the name of the '.d' file. 368fc544a13Smrg # pgcc 10.2 will output 369ff559fabSmrg # foo.o: sub/foo.c sub/foo.h 370fc544a13Smrg # and will wrap long lines using '\' : 371ff559fabSmrg # foo.o: sub/foo.c ... \ 372ff559fabSmrg # sub/foo.h ... \ 373ff559fabSmrg # ... 374fc544a13Smrg set_dir_from "$object" 375fc544a13Smrg # Use the source, not the object, to determine the base name, since 376fc544a13Smrg # that's sadly what pgcc will do too. 377fc544a13Smrg set_base_from "$source" 378fc544a13Smrg tmpdepfile=$base.d 379fc544a13Smrg 380fc544a13Smrg # For projects that build the same source file twice into different object 381fc544a13Smrg # files, the pgcc approach of using the *source* file root name can cause 382fc544a13Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383fc544a13Smrg # the same $tmpdepfile. 384fc544a13Smrg lockdir=$base.d-lock 385fc544a13Smrg trap " 386fc544a13Smrg echo '$0: caught signal, cleaning up...' >&2 387fc544a13Smrg rmdir '$lockdir' 388fc544a13Smrg exit 1 389fc544a13Smrg " 1 2 13 15 390fc544a13Smrg numtries=100 391fc544a13Smrg i=$numtries 392fc544a13Smrg while test $i -gt 0; do 393fc544a13Smrg # mkdir is a portable test-and-set. 394fc544a13Smrg if mkdir "$lockdir" 2>/dev/null; then 395fc544a13Smrg # This process acquired the lock. 396fc544a13Smrg "$@" -MD 397fc544a13Smrg stat=$? 398fc544a13Smrg # Release the lock. 399fc544a13Smrg rmdir "$lockdir" 400fc544a13Smrg break 401fc544a13Smrg else 402fc544a13Smrg # If the lock is being held by a different process, wait 403fc544a13Smrg # until the winning process is done or we timeout. 404fc544a13Smrg while test -d "$lockdir" && test $i -gt 0; do 405fc544a13Smrg sleep 1 406fc544a13Smrg i=`expr $i - 1` 407fc544a13Smrg done 408fc544a13Smrg fi 409fc544a13Smrg i=`expr $i - 1` 410fc544a13Smrg done 411fc544a13Smrg trap - 1 2 13 15 412fc544a13Smrg if test $i -le 0; then 413fc544a13Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414fc544a13Smrg echo "$0: check lockdir '$lockdir'" >&2 415fc544a13Smrg exit 1 416fc544a13Smrg fi 417ff559fabSmrg 418fc544a13Smrg if test $stat -ne 0; then 419ff559fabSmrg rm -f "$tmpdepfile" 420ff559fabSmrg exit $stat 421ff559fabSmrg fi 422ff559fabSmrg rm -f "$depfile" 423ff559fabSmrg # Each line is of the form `foo.o: dependent.h', 424ff559fabSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425ff559fabSmrg # Do two passes, one to just change these to 426ff559fabSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 427ff559fabSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428ff559fabSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 429ff559fabSmrg # correctly. Breaking it into two sed invocations is a workaround. 430fc544a13Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431fc544a13Smrg | sed -e 's/$/ :/' >> "$depfile" 432ff559fabSmrg rm -f "$tmpdepfile" 433ff559fabSmrg ;; 434ff559fabSmrg 4357a3b38f7Smrghp2) 4367a3b38f7Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4377a3b38f7Smrg # compilers, which have integrated preprocessors. The correct option 4387a3b38f7Smrg # to use with these is +Maked; it writes dependencies to a file named 4397a3b38f7Smrg # 'foo.d', which lands next to the object file, wherever that 4407a3b38f7Smrg # happens to be. 4417a3b38f7Smrg # Much of this is similar to the tru64 case; see comments there. 442fc544a13Smrg set_dir_from "$object" 443fc544a13Smrg set_base_from "$object" 4447a3b38f7Smrg if test "$libtool" = yes; then 4457a3b38f7Smrg tmpdepfile1=$dir$base.d 4467a3b38f7Smrg tmpdepfile2=$dir.libs/$base.d 4477a3b38f7Smrg "$@" -Wc,+Maked 4487a3b38f7Smrg else 4497a3b38f7Smrg tmpdepfile1=$dir$base.d 4507a3b38f7Smrg tmpdepfile2=$dir$base.d 4517a3b38f7Smrg "$@" +Maked 4527a3b38f7Smrg fi 4537a3b38f7Smrg stat=$? 454fc544a13Smrg if test $stat -ne 0; then 4557a3b38f7Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4567a3b38f7Smrg exit $stat 4577a3b38f7Smrg fi 4587a3b38f7Smrg 4597a3b38f7Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4607a3b38f7Smrg do 4617a3b38f7Smrg test -f "$tmpdepfile" && break 4627a3b38f7Smrg done 4637a3b38f7Smrg if test -f "$tmpdepfile"; then 464fc544a13Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465fc544a13Smrg # Add 'dependent.h:' lines. 46644dda7b2Smrg sed -ne '2,${ 467fc544a13Smrg s/^ *// 468fc544a13Smrg s/ \\*$// 469fc544a13Smrg s/$/:/ 470fc544a13Smrg p 471fc544a13Smrg }' "$tmpdepfile" >> "$depfile" 4727a3b38f7Smrg else 473fc544a13Smrg make_dummy_depfile 4747a3b38f7Smrg fi 4757a3b38f7Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4767a3b38f7Smrg ;; 4777a3b38f7Smrg 478ff559fabSmrgtru64) 479fc544a13Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 480fc544a13Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481fc544a13Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482fc544a13Smrg # dependencies in 'foo.d' instead, so we check for that too. 483fc544a13Smrg # Subdirectories are respected. 484fc544a13Smrg set_dir_from "$object" 485fc544a13Smrg set_base_from "$object" 486fc544a13Smrg 487fc544a13Smrg if test "$libtool" = yes; then 488fc544a13Smrg # Libtool generates 2 separate objects for the 2 libraries. These 489fc544a13Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 490fc544a13Smrg # in $dir$base.o.d. We have to check for both files, because 491fc544a13Smrg # one of the two compilations can be disabled. We should prefer 492fc544a13Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493fc544a13Smrg # automatically cleaned when .libs/ is deleted, while ignoring 494fc544a13Smrg # the former would cause a distcleancheck panic. 495fc544a13Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496fc544a13Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497fc544a13Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498fc544a13Smrg "$@" -Wc,-MD 499fc544a13Smrg else 500fc544a13Smrg tmpdepfile1=$dir$base.d 501fc544a13Smrg tmpdepfile2=$dir$base.d 502fc544a13Smrg tmpdepfile3=$dir$base.d 503fc544a13Smrg "$@" -MD 504fc544a13Smrg fi 505fc544a13Smrg 506fc544a13Smrg stat=$? 507fc544a13Smrg if test $stat -ne 0; then 508fc544a13Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509fc544a13Smrg exit $stat 510fc544a13Smrg fi 511fc544a13Smrg 512fc544a13Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513fc544a13Smrg do 514fc544a13Smrg test -f "$tmpdepfile" && break 515fc544a13Smrg done 516fc544a13Smrg # Same post-processing that is required for AIX mode. 517fc544a13Smrg aix_post_process_depfile 518fc544a13Smrg ;; 519fc544a13Smrg 520fc544a13Smrgmsvc7) 521fc544a13Smrg if test "$libtool" = yes; then 522fc544a13Smrg showIncludes=-Wc,-showIncludes 523fc544a13Smrg else 524fc544a13Smrg showIncludes=-showIncludes 525fc544a13Smrg fi 526fc544a13Smrg "$@" $showIncludes > "$tmpdepfile" 527fc544a13Smrg stat=$? 528fc544a13Smrg grep -v '^Note: including file: ' "$tmpdepfile" 529fc544a13Smrg if test $stat -ne 0; then 530fc544a13Smrg rm -f "$tmpdepfile" 531fc544a13Smrg exit $stat 532fc544a13Smrg fi 533fc544a13Smrg rm -f "$depfile" 534fc544a13Smrg echo "$object : \\" > "$depfile" 535fc544a13Smrg # The first sed program below extracts the file names and escapes 536fc544a13Smrg # backslashes for cygpath. The second sed program outputs the file 537fc544a13Smrg # name when reading, but also accumulates all include files in the 538fc544a13Smrg # hold buffer in order to output them again at the end. This only 539fc544a13Smrg # works with sed implementations that can handle large buffers. 540fc544a13Smrg sed < "$tmpdepfile" -n ' 541fc544a13Smrg/^Note: including file: *\(.*\)/ { 542fc544a13Smrg s//\1/ 543fc544a13Smrg s/\\/\\\\/g 544fc544a13Smrg p 545fc544a13Smrg}' | $cygpath_u | sort -u | sed -n ' 546fc544a13Smrgs/ /\\ /g 547fc544a13Smrgs/\(.*\)/'"$tab"'\1 \\/p 548fc544a13Smrgs/.\(.*\) \\/\1:/ 549fc544a13SmrgH 550fc544a13Smrg$ { 551fc544a13Smrg s/.*/'"$tab"'/ 552fc544a13Smrg G 553fc544a13Smrg p 554fc544a13Smrg}' >> "$depfile" 555fc544a13Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556fc544a13Smrg rm -f "$tmpdepfile" 557fc544a13Smrg ;; 558fc544a13Smrg 559fc544a13Smrgmsvc7msys) 560fc544a13Smrg # This case exists only to let depend.m4 do its work. It works by 561fc544a13Smrg # looking at the text of this script. This case will never be run, 562fc544a13Smrg # since it is checked for above. 563fc544a13Smrg exit 1 564fc544a13Smrg ;; 565ff559fabSmrg 566ff559fabSmrg#nosideeffect) 567ff559fabSmrg # This comment above is used by automake to tell side-effect 568ff559fabSmrg # dependency tracking mechanisms from slower ones. 569ff559fabSmrg 570ff559fabSmrgdashmstdout) 571ff559fabSmrg # Important note: in order to support this mode, a compiler *must* 572ff559fabSmrg # always write the preprocessed file to stdout, regardless of -o. 573ff559fabSmrg "$@" || exit $? 574ff559fabSmrg 575ff559fabSmrg # Remove the call to Libtool. 576ff559fabSmrg if test "$libtool" = yes; then 57744dda7b2Smrg while test "X$1" != 'X--mode=compile'; do 578ff559fabSmrg shift 579ff559fabSmrg done 580ff559fabSmrg shift 581ff559fabSmrg fi 582ff559fabSmrg 583fc544a13Smrg # Remove '-o $object'. 584ff559fabSmrg IFS=" " 585ff559fabSmrg for arg 586ff559fabSmrg do 587ff559fabSmrg case $arg in 588ff559fabSmrg -o) 589ff559fabSmrg shift 590ff559fabSmrg ;; 591ff559fabSmrg $object) 592ff559fabSmrg shift 593ff559fabSmrg ;; 594ff559fabSmrg *) 595ff559fabSmrg set fnord "$@" "$arg" 596ff559fabSmrg shift # fnord 597ff559fabSmrg shift # $arg 598ff559fabSmrg ;; 599ff559fabSmrg esac 600ff559fabSmrg done 601ff559fabSmrg 602ff559fabSmrg test -z "$dashmflag" && dashmflag=-M 603fc544a13Smrg # Require at least two characters before searching for ':' 604ff559fabSmrg # in the target name. This is to cope with DOS-style filenames: 605fc544a13Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606ff559fabSmrg "$@" $dashmflag | 607fc544a13Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608ff559fabSmrg rm -f "$depfile" 609ff559fabSmrg cat < "$tmpdepfile" > "$depfile" 610fc544a13Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611fc544a13Smrg # correctly. Breaking it into two sed invocations is a workaround. 612fc544a13Smrg tr ' ' "$nl" < "$tmpdepfile" \ 613fc544a13Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614fc544a13Smrg | sed -e 's/$/ :/' >> "$depfile" 615ff559fabSmrg rm -f "$tmpdepfile" 616ff559fabSmrg ;; 617ff559fabSmrg 618ff559fabSmrgdashXmstdout) 619ff559fabSmrg # This case only exists to satisfy depend.m4. It is never actually 620ff559fabSmrg # run, as this mode is specially recognized in the preamble. 621ff559fabSmrg exit 1 622ff559fabSmrg ;; 623ff559fabSmrg 624ff559fabSmrgmakedepend) 625ff559fabSmrg "$@" || exit $? 626ff559fabSmrg # Remove any Libtool call 627ff559fabSmrg if test "$libtool" = yes; then 62844dda7b2Smrg while test "X$1" != 'X--mode=compile'; do 629ff559fabSmrg shift 630ff559fabSmrg done 631ff559fabSmrg shift 632ff559fabSmrg fi 633ff559fabSmrg # X makedepend 634ff559fabSmrg shift 63544dda7b2Smrg cleared=no eat=no 63644dda7b2Smrg for arg 63744dda7b2Smrg do 638ff559fabSmrg case $cleared in 639ff559fabSmrg no) 640ff559fabSmrg set ""; shift 641ff559fabSmrg cleared=yes ;; 642ff559fabSmrg esac 64344dda7b2Smrg if test $eat = yes; then 64444dda7b2Smrg eat=no 64544dda7b2Smrg continue 64644dda7b2Smrg fi 647ff559fabSmrg case "$arg" in 648ff559fabSmrg -D*|-I*) 649ff559fabSmrg set fnord "$@" "$arg"; shift ;; 650ff559fabSmrg # Strip any option that makedepend may not understand. Remove 651ff559fabSmrg # the object too, otherwise makedepend will parse it as a source file. 65244dda7b2Smrg -arch) 65344dda7b2Smrg eat=yes ;; 654ff559fabSmrg -*|$object) 655ff559fabSmrg ;; 656ff559fabSmrg *) 657ff559fabSmrg set fnord "$@" "$arg"; shift ;; 658ff559fabSmrg esac 659ff559fabSmrg done 66044dda7b2Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661ff559fabSmrg touch "$tmpdepfile" 662ff559fabSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663ff559fabSmrg rm -f "$depfile" 664fc544a13Smrg # makedepend may prepend the VPATH from the source file name to the object. 665fc544a13Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666fc544a13Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667fc544a13Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668fc544a13Smrg # correctly. Breaking it into two sed invocations is a workaround. 669fc544a13Smrg sed '1,2d' "$tmpdepfile" \ 670fc544a13Smrg | tr ' ' "$nl" \ 671fc544a13Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672fc544a13Smrg | sed -e 's/$/ :/' >> "$depfile" 673ff559fabSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674ff559fabSmrg ;; 675ff559fabSmrg 676ff559fabSmrgcpp) 677ff559fabSmrg # Important note: in order to support this mode, a compiler *must* 678ff559fabSmrg # always write the preprocessed file to stdout. 679ff559fabSmrg "$@" || exit $? 680ff559fabSmrg 681ff559fabSmrg # Remove the call to Libtool. 682ff559fabSmrg if test "$libtool" = yes; then 68344dda7b2Smrg while test "X$1" != 'X--mode=compile'; do 684ff559fabSmrg shift 685ff559fabSmrg done 686ff559fabSmrg shift 687ff559fabSmrg fi 688ff559fabSmrg 689fc544a13Smrg # Remove '-o $object'. 690ff559fabSmrg IFS=" " 691ff559fabSmrg for arg 692ff559fabSmrg do 693ff559fabSmrg case $arg in 694ff559fabSmrg -o) 695ff559fabSmrg shift 696ff559fabSmrg ;; 697ff559fabSmrg $object) 698ff559fabSmrg shift 699ff559fabSmrg ;; 700ff559fabSmrg *) 701ff559fabSmrg set fnord "$@" "$arg" 702ff559fabSmrg shift # fnord 703ff559fabSmrg shift # $arg 704ff559fabSmrg ;; 705ff559fabSmrg esac 706ff559fabSmrg done 707ff559fabSmrg 708fc544a13Smrg "$@" -E \ 709fc544a13Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710fc544a13Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711fc544a13Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712ff559fabSmrg rm -f "$depfile" 713ff559fabSmrg echo "$object : \\" > "$depfile" 714ff559fabSmrg cat < "$tmpdepfile" >> "$depfile" 715ff559fabSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716ff559fabSmrg rm -f "$tmpdepfile" 717ff559fabSmrg ;; 718ff559fabSmrg 719ff559fabSmrgmsvisualcpp) 720ff559fabSmrg # Important note: in order to support this mode, a compiler *must* 72144dda7b2Smrg # always write the preprocessed file to stdout. 722ff559fabSmrg "$@" || exit $? 72344dda7b2Smrg 72444dda7b2Smrg # Remove the call to Libtool. 72544dda7b2Smrg if test "$libtool" = yes; then 72644dda7b2Smrg while test "X$1" != 'X--mode=compile'; do 72744dda7b2Smrg shift 72844dda7b2Smrg done 72944dda7b2Smrg shift 73044dda7b2Smrg fi 73144dda7b2Smrg 732ff559fabSmrg IFS=" " 733ff559fabSmrg for arg 734ff559fabSmrg do 735ff559fabSmrg case "$arg" in 73644dda7b2Smrg -o) 73744dda7b2Smrg shift 73844dda7b2Smrg ;; 73944dda7b2Smrg $object) 74044dda7b2Smrg shift 74144dda7b2Smrg ;; 742ff559fabSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743fc544a13Smrg set fnord "$@" 744fc544a13Smrg shift 745fc544a13Smrg shift 746fc544a13Smrg ;; 747ff559fabSmrg *) 748fc544a13Smrg set fnord "$@" "$arg" 749fc544a13Smrg shift 750fc544a13Smrg shift 751fc544a13Smrg ;; 752ff559fabSmrg esac 753ff559fabSmrg done 75444dda7b2Smrg "$@" -E 2>/dev/null | 75544dda7b2Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756ff559fabSmrg rm -f "$depfile" 757ff559fabSmrg echo "$object : \\" > "$depfile" 758fc544a13Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759fc544a13Smrg echo "$tab" >> "$depfile" 76044dda7b2Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761ff559fabSmrg rm -f "$tmpdepfile" 762ff559fabSmrg ;; 763ff559fabSmrg 76444dda7b2Smrgmsvcmsys) 76544dda7b2Smrg # This case exists only to let depend.m4 do its work. It works by 76644dda7b2Smrg # looking at the text of this script. This case will never be run, 76744dda7b2Smrg # since it is checked for above. 76844dda7b2Smrg exit 1 76944dda7b2Smrg ;; 77044dda7b2Smrg 771ff559fabSmrgnone) 772ff559fabSmrg exec "$@" 773ff559fabSmrg ;; 774ff559fabSmrg 775ff559fabSmrg*) 776ff559fabSmrg echo "Unknown depmode $depmode" 1>&2 777ff559fabSmrg exit 1 778ff559fabSmrg ;; 779ff559fabSmrgesac 780ff559fabSmrg 781ff559fabSmrgexit 0 782ff559fabSmrg 783ff559fabSmrg# Local Variables: 784ff559fabSmrg# mode: shell-script 785ff559fabSmrg# sh-indentation: 2 786515ec619Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 787ff559fabSmrg# time-stamp-start: "scriptversion=" 788ff559fabSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789515ec619Smrg# time-stamp-time-zone: "UTC0" 79044dda7b2Smrg# time-stamp-end: "; # UTC" 791ff559fabSmrg# End: 792