1264fa531Smrg#! /bin/sh 2264fa531Smrg# depcomp - compile a program generating dependencies as side-effects 3c37a63b8Smrg 4dfac8f13Smrgscriptversion=2024-06-19.01; # UTC 5c37a63b8Smrg 6dfac8f13Smrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 7264fa531Smrg 8264fa531Smrg# This program is free software; you can redistribute it and/or modify 9264fa531Smrg# it under the terms of the GNU General Public License as published by 10264fa531Smrg# the Free Software Foundation; either version 2, or (at your option) 11264fa531Smrg# any later version. 12264fa531Smrg 13264fa531Smrg# This program is distributed in the hope that it will be useful, 14264fa531Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15264fa531Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16264fa531Smrg# GNU General Public License for more details. 17264fa531Smrg 18264fa531Smrg# You should have received a copy of the GNU General Public License 19c9e4df9bSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20264fa531Smrg 21264fa531Smrg# As a special exception to the GNU General Public License, if you 22264fa531Smrg# distribute this file as part of a program that contains a 23264fa531Smrg# configuration script generated by Autoconf, you may include it under 24264fa531Smrg# the same distribution terms that you use for the rest of that program. 25264fa531Smrg 26264fa531Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27264fa531Smrg 28c37a63b8Smrgcase $1 in 29c37a63b8Smrg '') 30533545b5Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31533545b5Smrg exit 1; 32533545b5Smrg ;; 33c37a63b8Smrg -h | --h*) 34c37a63b8Smrg cat <<\EOF 35c37a63b8SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36c37a63b8Smrg 37c37a63b8SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38c37a63b8Smrgas side-effects. 39c37a63b8Smrg 40c37a63b8SmrgEnvironment variables: 41c37a63b8Smrg depmode Dependency tracking mode. 42533545b5Smrg source Source file read by 'PROGRAMS ARGS'. 43533545b5Smrg object Object file output by 'PROGRAMS ARGS'. 44c37a63b8Smrg DEPDIR directory where to store dependencies. 45c37a63b8Smrg depfile Dependency file to output. 46533545b5Smrg tmpdepfile Temporary file to use when outputting dependencies. 47c37a63b8Smrg libtool Whether libtool is used (yes/no). 48c37a63b8Smrg 49c37a63b8SmrgReport bugs to <bug-automake@gnu.org>. 50dfac8f13SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 51dfac8f13SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 52c37a63b8SmrgEOF 53c37a63b8Smrg exit $? 54c37a63b8Smrg ;; 55c37a63b8Smrg -v | --v*) 56dfac8f13Smrg echo "depcomp (GNU Automake) $scriptversion" 57c37a63b8Smrg exit $? 58c37a63b8Smrg ;; 59c37a63b8Smrgesac 60c37a63b8Smrg 61533545b5Smrg# Get the directory component of the given path, and save it in the 62533545b5Smrg# global variables '$dir'. Note that this directory component will 63533545b5Smrg# be either empty or ending with a '/' character. This is deliberate. 64533545b5Smrgset_dir_from () 65533545b5Smrg{ 66533545b5Smrg case $1 in 67533545b5Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 68533545b5Smrg *) dir=;; 69533545b5Smrg esac 70533545b5Smrg} 71533545b5Smrg 72533545b5Smrg# Get the suffix-stripped basename of the given path, and save it the 73533545b5Smrg# global variable '$base'. 74533545b5Smrgset_base_from () 75533545b5Smrg{ 76533545b5Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 77533545b5Smrg} 78533545b5Smrg 79533545b5Smrg# If no dependency file was actually created by the compiler invocation, 80533545b5Smrg# we still have to create a dummy depfile, to avoid errors with the 81533545b5Smrg# Makefile "include basename.Plo" scheme. 82533545b5Smrgmake_dummy_depfile () 83533545b5Smrg{ 84533545b5Smrg echo "#dummy" > "$depfile" 85533545b5Smrg} 86533545b5Smrg 87533545b5Smrg# Factor out some common post-processing of the generated depfile. 88533545b5Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 89533545b5Smrgaix_post_process_depfile () 90533545b5Smrg{ 91533545b5Smrg # If the compiler actually managed to produce a dependency file, 92533545b5Smrg # post-process it. 93533545b5Smrg if test -f "$tmpdepfile"; then 94533545b5Smrg # Each line is of the form 'foo.o: dependency.h'. 95533545b5Smrg # Do two passes, one to just change these to 96533545b5Smrg # $object: dependency.h 97533545b5Smrg # and one to simply output 98533545b5Smrg # dependency.h: 99533545b5Smrg # which is needed to avoid the deleted-header problem. 100533545b5Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 101533545b5Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 102533545b5Smrg } > "$depfile" 103533545b5Smrg rm -f "$tmpdepfile" 104533545b5Smrg else 105533545b5Smrg make_dummy_depfile 106533545b5Smrg fi 107533545b5Smrg} 108533545b5Smrg 109533545b5Smrg# A tabulation character. 110533545b5Smrgtab=' ' 111533545b5Smrg# A newline character. 112533545b5Smrgnl=' 113533545b5Smrg' 114533545b5Smrg# Character ranges might be problematic outside the C locale. 115533545b5Smrg# These definitions help. 116533545b5Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 117533545b5Smrglower=abcdefghijklmnopqrstuvwxyz 118533545b5Smrgalpha=${upper}${lower} 119533545b5Smrg 120264fa531Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 121264fa531Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 122264fa531Smrg exit 1 123264fa531Smrgfi 124264fa531Smrg 125c37a63b8Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 126c37a63b8Smrgdepfile=${depfile-`echo "$object" | 127c37a63b8Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 128264fa531Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 129264fa531Smrg 130264fa531Smrgrm -f "$tmpdepfile" 131264fa531Smrg 132dfac8f13Smrg# Avoid interference from the environment. 133533545b5Smrggccflag= dashmflag= 134533545b5Smrg 135264fa531Smrg# Some modes work just like other modes, but use different flags. We 136264fa531Smrg# parameterize here, but still list the modes in the big case below, 137264fa531Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 138264fa531Smrg# here, because this file can only contain one case statement. 139264fa531Smrgif test "$depmode" = hp; then 140264fa531Smrg # HP compiler uses -M and no extra arg. 141264fa531Smrg gccflag=-M 142264fa531Smrg depmode=gcc 143264fa531Smrgfi 144264fa531Smrg 145264fa531Smrgif test "$depmode" = dashXmstdout; then 146533545b5Smrg # This is just like dashmstdout with a different argument. 147533545b5Smrg dashmflag=-xM 148533545b5Smrg depmode=dashmstdout 149264fa531Smrgfi 150264fa531Smrg 151c37a63b8Smrgcygpath_u="cygpath -u -f -" 152c37a63b8Smrgif test "$depmode" = msvcmsys; then 153533545b5Smrg # This is just like msvisualcpp but w/o cygpath translation. 154533545b5Smrg # Just convert the backslash-escaped backslashes to single forward 155533545b5Smrg # slashes to satisfy depend.m4 156533545b5Smrg cygpath_u='sed s,\\\\,/,g' 157533545b5Smrg depmode=msvisualcpp 158533545b5Smrgfi 159533545b5Smrg 160533545b5Smrgif test "$depmode" = msvc7msys; then 161533545b5Smrg # This is just like msvc7 but w/o cygpath translation. 162533545b5Smrg # Just convert the backslash-escaped backslashes to single forward 163533545b5Smrg # slashes to satisfy depend.m4 164533545b5Smrg cygpath_u='sed s,\\\\,/,g' 165533545b5Smrg depmode=msvc7 166533545b5Smrgfi 167533545b5Smrg 168533545b5Smrgif test "$depmode" = xlc; then 169533545b5Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 170533545b5Smrg gccflag=-qmakedep=gcc,-MF 171533545b5Smrg depmode=gcc 172c37a63b8Smrgfi 173c37a63b8Smrg 174264fa531Smrgcase "$depmode" in 175264fa531Smrggcc3) 176264fa531Smrg## gcc 3 implements dependency tracking that does exactly what 177264fa531Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 178264fa531Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 179c37a63b8Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 180c37a63b8Smrg## the command line argument order; so add the flags where they 181c37a63b8Smrg## appear in depend2.am. Note that the slowdown incurred here 182c37a63b8Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 183c37a63b8Smrg for arg 184c37a63b8Smrg do 185c37a63b8Smrg case $arg in 186c37a63b8Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 187c37a63b8Smrg *) set fnord "$@" "$arg" ;; 188c37a63b8Smrg esac 189c37a63b8Smrg shift # fnord 190c37a63b8Smrg shift # $arg 191c37a63b8Smrg done 192c37a63b8Smrg "$@" 193264fa531Smrg stat=$? 194533545b5Smrg if test $stat -ne 0; then 195264fa531Smrg rm -f "$tmpdepfile" 196264fa531Smrg exit $stat 197264fa531Smrg fi 198264fa531Smrg mv "$tmpdepfile" "$depfile" 199264fa531Smrg ;; 200264fa531Smrg 201264fa531Smrggcc) 202dfac8f13Smrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 203dfac8f13Smrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 204533545b5Smrg## (see the conditional assignment to $gccflag above). 205264fa531Smrg## There are various ways to get dependency output from gcc. Here's 206264fa531Smrg## why we pick this rather obscure method: 207264fa531Smrg## - Don't want to use -MD because we'd like the dependencies to end 208264fa531Smrg## up in a subdir. Having to rename by hand is ugly. 209264fa531Smrg## (We might end up doing this anyway to support other compilers.) 210264fa531Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 211533545b5Smrg## -MM, not -M (despite what the docs say). Also, it might not be 212533545b5Smrg## supported by the other compilers which use the 'gcc' depmode. 213264fa531Smrg## - Using -M directly means running the compiler twice (even worse 214264fa531Smrg## than renaming). 215264fa531Smrg if test -z "$gccflag"; then 216264fa531Smrg gccflag=-MD, 217264fa531Smrg fi 218264fa531Smrg "$@" -Wp,"$gccflag$tmpdepfile" 219264fa531Smrg stat=$? 220533545b5Smrg if test $stat -ne 0; then 221264fa531Smrg rm -f "$tmpdepfile" 222264fa531Smrg exit $stat 223264fa531Smrg fi 224264fa531Smrg rm -f "$depfile" 225264fa531Smrg echo "$object : \\" > "$depfile" 226533545b5Smrg # The second -e expression handles DOS-style file names with drive 227533545b5Smrg # letters. 228264fa531Smrg sed -e 's/^[^:]*: / /' \ 229264fa531Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 230533545b5Smrg## This next piece of magic avoids the "deleted header file" problem. 231264fa531Smrg## The problem is that when a header file which appears in a .P file 232264fa531Smrg## is deleted, the dependency causes make to die (because there is 233264fa531Smrg## typically no way to rebuild the header). We avoid this by adding 234264fa531Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 235264fa531Smrg## this for us directly. 236533545b5Smrg## Some versions of gcc put a space before the ':'. On the theory 237264fa531Smrg## that the space means something, we add a space to the output as 238533545b5Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 239533545b5Smrg## to the object. Take care to not repeat it in the output. 240264fa531Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 241264fa531Smrg## correctly. Breaking it into two sed invocations is a workaround. 242533545b5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 243533545b5Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 244533545b5Smrg | sed -e 's/$/ :/' >> "$depfile" 245264fa531Smrg rm -f "$tmpdepfile" 246264fa531Smrg ;; 247264fa531Smrg 248264fa531Smrghp) 249264fa531Smrg # This case exists only to let depend.m4 do its work. It works by 250264fa531Smrg # looking at the text of this script. This case will never be run, 251264fa531Smrg # since it is checked for above. 252264fa531Smrg exit 1 253264fa531Smrg ;; 254264fa531Smrg 255264fa531Smrgsgi) 256264fa531Smrg if test "$libtool" = yes; then 257264fa531Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 258264fa531Smrg else 259264fa531Smrg "$@" -MDupdate "$tmpdepfile" 260264fa531Smrg fi 261264fa531Smrg stat=$? 262533545b5Smrg if test $stat -ne 0; then 263264fa531Smrg rm -f "$tmpdepfile" 264264fa531Smrg exit $stat 265264fa531Smrg fi 266264fa531Smrg rm -f "$depfile" 267264fa531Smrg 268264fa531Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 269264fa531Smrg echo "$object : \\" > "$depfile" 270264fa531Smrg # Clip off the initial element (the dependent). Don't try to be 271264fa531Smrg # clever and replace this with sed code, as IRIX sed won't handle 272264fa531Smrg # lines with more than a fixed number of characters (4096 in 273264fa531Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 274533545b5Smrg # the IRIX cc adds comments like '#:fec' to the end of the 275264fa531Smrg # dependency line. 276533545b5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 277533545b5Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 278533545b5Smrg | tr "$nl" ' ' >> "$depfile" 279c37a63b8Smrg echo >> "$depfile" 280264fa531Smrg # The second pass generates a dummy entry for each header file. 281533545b5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 282533545b5Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 283533545b5Smrg >> "$depfile" 284264fa531Smrg else 285533545b5Smrg make_dummy_depfile 286264fa531Smrg fi 287264fa531Smrg rm -f "$tmpdepfile" 288264fa531Smrg ;; 289264fa531Smrg 290533545b5Smrgxlc) 291533545b5Smrg # This case exists only to let depend.m4 do its work. It works by 292533545b5Smrg # looking at the text of this script. This case will never be run, 293533545b5Smrg # since it is checked for above. 294533545b5Smrg exit 1 295533545b5Smrg ;; 296533545b5Smrg 297264fa531Smrgaix) 298264fa531Smrg # The C for AIX Compiler uses -M and outputs the dependencies 299264fa531Smrg # in a .u file. In older versions, this file always lives in the 300533545b5Smrg # current directory. Also, the AIX compiler puts '$object:' at the 301264fa531Smrg # start of each line; $object doesn't have directory information. 302264fa531Smrg # Version 6 uses the directory in both cases. 303533545b5Smrg set_dir_from "$object" 304533545b5Smrg set_base_from "$object" 305264fa531Smrg if test "$libtool" = yes; then 306c37a63b8Smrg tmpdepfile1=$dir$base.u 307c37a63b8Smrg tmpdepfile2=$base.u 308c37a63b8Smrg tmpdepfile3=$dir.libs/$base.u 309264fa531Smrg "$@" -Wc,-M 310264fa531Smrg else 311c37a63b8Smrg tmpdepfile1=$dir$base.u 312c37a63b8Smrg tmpdepfile2=$dir$base.u 313c37a63b8Smrg tmpdepfile3=$dir$base.u 314264fa531Smrg "$@" -M 315264fa531Smrg fi 316264fa531Smrg stat=$? 317533545b5Smrg if test $stat -ne 0; then 318c37a63b8Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 319264fa531Smrg exit $stat 320264fa531Smrg fi 321264fa531Smrg 322c37a63b8Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 323c37a63b8Smrg do 324c37a63b8Smrg test -f "$tmpdepfile" && break 325c37a63b8Smrg done 326533545b5Smrg aix_post_process_depfile 327533545b5Smrg ;; 328533545b5Smrg 329533545b5Smrgtcc) 330533545b5Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 331533545b5Smrg # FIXME: That version still under development at the moment of writing. 332533545b5Smrg # Make that this statement remains true also for stable, released 333533545b5Smrg # versions. 334533545b5Smrg # It will wrap lines (doesn't matter whether long or short) with a 335533545b5Smrg # trailing '\', as in: 336533545b5Smrg # 337533545b5Smrg # foo.o : \ 338533545b5Smrg # foo.c \ 339533545b5Smrg # foo.h \ 340533545b5Smrg # 341533545b5Smrg # It will put a trailing '\' even on the last line, and will use leading 342533545b5Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 343533545b5Smrg # "Emit spaces for -MD"). 344533545b5Smrg "$@" -MD -MF "$tmpdepfile" 345533545b5Smrg stat=$? 346533545b5Smrg if test $stat -ne 0; then 347533545b5Smrg rm -f "$tmpdepfile" 348533545b5Smrg exit $stat 349264fa531Smrg fi 350533545b5Smrg rm -f "$depfile" 351533545b5Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 352533545b5Smrg # We have to change lines of the first kind to '$object: \'. 353533545b5Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 354533545b5Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 355533545b5Smrg # dummy dependency, to avoid the deleted-header problem. 356533545b5Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 357264fa531Smrg rm -f "$tmpdepfile" 358264fa531Smrg ;; 359264fa531Smrg 360533545b5Smrg## The order of this option in the case statement is important, since the 361533545b5Smrg## shell code in configure will try each of these formats in the order 362533545b5Smrg## listed in this file. A plain '-MD' option would be understood by many 363533545b5Smrg## compilers, so we must ensure this comes after the gcc and icc options. 364533545b5Smrgpgcc) 365533545b5Smrg # Portland's C compiler understands '-MD'. 366533545b5Smrg # Will always output deps to 'file.d' where file is the root name of the 367533545b5Smrg # source file under compilation, even if file resides in a subdirectory. 368533545b5Smrg # The object file name does not affect the name of the '.d' file. 369533545b5Smrg # pgcc 10.2 will output 370264fa531Smrg # foo.o: sub/foo.c sub/foo.h 371533545b5Smrg # and will wrap long lines using '\' : 372264fa531Smrg # foo.o: sub/foo.c ... \ 373264fa531Smrg # sub/foo.h ... \ 374264fa531Smrg # ... 375533545b5Smrg set_dir_from "$object" 376533545b5Smrg # Use the source, not the object, to determine the base name, since 377533545b5Smrg # that's sadly what pgcc will do too. 378533545b5Smrg set_base_from "$source" 379533545b5Smrg tmpdepfile=$base.d 380533545b5Smrg 381533545b5Smrg # For projects that build the same source file twice into different object 382533545b5Smrg # files, the pgcc approach of using the *source* file root name can cause 383533545b5Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 384533545b5Smrg # the same $tmpdepfile. 385533545b5Smrg lockdir=$base.d-lock 386533545b5Smrg trap " 387533545b5Smrg echo '$0: caught signal, cleaning up...' >&2 388533545b5Smrg rmdir '$lockdir' 389533545b5Smrg exit 1 390533545b5Smrg " 1 2 13 15 391533545b5Smrg numtries=100 392533545b5Smrg i=$numtries 393533545b5Smrg while test $i -gt 0; do 394533545b5Smrg # mkdir is a portable test-and-set. 395533545b5Smrg if mkdir "$lockdir" 2>/dev/null; then 396533545b5Smrg # This process acquired the lock. 397533545b5Smrg "$@" -MD 398533545b5Smrg stat=$? 399533545b5Smrg # Release the lock. 400533545b5Smrg rmdir "$lockdir" 401533545b5Smrg break 402533545b5Smrg else 403533545b5Smrg # If the lock is being held by a different process, wait 404533545b5Smrg # until the winning process is done or we timeout. 405533545b5Smrg while test -d "$lockdir" && test $i -gt 0; do 406533545b5Smrg sleep 1 407533545b5Smrg i=`expr $i - 1` 408533545b5Smrg done 409533545b5Smrg fi 410533545b5Smrg i=`expr $i - 1` 411533545b5Smrg done 412533545b5Smrg trap - 1 2 13 15 413533545b5Smrg if test $i -le 0; then 414533545b5Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 415533545b5Smrg echo "$0: check lockdir '$lockdir'" >&2 416533545b5Smrg exit 1 417533545b5Smrg fi 418264fa531Smrg 419533545b5Smrg if test $stat -ne 0; then 420264fa531Smrg rm -f "$tmpdepfile" 421264fa531Smrg exit $stat 422264fa531Smrg fi 423264fa531Smrg rm -f "$depfile" 424264fa531Smrg # Each line is of the form `foo.o: dependent.h', 425264fa531Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 426264fa531Smrg # Do two passes, one to just change these to 427264fa531Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 428264fa531Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 429264fa531Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 430264fa531Smrg # correctly. Breaking it into two sed invocations is a workaround. 431533545b5Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 432533545b5Smrg | sed -e 's/$/ :/' >> "$depfile" 433264fa531Smrg rm -f "$tmpdepfile" 434264fa531Smrg ;; 435264fa531Smrg 436c37a63b8Smrghp2) 437c37a63b8Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 438c37a63b8Smrg # compilers, which have integrated preprocessors. The correct option 439c37a63b8Smrg # to use with these is +Maked; it writes dependencies to a file named 440c37a63b8Smrg # 'foo.d', which lands next to the object file, wherever that 441c37a63b8Smrg # happens to be. 442c37a63b8Smrg # Much of this is similar to the tru64 case; see comments there. 443533545b5Smrg set_dir_from "$object" 444533545b5Smrg set_base_from "$object" 445c37a63b8Smrg if test "$libtool" = yes; then 446c37a63b8Smrg tmpdepfile1=$dir$base.d 447c37a63b8Smrg tmpdepfile2=$dir.libs/$base.d 448c37a63b8Smrg "$@" -Wc,+Maked 449c37a63b8Smrg else 450c37a63b8Smrg tmpdepfile1=$dir$base.d 451c37a63b8Smrg tmpdepfile2=$dir$base.d 452c37a63b8Smrg "$@" +Maked 453c37a63b8Smrg fi 454c37a63b8Smrg stat=$? 455533545b5Smrg if test $stat -ne 0; then 456c37a63b8Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 457c37a63b8Smrg exit $stat 458c37a63b8Smrg fi 459c37a63b8Smrg 460c37a63b8Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 461c37a63b8Smrg do 462c37a63b8Smrg test -f "$tmpdepfile" && break 463c37a63b8Smrg done 464c37a63b8Smrg if test -f "$tmpdepfile"; then 465533545b5Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 466533545b5Smrg # Add 'dependent.h:' lines. 467c37a63b8Smrg sed -ne '2,${ 468533545b5Smrg s/^ *// 469533545b5Smrg s/ \\*$// 470533545b5Smrg s/$/:/ 471533545b5Smrg p 472533545b5Smrg }' "$tmpdepfile" >> "$depfile" 473c37a63b8Smrg else 474533545b5Smrg make_dummy_depfile 475c37a63b8Smrg fi 476c37a63b8Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 477c37a63b8Smrg ;; 478c37a63b8Smrg 479264fa531Smrgtru64) 480533545b5Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 481533545b5Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 482533545b5Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 483533545b5Smrg # dependencies in 'foo.d' instead, so we check for that too. 484533545b5Smrg # Subdirectories are respected. 485533545b5Smrg set_dir_from "$object" 486533545b5Smrg set_base_from "$object" 487533545b5Smrg 488533545b5Smrg if test "$libtool" = yes; then 489533545b5Smrg # Libtool generates 2 separate objects for the 2 libraries. These 490533545b5Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 491533545b5Smrg # in $dir$base.o.d. We have to check for both files, because 492533545b5Smrg # one of the two compilations can be disabled. We should prefer 493533545b5Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 494533545b5Smrg # automatically cleaned when .libs/ is deleted, while ignoring 495533545b5Smrg # the former would cause a distcleancheck panic. 496533545b5Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 497533545b5Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 498533545b5Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 499533545b5Smrg "$@" -Wc,-MD 500533545b5Smrg else 501533545b5Smrg tmpdepfile1=$dir$base.d 502533545b5Smrg tmpdepfile2=$dir$base.d 503533545b5Smrg tmpdepfile3=$dir$base.d 504533545b5Smrg "$@" -MD 505533545b5Smrg fi 506533545b5Smrg 507533545b5Smrg stat=$? 508533545b5Smrg if test $stat -ne 0; then 509533545b5Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 510533545b5Smrg exit $stat 511533545b5Smrg fi 512533545b5Smrg 513533545b5Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 514533545b5Smrg do 515533545b5Smrg test -f "$tmpdepfile" && break 516533545b5Smrg done 517533545b5Smrg # Same post-processing that is required for AIX mode. 518533545b5Smrg aix_post_process_depfile 519533545b5Smrg ;; 520533545b5Smrg 521533545b5Smrgmsvc7) 522533545b5Smrg if test "$libtool" = yes; then 523533545b5Smrg showIncludes=-Wc,-showIncludes 524533545b5Smrg else 525533545b5Smrg showIncludes=-showIncludes 526533545b5Smrg fi 527533545b5Smrg "$@" $showIncludes > "$tmpdepfile" 528533545b5Smrg stat=$? 529533545b5Smrg grep -v '^Note: including file: ' "$tmpdepfile" 530533545b5Smrg if test $stat -ne 0; then 531533545b5Smrg rm -f "$tmpdepfile" 532533545b5Smrg exit $stat 533533545b5Smrg fi 534533545b5Smrg rm -f "$depfile" 535533545b5Smrg echo "$object : \\" > "$depfile" 536533545b5Smrg # The first sed program below extracts the file names and escapes 537533545b5Smrg # backslashes for cygpath. The second sed program outputs the file 538533545b5Smrg # name when reading, but also accumulates all include files in the 539533545b5Smrg # hold buffer in order to output them again at the end. This only 540533545b5Smrg # works with sed implementations that can handle large buffers. 541533545b5Smrg sed < "$tmpdepfile" -n ' 542533545b5Smrg/^Note: including file: *\(.*\)/ { 543533545b5Smrg s//\1/ 544533545b5Smrg s/\\/\\\\/g 545533545b5Smrg p 546533545b5Smrg}' | $cygpath_u | sort -u | sed -n ' 547533545b5Smrgs/ /\\ /g 548533545b5Smrgs/\(.*\)/'"$tab"'\1 \\/p 549533545b5Smrgs/.\(.*\) \\/\1:/ 550533545b5SmrgH 551533545b5Smrg$ { 552533545b5Smrg s/.*/'"$tab"'/ 553533545b5Smrg G 554533545b5Smrg p 555533545b5Smrg}' >> "$depfile" 556533545b5Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 557533545b5Smrg rm -f "$tmpdepfile" 558533545b5Smrg ;; 559533545b5Smrg 560533545b5Smrgmsvc7msys) 561533545b5Smrg # This case exists only to let depend.m4 do its work. It works by 562533545b5Smrg # looking at the text of this script. This case will never be run, 563533545b5Smrg # since it is checked for above. 564533545b5Smrg exit 1 565533545b5Smrg ;; 566264fa531Smrg 567264fa531Smrg#nosideeffect) 568264fa531Smrg # This comment above is used by automake to tell side-effect 569264fa531Smrg # dependency tracking mechanisms from slower ones. 570264fa531Smrg 571264fa531Smrgdashmstdout) 572264fa531Smrg # Important note: in order to support this mode, a compiler *must* 573264fa531Smrg # always write the preprocessed file to stdout, regardless of -o. 574264fa531Smrg "$@" || exit $? 575264fa531Smrg 576264fa531Smrg # Remove the call to Libtool. 577264fa531Smrg if test "$libtool" = yes; then 578c37a63b8Smrg while test "X$1" != 'X--mode=compile'; do 579264fa531Smrg shift 580264fa531Smrg done 581264fa531Smrg shift 582264fa531Smrg fi 583264fa531Smrg 584533545b5Smrg # Remove '-o $object'. 585264fa531Smrg IFS=" " 586264fa531Smrg for arg 587264fa531Smrg do 588264fa531Smrg case $arg in 589264fa531Smrg -o) 590264fa531Smrg shift 591264fa531Smrg ;; 592264fa531Smrg $object) 593264fa531Smrg shift 594264fa531Smrg ;; 595264fa531Smrg *) 596264fa531Smrg set fnord "$@" "$arg" 597264fa531Smrg shift # fnord 598264fa531Smrg shift # $arg 599264fa531Smrg ;; 600264fa531Smrg esac 601264fa531Smrg done 602264fa531Smrg 603264fa531Smrg test -z "$dashmflag" && dashmflag=-M 604533545b5Smrg # Require at least two characters before searching for ':' 605264fa531Smrg # in the target name. This is to cope with DOS-style filenames: 606533545b5Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 607264fa531Smrg "$@" $dashmflag | 608533545b5Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 609264fa531Smrg rm -f "$depfile" 610264fa531Smrg cat < "$tmpdepfile" > "$depfile" 611533545b5Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 612533545b5Smrg # correctly. Breaking it into two sed invocations is a workaround. 613533545b5Smrg tr ' ' "$nl" < "$tmpdepfile" \ 614533545b5Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 615533545b5Smrg | sed -e 's/$/ :/' >> "$depfile" 616264fa531Smrg rm -f "$tmpdepfile" 617264fa531Smrg ;; 618264fa531Smrg 619264fa531SmrgdashXmstdout) 620264fa531Smrg # This case only exists to satisfy depend.m4. It is never actually 621264fa531Smrg # run, as this mode is specially recognized in the preamble. 622264fa531Smrg exit 1 623264fa531Smrg ;; 624264fa531Smrg 625264fa531Smrgmakedepend) 626264fa531Smrg "$@" || exit $? 627264fa531Smrg # Remove any Libtool call 628264fa531Smrg if test "$libtool" = yes; then 629c37a63b8Smrg while test "X$1" != 'X--mode=compile'; do 630264fa531Smrg shift 631264fa531Smrg done 632264fa531Smrg shift 633264fa531Smrg fi 634264fa531Smrg # X makedepend 635264fa531Smrg shift 636c37a63b8Smrg cleared=no eat=no 637c37a63b8Smrg for arg 638c37a63b8Smrg do 639264fa531Smrg case $cleared in 640264fa531Smrg no) 641264fa531Smrg set ""; shift 642264fa531Smrg cleared=yes ;; 643264fa531Smrg esac 644c37a63b8Smrg if test $eat = yes; then 645c37a63b8Smrg eat=no 646c37a63b8Smrg continue 647c37a63b8Smrg fi 648264fa531Smrg case "$arg" in 649264fa531Smrg -D*|-I*) 650264fa531Smrg set fnord "$@" "$arg"; shift ;; 651264fa531Smrg # Strip any option that makedepend may not understand. Remove 652264fa531Smrg # the object too, otherwise makedepend will parse it as a source file. 653c37a63b8Smrg -arch) 654c37a63b8Smrg eat=yes ;; 655264fa531Smrg -*|$object) 656264fa531Smrg ;; 657264fa531Smrg *) 658264fa531Smrg set fnord "$@" "$arg"; shift ;; 659264fa531Smrg esac 660264fa531Smrg done 661c37a63b8Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 662264fa531Smrg touch "$tmpdepfile" 663264fa531Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 664264fa531Smrg rm -f "$depfile" 665533545b5Smrg # makedepend may prepend the VPATH from the source file name to the object. 666533545b5Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 667533545b5Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 668533545b5Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 669533545b5Smrg # correctly. Breaking it into two sed invocations is a workaround. 670533545b5Smrg sed '1,2d' "$tmpdepfile" \ 671533545b5Smrg | tr ' ' "$nl" \ 672533545b5Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 673533545b5Smrg | sed -e 's/$/ :/' >> "$depfile" 674264fa531Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 675264fa531Smrg ;; 676264fa531Smrg 677264fa531Smrgcpp) 678264fa531Smrg # Important note: in order to support this mode, a compiler *must* 679264fa531Smrg # always write the preprocessed file to stdout. 680264fa531Smrg "$@" || exit $? 681264fa531Smrg 682264fa531Smrg # Remove the call to Libtool. 683264fa531Smrg if test "$libtool" = yes; then 684c37a63b8Smrg while test "X$1" != 'X--mode=compile'; do 685264fa531Smrg shift 686264fa531Smrg done 687264fa531Smrg shift 688264fa531Smrg fi 689264fa531Smrg 690533545b5Smrg # Remove '-o $object'. 691264fa531Smrg IFS=" " 692264fa531Smrg for arg 693264fa531Smrg do 694264fa531Smrg case $arg in 695264fa531Smrg -o) 696264fa531Smrg shift 697264fa531Smrg ;; 698264fa531Smrg $object) 699264fa531Smrg shift 700264fa531Smrg ;; 701264fa531Smrg *) 702264fa531Smrg set fnord "$@" "$arg" 703264fa531Smrg shift # fnord 704264fa531Smrg shift # $arg 705264fa531Smrg ;; 706264fa531Smrg esac 707264fa531Smrg done 708264fa531Smrg 709533545b5Smrg "$@" -E \ 710533545b5Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711533545b5Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 712533545b5Smrg | sed '$ s: \\$::' > "$tmpdepfile" 713264fa531Smrg rm -f "$depfile" 714264fa531Smrg echo "$object : \\" > "$depfile" 715264fa531Smrg cat < "$tmpdepfile" >> "$depfile" 716264fa531Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 717264fa531Smrg rm -f "$tmpdepfile" 718264fa531Smrg ;; 719264fa531Smrg 720264fa531Smrgmsvisualcpp) 721264fa531Smrg # Important note: in order to support this mode, a compiler *must* 722c37a63b8Smrg # always write the preprocessed file to stdout. 723264fa531Smrg "$@" || exit $? 724c37a63b8Smrg 725c37a63b8Smrg # Remove the call to Libtool. 726c37a63b8Smrg if test "$libtool" = yes; then 727c37a63b8Smrg while test "X$1" != 'X--mode=compile'; do 728c37a63b8Smrg shift 729c37a63b8Smrg done 730c37a63b8Smrg shift 731c37a63b8Smrg fi 732c37a63b8Smrg 733264fa531Smrg IFS=" " 734264fa531Smrg for arg 735264fa531Smrg do 736264fa531Smrg case "$arg" in 737c37a63b8Smrg -o) 738c37a63b8Smrg shift 739c37a63b8Smrg ;; 740c37a63b8Smrg $object) 741c37a63b8Smrg shift 742c37a63b8Smrg ;; 743264fa531Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 744533545b5Smrg set fnord "$@" 745533545b5Smrg shift 746533545b5Smrg shift 747533545b5Smrg ;; 748264fa531Smrg *) 749533545b5Smrg set fnord "$@" "$arg" 750533545b5Smrg shift 751533545b5Smrg shift 752533545b5Smrg ;; 753264fa531Smrg esac 754264fa531Smrg done 755c37a63b8Smrg "$@" -E 2>/dev/null | 756c37a63b8Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 757264fa531Smrg rm -f "$depfile" 758264fa531Smrg echo "$object : \\" > "$depfile" 759533545b5Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 760533545b5Smrg echo "$tab" >> "$depfile" 761c37a63b8Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 762264fa531Smrg rm -f "$tmpdepfile" 763264fa531Smrg ;; 764264fa531Smrg 765c37a63b8Smrgmsvcmsys) 766c37a63b8Smrg # This case exists only to let depend.m4 do its work. It works by 767c37a63b8Smrg # looking at the text of this script. This case will never be run, 768c37a63b8Smrg # since it is checked for above. 769c37a63b8Smrg exit 1 770c37a63b8Smrg ;; 771c37a63b8Smrg 772264fa531Smrgnone) 773264fa531Smrg exec "$@" 774264fa531Smrg ;; 775264fa531Smrg 776264fa531Smrg*) 777264fa531Smrg echo "Unknown depmode $depmode" 1>&2 778264fa531Smrg exit 1 779264fa531Smrg ;; 780264fa531Smrgesac 781264fa531Smrg 782264fa531Smrgexit 0 783c37a63b8Smrg 784c37a63b8Smrg# Local Variables: 785c37a63b8Smrg# mode: shell-script 786c37a63b8Smrg# sh-indentation: 2 787c9e4df9bSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 788c37a63b8Smrg# time-stamp-start: "scriptversion=" 789c37a63b8Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 790c9e4df9bSmrg# time-stamp-time-zone: "UTC0" 791c37a63b8Smrg# time-stamp-end: "; # UTC" 792c37a63b8Smrg# End: 793