10ed7c580Smrg#! /bin/sh 20ed7c580Smrg# depcomp - compile a program generating dependencies as side-effects 30ed7c580Smrg 4a0cd246fSmrgscriptversion=2024-06-19.01; # UTC 50ed7c580Smrg 6a0cd246fSmrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 70ed7c580Smrg 80ed7c580Smrg# This program is free software; you can redistribute it and/or modify 90ed7c580Smrg# it under the terms of the GNU General Public License as published by 100ed7c580Smrg# the Free Software Foundation; either version 2, or (at your option) 110ed7c580Smrg# any later version. 120ed7c580Smrg 130ed7c580Smrg# This program is distributed in the hope that it will be useful, 140ed7c580Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 150ed7c580Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 160ed7c580Smrg# GNU General Public License for more details. 170ed7c580Smrg 180ed7c580Smrg# You should have received a copy of the GNU General Public License 191a28b98bSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 200ed7c580Smrg 210ed7c580Smrg# As a special exception to the GNU General Public License, if you 220ed7c580Smrg# distribute this file as part of a program that contains a 230ed7c580Smrg# configuration script generated by Autoconf, you may include it under 240ed7c580Smrg# the same distribution terms that you use for the rest of that program. 250ed7c580Smrg 260ed7c580Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 270ed7c580Smrg 280ed7c580Smrgcase $1 in 290ed7c580Smrg '') 300ed7c580Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 310ed7c580Smrg exit 1; 320ed7c580Smrg ;; 330ed7c580Smrg -h | --h*) 340ed7c580Smrg cat <<\EOF 350ed7c580SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 360ed7c580Smrg 370ed7c580SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 380ed7c580Smrgas side-effects. 390ed7c580Smrg 400ed7c580SmrgEnvironment variables: 410ed7c580Smrg depmode Dependency tracking mode. 420ed7c580Smrg source Source file read by 'PROGRAMS ARGS'. 430ed7c580Smrg object Object file output by 'PROGRAMS ARGS'. 440ed7c580Smrg DEPDIR directory where to store dependencies. 450ed7c580Smrg depfile Dependency file to output. 460ed7c580Smrg tmpdepfile Temporary file to use when outputting dependencies. 470ed7c580Smrg libtool Whether libtool is used (yes/no). 480ed7c580Smrg 490ed7c580SmrgReport bugs to <bug-automake@gnu.org>. 50a0cd246fSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 51a0cd246fSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 520ed7c580SmrgEOF 530ed7c580Smrg exit $? 540ed7c580Smrg ;; 550ed7c580Smrg -v | --v*) 56a0cd246fSmrg echo "depcomp (GNU Automake) $scriptversion" 570ed7c580Smrg exit $? 580ed7c580Smrg ;; 590ed7c580Smrgesac 600ed7c580Smrg 610ed7c580Smrg# Get the directory component of the given path, and save it in the 620ed7c580Smrg# global variables '$dir'. Note that this directory component will 630ed7c580Smrg# be either empty or ending with a '/' character. This is deliberate. 640ed7c580Smrgset_dir_from () 650ed7c580Smrg{ 660ed7c580Smrg case $1 in 670ed7c580Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 680ed7c580Smrg *) dir=;; 690ed7c580Smrg esac 700ed7c580Smrg} 710ed7c580Smrg 720ed7c580Smrg# Get the suffix-stripped basename of the given path, and save it the 730ed7c580Smrg# global variable '$base'. 740ed7c580Smrgset_base_from () 750ed7c580Smrg{ 760ed7c580Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 770ed7c580Smrg} 780ed7c580Smrg 790ed7c580Smrg# If no dependency file was actually created by the compiler invocation, 800ed7c580Smrg# we still have to create a dummy depfile, to avoid errors with the 810ed7c580Smrg# Makefile "include basename.Plo" scheme. 820ed7c580Smrgmake_dummy_depfile () 830ed7c580Smrg{ 840ed7c580Smrg echo "#dummy" > "$depfile" 850ed7c580Smrg} 860ed7c580Smrg 870ed7c580Smrg# Factor out some common post-processing of the generated depfile. 880ed7c580Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 890ed7c580Smrgaix_post_process_depfile () 900ed7c580Smrg{ 910ed7c580Smrg # If the compiler actually managed to produce a dependency file, 920ed7c580Smrg # post-process it. 930ed7c580Smrg if test -f "$tmpdepfile"; then 940ed7c580Smrg # Each line is of the form 'foo.o: dependency.h'. 950ed7c580Smrg # Do two passes, one to just change these to 960ed7c580Smrg # $object: dependency.h 970ed7c580Smrg # and one to simply output 980ed7c580Smrg # dependency.h: 990ed7c580Smrg # which is needed to avoid the deleted-header problem. 1000ed7c580Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 1010ed7c580Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 1020ed7c580Smrg } > "$depfile" 1030ed7c580Smrg rm -f "$tmpdepfile" 1040ed7c580Smrg else 1050ed7c580Smrg make_dummy_depfile 1060ed7c580Smrg fi 1070ed7c580Smrg} 1080ed7c580Smrg 1090ed7c580Smrg# A tabulation character. 1100ed7c580Smrgtab=' ' 1110ed7c580Smrg# A newline character. 1120ed7c580Smrgnl=' 1130ed7c580Smrg' 1140ed7c580Smrg# Character ranges might be problematic outside the C locale. 1150ed7c580Smrg# These definitions help. 1160ed7c580Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 1170ed7c580Smrglower=abcdefghijklmnopqrstuvwxyz 1180ed7c580Smrgalpha=${upper}${lower} 1190ed7c580Smrg 1200ed7c580Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 1210ed7c580Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 1220ed7c580Smrg exit 1 1230ed7c580Smrgfi 1240ed7c580Smrg 1250ed7c580Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1260ed7c580Smrgdepfile=${depfile-`echo "$object" | 1270ed7c580Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 1280ed7c580Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 1290ed7c580Smrg 1300ed7c580Smrgrm -f "$tmpdepfile" 1310ed7c580Smrg 132a0cd246fSmrg# Avoid interference from the environment. 1330ed7c580Smrggccflag= dashmflag= 1340ed7c580Smrg 1350ed7c580Smrg# Some modes work just like other modes, but use different flags. We 1360ed7c580Smrg# parameterize here, but still list the modes in the big case below, 1370ed7c580Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 1380ed7c580Smrg# here, because this file can only contain one case statement. 1390ed7c580Smrgif test "$depmode" = hp; then 1400ed7c580Smrg # HP compiler uses -M and no extra arg. 1410ed7c580Smrg gccflag=-M 1420ed7c580Smrg depmode=gcc 1430ed7c580Smrgfi 1440ed7c580Smrg 1450ed7c580Smrgif test "$depmode" = dashXmstdout; then 1460ed7c580Smrg # This is just like dashmstdout with a different argument. 1470ed7c580Smrg dashmflag=-xM 1480ed7c580Smrg depmode=dashmstdout 1490ed7c580Smrgfi 1500ed7c580Smrg 1510ed7c580Smrgcygpath_u="cygpath -u -f -" 1520ed7c580Smrgif test "$depmode" = msvcmsys; then 1530ed7c580Smrg # This is just like msvisualcpp but w/o cygpath translation. 1540ed7c580Smrg # Just convert the backslash-escaped backslashes to single forward 1550ed7c580Smrg # slashes to satisfy depend.m4 1560ed7c580Smrg cygpath_u='sed s,\\\\,/,g' 1570ed7c580Smrg depmode=msvisualcpp 1580ed7c580Smrgfi 1590ed7c580Smrg 1600ed7c580Smrgif test "$depmode" = msvc7msys; then 1610ed7c580Smrg # This is just like msvc7 but w/o cygpath translation. 1620ed7c580Smrg # Just convert the backslash-escaped backslashes to single forward 1630ed7c580Smrg # slashes to satisfy depend.m4 1640ed7c580Smrg cygpath_u='sed s,\\\\,/,g' 1650ed7c580Smrg depmode=msvc7 1660ed7c580Smrgfi 1670ed7c580Smrg 1680ed7c580Smrgif test "$depmode" = xlc; then 1690ed7c580Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 1700ed7c580Smrg gccflag=-qmakedep=gcc,-MF 1710ed7c580Smrg depmode=gcc 1720ed7c580Smrgfi 1730ed7c580Smrg 1740ed7c580Smrgcase "$depmode" in 1750ed7c580Smrggcc3) 1760ed7c580Smrg## gcc 3 implements dependency tracking that does exactly what 1770ed7c580Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 1780ed7c580Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1790ed7c580Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1800ed7c580Smrg## the command line argument order; so add the flags where they 1810ed7c580Smrg## appear in depend2.am. Note that the slowdown incurred here 1820ed7c580Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1830ed7c580Smrg for arg 1840ed7c580Smrg do 1850ed7c580Smrg case $arg in 1860ed7c580Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1870ed7c580Smrg *) set fnord "$@" "$arg" ;; 1880ed7c580Smrg esac 1890ed7c580Smrg shift # fnord 1900ed7c580Smrg shift # $arg 1910ed7c580Smrg done 1920ed7c580Smrg "$@" 1930ed7c580Smrg stat=$? 1940ed7c580Smrg if test $stat -ne 0; then 1950ed7c580Smrg rm -f "$tmpdepfile" 1960ed7c580Smrg exit $stat 1970ed7c580Smrg fi 1980ed7c580Smrg mv "$tmpdepfile" "$depfile" 1990ed7c580Smrg ;; 2000ed7c580Smrg 2010ed7c580Smrggcc) 202a0cd246fSmrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 203a0cd246fSmrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 2040ed7c580Smrg## (see the conditional assignment to $gccflag above). 2050ed7c580Smrg## There are various ways to get dependency output from gcc. Here's 2060ed7c580Smrg## why we pick this rather obscure method: 2070ed7c580Smrg## - Don't want to use -MD because we'd like the dependencies to end 2080ed7c580Smrg## up in a subdir. Having to rename by hand is ugly. 2090ed7c580Smrg## (We might end up doing this anyway to support other compilers.) 2100ed7c580Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 2110ed7c580Smrg## -MM, not -M (despite what the docs say). Also, it might not be 2120ed7c580Smrg## supported by the other compilers which use the 'gcc' depmode. 2130ed7c580Smrg## - Using -M directly means running the compiler twice (even worse 2140ed7c580Smrg## than renaming). 2150ed7c580Smrg if test -z "$gccflag"; then 2160ed7c580Smrg gccflag=-MD, 2170ed7c580Smrg fi 2180ed7c580Smrg "$@" -Wp,"$gccflag$tmpdepfile" 2190ed7c580Smrg stat=$? 2200ed7c580Smrg if test $stat -ne 0; then 2210ed7c580Smrg rm -f "$tmpdepfile" 2220ed7c580Smrg exit $stat 2230ed7c580Smrg fi 2240ed7c580Smrg rm -f "$depfile" 2250ed7c580Smrg echo "$object : \\" > "$depfile" 2260ed7c580Smrg # The second -e expression handles DOS-style file names with drive 2270ed7c580Smrg # letters. 2280ed7c580Smrg sed -e 's/^[^:]*: / /' \ 2290ed7c580Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 2300ed7c580Smrg## This next piece of magic avoids the "deleted header file" problem. 2310ed7c580Smrg## The problem is that when a header file which appears in a .P file 2320ed7c580Smrg## is deleted, the dependency causes make to die (because there is 2330ed7c580Smrg## typically no way to rebuild the header). We avoid this by adding 2340ed7c580Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 2350ed7c580Smrg## this for us directly. 2360ed7c580Smrg## Some versions of gcc put a space before the ':'. On the theory 2370ed7c580Smrg## that the space means something, we add a space to the output as 2380ed7c580Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 2390ed7c580Smrg## to the object. Take care to not repeat it in the output. 2400ed7c580Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 2410ed7c580Smrg## correctly. Breaking it into two sed invocations is a workaround. 2420ed7c580Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2430ed7c580Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 2440ed7c580Smrg | sed -e 's/$/ :/' >> "$depfile" 2450ed7c580Smrg rm -f "$tmpdepfile" 2460ed7c580Smrg ;; 2470ed7c580Smrg 2480ed7c580Smrghp) 2490ed7c580Smrg # This case exists only to let depend.m4 do its work. It works by 2500ed7c580Smrg # looking at the text of this script. This case will never be run, 2510ed7c580Smrg # since it is checked for above. 2520ed7c580Smrg exit 1 2530ed7c580Smrg ;; 2540ed7c580Smrg 2550ed7c580Smrgsgi) 2560ed7c580Smrg if test "$libtool" = yes; then 2570ed7c580Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 2580ed7c580Smrg else 2590ed7c580Smrg "$@" -MDupdate "$tmpdepfile" 2600ed7c580Smrg fi 2610ed7c580Smrg stat=$? 2620ed7c580Smrg if test $stat -ne 0; then 2630ed7c580Smrg rm -f "$tmpdepfile" 2640ed7c580Smrg exit $stat 2650ed7c580Smrg fi 2660ed7c580Smrg rm -f "$depfile" 2670ed7c580Smrg 2680ed7c580Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 2690ed7c580Smrg echo "$object : \\" > "$depfile" 2700ed7c580Smrg # Clip off the initial element (the dependent). Don't try to be 2710ed7c580Smrg # clever and replace this with sed code, as IRIX sed won't handle 2720ed7c580Smrg # lines with more than a fixed number of characters (4096 in 2730ed7c580Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 2740ed7c580Smrg # the IRIX cc adds comments like '#:fec' to the end of the 2750ed7c580Smrg # dependency line. 2760ed7c580Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2770ed7c580Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 2780ed7c580Smrg | tr "$nl" ' ' >> "$depfile" 2790ed7c580Smrg echo >> "$depfile" 2800ed7c580Smrg # The second pass generates a dummy entry for each header file. 2810ed7c580Smrg tr ' ' "$nl" < "$tmpdepfile" \ 2820ed7c580Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 2830ed7c580Smrg >> "$depfile" 2840ed7c580Smrg else 2850ed7c580Smrg make_dummy_depfile 2860ed7c580Smrg fi 2870ed7c580Smrg rm -f "$tmpdepfile" 2880ed7c580Smrg ;; 2890ed7c580Smrg 2900ed7c580Smrgxlc) 2910ed7c580Smrg # This case exists only to let depend.m4 do its work. It works by 2920ed7c580Smrg # looking at the text of this script. This case will never be run, 2930ed7c580Smrg # since it is checked for above. 2940ed7c580Smrg exit 1 2950ed7c580Smrg ;; 2960ed7c580Smrg 2970ed7c580Smrgaix) 2980ed7c580Smrg # The C for AIX Compiler uses -M and outputs the dependencies 2990ed7c580Smrg # in a .u file. In older versions, this file always lives in the 3000ed7c580Smrg # current directory. Also, the AIX compiler puts '$object:' at the 3010ed7c580Smrg # start of each line; $object doesn't have directory information. 3020ed7c580Smrg # Version 6 uses the directory in both cases. 3030ed7c580Smrg set_dir_from "$object" 3040ed7c580Smrg set_base_from "$object" 3050ed7c580Smrg if test "$libtool" = yes; then 3060ed7c580Smrg tmpdepfile1=$dir$base.u 3070ed7c580Smrg tmpdepfile2=$base.u 3080ed7c580Smrg tmpdepfile3=$dir.libs/$base.u 3090ed7c580Smrg "$@" -Wc,-M 3100ed7c580Smrg else 3110ed7c580Smrg tmpdepfile1=$dir$base.u 3120ed7c580Smrg tmpdepfile2=$dir$base.u 3130ed7c580Smrg tmpdepfile3=$dir$base.u 3140ed7c580Smrg "$@" -M 3150ed7c580Smrg fi 3160ed7c580Smrg stat=$? 3170ed7c580Smrg if test $stat -ne 0; then 3180ed7c580Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3190ed7c580Smrg exit $stat 3200ed7c580Smrg fi 3210ed7c580Smrg 3220ed7c580Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3230ed7c580Smrg do 3240ed7c580Smrg test -f "$tmpdepfile" && break 3250ed7c580Smrg done 3260ed7c580Smrg aix_post_process_depfile 3270ed7c580Smrg ;; 3280ed7c580Smrg 3290ed7c580Smrgtcc) 3300ed7c580Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 3310ed7c580Smrg # FIXME: That version still under development at the moment of writing. 3320ed7c580Smrg # Make that this statement remains true also for stable, released 3330ed7c580Smrg # versions. 3340ed7c580Smrg # It will wrap lines (doesn't matter whether long or short) with a 3350ed7c580Smrg # trailing '\', as in: 3360ed7c580Smrg # 3370ed7c580Smrg # foo.o : \ 3380ed7c580Smrg # foo.c \ 3390ed7c580Smrg # foo.h \ 3400ed7c580Smrg # 3410ed7c580Smrg # It will put a trailing '\' even on the last line, and will use leading 3420ed7c580Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 3430ed7c580Smrg # "Emit spaces for -MD"). 3440ed7c580Smrg "$@" -MD -MF "$tmpdepfile" 3450ed7c580Smrg stat=$? 3460ed7c580Smrg if test $stat -ne 0; then 3470ed7c580Smrg rm -f "$tmpdepfile" 3480ed7c580Smrg exit $stat 3490ed7c580Smrg fi 3500ed7c580Smrg rm -f "$depfile" 3510ed7c580Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 3520ed7c580Smrg # We have to change lines of the first kind to '$object: \'. 3530ed7c580Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 3540ed7c580Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 3550ed7c580Smrg # dummy dependency, to avoid the deleted-header problem. 3560ed7c580Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 3570ed7c580Smrg rm -f "$tmpdepfile" 3580ed7c580Smrg ;; 3590ed7c580Smrg 3600ed7c580Smrg## The order of this option in the case statement is important, since the 3610ed7c580Smrg## shell code in configure will try each of these formats in the order 3620ed7c580Smrg## listed in this file. A plain '-MD' option would be understood by many 3630ed7c580Smrg## compilers, so we must ensure this comes after the gcc and icc options. 3640ed7c580Smrgpgcc) 3650ed7c580Smrg # Portland's C compiler understands '-MD'. 3660ed7c580Smrg # Will always output deps to 'file.d' where file is the root name of the 3670ed7c580Smrg # source file under compilation, even if file resides in a subdirectory. 3680ed7c580Smrg # The object file name does not affect the name of the '.d' file. 3690ed7c580Smrg # pgcc 10.2 will output 3700ed7c580Smrg # foo.o: sub/foo.c sub/foo.h 3710ed7c580Smrg # and will wrap long lines using '\' : 3720ed7c580Smrg # foo.o: sub/foo.c ... \ 3730ed7c580Smrg # sub/foo.h ... \ 3740ed7c580Smrg # ... 3750ed7c580Smrg set_dir_from "$object" 3760ed7c580Smrg # Use the source, not the object, to determine the base name, since 3770ed7c580Smrg # that's sadly what pgcc will do too. 3780ed7c580Smrg set_base_from "$source" 3790ed7c580Smrg tmpdepfile=$base.d 3800ed7c580Smrg 3810ed7c580Smrg # For projects that build the same source file twice into different object 3820ed7c580Smrg # files, the pgcc approach of using the *source* file root name can cause 3830ed7c580Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 3840ed7c580Smrg # the same $tmpdepfile. 3850ed7c580Smrg lockdir=$base.d-lock 3860ed7c580Smrg trap " 3870ed7c580Smrg echo '$0: caught signal, cleaning up...' >&2 3880ed7c580Smrg rmdir '$lockdir' 3890ed7c580Smrg exit 1 3900ed7c580Smrg " 1 2 13 15 3910ed7c580Smrg numtries=100 3920ed7c580Smrg i=$numtries 3930ed7c580Smrg while test $i -gt 0; do 3940ed7c580Smrg # mkdir is a portable test-and-set. 3950ed7c580Smrg if mkdir "$lockdir" 2>/dev/null; then 3960ed7c580Smrg # This process acquired the lock. 3970ed7c580Smrg "$@" -MD 3980ed7c580Smrg stat=$? 3990ed7c580Smrg # Release the lock. 4000ed7c580Smrg rmdir "$lockdir" 4010ed7c580Smrg break 4020ed7c580Smrg else 4030ed7c580Smrg # If the lock is being held by a different process, wait 4040ed7c580Smrg # until the winning process is done or we timeout. 4050ed7c580Smrg while test -d "$lockdir" && test $i -gt 0; do 4060ed7c580Smrg sleep 1 4070ed7c580Smrg i=`expr $i - 1` 4080ed7c580Smrg done 4090ed7c580Smrg fi 4100ed7c580Smrg i=`expr $i - 1` 4110ed7c580Smrg done 4120ed7c580Smrg trap - 1 2 13 15 4130ed7c580Smrg if test $i -le 0; then 4140ed7c580Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 4150ed7c580Smrg echo "$0: check lockdir '$lockdir'" >&2 4160ed7c580Smrg exit 1 4170ed7c580Smrg fi 4180ed7c580Smrg 4190ed7c580Smrg if test $stat -ne 0; then 4200ed7c580Smrg rm -f "$tmpdepfile" 4210ed7c580Smrg exit $stat 4220ed7c580Smrg fi 4230ed7c580Smrg rm -f "$depfile" 4240ed7c580Smrg # Each line is of the form `foo.o: dependent.h', 4250ed7c580Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 4260ed7c580Smrg # Do two passes, one to just change these to 4270ed7c580Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 4280ed7c580Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 4290ed7c580Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 4300ed7c580Smrg # correctly. Breaking it into two sed invocations is a workaround. 4310ed7c580Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 4320ed7c580Smrg | sed -e 's/$/ :/' >> "$depfile" 4330ed7c580Smrg rm -f "$tmpdepfile" 4340ed7c580Smrg ;; 4350ed7c580Smrg 4360ed7c580Smrghp2) 4370ed7c580Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4380ed7c580Smrg # compilers, which have integrated preprocessors. The correct option 4390ed7c580Smrg # to use with these is +Maked; it writes dependencies to a file named 4400ed7c580Smrg # 'foo.d', which lands next to the object file, wherever that 4410ed7c580Smrg # happens to be. 4420ed7c580Smrg # Much of this is similar to the tru64 case; see comments there. 4430ed7c580Smrg set_dir_from "$object" 4440ed7c580Smrg set_base_from "$object" 4450ed7c580Smrg if test "$libtool" = yes; then 4460ed7c580Smrg tmpdepfile1=$dir$base.d 4470ed7c580Smrg tmpdepfile2=$dir.libs/$base.d 4480ed7c580Smrg "$@" -Wc,+Maked 4490ed7c580Smrg else 4500ed7c580Smrg tmpdepfile1=$dir$base.d 4510ed7c580Smrg tmpdepfile2=$dir$base.d 4520ed7c580Smrg "$@" +Maked 4530ed7c580Smrg fi 4540ed7c580Smrg stat=$? 4550ed7c580Smrg if test $stat -ne 0; then 4560ed7c580Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4570ed7c580Smrg exit $stat 4580ed7c580Smrg fi 4590ed7c580Smrg 4600ed7c580Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4610ed7c580Smrg do 4620ed7c580Smrg test -f "$tmpdepfile" && break 4630ed7c580Smrg done 4640ed7c580Smrg if test -f "$tmpdepfile"; then 4650ed7c580Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 4660ed7c580Smrg # Add 'dependent.h:' lines. 4670ed7c580Smrg sed -ne '2,${ 4680ed7c580Smrg s/^ *// 4690ed7c580Smrg s/ \\*$// 4700ed7c580Smrg s/$/:/ 4710ed7c580Smrg p 4720ed7c580Smrg }' "$tmpdepfile" >> "$depfile" 4730ed7c580Smrg else 4740ed7c580Smrg make_dummy_depfile 4750ed7c580Smrg fi 4760ed7c580Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4770ed7c580Smrg ;; 4780ed7c580Smrg 4790ed7c580Smrgtru64) 4800ed7c580Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 4810ed7c580Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 4820ed7c580Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 4830ed7c580Smrg # dependencies in 'foo.d' instead, so we check for that too. 4840ed7c580Smrg # Subdirectories are respected. 4850ed7c580Smrg set_dir_from "$object" 4860ed7c580Smrg set_base_from "$object" 4870ed7c580Smrg 4880ed7c580Smrg if test "$libtool" = yes; then 4890ed7c580Smrg # Libtool generates 2 separate objects for the 2 libraries. These 4900ed7c580Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 4910ed7c580Smrg # in $dir$base.o.d. We have to check for both files, because 4920ed7c580Smrg # one of the two compilations can be disabled. We should prefer 4930ed7c580Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 4940ed7c580Smrg # automatically cleaned when .libs/ is deleted, while ignoring 4950ed7c580Smrg # the former would cause a distcleancheck panic. 4960ed7c580Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 4970ed7c580Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 4980ed7c580Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 4990ed7c580Smrg "$@" -Wc,-MD 5000ed7c580Smrg else 5010ed7c580Smrg tmpdepfile1=$dir$base.d 5020ed7c580Smrg tmpdepfile2=$dir$base.d 5030ed7c580Smrg tmpdepfile3=$dir$base.d 5040ed7c580Smrg "$@" -MD 5050ed7c580Smrg fi 5060ed7c580Smrg 5070ed7c580Smrg stat=$? 5080ed7c580Smrg if test $stat -ne 0; then 5090ed7c580Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5100ed7c580Smrg exit $stat 5110ed7c580Smrg fi 5120ed7c580Smrg 5130ed7c580Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 5140ed7c580Smrg do 5150ed7c580Smrg test -f "$tmpdepfile" && break 5160ed7c580Smrg done 5170ed7c580Smrg # Same post-processing that is required for AIX mode. 5180ed7c580Smrg aix_post_process_depfile 5190ed7c580Smrg ;; 5200ed7c580Smrg 5210ed7c580Smrgmsvc7) 5220ed7c580Smrg if test "$libtool" = yes; then 5230ed7c580Smrg showIncludes=-Wc,-showIncludes 5240ed7c580Smrg else 5250ed7c580Smrg showIncludes=-showIncludes 5260ed7c580Smrg fi 5270ed7c580Smrg "$@" $showIncludes > "$tmpdepfile" 5280ed7c580Smrg stat=$? 5290ed7c580Smrg grep -v '^Note: including file: ' "$tmpdepfile" 5300ed7c580Smrg if test $stat -ne 0; then 5310ed7c580Smrg rm -f "$tmpdepfile" 5320ed7c580Smrg exit $stat 5330ed7c580Smrg fi 5340ed7c580Smrg rm -f "$depfile" 5350ed7c580Smrg echo "$object : \\" > "$depfile" 5360ed7c580Smrg # The first sed program below extracts the file names and escapes 5370ed7c580Smrg # backslashes for cygpath. The second sed program outputs the file 5380ed7c580Smrg # name when reading, but also accumulates all include files in the 5390ed7c580Smrg # hold buffer in order to output them again at the end. This only 5400ed7c580Smrg # works with sed implementations that can handle large buffers. 5410ed7c580Smrg sed < "$tmpdepfile" -n ' 5420ed7c580Smrg/^Note: including file: *\(.*\)/ { 5430ed7c580Smrg s//\1/ 5440ed7c580Smrg s/\\/\\\\/g 5450ed7c580Smrg p 5460ed7c580Smrg}' | $cygpath_u | sort -u | sed -n ' 5470ed7c580Smrgs/ /\\ /g 5480ed7c580Smrgs/\(.*\)/'"$tab"'\1 \\/p 5490ed7c580Smrgs/.\(.*\) \\/\1:/ 5500ed7c580SmrgH 5510ed7c580Smrg$ { 5520ed7c580Smrg s/.*/'"$tab"'/ 5530ed7c580Smrg G 5540ed7c580Smrg p 5550ed7c580Smrg}' >> "$depfile" 5560ed7c580Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5570ed7c580Smrg rm -f "$tmpdepfile" 5580ed7c580Smrg ;; 5590ed7c580Smrg 5600ed7c580Smrgmsvc7msys) 5610ed7c580Smrg # This case exists only to let depend.m4 do its work. It works by 5620ed7c580Smrg # looking at the text of this script. This case will never be run, 5630ed7c580Smrg # since it is checked for above. 5640ed7c580Smrg exit 1 5650ed7c580Smrg ;; 5660ed7c580Smrg 5670ed7c580Smrg#nosideeffect) 5680ed7c580Smrg # This comment above is used by automake to tell side-effect 5690ed7c580Smrg # dependency tracking mechanisms from slower ones. 5700ed7c580Smrg 5710ed7c580Smrgdashmstdout) 5720ed7c580Smrg # Important note: in order to support this mode, a compiler *must* 5730ed7c580Smrg # always write the preprocessed file to stdout, regardless of -o. 5740ed7c580Smrg "$@" || exit $? 5750ed7c580Smrg 5760ed7c580Smrg # Remove the call to Libtool. 5770ed7c580Smrg if test "$libtool" = yes; then 5780ed7c580Smrg while test "X$1" != 'X--mode=compile'; do 5790ed7c580Smrg shift 5800ed7c580Smrg done 5810ed7c580Smrg shift 5820ed7c580Smrg fi 5830ed7c580Smrg 5840ed7c580Smrg # Remove '-o $object'. 5850ed7c580Smrg IFS=" " 5860ed7c580Smrg for arg 5870ed7c580Smrg do 5880ed7c580Smrg case $arg in 5890ed7c580Smrg -o) 5900ed7c580Smrg shift 5910ed7c580Smrg ;; 5920ed7c580Smrg $object) 5930ed7c580Smrg shift 5940ed7c580Smrg ;; 5950ed7c580Smrg *) 5960ed7c580Smrg set fnord "$@" "$arg" 5970ed7c580Smrg shift # fnord 5980ed7c580Smrg shift # $arg 5990ed7c580Smrg ;; 6000ed7c580Smrg esac 6010ed7c580Smrg done 6020ed7c580Smrg 6030ed7c580Smrg test -z "$dashmflag" && dashmflag=-M 6040ed7c580Smrg # Require at least two characters before searching for ':' 6050ed7c580Smrg # in the target name. This is to cope with DOS-style filenames: 6060ed7c580Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 6070ed7c580Smrg "$@" $dashmflag | 6080ed7c580Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 6090ed7c580Smrg rm -f "$depfile" 6100ed7c580Smrg cat < "$tmpdepfile" > "$depfile" 6110ed7c580Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 6120ed7c580Smrg # correctly. Breaking it into two sed invocations is a workaround. 6130ed7c580Smrg tr ' ' "$nl" < "$tmpdepfile" \ 6140ed7c580Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6150ed7c580Smrg | sed -e 's/$/ :/' >> "$depfile" 6160ed7c580Smrg rm -f "$tmpdepfile" 6170ed7c580Smrg ;; 6180ed7c580Smrg 6190ed7c580SmrgdashXmstdout) 6200ed7c580Smrg # This case only exists to satisfy depend.m4. It is never actually 6210ed7c580Smrg # run, as this mode is specially recognized in the preamble. 6220ed7c580Smrg exit 1 6230ed7c580Smrg ;; 6240ed7c580Smrg 6250ed7c580Smrgmakedepend) 6260ed7c580Smrg "$@" || exit $? 6270ed7c580Smrg # Remove any Libtool call 6280ed7c580Smrg if test "$libtool" = yes; then 6290ed7c580Smrg while test "X$1" != 'X--mode=compile'; do 6300ed7c580Smrg shift 6310ed7c580Smrg done 6320ed7c580Smrg shift 6330ed7c580Smrg fi 6340ed7c580Smrg # X makedepend 6350ed7c580Smrg shift 6360ed7c580Smrg cleared=no eat=no 6370ed7c580Smrg for arg 6380ed7c580Smrg do 6390ed7c580Smrg case $cleared in 6400ed7c580Smrg no) 6410ed7c580Smrg set ""; shift 6420ed7c580Smrg cleared=yes ;; 6430ed7c580Smrg esac 6440ed7c580Smrg if test $eat = yes; then 6450ed7c580Smrg eat=no 6460ed7c580Smrg continue 6470ed7c580Smrg fi 6480ed7c580Smrg case "$arg" in 6490ed7c580Smrg -D*|-I*) 6500ed7c580Smrg set fnord "$@" "$arg"; shift ;; 6510ed7c580Smrg # Strip any option that makedepend may not understand. Remove 6520ed7c580Smrg # the object too, otherwise makedepend will parse it as a source file. 6530ed7c580Smrg -arch) 6540ed7c580Smrg eat=yes ;; 6550ed7c580Smrg -*|$object) 6560ed7c580Smrg ;; 6570ed7c580Smrg *) 6580ed7c580Smrg set fnord "$@" "$arg"; shift ;; 6590ed7c580Smrg esac 6600ed7c580Smrg done 6610ed7c580Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 6620ed7c580Smrg touch "$tmpdepfile" 6630ed7c580Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 6640ed7c580Smrg rm -f "$depfile" 6650ed7c580Smrg # makedepend may prepend the VPATH from the source file name to the object. 6660ed7c580Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 6670ed7c580Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 6680ed7c580Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 6690ed7c580Smrg # correctly. Breaking it into two sed invocations is a workaround. 6700ed7c580Smrg sed '1,2d' "$tmpdepfile" \ 6710ed7c580Smrg | tr ' ' "$nl" \ 6720ed7c580Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 6730ed7c580Smrg | sed -e 's/$/ :/' >> "$depfile" 6740ed7c580Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 6750ed7c580Smrg ;; 6760ed7c580Smrg 6770ed7c580Smrgcpp) 6780ed7c580Smrg # Important note: in order to support this mode, a compiler *must* 6790ed7c580Smrg # always write the preprocessed file to stdout. 6800ed7c580Smrg "$@" || exit $? 6810ed7c580Smrg 6820ed7c580Smrg # Remove the call to Libtool. 6830ed7c580Smrg if test "$libtool" = yes; then 6840ed7c580Smrg while test "X$1" != 'X--mode=compile'; do 6850ed7c580Smrg shift 6860ed7c580Smrg done 6870ed7c580Smrg shift 6880ed7c580Smrg fi 6890ed7c580Smrg 6900ed7c580Smrg # Remove '-o $object'. 6910ed7c580Smrg IFS=" " 6920ed7c580Smrg for arg 6930ed7c580Smrg do 6940ed7c580Smrg case $arg in 6950ed7c580Smrg -o) 6960ed7c580Smrg shift 6970ed7c580Smrg ;; 6980ed7c580Smrg $object) 6990ed7c580Smrg shift 7000ed7c580Smrg ;; 7010ed7c580Smrg *) 7020ed7c580Smrg set fnord "$@" "$arg" 7030ed7c580Smrg shift # fnord 7040ed7c580Smrg shift # $arg 7050ed7c580Smrg ;; 7060ed7c580Smrg esac 7070ed7c580Smrg done 7080ed7c580Smrg 7090ed7c580Smrg "$@" -E \ 7100ed7c580Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7110ed7c580Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 7120ed7c580Smrg | sed '$ s: \\$::' > "$tmpdepfile" 7130ed7c580Smrg rm -f "$depfile" 7140ed7c580Smrg echo "$object : \\" > "$depfile" 7150ed7c580Smrg cat < "$tmpdepfile" >> "$depfile" 7160ed7c580Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 7170ed7c580Smrg rm -f "$tmpdepfile" 7180ed7c580Smrg ;; 7190ed7c580Smrg 7200ed7c580Smrgmsvisualcpp) 7210ed7c580Smrg # Important note: in order to support this mode, a compiler *must* 7220ed7c580Smrg # always write the preprocessed file to stdout. 7230ed7c580Smrg "$@" || exit $? 7240ed7c580Smrg 7250ed7c580Smrg # Remove the call to Libtool. 7260ed7c580Smrg if test "$libtool" = yes; then 7270ed7c580Smrg while test "X$1" != 'X--mode=compile'; do 7280ed7c580Smrg shift 7290ed7c580Smrg done 7300ed7c580Smrg shift 7310ed7c580Smrg fi 7320ed7c580Smrg 7330ed7c580Smrg IFS=" " 7340ed7c580Smrg for arg 7350ed7c580Smrg do 7360ed7c580Smrg case "$arg" in 7370ed7c580Smrg -o) 7380ed7c580Smrg shift 7390ed7c580Smrg ;; 7400ed7c580Smrg $object) 7410ed7c580Smrg shift 7420ed7c580Smrg ;; 7430ed7c580Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 7440ed7c580Smrg set fnord "$@" 7450ed7c580Smrg shift 7460ed7c580Smrg shift 7470ed7c580Smrg ;; 7480ed7c580Smrg *) 7490ed7c580Smrg set fnord "$@" "$arg" 7500ed7c580Smrg shift 7510ed7c580Smrg shift 7520ed7c580Smrg ;; 7530ed7c580Smrg esac 7540ed7c580Smrg done 7550ed7c580Smrg "$@" -E 2>/dev/null | 7560ed7c580Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 7570ed7c580Smrg rm -f "$depfile" 7580ed7c580Smrg echo "$object : \\" > "$depfile" 7590ed7c580Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 7600ed7c580Smrg echo "$tab" >> "$depfile" 7610ed7c580Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 7620ed7c580Smrg rm -f "$tmpdepfile" 7630ed7c580Smrg ;; 7640ed7c580Smrg 7650ed7c580Smrgmsvcmsys) 7660ed7c580Smrg # This case exists only to let depend.m4 do its work. It works by 7670ed7c580Smrg # looking at the text of this script. This case will never be run, 7680ed7c580Smrg # since it is checked for above. 7690ed7c580Smrg exit 1 7700ed7c580Smrg ;; 7710ed7c580Smrg 7720ed7c580Smrgnone) 7730ed7c580Smrg exec "$@" 7740ed7c580Smrg ;; 7750ed7c580Smrg 7760ed7c580Smrg*) 7770ed7c580Smrg echo "Unknown depmode $depmode" 1>&2 7780ed7c580Smrg exit 1 7790ed7c580Smrg ;; 7800ed7c580Smrgesac 7810ed7c580Smrg 7820ed7c580Smrgexit 0 7830ed7c580Smrg 7840ed7c580Smrg# Local Variables: 7850ed7c580Smrg# mode: shell-script 7860ed7c580Smrg# sh-indentation: 2 7871a28b98bSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7880ed7c580Smrg# time-stamp-start: "scriptversion=" 7890ed7c580Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 7901a28b98bSmrg# time-stamp-time-zone: "UTC0" 7910ed7c580Smrg# time-stamp-end: "; # UTC" 7920ed7c580Smrg# End: 793