mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-10-10 00:25:06 -04:00
nasm: new option -MW to emit Watcom-style Makefile rules
Allow NASM to generate Watcom-style Makefile dependencies, in addition to the default POSIX-style Makefile dependencies. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
87
asm/nasm.c
87
asm/nasm.c
@@ -141,7 +141,9 @@ static bool want_usage;
|
|||||||
static bool terminate_after_phase;
|
static bool terminate_after_phase;
|
||||||
bool user_nolist = false;
|
bool user_nolist = false;
|
||||||
|
|
||||||
static char *quote_for_make(const char *str);
|
static char *quote_for_pmake(const char *str);
|
||||||
|
static char *quote_for_wmake(const char *str);
|
||||||
|
static char *(*quote_for_make)(const char *) = quote_for_pmake;
|
||||||
|
|
||||||
static int64_t get_curr_offs(void)
|
static int64_t get_curr_offs(void)
|
||||||
{
|
{
|
||||||
@@ -217,6 +219,9 @@ static void emit_dependencies(StrList *list)
|
|||||||
FILE *deps;
|
FILE *deps;
|
||||||
int linepos, len;
|
int linepos, len;
|
||||||
StrList *l, *nl;
|
StrList *l, *nl;
|
||||||
|
char wrapstr[] = " \\\n ";
|
||||||
|
|
||||||
|
wrapstr[1] = (quote_for_make == quote_for_wmake) ? '&' : '\\';
|
||||||
|
|
||||||
if (depend_file && strcmp(depend_file, "-")) {
|
if (depend_file && strcmp(depend_file, "-")) {
|
||||||
deps = nasm_open_write(depend_file, NF_TEXT);
|
deps = nasm_open_write(depend_file, NF_TEXT);
|
||||||
@@ -234,7 +239,7 @@ static void emit_dependencies(StrList *list)
|
|||||||
char *file = quote_for_make(l->str);
|
char *file = quote_for_make(l->str);
|
||||||
len = strlen(file);
|
len = strlen(file);
|
||||||
if (linepos + len > 62 && linepos > 1) {
|
if (linepos + len > 62 && linepos > 1) {
|
||||||
fprintf(deps, " \\\n ");
|
fwrite(wrapstr, 1, sizeof wrapstr-1, deps);
|
||||||
linepos = 1;
|
linepos = 1;
|
||||||
}
|
}
|
||||||
fprintf(deps, " %s", file);
|
fprintf(deps, " %s", file);
|
||||||
@@ -244,8 +249,11 @@ static void emit_dependencies(StrList *list)
|
|||||||
fprintf(deps, "\n\n");
|
fprintf(deps, "\n\n");
|
||||||
|
|
||||||
list_for_each_safe(l, nl, list) {
|
list_for_each_safe(l, nl, list) {
|
||||||
if (depend_emit_phony)
|
if (depend_emit_phony) {
|
||||||
fprintf(deps, "%s:\n\n", l->str);
|
char *file = quote_for_make(l->str);
|
||||||
|
fprintf(deps, "%s :\n\n", file);
|
||||||
|
nasm_free(file);
|
||||||
|
}
|
||||||
nasm_free(l);
|
nasm_free(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,6 +385,7 @@ int main(int argc, char **argv)
|
|||||||
define_macros_late();
|
define_macros_late();
|
||||||
|
|
||||||
depend_ptr = (depend_file || (operating_mode & OP_DEPEND)) ? &depend_list : NULL;
|
depend_ptr = (depend_file || (operating_mode & OP_DEPEND)) ? &depend_list : NULL;
|
||||||
|
|
||||||
if (!depend_target)
|
if (!depend_target)
|
||||||
depend_target = quote_for_make(outname);
|
depend_target = quote_for_make(outname);
|
||||||
|
|
||||||
@@ -538,9 +547,9 @@ static void copy_filename(char *dst, const char *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert a string to Make-safe form
|
* Convert a string to a POSIX make-safe form
|
||||||
*/
|
*/
|
||||||
static char *quote_for_make(const char *str)
|
static char *quote_for_pmake(const char *str)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
char *os, *q;
|
char *os, *q;
|
||||||
@@ -619,6 +628,51 @@ static char *quote_for_make(const char *str)
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a string to a Watcom make-safe form
|
||||||
|
*/
|
||||||
|
static char *quote_for_wmake(const char *str)
|
||||||
|
{
|
||||||
|
const char *p;
|
||||||
|
char *os, *q;
|
||||||
|
|
||||||
|
size_t n = 1; /* Terminating zero */
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (p = str; *p; p++) {
|
||||||
|
switch (*p) {
|
||||||
|
case '$':
|
||||||
|
case '#':
|
||||||
|
n += 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
n++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os = q = nasm_malloc(n);
|
||||||
|
|
||||||
|
for (p = str; *p; p++) {
|
||||||
|
switch (*p) {
|
||||||
|
case '$':
|
||||||
|
case '#':
|
||||||
|
*q++ = '$';
|
||||||
|
*q++ = *p;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*q++ = *p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*q = '\0';
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
struct textargs {
|
struct textargs {
|
||||||
const char *label;
|
const char *label;
|
||||||
int value;
|
int value;
|
||||||
@@ -890,7 +944,21 @@ static bool process_arg(char *p, char *q, int pass)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
if (pass == 2) {
|
if (pass == 1) {
|
||||||
|
switch (p[2]) {
|
||||||
|
case 'W':
|
||||||
|
quote_for_make = quote_for_wmake;
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
case 'F':
|
||||||
|
case 'T':
|
||||||
|
case 'Q':
|
||||||
|
advance = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
switch (p[2]) {
|
switch (p[2]) {
|
||||||
case 0:
|
case 0:
|
||||||
operating_mode = OP_DEPEND;
|
operating_mode = OP_DEPEND;
|
||||||
@@ -919,17 +987,20 @@ static bool process_arg(char *p, char *q, int pass)
|
|||||||
depend_target = quote_for_make(q);
|
depend_target = quote_for_make(q);
|
||||||
advance = true;
|
advance = true;
|
||||||
break;
|
break;
|
||||||
|
case 'W':
|
||||||
|
/* handled in pass 1 */
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
|
nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
|
||||||
"unknown dependency option `-M%c'", p[2]);
|
"unknown dependency option `-M%c'", p[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (advance && (!q || !q[0])) {
|
if (advance && (!q || !q[0])) {
|
||||||
nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
|
nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
|
||||||
"option `-M%c' requires a parameter", p[2]);
|
"option `-M%c' requires a parameter", p[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
|
|||||||
@@ -7,6 +7,11 @@
|
|||||||
The NASM 2 series supports x86-64, and is the production version of NASM
|
The NASM 2 series supports x86-64, and is the production version of NASM
|
||||||
since 2007.
|
since 2007.
|
||||||
|
|
||||||
|
\S{cl-2.13.02} Version 2.13.02
|
||||||
|
|
||||||
|
\b Option \c{-MW} to quote dependency outputs according to Watcom
|
||||||
|
Make conventions. See \k{opt-MW}.
|
||||||
|
|
||||||
\S{cl-2.13.01} Version 2.13.01
|
\S{cl-2.13.01} Version 2.13.01
|
||||||
|
|
||||||
\b Fix incorrect output for some types of \c{FAR} or \c{SEG}
|
\b Fix incorrect output for some types of \c{FAR} or \c{SEG}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@
|
|||||||
\IR{-MP} \c{-MP} option
|
\IR{-MP} \c{-MP} option
|
||||||
\IR{-MQ} \c{-MQ} option
|
\IR{-MQ} \c{-MQ} option
|
||||||
\IR{-MT} \c{-MT} option
|
\IR{-MT} \c{-MT} option
|
||||||
|
\IR{-MW} \c{-MW} option
|
||||||
\IR{-O} \c{-O} option
|
\IR{-O} \c{-O} option
|
||||||
\IR{-P} \c{-P} option
|
\IR{-P} \c{-P} option
|
||||||
\IR{-U} \c{-U} option
|
\IR{-U} \c{-U} option
|
||||||
@@ -518,6 +519,14 @@ each header file. This prevents Make from complaining if a header
|
|||||||
file has been removed.
|
file has been removed.
|
||||||
|
|
||||||
|
|
||||||
|
\S{opt-MW} The \i\c{-MW} Option: Watcom Make quoting style
|
||||||
|
|
||||||
|
This option causes NASM to attempt to quote dependencies according to
|
||||||
|
Watcom Make conventions rather than POSIX Make conventions (also used
|
||||||
|
by most other Make variants.) This quotes \c{#} as \c{$#} rather than
|
||||||
|
\c{\\#}, and uses \c{&} rather than \c{\\} for continuation lines.
|
||||||
|
|
||||||
|
|
||||||
\S{opt-F} The \i\c{-F} Option: Selecting a \i{Debug Information Format}
|
\S{opt-F} The \i\c{-F} Option: Selecting a \i{Debug Information Format}
|
||||||
|
|
||||||
This option is used to select the format of the debug information
|
This option is used to select the format of the debug information
|
||||||
|
|||||||
Reference in New Issue
Block a user