depcomp revision b0c24a08
16ea72052Smrg#! /bin/sh 26ea72052Smrg# depcomp - compile a program generating dependencies as side-effects 3168023feSmrg 4b0c24a08Smrgscriptversion=2013-05-30.07; # UTC 5168023feSmrg 6b0c24a08Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc. 76ea72052Smrg 86ea72052Smrg# This program is free software; you can redistribute it and/or modify 96ea72052Smrg# it under the terms of the GNU General Public License as published by 106ea72052Smrg# the Free Software Foundation; either version 2, or (at your option) 116ea72052Smrg# any later version. 126ea72052Smrg 136ea72052Smrg# This program is distributed in the hope that it will be useful, 146ea72052Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 156ea72052Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 166ea72052Smrg# GNU General Public License for more details. 176ea72052Smrg 186ea72052Smrg# You should have received a copy of the GNU General Public License 19168023feSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 206ea72052Smrg 216ea72052Smrg# As a special exception to the GNU General Public License, if you 226ea72052Smrg# distribute this file as part of a program that contains a 236ea72052Smrg# configuration script generated by Autoconf, you may include it under 246ea72052Smrg# the same distribution terms that you use for the rest of that program. 256ea72052Smrg 266ea72052Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 276ea72052Smrg 28168023feSmrgcase $1 in 29168023feSmrg '') 30b0c24a08Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31b0c24a08Smrg exit 1; 32b0c24a08Smrg ;; 33168023feSmrg -h | --h*) 34168023feSmrg cat <<\EOF 35168023feSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36168023feSmrg 37168023feSmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38168023feSmrgas side-effects. 39168023feSmrg 40168023feSmrgEnvironment variables: 41168023feSmrg depmode Dependency tracking mode. 42b0c24a08Smrg source Source file read by 'PROGRAMS ARGS'. 43b0c24a08Smrg object Object file output by 'PROGRAMS ARGS'. 44168023feSmrg DEPDIR directory where to store dependencies. 45168023feSmrg depfile Dependency file to output. 46b0c24a08Smrg tmpdepfile Temporary file to use when outputting dependencies. 47168023feSmrg libtool Whether libtool is used (yes/no). 48168023feSmrg 49168023feSmrgReport bugs to <bug-automake@gnu.org>. 50168023feSmrgEOF 51168023feSmrg exit $? 52168023feSmrg ;; 53168023feSmrg -v | --v*) 54168023feSmrg echo "depcomp $scriptversion" 55168023feSmrg exit $? 56168023feSmrg ;; 57168023feSmrgesac 58168023feSmrg 59b0c24a08Smrg# Get the directory component of the given path, and save it in the 60b0c24a08Smrg# global variables '$dir'. Note that this directory component will 61b0c24a08Smrg# be either empty or ending with a '/' character. This is deliberate. 62b0c24a08Smrgset_dir_from () 63b0c24a08Smrg{ 64b0c24a08Smrg case $1 in 65b0c24a08Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66b0c24a08Smrg *) dir=;; 67b0c24a08Smrg esac 68b0c24a08Smrg} 69b0c24a08Smrg 70b0c24a08Smrg# Get the suffix-stripped basename of the given path, and save it the 71b0c24a08Smrg# global variable '$base'. 72b0c24a08Smrgset_base_from () 73b0c24a08Smrg{ 74b0c24a08Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75b0c24a08Smrg} 76b0c24a08Smrg 77b0c24a08Smrg# If no dependency file was actually created by the compiler invocation, 78b0c24a08Smrg# we still have to create a dummy depfile, to avoid errors with the 79b0c24a08Smrg# Makefile "include basename.Plo" scheme. 80b0c24a08Smrgmake_dummy_depfile () 81b0c24a08Smrg{ 82b0c24a08Smrg echo "#dummy" > "$depfile" 83b0c24a08Smrg} 84b0c24a08Smrg 85b0c24a08Smrg# Factor out some common post-processing of the generated depfile. 86b0c24a08Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87b0c24a08Smrgaix_post_process_depfile () 88b0c24a08Smrg{ 89b0c24a08Smrg # If the compiler actually managed to produce a dependency file, 90b0c24a08Smrg # post-process it. 91b0c24a08Smrg if test -f "$tmpdepfile"; then 92b0c24a08Smrg # Each line is of the form 'foo.o: dependency.h'. 93b0c24a08Smrg # Do two passes, one to just change these to 94b0c24a08Smrg # $object: dependency.h 95b0c24a08Smrg # and one to simply output 96b0c24a08Smrg # dependency.h: 97b0c24a08Smrg # which is needed to avoid the deleted-header problem. 98b0c24a08Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99b0c24a08Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100b0c24a08Smrg } > "$depfile" 101b0c24a08Smrg rm -f "$tmpdepfile" 102b0c24a08Smrg else 103b0c24a08Smrg make_dummy_depfile 104b0c24a08Smrg fi 105b0c24a08Smrg} 106b0c24a08Smrg 107b0c24a08Smrg# A tabulation character. 108b0c24a08Smrgtab=' ' 109b0c24a08Smrg# A newline character. 110b0c24a08Smrgnl=' 111b0c24a08Smrg' 112b0c24a08Smrg# Character ranges might be problematic outside the C locale. 113b0c24a08Smrg# These definitions help. 114b0c24a08Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115b0c24a08Smrglower=abcdefghijklmnopqrstuvwxyz 116b0c24a08Smrgdigits=0123456789 117b0c24a08Smrgalpha=${upper}${lower} 118b0c24a08Smrg 1196ea72052Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1206ea72052Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1216ea72052Smrg exit 1 1226ea72052Smrgfi 1236ea72052Smrg 124168023feSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125168023feSmrgdepfile=${depfile-`echo "$object" | 126168023feSmrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1276ea72052Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1286ea72052Smrg 1296ea72052Smrgrm -f "$tmpdepfile" 1306ea72052Smrg 131b0c24a08Smrg# Avoid interferences from the environment. 132b0c24a08Smrggccflag= dashmflag= 133b0c24a08Smrg 1346ea72052Smrg# Some modes work just like other modes, but use different flags. We 1356ea72052Smrg# parameterize here, but still list the modes in the big case below, 1366ea72052Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1376ea72052Smrg# here, because this file can only contain one case statement. 1386ea72052Smrgif test "$depmode" = hp; then 1396ea72052Smrg # HP compiler uses -M and no extra arg. 1406ea72052Smrg gccflag=-M 1416ea72052Smrg depmode=gcc 1426ea72052Smrgfi 1436ea72052Smrg 1446ea72052Smrgif test "$depmode" = dashXmstdout; then 145b0c24a08Smrg # This is just like dashmstdout with a different argument. 146b0c24a08Smrg dashmflag=-xM 147b0c24a08Smrg depmode=dashmstdout 1486ea72052Smrgfi 1496ea72052Smrg 150168023feSmrgcygpath_u="cygpath -u -f -" 151168023feSmrgif test "$depmode" = msvcmsys; then 152b0c24a08Smrg # This is just like msvisualcpp but w/o cygpath translation. 153b0c24a08Smrg # Just convert the backslash-escaped backslashes to single forward 154b0c24a08Smrg # slashes to satisfy depend.m4 155b0c24a08Smrg cygpath_u='sed s,\\\\,/,g' 156b0c24a08Smrg depmode=msvisualcpp 157b0c24a08Smrgfi 158b0c24a08Smrg 159b0c24a08Smrgif test "$depmode" = msvc7msys; then 160b0c24a08Smrg # This is just like msvc7 but w/o cygpath translation. 161b0c24a08Smrg # Just convert the backslash-escaped backslashes to single forward 162b0c24a08Smrg # slashes to satisfy depend.m4 163b0c24a08Smrg cygpath_u='sed s,\\\\,/,g' 164b0c24a08Smrg depmode=msvc7 165b0c24a08Smrgfi 166b0c24a08Smrg 167b0c24a08Smrgif test "$depmode" = xlc; then 168b0c24a08Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169b0c24a08Smrg gccflag=-qmakedep=gcc,-MF 170b0c24a08Smrg depmode=gcc 171168023feSmrgfi 172168023feSmrg 1736ea72052Smrgcase "$depmode" in 1746ea72052Smrggcc3) 1756ea72052Smrg## gcc 3 implements dependency tracking that does exactly what 1766ea72052Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1776ea72052Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178168023feSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179168023feSmrg## the command line argument order; so add the flags where they 180168023feSmrg## appear in depend2.am. Note that the slowdown incurred here 181168023feSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182168023feSmrg for arg 183168023feSmrg do 184168023feSmrg case $arg in 185168023feSmrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186168023feSmrg *) set fnord "$@" "$arg" ;; 187168023feSmrg esac 188168023feSmrg shift # fnord 189168023feSmrg shift # $arg 190168023feSmrg done 191168023feSmrg "$@" 1926ea72052Smrg stat=$? 193b0c24a08Smrg if test $stat -ne 0; then 1946ea72052Smrg rm -f "$tmpdepfile" 1956ea72052Smrg exit $stat 1966ea72052Smrg fi 1976ea72052Smrg mv "$tmpdepfile" "$depfile" 1986ea72052Smrg ;; 1996ea72052Smrg 2006ea72052Smrggcc) 201b0c24a08Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202b0c24a08Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203b0c24a08Smrg## (see the conditional assignment to $gccflag above). 2046ea72052Smrg## There are various ways to get dependency output from gcc. Here's 2056ea72052Smrg## why we pick this rather obscure method: 2066ea72052Smrg## - Don't want to use -MD because we'd like the dependencies to end 2076ea72052Smrg## up in a subdir. Having to rename by hand is ugly. 2086ea72052Smrg## (We might end up doing this anyway to support other compilers.) 2096ea72052Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210b0c24a08Smrg## -MM, not -M (despite what the docs say). Also, it might not be 211b0c24a08Smrg## supported by the other compilers which use the 'gcc' depmode. 2126ea72052Smrg## - Using -M directly means running the compiler twice (even worse 2136ea72052Smrg## than renaming). 2146ea72052Smrg if test -z "$gccflag"; then 2156ea72052Smrg gccflag=-MD, 2166ea72052Smrg fi 2176ea72052Smrg "$@" -Wp,"$gccflag$tmpdepfile" 2186ea72052Smrg stat=$? 219b0c24a08Smrg if test $stat -ne 0; then 2206ea72052Smrg rm -f "$tmpdepfile" 2216ea72052Smrg exit $stat 2226ea72052Smrg fi 2236ea72052Smrg rm -f "$depfile" 2246ea72052Smrg echo "$object : \\" > "$depfile" 225b0c24a08Smrg # The second -e expression handles DOS-style file names with drive 226b0c24a08Smrg # letters. 2276ea72052Smrg sed -e 's/^[^:]*: / /' \ 2286ea72052Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229b0c24a08Smrg## This next piece of magic avoids the "deleted header file" problem. 2306ea72052Smrg## The problem is that when a header file which appears in a .P file 2316ea72052Smrg## is deleted, the dependency causes make to die (because there is 2326ea72052Smrg## typically no way to rebuild the header). We avoid this by adding 2336ea72052Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 2346ea72052Smrg## this for us directly. 235b0c24a08Smrg## Some versions of gcc put a space before the ':'. On the theory 2366ea72052Smrg## that the space means something, we add a space to the output as 237b0c24a08Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238b0c24a08Smrg## to the object. Take care to not repeat it in the output. 2396ea72052Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 2406ea72052Smrg## correctly. Breaking it into two sed invocations is a workaround. 241b0c24a08Smrg tr ' ' "$nl" < "$tmpdepfile" \ 242b0c24a08Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243b0c24a08Smrg | sed -e 's/$/ :/' >> "$depfile" 2446ea72052Smrg rm -f "$tmpdepfile" 2456ea72052Smrg ;; 2466ea72052Smrg 2476ea72052Smrghp) 2486ea72052Smrg # This case exists only to let depend.m4 do its work. It works by 2496ea72052Smrg # looking at the text of this script. This case will never be run, 2506ea72052Smrg # since it is checked for above. 2516ea72052Smrg exit 1 2526ea72052Smrg ;; 2536ea72052Smrg 2546ea72052Smrgsgi) 2556ea72052Smrg if test "$libtool" = yes; then 2566ea72052Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2576ea72052Smrg else 2586ea72052Smrg "$@" -MDupdate "$tmpdepfile" 2596ea72052Smrg fi 2606ea72052Smrg stat=$? 261b0c24a08Smrg if test $stat -ne 0; then 2626ea72052Smrg rm -f "$tmpdepfile" 2636ea72052Smrg exit $stat 2646ea72052Smrg fi 2656ea72052Smrg rm -f "$depfile" 2666ea72052Smrg 2676ea72052Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2686ea72052Smrg echo "$object : \\" > "$depfile" 2696ea72052Smrg # Clip off the initial element (the dependent). Don't try to be 2706ea72052Smrg # clever and replace this with sed code, as IRIX sed won't handle 2716ea72052Smrg # lines with more than a fixed number of characters (4096 in 2726ea72052Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273b0c24a08Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2746ea72052Smrg # dependency line. 275b0c24a08Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276b0c24a08Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277b0c24a08Smrg | tr "$nl" ' ' >> "$depfile" 278168023feSmrg echo >> "$depfile" 2796ea72052Smrg # The second pass generates a dummy entry for each header file. 280b0c24a08Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281b0c24a08Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282b0c24a08Smrg >> "$depfile" 2836ea72052Smrg else 284b0c24a08Smrg make_dummy_depfile 2856ea72052Smrg fi 2866ea72052Smrg rm -f "$tmpdepfile" 2876ea72052Smrg ;; 2886ea72052Smrg 289b0c24a08Smrgxlc) 290b0c24a08Smrg # This case exists only to let depend.m4 do its work. It works by 291b0c24a08Smrg # looking at the text of this script. This case will never be run, 292b0c24a08Smrg # since it is checked for above. 293b0c24a08Smrg exit 1 294b0c24a08Smrg ;; 295b0c24a08Smrg 2966ea72052Smrgaix) 2976ea72052Smrg # The C for AIX Compiler uses -M and outputs the dependencies 2986ea72052Smrg # in a .u file. In older versions, this file always lives in the 299b0c24a08Smrg # current directory. Also, the AIX compiler puts '$object:' at the 3006ea72052Smrg # start of each line; $object doesn't have directory information. 3016ea72052Smrg # Version 6 uses the directory in both cases. 302b0c24a08Smrg set_dir_from "$object" 303b0c24a08Smrg set_base_from "$object" 3046ea72052Smrg if test "$libtool" = yes; then 305168023feSmrg tmpdepfile1=$dir$base.u 306168023feSmrg tmpdepfile2=$base.u 307168023feSmrg tmpdepfile3=$dir.libs/$base.u 3086ea72052Smrg "$@" -Wc,-M 3096ea72052Smrg else 310168023feSmrg tmpdepfile1=$dir$base.u 311168023feSmrg tmpdepfile2=$dir$base.u 312168023feSmrg tmpdepfile3=$dir$base.u 3136ea72052Smrg "$@" -M 3146ea72052Smrg fi 3156ea72052Smrg stat=$? 316b0c24a08Smrg if test $stat -ne 0; then 317168023feSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3186ea72052Smrg exit $stat 3196ea72052Smrg fi 3206ea72052Smrg 321168023feSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322168023feSmrg do 323168023feSmrg test -f "$tmpdepfile" && break 324168023feSmrg done 325b0c24a08Smrg aix_post_process_depfile 326b0c24a08Smrg ;; 327b0c24a08Smrg 328b0c24a08Smrgtcc) 329b0c24a08Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330b0c24a08Smrg # FIXME: That version still under development at the moment of writing. 331b0c24a08Smrg # Make that this statement remains true also for stable, released 332b0c24a08Smrg # versions. 333b0c24a08Smrg # It will wrap lines (doesn't matter whether long or short) with a 334b0c24a08Smrg # trailing '\', as in: 335b0c24a08Smrg # 336b0c24a08Smrg # foo.o : \ 337b0c24a08Smrg # foo.c \ 338b0c24a08Smrg # foo.h \ 339b0c24a08Smrg # 340b0c24a08Smrg # It will put a trailing '\' even on the last line, and will use leading 341b0c24a08Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 342b0c24a08Smrg # "Emit spaces for -MD"). 343b0c24a08Smrg "$@" -MD -MF "$tmpdepfile" 344b0c24a08Smrg stat=$? 345b0c24a08Smrg if test $stat -ne 0; then 346b0c24a08Smrg rm -f "$tmpdepfile" 347b0c24a08Smrg exit $stat 3486ea72052Smrg fi 349b0c24a08Smrg rm -f "$depfile" 350b0c24a08Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351b0c24a08Smrg # We have to change lines of the first kind to '$object: \'. 352b0c24a08Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353b0c24a08Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 354b0c24a08Smrg # dummy dependency, to avoid the deleted-header problem. 355b0c24a08Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3566ea72052Smrg rm -f "$tmpdepfile" 3576ea72052Smrg ;; 3586ea72052Smrg 359b0c24a08Smrg## The order of this option in the case statement is important, since the 360b0c24a08Smrg## shell code in configure will try each of these formats in the order 361b0c24a08Smrg## listed in this file. A plain '-MD' option would be understood by many 362b0c24a08Smrg## compilers, so we must ensure this comes after the gcc and icc options. 363b0c24a08Smrgpgcc) 364b0c24a08Smrg # Portland's C compiler understands '-MD'. 365b0c24a08Smrg # Will always output deps to 'file.d' where file is the root name of the 366b0c24a08Smrg # source file under compilation, even if file resides in a subdirectory. 367b0c24a08Smrg # The object file name does not affect the name of the '.d' file. 368b0c24a08Smrg # pgcc 10.2 will output 3696ea72052Smrg # foo.o: sub/foo.c sub/foo.h 370b0c24a08Smrg # and will wrap long lines using '\' : 3716ea72052Smrg # foo.o: sub/foo.c ... \ 3726ea72052Smrg # sub/foo.h ... \ 3736ea72052Smrg # ... 374b0c24a08Smrg set_dir_from "$object" 375b0c24a08Smrg # Use the source, not the object, to determine the base name, since 376b0c24a08Smrg # that's sadly what pgcc will do too. 377b0c24a08Smrg set_base_from "$source" 378b0c24a08Smrg tmpdepfile=$base.d 379b0c24a08Smrg 380b0c24a08Smrg # For projects that build the same source file twice into different object 381b0c24a08Smrg # files, the pgcc approach of using the *source* file root name can cause 382b0c24a08Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383b0c24a08Smrg # the same $tmpdepfile. 384b0c24a08Smrg lockdir=$base.d-lock 385b0c24a08Smrg trap " 386b0c24a08Smrg echo '$0: caught signal, cleaning up...' >&2 387b0c24a08Smrg rmdir '$lockdir' 388b0c24a08Smrg exit 1 389b0c24a08Smrg " 1 2 13 15 390b0c24a08Smrg numtries=100 391b0c24a08Smrg i=$numtries 392b0c24a08Smrg while test $i -gt 0; do 393b0c24a08Smrg # mkdir is a portable test-and-set. 394b0c24a08Smrg if mkdir "$lockdir" 2>/dev/null; then 395b0c24a08Smrg # This process acquired the lock. 396b0c24a08Smrg "$@" -MD 397b0c24a08Smrg stat=$? 398b0c24a08Smrg # Release the lock. 399b0c24a08Smrg rmdir "$lockdir" 400b0c24a08Smrg break 401b0c24a08Smrg else 402b0c24a08Smrg # If the lock is being held by a different process, wait 403b0c24a08Smrg # until the winning process is done or we timeout. 404b0c24a08Smrg while test -d "$lockdir" && test $i -gt 0; do 405b0c24a08Smrg sleep 1 406b0c24a08Smrg i=`expr $i - 1` 407b0c24a08Smrg done 408b0c24a08Smrg fi 409b0c24a08Smrg i=`expr $i - 1` 410b0c24a08Smrg done 411b0c24a08Smrg trap - 1 2 13 15 412b0c24a08Smrg if test $i -le 0; then 413b0c24a08Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414b0c24a08Smrg echo "$0: check lockdir '$lockdir'" >&2 415b0c24a08Smrg exit 1 416b0c24a08Smrg fi 4176ea72052Smrg 418b0c24a08Smrg if test $stat -ne 0; then 4196ea72052Smrg rm -f "$tmpdepfile" 4206ea72052Smrg exit $stat 4216ea72052Smrg fi 4226ea72052Smrg rm -f "$depfile" 4236ea72052Smrg # Each line is of the form `foo.o: dependent.h', 4246ea72052Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4256ea72052Smrg # Do two passes, one to just change these to 4266ea72052Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 4276ea72052Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4286ea72052Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 4296ea72052Smrg # correctly. Breaking it into two sed invocations is a workaround. 430b0c24a08Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431b0c24a08Smrg | sed -e 's/$/ :/' >> "$depfile" 4326ea72052Smrg rm -f "$tmpdepfile" 4336ea72052Smrg ;; 4346ea72052Smrg 435168023feSmrghp2) 436168023feSmrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437168023feSmrg # compilers, which have integrated preprocessors. The correct option 438168023feSmrg # to use with these is +Maked; it writes dependencies to a file named 439168023feSmrg # 'foo.d', which lands next to the object file, wherever that 440168023feSmrg # happens to be. 441168023feSmrg # Much of this is similar to the tru64 case; see comments there. 442b0c24a08Smrg set_dir_from "$object" 443b0c24a08Smrg set_base_from "$object" 444168023feSmrg if test "$libtool" = yes; then 445168023feSmrg tmpdepfile1=$dir$base.d 446168023feSmrg tmpdepfile2=$dir.libs/$base.d 447168023feSmrg "$@" -Wc,+Maked 448168023feSmrg else 449168023feSmrg tmpdepfile1=$dir$base.d 450168023feSmrg tmpdepfile2=$dir$base.d 451168023feSmrg "$@" +Maked 452168023feSmrg fi 453168023feSmrg stat=$? 454b0c24a08Smrg if test $stat -ne 0; then 455168023feSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456168023feSmrg exit $stat 457168023feSmrg fi 458168023feSmrg 459168023feSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460168023feSmrg do 461168023feSmrg test -f "$tmpdepfile" && break 462168023feSmrg done 463168023feSmrg if test -f "$tmpdepfile"; then 464b0c24a08Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465b0c24a08Smrg # Add 'dependent.h:' lines. 466168023feSmrg sed -ne '2,${ 467b0c24a08Smrg s/^ *// 468b0c24a08Smrg s/ \\*$// 469b0c24a08Smrg s/$/:/ 470b0c24a08Smrg p 471b0c24a08Smrg }' "$tmpdepfile" >> "$depfile" 472168023feSmrg else 473b0c24a08Smrg make_dummy_depfile 474168023feSmrg fi 475168023feSmrg rm -f "$tmpdepfile" "$tmpdepfile2" 476168023feSmrg ;; 477168023feSmrg 4786ea72052Smrgtru64) 479b0c24a08Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 480b0c24a08Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481b0c24a08Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482b0c24a08Smrg # dependencies in 'foo.d' instead, so we check for that too. 483b0c24a08Smrg # Subdirectories are respected. 484b0c24a08Smrg set_dir_from "$object" 485b0c24a08Smrg set_base_from "$object" 486b0c24a08Smrg 487b0c24a08Smrg if test "$libtool" = yes; then 488b0c24a08Smrg # Libtool generates 2 separate objects for the 2 libraries. These 489b0c24a08Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 490b0c24a08Smrg # in $dir$base.o.d. We have to check for both files, because 491b0c24a08Smrg # one of the two compilations can be disabled. We should prefer 492b0c24a08Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493b0c24a08Smrg # automatically cleaned when .libs/ is deleted, while ignoring 494b0c24a08Smrg # the former would cause a distcleancheck panic. 495b0c24a08Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496b0c24a08Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497b0c24a08Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498b0c24a08Smrg "$@" -Wc,-MD 499b0c24a08Smrg else 500b0c24a08Smrg tmpdepfile1=$dir$base.d 501b0c24a08Smrg tmpdepfile2=$dir$base.d 502b0c24a08Smrg tmpdepfile3=$dir$base.d 503b0c24a08Smrg "$@" -MD 504b0c24a08Smrg fi 505b0c24a08Smrg 506b0c24a08Smrg stat=$? 507b0c24a08Smrg if test $stat -ne 0; then 508b0c24a08Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509b0c24a08Smrg exit $stat 510b0c24a08Smrg fi 511b0c24a08Smrg 512b0c24a08Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513b0c24a08Smrg do 514b0c24a08Smrg test -f "$tmpdepfile" && break 515b0c24a08Smrg done 516b0c24a08Smrg # Same post-processing that is required for AIX mode. 517b0c24a08Smrg aix_post_process_depfile 518b0c24a08Smrg ;; 519b0c24a08Smrg 520b0c24a08Smrgmsvc7) 521b0c24a08Smrg if test "$libtool" = yes; then 522b0c24a08Smrg showIncludes=-Wc,-showIncludes 523b0c24a08Smrg else 524b0c24a08Smrg showIncludes=-showIncludes 525b0c24a08Smrg fi 526b0c24a08Smrg "$@" $showIncludes > "$tmpdepfile" 527b0c24a08Smrg stat=$? 528b0c24a08Smrg grep -v '^Note: including file: ' "$tmpdepfile" 529b0c24a08Smrg if test $stat -ne 0; then 530b0c24a08Smrg rm -f "$tmpdepfile" 531b0c24a08Smrg exit $stat 532b0c24a08Smrg fi 533b0c24a08Smrg rm -f "$depfile" 534b0c24a08Smrg echo "$object : \\" > "$depfile" 535b0c24a08Smrg # The first sed program below extracts the file names and escapes 536b0c24a08Smrg # backslashes for cygpath. The second sed program outputs the file 537b0c24a08Smrg # name when reading, but also accumulates all include files in the 538b0c24a08Smrg # hold buffer in order to output them again at the end. This only 539b0c24a08Smrg # works with sed implementations that can handle large buffers. 540b0c24a08Smrg sed < "$tmpdepfile" -n ' 541b0c24a08Smrg/^Note: including file: *\(.*\)/ { 542b0c24a08Smrg s//\1/ 543b0c24a08Smrg s/\\/\\\\/g 544b0c24a08Smrg p 545b0c24a08Smrg}' | $cygpath_u | sort -u | sed -n ' 546b0c24a08Smrgs/ /\\ /g 547b0c24a08Smrgs/\(.*\)/'"$tab"'\1 \\/p 548b0c24a08Smrgs/.\(.*\) \\/\1:/ 549b0c24a08SmrgH 550b0c24a08Smrg$ { 551b0c24a08Smrg s/.*/'"$tab"'/ 552b0c24a08Smrg G 553b0c24a08Smrg p 554b0c24a08Smrg}' >> "$depfile" 555b0c24a08Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556b0c24a08Smrg rm -f "$tmpdepfile" 557b0c24a08Smrg ;; 558b0c24a08Smrg 559b0c24a08Smrgmsvc7msys) 560b0c24a08Smrg # This case exists only to let depend.m4 do its work. It works by 561b0c24a08Smrg # looking at the text of this script. This case will never be run, 562b0c24a08Smrg # since it is checked for above. 563b0c24a08Smrg exit 1 564b0c24a08Smrg ;; 5656ea72052Smrg 5666ea72052Smrg#nosideeffect) 5676ea72052Smrg # This comment above is used by automake to tell side-effect 5686ea72052Smrg # dependency tracking mechanisms from slower ones. 5696ea72052Smrg 5706ea72052Smrgdashmstdout) 5716ea72052Smrg # Important note: in order to support this mode, a compiler *must* 5726ea72052Smrg # always write the preprocessed file to stdout, regardless of -o. 5736ea72052Smrg "$@" || exit $? 5746ea72052Smrg 5756ea72052Smrg # Remove the call to Libtool. 5766ea72052Smrg if test "$libtool" = yes; then 577168023feSmrg while test "X$1" != 'X--mode=compile'; do 5786ea72052Smrg shift 5796ea72052Smrg done 5806ea72052Smrg shift 5816ea72052Smrg fi 5826ea72052Smrg 583b0c24a08Smrg # Remove '-o $object'. 5846ea72052Smrg IFS=" " 5856ea72052Smrg for arg 5866ea72052Smrg do 5876ea72052Smrg case $arg in 5886ea72052Smrg -o) 5896ea72052Smrg shift 5906ea72052Smrg ;; 5916ea72052Smrg $object) 5926ea72052Smrg shift 5936ea72052Smrg ;; 5946ea72052Smrg *) 5956ea72052Smrg set fnord "$@" "$arg" 5966ea72052Smrg shift # fnord 5976ea72052Smrg shift # $arg 5986ea72052Smrg ;; 5996ea72052Smrg esac 6006ea72052Smrg done 6016ea72052Smrg 6026ea72052Smrg test -z "$dashmflag" && dashmflag=-M 603b0c24a08Smrg # Require at least two characters before searching for ':' 6046ea72052Smrg # in the target name. This is to cope with DOS-style filenames: 605b0c24a08Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6066ea72052Smrg "$@" $dashmflag | 607b0c24a08Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6086ea72052Smrg rm -f "$depfile" 6096ea72052Smrg cat < "$tmpdepfile" > "$depfile" 610b0c24a08Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611b0c24a08Smrg # correctly. Breaking it into two sed invocations is a workaround. 612b0c24a08Smrg tr ' ' "$nl" < "$tmpdepfile" \ 613b0c24a08Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614b0c24a08Smrg | sed -e 's/$/ :/' >> "$depfile" 6156ea72052Smrg rm -f "$tmpdepfile" 6166ea72052Smrg ;; 6176ea72052Smrg 6186ea72052SmrgdashXmstdout) 6196ea72052Smrg # This case only exists to satisfy depend.m4. It is never actually 6206ea72052Smrg # run, as this mode is specially recognized in the preamble. 6216ea72052Smrg exit 1 6226ea72052Smrg ;; 6236ea72052Smrg 6246ea72052Smrgmakedepend) 6256ea72052Smrg "$@" || exit $? 6266ea72052Smrg # Remove any Libtool call 6276ea72052Smrg if test "$libtool" = yes; then 628168023feSmrg while test "X$1" != 'X--mode=compile'; do 6296ea72052Smrg shift 6306ea72052Smrg done 6316ea72052Smrg shift 6326ea72052Smrg fi 6336ea72052Smrg # X makedepend 6346ea72052Smrg shift 635168023feSmrg cleared=no eat=no 636168023feSmrg for arg 637168023feSmrg do 6386ea72052Smrg case $cleared in 6396ea72052Smrg no) 6406ea72052Smrg set ""; shift 6416ea72052Smrg cleared=yes ;; 6426ea72052Smrg esac 643168023feSmrg if test $eat = yes; then 644168023feSmrg eat=no 645168023feSmrg continue 646168023feSmrg fi 6476ea72052Smrg case "$arg" in 6486ea72052Smrg -D*|-I*) 6496ea72052Smrg set fnord "$@" "$arg"; shift ;; 6506ea72052Smrg # Strip any option that makedepend may not understand. Remove 6516ea72052Smrg # the object too, otherwise makedepend will parse it as a source file. 652168023feSmrg -arch) 653168023feSmrg eat=yes ;; 6546ea72052Smrg -*|$object) 6556ea72052Smrg ;; 6566ea72052Smrg *) 6576ea72052Smrg set fnord "$@" "$arg"; shift ;; 6586ea72052Smrg esac 6596ea72052Smrg done 660168023feSmrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6616ea72052Smrg touch "$tmpdepfile" 6626ea72052Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6636ea72052Smrg rm -f "$depfile" 664b0c24a08Smrg # makedepend may prepend the VPATH from the source file name to the object. 665b0c24a08Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666b0c24a08Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667b0c24a08Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668b0c24a08Smrg # correctly. Breaking it into two sed invocations is a workaround. 669b0c24a08Smrg sed '1,2d' "$tmpdepfile" \ 670b0c24a08Smrg | tr ' ' "$nl" \ 671b0c24a08Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672b0c24a08Smrg | sed -e 's/$/ :/' >> "$depfile" 6736ea72052Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6746ea72052Smrg ;; 6756ea72052Smrg 6766ea72052Smrgcpp) 6776ea72052Smrg # Important note: in order to support this mode, a compiler *must* 6786ea72052Smrg # always write the preprocessed file to stdout. 6796ea72052Smrg "$@" || exit $? 6806ea72052Smrg 6816ea72052Smrg # Remove the call to Libtool. 6826ea72052Smrg if test "$libtool" = yes; then 683168023feSmrg while test "X$1" != 'X--mode=compile'; do 6846ea72052Smrg shift 6856ea72052Smrg done 6866ea72052Smrg shift 6876ea72052Smrg fi 6886ea72052Smrg 689b0c24a08Smrg # Remove '-o $object'. 6906ea72052Smrg IFS=" " 6916ea72052Smrg for arg 6926ea72052Smrg do 6936ea72052Smrg case $arg in 6946ea72052Smrg -o) 6956ea72052Smrg shift 6966ea72052Smrg ;; 6976ea72052Smrg $object) 6986ea72052Smrg shift 6996ea72052Smrg ;; 7006ea72052Smrg *) 7016ea72052Smrg set fnord "$@" "$arg" 7026ea72052Smrg shift # fnord 7036ea72052Smrg shift # $arg 7046ea72052Smrg ;; 7056ea72052Smrg esac 7066ea72052Smrg done 7076ea72052Smrg 708b0c24a08Smrg "$@" -E \ 709b0c24a08Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710b0c24a08Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711b0c24a08Smrg | sed '$ s: \\$::' > "$tmpdepfile" 7126ea72052Smrg rm -f "$depfile" 7136ea72052Smrg echo "$object : \\" > "$depfile" 7146ea72052Smrg cat < "$tmpdepfile" >> "$depfile" 7156ea72052Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7166ea72052Smrg rm -f "$tmpdepfile" 7176ea72052Smrg ;; 7186ea72052Smrg 7196ea72052Smrgmsvisualcpp) 7206ea72052Smrg # Important note: in order to support this mode, a compiler *must* 721168023feSmrg # always write the preprocessed file to stdout. 7226ea72052Smrg "$@" || exit $? 723168023feSmrg 724168023feSmrg # Remove the call to Libtool. 725168023feSmrg if test "$libtool" = yes; then 726168023feSmrg while test "X$1" != 'X--mode=compile'; do 727168023feSmrg shift 728168023feSmrg done 729168023feSmrg shift 730168023feSmrg fi 731168023feSmrg 7326ea72052Smrg IFS=" " 7336ea72052Smrg for arg 7346ea72052Smrg do 7356ea72052Smrg case "$arg" in 736168023feSmrg -o) 737168023feSmrg shift 738168023feSmrg ;; 739168023feSmrg $object) 740168023feSmrg shift 741168023feSmrg ;; 7426ea72052Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743b0c24a08Smrg set fnord "$@" 744b0c24a08Smrg shift 745b0c24a08Smrg shift 746b0c24a08Smrg ;; 7476ea72052Smrg *) 748b0c24a08Smrg set fnord "$@" "$arg" 749b0c24a08Smrg shift 750b0c24a08Smrg shift 751b0c24a08Smrg ;; 7526ea72052Smrg esac 7536ea72052Smrg done 754168023feSmrg "$@" -E 2>/dev/null | 755168023feSmrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7566ea72052Smrg rm -f "$depfile" 7576ea72052Smrg echo "$object : \\" > "$depfile" 758b0c24a08Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759b0c24a08Smrg echo "$tab" >> "$depfile" 760168023feSmrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7616ea72052Smrg rm -f "$tmpdepfile" 7626ea72052Smrg ;; 7636ea72052Smrg 764168023feSmrgmsvcmsys) 765168023feSmrg # This case exists only to let depend.m4 do its work. It works by 766168023feSmrg # looking at the text of this script. This case will never be run, 767168023feSmrg # since it is checked for above. 768168023feSmrg exit 1 769168023feSmrg ;; 770168023feSmrg 7716ea72052Smrgnone) 7726ea72052Smrg exec "$@" 7736ea72052Smrg ;; 7746ea72052Smrg 7756ea72052Smrg*) 7766ea72052Smrg echo "Unknown depmode $depmode" 1>&2 7776ea72052Smrg exit 1 7786ea72052Smrg ;; 7796ea72052Smrgesac 7806ea72052Smrg 7816ea72052Smrgexit 0 782168023feSmrg 783168023feSmrg# Local Variables: 784168023feSmrg# mode: shell-script 785168023feSmrg# sh-indentation: 2 786168023feSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 787168023feSmrg# time-stamp-start: "scriptversion=" 788168023feSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789168023feSmrg# time-stamp-time-zone: "UTC" 790168023feSmrg# time-stamp-end: "; # UTC" 791168023feSmrg# End: 792