From: Marc Espie Subject: patch: tweak make "magic variables" handling To: tech@openbsd.org Date: Tue, 25 Nov 2025 12:03:33 +0100 The idea is that it's shorter to special-case ${@D} and the likes (two characters variables ending in D or F) instead of having a weird idx encoding. Cons: - this yields an extra "ext" parameter to classify_var Pros: - the weird index encoding vanishes - no need for special treatment if we add more similar variables. - drastically reduces the size of the switch (and the modulo shrinks from 82 to 36) - code will recognize constructs like ${?D} and ${?F}, which puts us in line with FreeBSD and NetBSD bmake, and also with gnu make. Index: Makefile =================================================================== RCS file: /build/data/openbsd/cvs/src/usr.bin/make/Makefile,v diff -u -p -r1.65 Makefile --- Makefile 4 Sep 2023 11:35:11 -0000 1.65 +++ Makefile 22 Nov 2025 09:42:30 -0000 @@ -27,7 +27,7 @@ CLEANFILES+=generate generate.o regress. CLEANFILES+= varhashconsts.h condhashconsts.h nodehashconsts.h # may need tweaking if you add variable synonyms or change the hash function -MAGICVARSLOTS=82 +MAGICVARSLOTS=36 MAGICCONDSLOTS=65 varhashconsts.h: generate Index: generate.c =================================================================== RCS file: /build/data/openbsd/cvs/src/usr.bin/make/generate.c,v diff -u -p -r1.18 generate.c --- generate.c 14 Oct 2016 09:27:21 -0000 1.18 +++ generate.c 22 Nov 2025 14:59:44 -0000 @@ -53,16 +53,6 @@ char *table_var[] = { M(LONGPREFIX), M(LONGARCHIVE), M(LONGMEMBER), - M(FTARGET), - M(DTARGET), - M(FPREFIX), - M(DPREFIX), - M(FARCHIVE), - M(DARCHIVE), - M(FMEMBER), - M(DMEMBER), - M(FIMPSRC), - M(DIMPSRC), NULL }; Index: make.1 =================================================================== RCS file: /build/data/openbsd/cvs/src/usr.bin/make/make.1,v diff -u -p -r1.141 make.1 --- make.1 10 Aug 2023 10:56:34 -0000 1.141 +++ make.1 25 Nov 2025 11:02:57 -0000 @@ -639,19 +639,24 @@ The file prefix of the file, containing no suffix or preceding directory components. .El .Pp -The six variables -.Sq Va "@F" , -.Sq Va "@D" , -.Sq Va " +.Pc +may be suffixed with a +.Sq D +or a +.Sq F , +to yield the filename or directory part of the corresponding variables, e.g., +.Sq ${ Ns Va @F Ns } +is equivalent +to +.Sq ${@:T} and -.Qq directory -parts of the corresponding macros. +.Sq ${ Ns Va @D Ns } +is equivalent to +.Sq ${@:H} . .Pp For maximum compatibility, .Sq Va \&< Index: var.c =================================================================== RCS file: /build/data/openbsd/cvs/src/usr.bin/make/var.c,v diff -u -p -r1.107 var.c --- var.c 18 Jun 2024 02:11:04 -0000 1.107 +++ var.c 22 Nov 2025 15:00:25 -0000 @@ -152,16 +152,6 @@ static char *varnames[] = { IMPSRC, OODATE, ALLSRC, - FTARGET, - DTARGET, - FPREFIX, - DPREFIX, - FARCHIVE, - DARCHIVE, - FMEMBER, - DMEMBER, - FIMPSRC, - DIMPSRC }; static bool xtlist[] = { @@ -173,16 +163,6 @@ static bool xtlist[] = { true, /* $< */ false, /* $? */ false, /* $> */ - true, /* ${@F} */ - true, /* ${@D} */ - false, /* ${*F} */ - false, /* ${*D} */ - false, /* ${!F} */ - false, /* ${!D} */ - true, /* ${%F} */ - true, /* ${%D} */ - true, /* ${locals[idx]; - else - val = ctxt->locals[EXTENDED2SIMPLE(idx)]; + val = ctxt->locals[idx]; } else val = NULL; if (val == NULL) return NULL; - if (idx >= LOCAL_SIZE) { - if (IS_EXTENDED_F(idx)) - val = Var_GetTail(val); - else - val = Var_GetHead(val); + if (ext == 'F') { + val = Var_GetTail(val); + *freePtr = true; + } else if (ext == 'D') { + val = Var_GetHead(val); *freePtr = true; } } @@ -1012,8 +948,6 @@ bad_dynamic_variable(int idx) Location origin; Parse_FillLocation(&origin); - if (idx >= LOCAL_SIZE) - idx = EXTENDED2SIMPLE(idx); switch(idx) { case IMPSRC_INDEX: if (origin.fname) @@ -1050,6 +984,7 @@ Var_Parse(const char *str, /* The string uint32_t k; int idx; bool has_modifier; + char ext; *freePtr = false; @@ -1063,8 +998,9 @@ Var_Parse(const char *str, /* The string has_modifier = parse_base_variable_name(&tstr, &name, ctxt); - idx = classify_var(name.s, &name.e, &k); - val = get_expanded_value(name.s, name.e, idx, k, ctxt, err, freePtr); + idx = classify_var(name.s, &name.e, &k, &ext); + val = get_expanded_value(name.s, name.e, idx, k, ext, ctxt, err, + freePtr); if (has_modifier) { val = VarModifiers_Apply(val, &name, ctxt, err, freePtr, &tstr, str[1]); @@ -1183,6 +1119,7 @@ Var_Check_for_target(const char *str) int idx; bool has_modifier; struct Name name; + char ext; /* skip over uninteresting stuff */ for (; *str != '\0' && *str != '$'; str++) @@ -1198,7 +1135,7 @@ Var_Check_for_target(const char *str) tstr = str; has_modifier = parse_base_variable_name(&tstr, &name, NULL); - idx = classify_var(name.s, &name.e, &k); + idx = classify_var(name.s, &name.e, &k, &ext); if (has_modifier) { bool doFree = false; char *val = VarModifiers_Apply(NULL, NULL, NULL, false, Index: var_int.h =================================================================== RCS file: /build/data/openbsd/cvs/src/usr.bin/make/var_int.h,v diff -u -p -r1.2 var_int.h --- var_int.h 19 Jul 2010 19:46:44 -0000 1.2 +++ var_int.h 22 Nov 2025 15:00:54 -0000 @@ -42,16 +42,4 @@ #define LONGARCHIVE ".ARCHIVE" #define LONGMEMBER ".MEMBER" -/* System V extended variables (get directory/file part) */ -#define FTARGET "@F" -#define DTARGET "@D" -#define FIMPSRC "