1bd1da9d7Smrg#! /bin/sh 2bd1da9d7Smrg# depcomp - compile a program generating dependencies as side-effects 3bd1da9d7Smrg 46ad5a0e2Smrgscriptversion=2018-03-07.03; # UTC 5bd1da9d7Smrg 6a392d4f3Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7bd1da9d7Smrg 8bd1da9d7Smrg# This program is free software; you can redistribute it and/or modify 9bd1da9d7Smrg# it under the terms of the GNU General Public License as published by 10bd1da9d7Smrg# the Free Software Foundation; either version 2, or (at your option) 11bd1da9d7Smrg# any later version. 12bd1da9d7Smrg 13bd1da9d7Smrg# This program is distributed in the hope that it will be useful, 14bd1da9d7Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15bd1da9d7Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16bd1da9d7Smrg# GNU General Public License for more details. 17bd1da9d7Smrg 18bd1da9d7Smrg# You should have received a copy of the GNU General Public License 196ad5a0e2Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20bd1da9d7Smrg 21bd1da9d7Smrg# As a special exception to the GNU General Public License, if you 22bd1da9d7Smrg# distribute this file as part of a program that contains a 23bd1da9d7Smrg# configuration script generated by Autoconf, you may include it under 24bd1da9d7Smrg# the same distribution terms that you use for the rest of that program. 25bd1da9d7Smrg 26bd1da9d7Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27bd1da9d7Smrg 28bd1da9d7Smrgcase $1 in 29bd1da9d7Smrg '') 30899129b3Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31899129b3Smrg exit 1; 32899129b3Smrg ;; 33bd1da9d7Smrg -h | --h*) 34bd1da9d7Smrg cat <<\EOF 35bd1da9d7SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36bd1da9d7Smrg 37bd1da9d7SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38bd1da9d7Smrgas side-effects. 39bd1da9d7Smrg 40bd1da9d7SmrgEnvironment variables: 41bd1da9d7Smrg depmode Dependency tracking mode. 42899129b3Smrg source Source file read by 'PROGRAMS ARGS'. 43899129b3Smrg object Object file output by 'PROGRAMS ARGS'. 44bd1da9d7Smrg DEPDIR directory where to store dependencies. 45bd1da9d7Smrg depfile Dependency file to output. 46899129b3Smrg tmpdepfile Temporary file to use when outputting dependencies. 47bd1da9d7Smrg libtool Whether libtool is used (yes/no). 48bd1da9d7Smrg 49bd1da9d7SmrgReport bugs to <bug-automake@gnu.org>. 50bd1da9d7SmrgEOF 51bd1da9d7Smrg exit $? 52bd1da9d7Smrg ;; 53bd1da9d7Smrg -v | --v*) 54bd1da9d7Smrg echo "depcomp $scriptversion" 55bd1da9d7Smrg exit $? 56bd1da9d7Smrg ;; 57bd1da9d7Smrgesac 58bd1da9d7Smrg 59899129b3Smrg# Get the directory component of the given path, and save it in the 60899129b3Smrg# global variables '$dir'. Note that this directory component will 61899129b3Smrg# be either empty or ending with a '/' character. This is deliberate. 62899129b3Smrgset_dir_from () 63899129b3Smrg{ 64899129b3Smrg case $1 in 65899129b3Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66899129b3Smrg *) dir=;; 67899129b3Smrg esac 68899129b3Smrg} 69899129b3Smrg 70899129b3Smrg# Get the suffix-stripped basename of the given path, and save it the 71899129b3Smrg# global variable '$base'. 72899129b3Smrgset_base_from () 73899129b3Smrg{ 74899129b3Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75899129b3Smrg} 76899129b3Smrg 77899129b3Smrg# If no dependency file was actually created by the compiler invocation, 78899129b3Smrg# we still have to create a dummy depfile, to avoid errors with the 79899129b3Smrg# Makefile "include basename.Plo" scheme. 80899129b3Smrgmake_dummy_depfile () 81899129b3Smrg{ 82899129b3Smrg echo "#dummy" > "$depfile" 83899129b3Smrg} 84899129b3Smrg 85899129b3Smrg# Factor out some common post-processing of the generated depfile. 86899129b3Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87899129b3Smrgaix_post_process_depfile () 88899129b3Smrg{ 89899129b3Smrg # If the compiler actually managed to produce a dependency file, 90899129b3Smrg # post-process it. 91899129b3Smrg if test -f "$tmpdepfile"; then 92899129b3Smrg # Each line is of the form 'foo.o: dependency.h'. 93899129b3Smrg # Do two passes, one to just change these to 94899129b3Smrg # $object: dependency.h 95899129b3Smrg # and one to simply output 96899129b3Smrg # dependency.h: 97899129b3Smrg # which is needed to avoid the deleted-header problem. 98899129b3Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99899129b3Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100899129b3Smrg } > "$depfile" 101899129b3Smrg rm -f "$tmpdepfile" 102899129b3Smrg else 103899129b3Smrg make_dummy_depfile 104899129b3Smrg fi 105899129b3Smrg} 106899129b3Smrg 107899129b3Smrg# A tabulation character. 108899129b3Smrgtab=' ' 109899129b3Smrg# A newline character. 110899129b3Smrgnl=' 111899129b3Smrg' 112899129b3Smrg# Character ranges might be problematic outside the C locale. 113899129b3Smrg# These definitions help. 114899129b3Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115899129b3Smrglower=abcdefghijklmnopqrstuvwxyz 116899129b3Smrgdigits=0123456789 117899129b3Smrgalpha=${upper}${lower} 118899129b3Smrg 119bd1da9d7Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120bd1da9d7Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121bd1da9d7Smrg exit 1 122bd1da9d7Smrgfi 123bd1da9d7Smrg 124bd1da9d7Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125bd1da9d7Smrgdepfile=${depfile-`echo "$object" | 126bd1da9d7Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127bd1da9d7Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128bd1da9d7Smrg 129bd1da9d7Smrgrm -f "$tmpdepfile" 130bd1da9d7Smrg 131899129b3Smrg# Avoid interferences from the environment. 132899129b3Smrggccflag= dashmflag= 133899129b3Smrg 134bd1da9d7Smrg# Some modes work just like other modes, but use different flags. We 135bd1da9d7Smrg# parameterize here, but still list the modes in the big case below, 136bd1da9d7Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137bd1da9d7Smrg# here, because this file can only contain one case statement. 138bd1da9d7Smrgif test "$depmode" = hp; then 139bd1da9d7Smrg # HP compiler uses -M and no extra arg. 140bd1da9d7Smrg gccflag=-M 141bd1da9d7Smrg depmode=gcc 142bd1da9d7Smrgfi 143bd1da9d7Smrg 144bd1da9d7Smrgif test "$depmode" = dashXmstdout; then 145899129b3Smrg # This is just like dashmstdout with a different argument. 146899129b3Smrg dashmflag=-xM 147899129b3Smrg depmode=dashmstdout 148bd1da9d7Smrgfi 149bd1da9d7Smrg 1505bcb6992Smrgcygpath_u="cygpath -u -f -" 1515bcb6992Smrgif test "$depmode" = msvcmsys; then 152899129b3Smrg # This is just like msvisualcpp but w/o cygpath translation. 153899129b3Smrg # Just convert the backslash-escaped backslashes to single forward 154899129b3Smrg # slashes to satisfy depend.m4 155899129b3Smrg cygpath_u='sed s,\\\\,/,g' 156899129b3Smrg depmode=msvisualcpp 157899129b3Smrgfi 158899129b3Smrg 159899129b3Smrgif test "$depmode" = msvc7msys; then 160899129b3Smrg # This is just like msvc7 but w/o cygpath translation. 161899129b3Smrg # Just convert the backslash-escaped backslashes to single forward 162899129b3Smrg # slashes to satisfy depend.m4 163899129b3Smrg cygpath_u='sed s,\\\\,/,g' 164899129b3Smrg depmode=msvc7 165899129b3Smrgfi 166899129b3Smrg 167899129b3Smrgif test "$depmode" = xlc; then 168899129b3Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169899129b3Smrg gccflag=-qmakedep=gcc,-MF 170899129b3Smrg depmode=gcc 1715bcb6992Smrgfi 1725bcb6992Smrg 173bd1da9d7Smrgcase "$depmode" in 174bd1da9d7Smrggcc3) 175bd1da9d7Smrg## gcc 3 implements dependency tracking that does exactly what 176bd1da9d7Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177bd1da9d7Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1785bcb6992Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1795bcb6992Smrg## the command line argument order; so add the flags where they 1805bcb6992Smrg## appear in depend2.am. Note that the slowdown incurred here 1815bcb6992Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1825bcb6992Smrg for arg 1835bcb6992Smrg do 1845bcb6992Smrg case $arg in 1855bcb6992Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1865bcb6992Smrg *) set fnord "$@" "$arg" ;; 1875bcb6992Smrg esac 1885bcb6992Smrg shift # fnord 1895bcb6992Smrg shift # $arg 1905bcb6992Smrg done 1915bcb6992Smrg "$@" 192bd1da9d7Smrg stat=$? 193899129b3Smrg if test $stat -ne 0; then 194bd1da9d7Smrg rm -f "$tmpdepfile" 195bd1da9d7Smrg exit $stat 196bd1da9d7Smrg fi 197bd1da9d7Smrg mv "$tmpdepfile" "$depfile" 198bd1da9d7Smrg ;; 199bd1da9d7Smrg 200bd1da9d7Smrggcc) 201899129b3Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202899129b3Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203899129b3Smrg## (see the conditional assignment to $gccflag above). 204bd1da9d7Smrg## There are various ways to get dependency output from gcc. Here's 205bd1da9d7Smrg## why we pick this rather obscure method: 206bd1da9d7Smrg## - Don't want to use -MD because we'd like the dependencies to end 207bd1da9d7Smrg## up in a subdir. Having to rename by hand is ugly. 208bd1da9d7Smrg## (We might end up doing this anyway to support other compilers.) 209bd1da9d7Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210899129b3Smrg## -MM, not -M (despite what the docs say). Also, it might not be 211899129b3Smrg## supported by the other compilers which use the 'gcc' depmode. 212bd1da9d7Smrg## - Using -M directly means running the compiler twice (even worse 213bd1da9d7Smrg## than renaming). 214bd1da9d7Smrg if test -z "$gccflag"; then 215bd1da9d7Smrg gccflag=-MD, 216bd1da9d7Smrg fi 217bd1da9d7Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218bd1da9d7Smrg stat=$? 219899129b3Smrg if test $stat -ne 0; then 220bd1da9d7Smrg rm -f "$tmpdepfile" 221bd1da9d7Smrg exit $stat 222bd1da9d7Smrg fi 223bd1da9d7Smrg rm -f "$depfile" 224bd1da9d7Smrg echo "$object : \\" > "$depfile" 225899129b3Smrg # The second -e expression handles DOS-style file names with drive 226899129b3Smrg # letters. 227bd1da9d7Smrg sed -e 's/^[^:]*: / /' \ 228bd1da9d7Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229899129b3Smrg## This next piece of magic avoids the "deleted header file" problem. 230bd1da9d7Smrg## The problem is that when a header file which appears in a .P file 231bd1da9d7Smrg## is deleted, the dependency causes make to die (because there is 232bd1da9d7Smrg## typically no way to rebuild the header). We avoid this by adding 233bd1da9d7Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234bd1da9d7Smrg## this for us directly. 235899129b3Smrg## Some versions of gcc put a space before the ':'. On the theory 236bd1da9d7Smrg## that the space means something, we add a space to the output as 237899129b3Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238899129b3Smrg## to the object. Take care to not repeat it in the output. 239bd1da9d7Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240bd1da9d7Smrg## correctly. Breaking it into two sed invocations is a workaround. 241899129b3Smrg tr ' ' "$nl" < "$tmpdepfile" \ 242899129b3Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243899129b3Smrg | sed -e 's/$/ :/' >> "$depfile" 244bd1da9d7Smrg rm -f "$tmpdepfile" 245bd1da9d7Smrg ;; 246bd1da9d7Smrg 247bd1da9d7Smrghp) 248bd1da9d7Smrg # This case exists only to let depend.m4 do its work. It works by 249bd1da9d7Smrg # looking at the text of this script. This case will never be run, 250bd1da9d7Smrg # since it is checked for above. 251bd1da9d7Smrg exit 1 252bd1da9d7Smrg ;; 253bd1da9d7Smrg 254bd1da9d7Smrgsgi) 255bd1da9d7Smrg if test "$libtool" = yes; then 256bd1da9d7Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257bd1da9d7Smrg else 258bd1da9d7Smrg "$@" -MDupdate "$tmpdepfile" 259bd1da9d7Smrg fi 260bd1da9d7Smrg stat=$? 261899129b3Smrg if test $stat -ne 0; then 262bd1da9d7Smrg rm -f "$tmpdepfile" 263bd1da9d7Smrg exit $stat 264bd1da9d7Smrg fi 265bd1da9d7Smrg rm -f "$depfile" 266bd1da9d7Smrg 267bd1da9d7Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268bd1da9d7Smrg echo "$object : \\" > "$depfile" 269bd1da9d7Smrg # Clip off the initial element (the dependent). Don't try to be 270bd1da9d7Smrg # clever and replace this with sed code, as IRIX sed won't handle 271bd1da9d7Smrg # lines with more than a fixed number of characters (4096 in 272bd1da9d7Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273899129b3Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274bd1da9d7Smrg # dependency line. 275899129b3Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276899129b3Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277899129b3Smrg | tr "$nl" ' ' >> "$depfile" 2785bcb6992Smrg echo >> "$depfile" 279bd1da9d7Smrg # The second pass generates a dummy entry for each header file. 280899129b3Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281899129b3Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282899129b3Smrg >> "$depfile" 283bd1da9d7Smrg else 284899129b3Smrg make_dummy_depfile 285bd1da9d7Smrg fi 286bd1da9d7Smrg rm -f "$tmpdepfile" 287bd1da9d7Smrg ;; 288bd1da9d7Smrg 289899129b3Smrgxlc) 290899129b3Smrg # This case exists only to let depend.m4 do its work. It works by 291899129b3Smrg # looking at the text of this script. This case will never be run, 292899129b3Smrg # since it is checked for above. 293899129b3Smrg exit 1 294899129b3Smrg ;; 295899129b3Smrg 296bd1da9d7Smrgaix) 297bd1da9d7Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298bd1da9d7Smrg # in a .u file. In older versions, this file always lives in the 299899129b3Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300bd1da9d7Smrg # start of each line; $object doesn't have directory information. 301bd1da9d7Smrg # Version 6 uses the directory in both cases. 302899129b3Smrg set_dir_from "$object" 303899129b3Smrg set_base_from "$object" 304bd1da9d7Smrg if test "$libtool" = yes; then 3055bcb6992Smrg tmpdepfile1=$dir$base.u 3065bcb6992Smrg tmpdepfile2=$base.u 3075bcb6992Smrg tmpdepfile3=$dir.libs/$base.u 308bd1da9d7Smrg "$@" -Wc,-M 309bd1da9d7Smrg else 3105bcb6992Smrg tmpdepfile1=$dir$base.u 3115bcb6992Smrg tmpdepfile2=$dir$base.u 3125bcb6992Smrg tmpdepfile3=$dir$base.u 313bd1da9d7Smrg "$@" -M 314bd1da9d7Smrg fi 315bd1da9d7Smrg stat=$? 316899129b3Smrg if test $stat -ne 0; then 3175bcb6992Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318bd1da9d7Smrg exit $stat 319bd1da9d7Smrg fi 320bd1da9d7Smrg 3215bcb6992Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3225bcb6992Smrg do 3235bcb6992Smrg test -f "$tmpdepfile" && break 3245bcb6992Smrg done 325899129b3Smrg aix_post_process_depfile 326899129b3Smrg ;; 327899129b3Smrg 328899129b3Smrgtcc) 329899129b3Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330899129b3Smrg # FIXME: That version still under development at the moment of writing. 331899129b3Smrg # Make that this statement remains true also for stable, released 332899129b3Smrg # versions. 333899129b3Smrg # It will wrap lines (doesn't matter whether long or short) with a 334899129b3Smrg # trailing '\', as in: 335899129b3Smrg # 336899129b3Smrg # foo.o : \ 337899129b3Smrg # foo.c \ 338899129b3Smrg # foo.h \ 339899129b3Smrg # 340899129b3Smrg # It will put a trailing '\' even on the last line, and will use leading 341899129b3Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 342899129b3Smrg # "Emit spaces for -MD"). 343899129b3Smrg "$@" -MD -MF "$tmpdepfile" 344899129b3Smrg stat=$? 345899129b3Smrg if test $stat -ne 0; then 346899129b3Smrg rm -f "$tmpdepfile" 347899129b3Smrg exit $stat 348bd1da9d7Smrg fi 349899129b3Smrg rm -f "$depfile" 350899129b3Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351899129b3Smrg # We have to change lines of the first kind to '$object: \'. 352899129b3Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353899129b3Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 354899129b3Smrg # dummy dependency, to avoid the deleted-header problem. 355899129b3Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356bd1da9d7Smrg rm -f "$tmpdepfile" 357bd1da9d7Smrg ;; 358bd1da9d7Smrg 359899129b3Smrg## The order of this option in the case statement is important, since the 360899129b3Smrg## shell code in configure will try each of these formats in the order 361899129b3Smrg## listed in this file. A plain '-MD' option would be understood by many 362899129b3Smrg## compilers, so we must ensure this comes after the gcc and icc options. 363899129b3Smrgpgcc) 364899129b3Smrg # Portland's C compiler understands '-MD'. 365899129b3Smrg # Will always output deps to 'file.d' where file is the root name of the 366899129b3Smrg # source file under compilation, even if file resides in a subdirectory. 367899129b3Smrg # The object file name does not affect the name of the '.d' file. 368899129b3Smrg # pgcc 10.2 will output 369bd1da9d7Smrg # foo.o: sub/foo.c sub/foo.h 370899129b3Smrg # and will wrap long lines using '\' : 371bd1da9d7Smrg # foo.o: sub/foo.c ... \ 372bd1da9d7Smrg # sub/foo.h ... \ 373bd1da9d7Smrg # ... 374899129b3Smrg set_dir_from "$object" 375899129b3Smrg # Use the source, not the object, to determine the base name, since 376899129b3Smrg # that's sadly what pgcc will do too. 377899129b3Smrg set_base_from "$source" 378899129b3Smrg tmpdepfile=$base.d 379899129b3Smrg 380899129b3Smrg # For projects that build the same source file twice into different object 381899129b3Smrg # files, the pgcc approach of using the *source* file root name can cause 382899129b3Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383899129b3Smrg # the same $tmpdepfile. 384899129b3Smrg lockdir=$base.d-lock 385899129b3Smrg trap " 386899129b3Smrg echo '$0: caught signal, cleaning up...' >&2 387899129b3Smrg rmdir '$lockdir' 388899129b3Smrg exit 1 389899129b3Smrg " 1 2 13 15 390899129b3Smrg numtries=100 391899129b3Smrg i=$numtries 392899129b3Smrg while test $i -gt 0; do 393899129b3Smrg # mkdir is a portable test-and-set. 394899129b3Smrg if mkdir "$lockdir" 2>/dev/null; then 395899129b3Smrg # This process acquired the lock. 396899129b3Smrg "$@" -MD 397899129b3Smrg stat=$? 398899129b3Smrg # Release the lock. 399899129b3Smrg rmdir "$lockdir" 400899129b3Smrg break 401899129b3Smrg else 402899129b3Smrg # If the lock is being held by a different process, wait 403899129b3Smrg # until the winning process is done or we timeout. 404899129b3Smrg while test -d "$lockdir" && test $i -gt 0; do 405899129b3Smrg sleep 1 406899129b3Smrg i=`expr $i - 1` 407899129b3Smrg done 408899129b3Smrg fi 409899129b3Smrg i=`expr $i - 1` 410899129b3Smrg done 411899129b3Smrg trap - 1 2 13 15 412899129b3Smrg if test $i -le 0; then 413899129b3Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414899129b3Smrg echo "$0: check lockdir '$lockdir'" >&2 415899129b3Smrg exit 1 416899129b3Smrg fi 417bd1da9d7Smrg 418899129b3Smrg if test $stat -ne 0; then 419bd1da9d7Smrg rm -f "$tmpdepfile" 420bd1da9d7Smrg exit $stat 421bd1da9d7Smrg fi 422bd1da9d7Smrg rm -f "$depfile" 423bd1da9d7Smrg # Each line is of the form `foo.o: dependent.h', 424bd1da9d7Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425bd1da9d7Smrg # Do two passes, one to just change these to 426bd1da9d7Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427bd1da9d7Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428bd1da9d7Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429bd1da9d7Smrg # correctly. Breaking it into two sed invocations is a workaround. 430899129b3Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431899129b3Smrg | sed -e 's/$/ :/' >> "$depfile" 432bd1da9d7Smrg rm -f "$tmpdepfile" 433bd1da9d7Smrg ;; 434bd1da9d7Smrg 4355bcb6992Smrghp2) 4365bcb6992Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4375bcb6992Smrg # compilers, which have integrated preprocessors. The correct option 4385bcb6992Smrg # to use with these is +Maked; it writes dependencies to a file named 4395bcb6992Smrg # 'foo.d', which lands next to the object file, wherever that 4405bcb6992Smrg # happens to be. 4415bcb6992Smrg # Much of this is similar to the tru64 case; see comments there. 442899129b3Smrg set_dir_from "$object" 443899129b3Smrg set_base_from "$object" 4445bcb6992Smrg if test "$libtool" = yes; then 4455bcb6992Smrg tmpdepfile1=$dir$base.d 4465bcb6992Smrg tmpdepfile2=$dir.libs/$base.d 4475bcb6992Smrg "$@" -Wc,+Maked 4485bcb6992Smrg else 4495bcb6992Smrg tmpdepfile1=$dir$base.d 4505bcb6992Smrg tmpdepfile2=$dir$base.d 4515bcb6992Smrg "$@" +Maked 4525bcb6992Smrg fi 4535bcb6992Smrg stat=$? 454899129b3Smrg if test $stat -ne 0; then 4555bcb6992Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4565bcb6992Smrg exit $stat 4575bcb6992Smrg fi 4585bcb6992Smrg 4595bcb6992Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4605bcb6992Smrg do 4615bcb6992Smrg test -f "$tmpdepfile" && break 4625bcb6992Smrg done 4635bcb6992Smrg if test -f "$tmpdepfile"; then 464899129b3Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465899129b3Smrg # Add 'dependent.h:' lines. 4665bcb6992Smrg sed -ne '2,${ 467899129b3Smrg s/^ *// 468899129b3Smrg s/ \\*$// 469899129b3Smrg s/$/:/ 470899129b3Smrg p 471899129b3Smrg }' "$tmpdepfile" >> "$depfile" 4725bcb6992Smrg else 473899129b3Smrg make_dummy_depfile 4745bcb6992Smrg fi 4755bcb6992Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4765bcb6992Smrg ;; 4775bcb6992Smrg 478bd1da9d7Smrgtru64) 479899129b3Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 480899129b3Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481899129b3Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482899129b3Smrg # dependencies in 'foo.d' instead, so we check for that too. 483899129b3Smrg # Subdirectories are respected. 484899129b3Smrg set_dir_from "$object" 485899129b3Smrg set_base_from "$object" 486899129b3Smrg 487899129b3Smrg if test "$libtool" = yes; then 488899129b3Smrg # Libtool generates 2 separate objects for the 2 libraries. These 489899129b3Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 490899129b3Smrg # in $dir$base.o.d. We have to check for both files, because 491899129b3Smrg # one of the two compilations can be disabled. We should prefer 492899129b3Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493899129b3Smrg # automatically cleaned when .libs/ is deleted, while ignoring 494899129b3Smrg # the former would cause a distcleancheck panic. 495899129b3Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496899129b3Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497899129b3Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498899129b3Smrg "$@" -Wc,-MD 499899129b3Smrg else 500899129b3Smrg tmpdepfile1=$dir$base.d 501899129b3Smrg tmpdepfile2=$dir$base.d 502899129b3Smrg tmpdepfile3=$dir$base.d 503899129b3Smrg "$@" -MD 504899129b3Smrg fi 505899129b3Smrg 506899129b3Smrg stat=$? 507899129b3Smrg if test $stat -ne 0; then 508899129b3Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509899129b3Smrg exit $stat 510899129b3Smrg fi 511899129b3Smrg 512899129b3Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513899129b3Smrg do 514899129b3Smrg test -f "$tmpdepfile" && break 515899129b3Smrg done 516899129b3Smrg # Same post-processing that is required for AIX mode. 517899129b3Smrg aix_post_process_depfile 518899129b3Smrg ;; 519899129b3Smrg 520899129b3Smrgmsvc7) 521899129b3Smrg if test "$libtool" = yes; then 522899129b3Smrg showIncludes=-Wc,-showIncludes 523899129b3Smrg else 524899129b3Smrg showIncludes=-showIncludes 525899129b3Smrg fi 526899129b3Smrg "$@" $showIncludes > "$tmpdepfile" 527899129b3Smrg stat=$? 528899129b3Smrg grep -v '^Note: including file: ' "$tmpdepfile" 529899129b3Smrg if test $stat -ne 0; then 530899129b3Smrg rm -f "$tmpdepfile" 531899129b3Smrg exit $stat 532899129b3Smrg fi 533899129b3Smrg rm -f "$depfile" 534899129b3Smrg echo "$object : \\" > "$depfile" 535899129b3Smrg # The first sed program below extracts the file names and escapes 536899129b3Smrg # backslashes for cygpath. The second sed program outputs the file 537899129b3Smrg # name when reading, but also accumulates all include files in the 538899129b3Smrg # hold buffer in order to output them again at the end. This only 539899129b3Smrg # works with sed implementations that can handle large buffers. 540899129b3Smrg sed < "$tmpdepfile" -n ' 541899129b3Smrg/^Note: including file: *\(.*\)/ { 542899129b3Smrg s//\1/ 543899129b3Smrg s/\\/\\\\/g 544899129b3Smrg p 545899129b3Smrg}' | $cygpath_u | sort -u | sed -n ' 546899129b3Smrgs/ /\\ /g 547899129b3Smrgs/\(.*\)/'"$tab"'\1 \\/p 548899129b3Smrgs/.\(.*\) \\/\1:/ 549899129b3SmrgH 550899129b3Smrg$ { 551899129b3Smrg s/.*/'"$tab"'/ 552899129b3Smrg G 553899129b3Smrg p 554899129b3Smrg}' >> "$depfile" 555e6d2e958Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556899129b3Smrg rm -f "$tmpdepfile" 557899129b3Smrg ;; 558899129b3Smrg 559899129b3Smrgmsvc7msys) 560899129b3Smrg # This case exists only to let depend.m4 do its work. It works by 561899129b3Smrg # looking at the text of this script. This case will never be run, 562899129b3Smrg # since it is checked for above. 563899129b3Smrg exit 1 564899129b3Smrg ;; 565bd1da9d7Smrg 566bd1da9d7Smrg#nosideeffect) 567bd1da9d7Smrg # This comment above is used by automake to tell side-effect 568bd1da9d7Smrg # dependency tracking mechanisms from slower ones. 569bd1da9d7Smrg 570bd1da9d7Smrgdashmstdout) 571bd1da9d7Smrg # Important note: in order to support this mode, a compiler *must* 572bd1da9d7Smrg # always write the preprocessed file to stdout, regardless of -o. 573bd1da9d7Smrg "$@" || exit $? 574bd1da9d7Smrg 575bd1da9d7Smrg # Remove the call to Libtool. 576bd1da9d7Smrg if test "$libtool" = yes; then 5775bcb6992Smrg while test "X$1" != 'X--mode=compile'; do 578bd1da9d7Smrg shift 579bd1da9d7Smrg done 580bd1da9d7Smrg shift 581bd1da9d7Smrg fi 582bd1da9d7Smrg 583899129b3Smrg # Remove '-o $object'. 584bd1da9d7Smrg IFS=" " 585bd1da9d7Smrg for arg 586bd1da9d7Smrg do 587bd1da9d7Smrg case $arg in 588bd1da9d7Smrg -o) 589bd1da9d7Smrg shift 590bd1da9d7Smrg ;; 591bd1da9d7Smrg $object) 592bd1da9d7Smrg shift 593bd1da9d7Smrg ;; 594bd1da9d7Smrg *) 595bd1da9d7Smrg set fnord "$@" "$arg" 596bd1da9d7Smrg shift # fnord 597bd1da9d7Smrg shift # $arg 598bd1da9d7Smrg ;; 599bd1da9d7Smrg esac 600bd1da9d7Smrg done 601bd1da9d7Smrg 602bd1da9d7Smrg test -z "$dashmflag" && dashmflag=-M 603899129b3Smrg # Require at least two characters before searching for ':' 604bd1da9d7Smrg # in the target name. This is to cope with DOS-style filenames: 605899129b3Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606bd1da9d7Smrg "$@" $dashmflag | 607899129b3Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608bd1da9d7Smrg rm -f "$depfile" 609bd1da9d7Smrg cat < "$tmpdepfile" > "$depfile" 610899129b3Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611899129b3Smrg # correctly. Breaking it into two sed invocations is a workaround. 612899129b3Smrg tr ' ' "$nl" < "$tmpdepfile" \ 613899129b3Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614899129b3Smrg | sed -e 's/$/ :/' >> "$depfile" 615bd1da9d7Smrg rm -f "$tmpdepfile" 616bd1da9d7Smrg ;; 617bd1da9d7Smrg 618bd1da9d7SmrgdashXmstdout) 619bd1da9d7Smrg # This case only exists to satisfy depend.m4. It is never actually 620bd1da9d7Smrg # run, as this mode is specially recognized in the preamble. 621bd1da9d7Smrg exit 1 622bd1da9d7Smrg ;; 623bd1da9d7Smrg 624bd1da9d7Smrgmakedepend) 625bd1da9d7Smrg "$@" || exit $? 626bd1da9d7Smrg # Remove any Libtool call 627bd1da9d7Smrg if test "$libtool" = yes; then 6285bcb6992Smrg while test "X$1" != 'X--mode=compile'; do 629bd1da9d7Smrg shift 630bd1da9d7Smrg done 631bd1da9d7Smrg shift 632bd1da9d7Smrg fi 633bd1da9d7Smrg # X makedepend 634bd1da9d7Smrg shift 6355bcb6992Smrg cleared=no eat=no 6365bcb6992Smrg for arg 6375bcb6992Smrg do 638bd1da9d7Smrg case $cleared in 639bd1da9d7Smrg no) 640bd1da9d7Smrg set ""; shift 641bd1da9d7Smrg cleared=yes ;; 642bd1da9d7Smrg esac 6435bcb6992Smrg if test $eat = yes; then 6445bcb6992Smrg eat=no 6455bcb6992Smrg continue 6465bcb6992Smrg fi 647bd1da9d7Smrg case "$arg" in 648bd1da9d7Smrg -D*|-I*) 649bd1da9d7Smrg set fnord "$@" "$arg"; shift ;; 650bd1da9d7Smrg # Strip any option that makedepend may not understand. Remove 651bd1da9d7Smrg # the object too, otherwise makedepend will parse it as a source file. 6525bcb6992Smrg -arch) 6535bcb6992Smrg eat=yes ;; 654bd1da9d7Smrg -*|$object) 655bd1da9d7Smrg ;; 656bd1da9d7Smrg *) 657bd1da9d7Smrg set fnord "$@" "$arg"; shift ;; 658bd1da9d7Smrg esac 659bd1da9d7Smrg done 6605bcb6992Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661bd1da9d7Smrg touch "$tmpdepfile" 662bd1da9d7Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663bd1da9d7Smrg rm -f "$depfile" 664899129b3Smrg # makedepend may prepend the VPATH from the source file name to the object. 665899129b3Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666899129b3Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667899129b3Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668899129b3Smrg # correctly. Breaking it into two sed invocations is a workaround. 669899129b3Smrg sed '1,2d' "$tmpdepfile" \ 670899129b3Smrg | tr ' ' "$nl" \ 671899129b3Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672899129b3Smrg | sed -e 's/$/ :/' >> "$depfile" 673bd1da9d7Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674bd1da9d7Smrg ;; 675bd1da9d7Smrg 676bd1da9d7Smrgcpp) 677bd1da9d7Smrg # Important note: in order to support this mode, a compiler *must* 678bd1da9d7Smrg # always write the preprocessed file to stdout. 679bd1da9d7Smrg "$@" || exit $? 680bd1da9d7Smrg 681bd1da9d7Smrg # Remove the call to Libtool. 682bd1da9d7Smrg if test "$libtool" = yes; then 6835bcb6992Smrg while test "X$1" != 'X--mode=compile'; do 684bd1da9d7Smrg shift 685bd1da9d7Smrg done 686bd1da9d7Smrg shift 687bd1da9d7Smrg fi 688bd1da9d7Smrg 689899129b3Smrg # Remove '-o $object'. 690bd1da9d7Smrg IFS=" " 691bd1da9d7Smrg for arg 692bd1da9d7Smrg do 693bd1da9d7Smrg case $arg in 694bd1da9d7Smrg -o) 695bd1da9d7Smrg shift 696bd1da9d7Smrg ;; 697bd1da9d7Smrg $object) 698bd1da9d7Smrg shift 699bd1da9d7Smrg ;; 700bd1da9d7Smrg *) 701bd1da9d7Smrg set fnord "$@" "$arg" 702bd1da9d7Smrg shift # fnord 703bd1da9d7Smrg shift # $arg 704bd1da9d7Smrg ;; 705bd1da9d7Smrg esac 706bd1da9d7Smrg done 707bd1da9d7Smrg 708899129b3Smrg "$@" -E \ 709899129b3Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710899129b3Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711899129b3Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712bd1da9d7Smrg rm -f "$depfile" 713bd1da9d7Smrg echo "$object : \\" > "$depfile" 714bd1da9d7Smrg cat < "$tmpdepfile" >> "$depfile" 715bd1da9d7Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716bd1da9d7Smrg rm -f "$tmpdepfile" 717bd1da9d7Smrg ;; 718bd1da9d7Smrg 719bd1da9d7Smrgmsvisualcpp) 720bd1da9d7Smrg # Important note: in order to support this mode, a compiler *must* 7215bcb6992Smrg # always write the preprocessed file to stdout. 722bd1da9d7Smrg "$@" || exit $? 7235bcb6992Smrg 7245bcb6992Smrg # Remove the call to Libtool. 7255bcb6992Smrg if test "$libtool" = yes; then 7265bcb6992Smrg while test "X$1" != 'X--mode=compile'; do 7275bcb6992Smrg shift 7285bcb6992Smrg done 7295bcb6992Smrg shift 7305bcb6992Smrg fi 7315bcb6992Smrg 732bd1da9d7Smrg IFS=" " 733bd1da9d7Smrg for arg 734bd1da9d7Smrg do 735bd1da9d7Smrg case "$arg" in 7365bcb6992Smrg -o) 7375bcb6992Smrg shift 7385bcb6992Smrg ;; 7395bcb6992Smrg $object) 7405bcb6992Smrg shift 7415bcb6992Smrg ;; 742bd1da9d7Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743899129b3Smrg set fnord "$@" 744899129b3Smrg shift 745899129b3Smrg shift 746899129b3Smrg ;; 747bd1da9d7Smrg *) 748899129b3Smrg set fnord "$@" "$arg" 749899129b3Smrg shift 750899129b3Smrg shift 751899129b3Smrg ;; 752bd1da9d7Smrg esac 753bd1da9d7Smrg done 7545bcb6992Smrg "$@" -E 2>/dev/null | 7555bcb6992Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756bd1da9d7Smrg rm -f "$depfile" 757bd1da9d7Smrg echo "$object : \\" > "$depfile" 758899129b3Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759899129b3Smrg echo "$tab" >> "$depfile" 7605bcb6992Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761bd1da9d7Smrg rm -f "$tmpdepfile" 762bd1da9d7Smrg ;; 763bd1da9d7Smrg 7645bcb6992Smrgmsvcmsys) 7655bcb6992Smrg # This case exists only to let depend.m4 do its work. It works by 7665bcb6992Smrg # looking at the text of this script. This case will never be run, 7675bcb6992Smrg # since it is checked for above. 7685bcb6992Smrg exit 1 7695bcb6992Smrg ;; 7705bcb6992Smrg 771bd1da9d7Smrgnone) 772bd1da9d7Smrg exec "$@" 773bd1da9d7Smrg ;; 774bd1da9d7Smrg 775bd1da9d7Smrg*) 776bd1da9d7Smrg echo "Unknown depmode $depmode" 1>&2 777bd1da9d7Smrg exit 1 778bd1da9d7Smrg ;; 779bd1da9d7Smrgesac 780bd1da9d7Smrg 781bd1da9d7Smrgexit 0 782bd1da9d7Smrg 783bd1da9d7Smrg# Local Variables: 784bd1da9d7Smrg# mode: shell-script 785bd1da9d7Smrg# sh-indentation: 2 7866ad5a0e2Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 787bd1da9d7Smrg# time-stamp-start: "scriptversion=" 788bd1da9d7Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 7896ad5a0e2Smrg# time-stamp-time-zone: "UTC0" 7905bcb6992Smrg# time-stamp-end: "; # UTC" 791bd1da9d7Smrg# End: 792