1c06b6b69Smrg#! /bin/sh 2c06b6b69Smrg# depcomp - compile a program generating dependencies as side-effects 3c06b6b69Smrg 444256261Smrgscriptversion=2018-03-07.03; # UTC 5c06b6b69Smrg 644256261Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7c06b6b69Smrg 8c06b6b69Smrg# This program is free software; you can redistribute it and/or modify 9c06b6b69Smrg# it under the terms of the GNU General Public License as published by 10c06b6b69Smrg# the Free Software Foundation; either version 2, or (at your option) 11c06b6b69Smrg# any later version. 12c06b6b69Smrg 13c06b6b69Smrg# This program is distributed in the hope that it will be useful, 14c06b6b69Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15c06b6b69Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c06b6b69Smrg# GNU General Public License for more details. 17c06b6b69Smrg 18c06b6b69Smrg# You should have received a copy of the GNU General Public License 1944256261Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20c06b6b69Smrg 21c06b6b69Smrg# As a special exception to the GNU General Public License, if you 22c06b6b69Smrg# distribute this file as part of a program that contains a 23c06b6b69Smrg# configuration script generated by Autoconf, you may include it under 24c06b6b69Smrg# the same distribution terms that you use for the rest of that program. 25c06b6b69Smrg 26c06b6b69Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27c06b6b69Smrg 28c06b6b69Smrgcase $1 in 29c06b6b69Smrg '') 307a5ec427Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 317a5ec427Smrg exit 1; 327a5ec427Smrg ;; 33c06b6b69Smrg -h | --h*) 34c06b6b69Smrg cat <<\EOF 35c06b6b69SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36c06b6b69Smrg 37c06b6b69SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38c06b6b69Smrgas side-effects. 39c06b6b69Smrg 40c06b6b69SmrgEnvironment variables: 41c06b6b69Smrg depmode Dependency tracking mode. 427a5ec427Smrg source Source file read by 'PROGRAMS ARGS'. 437a5ec427Smrg object Object file output by 'PROGRAMS ARGS'. 44c06b6b69Smrg DEPDIR directory where to store dependencies. 45c06b6b69Smrg depfile Dependency file to output. 46a1d73b4bSmrg tmpdepfile Temporary file to use when outputting dependencies. 47c06b6b69Smrg libtool Whether libtool is used (yes/no). 48c06b6b69Smrg 49c06b6b69SmrgReport bugs to <bug-automake@gnu.org>. 50c06b6b69SmrgEOF 51c06b6b69Smrg exit $? 52c06b6b69Smrg ;; 53c06b6b69Smrg -v | --v*) 54c06b6b69Smrg echo "depcomp $scriptversion" 55c06b6b69Smrg exit $? 56c06b6b69Smrg ;; 57c06b6b69Smrgesac 58c06b6b69Smrg 597a5ec427Smrg# Get the directory component of the given path, and save it in the 607a5ec427Smrg# global variables '$dir'. Note that this directory component will 617a5ec427Smrg# be either empty or ending with a '/' character. This is deliberate. 627a5ec427Smrgset_dir_from () 637a5ec427Smrg{ 647a5ec427Smrg case $1 in 657a5ec427Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 667a5ec427Smrg *) dir=;; 677a5ec427Smrg esac 687a5ec427Smrg} 697a5ec427Smrg 707a5ec427Smrg# Get the suffix-stripped basename of the given path, and save it the 717a5ec427Smrg# global variable '$base'. 727a5ec427Smrgset_base_from () 737a5ec427Smrg{ 747a5ec427Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 757a5ec427Smrg} 767a5ec427Smrg 777a5ec427Smrg# If no dependency file was actually created by the compiler invocation, 787a5ec427Smrg# we still have to create a dummy depfile, to avoid errors with the 797a5ec427Smrg# Makefile "include basename.Plo" scheme. 807a5ec427Smrgmake_dummy_depfile () 817a5ec427Smrg{ 827a5ec427Smrg echo "#dummy" > "$depfile" 837a5ec427Smrg} 847a5ec427Smrg 857a5ec427Smrg# Factor out some common post-processing of the generated depfile. 867a5ec427Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 877a5ec427Smrgaix_post_process_depfile () 887a5ec427Smrg{ 897a5ec427Smrg # If the compiler actually managed to produce a dependency file, 907a5ec427Smrg # post-process it. 917a5ec427Smrg if test -f "$tmpdepfile"; then 927a5ec427Smrg # Each line is of the form 'foo.o: dependency.h'. 937a5ec427Smrg # Do two passes, one to just change these to 947a5ec427Smrg # $object: dependency.h 957a5ec427Smrg # and one to simply output 967a5ec427Smrg # dependency.h: 977a5ec427Smrg # which is needed to avoid the deleted-header problem. 987a5ec427Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 997a5ec427Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1007a5ec427Smrg } > "$depfile" 1017a5ec427Smrg rm -f "$tmpdepfile" 1027a5ec427Smrg else 1037a5ec427Smrg make_dummy_depfile 1047a5ec427Smrg fi 1057a5ec427Smrg} 1067a5ec427Smrg 1077a5ec427Smrg# A tabulation character. 1087a5ec427Smrgtab=' ' 1097a5ec427Smrg# A newline character. 1107a5ec427Smrgnl=' 1117a5ec427Smrg' 1127a5ec427Smrg# Character ranges might be problematic outside the C locale. 1137a5ec427Smrg# These definitions help. 1147a5ec427Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1157a5ec427Smrglower=abcdefghijklmnopqrstuvwxyz 1167a5ec427Smrgdigits=0123456789 1177a5ec427Smrgalpha=${upper}${lower} 1187a5ec427Smrg 119c06b6b69Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120c06b6b69Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121c06b6b69Smrg exit 1 122c06b6b69Smrgfi 123c06b6b69Smrg 124c06b6b69Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125c06b6b69Smrgdepfile=${depfile-`echo "$object" | 126c06b6b69Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127c06b6b69Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128c06b6b69Smrg 129c06b6b69Smrgrm -f "$tmpdepfile" 130c06b6b69Smrg 1317a5ec427Smrg# Avoid interferences from the environment. 1327a5ec427Smrggccflag= dashmflag= 1337a5ec427Smrg 134c06b6b69Smrg# Some modes work just like other modes, but use different flags. We 135c06b6b69Smrg# parameterize here, but still list the modes in the big case below, 136c06b6b69Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137c06b6b69Smrg# here, because this file can only contain one case statement. 138c06b6b69Smrgif test "$depmode" = hp; then 139c06b6b69Smrg # HP compiler uses -M and no extra arg. 140c06b6b69Smrg gccflag=-M 141c06b6b69Smrg depmode=gcc 142c06b6b69Smrgfi 143c06b6b69Smrg 144c06b6b69Smrgif test "$depmode" = dashXmstdout; then 1457a5ec427Smrg # This is just like dashmstdout with a different argument. 1467a5ec427Smrg dashmflag=-xM 1477a5ec427Smrg depmode=dashmstdout 148c06b6b69Smrgfi 149c06b6b69Smrg 1507d17d341Smrgcygpath_u="cygpath -u -f -" 1517d17d341Smrgif test "$depmode" = msvcmsys; then 1527a5ec427Smrg # This is just like msvisualcpp but w/o cygpath translation. 1537a5ec427Smrg # Just convert the backslash-escaped backslashes to single forward 1547a5ec427Smrg # slashes to satisfy depend.m4 1557a5ec427Smrg cygpath_u='sed s,\\\\,/,g' 1567a5ec427Smrg depmode=msvisualcpp 1577d17d341Smrgfi 1587d17d341Smrg 159a1d73b4bSmrgif test "$depmode" = msvc7msys; then 1607a5ec427Smrg # This is just like msvc7 but w/o cygpath translation. 1617a5ec427Smrg # Just convert the backslash-escaped backslashes to single forward 1627a5ec427Smrg # slashes to satisfy depend.m4 1637a5ec427Smrg cygpath_u='sed s,\\\\,/,g' 1647a5ec427Smrg depmode=msvc7 1657a5ec427Smrgfi 1667a5ec427Smrg 1677a5ec427Smrgif test "$depmode" = xlc; then 1687a5ec427Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1697a5ec427Smrg gccflag=-qmakedep=gcc,-MF 1707a5ec427Smrg depmode=gcc 171a1d73b4bSmrgfi 172a1d73b4bSmrg 173c06b6b69Smrgcase "$depmode" in 174c06b6b69Smrggcc3) 175c06b6b69Smrg## gcc 3 implements dependency tracking that does exactly what 176c06b6b69Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177c06b6b69Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1789f4658d1Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1799f4658d1Smrg## the command line argument order; so add the flags where they 1809f4658d1Smrg## appear in depend2.am. Note that the slowdown incurred here 1819f4658d1Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1829f4658d1Smrg for arg 1839f4658d1Smrg do 1849f4658d1Smrg case $arg in 1859f4658d1Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1869f4658d1Smrg *) set fnord "$@" "$arg" ;; 1879f4658d1Smrg esac 1889f4658d1Smrg shift # fnord 1899f4658d1Smrg shift # $arg 1909f4658d1Smrg done 1919f4658d1Smrg "$@" 192c06b6b69Smrg stat=$? 1937a5ec427Smrg if test $stat -ne 0; then 194c06b6b69Smrg rm -f "$tmpdepfile" 195c06b6b69Smrg exit $stat 196c06b6b69Smrg fi 197c06b6b69Smrg mv "$tmpdepfile" "$depfile" 198c06b6b69Smrg ;; 199c06b6b69Smrg 200c06b6b69Smrggcc) 2017a5ec427Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 2027a5ec427Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 2037a5ec427Smrg## (see the conditional assignment to $gccflag above). 204c06b6b69Smrg## There are various ways to get dependency output from gcc. Here's 205c06b6b69Smrg## why we pick this rather obscure method: 206c06b6b69Smrg## - Don't want to use -MD because we'd like the dependencies to end 207c06b6b69Smrg## up in a subdir. Having to rename by hand is ugly. 208c06b6b69Smrg## (We might end up doing this anyway to support other compilers.) 209c06b6b69Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2107a5ec427Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2117a5ec427Smrg## supported by the other compilers which use the 'gcc' depmode. 212c06b6b69Smrg## - Using -M directly means running the compiler twice (even worse 213c06b6b69Smrg## than renaming). 214c06b6b69Smrg if test -z "$gccflag"; then 215c06b6b69Smrg gccflag=-MD, 216c06b6b69Smrg fi 217c06b6b69Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218c06b6b69Smrg stat=$? 2197a5ec427Smrg if test $stat -ne 0; then 220c06b6b69Smrg rm -f "$tmpdepfile" 221c06b6b69Smrg exit $stat 222c06b6b69Smrg fi 223c06b6b69Smrg rm -f "$depfile" 224c06b6b69Smrg echo "$object : \\" > "$depfile" 2257a5ec427Smrg # The second -e expression handles DOS-style file names with drive 2267a5ec427Smrg # letters. 227c06b6b69Smrg sed -e 's/^[^:]*: / /' \ 228c06b6b69Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2297a5ec427Smrg## This next piece of magic avoids the "deleted header file" problem. 230c06b6b69Smrg## The problem is that when a header file which appears in a .P file 231c06b6b69Smrg## is deleted, the dependency causes make to die (because there is 232c06b6b69Smrg## typically no way to rebuild the header). We avoid this by adding 233c06b6b69Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234c06b6b69Smrg## this for us directly. 2357a5ec427Smrg## Some versions of gcc put a space before the ':'. On the theory 236c06b6b69Smrg## that the space means something, we add a space to the output as 237a1d73b4bSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 238a1d73b4bSmrg## to the object. Take care to not repeat it in the output. 239c06b6b69Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240c06b6b69Smrg## correctly. Breaking it into two sed invocations is a workaround. 2417a5ec427Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2427a5ec427Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2437a5ec427Smrg | sed -e 's/$/ :/' >> "$depfile" 244c06b6b69Smrg rm -f "$tmpdepfile" 245c06b6b69Smrg ;; 246c06b6b69Smrg 247c06b6b69Smrghp) 248c06b6b69Smrg # This case exists only to let depend.m4 do its work. It works by 249c06b6b69Smrg # looking at the text of this script. This case will never be run, 250c06b6b69Smrg # since it is checked for above. 251c06b6b69Smrg exit 1 252c06b6b69Smrg ;; 253c06b6b69Smrg 254c06b6b69Smrgsgi) 255c06b6b69Smrg if test "$libtool" = yes; then 256c06b6b69Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257c06b6b69Smrg else 258c06b6b69Smrg "$@" -MDupdate "$tmpdepfile" 259c06b6b69Smrg fi 260c06b6b69Smrg stat=$? 2617a5ec427Smrg if test $stat -ne 0; then 262c06b6b69Smrg rm -f "$tmpdepfile" 263c06b6b69Smrg exit $stat 264c06b6b69Smrg fi 265c06b6b69Smrg rm -f "$depfile" 266c06b6b69Smrg 267c06b6b69Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268c06b6b69Smrg echo "$object : \\" > "$depfile" 269c06b6b69Smrg # Clip off the initial element (the dependent). Don't try to be 270c06b6b69Smrg # clever and replace this with sed code, as IRIX sed won't handle 271c06b6b69Smrg # lines with more than a fixed number of characters (4096 in 272c06b6b69Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2737a5ec427Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274c06b6b69Smrg # dependency line. 2757a5ec427Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2767a5ec427Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2777a5ec427Smrg | tr "$nl" ' ' >> "$depfile" 2787d17d341Smrg echo >> "$depfile" 279c06b6b69Smrg # The second pass generates a dummy entry for each header file. 2807a5ec427Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2817a5ec427Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2827a5ec427Smrg >> "$depfile" 283c06b6b69Smrg else 2847a5ec427Smrg make_dummy_depfile 285c06b6b69Smrg fi 286c06b6b69Smrg rm -f "$tmpdepfile" 287c06b6b69Smrg ;; 288c06b6b69Smrg 2897a5ec427Smrgxlc) 2907a5ec427Smrg # This case exists only to let depend.m4 do its work. It works by 2917a5ec427Smrg # looking at the text of this script. This case will never be run, 2927a5ec427Smrg # since it is checked for above. 2937a5ec427Smrg exit 1 2947a5ec427Smrg ;; 2957a5ec427Smrg 296c06b6b69Smrgaix) 297c06b6b69Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298c06b6b69Smrg # in a .u file. In older versions, this file always lives in the 2997a5ec427Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300c06b6b69Smrg # start of each line; $object doesn't have directory information. 301c06b6b69Smrg # Version 6 uses the directory in both cases. 3027a5ec427Smrg set_dir_from "$object" 3037a5ec427Smrg set_base_from "$object" 304c06b6b69Smrg if test "$libtool" = yes; then 3059f4658d1Smrg tmpdepfile1=$dir$base.u 3069f4658d1Smrg tmpdepfile2=$base.u 3079f4658d1Smrg tmpdepfile3=$dir.libs/$base.u 308c06b6b69Smrg "$@" -Wc,-M 309c06b6b69Smrg else 3109f4658d1Smrg tmpdepfile1=$dir$base.u 3119f4658d1Smrg tmpdepfile2=$dir$base.u 3129f4658d1Smrg tmpdepfile3=$dir$base.u 313c06b6b69Smrg "$@" -M 314c06b6b69Smrg fi 315c06b6b69Smrg stat=$? 3167a5ec427Smrg if test $stat -ne 0; then 3179f4658d1Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318c06b6b69Smrg exit $stat 319c06b6b69Smrg fi 320c06b6b69Smrg 3219f4658d1Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3229f4658d1Smrg do 3239f4658d1Smrg test -f "$tmpdepfile" && break 3249f4658d1Smrg done 3257a5ec427Smrg aix_post_process_depfile 3267a5ec427Smrg ;; 3277a5ec427Smrg 3287a5ec427Smrgtcc) 3297a5ec427Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3307a5ec427Smrg # FIXME: That version still under development at the moment of writing. 3317a5ec427Smrg # Make that this statement remains true also for stable, released 3327a5ec427Smrg # versions. 3337a5ec427Smrg # It will wrap lines (doesn't matter whether long or short) with a 3347a5ec427Smrg # trailing '\', as in: 3357a5ec427Smrg # 3367a5ec427Smrg # foo.o : \ 3377a5ec427Smrg # foo.c \ 3387a5ec427Smrg # foo.h \ 3397a5ec427Smrg # 3407a5ec427Smrg # It will put a trailing '\' even on the last line, and will use leading 3417a5ec427Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3427a5ec427Smrg # "Emit spaces for -MD"). 3437a5ec427Smrg "$@" -MD -MF "$tmpdepfile" 3447a5ec427Smrg stat=$? 3457a5ec427Smrg if test $stat -ne 0; then 3467a5ec427Smrg rm -f "$tmpdepfile" 3477a5ec427Smrg exit $stat 348c06b6b69Smrg fi 3497a5ec427Smrg rm -f "$depfile" 3507a5ec427Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3517a5ec427Smrg # We have to change lines of the first kind to '$object: \'. 3527a5ec427Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3537a5ec427Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3547a5ec427Smrg # dummy dependency, to avoid the deleted-header problem. 3557a5ec427Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356c06b6b69Smrg rm -f "$tmpdepfile" 357c06b6b69Smrg ;; 358c06b6b69Smrg 3597a5ec427Smrg## The order of this option in the case statement is important, since the 3607a5ec427Smrg## shell code in configure will try each of these formats in the order 3617a5ec427Smrg## listed in this file. A plain '-MD' option would be understood by many 3627a5ec427Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3637a5ec427Smrgpgcc) 3647a5ec427Smrg # Portland's C compiler understands '-MD'. 3657a5ec427Smrg # Will always output deps to 'file.d' where file is the root name of the 3667a5ec427Smrg # source file under compilation, even if file resides in a subdirectory. 3677a5ec427Smrg # The object file name does not affect the name of the '.d' file. 3687a5ec427Smrg # pgcc 10.2 will output 369c06b6b69Smrg # foo.o: sub/foo.c sub/foo.h 3707a5ec427Smrg # and will wrap long lines using '\' : 371c06b6b69Smrg # foo.o: sub/foo.c ... \ 372c06b6b69Smrg # sub/foo.h ... \ 373c06b6b69Smrg # ... 3747a5ec427Smrg set_dir_from "$object" 3757a5ec427Smrg # Use the source, not the object, to determine the base name, since 3767a5ec427Smrg # that's sadly what pgcc will do too. 3777a5ec427Smrg set_base_from "$source" 3787a5ec427Smrg tmpdepfile=$base.d 3797a5ec427Smrg 3807a5ec427Smrg # For projects that build the same source file twice into different object 3817a5ec427Smrg # files, the pgcc approach of using the *source* file root name can cause 3827a5ec427Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3837a5ec427Smrg # the same $tmpdepfile. 3847a5ec427Smrg lockdir=$base.d-lock 3857a5ec427Smrg trap " 3867a5ec427Smrg echo '$0: caught signal, cleaning up...' >&2 3877a5ec427Smrg rmdir '$lockdir' 3887a5ec427Smrg exit 1 3897a5ec427Smrg " 1 2 13 15 3907a5ec427Smrg numtries=100 3917a5ec427Smrg i=$numtries 3927a5ec427Smrg while test $i -gt 0; do 3937a5ec427Smrg # mkdir is a portable test-and-set. 3947a5ec427Smrg if mkdir "$lockdir" 2>/dev/null; then 3957a5ec427Smrg # This process acquired the lock. 3967a5ec427Smrg "$@" -MD 3977a5ec427Smrg stat=$? 3987a5ec427Smrg # Release the lock. 3997a5ec427Smrg rmdir "$lockdir" 4007a5ec427Smrg break 4017a5ec427Smrg else 4027a5ec427Smrg # If the lock is being held by a different process, wait 4037a5ec427Smrg # until the winning process is done or we timeout. 4047a5ec427Smrg while test -d "$lockdir" && test $i -gt 0; do 4057a5ec427Smrg sleep 1 4067a5ec427Smrg i=`expr $i - 1` 4077a5ec427Smrg done 4087a5ec427Smrg fi 4097a5ec427Smrg i=`expr $i - 1` 4107a5ec427Smrg done 4117a5ec427Smrg trap - 1 2 13 15 4127a5ec427Smrg if test $i -le 0; then 4137a5ec427Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4147a5ec427Smrg echo "$0: check lockdir '$lockdir'" >&2 4157a5ec427Smrg exit 1 4167a5ec427Smrg fi 417c06b6b69Smrg 4187a5ec427Smrg if test $stat -ne 0; then 419c06b6b69Smrg rm -f "$tmpdepfile" 420c06b6b69Smrg exit $stat 421c06b6b69Smrg fi 422c06b6b69Smrg rm -f "$depfile" 423c06b6b69Smrg # Each line is of the form `foo.o: dependent.h', 424c06b6b69Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425c06b6b69Smrg # Do two passes, one to just change these to 426c06b6b69Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 427c06b6b69Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428c06b6b69Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 429c06b6b69Smrg # correctly. Breaking it into two sed invocations is a workaround. 4307a5ec427Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4317a5ec427Smrg | sed -e 's/$/ :/' >> "$depfile" 432c06b6b69Smrg rm -f "$tmpdepfile" 433c06b6b69Smrg ;; 434c06b6b69Smrg 4359f4658d1Smrghp2) 4369f4658d1Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4379f4658d1Smrg # compilers, which have integrated preprocessors. The correct option 4389f4658d1Smrg # to use with these is +Maked; it writes dependencies to a file named 4399f4658d1Smrg # 'foo.d', which lands next to the object file, wherever that 4409f4658d1Smrg # happens to be. 4419f4658d1Smrg # Much of this is similar to the tru64 case; see comments there. 4427a5ec427Smrg set_dir_from "$object" 4437a5ec427Smrg set_base_from "$object" 4449f4658d1Smrg if test "$libtool" = yes; then 4459f4658d1Smrg tmpdepfile1=$dir$base.d 4469f4658d1Smrg tmpdepfile2=$dir.libs/$base.d 4479f4658d1Smrg "$@" -Wc,+Maked 4489f4658d1Smrg else 4499f4658d1Smrg tmpdepfile1=$dir$base.d 4509f4658d1Smrg tmpdepfile2=$dir$base.d 4519f4658d1Smrg "$@" +Maked 4529f4658d1Smrg fi 4539f4658d1Smrg stat=$? 4547a5ec427Smrg if test $stat -ne 0; then 4559f4658d1Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4569f4658d1Smrg exit $stat 4579f4658d1Smrg fi 4589f4658d1Smrg 4599f4658d1Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4609f4658d1Smrg do 4619f4658d1Smrg test -f "$tmpdepfile" && break 4629f4658d1Smrg done 4639f4658d1Smrg if test -f "$tmpdepfile"; then 4647a5ec427Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4657a5ec427Smrg # Add 'dependent.h:' lines. 4667d17d341Smrg sed -ne '2,${ 4677a5ec427Smrg s/^ *// 4687a5ec427Smrg s/ \\*$// 4697a5ec427Smrg s/$/:/ 4707a5ec427Smrg p 4717a5ec427Smrg }' "$tmpdepfile" >> "$depfile" 4729f4658d1Smrg else 4737a5ec427Smrg make_dummy_depfile 4749f4658d1Smrg fi 4759f4658d1Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4769f4658d1Smrg ;; 4779f4658d1Smrg 478c06b6b69Smrgtru64) 4797a5ec427Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4807a5ec427Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4817a5ec427Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4827a5ec427Smrg # dependencies in 'foo.d' instead, so we check for that too. 4837a5ec427Smrg # Subdirectories are respected. 4847a5ec427Smrg set_dir_from "$object" 4857a5ec427Smrg set_base_from "$object" 4867a5ec427Smrg 4877a5ec427Smrg if test "$libtool" = yes; then 4887a5ec427Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4897a5ec427Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4907a5ec427Smrg # in $dir$base.o.d. We have to check for both files, because 4917a5ec427Smrg # one of the two compilations can be disabled. We should prefer 4927a5ec427Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4937a5ec427Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4947a5ec427Smrg # the former would cause a distcleancheck panic. 4957a5ec427Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4967a5ec427Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4977a5ec427Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4987a5ec427Smrg "$@" -Wc,-MD 4997a5ec427Smrg else 5007a5ec427Smrg tmpdepfile1=$dir$base.d 5017a5ec427Smrg tmpdepfile2=$dir$base.d 5027a5ec427Smrg tmpdepfile3=$dir$base.d 5037a5ec427Smrg "$@" -MD 5047a5ec427Smrg fi 5057a5ec427Smrg 5067a5ec427Smrg stat=$? 5077a5ec427Smrg if test $stat -ne 0; then 5087a5ec427Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5097a5ec427Smrg exit $stat 5107a5ec427Smrg fi 5117a5ec427Smrg 5127a5ec427Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5137a5ec427Smrg do 5147a5ec427Smrg test -f "$tmpdepfile" && break 5157a5ec427Smrg done 5167a5ec427Smrg # Same post-processing that is required for AIX mode. 5177a5ec427Smrg aix_post_process_depfile 5187a5ec427Smrg ;; 519c06b6b69Smrg 520a1d73b4bSmrgmsvc7) 521a1d73b4bSmrg if test "$libtool" = yes; then 522a1d73b4bSmrg showIncludes=-Wc,-showIncludes 523a1d73b4bSmrg else 524a1d73b4bSmrg showIncludes=-showIncludes 525a1d73b4bSmrg fi 526a1d73b4bSmrg "$@" $showIncludes > "$tmpdepfile" 527a1d73b4bSmrg stat=$? 528a1d73b4bSmrg grep -v '^Note: including file: ' "$tmpdepfile" 5297a5ec427Smrg if test $stat -ne 0; then 530a1d73b4bSmrg rm -f "$tmpdepfile" 531a1d73b4bSmrg exit $stat 532a1d73b4bSmrg fi 533a1d73b4bSmrg rm -f "$depfile" 534a1d73b4bSmrg echo "$object : \\" > "$depfile" 535a1d73b4bSmrg # The first sed program below extracts the file names and escapes 536a1d73b4bSmrg # backslashes for cygpath. The second sed program outputs the file 537a1d73b4bSmrg # name when reading, but also accumulates all include files in the 538a1d73b4bSmrg # hold buffer in order to output them again at the end. This only 539a1d73b4bSmrg # works with sed implementations that can handle large buffers. 540a1d73b4bSmrg sed < "$tmpdepfile" -n ' 541a1d73b4bSmrg/^Note: including file: *\(.*\)/ { 542a1d73b4bSmrg s//\1/ 543a1d73b4bSmrg s/\\/\\\\/g 544a1d73b4bSmrg p 545a1d73b4bSmrg}' | $cygpath_u | sort -u | sed -n ' 546a1d73b4bSmrgs/ /\\ /g 5477a5ec427Smrgs/\(.*\)/'"$tab"'\1 \\/p 548a1d73b4bSmrgs/.\(.*\) \\/\1:/ 549a1d73b4bSmrgH 550a1d73b4bSmrg$ { 5517a5ec427Smrg s/.*/'"$tab"'/ 552a1d73b4bSmrg G 553a1d73b4bSmrg p 554a1d73b4bSmrg}' >> "$depfile" 5557a5ec427Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556a1d73b4bSmrg rm -f "$tmpdepfile" 557a1d73b4bSmrg ;; 558a1d73b4bSmrg 559a1d73b4bSmrgmsvc7msys) 560a1d73b4bSmrg # This case exists only to let depend.m4 do its work. It works by 561a1d73b4bSmrg # looking at the text of this script. This case will never be run, 562a1d73b4bSmrg # since it is checked for above. 563a1d73b4bSmrg exit 1 564a1d73b4bSmrg ;; 565a1d73b4bSmrg 566c06b6b69Smrg#nosideeffect) 567c06b6b69Smrg # This comment above is used by automake to tell side-effect 568c06b6b69Smrg # dependency tracking mechanisms from slower ones. 569c06b6b69Smrg 570c06b6b69Smrgdashmstdout) 571c06b6b69Smrg # Important note: in order to support this mode, a compiler *must* 572c06b6b69Smrg # always write the preprocessed file to stdout, regardless of -o. 573c06b6b69Smrg "$@" || exit $? 574c06b6b69Smrg 575c06b6b69Smrg # Remove the call to Libtool. 576c06b6b69Smrg if test "$libtool" = yes; then 5777d17d341Smrg while test "X$1" != 'X--mode=compile'; do 578c06b6b69Smrg shift 579c06b6b69Smrg done 580c06b6b69Smrg shift 581c06b6b69Smrg fi 582c06b6b69Smrg 5837a5ec427Smrg # Remove '-o $object'. 584c06b6b69Smrg IFS=" " 585c06b6b69Smrg for arg 586c06b6b69Smrg do 587c06b6b69Smrg case $arg in 588c06b6b69Smrg -o) 589c06b6b69Smrg shift 590c06b6b69Smrg ;; 591c06b6b69Smrg $object) 592c06b6b69Smrg shift 593c06b6b69Smrg ;; 594c06b6b69Smrg *) 595c06b6b69Smrg set fnord "$@" "$arg" 596c06b6b69Smrg shift # fnord 597c06b6b69Smrg shift # $arg 598c06b6b69Smrg ;; 599c06b6b69Smrg esac 600c06b6b69Smrg done 601c06b6b69Smrg 602c06b6b69Smrg test -z "$dashmflag" && dashmflag=-M 6037a5ec427Smrg # Require at least two characters before searching for ':' 604c06b6b69Smrg # in the target name. This is to cope with DOS-style filenames: 6057a5ec427Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606c06b6b69Smrg "$@" $dashmflag | 6077a5ec427Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608c06b6b69Smrg rm -f "$depfile" 609c06b6b69Smrg cat < "$tmpdepfile" > "$depfile" 6107a5ec427Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6117a5ec427Smrg # correctly. Breaking it into two sed invocations is a workaround. 6127a5ec427Smrg tr ' ' "$nl" < "$tmpdepfile" \ 6137a5ec427Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6147a5ec427Smrg | sed -e 's/$/ :/' >> "$depfile" 615c06b6b69Smrg rm -f "$tmpdepfile" 616c06b6b69Smrg ;; 617c06b6b69Smrg 618c06b6b69SmrgdashXmstdout) 619c06b6b69Smrg # This case only exists to satisfy depend.m4. It is never actually 620c06b6b69Smrg # run, as this mode is specially recognized in the preamble. 621c06b6b69Smrg exit 1 622c06b6b69Smrg ;; 623c06b6b69Smrg 624c06b6b69Smrgmakedepend) 625c06b6b69Smrg "$@" || exit $? 626c06b6b69Smrg # Remove any Libtool call 627c06b6b69Smrg if test "$libtool" = yes; then 6287d17d341Smrg while test "X$1" != 'X--mode=compile'; do 629c06b6b69Smrg shift 630c06b6b69Smrg done 631c06b6b69Smrg shift 632c06b6b69Smrg fi 633c06b6b69Smrg # X makedepend 634c06b6b69Smrg shift 6357d17d341Smrg cleared=no eat=no 6367d17d341Smrg for arg 6377d17d341Smrg do 638c06b6b69Smrg case $cleared in 639c06b6b69Smrg no) 640c06b6b69Smrg set ""; shift 641c06b6b69Smrg cleared=yes ;; 642c06b6b69Smrg esac 6437d17d341Smrg if test $eat = yes; then 6447d17d341Smrg eat=no 6457d17d341Smrg continue 6467d17d341Smrg fi 647c06b6b69Smrg case "$arg" in 648c06b6b69Smrg -D*|-I*) 649c06b6b69Smrg set fnord "$@" "$arg"; shift ;; 650c06b6b69Smrg # Strip any option that makedepend may not understand. Remove 651c06b6b69Smrg # the object too, otherwise makedepend will parse it as a source file. 6527d17d341Smrg -arch) 6537d17d341Smrg eat=yes ;; 654c06b6b69Smrg -*|$object) 655c06b6b69Smrg ;; 656c06b6b69Smrg *) 657c06b6b69Smrg set fnord "$@" "$arg"; shift ;; 658c06b6b69Smrg esac 659c06b6b69Smrg done 6607d17d341Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661c06b6b69Smrg touch "$tmpdepfile" 662c06b6b69Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663c06b6b69Smrg rm -f "$depfile" 664a1d73b4bSmrg # makedepend may prepend the VPATH from the source file name to the object. 665a1d73b4bSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 666a1d73b4bSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6677a5ec427Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6687a5ec427Smrg # correctly. Breaking it into two sed invocations is a workaround. 6697a5ec427Smrg sed '1,2d' "$tmpdepfile" \ 6707a5ec427Smrg | tr ' ' "$nl" \ 6717a5ec427Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6727a5ec427Smrg | sed -e 's/$/ :/' >> "$depfile" 673c06b6b69Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674c06b6b69Smrg ;; 675c06b6b69Smrg 676c06b6b69Smrgcpp) 677c06b6b69Smrg # Important note: in order to support this mode, a compiler *must* 678c06b6b69Smrg # always write the preprocessed file to stdout. 679c06b6b69Smrg "$@" || exit $? 680c06b6b69Smrg 681c06b6b69Smrg # Remove the call to Libtool. 682c06b6b69Smrg if test "$libtool" = yes; then 6837d17d341Smrg while test "X$1" != 'X--mode=compile'; do 684c06b6b69Smrg shift 685c06b6b69Smrg done 686c06b6b69Smrg shift 687c06b6b69Smrg fi 688c06b6b69Smrg 6897a5ec427Smrg # Remove '-o $object'. 690c06b6b69Smrg IFS=" " 691c06b6b69Smrg for arg 692c06b6b69Smrg do 693c06b6b69Smrg case $arg in 694c06b6b69Smrg -o) 695c06b6b69Smrg shift 696c06b6b69Smrg ;; 697c06b6b69Smrg $object) 698c06b6b69Smrg shift 699c06b6b69Smrg ;; 700c06b6b69Smrg *) 701c06b6b69Smrg set fnord "$@" "$arg" 702c06b6b69Smrg shift # fnord 703c06b6b69Smrg shift # $arg 704c06b6b69Smrg ;; 705c06b6b69Smrg esac 706c06b6b69Smrg done 707c06b6b69Smrg 7087a5ec427Smrg "$@" -E \ 7097a5ec427Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7107a5ec427Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7117a5ec427Smrg | sed '$ s: \\$::' > "$tmpdepfile" 712c06b6b69Smrg rm -f "$depfile" 713c06b6b69Smrg echo "$object : \\" > "$depfile" 714c06b6b69Smrg cat < "$tmpdepfile" >> "$depfile" 715c06b6b69Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716c06b6b69Smrg rm -f "$tmpdepfile" 717c06b6b69Smrg ;; 718c06b6b69Smrg 719c06b6b69Smrgmsvisualcpp) 720c06b6b69Smrg # Important note: in order to support this mode, a compiler *must* 7217d17d341Smrg # always write the preprocessed file to stdout. 722c06b6b69Smrg "$@" || exit $? 7237d17d341Smrg 7247d17d341Smrg # Remove the call to Libtool. 7257d17d341Smrg if test "$libtool" = yes; then 7267d17d341Smrg while test "X$1" != 'X--mode=compile'; do 7277d17d341Smrg shift 7287d17d341Smrg done 7297d17d341Smrg shift 7307d17d341Smrg fi 7317d17d341Smrg 732c06b6b69Smrg IFS=" " 733c06b6b69Smrg for arg 734c06b6b69Smrg do 735c06b6b69Smrg case "$arg" in 7367d17d341Smrg -o) 7377d17d341Smrg shift 7387d17d341Smrg ;; 7397d17d341Smrg $object) 7407d17d341Smrg shift 7417d17d341Smrg ;; 742c06b6b69Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7437a5ec427Smrg set fnord "$@" 7447a5ec427Smrg shift 7457a5ec427Smrg shift 7467a5ec427Smrg ;; 747c06b6b69Smrg *) 7487a5ec427Smrg set fnord "$@" "$arg" 7497a5ec427Smrg shift 7507a5ec427Smrg shift 7517a5ec427Smrg ;; 752c06b6b69Smrg esac 753c06b6b69Smrg done 7547d17d341Smrg "$@" -E 2>/dev/null | 7557d17d341Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756c06b6b69Smrg rm -f "$depfile" 757c06b6b69Smrg echo "$object : \\" > "$depfile" 7587a5ec427Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7597a5ec427Smrg echo "$tab" >> "$depfile" 7607d17d341Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761c06b6b69Smrg rm -f "$tmpdepfile" 762c06b6b69Smrg ;; 763c06b6b69Smrg 7647d17d341Smrgmsvcmsys) 7657d17d341Smrg # This case exists only to let depend.m4 do its work. It works by 7667d17d341Smrg # looking at the text of this script. This case will never be run, 7677d17d341Smrg # since it is checked for above. 7687d17d341Smrg exit 1 7697d17d341Smrg ;; 7707d17d341Smrg 771c06b6b69Smrgnone) 772c06b6b69Smrg exec "$@" 773c06b6b69Smrg ;; 774c06b6b69Smrg 775c06b6b69Smrg*) 776c06b6b69Smrg echo "Unknown depmode $depmode" 1>&2 777c06b6b69Smrg exit 1 778c06b6b69Smrg ;; 779c06b6b69Smrgesac 780c06b6b69Smrg 781c06b6b69Smrgexit 0 782c06b6b69Smrg 783c06b6b69Smrg# Local Variables: 784c06b6b69Smrg# mode: shell-script 785c06b6b69Smrg# sh-indentation: 2 78644256261Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 787c06b6b69Smrg# time-stamp-start: "scriptversion=" 788c06b6b69Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 78944256261Smrg# time-stamp-time-zone: "UTC0" 7907d17d341Smrg# time-stamp-end: "; # UTC" 791c06b6b69Smrg# End: 792