1a253d6aeSmrg#! /bin/sh 2a253d6aeSmrg# depcomp - compile a program generating dependencies as side-effects 3a253d6aeSmrg 410f94802Smrgscriptversion=2024-06-19.01; # UTC 5a253d6aeSmrg 610f94802Smrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 7a253d6aeSmrg 8a253d6aeSmrg# This program is free software; you can redistribute it and/or modify 9a253d6aeSmrg# it under the terms of the GNU General Public License as published by 10a253d6aeSmrg# the Free Software Foundation; either version 2, or (at your option) 11a253d6aeSmrg# any later version. 12a253d6aeSmrg 13a253d6aeSmrg# This program is distributed in the hope that it will be useful, 14a253d6aeSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15a253d6aeSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a253d6aeSmrg# GNU General Public License for more details. 17a253d6aeSmrg 18a253d6aeSmrg# You should have received a copy of the GNU General Public License 19b41a30aaSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20a253d6aeSmrg 21a253d6aeSmrg# As a special exception to the GNU General Public License, if you 22a253d6aeSmrg# distribute this file as part of a program that contains a 23a253d6aeSmrg# configuration script generated by Autoconf, you may include it under 24a253d6aeSmrg# the same distribution terms that you use for the rest of that program. 25a253d6aeSmrg 26a253d6aeSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27a253d6aeSmrg 28a253d6aeSmrgcase $1 in 29a253d6aeSmrg '') 3057ee1794Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3157ee1794Smrg exit 1; 3257ee1794Smrg ;; 33a253d6aeSmrg -h | --h*) 34a253d6aeSmrg cat <<\EOF 35a253d6aeSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36a253d6aeSmrg 37a253d6aeSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38a253d6aeSmrgas side-effects. 39a253d6aeSmrg 40a253d6aeSmrgEnvironment variables: 41a253d6aeSmrg depmode Dependency tracking mode. 4257ee1794Smrg source Source file read by 'PROGRAMS ARGS'. 4357ee1794Smrg object Object file output by 'PROGRAMS ARGS'. 44a253d6aeSmrg DEPDIR directory where to store dependencies. 45a253d6aeSmrg depfile Dependency file to output. 4657ee1794Smrg tmpdepfile Temporary file to use when outputting dependencies. 47a253d6aeSmrg libtool Whether libtool is used (yes/no). 48a253d6aeSmrg 49a253d6aeSmrgReport bugs to <bug-automake@gnu.org>. 5010f94802SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 5110f94802SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 52a253d6aeSmrgEOF 53a253d6aeSmrg exit $? 54a253d6aeSmrg ;; 55a253d6aeSmrg -v | --v*) 5610f94802Smrg echo "depcomp (GNU Automake) $scriptversion" 57a253d6aeSmrg exit $? 58a253d6aeSmrg ;; 59a253d6aeSmrgesac 60a253d6aeSmrg 6157ee1794Smrg# Get the directory component of the given path, and save it in the 6257ee1794Smrg# global variables '$dir'. Note that this directory component will 6357ee1794Smrg# be either empty or ending with a '/' character. This is deliberate. 6457ee1794Smrgset_dir_from () 6557ee1794Smrg{ 6657ee1794Smrg case $1 in 6757ee1794Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6857ee1794Smrg *) dir=;; 6957ee1794Smrg esac 7057ee1794Smrg} 7157ee1794Smrg 7257ee1794Smrg# Get the suffix-stripped basename of the given path, and save it the 7357ee1794Smrg# global variable '$base'. 7457ee1794Smrgset_base_from () 7557ee1794Smrg{ 7657ee1794Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7757ee1794Smrg} 7857ee1794Smrg 7957ee1794Smrg# If no dependency file was actually created by the compiler invocation, 8057ee1794Smrg# we still have to create a dummy depfile, to avoid errors with the 8157ee1794Smrg# Makefile "include basename.Plo" scheme. 8257ee1794Smrgmake_dummy_depfile () 8357ee1794Smrg{ 8457ee1794Smrg echo "#dummy" > "$depfile" 8557ee1794Smrg} 8657ee1794Smrg 8757ee1794Smrg# Factor out some common post-processing of the generated depfile. 8857ee1794Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8957ee1794Smrgaix_post_process_depfile () 9057ee1794Smrg{ 9157ee1794Smrg # If the compiler actually managed to produce a dependency file, 9257ee1794Smrg # post-process it. 9357ee1794Smrg if test -f "$tmpdepfile"; then 9457ee1794Smrg # Each line is of the form 'foo.o: dependency.h'. 9557ee1794Smrg # Do two passes, one to just change these to 9657ee1794Smrg # $object: dependency.h 9757ee1794Smrg # and one to simply output 9857ee1794Smrg # dependency.h: 9957ee1794Smrg # which is needed to avoid the deleted-header problem. 10057ee1794Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 10157ee1794Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10257ee1794Smrg } > "$depfile" 10357ee1794Smrg rm -f "$tmpdepfile" 10457ee1794Smrg else 10557ee1794Smrg make_dummy_depfile 10657ee1794Smrg fi 10757ee1794Smrg} 10857ee1794Smrg 10957ee1794Smrg# A tabulation character. 11057ee1794Smrgtab=' ' 11157ee1794Smrg# A newline character. 11257ee1794Smrgnl=' 11357ee1794Smrg' 11457ee1794Smrg# Character ranges might be problematic outside the C locale. 11557ee1794Smrg# These definitions help. 11657ee1794Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11757ee1794Smrglower=abcdefghijklmnopqrstuvwxyz 11857ee1794Smrgalpha=${upper}${lower} 11957ee1794Smrg 120a253d6aeSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 121a253d6aeSmrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 122a253d6aeSmrg exit 1 123a253d6aeSmrgfi 124a253d6aeSmrg 125a253d6aeSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 126a253d6aeSmrgdepfile=${depfile-`echo "$object" | 127a253d6aeSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 128a253d6aeSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 129a253d6aeSmrg 130a253d6aeSmrgrm -f "$tmpdepfile" 131a253d6aeSmrg 13210f94802Smrg# Avoid interference from the environment. 13357ee1794Smrggccflag= dashmflag= 13457ee1794Smrg 135a253d6aeSmrg# Some modes work just like other modes, but use different flags. We 136a253d6aeSmrg# parameterize here, but still list the modes in the big case below, 137a253d6aeSmrg# to make depend.m4 easier to write. Note that we *cannot* use a case 138a253d6aeSmrg# here, because this file can only contain one case statement. 139a253d6aeSmrgif test "$depmode" = hp; then 140a253d6aeSmrg # HP compiler uses -M and no extra arg. 141a253d6aeSmrg gccflag=-M 142a253d6aeSmrg depmode=gcc 143a253d6aeSmrgfi 144a253d6aeSmrg 145a253d6aeSmrgif test "$depmode" = dashXmstdout; then 14657ee1794Smrg # This is just like dashmstdout with a different argument. 14757ee1794Smrg dashmflag=-xM 14857ee1794Smrg depmode=dashmstdout 149a253d6aeSmrgfi 150a253d6aeSmrg 15125b89263Smrgcygpath_u="cygpath -u -f -" 15225b89263Smrgif test "$depmode" = msvcmsys; then 15357ee1794Smrg # This is just like msvisualcpp but w/o cygpath translation. 15457ee1794Smrg # Just convert the backslash-escaped backslashes to single forward 15557ee1794Smrg # slashes to satisfy depend.m4 15657ee1794Smrg cygpath_u='sed s,\\\\,/,g' 15757ee1794Smrg depmode=msvisualcpp 15857ee1794Smrgfi 15957ee1794Smrg 16057ee1794Smrgif test "$depmode" = msvc7msys; then 16157ee1794Smrg # This is just like msvc7 but w/o cygpath translation. 16257ee1794Smrg # Just convert the backslash-escaped backslashes to single forward 16357ee1794Smrg # slashes to satisfy depend.m4 16457ee1794Smrg cygpath_u='sed s,\\\\,/,g' 16557ee1794Smrg depmode=msvc7 16657ee1794Smrgfi 16757ee1794Smrg 16857ee1794Smrgif test "$depmode" = xlc; then 16957ee1794Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 17057ee1794Smrg gccflag=-qmakedep=gcc,-MF 17157ee1794Smrg depmode=gcc 17225b89263Smrgfi 17325b89263Smrg 174a253d6aeSmrgcase "$depmode" in 175a253d6aeSmrggcc3) 176a253d6aeSmrg## gcc 3 implements dependency tracking that does exactly what 177a253d6aeSmrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 178a253d6aeSmrg## it if -MD -MP comes after the -MF stuff. Hmm. 179a253d6aeSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 180a253d6aeSmrg## the command line argument order; so add the flags where they 181a253d6aeSmrg## appear in depend2.am. Note that the slowdown incurred here 182a253d6aeSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 183a253d6aeSmrg for arg 184a253d6aeSmrg do 185a253d6aeSmrg case $arg in 186a253d6aeSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 187a253d6aeSmrg *) set fnord "$@" "$arg" ;; 188a253d6aeSmrg esac 189a253d6aeSmrg shift # fnord 190a253d6aeSmrg shift # $arg 191a253d6aeSmrg done 192a253d6aeSmrg "$@" 193a253d6aeSmrg stat=$? 19457ee1794Smrg if test $stat -ne 0; then 195a253d6aeSmrg rm -f "$tmpdepfile" 196a253d6aeSmrg exit $stat 197a253d6aeSmrg fi 198a253d6aeSmrg mv "$tmpdepfile" "$depfile" 199a253d6aeSmrg ;; 200a253d6aeSmrg 201a253d6aeSmrggcc) 20210f94802Smrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 20310f94802Smrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 20457ee1794Smrg## (see the conditional assignment to $gccflag above). 205a253d6aeSmrg## There are various ways to get dependency output from gcc. Here's 206a253d6aeSmrg## why we pick this rather obscure method: 207a253d6aeSmrg## - Don't want to use -MD because we'd like the dependencies to end 208a253d6aeSmrg## up in a subdir. Having to rename by hand is ugly. 209a253d6aeSmrg## (We might end up doing this anyway to support other compilers.) 210a253d6aeSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21157ee1794Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21257ee1794Smrg## supported by the other compilers which use the 'gcc' depmode. 213a253d6aeSmrg## - Using -M directly means running the compiler twice (even worse 214a253d6aeSmrg## than renaming). 215a253d6aeSmrg if test -z "$gccflag"; then 216a253d6aeSmrg gccflag=-MD, 217a253d6aeSmrg fi 218a253d6aeSmrg "$@" -Wp,"$gccflag$tmpdepfile" 219a253d6aeSmrg stat=$? 22057ee1794Smrg if test $stat -ne 0; then 221a253d6aeSmrg rm -f "$tmpdepfile" 222a253d6aeSmrg exit $stat 223a253d6aeSmrg fi 224a253d6aeSmrg rm -f "$depfile" 225a253d6aeSmrg echo "$object : \\" > "$depfile" 22657ee1794Smrg # The second -e expression handles DOS-style file names with drive 22757ee1794Smrg # letters. 228a253d6aeSmrg sed -e 's/^[^:]*: / /' \ 229a253d6aeSmrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 23057ee1794Smrg## This next piece of magic avoids the "deleted header file" problem. 231a253d6aeSmrg## The problem is that when a header file which appears in a .P file 232a253d6aeSmrg## is deleted, the dependency causes make to die (because there is 233a253d6aeSmrg## typically no way to rebuild the header). We avoid this by adding 234a253d6aeSmrg## dummy dependencies for each header file. Too bad gcc doesn't do 235a253d6aeSmrg## this for us directly. 23657ee1794Smrg## Some versions of gcc put a space before the ':'. On the theory 237a253d6aeSmrg## that the space means something, we add a space to the output as 23857ee1794Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 23957ee1794Smrg## to the object. Take care to not repeat it in the output. 240a253d6aeSmrg## Some versions of the HPUX 10.20 sed can't process this invocation 241a253d6aeSmrg## correctly. Breaking it into two sed invocations is a workaround. 24257ee1794Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24357ee1794Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24457ee1794Smrg | sed -e 's/$/ :/' >> "$depfile" 245a253d6aeSmrg rm -f "$tmpdepfile" 246a253d6aeSmrg ;; 247a253d6aeSmrg 248a253d6aeSmrghp) 249a253d6aeSmrg # This case exists only to let depend.m4 do its work. It works by 250a253d6aeSmrg # looking at the text of this script. This case will never be run, 251a253d6aeSmrg # since it is checked for above. 252a253d6aeSmrg exit 1 253a253d6aeSmrg ;; 254a253d6aeSmrg 255a253d6aeSmrgsgi) 256a253d6aeSmrg if test "$libtool" = yes; then 257a253d6aeSmrg "$@" "-Wp,-MDupdate,$tmpdepfile" 258a253d6aeSmrg else 259a253d6aeSmrg "$@" -MDupdate "$tmpdepfile" 260a253d6aeSmrg fi 261a253d6aeSmrg stat=$? 26257ee1794Smrg if test $stat -ne 0; then 263a253d6aeSmrg rm -f "$tmpdepfile" 264a253d6aeSmrg exit $stat 265a253d6aeSmrg fi 266a253d6aeSmrg rm -f "$depfile" 267a253d6aeSmrg 268a253d6aeSmrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 269a253d6aeSmrg echo "$object : \\" > "$depfile" 270a253d6aeSmrg # Clip off the initial element (the dependent). Don't try to be 271a253d6aeSmrg # clever and replace this with sed code, as IRIX sed won't handle 272a253d6aeSmrg # lines with more than a fixed number of characters (4096 in 273a253d6aeSmrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27457ee1794Smrg # the IRIX cc adds comments like '#:fec' to the end of the 275a253d6aeSmrg # dependency line. 27657ee1794Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27757ee1794Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27857ee1794Smrg | tr "$nl" ' ' >> "$depfile" 27925b89263Smrg echo >> "$depfile" 280a253d6aeSmrg # The second pass generates a dummy entry for each header file. 28157ee1794Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28257ee1794Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28357ee1794Smrg >> "$depfile" 284a253d6aeSmrg else 28557ee1794Smrg make_dummy_depfile 286a253d6aeSmrg fi 287a253d6aeSmrg rm -f "$tmpdepfile" 288a253d6aeSmrg ;; 289a253d6aeSmrg 29057ee1794Smrgxlc) 29157ee1794Smrg # This case exists only to let depend.m4 do its work. It works by 29257ee1794Smrg # looking at the text of this script. This case will never be run, 29357ee1794Smrg # since it is checked for above. 29457ee1794Smrg exit 1 29557ee1794Smrg ;; 29657ee1794Smrg 297a253d6aeSmrgaix) 298a253d6aeSmrg # The C for AIX Compiler uses -M and outputs the dependencies 299a253d6aeSmrg # in a .u file. In older versions, this file always lives in the 30057ee1794Smrg # current directory. Also, the AIX compiler puts '$object:' at the 301a253d6aeSmrg # start of each line; $object doesn't have directory information. 302a253d6aeSmrg # Version 6 uses the directory in both cases. 30357ee1794Smrg set_dir_from "$object" 30457ee1794Smrg set_base_from "$object" 305a253d6aeSmrg if test "$libtool" = yes; then 306ea133fd7Smrg tmpdepfile1=$dir$base.u 307ea133fd7Smrg tmpdepfile2=$base.u 308ea133fd7Smrg tmpdepfile3=$dir.libs/$base.u 309a253d6aeSmrg "$@" -Wc,-M 310a253d6aeSmrg else 311ea133fd7Smrg tmpdepfile1=$dir$base.u 312ea133fd7Smrg tmpdepfile2=$dir$base.u 313ea133fd7Smrg tmpdepfile3=$dir$base.u 314a253d6aeSmrg "$@" -M 315a253d6aeSmrg fi 316a253d6aeSmrg stat=$? 31757ee1794Smrg if test $stat -ne 0; then 318ea133fd7Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 319a253d6aeSmrg exit $stat 320a253d6aeSmrg fi 321a253d6aeSmrg 322ea133fd7Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 323ea133fd7Smrg do 324ea133fd7Smrg test -f "$tmpdepfile" && break 325ea133fd7Smrg done 32657ee1794Smrg aix_post_process_depfile 32757ee1794Smrg ;; 32857ee1794Smrg 32957ee1794Smrgtcc) 33057ee1794Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33157ee1794Smrg # FIXME: That version still under development at the moment of writing. 33257ee1794Smrg # Make that this statement remains true also for stable, released 33357ee1794Smrg # versions. 33457ee1794Smrg # It will wrap lines (doesn't matter whether long or short) with a 33557ee1794Smrg # trailing '\', as in: 33657ee1794Smrg # 33757ee1794Smrg # foo.o : \ 33857ee1794Smrg # foo.c \ 33957ee1794Smrg # foo.h \ 34057ee1794Smrg # 34157ee1794Smrg # It will put a trailing '\' even on the last line, and will use leading 34257ee1794Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34357ee1794Smrg # "Emit spaces for -MD"). 34457ee1794Smrg "$@" -MD -MF "$tmpdepfile" 34557ee1794Smrg stat=$? 34657ee1794Smrg if test $stat -ne 0; then 34757ee1794Smrg rm -f "$tmpdepfile" 34857ee1794Smrg exit $stat 349a253d6aeSmrg fi 35057ee1794Smrg rm -f "$depfile" 35157ee1794Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35257ee1794Smrg # We have to change lines of the first kind to '$object: \'. 35357ee1794Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35457ee1794Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35557ee1794Smrg # dummy dependency, to avoid the deleted-header problem. 35657ee1794Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 357a253d6aeSmrg rm -f "$tmpdepfile" 358a253d6aeSmrg ;; 359a253d6aeSmrg 36057ee1794Smrg## The order of this option in the case statement is important, since the 36157ee1794Smrg## shell code in configure will try each of these formats in the order 36257ee1794Smrg## listed in this file. A plain '-MD' option would be understood by many 36357ee1794Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36457ee1794Smrgpgcc) 36557ee1794Smrg # Portland's C compiler understands '-MD'. 36657ee1794Smrg # Will always output deps to 'file.d' where file is the root name of the 36757ee1794Smrg # source file under compilation, even if file resides in a subdirectory. 36857ee1794Smrg # The object file name does not affect the name of the '.d' file. 36957ee1794Smrg # pgcc 10.2 will output 370a253d6aeSmrg # foo.o: sub/foo.c sub/foo.h 37157ee1794Smrg # and will wrap long lines using '\' : 372a253d6aeSmrg # foo.o: sub/foo.c ... \ 373a253d6aeSmrg # sub/foo.h ... \ 374a253d6aeSmrg # ... 37557ee1794Smrg set_dir_from "$object" 37657ee1794Smrg # Use the source, not the object, to determine the base name, since 37757ee1794Smrg # that's sadly what pgcc will do too. 37857ee1794Smrg set_base_from "$source" 37957ee1794Smrg tmpdepfile=$base.d 38057ee1794Smrg 38157ee1794Smrg # For projects that build the same source file twice into different object 38257ee1794Smrg # files, the pgcc approach of using the *source* file root name can cause 38357ee1794Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38457ee1794Smrg # the same $tmpdepfile. 38557ee1794Smrg lockdir=$base.d-lock 38657ee1794Smrg trap " 38757ee1794Smrg echo '$0: caught signal, cleaning up...' >&2 38857ee1794Smrg rmdir '$lockdir' 38957ee1794Smrg exit 1 39057ee1794Smrg " 1 2 13 15 39157ee1794Smrg numtries=100 39257ee1794Smrg i=$numtries 39357ee1794Smrg while test $i -gt 0; do 39457ee1794Smrg # mkdir is a portable test-and-set. 39557ee1794Smrg if mkdir "$lockdir" 2>/dev/null; then 39657ee1794Smrg # This process acquired the lock. 39757ee1794Smrg "$@" -MD 39857ee1794Smrg stat=$? 39957ee1794Smrg # Release the lock. 40057ee1794Smrg rmdir "$lockdir" 40157ee1794Smrg break 40257ee1794Smrg else 40357ee1794Smrg # If the lock is being held by a different process, wait 40457ee1794Smrg # until the winning process is done or we timeout. 40557ee1794Smrg while test -d "$lockdir" && test $i -gt 0; do 40657ee1794Smrg sleep 1 40757ee1794Smrg i=`expr $i - 1` 40857ee1794Smrg done 40957ee1794Smrg fi 41057ee1794Smrg i=`expr $i - 1` 41157ee1794Smrg done 41257ee1794Smrg trap - 1 2 13 15 41357ee1794Smrg if test $i -le 0; then 41457ee1794Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41557ee1794Smrg echo "$0: check lockdir '$lockdir'" >&2 41657ee1794Smrg exit 1 41757ee1794Smrg fi 418a253d6aeSmrg 41957ee1794Smrg if test $stat -ne 0; then 420a253d6aeSmrg rm -f "$tmpdepfile" 421a253d6aeSmrg exit $stat 422a253d6aeSmrg fi 423a253d6aeSmrg rm -f "$depfile" 424a253d6aeSmrg # Each line is of the form `foo.o: dependent.h', 425a253d6aeSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 426a253d6aeSmrg # Do two passes, one to just change these to 427a253d6aeSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 428a253d6aeSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 429a253d6aeSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 430a253d6aeSmrg # correctly. Breaking it into two sed invocations is a workaround. 43157ee1794Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43257ee1794Smrg | sed -e 's/$/ :/' >> "$depfile" 433a253d6aeSmrg rm -f "$tmpdepfile" 434a253d6aeSmrg ;; 435a253d6aeSmrg 436a253d6aeSmrghp2) 437a253d6aeSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 438a253d6aeSmrg # compilers, which have integrated preprocessors. The correct option 439a253d6aeSmrg # to use with these is +Maked; it writes dependencies to a file named 440a253d6aeSmrg # 'foo.d', which lands next to the object file, wherever that 441a253d6aeSmrg # happens to be. 442a253d6aeSmrg # Much of this is similar to the tru64 case; see comments there. 44357ee1794Smrg set_dir_from "$object" 44457ee1794Smrg set_base_from "$object" 445a253d6aeSmrg if test "$libtool" = yes; then 446a253d6aeSmrg tmpdepfile1=$dir$base.d 447a253d6aeSmrg tmpdepfile2=$dir.libs/$base.d 448a253d6aeSmrg "$@" -Wc,+Maked 449a253d6aeSmrg else 450a253d6aeSmrg tmpdepfile1=$dir$base.d 451a253d6aeSmrg tmpdepfile2=$dir$base.d 452a253d6aeSmrg "$@" +Maked 453a253d6aeSmrg fi 454a253d6aeSmrg stat=$? 45557ee1794Smrg if test $stat -ne 0; then 456a253d6aeSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 457a253d6aeSmrg exit $stat 458a253d6aeSmrg fi 459a253d6aeSmrg 460a253d6aeSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 461a253d6aeSmrg do 462a253d6aeSmrg test -f "$tmpdepfile" && break 463a253d6aeSmrg done 464a253d6aeSmrg if test -f "$tmpdepfile"; then 46557ee1794Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46657ee1794Smrg # Add 'dependent.h:' lines. 46725b89263Smrg sed -ne '2,${ 46857ee1794Smrg s/^ *// 46957ee1794Smrg s/ \\*$// 47057ee1794Smrg s/$/:/ 47157ee1794Smrg p 47257ee1794Smrg }' "$tmpdepfile" >> "$depfile" 473a253d6aeSmrg else 47457ee1794Smrg make_dummy_depfile 475a253d6aeSmrg fi 476a253d6aeSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 477a253d6aeSmrg ;; 478a253d6aeSmrg 479a253d6aeSmrgtru64) 48057ee1794Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48157ee1794Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48257ee1794Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48357ee1794Smrg # dependencies in 'foo.d' instead, so we check for that too. 48457ee1794Smrg # Subdirectories are respected. 48557ee1794Smrg set_dir_from "$object" 48657ee1794Smrg set_base_from "$object" 48757ee1794Smrg 48857ee1794Smrg if test "$libtool" = yes; then 48957ee1794Smrg # Libtool generates 2 separate objects for the 2 libraries. These 49057ee1794Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49157ee1794Smrg # in $dir$base.o.d. We have to check for both files, because 49257ee1794Smrg # one of the two compilations can be disabled. We should prefer 49357ee1794Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49457ee1794Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49557ee1794Smrg # the former would cause a distcleancheck panic. 49657ee1794Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49757ee1794Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49857ee1794Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49957ee1794Smrg "$@" -Wc,-MD 50057ee1794Smrg else 50157ee1794Smrg tmpdepfile1=$dir$base.d 50257ee1794Smrg tmpdepfile2=$dir$base.d 50357ee1794Smrg tmpdepfile3=$dir$base.d 50457ee1794Smrg "$@" -MD 50557ee1794Smrg fi 50657ee1794Smrg 50757ee1794Smrg stat=$? 50857ee1794Smrg if test $stat -ne 0; then 50957ee1794Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51057ee1794Smrg exit $stat 51157ee1794Smrg fi 51257ee1794Smrg 51357ee1794Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51457ee1794Smrg do 51557ee1794Smrg test -f "$tmpdepfile" && break 51657ee1794Smrg done 51757ee1794Smrg # Same post-processing that is required for AIX mode. 51857ee1794Smrg aix_post_process_depfile 51957ee1794Smrg ;; 52057ee1794Smrg 52157ee1794Smrgmsvc7) 52257ee1794Smrg if test "$libtool" = yes; then 52357ee1794Smrg showIncludes=-Wc,-showIncludes 52457ee1794Smrg else 52557ee1794Smrg showIncludes=-showIncludes 52657ee1794Smrg fi 52757ee1794Smrg "$@" $showIncludes > "$tmpdepfile" 52857ee1794Smrg stat=$? 52957ee1794Smrg grep -v '^Note: including file: ' "$tmpdepfile" 53057ee1794Smrg if test $stat -ne 0; then 53157ee1794Smrg rm -f "$tmpdepfile" 53257ee1794Smrg exit $stat 53357ee1794Smrg fi 53457ee1794Smrg rm -f "$depfile" 53557ee1794Smrg echo "$object : \\" > "$depfile" 53657ee1794Smrg # The first sed program below extracts the file names and escapes 53757ee1794Smrg # backslashes for cygpath. The second sed program outputs the file 53857ee1794Smrg # name when reading, but also accumulates all include files in the 53957ee1794Smrg # hold buffer in order to output them again at the end. This only 54057ee1794Smrg # works with sed implementations that can handle large buffers. 54157ee1794Smrg sed < "$tmpdepfile" -n ' 54257ee1794Smrg/^Note: including file: *\(.*\)/ { 54357ee1794Smrg s//\1/ 54457ee1794Smrg s/\\/\\\\/g 54557ee1794Smrg p 54657ee1794Smrg}' | $cygpath_u | sort -u | sed -n ' 54757ee1794Smrgs/ /\\ /g 54857ee1794Smrgs/\(.*\)/'"$tab"'\1 \\/p 54957ee1794Smrgs/.\(.*\) \\/\1:/ 55057ee1794SmrgH 55157ee1794Smrg$ { 55257ee1794Smrg s/.*/'"$tab"'/ 55357ee1794Smrg G 55457ee1794Smrg p 55557ee1794Smrg}' >> "$depfile" 55631637056Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 55757ee1794Smrg rm -f "$tmpdepfile" 55857ee1794Smrg ;; 55957ee1794Smrg 56057ee1794Smrgmsvc7msys) 56157ee1794Smrg # This case exists only to let depend.m4 do its work. It works by 56257ee1794Smrg # looking at the text of this script. This case will never be run, 56357ee1794Smrg # since it is checked for above. 56457ee1794Smrg exit 1 56557ee1794Smrg ;; 566a253d6aeSmrg 567a253d6aeSmrg#nosideeffect) 568a253d6aeSmrg # This comment above is used by automake to tell side-effect 569a253d6aeSmrg # dependency tracking mechanisms from slower ones. 570a253d6aeSmrg 571a253d6aeSmrgdashmstdout) 572a253d6aeSmrg # Important note: in order to support this mode, a compiler *must* 573a253d6aeSmrg # always write the preprocessed file to stdout, regardless of -o. 574a253d6aeSmrg "$@" || exit $? 575a253d6aeSmrg 576a253d6aeSmrg # Remove the call to Libtool. 577a253d6aeSmrg if test "$libtool" = yes; then 57825b89263Smrg while test "X$1" != 'X--mode=compile'; do 579a253d6aeSmrg shift 580a253d6aeSmrg done 581a253d6aeSmrg shift 582a253d6aeSmrg fi 583a253d6aeSmrg 58457ee1794Smrg # Remove '-o $object'. 585a253d6aeSmrg IFS=" " 586a253d6aeSmrg for arg 587a253d6aeSmrg do 588a253d6aeSmrg case $arg in 589a253d6aeSmrg -o) 590a253d6aeSmrg shift 591a253d6aeSmrg ;; 592a253d6aeSmrg $object) 593a253d6aeSmrg shift 594a253d6aeSmrg ;; 595a253d6aeSmrg *) 596a253d6aeSmrg set fnord "$@" "$arg" 597a253d6aeSmrg shift # fnord 598a253d6aeSmrg shift # $arg 599a253d6aeSmrg ;; 600a253d6aeSmrg esac 601a253d6aeSmrg done 602a253d6aeSmrg 603a253d6aeSmrg test -z "$dashmflag" && dashmflag=-M 60457ee1794Smrg # Require at least two characters before searching for ':' 605a253d6aeSmrg # in the target name. This is to cope with DOS-style filenames: 60657ee1794Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 607a253d6aeSmrg "$@" $dashmflag | 60857ee1794Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 609a253d6aeSmrg rm -f "$depfile" 610a253d6aeSmrg cat < "$tmpdepfile" > "$depfile" 61157ee1794Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61257ee1794Smrg # correctly. Breaking it into two sed invocations is a workaround. 61357ee1794Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61457ee1794Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61557ee1794Smrg | sed -e 's/$/ :/' >> "$depfile" 616a253d6aeSmrg rm -f "$tmpdepfile" 617a253d6aeSmrg ;; 618a253d6aeSmrg 619a253d6aeSmrgdashXmstdout) 620a253d6aeSmrg # This case only exists to satisfy depend.m4. It is never actually 621a253d6aeSmrg # run, as this mode is specially recognized in the preamble. 622a253d6aeSmrg exit 1 623a253d6aeSmrg ;; 624a253d6aeSmrg 625a253d6aeSmrgmakedepend) 626a253d6aeSmrg "$@" || exit $? 627a253d6aeSmrg # Remove any Libtool call 628a253d6aeSmrg if test "$libtool" = yes; then 62925b89263Smrg while test "X$1" != 'X--mode=compile'; do 630a253d6aeSmrg shift 631a253d6aeSmrg done 632a253d6aeSmrg shift 633a253d6aeSmrg fi 634a253d6aeSmrg # X makedepend 635a253d6aeSmrg shift 63625b89263Smrg cleared=no eat=no 63725b89263Smrg for arg 63825b89263Smrg do 639a253d6aeSmrg case $cleared in 640a253d6aeSmrg no) 641a253d6aeSmrg set ""; shift 642a253d6aeSmrg cleared=yes ;; 643a253d6aeSmrg esac 64425b89263Smrg if test $eat = yes; then 64525b89263Smrg eat=no 64625b89263Smrg continue 64725b89263Smrg fi 648a253d6aeSmrg case "$arg" in 649a253d6aeSmrg -D*|-I*) 650a253d6aeSmrg set fnord "$@" "$arg"; shift ;; 651a253d6aeSmrg # Strip any option that makedepend may not understand. Remove 652a253d6aeSmrg # the object too, otherwise makedepend will parse it as a source file. 65325b89263Smrg -arch) 65425b89263Smrg eat=yes ;; 655a253d6aeSmrg -*|$object) 656a253d6aeSmrg ;; 657a253d6aeSmrg *) 658a253d6aeSmrg set fnord "$@" "$arg"; shift ;; 659a253d6aeSmrg esac 660a253d6aeSmrg done 66125b89263Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 662a253d6aeSmrg touch "$tmpdepfile" 663a253d6aeSmrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 664a253d6aeSmrg rm -f "$depfile" 66557ee1794Smrg # makedepend may prepend the VPATH from the source file name to the object. 66657ee1794Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 66757ee1794Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66857ee1794Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66957ee1794Smrg # correctly. Breaking it into two sed invocations is a workaround. 67057ee1794Smrg sed '1,2d' "$tmpdepfile" \ 67157ee1794Smrg | tr ' ' "$nl" \ 67257ee1794Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67357ee1794Smrg | sed -e 's/$/ :/' >> "$depfile" 674a253d6aeSmrg rm -f "$tmpdepfile" "$tmpdepfile".bak 675a253d6aeSmrg ;; 676a253d6aeSmrg 677a253d6aeSmrgcpp) 678a253d6aeSmrg # Important note: in order to support this mode, a compiler *must* 679a253d6aeSmrg # always write the preprocessed file to stdout. 680a253d6aeSmrg "$@" || exit $? 681a253d6aeSmrg 682a253d6aeSmrg # Remove the call to Libtool. 683a253d6aeSmrg if test "$libtool" = yes; then 68425b89263Smrg while test "X$1" != 'X--mode=compile'; do 685a253d6aeSmrg shift 686a253d6aeSmrg done 687a253d6aeSmrg shift 688a253d6aeSmrg fi 689a253d6aeSmrg 69057ee1794Smrg # Remove '-o $object'. 691a253d6aeSmrg IFS=" " 692a253d6aeSmrg for arg 693a253d6aeSmrg do 694a253d6aeSmrg case $arg in 695a253d6aeSmrg -o) 696a253d6aeSmrg shift 697a253d6aeSmrg ;; 698a253d6aeSmrg $object) 699a253d6aeSmrg shift 700a253d6aeSmrg ;; 701a253d6aeSmrg *) 702a253d6aeSmrg set fnord "$@" "$arg" 703a253d6aeSmrg shift # fnord 704a253d6aeSmrg shift # $arg 705a253d6aeSmrg ;; 706a253d6aeSmrg esac 707a253d6aeSmrg done 708a253d6aeSmrg 70957ee1794Smrg "$@" -E \ 71057ee1794Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71157ee1794Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71257ee1794Smrg | sed '$ s: \\$::' > "$tmpdepfile" 713a253d6aeSmrg rm -f "$depfile" 714a253d6aeSmrg echo "$object : \\" > "$depfile" 715a253d6aeSmrg cat < "$tmpdepfile" >> "$depfile" 716a253d6aeSmrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 717a253d6aeSmrg rm -f "$tmpdepfile" 718a253d6aeSmrg ;; 719a253d6aeSmrg 720a253d6aeSmrgmsvisualcpp) 721a253d6aeSmrg # Important note: in order to support this mode, a compiler *must* 72225b89263Smrg # always write the preprocessed file to stdout. 723a253d6aeSmrg "$@" || exit $? 72425b89263Smrg 72525b89263Smrg # Remove the call to Libtool. 72625b89263Smrg if test "$libtool" = yes; then 72725b89263Smrg while test "X$1" != 'X--mode=compile'; do 72825b89263Smrg shift 72925b89263Smrg done 73025b89263Smrg shift 73125b89263Smrg fi 73225b89263Smrg 733a253d6aeSmrg IFS=" " 734a253d6aeSmrg for arg 735a253d6aeSmrg do 736a253d6aeSmrg case "$arg" in 73725b89263Smrg -o) 73825b89263Smrg shift 73925b89263Smrg ;; 74025b89263Smrg $object) 74125b89263Smrg shift 74225b89263Smrg ;; 743a253d6aeSmrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74457ee1794Smrg set fnord "$@" 74557ee1794Smrg shift 74657ee1794Smrg shift 74757ee1794Smrg ;; 748a253d6aeSmrg *) 74957ee1794Smrg set fnord "$@" "$arg" 75057ee1794Smrg shift 75157ee1794Smrg shift 75257ee1794Smrg ;; 753a253d6aeSmrg esac 754a253d6aeSmrg done 75525b89263Smrg "$@" -E 2>/dev/null | 75625b89263Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 757a253d6aeSmrg rm -f "$depfile" 758a253d6aeSmrg echo "$object : \\" > "$depfile" 75957ee1794Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 76057ee1794Smrg echo "$tab" >> "$depfile" 76125b89263Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 762a253d6aeSmrg rm -f "$tmpdepfile" 763a253d6aeSmrg ;; 764a253d6aeSmrg 76525b89263Smrgmsvcmsys) 76625b89263Smrg # This case exists only to let depend.m4 do its work. It works by 76725b89263Smrg # looking at the text of this script. This case will never be run, 76825b89263Smrg # since it is checked for above. 76925b89263Smrg exit 1 77025b89263Smrg ;; 77125b89263Smrg 772a253d6aeSmrgnone) 773a253d6aeSmrg exec "$@" 774a253d6aeSmrg ;; 775a253d6aeSmrg 776a253d6aeSmrg*) 777a253d6aeSmrg echo "Unknown depmode $depmode" 1>&2 778a253d6aeSmrg exit 1 779a253d6aeSmrg ;; 780a253d6aeSmrgesac 781a253d6aeSmrg 782a253d6aeSmrgexit 0 783a253d6aeSmrg 784a253d6aeSmrg# Local Variables: 785a253d6aeSmrg# mode: shell-script 786a253d6aeSmrg# sh-indentation: 2 787b41a30aaSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 788a253d6aeSmrg# time-stamp-start: "scriptversion=" 789a253d6aeSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 790b41a30aaSmrg# time-stamp-time-zone: "UTC0" 79125b89263Smrg# time-stamp-end: "; # UTC" 792a253d6aeSmrg# End: 793