nasm: fix the combination -E -MD, handle -MD without a filename

-E -MD should work and output a dependency file.
-MD can be used without a filename; there is a default filename or
-\c{-MF} can be used.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2018-11-28 12:36:53 -08:00
parent c06c87dbb5
commit 3475462ee8
3 changed files with 34 additions and 10 deletions

View file

@ -136,9 +136,9 @@ static const struct forwrefinfo *forwref;
static const struct preproc_ops *preproc;
static StrList *include_path;
#define OP_NORMAL (1u << 0)
#define OP_PREPROCESS (1u << 1)
#define OP_DEPEND (1u << 2)
#define OP_NORMAL (1U << 0)
#define OP_PREPROCESS (1U << 1)
#define OP_DEPEND (1U << 2)
static unsigned int operating_mode;
@ -509,9 +509,17 @@ int main(int argc, char **argv)
/* Save away the default state of warnings */
memcpy(warning_state_init, warning_state, sizeof warning_state);
/* Dependency filename if we are also doing other things */
if (!depend_file && (operating_mode & ~OP_DEPEND)) {
if (outname)
depend_file = nasm_strcat(outname, ".d");
else
depend_file = filename_set_extension(inname, ".d");
}
/*
* If no output file name provided and this
* is a preprocess mode, we're perfectly
* is preprocess mode, we're perfectly
* fine to output into stdout.
*/
if (!outname && !(operating_mode & OP_PREPROCESS)) {
@ -524,13 +532,12 @@ int main(int argc, char **argv)
}
}
depend_ptr = (depend_file || (operating_mode & OP_DEPEND))
? &depend_list : NULL;
depend_ptr = (operating_mode & OP_DEPEND) ? &depend_list : NULL;
if (!depend_target)
depend_target = quote_for_make(outname);
if (operating_mode & OP_DEPEND) {
if (!(operating_mode & (OP_PREPROCESS|OP_NORMAL))) {
char *line;
if (depend_missing_ok)
@ -1077,9 +1084,11 @@ static bool process_arg(char *p, char *q, int pass)
depend_emit_phony = true;
break;
case 'D':
operating_mode = OP_NORMAL;
depend_file = q;
advance = true;
operating_mode |= OP_DEPEND;
if (q && (q[0] != '-' || q[1] == '\0')) {
depend_file = q;
advance = true;
}
break;
case 'F':
depend_file = q;

View file

@ -25,6 +25,12 @@ or hexadecimal floating-point having at least 32, 11, or 8 mantissa
digits could produce slightly incorrect results under very specific
conditions.
\b Support \c{-MD} without a filename, for \c{gcc}
compatibility. \c{-MF} can be used to set the dependencies output
filename. See \k{opt-MD}.
\b Fix \c{-E} in combination with \c{-MD}. See \k{opt-E}.
\S{cl-2.14} Version 2.14
\b Changed \c{-I} option semantics by adding a trailing path separator

View file

@ -496,6 +496,15 @@ updated dependencies with every assembly session. For example:
\c nasm -f elf -o myfile.o -MD myfile.dep myfile.asm
If the argument after \c{-MD} is an option rather than a filename,
then the output filename is the first applicable one of:
\b the filename set in the \c{-MF} option;
\b the output filename from the \c{-o} option with \c{.d} appended;
\b the input filename with the extension set to \c{.d}.
\S{opt-MT} The \i\c{-MT} Option: Dependency Target Name