From 997961d8a9a2c67e06508ac5f3733edb3ad6ebc7 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 8 Jun 2024 11:42:57 +0100 Subject: make: allow := macro assignment on command line Only the forms of macro assignment required by POSIX were allowed on the command line. Add support for the non-POSIX := form too. Adds 16-24 bytes. --- miscutils/make.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/miscutils/make.c b/miscutils/make.c index e098b0880..7d2196139 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -51,10 +51,10 @@ //usage:#define make_trivial_usage //usage: IF_FEATURE_MAKE_POSIX( -//usage: "[--posix] [-C DIR] [-f FILE] [-j NUM] [-x PRAG] [-eiknpqrsSt] [MACRO[::[:]]=VAL]... [TARGET]..." +//usage: "[--posix] [-C DIR] [-f FILE] [-j NUM] [-x PRAG] [-eiknpqrsSt] [MACRO[:[:[:]]]=VAL]... [TARGET]..." //usage: ) //usage: IF_NOT_FEATURE_MAKE_POSIX( -//usage: "[-C DIR] [-f FILE] [-j NUM] [-eiknpqrsSt] [MACRO[::[:]]=VAL]... [TARGET]..." +//usage: "[-C DIR] [-f FILE] [-j NUM] [-eiknpqrsSt] [MACRO[:[:[:]]]=VAL]... [TARGET]..." //usage: ) //usage:#define make_full_usage "\n\n" //usage: "Maintain files based on their dependencies\n" @@ -2855,21 +2855,29 @@ process_macros(char **argv, int level) break; } - if (equal - 2 > *argv && equal[-1] == ':' && equal[-2] == ':') { - if (POSIX_2017) - error("invalid macro assignment"); - if (equal - 3 > *argv && equal[-3] == ':') { - // BSD-style ':='. Expand RHS, but not '$$', - // resulting macro is delayed expansion. - colon = equal - 3; - except_dollar = TRUE; + if (equal - 1 > *argv && equal[-1] == ':') { + if (equal - 2 > *argv && equal[-2] == ':') { + if (POSIX_2017) + error("invalid macro assignment"); + if (equal - 3 > *argv && equal[-3] == ':') { + // BSD-style ':='. Expand RHS, but not '$$', + // resulting macro is delayed expansion. + colon = equal - 3; + except_dollar = TRUE; + } else { + // GNU-style ':='. Expand RHS, including '$$', + // resulting macro is immediate expansion. + colon = equal - 2; + immediate = M_IMMEDIATE; + } + *colon = '\0'; } else { - // GNU-style ':='. Expand RHS, including '$$', - // resulting macro is immediate expansion. - colon = equal - 2; + if (posix) + error("invalid macro assignment"); + colon = equal - 1; immediate = M_IMMEDIATE; + *colon = '\0'; } - *colon = '\0'; } else *equal = '\0'; -- cgit v1.2.3-55-g6feb