1659607e0Smrg#! /bin/sh 2659607e0Smrg# depcomp - compile a program generating dependencies as side-effects 3659607e0Smrg 4370b807fSmrgscriptversion=2018-03-07.03; # UTC 5659607e0Smrg 6370b807fSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7659607e0Smrg 8659607e0Smrg# This program is free software; you can redistribute it and/or modify 9659607e0Smrg# it under the terms of the GNU General Public License as published by 10659607e0Smrg# the Free Software Foundation; either version 2, or (at your option) 11659607e0Smrg# any later version. 12659607e0Smrg 13659607e0Smrg# This program is distributed in the hope that it will be useful, 14659607e0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15659607e0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16659607e0Smrg# GNU General Public License for more details. 17659607e0Smrg 18659607e0Smrg# You should have received a copy of the GNU General Public License 19370b807fSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20659607e0Smrg 21659607e0Smrg# As a special exception to the GNU General Public License, if you 22659607e0Smrg# distribute this file as part of a program that contains a 23659607e0Smrg# configuration script generated by Autoconf, you may include it under 24659607e0Smrg# the same distribution terms that you use for the rest of that program. 25659607e0Smrg 26659607e0Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. 27659607e0Smrg 28659607e0Smrgcase $1 in 29659607e0Smrg '') 30370b807fSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 31370b807fSmrg exit 1; 32370b807fSmrg ;; 33659607e0Smrg -h | --h*) 34659607e0Smrg cat <<\EOF 35659607e0SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS] 36659607e0Smrg 37659607e0SmrgRun PROGRAMS ARGS to compile a file, generating dependencies 38659607e0Smrgas side-effects. 39659607e0Smrg 40659607e0SmrgEnvironment variables: 41659607e0Smrg depmode Dependency tracking mode. 42a73597f9Smrg source Source file read by 'PROGRAMS ARGS'. 43a73597f9Smrg object Object file output by 'PROGRAMS ARGS'. 44659607e0Smrg DEPDIR directory where to store dependencies. 45659607e0Smrg depfile Dependency file to output. 46a73597f9Smrg tmpdepfile Temporary file to use when outputting dependencies. 47659607e0Smrg libtool Whether libtool is used (yes/no). 48659607e0Smrg 49659607e0SmrgReport bugs to <bug-automake@gnu.org>. 50659607e0SmrgEOF 51659607e0Smrg exit $? 52659607e0Smrg ;; 53659607e0Smrg -v | --v*) 54659607e0Smrg echo "depcomp $scriptversion" 55659607e0Smrg exit $? 56659607e0Smrg ;; 57659607e0Smrgesac 58659607e0Smrg 59370b807fSmrg# Get the directory component of the given path, and save it in the 60370b807fSmrg# global variables '$dir'. Note that this directory component will 61370b807fSmrg# be either empty or ending with a '/' character. This is deliberate. 62370b807fSmrgset_dir_from () 63370b807fSmrg{ 64370b807fSmrg case $1 in 65370b807fSmrg */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; 66370b807fSmrg *) dir=;; 67370b807fSmrg esac 68370b807fSmrg} 69370b807fSmrg 70370b807fSmrg# Get the suffix-stripped basename of the given path, and save it the 71370b807fSmrg# global variable '$base'. 72370b807fSmrgset_base_from () 73370b807fSmrg{ 74370b807fSmrg base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` 75370b807fSmrg} 76370b807fSmrg 77370b807fSmrg# If no dependency file was actually created by the compiler invocation, 78370b807fSmrg# we still have to create a dummy depfile, to avoid errors with the 79370b807fSmrg# Makefile "include basename.Plo" scheme. 80370b807fSmrgmake_dummy_depfile () 81370b807fSmrg{ 82370b807fSmrg echo "#dummy" > "$depfile" 83370b807fSmrg} 84370b807fSmrg 85370b807fSmrg# Factor out some common post-processing of the generated depfile. 86370b807fSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set. 87370b807fSmrgaix_post_process_depfile () 88370b807fSmrg{ 89370b807fSmrg # If the compiler actually managed to produce a dependency file, 90370b807fSmrg # post-process it. 91370b807fSmrg if test -f "$tmpdepfile"; then 92370b807fSmrg # Each line is of the form 'foo.o: dependency.h'. 93370b807fSmrg # Do two passes, one to just change these to 94370b807fSmrg # $object: dependency.h 95370b807fSmrg # and one to simply output 96370b807fSmrg # dependency.h: 97370b807fSmrg # which is needed to avoid the deleted-header problem. 98370b807fSmrg { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" 99370b807fSmrg sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" 100370b807fSmrg } > "$depfile" 101370b807fSmrg rm -f "$tmpdepfile" 102370b807fSmrg else 103370b807fSmrg make_dummy_depfile 104370b807fSmrg fi 105370b807fSmrg} 106370b807fSmrg 107a73597f9Smrg# A tabulation character. 108a73597f9Smrgtab=' ' 109a73597f9Smrg# A newline character. 110a73597f9Smrgnl=' 111a73597f9Smrg' 112370b807fSmrg# Character ranges might be problematic outside the C locale. 113370b807fSmrg# These definitions help. 114370b807fSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ 115370b807fSmrglower=abcdefghijklmnopqrstuvwxyz 116370b807fSmrgdigits=0123456789 117370b807fSmrgalpha=${upper}${lower} 118a73597f9Smrg 119659607e0Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then 120659607e0Smrg echo "depcomp: Variables source, object and depmode must be set" 1>&2 121659607e0Smrg exit 1 122659607e0Smrgfi 123659607e0Smrg 124659607e0Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 125659607e0Smrgdepfile=${depfile-`echo "$object" | 126659607e0Smrg sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 127659607e0Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 128659607e0Smrg 129659607e0Smrgrm -f "$tmpdepfile" 130659607e0Smrg 131370b807fSmrg# Avoid interferences from the environment. 132370b807fSmrggccflag= dashmflag= 133370b807fSmrg 134659607e0Smrg# Some modes work just like other modes, but use different flags. We 135659607e0Smrg# parameterize here, but still list the modes in the big case below, 136659607e0Smrg# to make depend.m4 easier to write. Note that we *cannot* use a case 137659607e0Smrg# here, because this file can only contain one case statement. 138659607e0Smrgif test "$depmode" = hp; then 139659607e0Smrg # HP compiler uses -M and no extra arg. 140659607e0Smrg gccflag=-M 141659607e0Smrg depmode=gcc 142659607e0Smrgfi 143659607e0Smrg 144659607e0Smrgif test "$depmode" = dashXmstdout; then 145370b807fSmrg # This is just like dashmstdout with a different argument. 146370b807fSmrg dashmflag=-xM 147370b807fSmrg depmode=dashmstdout 148659607e0Smrgfi 149659607e0Smrg 150b73be646Smrgcygpath_u="cygpath -u -f -" 151b73be646Smrgif test "$depmode" = msvcmsys; then 152370b807fSmrg # This is just like msvisualcpp but w/o cygpath translation. 153370b807fSmrg # Just convert the backslash-escaped backslashes to single forward 154370b807fSmrg # slashes to satisfy depend.m4 155370b807fSmrg cygpath_u='sed s,\\\\,/,g' 156370b807fSmrg depmode=msvisualcpp 157b73be646Smrgfi 158b73be646Smrg 159a73597f9Smrgif test "$depmode" = msvc7msys; then 160370b807fSmrg # This is just like msvc7 but w/o cygpath translation. 161370b807fSmrg # Just convert the backslash-escaped backslashes to single forward 162370b807fSmrg # slashes to satisfy depend.m4 163370b807fSmrg cygpath_u='sed s,\\\\,/,g' 164370b807fSmrg depmode=msvc7 165a73597f9Smrgfi 166a73597f9Smrg 167a73597f9Smrgif test "$depmode" = xlc; then 168370b807fSmrg # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. 169370b807fSmrg gccflag=-qmakedep=gcc,-MF 170370b807fSmrg depmode=gcc 171a73597f9Smrgfi 172a73597f9Smrg 173659607e0Smrgcase "$depmode" in 174659607e0Smrggcc3) 175659607e0Smrg## gcc 3 implements dependency tracking that does exactly what 176659607e0Smrg## we want. Yay! Note: for some reason libtool 1.4 doesn't like 177659607e0Smrg## it if -MD -MP comes after the -MF stuff. Hmm. 178659607e0Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon 179659607e0Smrg## the command line argument order; so add the flags where they 180659607e0Smrg## appear in depend2.am. Note that the slowdown incurred here 181659607e0Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this. 182659607e0Smrg for arg 183659607e0Smrg do 184659607e0Smrg case $arg in 185659607e0Smrg -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 186659607e0Smrg *) set fnord "$@" "$arg" ;; 187659607e0Smrg esac 188659607e0Smrg shift # fnord 189659607e0Smrg shift # $arg 190659607e0Smrg done 191659607e0Smrg "$@" 192659607e0Smrg stat=$? 193370b807fSmrg if test $stat -ne 0; then 194659607e0Smrg rm -f "$tmpdepfile" 195659607e0Smrg exit $stat 196659607e0Smrg fi 197659607e0Smrg mv "$tmpdepfile" "$depfile" 198659607e0Smrg ;; 199659607e0Smrg 200659607e0Smrggcc) 201370b807fSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. 202370b807fSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. 203370b807fSmrg## (see the conditional assignment to $gccflag above). 204659607e0Smrg## There are various ways to get dependency output from gcc. Here's 205659607e0Smrg## why we pick this rather obscure method: 206659607e0Smrg## - Don't want to use -MD because we'd like the dependencies to end 207659607e0Smrg## up in a subdir. Having to rename by hand is ugly. 208659607e0Smrg## (We might end up doing this anyway to support other compilers.) 209659607e0Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 210370b807fSmrg## -MM, not -M (despite what the docs say). Also, it might not be 211370b807fSmrg## supported by the other compilers which use the 'gcc' depmode. 212659607e0Smrg## - Using -M directly means running the compiler twice (even worse 213659607e0Smrg## than renaming). 214659607e0Smrg if test -z "$gccflag"; then 215659607e0Smrg gccflag=-MD, 216659607e0Smrg fi 217659607e0Smrg "$@" -Wp,"$gccflag$tmpdepfile" 218659607e0Smrg stat=$? 219370b807fSmrg if test $stat -ne 0; then 220659607e0Smrg rm -f "$tmpdepfile" 221659607e0Smrg exit $stat 222659607e0Smrg fi 223659607e0Smrg rm -f "$depfile" 224659607e0Smrg echo "$object : \\" > "$depfile" 225370b807fSmrg # The second -e expression handles DOS-style file names with drive 226370b807fSmrg # letters. 227659607e0Smrg sed -e 's/^[^:]*: / /' \ 228659607e0Smrg -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 229a73597f9Smrg## This next piece of magic avoids the "deleted header file" problem. 230659607e0Smrg## The problem is that when a header file which appears in a .P file 231659607e0Smrg## is deleted, the dependency causes make to die (because there is 232659607e0Smrg## typically no way to rebuild the header). We avoid this by adding 233659607e0Smrg## dummy dependencies for each header file. Too bad gcc doesn't do 234659607e0Smrg## this for us directly. 235a73597f9Smrg## Some versions of gcc put a space before the ':'. On the theory 236659607e0Smrg## that the space means something, we add a space to the output as 237a73597f9Smrg## well. hp depmode also adds that space, but also prefixes the VPATH 238a73597f9Smrg## to the object. Take care to not repeat it in the output. 239659607e0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation 240659607e0Smrg## correctly. Breaking it into two sed invocations is a workaround. 241370b807fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 242370b807fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 243370b807fSmrg | sed -e 's/$/ :/' >> "$depfile" 244659607e0Smrg rm -f "$tmpdepfile" 245659607e0Smrg ;; 246659607e0Smrg 247659607e0Smrghp) 248659607e0Smrg # This case exists only to let depend.m4 do its work. It works by 249659607e0Smrg # looking at the text of this script. This case will never be run, 250659607e0Smrg # since it is checked for above. 251659607e0Smrg exit 1 252659607e0Smrg ;; 253659607e0Smrg 254659607e0Smrgsgi) 255659607e0Smrg if test "$libtool" = yes; then 256659607e0Smrg "$@" "-Wp,-MDupdate,$tmpdepfile" 257659607e0Smrg else 258659607e0Smrg "$@" -MDupdate "$tmpdepfile" 259659607e0Smrg fi 260659607e0Smrg stat=$? 261370b807fSmrg if test $stat -ne 0; then 262659607e0Smrg rm -f "$tmpdepfile" 263659607e0Smrg exit $stat 264659607e0Smrg fi 265659607e0Smrg rm -f "$depfile" 266659607e0Smrg 267659607e0Smrg if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 268659607e0Smrg echo "$object : \\" > "$depfile" 269659607e0Smrg # Clip off the initial element (the dependent). Don't try to be 270659607e0Smrg # clever and replace this with sed code, as IRIX sed won't handle 271659607e0Smrg # lines with more than a fixed number of characters (4096 in 272659607e0Smrg # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 273a73597f9Smrg # the IRIX cc adds comments like '#:fec' to the end of the 274659607e0Smrg # dependency line. 275a73597f9Smrg tr ' ' "$nl" < "$tmpdepfile" \ 276370b807fSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ 277370b807fSmrg | tr "$nl" ' ' >> "$depfile" 278b73be646Smrg echo >> "$depfile" 279659607e0Smrg # The second pass generates a dummy entry for each header file. 280a73597f9Smrg tr ' ' "$nl" < "$tmpdepfile" \ 281370b807fSmrg | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 282370b807fSmrg >> "$depfile" 283659607e0Smrg else 284370b807fSmrg make_dummy_depfile 285659607e0Smrg fi 286659607e0Smrg rm -f "$tmpdepfile" 287659607e0Smrg ;; 288659607e0Smrg 289a73597f9Smrgxlc) 290a73597f9Smrg # This case exists only to let depend.m4 do its work. It works by 291a73597f9Smrg # looking at the text of this script. This case will never be run, 292a73597f9Smrg # since it is checked for above. 293a73597f9Smrg exit 1 294a73597f9Smrg ;; 295a73597f9Smrg 296659607e0Smrgaix) 297659607e0Smrg # The C for AIX Compiler uses -M and outputs the dependencies 298659607e0Smrg # in a .u file. In older versions, this file always lives in the 299a73597f9Smrg # current directory. Also, the AIX compiler puts '$object:' at the 300659607e0Smrg # start of each line; $object doesn't have directory information. 301659607e0Smrg # Version 6 uses the directory in both cases. 302370b807fSmrg set_dir_from "$object" 303370b807fSmrg set_base_from "$object" 304659607e0Smrg if test "$libtool" = yes; then 305fc27e79cSmrg tmpdepfile1=$dir$base.u 306fc27e79cSmrg tmpdepfile2=$base.u 307fc27e79cSmrg tmpdepfile3=$dir.libs/$base.u 308659607e0Smrg "$@" -Wc,-M 309659607e0Smrg else 310fc27e79cSmrg tmpdepfile1=$dir$base.u 311fc27e79cSmrg tmpdepfile2=$dir$base.u 312fc27e79cSmrg tmpdepfile3=$dir$base.u 313659607e0Smrg "$@" -M 314659607e0Smrg fi 315659607e0Smrg stat=$? 316370b807fSmrg if test $stat -ne 0; then 317fc27e79cSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 318659607e0Smrg exit $stat 319659607e0Smrg fi 320659607e0Smrg 321fc27e79cSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 322fc27e79cSmrg do 323fc27e79cSmrg test -f "$tmpdepfile" && break 324fc27e79cSmrg done 325370b807fSmrg aix_post_process_depfile 326370b807fSmrg ;; 327370b807fSmrg 328370b807fSmrgtcc) 329370b807fSmrg # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 330370b807fSmrg # FIXME: That version still under development at the moment of writing. 331370b807fSmrg # Make that this statement remains true also for stable, released 332370b807fSmrg # versions. 333370b807fSmrg # It will wrap lines (doesn't matter whether long or short) with a 334370b807fSmrg # trailing '\', as in: 335370b807fSmrg # 336370b807fSmrg # foo.o : \ 337370b807fSmrg # foo.c \ 338370b807fSmrg # foo.h \ 339370b807fSmrg # 340370b807fSmrg # It will put a trailing '\' even on the last line, and will use leading 341370b807fSmrg # spaces rather than leading tabs (at least since its commit 0394caf7 342370b807fSmrg # "Emit spaces for -MD"). 343370b807fSmrg "$@" -MD -MF "$tmpdepfile" 344370b807fSmrg stat=$? 345370b807fSmrg if test $stat -ne 0; then 346370b807fSmrg rm -f "$tmpdepfile" 347370b807fSmrg exit $stat 348659607e0Smrg fi 349370b807fSmrg rm -f "$depfile" 350370b807fSmrg # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. 351370b807fSmrg # We have to change lines of the first kind to '$object: \'. 352370b807fSmrg sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" 353370b807fSmrg # And for each line of the second kind, we have to emit a 'dep.h:' 354370b807fSmrg # dummy dependency, to avoid the deleted-header problem. 355370b807fSmrg sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" 356659607e0Smrg rm -f "$tmpdepfile" 357659607e0Smrg ;; 358659607e0Smrg 359370b807fSmrg## The order of this option in the case statement is important, since the 360370b807fSmrg## shell code in configure will try each of these formats in the order 361370b807fSmrg## listed in this file. A plain '-MD' option would be understood by many 362370b807fSmrg## compilers, so we must ensure this comes after the gcc and icc options. 363370b807fSmrgpgcc) 364370b807fSmrg # Portland's C compiler understands '-MD'. 365370b807fSmrg # Will always output deps to 'file.d' where file is the root name of the 366370b807fSmrg # source file under compilation, even if file resides in a subdirectory. 367370b807fSmrg # The object file name does not affect the name of the '.d' file. 368370b807fSmrg # pgcc 10.2 will output 369659607e0Smrg # foo.o: sub/foo.c sub/foo.h 370370b807fSmrg # and will wrap long lines using '\' : 371659607e0Smrg # foo.o: sub/foo.c ... \ 372659607e0Smrg # sub/foo.h ... \ 373659607e0Smrg # ... 374370b807fSmrg set_dir_from "$object" 375370b807fSmrg # Use the source, not the object, to determine the base name, since 376370b807fSmrg # that's sadly what pgcc will do too. 377370b807fSmrg set_base_from "$source" 378370b807fSmrg tmpdepfile=$base.d 379370b807fSmrg 380370b807fSmrg # For projects that build the same source file twice into different object 381370b807fSmrg # files, the pgcc approach of using the *source* file root name can cause 382370b807fSmrg # problems in parallel builds. Use a locking strategy to avoid stomping on 383370b807fSmrg # the same $tmpdepfile. 384370b807fSmrg lockdir=$base.d-lock 385370b807fSmrg trap " 386370b807fSmrg echo '$0: caught signal, cleaning up...' >&2 387370b807fSmrg rmdir '$lockdir' 388370b807fSmrg exit 1 389370b807fSmrg " 1 2 13 15 390370b807fSmrg numtries=100 391370b807fSmrg i=$numtries 392370b807fSmrg while test $i -gt 0; do 393370b807fSmrg # mkdir is a portable test-and-set. 394370b807fSmrg if mkdir "$lockdir" 2>/dev/null; then 395370b807fSmrg # This process acquired the lock. 396370b807fSmrg "$@" -MD 397370b807fSmrg stat=$? 398370b807fSmrg # Release the lock. 399370b807fSmrg rmdir "$lockdir" 400370b807fSmrg break 401370b807fSmrg else 402370b807fSmrg # If the lock is being held by a different process, wait 403370b807fSmrg # until the winning process is done or we timeout. 404370b807fSmrg while test -d "$lockdir" && test $i -gt 0; do 405370b807fSmrg sleep 1 406370b807fSmrg i=`expr $i - 1` 407370b807fSmrg done 408370b807fSmrg fi 409370b807fSmrg i=`expr $i - 1` 410370b807fSmrg done 411370b807fSmrg trap - 1 2 13 15 412370b807fSmrg if test $i -le 0; then 413370b807fSmrg echo "$0: failed to acquire lock after $numtries attempts" >&2 414370b807fSmrg echo "$0: check lockdir '$lockdir'" >&2 415370b807fSmrg exit 1 416370b807fSmrg fi 417370b807fSmrg 418370b807fSmrg if test $stat -ne 0; then 419659607e0Smrg rm -f "$tmpdepfile" 420659607e0Smrg exit $stat 421659607e0Smrg fi 422659607e0Smrg rm -f "$depfile" 423370b807fSmrg # Each line is of the form `foo.o: dependent.h', 424370b807fSmrg # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 425659607e0Smrg # Do two passes, one to just change these to 426370b807fSmrg # `$object: dependent.h' and one to simply `dependent.h:'. 427370b807fSmrg sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 428370b807fSmrg # Some versions of the HPUX 10.20 sed can't process this invocation 429370b807fSmrg # correctly. Breaking it into two sed invocations is a workaround. 430370b807fSmrg sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ 431370b807fSmrg | sed -e 's/$/ :/' >> "$depfile" 432659607e0Smrg rm -f "$tmpdepfile" 433659607e0Smrg ;; 434659607e0Smrg 435659607e0Smrghp2) 436659607e0Smrg # The "hp" stanza above does not work with aCC (C++) and HP's ia64 437659607e0Smrg # compilers, which have integrated preprocessors. The correct option 438659607e0Smrg # to use with these is +Maked; it writes dependencies to a file named 439659607e0Smrg # 'foo.d', which lands next to the object file, wherever that 440659607e0Smrg # happens to be. 441659607e0Smrg # Much of this is similar to the tru64 case; see comments there. 442370b807fSmrg set_dir_from "$object" 443370b807fSmrg set_base_from "$object" 444659607e0Smrg if test "$libtool" = yes; then 445659607e0Smrg tmpdepfile1=$dir$base.d 446659607e0Smrg tmpdepfile2=$dir.libs/$base.d 447659607e0Smrg "$@" -Wc,+Maked 448659607e0Smrg else 449659607e0Smrg tmpdepfile1=$dir$base.d 450659607e0Smrg tmpdepfile2=$dir$base.d 451659607e0Smrg "$@" +Maked 452659607e0Smrg fi 453659607e0Smrg stat=$? 454370b807fSmrg if test $stat -ne 0; then 455659607e0Smrg rm -f "$tmpdepfile1" "$tmpdepfile2" 456659607e0Smrg exit $stat 457659607e0Smrg fi 458659607e0Smrg 459659607e0Smrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 460659607e0Smrg do 461659607e0Smrg test -f "$tmpdepfile" && break 462659607e0Smrg done 463659607e0Smrg if test -f "$tmpdepfile"; then 464370b807fSmrg sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" 465a73597f9Smrg # Add 'dependent.h:' lines. 466b73be646Smrg sed -ne '2,${ 467370b807fSmrg s/^ *// 468370b807fSmrg s/ \\*$// 469370b807fSmrg s/$/:/ 470370b807fSmrg p 471370b807fSmrg }' "$tmpdepfile" >> "$depfile" 472659607e0Smrg else 473370b807fSmrg make_dummy_depfile 474659607e0Smrg fi 475659607e0Smrg rm -f "$tmpdepfile" "$tmpdepfile2" 476659607e0Smrg ;; 477659607e0Smrg 478659607e0Smrgtru64) 479370b807fSmrg # The Tru64 compiler uses -MD to generate dependencies as a side 480370b807fSmrg # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. 481370b807fSmrg # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 482370b807fSmrg # dependencies in 'foo.d' instead, so we check for that too. 483370b807fSmrg # Subdirectories are respected. 484370b807fSmrg set_dir_from "$object" 485370b807fSmrg set_base_from "$object" 486370b807fSmrg 487370b807fSmrg if test "$libtool" = yes; then 488370b807fSmrg # Libtool generates 2 separate objects for the 2 libraries. These 489370b807fSmrg # two compilations output dependencies in $dir.libs/$base.o.d and 490370b807fSmrg # in $dir$base.o.d. We have to check for both files, because 491370b807fSmrg # one of the two compilations can be disabled. We should prefer 492370b807fSmrg # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 493370b807fSmrg # automatically cleaned when .libs/ is deleted, while ignoring 494370b807fSmrg # the former would cause a distcleancheck panic. 495370b807fSmrg tmpdepfile1=$dir$base.o.d # libtool 1.5 496370b807fSmrg tmpdepfile2=$dir.libs/$base.o.d # Likewise. 497370b807fSmrg tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 498370b807fSmrg "$@" -Wc,-MD 499370b807fSmrg else 500370b807fSmrg tmpdepfile1=$dir$base.d 501370b807fSmrg tmpdepfile2=$dir$base.d 502370b807fSmrg tmpdepfile3=$dir$base.d 503370b807fSmrg "$@" -MD 504370b807fSmrg fi 505370b807fSmrg 506370b807fSmrg stat=$? 507370b807fSmrg if test $stat -ne 0; then 508370b807fSmrg rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 509370b807fSmrg exit $stat 510370b807fSmrg fi 511370b807fSmrg 512370b807fSmrg for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 513370b807fSmrg do 514370b807fSmrg test -f "$tmpdepfile" && break 515370b807fSmrg done 516370b807fSmrg # Same post-processing that is required for AIX mode. 517370b807fSmrg aix_post_process_depfile 518370b807fSmrg ;; 519659607e0Smrg 520a73597f9Smrgmsvc7) 521a73597f9Smrg if test "$libtool" = yes; then 522a73597f9Smrg showIncludes=-Wc,-showIncludes 523a73597f9Smrg else 524a73597f9Smrg showIncludes=-showIncludes 525a73597f9Smrg fi 526a73597f9Smrg "$@" $showIncludes > "$tmpdepfile" 527a73597f9Smrg stat=$? 528a73597f9Smrg grep -v '^Note: including file: ' "$tmpdepfile" 529370b807fSmrg if test $stat -ne 0; then 530a73597f9Smrg rm -f "$tmpdepfile" 531a73597f9Smrg exit $stat 532a73597f9Smrg fi 533a73597f9Smrg rm -f "$depfile" 534a73597f9Smrg echo "$object : \\" > "$depfile" 535a73597f9Smrg # The first sed program below extracts the file names and escapes 536a73597f9Smrg # backslashes for cygpath. The second sed program outputs the file 537a73597f9Smrg # name when reading, but also accumulates all include files in the 538a73597f9Smrg # hold buffer in order to output them again at the end. This only 539a73597f9Smrg # works with sed implementations that can handle large buffers. 540a73597f9Smrg sed < "$tmpdepfile" -n ' 541a73597f9Smrg/^Note: including file: *\(.*\)/ { 542a73597f9Smrg s//\1/ 543a73597f9Smrg s/\\/\\\\/g 544a73597f9Smrg p 545a73597f9Smrg}' | $cygpath_u | sort -u | sed -n ' 546a73597f9Smrgs/ /\\ /g 547a73597f9Smrgs/\(.*\)/'"$tab"'\1 \\/p 548a73597f9Smrgs/.\(.*\) \\/\1:/ 549a73597f9SmrgH 550a73597f9Smrg$ { 551a73597f9Smrg s/.*/'"$tab"'/ 552a73597f9Smrg G 553a73597f9Smrg p 554a73597f9Smrg}' >> "$depfile" 555370b807fSmrg echo >> "$depfile" # make sure the fragment doesn't end with a backslash 556a73597f9Smrg rm -f "$tmpdepfile" 557a73597f9Smrg ;; 558a73597f9Smrg 559a73597f9Smrgmsvc7msys) 560a73597f9Smrg # This case exists only to let depend.m4 do its work. It works by 561a73597f9Smrg # looking at the text of this script. This case will never be run, 562a73597f9Smrg # since it is checked for above. 563a73597f9Smrg exit 1 564a73597f9Smrg ;; 565a73597f9Smrg 566659607e0Smrg#nosideeffect) 567659607e0Smrg # This comment above is used by automake to tell side-effect 568659607e0Smrg # dependency tracking mechanisms from slower ones. 569659607e0Smrg 570659607e0Smrgdashmstdout) 571659607e0Smrg # Important note: in order to support this mode, a compiler *must* 572659607e0Smrg # always write the preprocessed file to stdout, regardless of -o. 573659607e0Smrg "$@" || exit $? 574659607e0Smrg 575659607e0Smrg # Remove the call to Libtool. 576659607e0Smrg if test "$libtool" = yes; then 577b73be646Smrg while test "X$1" != 'X--mode=compile'; do 578659607e0Smrg shift 579659607e0Smrg done 580659607e0Smrg shift 581659607e0Smrg fi 582659607e0Smrg 583a73597f9Smrg # Remove '-o $object'. 584659607e0Smrg IFS=" " 585659607e0Smrg for arg 586659607e0Smrg do 587659607e0Smrg case $arg in 588659607e0Smrg -o) 589659607e0Smrg shift 590659607e0Smrg ;; 591659607e0Smrg $object) 592659607e0Smrg shift 593659607e0Smrg ;; 594659607e0Smrg *) 595659607e0Smrg set fnord "$@" "$arg" 596659607e0Smrg shift # fnord 597659607e0Smrg shift # $arg 598659607e0Smrg ;; 599659607e0Smrg esac 600659607e0Smrg done 601659607e0Smrg 602659607e0Smrg test -z "$dashmflag" && dashmflag=-M 603a73597f9Smrg # Require at least two characters before searching for ':' 604659607e0Smrg # in the target name. This is to cope with DOS-style filenames: 605a73597f9Smrg # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. 606659607e0Smrg "$@" $dashmflag | 607370b807fSmrg sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" 608659607e0Smrg rm -f "$depfile" 609659607e0Smrg cat < "$tmpdepfile" > "$depfile" 610370b807fSmrg # Some versions of the HPUX 10.20 sed can't process this sed invocation 611370b807fSmrg # correctly. Breaking it into two sed invocations is a workaround. 612370b807fSmrg tr ' ' "$nl" < "$tmpdepfile" \ 613370b807fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 614370b807fSmrg | sed -e 's/$/ :/' >> "$depfile" 615659607e0Smrg rm -f "$tmpdepfile" 616659607e0Smrg ;; 617659607e0Smrg 618659607e0SmrgdashXmstdout) 619659607e0Smrg # This case only exists to satisfy depend.m4. It is never actually 620659607e0Smrg # run, as this mode is specially recognized in the preamble. 621659607e0Smrg exit 1 622659607e0Smrg ;; 623659607e0Smrg 624659607e0Smrgmakedepend) 625659607e0Smrg "$@" || exit $? 626659607e0Smrg # Remove any Libtool call 627659607e0Smrg if test "$libtool" = yes; then 628b73be646Smrg while test "X$1" != 'X--mode=compile'; do 629659607e0Smrg shift 630659607e0Smrg done 631659607e0Smrg shift 632659607e0Smrg fi 633659607e0Smrg # X makedepend 634659607e0Smrg shift 635b73be646Smrg cleared=no eat=no 636b73be646Smrg for arg 637b73be646Smrg do 638659607e0Smrg case $cleared in 639659607e0Smrg no) 640659607e0Smrg set ""; shift 641659607e0Smrg cleared=yes ;; 642659607e0Smrg esac 643b73be646Smrg if test $eat = yes; then 644b73be646Smrg eat=no 645b73be646Smrg continue 646b73be646Smrg fi 647659607e0Smrg case "$arg" in 648659607e0Smrg -D*|-I*) 649659607e0Smrg set fnord "$@" "$arg"; shift ;; 650659607e0Smrg # Strip any option that makedepend may not understand. Remove 651659607e0Smrg # the object too, otherwise makedepend will parse it as a source file. 652b73be646Smrg -arch) 653b73be646Smrg eat=yes ;; 654659607e0Smrg -*|$object) 655659607e0Smrg ;; 656659607e0Smrg *) 657659607e0Smrg set fnord "$@" "$arg"; shift ;; 658659607e0Smrg esac 659659607e0Smrg done 660b73be646Smrg obj_suffix=`echo "$object" | sed 's/^.*\././'` 661659607e0Smrg touch "$tmpdepfile" 662659607e0Smrg ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 663659607e0Smrg rm -f "$depfile" 664a73597f9Smrg # makedepend may prepend the VPATH from the source file name to the object. 665a73597f9Smrg # No need to regex-escape $object, excess matching of '.' is harmless. 666a73597f9Smrg sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 667370b807fSmrg # Some versions of the HPUX 10.20 sed can't process the last invocation 668370b807fSmrg # correctly. Breaking it into two sed invocations is a workaround. 669370b807fSmrg sed '1,2d' "$tmpdepfile" \ 670370b807fSmrg | tr ' ' "$nl" \ 671370b807fSmrg | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ 672370b807fSmrg | sed -e 's/$/ :/' >> "$depfile" 673659607e0Smrg rm -f "$tmpdepfile" "$tmpdepfile".bak 674659607e0Smrg ;; 675659607e0Smrg 676659607e0Smrgcpp) 677659607e0Smrg # Important note: in order to support this mode, a compiler *must* 678659607e0Smrg # always write the preprocessed file to stdout. 679659607e0Smrg "$@" || exit $? 680659607e0Smrg 681659607e0Smrg # Remove the call to Libtool. 682659607e0Smrg if test "$libtool" = yes; then 683b73be646Smrg while test "X$1" != 'X--mode=compile'; do 684659607e0Smrg shift 685659607e0Smrg done 686659607e0Smrg shift 687659607e0Smrg fi 688659607e0Smrg 689a73597f9Smrg # Remove '-o $object'. 690659607e0Smrg IFS=" " 691659607e0Smrg for arg 692659607e0Smrg do 693659607e0Smrg case $arg in 694659607e0Smrg -o) 695659607e0Smrg shift 696659607e0Smrg ;; 697659607e0Smrg $object) 698659607e0Smrg shift 699659607e0Smrg ;; 700659607e0Smrg *) 701659607e0Smrg set fnord "$@" "$arg" 702659607e0Smrg shift # fnord 703659607e0Smrg shift # $arg 704659607e0Smrg ;; 705659607e0Smrg esac 706659607e0Smrg done 707659607e0Smrg 708370b807fSmrg "$@" -E \ 709370b807fSmrg | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 710370b807fSmrg -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 711370b807fSmrg | sed '$ s: \\$::' > "$tmpdepfile" 712659607e0Smrg rm -f "$depfile" 713659607e0Smrg echo "$object : \\" > "$depfile" 714659607e0Smrg cat < "$tmpdepfile" >> "$depfile" 715659607e0Smrg sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 716659607e0Smrg rm -f "$tmpdepfile" 717659607e0Smrg ;; 718659607e0Smrg 719659607e0Smrgmsvisualcpp) 720659607e0Smrg # Important note: in order to support this mode, a compiler *must* 721b73be646Smrg # always write the preprocessed file to stdout. 722659607e0Smrg "$@" || exit $? 723b73be646Smrg 724b73be646Smrg # Remove the call to Libtool. 725b73be646Smrg if test "$libtool" = yes; then 726b73be646Smrg while test "X$1" != 'X--mode=compile'; do 727b73be646Smrg shift 728b73be646Smrg done 729b73be646Smrg shift 730b73be646Smrg fi 731b73be646Smrg 732659607e0Smrg IFS=" " 733659607e0Smrg for arg 734659607e0Smrg do 735659607e0Smrg case "$arg" in 736b73be646Smrg -o) 737b73be646Smrg shift 738b73be646Smrg ;; 739b73be646Smrg $object) 740b73be646Smrg shift 741b73be646Smrg ;; 742659607e0Smrg "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 743370b807fSmrg set fnord "$@" 744370b807fSmrg shift 745370b807fSmrg shift 746370b807fSmrg ;; 747659607e0Smrg *) 748370b807fSmrg set fnord "$@" "$arg" 749370b807fSmrg shift 750370b807fSmrg shift 751370b807fSmrg ;; 752659607e0Smrg esac 753659607e0Smrg done 754b73be646Smrg "$@" -E 2>/dev/null | 755b73be646Smrg sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 756659607e0Smrg rm -f "$depfile" 757659607e0Smrg echo "$object : \\" > "$depfile" 758a73597f9Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" 759a73597f9Smrg echo "$tab" >> "$depfile" 760b73be646Smrg sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 761659607e0Smrg rm -f "$tmpdepfile" 762659607e0Smrg ;; 763659607e0Smrg 764b73be646Smrgmsvcmsys) 765b73be646Smrg # This case exists only to let depend.m4 do its work. It works by 766b73be646Smrg # looking at the text of this script. This case will never be run, 767b73be646Smrg # since it is checked for above. 768b73be646Smrg exit 1 769b73be646Smrg ;; 770b73be646Smrg 771659607e0Smrgnone) 772659607e0Smrg exec "$@" 773659607e0Smrg ;; 774659607e0Smrg 775659607e0Smrg*) 776659607e0Smrg echo "Unknown depmode $depmode" 1>&2 777659607e0Smrg exit 1 778659607e0Smrg ;; 779659607e0Smrgesac 780659607e0Smrg 781659607e0Smrgexit 0 782659607e0Smrg 783659607e0Smrg# Local Variables: 784659607e0Smrg# mode: shell-script 785659607e0Smrg# sh-indentation: 2 786370b807fSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 787659607e0Smrg# time-stamp-start: "scriptversion=" 788659607e0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 789370b807fSmrg# time-stamp-time-zone: "UTC0" 790b73be646Smrg# time-stamp-end: "; # UTC" 791659607e0Smrg# End: 792