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