tool/cosmocc: Properly handle dependency output (#1091)

a2753de contains some regressions, causing `fixupobj` to be
inappropriately suppressed when `-MD` or `-MMD` is passed.

This commit reverts most changes by a2753de, and:
- Treats all invocations of the compiler with `-M` and `-MM` as with the
`cpp` intent, since these flags imply `-E`.
- Handle the dependency output path specified by `-MF`.
  + This is trivial for `cosmocross` since the script does not throw
  objects to and from temporary directories.
  + For `cosmocc`, the file names are calculated based on the `-MF`
  value provided by the user. If this flag is not specified, the script
  generates the file name based on the output file using GCC rules.
  Then, before calling the real compilers, an additional `-MF` flag is
  passed to override the dependency outputs with mangled file names.
This commit is contained in:
Trung Nguyen 2024-01-23 01:22:16 +07:00 committed by GitHub
parent 8ab3a545c6
commit 83a8686c06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 57 additions and 38 deletions

View file

@ -100,7 +100,6 @@ INTENT=ld
GOT_SOME=0
NEED_OUTPUT=
RELOCATABLE=0
OUTPUT_IS_TEXT=0
for x; do
if [ $FIRST -eq 1 ]; then
set --
@ -128,7 +127,9 @@ for x; do
continue
elif [ x"$x" = x"-r" ]; then
RELOCATABLE=1
elif [ x"$x" = x"-E" ]; then
elif [ x"$x" = x"-E" ] ||
[ x"$x" = x"-M" ] ||
[ x"$x" = x"-MM" ]; then
INTENT=cpp
elif [ x"$x" = x"-o" ]; then
NEED_OUTPUT=1
@ -176,12 +177,6 @@ for x; do
GOT_SOME=1
elif [ x"$x" = x"-dumpmachine" ]; then
GOT_SOME=1
elif [ x"$x" = x"-M" ] ||
[ x"$x" = x"-MM" ] ||
[ x"$x" = x"-MD" ] ||
[ x"$x" = x"-MMD" ] ||
[ x"$x" = x"-E" ]; then
OUTPUT_IS_TEXT=1
fi
set -- "$@" "$x"
done
@ -223,10 +218,7 @@ log_command "$@"
if [ -n "$OUTPUT" ] && [ -f "$OUTPUT" ]; then
if [ $INTENT = cc ] || [ $INTENT = ld ]; then
if [ $OUTPUT_IS_TEXT -eq 0 ]; then
"$BIN/fixupobj" "$OUTPUT"
fi
exit
"$BIN/fixupobj" "$OUTPUT" || exit
fi
if [ $INTENT = ld ]; then
if [ x"$OUTPUT" != x"${OUTPUT%.com}" ] ||