1bccedf53Smrg#! /bin/sh 2bccedf53Smrg# depcomp - compile a program generating dependencies as side-effects 37c5f6000Smrg 4a2394c98Smrgscriptversion=2024-06-19.01; # UTC 57c5f6000Smrg 6a2394c98Smrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 7bccedf53Smrg 8bccedf53Smrg# This program is free software; you can redistribute it and/or modify 9bccedf53Smrg# it under the terms of the GNU General Public License as published by 10bccedf53Smrg# the Free Software Foundation; either version 2, or (at your option) 11bccedf53Smrg# any later version. 12bccedf53Smrg 13bccedf53Smrg# This program is distributed in the hope that it will be useful, 14bccedf53Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15bccedf53Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16bccedf53Smrg# GNU General Public License for more details. 17bccedf53Smrg 18bccedf53Smrg# You should have received a copy of the GNU General Public License 19ec318dbfSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20bccedf53Smrg 21bccedf53Smrg# As a special exception to the GNU General Public License, if you 22bccedf53Smrg# distribute this file as part of a program that contains a 23bccedf53Smrg# configuration script generated by Autoconf, you may include it under 24bccedf53Smrg# the same distribution terms that you use for the rest of that program. 25bccedf53Smrg 26bccedf53Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27bccedf53Smrg 287c5f6000Smrgcase $1 in 297c5f6000Smrg '') 3089afc689Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 3189afc689Smrg exit 1; 3289afc689Smrg ;; 337c5f6000Smrg -h | --h*) 347c5f6000Smrg cat <<\EOF 357c5f6000SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 367c5f6000Smrg 377c5f6000SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 387c5f6000Smrgas side-effects. 397c5f6000Smrg 407c5f6000SmrgEnvironment variables: 417c5f6000Smrg depmode Dependency tracking mode. 4289afc689Smrg source Source file read by 'PROGRAMS ARGS'. 4389afc689Smrg object Object file output by 'PROGRAMS ARGS'. 447c5f6000Smrg DEPDIR directory where to store dependencies. 457c5f6000Smrg depfile Dependency file to output. 461b1389eeSmrg tmpdepfile Temporary file to use when outputting dependencies. 477c5f6000Smrg libtool Whether libtool is used (yes/no). 487c5f6000Smrg 497c5f6000SmrgReport bugs to <bug-automake@gnu.org>. 50a2394c98SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 51a2394c98SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 527c5f6000SmrgEOF 537c5f6000Smrg exit $? 547c5f6000Smrg ;; 557c5f6000Smrg -v | --v*) 56a2394c98Smrg echo "depcomp (GNU Automake) $scriptversion" 577c5f6000Smrg exit $? 587c5f6000Smrg ;; 597c5f6000Smrgesac 607c5f6000Smrg 6189afc689Smrg# Get the directory component of the given path, and save it in the 6289afc689Smrg# global variables '$dir'. Note that this directory component will 6389afc689Smrg# be either empty or ending with a '/' character. This is deliberate. 6489afc689Smrgset_dir_from () 6589afc689Smrg{ 6689afc689Smrg case $1 in 6789afc689Smrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 6889afc689Smrg *) dir=;; 6989afc689Smrg esac 7089afc689Smrg} 7189afc689Smrg 7289afc689Smrg# Get the suffix-stripped basename of the given path, and save it the 7389afc689Smrg# global variable '$base'. 7489afc689Smrgset_base_from () 7589afc689Smrg{ 7689afc689Smrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 7789afc689Smrg} 7889afc689Smrg 7989afc689Smrg# If no dependency file was actually created by the compiler invocation, 8089afc689Smrg# we still have to create a dummy depfile, to avoid errors with the 8189afc689Smrg# Makefile "include basename.Plo" scheme. 8289afc689Smrgmake_dummy_depfile () 8389afc689Smrg{ 8489afc689Smrg echo "#dummy" > "$depfile" 8589afc689Smrg} 8689afc689Smrg 8789afc689Smrg# Factor out some common post-processing of the generated depfile. 8889afc689Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 8989afc689Smrgaix_post_process_depfile () 9089afc689Smrg{ 9189afc689Smrg # If the compiler actually managed to produce a dependency file, 9289afc689Smrg # post-process it. 9389afc689Smrg if test -f "$tmpdepfile"; then 9489afc689Smrg # Each line is of the form 'foo.o: dependency.h'. 9589afc689Smrg # Do two passes, one to just change these to 9689afc689Smrg # $object: dependency.h 9789afc689Smrg # and one to simply output 9889afc689Smrg # dependency.h: 9989afc689Smrg # which is needed to avoid the deleted-header problem. 10089afc689Smrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 10189afc689Smrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 10289afc689Smrg } > "$depfile" 10389afc689Smrg rm -f "$tmpdepfile" 10489afc689Smrg else 10589afc689Smrg make_dummy_depfile 10689afc689Smrg fi 10789afc689Smrg} 10889afc689Smrg 10989afc689Smrg# A tabulation character. 11089afc689Smrgtab=' ' 11189afc689Smrg# A newline character. 11289afc689Smrgnl=' 11389afc689Smrg' 11489afc689Smrg# Character ranges might be problematic outside the C locale. 11589afc689Smrg# These definitions help. 11689afc689Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 11789afc689Smrglower=abcdefghijklmnopqrstuvwxyz 11889afc689Smrgalpha=${upper}${lower} 11989afc689Smrg 120bccedf53Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 121bccedf53Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 122bccedf53Smrg exit 1 123bccedf53Smrgfi 124bccedf53Smrg 1257c5f6000Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 1267c5f6000Smrgdepfile=${depfile-`echo "$object" | 1277c5f6000Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 128bccedf53Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 129bccedf53Smrg 130bccedf53Smrgrm -f "$tmpdepfile" 131bccedf53Smrg 132a2394c98Smrg# Avoid interference from the environment. 13389afc689Smrggccflag= dashmflag= 13489afc689Smrg 135bccedf53Smrg# Some modes work just like other modes, but use different flags. We 136bccedf53Smrg# parameterize here, but still list the modes in the big case below, 137bccedf53Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 138bccedf53Smrg# here, because this file can only contain one case statement. 139bccedf53Smrgif test "$depmode" = hp; then 140bccedf53Smrg # HP compiler uses -M and no extra arg. 141bccedf53Smrg gccflag=-M 142bccedf53Smrg depmode=gcc 143bccedf53Smrgfi 144bccedf53Smrg 145bccedf53Smrgif test "$depmode" = dashXmstdout; then 14689afc689Smrg # This is just like dashmstdout with a different argument. 14789afc689Smrg dashmflag=-xM 14889afc689Smrg depmode=dashmstdout 149bccedf53Smrgfi 150bccedf53Smrg 1517c5f6000Smrgcygpath_u="cygpath -u -f -" 1527c5f6000Smrgif test "$depmode" = msvcmsys; then 15389afc689Smrg # This is just like msvisualcpp but w/o cygpath translation. 15489afc689Smrg # Just convert the backslash-escaped backslashes to single forward 15589afc689Smrg # slashes to satisfy depend.m4 15689afc689Smrg cygpath_u='sed s,\\\\,/,g' 15789afc689Smrg depmode=msvisualcpp 1587c5f6000Smrgfi 1597c5f6000Smrg 1601b1389eeSmrgif test "$depmode" = msvc7msys; then 16189afc689Smrg # This is just like msvc7 but w/o cygpath translation. 16289afc689Smrg # Just convert the backslash-escaped backslashes to single forward 16389afc689Smrg # slashes to satisfy depend.m4 16489afc689Smrg cygpath_u='sed s,\\\\,/,g' 16589afc689Smrg depmode=msvc7 16689afc689Smrgfi 16789afc689Smrg 16889afc689Smrgif test "$depmode" = xlc; then 16989afc689Smrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 17089afc689Smrg gccflag=-qmakedep=gcc,-MF 17189afc689Smrg depmode=gcc 1721b1389eeSmrgfi 1731b1389eeSmrg 174bccedf53Smrgcase "$depmode" in 175bccedf53Smrggcc3) 176bccedf53Smrg## gcc 3 implements dependency tracking that does exactly what 177bccedf53Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 178bccedf53Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 1797c5f6000Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 1807c5f6000Smrg## the command line argument order; so add the flags where they 1817c5f6000Smrg## appear in depend2.am. Note that the slowdown incurred here 1827c5f6000Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 1837c5f6000Smrg for arg 1847c5f6000Smrg do 1857c5f6000Smrg case $arg in 1867c5f6000Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 1877c5f6000Smrg *) set fnord "$@" "$arg" ;; 1887c5f6000Smrg esac 1897c5f6000Smrg shift # fnord 1907c5f6000Smrg shift # $arg 1917c5f6000Smrg done 1927c5f6000Smrg "$@" 193bccedf53Smrg stat=$? 19489afc689Smrg if test $stat -ne 0; then 195bccedf53Smrg rm -f "$tmpdepfile" 196bccedf53Smrg exit $stat 197bccedf53Smrg fi 198bccedf53Smrg mv "$tmpdepfile" "$depfile" 199bccedf53Smrg ;; 200bccedf53Smrg 201bccedf53Smrggcc) 202a2394c98Smrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers. 203a2394c98Smrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler. 20489afc689Smrg## (see the conditional assignment to $gccflag above). 205bccedf53Smrg## There are various ways to get dependency output from gcc. Here's 206bccedf53Smrg## why we pick this rather obscure method: 207bccedf53Smrg## - Don't want to use -MD because we'd like the dependencies to end 208bccedf53Smrg## up in a subdir. Having to rename by hand is ugly. 209bccedf53Smrg## (We might end up doing this anyway to support other compilers.) 210bccedf53Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 21189afc689Smrg## -MM, not -M (despite what the docs say). Also, it might not be 21289afc689Smrg## supported by the other compilers which use the 'gcc' depmode. 213bccedf53Smrg## - Using -M directly means running the compiler twice (even worse 214bccedf53Smrg## than renaming). 215bccedf53Smrg if test -z "$gccflag"; then 216bccedf53Smrg gccflag=-MD, 217bccedf53Smrg fi 218bccedf53Smrg "$@" -Wp,"$gccflag$tmpdepfile" 219bccedf53Smrg stat=$? 22089afc689Smrg if test $stat -ne 0; then 221bccedf53Smrg rm -f "$tmpdepfile" 222bccedf53Smrg exit $stat 223bccedf53Smrg fi 224bccedf53Smrg rm -f "$depfile" 225bccedf53Smrg echo "$object : \\" > "$depfile" 22689afc689Smrg # The second -e expression handles DOS-style file names with drive 22789afc689Smrg # letters. 228bccedf53Smrg sed -e 's/^[^:]*: / /' \ 229bccedf53Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 23089afc689Smrg## This next piece of magic avoids the "deleted header file" problem. 231bccedf53Smrg## The problem is that when a header file which appears in a .P file 232bccedf53Smrg## is deleted, the dependency causes make to die (because there is 233bccedf53Smrg## typically no way to rebuild the header). We avoid this by adding 234bccedf53Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 235bccedf53Smrg## this for us directly. 23689afc689Smrg## Some versions of gcc put a space before the ':'. On the theory 237bccedf53Smrg## that the space means something, we add a space to the output as 2381b1389eeSmrg## well. hp depmode also adds that space, but also prefixes the VPATH 2391b1389eeSmrg## to the object. Take care to not repeat it in the output. 240bccedf53Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 241bccedf53Smrg## correctly. Breaking it into two sed invocations is a workaround. 24289afc689Smrg tr ' ' "$nl" < "$tmpdepfile" \ 24389afc689Smrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 24489afc689Smrg | sed -e 's/$/ :/' >> "$depfile" 245bccedf53Smrg rm -f "$tmpdepfile" 246bccedf53Smrg ;; 247bccedf53Smrg 248bccedf53Smrghp) 249bccedf53Smrg # This case exists only to let depend.m4 do its work. It works by 250bccedf53Smrg # looking at the text of this script. This case will never be run, 251bccedf53Smrg # since it is checked for above. 252bccedf53Smrg exit 1 253bccedf53Smrg ;; 254bccedf53Smrg 255bccedf53Smrgsgi) 256bccedf53Smrg if test "$libtool" = yes; then 257bccedf53Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 258bccedf53Smrg else 259bccedf53Smrg "$@" -MDupdate "$tmpdepfile" 260bccedf53Smrg fi 261bccedf53Smrg stat=$? 26289afc689Smrg if test $stat -ne 0; then 263bccedf53Smrg rm -f "$tmpdepfile" 264bccedf53Smrg exit $stat 265bccedf53Smrg fi 266bccedf53Smrg rm -f "$depfile" 267bccedf53Smrg 268bccedf53Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 269bccedf53Smrg echo "$object : \\" > "$depfile" 270bccedf53Smrg # Clip off the initial element (the dependent). Don't try to be 271bccedf53Smrg # clever and replace this with sed code, as IRIX sed won't handle 272bccedf53Smrg # lines with more than a fixed number of characters (4096 in 273bccedf53Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 27489afc689Smrg # the IRIX cc adds comments like '#:fec' to the end of the 275bccedf53Smrg # dependency line. 27689afc689Smrg tr ' ' "$nl" < "$tmpdepfile" \ 27789afc689Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 27889afc689Smrg | tr "$nl" ' ' >> "$depfile" 2797c5f6000Smrg echo >> "$depfile" 280bccedf53Smrg # The second pass generates a dummy entry for each header file. 28189afc689Smrg tr ' ' "$nl" < "$tmpdepfile" \ 28289afc689Smrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 28389afc689Smrg >> "$depfile" 284bccedf53Smrg else 28589afc689Smrg make_dummy_depfile 286bccedf53Smrg fi 287bccedf53Smrg rm -f "$tmpdepfile" 288bccedf53Smrg ;; 289bccedf53Smrg 29089afc689Smrgxlc) 29189afc689Smrg # This case exists only to let depend.m4 do its work. It works by 29289afc689Smrg # looking at the text of this script. This case will never be run, 29389afc689Smrg # since it is checked for above. 29489afc689Smrg exit 1 29589afc689Smrg ;; 29689afc689Smrg 297bccedf53Smrgaix) 298bccedf53Smrg # The C for AIX Compiler uses -M and outputs the dependencies 299bccedf53Smrg # in a .u file. In older versions, this file always lives in the 30089afc689Smrg # current directory. Also, the AIX compiler puts '$object:' at the 301bccedf53Smrg # start of each line; $object doesn't have directory information. 302bccedf53Smrg # Version 6 uses the directory in both cases. 30389afc689Smrg set_dir_from "$object" 30489afc689Smrg set_base_from "$object" 305bccedf53Smrg if test "$libtool" = yes; then 3067c5f6000Smrg tmpdepfile1=$dir$base.u 3077c5f6000Smrg tmpdepfile2=$base.u 3087c5f6000Smrg tmpdepfile3=$dir.libs/$base.u 309bccedf53Smrg "$@" -Wc,-M 310bccedf53Smrg else 3117c5f6000Smrg tmpdepfile1=$dir$base.u 3127c5f6000Smrg tmpdepfile2=$dir$base.u 3137c5f6000Smrg tmpdepfile3=$dir$base.u 314bccedf53Smrg "$@" -M 315bccedf53Smrg fi 316bccedf53Smrg stat=$? 31789afc689Smrg if test $stat -ne 0; then 3187c5f6000Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 319bccedf53Smrg exit $stat 320bccedf53Smrg fi 321bccedf53Smrg 3227c5f6000Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 3237c5f6000Smrg do 3247c5f6000Smrg test -f "$tmpdepfile" && break 3257c5f6000Smrg done 32689afc689Smrg aix_post_process_depfile 32789afc689Smrg ;; 32889afc689Smrg 32989afc689Smrgtcc) 33089afc689Smrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 33189afc689Smrg # FIXME: That version still under development at the moment of writing. 33289afc689Smrg # Make that this statement remains true also for stable, released 33389afc689Smrg # versions. 33489afc689Smrg # It will wrap lines (doesn't matter whether long or short) with a 33589afc689Smrg # trailing '\', as in: 33689afc689Smrg # 33789afc689Smrg # foo.o : \ 33889afc689Smrg # foo.c \ 33989afc689Smrg # foo.h \ 34089afc689Smrg # 34189afc689Smrg # It will put a trailing '\' even on the last line, and will use leading 34289afc689Smrg # spaces rather than leading tabs (at least since its commit 0394caf7 34389afc689Smrg # "Emit spaces for -MD"). 34489afc689Smrg "$@" -MD -MF "$tmpdepfile" 34589afc689Smrg stat=$? 34689afc689Smrg if test $stat -ne 0; then 34789afc689Smrg rm -f "$tmpdepfile" 34889afc689Smrg exit $stat 349bccedf53Smrg fi 35089afc689Smrg rm -f "$depfile" 35189afc689Smrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 35289afc689Smrg # We have to change lines of the first kind to '$object: \'. 35389afc689Smrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 35489afc689Smrg # And for each line of the second kind, we have to emit a 'dep.h:' 35589afc689Smrg # dummy dependency, to avoid the deleted-header problem. 35689afc689Smrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 357bccedf53Smrg rm -f "$tmpdepfile" 358bccedf53Smrg ;; 359bccedf53Smrg 36089afc689Smrg## The order of this option in the case statement is important, since the 36189afc689Smrg## shell code in configure will try each of these formats in the order 36289afc689Smrg## listed in this file. A plain '-MD' option would be understood by many 36389afc689Smrg## compilers, so we must ensure this comes after the gcc and icc options. 36489afc689Smrgpgcc) 36589afc689Smrg # Portland's C compiler understands '-MD'. 36689afc689Smrg # Will always output deps to 'file.d' where file is the root name of the 36789afc689Smrg # source file under compilation, even if file resides in a subdirectory. 36889afc689Smrg # The object file name does not affect the name of the '.d' file. 36989afc689Smrg # pgcc 10.2 will output 370bccedf53Smrg # foo.o: sub/foo.c sub/foo.h 37189afc689Smrg # and will wrap long lines using '\' : 372bccedf53Smrg # foo.o: sub/foo.c ... \ 373bccedf53Smrg # sub/foo.h ... \ 374bccedf53Smrg # ... 37589afc689Smrg set_dir_from "$object" 37689afc689Smrg # Use the source, not the object, to determine the base name, since 37789afc689Smrg # that's sadly what pgcc will do too. 37889afc689Smrg set_base_from "$source" 37989afc689Smrg tmpdepfile=$base.d 38089afc689Smrg 38189afc689Smrg # For projects that build the same source file twice into different object 38289afc689Smrg # files, the pgcc approach of using the *source* file root name can cause 38389afc689Smrg # problems in parallel builds. Use a locking strategy to avoid stomping on 38489afc689Smrg # the same $tmpdepfile. 38589afc689Smrg lockdir=$base.d-lock 38689afc689Smrg trap " 38789afc689Smrg echo '$0: caught signal, cleaning up...' >&2 38889afc689Smrg rmdir '$lockdir' 38989afc689Smrg exit 1 39089afc689Smrg " 1 2 13 15 39189afc689Smrg numtries=100 39289afc689Smrg i=$numtries 39389afc689Smrg while test $i -gt 0; do 39489afc689Smrg # mkdir is a portable test-and-set. 39589afc689Smrg if mkdir "$lockdir" 2>/dev/null; then 39689afc689Smrg # This process acquired the lock. 39789afc689Smrg "$@" -MD 39889afc689Smrg stat=$? 39989afc689Smrg # Release the lock. 40089afc689Smrg rmdir "$lockdir" 40189afc689Smrg break 40289afc689Smrg else 40389afc689Smrg # If the lock is being held by a different process, wait 40489afc689Smrg # until the winning process is done or we timeout. 40589afc689Smrg while test -d "$lockdir" && test $i -gt 0; do 40689afc689Smrg sleep 1 40789afc689Smrg i=`expr $i - 1` 40889afc689Smrg done 40989afc689Smrg fi 41089afc689Smrg i=`expr $i - 1` 41189afc689Smrg done 41289afc689Smrg trap - 1 2 13 15 41389afc689Smrg if test $i -le 0; then 41489afc689Smrg echo "$0: failed to acquire lock after $numtries attempts" >&2 41589afc689Smrg echo "$0: check lockdir '$lockdir'" >&2 41689afc689Smrg exit 1 41789afc689Smrg fi 418bccedf53Smrg 41989afc689Smrg if test $stat -ne 0; then 420bccedf53Smrg rm -f "$tmpdepfile" 421bccedf53Smrg exit $stat 422bccedf53Smrg fi 423bccedf53Smrg rm -f "$depfile" 424bccedf53Smrg # Each line is of the form `foo.o: dependent.h', 425bccedf53Smrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 426bccedf53Smrg # Do two passes, one to just change these to 427bccedf53Smrg # `$object: dependent.h' and one to simply `dependent.h:'. 428bccedf53Smrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 429bccedf53Smrg # Some versions of the HPUX 10.20 sed can't process this invocation 430bccedf53Smrg # correctly. Breaking it into two sed invocations is a workaround. 43189afc689Smrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 43289afc689Smrg | sed -e 's/$/ :/' >> "$depfile" 433bccedf53Smrg rm -f "$tmpdepfile" 434bccedf53Smrg ;; 435bccedf53Smrg 4367c5f6000Smrghp2) 4377c5f6000Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 4387c5f6000Smrg # compilers, which have integrated preprocessors. The correct option 4397c5f6000Smrg # to use with these is +Maked; it writes dependencies to a file named 4407c5f6000Smrg # 'foo.d', which lands next to the object file, wherever that 4417c5f6000Smrg # happens to be. 4427c5f6000Smrg # Much of this is similar to the tru64 case; see comments there. 44389afc689Smrg set_dir_from "$object" 44489afc689Smrg set_base_from "$object" 4457c5f6000Smrg if test "$libtool" = yes; then 4467c5f6000Smrg tmpdepfile1=$dir$base.d 4477c5f6000Smrg tmpdepfile2=$dir.libs/$base.d 4487c5f6000Smrg "$@" -Wc,+Maked 4497c5f6000Smrg else 4507c5f6000Smrg tmpdepfile1=$dir$base.d 4517c5f6000Smrg tmpdepfile2=$dir$base.d 4527c5f6000Smrg "$@" +Maked 4537c5f6000Smrg fi 4547c5f6000Smrg stat=$? 45589afc689Smrg if test $stat -ne 0; then 4567c5f6000Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 4577c5f6000Smrg exit $stat 4587c5f6000Smrg fi 4597c5f6000Smrg 4607c5f6000Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 4617c5f6000Smrg do 4627c5f6000Smrg test -f "$tmpdepfile" && break 4637c5f6000Smrg done 4647c5f6000Smrg if test -f "$tmpdepfile"; then 46589afc689Smrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 46689afc689Smrg # Add 'dependent.h:' lines. 4677c5f6000Smrg sed -ne '2,${ 46889afc689Smrg s/^ *// 46989afc689Smrg s/ \\*$// 47089afc689Smrg s/$/:/ 47189afc689Smrg p 47289afc689Smrg }' "$tmpdepfile" >> "$depfile" 4737c5f6000Smrg else 47489afc689Smrg make_dummy_depfile 4757c5f6000Smrg fi 4767c5f6000Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 4777c5f6000Smrg ;; 4787c5f6000Smrg 479bccedf53Smrgtru64) 48089afc689Smrg # The Tru64 compiler uses -MD to generate dependencies as a side 48189afc689Smrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 48289afc689Smrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 48389afc689Smrg # dependencies in 'foo.d' instead, so we check for that too. 48489afc689Smrg # Subdirectories are respected. 48589afc689Smrg set_dir_from "$object" 48689afc689Smrg set_base_from "$object" 48789afc689Smrg 48889afc689Smrg if test "$libtool" = yes; then 48989afc689Smrg # Libtool generates 2 separate objects for the 2 libraries. These 49089afc689Smrg # two compilations output dependencies in $dir.libs/$base.o.d and 49189afc689Smrg # in $dir$base.o.d. We have to check for both files, because 49289afc689Smrg # one of the two compilations can be disabled. We should prefer 49389afc689Smrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 49489afc689Smrg # automatically cleaned when .libs/ is deleted, while ignoring 49589afc689Smrg # the former would cause a distcleancheck panic. 49689afc689Smrg tmpdepfile1=$dir$base.o.d # libtool 1.5 49789afc689Smrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 49889afc689Smrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 49989afc689Smrg "$@" -Wc,-MD 50089afc689Smrg else 50189afc689Smrg tmpdepfile1=$dir$base.d 50289afc689Smrg tmpdepfile2=$dir$base.d 50389afc689Smrg tmpdepfile3=$dir$base.d 50489afc689Smrg "$@" -MD 50589afc689Smrg fi 50689afc689Smrg 50789afc689Smrg stat=$? 50889afc689Smrg if test $stat -ne 0; then 50989afc689Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51089afc689Smrg exit $stat 51189afc689Smrg fi 51289afc689Smrg 51389afc689Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 51489afc689Smrg do 51589afc689Smrg test -f "$tmpdepfile" && break 51689afc689Smrg done 51789afc689Smrg # Same post-processing that is required for AIX mode. 51889afc689Smrg aix_post_process_depfile 51989afc689Smrg ;; 520bccedf53Smrg 5211b1389eeSmrgmsvc7) 5221b1389eeSmrg if test "$libtool" = yes; then 5231b1389eeSmrg showIncludes=-Wc,-showIncludes 5241b1389eeSmrg else 5251b1389eeSmrg showIncludes=-showIncludes 5261b1389eeSmrg fi 5271b1389eeSmrg "$@" $showIncludes > "$tmpdepfile" 5281b1389eeSmrg stat=$? 5291b1389eeSmrg grep -v '^Note: including file: ' "$tmpdepfile" 53089afc689Smrg if test $stat -ne 0; then 5311b1389eeSmrg rm -f "$tmpdepfile" 5321b1389eeSmrg exit $stat 5331b1389eeSmrg fi 5341b1389eeSmrg rm -f "$depfile" 5351b1389eeSmrg echo "$object : \\" > "$depfile" 5361b1389eeSmrg # The first sed program below extracts the file names and escapes 5371b1389eeSmrg # backslashes for cygpath. The second sed program outputs the file 5381b1389eeSmrg # name when reading, but also accumulates all include files in the 5391b1389eeSmrg # hold buffer in order to output them again at the end. This only 5401b1389eeSmrg # works with sed implementations that can handle large buffers. 5411b1389eeSmrg sed < "$tmpdepfile" -n ' 5421b1389eeSmrg/^Note: including file: *\(.*\)/ { 5431b1389eeSmrg s//\1/ 5441b1389eeSmrg s/\\/\\\\/g 5451b1389eeSmrg p 5461b1389eeSmrg}' | $cygpath_u | sort -u | sed -n ' 5471b1389eeSmrgs/ /\\ /g 54889afc689Smrgs/\(.*\)/'"$tab"'\1 \\/p 5491b1389eeSmrgs/.\(.*\) \\/\1:/ 5501b1389eeSmrgH 5511b1389eeSmrg$ { 55289afc689Smrg s/.*/'"$tab"'/ 5531b1389eeSmrg G 5541b1389eeSmrg p 5551b1389eeSmrg}' >> "$depfile" 55689afc689Smrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 5571b1389eeSmrg rm -f "$tmpdepfile" 5581b1389eeSmrg ;; 5591b1389eeSmrg 5601b1389eeSmrgmsvc7msys) 5611b1389eeSmrg # This case exists only to let depend.m4 do its work. It works by 5621b1389eeSmrg # looking at the text of this script. This case will never be run, 5631b1389eeSmrg # since it is checked for above. 5641b1389eeSmrg exit 1 5651b1389eeSmrg ;; 5661b1389eeSmrg 567bccedf53Smrg#nosideeffect) 568bccedf53Smrg # This comment above is used by automake to tell side-effect 569bccedf53Smrg # dependency tracking mechanisms from slower ones. 570bccedf53Smrg 571bccedf53Smrgdashmstdout) 572bccedf53Smrg # Important note: in order to support this mode, a compiler *must* 573bccedf53Smrg # always write the preprocessed file to stdout, regardless of -o. 574bccedf53Smrg "$@" || exit $? 575bccedf53Smrg 576bccedf53Smrg # Remove the call to Libtool. 577bccedf53Smrg if test "$libtool" = yes; then 5787c5f6000Smrg while test "X$1" != 'X--mode=compile'; do 579bccedf53Smrg shift 580bccedf53Smrg done 581bccedf53Smrg shift 582bccedf53Smrg fi 583bccedf53Smrg 58489afc689Smrg # Remove '-o $object'. 585bccedf53Smrg IFS=" " 586bccedf53Smrg for arg 587bccedf53Smrg do 588bccedf53Smrg case $arg in 589bccedf53Smrg -o) 590bccedf53Smrg shift 591bccedf53Smrg ;; 592bccedf53Smrg $object) 593bccedf53Smrg shift 594bccedf53Smrg ;; 595bccedf53Smrg *) 596bccedf53Smrg set fnord "$@" "$arg" 597bccedf53Smrg shift # fnord 598bccedf53Smrg shift # $arg 599bccedf53Smrg ;; 600bccedf53Smrg esac 601bccedf53Smrg done 602bccedf53Smrg 603bccedf53Smrg test -z "$dashmflag" && dashmflag=-M 60489afc689Smrg # Require at least two characters before searching for ':' 605bccedf53Smrg # in the target name. This is to cope with DOS-style filenames: 60689afc689Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 607bccedf53Smrg "$@" $dashmflag | 60889afc689Smrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 609bccedf53Smrg rm -f "$depfile" 610bccedf53Smrg cat < "$tmpdepfile" > "$depfile" 61189afc689Smrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 61289afc689Smrg # correctly. Breaking it into two sed invocations is a workaround. 61389afc689Smrg tr ' ' "$nl" < "$tmpdepfile" \ 61489afc689Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 61589afc689Smrg | sed -e 's/$/ :/' >> "$depfile" 616bccedf53Smrg rm -f "$tmpdepfile" 617bccedf53Smrg ;; 618bccedf53Smrg 619bccedf53SmrgdashXmstdout) 620bccedf53Smrg # This case only exists to satisfy depend.m4. It is never actually 621bccedf53Smrg # run, as this mode is specially recognized in the preamble. 622bccedf53Smrg exit 1 623bccedf53Smrg ;; 624bccedf53Smrg 625bccedf53Smrgmakedepend) 626bccedf53Smrg "$@" || exit $? 627bccedf53Smrg # Remove any Libtool call 628bccedf53Smrg if test "$libtool" = yes; then 6297c5f6000Smrg while test "X$1" != 'X--mode=compile'; do 630bccedf53Smrg shift 631bccedf53Smrg done 632bccedf53Smrg shift 633bccedf53Smrg fi 634bccedf53Smrg # X makedepend 635bccedf53Smrg shift 6367c5f6000Smrg cleared=no eat=no 6377c5f6000Smrg for arg 6387c5f6000Smrg do 639bccedf53Smrg case $cleared in 640bccedf53Smrg no) 641bccedf53Smrg set ""; shift 642bccedf53Smrg cleared=yes ;; 643bccedf53Smrg esac 6447c5f6000Smrg if test $eat = yes; then 6457c5f6000Smrg eat=no 6467c5f6000Smrg continue 6477c5f6000Smrg fi 648bccedf53Smrg case "$arg" in 649bccedf53Smrg -D*|-I*) 650bccedf53Smrg set fnord "$@" "$arg"; shift ;; 651bccedf53Smrg # Strip any option that makedepend may not understand. Remove 652bccedf53Smrg # the object too, otherwise makedepend will parse it as a source file. 6537c5f6000Smrg -arch) 6547c5f6000Smrg eat=yes ;; 655bccedf53Smrg -*|$object) 656bccedf53Smrg ;; 657bccedf53Smrg *) 658bccedf53Smrg set fnord "$@" "$arg"; shift ;; 659bccedf53Smrg esac 660bccedf53Smrg done 6617c5f6000Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 662bccedf53Smrg touch "$tmpdepfile" 663bccedf53Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 664bccedf53Smrg rm -f "$depfile" 6651b1389eeSmrg # makedepend may prepend the VPATH from the source file name to the object. 6661b1389eeSmrg # No need to regex-escape $object, excess matching of '.' is harmless. 6671b1389eeSmrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 66889afc689Smrg # Some versions of the HPUX 10.20 sed can't process the last invocation 66989afc689Smrg # correctly. Breaking it into two sed invocations is a workaround. 67089afc689Smrg sed '1,2d' "$tmpdepfile" \ 67189afc689Smrg | tr ' ' "$nl" \ 67289afc689Smrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 67389afc689Smrg | sed -e 's/$/ :/' >> "$depfile" 674bccedf53Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 675bccedf53Smrg ;; 676bccedf53Smrg 677bccedf53Smrgcpp) 678bccedf53Smrg # Important note: in order to support this mode, a compiler *must* 679bccedf53Smrg # always write the preprocessed file to stdout. 680bccedf53Smrg "$@" || exit $? 681bccedf53Smrg 682bccedf53Smrg # Remove the call to Libtool. 683bccedf53Smrg if test "$libtool" = yes; then 6847c5f6000Smrg while test "X$1" != 'X--mode=compile'; do 685bccedf53Smrg shift 686bccedf53Smrg done 687bccedf53Smrg shift 688bccedf53Smrg fi 689bccedf53Smrg 69089afc689Smrg # Remove '-o $object'. 691bccedf53Smrg IFS=" " 692bccedf53Smrg for arg 693bccedf53Smrg do 694bccedf53Smrg case $arg in 695bccedf53Smrg -o) 696bccedf53Smrg shift 697bccedf53Smrg ;; 698bccedf53Smrg $object) 699bccedf53Smrg shift 700bccedf53Smrg ;; 701bccedf53Smrg *) 702bccedf53Smrg set fnord "$@" "$arg" 703bccedf53Smrg shift # fnord 704bccedf53Smrg shift # $arg 705bccedf53Smrg ;; 706bccedf53Smrg esac 707bccedf53Smrg done 708bccedf53Smrg 70989afc689Smrg "$@" -E \ 71089afc689Smrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71189afc689Smrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 71289afc689Smrg | sed '$ s: \\$::' > "$tmpdepfile" 713bccedf53Smrg rm -f "$depfile" 714bccedf53Smrg echo "$object : \\" > "$depfile" 715bccedf53Smrg cat < "$tmpdepfile" >> "$depfile" 716bccedf53Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 717bccedf53Smrg rm -f "$tmpdepfile" 718bccedf53Smrg ;; 719bccedf53Smrg 720bccedf53Smrgmsvisualcpp) 721bccedf53Smrg # Important note: in order to support this mode, a compiler *must* 7227c5f6000Smrg # always write the preprocessed file to stdout. 723bccedf53Smrg "$@" || exit $? 7247c5f6000Smrg 7257c5f6000Smrg # Remove the call to Libtool. 7267c5f6000Smrg if test "$libtool" = yes; then 7277c5f6000Smrg while test "X$1" != 'X--mode=compile'; do 7287c5f6000Smrg shift 7297c5f6000Smrg done 7307c5f6000Smrg shift 7317c5f6000Smrg fi 7327c5f6000Smrg 733bccedf53Smrg IFS=" " 734bccedf53Smrg for arg 735bccedf53Smrg do 736bccedf53Smrg case "$arg" in 7377c5f6000Smrg -o) 7387c5f6000Smrg shift 7397c5f6000Smrg ;; 7407c5f6000Smrg $object) 7417c5f6000Smrg shift 7427c5f6000Smrg ;; 743bccedf53Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 74489afc689Smrg set fnord "$@" 74589afc689Smrg shift 74689afc689Smrg shift 74789afc689Smrg ;; 748bccedf53Smrg *) 74989afc689Smrg set fnord "$@" "$arg" 75089afc689Smrg shift 75189afc689Smrg shift 75289afc689Smrg ;; 753bccedf53Smrg esac 754bccedf53Smrg done 7557c5f6000Smrg "$@" -E 2>/dev/null | 7567c5f6000Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 757bccedf53Smrg rm -f "$depfile" 758bccedf53Smrg echo "$object : \\" > "$depfile" 75989afc689Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 76089afc689Smrg echo "$tab" >> "$depfile" 7617c5f6000Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 762bccedf53Smrg rm -f "$tmpdepfile" 763bccedf53Smrg ;; 764bccedf53Smrg 7657c5f6000Smrgmsvcmsys) 7667c5f6000Smrg # This case exists only to let depend.m4 do its work. It works by 7677c5f6000Smrg # looking at the text of this script. This case will never be run, 7687c5f6000Smrg # since it is checked for above. 7697c5f6000Smrg exit 1 7707c5f6000Smrg ;; 7717c5f6000Smrg 772bccedf53Smrgnone) 773bccedf53Smrg exec "$@" 774bccedf53Smrg ;; 775bccedf53Smrg 776bccedf53Smrg*) 777bccedf53Smrg echo "Unknown depmode $depmode" 1>&2 778bccedf53Smrg exit 1 779bccedf53Smrg ;; 780bccedf53Smrgesac 781bccedf53Smrg 782bccedf53Smrgexit 0 7837c5f6000Smrg 7847c5f6000Smrg# Local Variables: 7857c5f6000Smrg# mode: shell-script 7867c5f6000Smrg# sh-indentation: 2 787ec318dbfSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 7887c5f6000Smrg# time-stamp-start: "scriptversion=" 7897c5f6000Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 790ec318dbfSmrg# time-stamp-time-zone: "UTC0" 7917c5f6000Smrg# time-stamp-end: "; # UTC" 7927c5f6000Smrg# End: 793