💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Menkar › files › 04701da536f33a7c39d7bb01b87… captured on 2023-05-24 at 18:26:51. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-03-20)

➡️ Next capture (2023-09-08)

-=-=-=-=-=-=-

0 #! /bin/sh

1 # depcomp - compile a program generating dependencies as side-effects

2

3 scriptversion=2005-07-09.11

4

5 # Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.

6

7 # This program is free software; you can redistribute it and/or modify

8 # it under the terms of the GNU General Public License as published by

9 # the Free Software Foundation; either version 2, or (at your option)

10 # any later version.

11

12 # This program is distributed in the hope that it will be useful,

13 # but WITHOUT ANY WARRANTY; without even the implied warranty of

14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

15 # GNU General Public License for more details.

16

17 # You should have received a copy of the GNU General Public License

18 # along with this program; if not, write to the Free Software

19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA

20 # 02110-1301, USA.

21

22 # As a special exception to the GNU General Public License, if you

23 # distribute this file as part of a program that contains a

24 # configuration script generated by Autoconf, you may include it under

25 # the same distribution terms that you use for the rest of that program.

26

27 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.

28

29 case $1 in

30 '')

31 echo "$0: No command. Try \`$0 --help' for more information." 1>&2

32 exit 1;

33 ;;

34 -h | --h*)

35 cat <<\EOF

36 Usage: depcomp [--help] [--version] PROGRAM [ARGS]

37

38 Run PROGRAMS ARGS to compile a file, generating dependencies

39 as side-effects.

40

41 Environment variables:

42 depmode Dependency tracking mode.

43 source Source file read by `PROGRAMS ARGS'.

44 object Object file output by `PROGRAMS ARGS'.

45 DEPDIR directory where to store dependencies.

46 depfile Dependency file to output.

47 tmpdepfile Temporary file to use when outputing dependencies.

48 libtool Whether libtool is used (yes/no).

49

50 Report bugs to <bug-automake@gnu.org>.

51 EOF

52 exit $?

53 ;;

54 -v | --v*)

55 echo "depcomp $scriptversion"

56 exit $?

57 ;;

58 esac

59

60 if test -z "$depmode" || test -z "$source" || test -z "$object"; then

61 echo "depcomp: Variables source, object and depmode must be set" 1>&2

62 exit 1

63 fi

64

65 # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.

66 depfile=${depfile-`echo "$object" |

67 sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}

68 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}

69

70 rm -f "$tmpdepfile"

71

72 # Some modes work just like other modes, but use different flags. We

73 # parameterize here, but still list the modes in the big case below,

74 # to make depend.m4 easier to write. Note that we *cannot* use a case

75 # here, because this file can only contain one case statement.

76 if test "$depmode" = hp; then

77 # HP compiler uses -M and no extra arg.

78 gccflag=-M

79 depmode=gcc

80 fi

81

82 if test "$depmode" = dashXmstdout; then

83 # This is just like dashmstdout with a different argument.

84 dashmflag=-xM

85 depmode=dashmstdout

86 fi

87

88 case "$depmode" in

89 gcc3)

90 ## gcc 3 implements dependency tracking that does exactly what

91 ## we want. Yay! Note: for some reason libtool 1.4 doesn't like

92 ## it if -MD -MP comes after the -MF stuff. Hmm.

93 "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"

94 stat=$?

95 if test $stat -eq 0; then :

96 else

97 rm -f "$tmpdepfile"

98 exit $stat

99 fi

100 mv "$tmpdepfile" "$depfile"

101 ;;

102

103 gcc)

104 ## There are various ways to get dependency output from gcc. Here's

105 ## why we pick this rather obscure method:

106 ## - Don't want to use -MD because we'd like the dependencies to end

107 ## up in a subdir. Having to rename by hand is ugly.

108 ## (We might end up doing this anyway to support other compilers.)

109 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like

110 ## -MM, not -M (despite what the docs say).

111 ## - Using -M directly means running the compiler twice (even worse

112 ## than renaming).

113 if test -z "$gccflag"; then

114 gccflag=-MD,

115 fi

116 "$@" -Wp,"$gccflag$tmpdepfile"

117 stat=$?

118 if test $stat -eq 0; then :

119 else

120 rm -f "$tmpdepfile"

121 exit $stat

122 fi

123 rm -f "$depfile"

124 echo "$object : \\" > "$depfile"

125 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

126 ## The second -e expression handles DOS-style file names with drive letters.

127 sed -e 's/^[^:]*: / /' \

128 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"

129 ## This next piece of magic avoids the `deleted header file' problem.

130 ## The problem is that when a header file which appears in a .P file

131 ## is deleted, the dependency causes make to die (because there is

132 ## typically no way to rebuild the header). We avoid this by adding

133 ## dummy dependencies for each header file. Too bad gcc doesn't do

134 ## this for us directly.

135 tr ' ' '

136 ' < "$tmpdepfile" |

137 ## Some versions of gcc put a space before the `:'. On the theory

138 ## that the space means something, we add a space to the output as

139 ## well.

140 ## Some versions of the HPUX 10.20 sed can't process this invocation

141 ## correctly. Breaking it into two sed invocations is a workaround.

142 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"

143 rm -f "$tmpdepfile"

144 ;;

145

146 hp)

147 # This case exists only to let depend.m4 do its work. It works by

148 # looking at the text of this script. This case will never be run,

149 # since it is checked for above.

150 exit 1

151 ;;

152

153 sgi)

154 if test "$libtool" = yes; then

155 "$@" "-Wp,-MDupdate,$tmpdepfile"

156 else

157 "$@" -MDupdate "$tmpdepfile"

158 fi

159 stat=$?

160 if test $stat -eq 0; then :

161 else

162 rm -f "$tmpdepfile"

163 exit $stat

164 fi

165 rm -f "$depfile"

166

167 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files

168 echo "$object : \\" > "$depfile"

169

170 # Clip off the initial element (the dependent). Don't try to be

171 # clever and replace this with sed code, as IRIX sed won't handle

172 # lines with more than a fixed number of characters (4096 in

173 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;

174 # the IRIX cc adds comments like `#:fec' to the end of the

175 # dependency line.

176 tr ' ' '

177 ' < "$tmpdepfile" \

178 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \

179 tr '

180 ' ' ' >> $depfile

181 echo >> $depfile

182

183 # The second pass generates a dummy entry for each header file.

184 tr ' ' '

185 ' < "$tmpdepfile" \

186 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \

187 >> $depfile

188 else

189 # The sourcefile does not contain any dependencies, so just

190 # store a dummy comment line, to avoid errors with the Makefile

191 # "include basename.Plo" scheme.

192 echo "#dummy" > "$depfile"

193 fi

194 rm -f "$tmpdepfile"

195 ;;

196

197 aix)

198 # The C for AIX Compiler uses -M and outputs the dependencies

199 # in a .u file. In older versions, this file always lives in the

200 # current directory. Also, the AIX compiler puts `$object:' at the

201 # start of each line; $object doesn't have directory information.

202 # Version 6 uses the directory in both cases.

203 stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`

204 tmpdepfile="$stripped.u"

205 if test "$libtool" = yes; then

206 "$@" -Wc,-M

207 else

208 "$@" -M

209 fi

210 stat=$?

211

212 if test -f "$tmpdepfile"; then :

213 else

214 stripped=`echo "$stripped" | sed 's,^.*/,,'`

215 tmpdepfile="$stripped.u"

216 fi

217

218 if test $stat -eq 0; then :

219 else

220 rm -f "$tmpdepfile"

221 exit $stat

222 fi

223

224 if test -f "$tmpdepfile"; then

225 outname="$stripped.o"

226 # Each line is of the form `foo.o: dependent.h'.

227 # Do two passes, one to just change these to

228 # `$object: dependent.h' and one to simply `dependent.h:'.

229 sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"

230 sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"

231 else

232 # The sourcefile does not contain any dependencies, so just

233 # store a dummy comment line, to avoid errors with the Makefile

234 # "include basename.Plo" scheme.

235 echo "#dummy" > "$depfile"

236 fi

237 rm -f "$tmpdepfile"

238 ;;

239

240 icc)

241 # Intel's C compiler understands `-MD -MF file'. However on

242 # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c

243 # ICC 7.0 will fill foo.d with something like

244 # foo.o: sub/foo.c

245 # foo.o: sub/foo.h

246 # which is wrong. We want:

247 # sub/foo.o: sub/foo.c

248 # sub/foo.o: sub/foo.h

249 # sub/foo.c:

250 # sub/foo.h:

251 # ICC 7.1 will output

252 # foo.o: sub/foo.c sub/foo.h

253 # and will wrap long lines using \ :

254 # foo.o: sub/foo.c ... \

255 # sub/foo.h ... \

256 # ...

257

258 "$@" -MD -MF "$tmpdepfile"

259 stat=$?

260 if test $stat -eq 0; then :

261 else

262 rm -f "$tmpdepfile"

263 exit $stat

264 fi

265 rm -f "$depfile"

266 # Each line is of the form `foo.o: dependent.h',

267 # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.

268 # Do two passes, one to just change these to

269 # `$object: dependent.h' and one to simply `dependent.h:'.

270 sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"

271 # Some versions of the HPUX 10.20 sed can't process this invocation

272 # correctly. Breaking it into two sed invocations is a workaround.

273 sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |

274 sed -e 's/$/ :/' >> "$depfile"

275 rm -f "$tmpdepfile"

276 ;;

277

278 tru64)

279 # The Tru64 compiler uses -MD to generate dependencies as a side

280 # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.

281 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put

282 # dependencies in `foo.d' instead, so we check for that too.

283 # Subdirectories are respected.

284 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`

285 test "x$dir" = "x$object" && dir=

286 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`

287

288 if test "$libtool" = yes; then

289 # With Tru64 cc, shared objects can also be used to make a

290 # static library. This mecanism is used in libtool 1.4 series to

291 # handle both shared and static libraries in a single compilation.

292 # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.

293 #

294 # With libtool 1.5 this exception was removed, and libtool now

295 # generates 2 separate objects for the 2 libraries. These two

296 # compilations output dependencies in in $dir.libs/$base.o.d and

297 # in $dir$base.o.d. We have to check for both files, because

298 # one of the two compilations can be disabled. We should prefer

299 # $dir$base.o.d over $dir.libs/$base.o.d because the latter is

300 # automatically cleaned when .libs/ is deleted, while ignoring

301 # the former would cause a distcleancheck panic.

302 tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4

303 tmpdepfile2=$dir$base.o.d # libtool 1.5

304 tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5

305 tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504

306 "$@" -Wc,-MD

307 else

308 tmpdepfile1=$dir$base.o.d

309 tmpdepfile2=$dir$base.d

310 tmpdepfile3=$dir$base.d

311 tmpdepfile4=$dir$base.d

312 "$@" -MD

313 fi

314

315 stat=$?

316 if test $stat -eq 0; then :

317 else

318 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"

319 exit $stat

320 fi

321

322 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"

323 do

324 test -f "$tmpdepfile" && break

325 done

326 if test -f "$tmpdepfile"; then

327 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"

328 # That's a tab and a space in the [].

329 sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"

330 else

331 echo "#dummy" > "$depfile"

332 fi

333 rm -f "$tmpdepfile"

334 ;;

335

336 #nosideeffect)

337 # This comment above is used by automake to tell side-effect

338 # dependency tracking mechanisms from slower ones.

339

340 dashmstdout)

341 # Important note: in order to support this mode, a compiler *must*

342 # always write the preprocessed file to stdout, regardless of -o.

343 "$@" || exit $?

344

345 # Remove the call to Libtool.

346 if test "$libtool" = yes; then

347 while test $1 != '--mode=compile'; do

348 shift

349 done

350 shift

351 fi

352

353 # Remove `-o $object'.

354 IFS=" "

355 for arg

356 do

357 case $arg in

358 -o)

359 shift

360 ;;

361 $object)

362 shift

363 ;;

364 *)

365 set fnord "$@" "$arg"

366 shift # fnord

367 shift # $arg

368 ;;

369 esac

370 done

371

372 test -z "$dashmflag" && dashmflag=-M

373 # Require at least two characters before searching for `:'

374 # in the target name. This is to cope with DOS-style filenames:

375 # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.

376 "$@" $dashmflag |

377 sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"

378 rm -f "$depfile"

379 cat < "$tmpdepfile" > "$depfile"

380 tr ' ' '

381 ' < "$tmpdepfile" | \

382 ## Some versions of the HPUX 10.20 sed can't process this invocation

383 ## correctly. Breaking it into two sed invocations is a workaround.

384 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"

385 rm -f "$tmpdepfile"

386 ;;

387

388 dashXmstdout)

389 # This case only exists to satisfy depend.m4. It is never actually

390 # run, as this mode is specially recognized in the preamble.

391 exit 1

392 ;;

393

394 makedepend)

395 "$@" || exit $?

396 # Remove any Libtool call

397 if test "$libtool" = yes; then

398 while test $1 != '--mode=compile'; do

399 shift

400 done

401 shift

402 fi

403 # X makedepend

404 shift

405 cleared=no

406 for arg in "$@"; do

407 case $cleared in

408 no)

409 set ""; shift

410 cleared=yes ;;

411 esac

412 case "$arg" in

413 -D*|-I*)

414 set fnord "$@" "$arg"; shift ;;

415 # Strip any option that makedepend may not understand. Remove

416 # the object too, otherwise makedepend will parse it as a source file.

417 -*|$object)

418 ;;

419 *)

420 set fnord "$@" "$arg"; shift ;;

421 esac

422 done

423 obj_suffix="`echo $object | sed 's/^.*\././'`"

424 touch "$tmpdepfile"

425 ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"

426 rm -f "$depfile"

427 cat < "$tmpdepfile" > "$depfile"

428 sed '1,2d' "$tmpdepfile" | tr ' ' '

429 ' | \

430 ## Some versions of the HPUX 10.20 sed can't process this invocation

431 ## correctly. Breaking it into two sed invocations is a workaround.

432 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"

433 rm -f "$tmpdepfile" "$tmpdepfile".bak

434 ;;

435

436 cpp)

437 # Important note: in order to support this mode, a compiler *must*

438 # always write the preprocessed file to stdout.

439 "$@" || exit $?

440

441 # Remove the call to Libtool.

442 if test "$libtool" = yes; then

443 while test $1 != '--mode=compile'; do

444 shift

445 done

446 shift

447 fi

448

449 # Remove `-o $object'.

450 IFS=" "

451 for arg

452 do

453 case $arg in

454 -o)

455 shift

456 ;;

457 $object)

458 shift

459 ;;

460 *)

461 set fnord "$@" "$arg"

462 shift # fnord

463 shift # $arg

464 ;;

465 esac

466 done

467

468 "$@" -E |

469 sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \

470 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |

471 sed '$ s: \\$::' > "$tmpdepfile"

472 rm -f "$depfile"

473 echo "$object : \\" > "$depfile"

474 cat < "$tmpdepfile" >> "$depfile"

475 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"

476 rm -f "$tmpdepfile"

477 ;;

478

479 msvisualcpp)

480 # Important note: in order to support this mode, a compiler *must*

481 # always write the preprocessed file to stdout, regardless of -o,

482 # because we must use -o when running libtool.

483 "$@" || exit $?

484 IFS=" "

485 for arg

486 do

487 case "$arg" in

488 "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")

489 set fnord "$@"

490 shift

491 shift

492 ;;

493 *)

494 set fnord "$@" "$arg"

495 shift

496 shift

497 ;;

498 esac

499 done

500 "$@" -E |

501 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"

502 rm -f "$depfile"

503 echo "$object : \\" > "$depfile"

504 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"

505 echo " " >> "$depfile"

506 . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"

507 rm -f "$tmpdepfile"

508 ;;

509

510 none)

511 exec "$@"

512 ;;

513

514 *)

515 echo "Unknown depmode $depmode" 1>&2

516 exit 1

517 ;;

518 esac

519

520 exit 0

521

522 # Local Variables:

523 # mode: shell-script

524 # sh-indentation: 2

525 # eval: (add-hook 'write-file-hooks 'time-stamp)

526 # time-stamp-start: "scriptversion="

527 # time-stamp-format: "%:y-%02m-%02d.%02H"

528 # time-stamp-end: "$"

529 # End:

530