A long time ago, I tried to host our fork of make, in the hope it would get picked up by other systems.
Accordingly, some features were added to mimic netbsd's extensions, hidden behind FEATURES macros. Turns out that, for better or for worse, FreeBSD decided to go with NetBSD's fork of bmake, so this is just dead weight that makes stuff more complex. Accordingly, config.h is no longer really needed, as it shrinks to two little defines. (the only part worth looking at is varmodifiers... this survived a full build of base and xenocara without any issue, along with quite a few ports) Index: Makefile =================================================================== RCS file: /cvs/src/usr.bin/make/Makefile,v retrieving revision 1.64 diff -u -p -r1.64 Makefile --- Makefile 13 Jan 2020 15:41:53 -0000 1.64 +++ Makefile 31 Aug 2023 06:56:02 -0000 @@ -6,8 +6,7 @@ HOSTCFLAGS+= -I${.OBJDIR} -I${.CURDIR} CDIAGFLAGS=-Wall -W -Wno-char-subscripts -Wstrict-prototypes -pedantic \ -Wmissing-prototypes -Wdeclaration-after-statement -std=c99 -CDEFS+=-DHAS_PATHS_H -CDEFS+=-DHAS_EXTENDED_GETCWD +CDEFS+=-DMAKE_BSIZE=256 -DDEFMAXJOBS=4 #CDEFS+=-DHAS_STATS DPADD += ${LIBUTIL} Index: arch.c =================================================================== RCS file: /cvs/src/usr.bin/make/arch.c,v retrieving revision 1.93 diff -u -p -r1.93 arch.c --- arch.c 17 Feb 2023 17:59:36 -0000 1.93 +++ arch.c 31 Aug 2023 06:56:02 -0000 @@ -82,7 +82,6 @@ #include <string.h> #include <unistd.h> #include <ohash.h> -#include "config.h" #include "defines.h" #include "buf.h" #include "dir.h" Index: buf.c =================================================================== RCS file: /cvs/src/usr.bin/make/buf.c,v retrieving revision 1.29 diff -u -p -r1.29 buf.c --- buf.c 13 Jan 2020 13:54:44 -0000 1.29 +++ buf.c 31 Aug 2023 06:56:02 -0000 @@ -75,7 +75,6 @@ #include <string.h> #include <stdio.h> #include <stdarg.h> -#include "config.h" #include "defines.h" #include "buf.h" #include "stats.h" Index: cmd_exec.c =================================================================== RCS file: /cvs/src/usr.bin/make/cmd_exec.c,v retrieving revision 1.12 diff -u -p -r1.12 cmd_exec.c --- cmd_exec.c 31 Aug 2023 06:53:28 -0000 1.12 +++ cmd_exec.c 31 Aug 2023 06:56:02 -0000 @@ -30,7 +30,6 @@ #include <stdio.h> #include <string.h> #include <unistd.h> -#include "config.h" #include "defines.h" #include "cmd_exec.h" #include "buf.h" Index: compat.c =================================================================== RCS file: /cvs/src/usr.bin/make/compat.c,v retrieving revision 1.93 diff -u -p -r1.93 compat.c --- compat.c 26 Jan 2020 12:41:21 -0000 1.93 +++ compat.c 31 Aug 2023 06:56:02 -0000 @@ -40,7 +40,6 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include "config.h" #include "defines.h" #include "dir.h" #include "engine.h" Index: cond.c =================================================================== RCS file: /cvs/src/usr.bin/make/cond.c,v retrieving revision 1.54 diff -u -p -r1.54 cond.c --- cond.c 21 Dec 2019 15:29:25 -0000 1.54 +++ cond.c 31 Aug 2023 06:56:03 -0000 @@ -42,7 +42,6 @@ #include <stdlib.h> #include <string.h> #include <ohash.h> -#include "config.h" #include "defines.h" #include "dir.h" #include "buf.h" Index: dir.c =================================================================== RCS file: /cvs/src/usr.bin/make/dir.c,v retrieving revision 1.68 diff -u -p -r1.68 dir.c --- dir.c 21 Oct 2016 16:12:38 -0000 1.68 +++ dir.c 31 Aug 2023 06:56:03 -0000 @@ -70,7 +70,6 @@ #include <stdlib.h> #include <string.h> #include <ohash.h> -#include "config.h" #include "defines.h" #include "dir.h" #include "lst.h" Index: direxpand.c =================================================================== RCS file: /cvs/src/usr.bin/make/direxpand.c,v retrieving revision 1.8 diff -u -p -r1.8 direxpand.c --- direxpand.c 21 Oct 2016 16:12:38 -0000 1.8 +++ direxpand.c 31 Aug 2023 06:56:03 -0000 @@ -62,7 +62,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "config.h" #include "defines.h" #include "lst.h" #include "dir.h" Index: engine.c =================================================================== RCS file: /cvs/src/usr.bin/make/engine.c,v retrieving revision 1.72 diff -u -p -r1.72 engine.c --- engine.c 31 Aug 2023 06:53:28 -0000 1.72 +++ engine.c 31 Aug 2023 06:56:03 -0000 @@ -73,7 +73,6 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> -#include "config.h" #include "defines.h" #include "cmd_exec.h" #include "dir.h" Index: enginechoice.c =================================================================== RCS file: /cvs/src/usr.bin/make/enginechoice.c,v retrieving revision 1.3 diff -u -p -r1.3 enginechoice.c --- enginechoice.c 4 Mar 2021 09:34:30 -0000 1.3 +++ enginechoice.c 31 Aug 2023 06:56:03 -0000 @@ -23,7 +23,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "config.h" #include "defines.h" #include "compat.h" #include "make.h" Index: error.c =================================================================== RCS file: /cvs/src/usr.bin/make/error.c,v retrieving revision 1.25 diff -u -p -r1.25 error.c --- error.c 27 Sep 2015 16:58:16 -0000 1.25 +++ error.c 31 Aug 2023 06:56:03 -0000 @@ -31,7 +31,6 @@ #include <sys/types.h> #include <unistd.h> -#include "config.h" #include "defines.h" #include "error.h" #include "job.h" Index: expandchildren.c =================================================================== RCS file: /cvs/src/usr.bin/make/expandchildren.c,v retrieving revision 1.2 diff -u -p -r1.2 expandchildren.c --- expandchildren.c 26 Jan 2020 12:41:21 -0000 1.2 +++ expandchildren.c 31 Aug 2023 06:56:03 -0000 @@ -44,7 +44,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "config.h" #include "defines.h" #include "direxpand.h" #include "engine.h" Index: for.c =================================================================== RCS file: /cvs/src/usr.bin/make/for.c,v retrieving revision 1.47 diff -u -p -r1.47 for.c --- for.c 5 Dec 2017 17:47:09 -0000 1.47 +++ for.c 31 Aug 2023 06:56:03 -0000 @@ -63,7 +63,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "config.h" #include "defines.h" #include "buf.h" #include "for.h" Index: init.c =================================================================== RCS file: /cvs/src/usr.bin/make/init.c,v retrieving revision 1.9 diff -u -p -r1.9 init.c --- init.c 31 Aug 2023 06:53:28 -0000 1.9 +++ init.c 31 Aug 2023 06:56:03 -0000 @@ -26,7 +26,6 @@ */ #include <stdio.h> #include "defines.h" -#include "config.h" #include "init.h" #include "timestamp.h" #include "stats.h" Index: job.c =================================================================== RCS file: /cvs/src/usr.bin/make/job.c,v retrieving revision 1.164 diff -u -p -r1.164 job.c --- job.c 8 Mar 2023 04:43:11 -0000 1.164 +++ job.c 31 Aug 2023 06:56:03 -0000 @@ -93,7 +93,6 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> -#include "config.h" #include "defines.h" #include "job.h" #include "engine.h" Index: lowparse.c =================================================================== RCS file: /cvs/src/usr.bin/make/lowparse.c,v retrieving revision 1.35 diff -u -p -r1.35 lowparse.c --- lowparse.c 21 Oct 2016 16:12:38 -0000 1.35 +++ lowparse.c 31 Aug 2023 06:56:03 -0000 @@ -35,7 +35,6 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> -#include "config.h" #include "defines.h" #include "buf.h" #include "lowparse.h" Index: main.c =================================================================== RCS file: /cvs/src/usr.bin/make/main.c,v retrieving revision 1.131 diff -u -p -r1.131 main.c --- main.c 8 Jul 2023 21:51:45 -0000 1.131 +++ main.c 31 Aug 2023 06:56:03 -0000 @@ -45,7 +45,6 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> -#include "config.h" #include "defines.h" #include "var.h" #include "lowparse.h" @@ -517,7 +516,7 @@ figure_out_CURDIR() struct stat sa, sb; /* curdir is cwd... */ - cwd = dogetcwd(); + cwd = getcwd(NULL, 0); if (cwd == NULL) err(2, "getcwd"); Index: make.c =================================================================== RCS file: /cvs/src/usr.bin/make/make.c,v retrieving revision 1.83 diff -u -p -r1.83 make.c --- make.c 8 Jul 2023 18:42:27 -0000 1.83 +++ make.c 31 Aug 2023 06:56:03 -0000 @@ -64,7 +64,6 @@ #include <stdlib.h> #include <string.h> #include <ohash.h> -#include "config.h" #include "defines.h" #include "dir.h" #include "job.h" Index: parse.c =================================================================== RCS file: /cvs/src/usr.bin/make/parse.c,v retrieving revision 1.135 diff -u -p -r1.135 parse.c --- parse.c 30 May 2023 04:42:21 -0000 1.135 +++ parse.c 31 Aug 2023 06:56:03 -0000 @@ -68,7 +68,6 @@ #include <stdlib.h> #include <string.h> #include <ohash.h> -#include "config.h" #include "defines.h" #include "dir.h" #include "direxpand.h" @@ -1555,23 +1554,20 @@ parse_as_special_line(Buffer buf, Buffer { if (*line == '.' && handle_bsd_command(buf, copy, line+1)) return true; - if (FEATURES(FEATURE_SYSVINCLUDE) && - strncmp(line, "include", 7) == 0 && + if (strncmp(line, "include", 7) == 0 && ISSPACE(line[7]) && strchr(line, ':') == NULL) { /* It's an S3/S5-style "include". */ lookup_sysv_include(line + 7, "include"); return true; } - if (FEATURES(FEATURE_CONDINCLUDE) && - strncmp(line, "sinclude", 8) == 0 && + if (strncmp(line, "sinclude", 8) == 0 && ISSPACE(line[8]) && strchr(line, ':') == NULL) { lookup_conditional_include(line+8, "sinclude"); return true; } - if (FEATURES(FEATURE_CONDINCLUDE) && - strncmp(line, "-include", 8) == 0 && + if (strncmp(line, "-include", 8) == 0 && ISSPACE(line[8]) && strchr(line, ':') == NULL) { lookup_conditional_include(line+8, "-include"); Index: parsevar.c =================================================================== RCS file: /cvs/src/usr.bin/make/parsevar.c,v retrieving revision 1.16 diff -u -p -r1.16 parsevar.c --- parsevar.c 23 Oct 2016 14:54:14 -0000 1.16 +++ parsevar.c 31 Aug 2023 06:56:03 -0000 @@ -30,7 +30,6 @@ #include <stddef.h> #include <stdlib.h> #include <string.h> -#include "config.h" #include "defines.h" #include "var.h" #include "varname.h" @@ -84,8 +83,7 @@ parse_variable_assignment(const char *li int type; struct Name name; - arg = VarName_Get(line, &name, NULL, true, - FEATURES(FEATURE_SUNSHCMD) ? find_op1 : find_op2); + arg = VarName_Get(line, &name, NULL, true, find_op1); while (ISSPACE(*arg)) arg++; @@ -113,8 +111,7 @@ parse_variable_assignment(const char *li break; case ':': - if (FEATURES(FEATURE_SUNSHCMD) && - strncmp(arg, "sh", 2) == 0) { + if (strncmp(arg, "sh", 2) == 0) { type = VAR_SUNSHELL; arg += 2; while (*arg != '=' && *arg != '\0') Index: stats.c =================================================================== RCS file: /cvs/src/usr.bin/make/stats.c,v retrieving revision 1.11 diff -u -p -r1.11 stats.c --- stats.c 22 Apr 2014 12:21:17 -0000 1.11 +++ stats.c 31 Aug 2023 06:56:03 -0000 @@ -34,7 +34,6 @@ to allow for concurrent adjustment to variables. */ -#include "config.h" #include "defines.h" #include "stats.h" Index: str.c =================================================================== RCS file: /cvs/src/usr.bin/make/str.c,v retrieving revision 1.32 diff -u -p -r1.32 str.c --- str.c 21 May 2019 17:21:02 -0000 1.32 +++ str.c 31 Aug 2023 06:56:03 -0000 @@ -37,7 +37,6 @@ #include <ctype.h> #include <string.h> -#include "config.h" #include "defines.h" #include "str.h" #include "memory.h" Index: suff.c =================================================================== RCS file: /cvs/src/usr.bin/make/suff.c,v retrieving revision 1.102 diff -u -p -r1.102 suff.c --- suff.c 13 Jan 2020 15:41:53 -0000 1.102 +++ suff.c 31 Aug 2023 06:56:03 -0000 @@ -48,7 +48,6 @@ #include <stdlib.h> #include <string.h> #include <ohash.h> -#include "config.h" #include "defines.h" #include "dir.h" #include "engine.h" Index: targ.c =================================================================== RCS file: /cvs/src/usr.bin/make/targ.c,v retrieving revision 1.85 diff -u -p -r1.85 targ.c --- targ.c 26 Jan 2020 12:41:21 -0000 1.85 +++ targ.c 31 Aug 2023 06:56:03 -0000 @@ -102,7 +102,6 @@ #include <stdlib.h> #include <string.h> #include <ohash.h> -#include "config.h" #include "defines.h" #include "stats.h" #include "suff.h" Index: targequiv.c =================================================================== RCS file: /cvs/src/usr.bin/make/targequiv.c,v retrieving revision 1.9 diff -u -p -r1.9 targequiv.c --- targequiv.c 21 Dec 2019 15:29:25 -0000 1.9 +++ targequiv.c 31 Aug 2023 06:56:03 -0000 @@ -37,7 +37,6 @@ #include <string.h> #include <ohash.h> #include <limits.h> -#include "config.h" #include "defines.h" #include "memory.h" #include "gnode.h" Index: timestamp.c =================================================================== RCS file: /cvs/src/usr.bin/make/timestamp.c,v retrieving revision 1.10 diff -u -p -r1.10 timestamp.c --- timestamp.c 22 May 2013 12:14:08 -0000 1.10 +++ timestamp.c 31 Aug 2023 06:56:03 -0000 @@ -27,7 +27,6 @@ #include <sys/time.h> #include <stdio.h> #include <string.h> -#include "config.h" #include "defines.h" #include "timestamp.h" Index: var.c =================================================================== RCS file: /cvs/src/usr.bin/make/var.c,v retrieving revision 1.105 diff -u -p -r1.105 var.c --- var.c 10 Aug 2023 10:52:43 -0000 1.105 +++ var.c 31 Aug 2023 06:56:03 -0000 @@ -69,7 +69,6 @@ #include <string.h> #include <ohash.h> -#include "config.h" #include "defines.h" #include "buf.h" #include "cmd_exec.h" Index: varmodifiers.c =================================================================== RCS file: /cvs/src/usr.bin/make/varmodifiers.c,v retrieving revision 1.48 diff -u -p -r1.48 varmodifiers.c --- varmodifiers.c 30 Aug 2020 12:16:04 -0000 1.48 +++ varmodifiers.c 31 Aug 2023 06:56:03 -0000 @@ -72,7 +72,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "config.h" #include "defines.h" #include "buf.h" #include "var.h" @@ -100,7 +99,7 @@ #define VAR_BANG_EQUAL 0x100 typedef struct { - char *lbuffer; /* left string to free */ + char *lbuffer; /* Left string to free */ char *lhs; /* String to match */ size_t leftLen; /* Length of string */ char *rhs; /* Replacement string (w/ &'s removed) */ @@ -108,12 +107,6 @@ typedef struct { int flags; } VarPattern; -struct LoopStuff { - struct LoopVar *var; - char *expand; - bool err; -}; - static bool VarHead(struct Name *, bool, Buffer, void *); static bool VarTail(struct Name *, bool, Buffer, void *); static bool VarSuffix(struct Name *, bool, Buffer, void *); @@ -121,8 +114,6 @@ static bool VarRoot(struct Name *, bool, static bool VarMatch(struct Name *, bool, Buffer, void *); static bool VarSYSVMatch(struct Name *, bool, Buffer, void *); static bool VarNoMatch(struct Name *, bool, Buffer, void *); -static bool VarUniq(struct Name *, bool, Buffer, void *); -static bool VarLoop(struct Name *, bool, Buffer, void *); static void VarREError(int, regex_t *, const char *); @@ -149,62 +140,36 @@ static char *do_upper(const char *, cons static char *do_lower(const char *, const struct Name *, void *); static void *check_shcmd(const char **, SymTable *, bool, int); static char *do_shcmd(const char *, const struct Name *, void *); -static char *do_sort(const char *, const struct Name *, void *); -static char *finish_loop(const char *, const struct Name *, void *); -static int NameCompare(const void *, const void *); -static char *do_label(const char *, const struct Name *, void *); -static char *do_path(const char *, const struct Name *, void *); -static char *do_def(const char *, const struct Name *, void *); -static char *do_undef(const char *, const struct Name *, void *); -static char *do_assign(const char *, const struct Name *, void *); -static char *do_exec(const char *, const struct Name *, void *); - -static void *assign_get_value(const char **, SymTable *, bool, int); -static void *get_cmd(const char **, SymTable *, bool, int); -static void *get_value(const char **, SymTable *, bool, int); static void *get_stringarg(const char **, SymTable *, bool, int); static void free_stringarg(void *); static void *get_patternarg(const char **, SymTable *, bool, int); static void *get_spatternarg(const char **, SymTable *, bool, int); static void *common_get_patternarg(const char **, SymTable *, bool, int, bool); static void free_patternarg(void *); -static void free_looparg(void *); static void *get_sysvpattern(const char **, SymTable *, bool, int); -static void *get_loop(const char **, SymTable *, bool, int); -static char *LoopGrab(const char **); static struct Name dummy; static struct Name *dummy_arg = &dummy; static struct modifier { - bool atstart; void * (*getarg)(const char **, SymTable *, bool, int); char * (*apply)(const char *, const struct Name *, void *); bool (*word_apply)(struct Name *, bool, Buffer, void *); void (*freearg)(void *); } *choose_mod[256], - match_mod = {false, get_stringarg, NULL, VarMatch, free_stringarg}, - nomatch_mod = {false, get_stringarg, NULL, VarNoMatch, free_stringarg}, - subst_mod = {false, get_spatternarg, NULL, VarSubstitute, free_patternarg}, - resubst_mod = {false, get_patternarg, do_regex, NULL, free_patternarg}, - quote_mod = {false, check_quote, VarQuote, NULL , free}, - tail_mod = {false, check_empty, NULL, VarTail, NULL}, - head_mod = {false, check_empty, NULL, VarHead, NULL}, - suffix_mod = {false, check_empty, NULL, VarSuffix, NULL}, - root_mod = {false, check_empty, NULL, VarRoot, NULL}, - upper_mod = {false, check_empty, do_upper, NULL, NULL}, - lower_mod = {false, check_empty, do_lower, NULL, NULL}, - shcmd_mod = {false, check_shcmd, do_shcmd, NULL, NULL}, - sysv_mod = {false, get_sysvpattern, NULL, VarSYSVMatch, free_patternarg}, - uniq_mod = {false, check_empty, NULL, VarUniq, NULL}, - sort_mod = {false, check_empty, do_sort, NULL, NULL}, - loop_mod = {false, get_loop, finish_loop, VarLoop, free_looparg}, - undef_mod = {true, get_value, do_undef, NULL, NULL}, - def_mod = {true, get_value, do_def, NULL, NULL}, - label_mod = {true, check_empty, do_label, NULL, NULL}, - path_mod = {true, check_empty, do_path, NULL, NULL}, - assign_mod = {true, assign_get_value, do_assign, NULL, free_patternarg}, - exec_mod = {true, get_cmd, do_exec, NULL, free_patternarg} + match_mod = {get_stringarg, NULL, VarMatch, free_stringarg}, + nomatch_mod = {get_stringarg, NULL, VarNoMatch, free_stringarg}, + subst_mod = {get_spatternarg, NULL, VarSubstitute, free_patternarg}, + resubst_mod = {get_patternarg, do_regex, NULL, free_patternarg}, + quote_mod = {check_quote, VarQuote, NULL , free}, + tail_mod = {check_empty, NULL, VarTail, NULL}, + head_mod = {check_empty, NULL, VarHead, NULL}, + suffix_mod = {check_empty, NULL, VarSuffix, NULL}, + root_mod = {check_empty, NULL, VarRoot, NULL}, + upper_mod = {check_empty, do_upper, NULL, NULL}, + lower_mod = {check_empty, do_lower, NULL, NULL}, + shcmd_mod = {check_shcmd, do_shcmd, NULL, NULL}, + sysv_mod = {get_sysvpattern, NULL, VarSYSVMatch, free_patternarg} ; void @@ -219,27 +184,9 @@ VarModifiers_Init() choose_mod['H'] = &head_mod; choose_mod['E'] = &suffix_mod; choose_mod['R'] = &root_mod; - if (FEATURES(FEATURE_UPPERLOWER)) { - choose_mod['U'] = &upper_mod; - choose_mod['L'] = &lower_mod; - } - if (FEATURES(FEATURE_SUNSHCMD)) - choose_mod['s'] = &shcmd_mod; - if (FEATURES(FEATURE_UNIQ)) - choose_mod['u'] = &uniq_mod; - if (FEATURES(FEATURE_SORT)) - choose_mod['O'] = &sort_mod; - if (FEATURES(FEATURE_ODE)) { - choose_mod['@'] = &loop_mod; - choose_mod['D'] = &def_mod; - choose_mod['U'] = &undef_mod; - choose_mod['L'] = &label_mod; - choose_mod['P'] = &path_mod; - } - if (FEATURES(FEATURE_ASSIGN)) - choose_mod[':'] = &assign_mod; - if (FEATURES(FEATURE_EXECMOD)) - choose_mod['!'] = &exec_mod; + choose_mod['U'] = &upper_mod; + choose_mod['L'] = &lower_mod; + choose_mod['s'] = &shcmd_mod; } /* All modifiers handle addSpace (need to add a space before placing the @@ -345,8 +292,7 @@ VarRoot(struct Name *word, bool addSpace *----------------------------------------------------------------------- */ static bool -VarMatch(struct Name *word, bool addSpace, Buffer buf, - void *pattern) /* Pattern the word must match */ +VarMatch(struct Name *word, bool addSpace, Buffer buf, void *pattern) { const char *pat = pattern; @@ -366,8 +312,7 @@ VarMatch(struct Name *word, bool addSpac *----------------------------------------------------------------------- */ static bool -VarNoMatch(struct Name *word, bool addSpace, Buffer buf, - void *pattern) /* Pattern the word must not match */ +VarNoMatch(struct Name *word, bool addSpace, Buffer buf, void *pattern) { const char *pat = pattern; @@ -380,198 +325,6 @@ VarNoMatch(struct Name *word, bool addSp return addSpace; } -static bool -VarUniq(struct Name *word, bool addSpace, Buffer buf, void *lastp) -{ - struct Name *last = lastp; - - /* does not match */ - if (last->s == NULL || last->e - last->s != word->e - word->s || - strncmp(word->s, last->s, word->e - word->s) != 0) { - if (addSpace) - Buf_AddSpace(buf); - Buf_Addi(buf, word->s, word->e); - addSpace = true; - } - last->s = word->s; - last->e = word->e; - return addSpace; -} - -static bool -VarLoop(struct Name *word, bool addSpace, Buffer buf, void *vp) -{ - struct LoopStuff *v = vp; - - if (addSpace) - Buf_AddSpace(buf); - Var_SubstVar(buf, v->expand, v->var, word->s); - return true; -} - -static char * -finish_loop(const char *s, const struct Name *n UNUSED , void *p) -{ - struct LoopStuff *l = p; - - return Var_Subst(s, NULL, l->err); -} - -static int -NameCompare(const void *ap, const void *bp) -{ - const struct Name *a, *b; - size_t n, m; - int c; - - a = ap; - b = bp; - n = a->e - a->s; - m = b->e - b->s; - if (n < m) { - c = strncmp(a->s, b->s, n); - if (c != 0) - return c; - else - return -1; - } else if (m < n) { - c = strncmp(a->s, b->s, m); - if (c != 0) - return c; - else - return 1; - } else - return strncmp(a->s, b->s, n); -} - -static char * -do_sort(const char *s, const struct Name *dummy UNUSED, void *arg UNUSED) -{ - struct Name *t; - unsigned long n, i, j; - const char *start, *end; - - n = 1024; /* start at 1024 words */ - t = ereallocarray(NULL, n, sizeof(struct Name)); - start = s; - end = start; - - for (i = 0;; i++) { - if (i == n) { - n *= 2; - t = ereallocarray(t, n, sizeof(struct Name)); - } - start = iterate_words(&end); - if (start == NULL) - break; - t[i].s = start; - t[i].e = end; - } - if (i > 0) { - BUFFER buf; - - Buf_Init(&buf, end - s); - qsort(t, i, sizeof(struct Name), NameCompare); - Buf_Addi(&buf, t[0].s, t[0].e); - for (j = 1; j < i; j++) { - Buf_AddSpace(&buf); - Buf_Addi(&buf, t[j].s, t[j].e); - } - free(t); - return Buf_Retrieve(&buf); - } else { - free(t); - return ""; - } -} - -static char * -do_label(const char *s UNUSED, const struct Name *n, void *arg UNUSED) -{ - return Str_dupi(n->s, n->e); -} - -static char * -do_path(const char *s UNUSED, const struct Name *n, void *arg UNUSED) -{ - GNode *gn; - - gn = Targ_FindNodei(n->s, n->e, TARG_NOCREATE); - if (gn == NULL) - return Str_dupi(n->s, n->e); - else - return strdup(gn->path); -} - -static char * -do_def(const char *s, const struct Name *n UNUSED, void *arg) -{ - VarPattern *v = arg; - if (s == NULL) { - free_patternarg(v); - return NULL; - } else - return v->lbuffer; -} - -static char * -do_undef(const char *s, const struct Name *n UNUSED, void *arg) -{ - VarPattern *v = arg; - if (s != NULL) { - free_patternarg(v); - return NULL; - } else - return v->lbuffer; -} - -static char * -do_assign(const char *s, const struct Name *n, void *arg) -{ - VarPattern *v = arg; - char *msg; - char *result; - - switch (v->flags) { - case VAR_EQUAL: - Var_Seti(n->s, n->e, v->lbuffer); - break; - case VAR_MAY_EQUAL: - if (s == NULL) - Var_Seti(n->s, n->e, v->lbuffer); - break; - case VAR_ADD_EQUAL: - if (s == NULL) - Var_Seti(n->s, n->e, v->lbuffer); - else - Var_Appendi(n->s, n->e, v->lbuffer); - break; - case VAR_BANG_EQUAL: - result = Cmd_Exec(v->lbuffer, &msg); - if (result != NULL) { - Var_Seti(n->s, n->e, result); - free(result); - } else - Error(msg, v->lbuffer); - break; - - } - return NULL; -} - -static char * -do_exec(const char *s UNUSED, const struct Name *n UNUSED, void *arg) -{ - VarPattern *v = arg; - char *msg; - char *result; - - result = Cmd_Exec(v->lbuffer, &msg); - if (result == NULL) - Error(msg, v->lbuffer); - return result; -} - /*- *----------------------------------------------------------------------- * VarSYSVMatch -- @@ -958,7 +711,7 @@ VarRESubstitute(struct Name *word, bool *----------------------------------------------------------------------- * VarModify -- * Modify each of the words of the passed string using the given - * function. Used to implement all modifiers. + * function. Used to implement most modifiers. * * Results: * A string of all the words modified appropriately. @@ -1218,56 +971,6 @@ get_spatternarg(const char **p, SymTable return common_get_patternarg(p, ctxt, err, endc, true); } -static void -free_looparg(void *arg) -{ - struct LoopStuff *l = arg; - - Var_DeleteLoopVar(l->var); - free(l->expand); -} - -static char * -LoopGrab(const char **s) -{ - const char *p, *start; - - start = *s; - for (p = start; *p != '@'; p++) { - if (*p == '\\') - p++; - if (*p == 0) - return NULL; - } - *s = p+1; - return escape_dupi(start, p, "@\\"); -} - -static void * -get_loop(const char **p, SymTable *ctxt UNUSED, bool err, int endc) -{ - static struct LoopStuff loop; - const char *s; - const char *var; - - s = *p +1; - - loop.var = NULL; - loop.expand = NULL; - loop.err = err; - var = LoopGrab(&s); - if (var != NULL) { - loop.expand = LoopGrab(&s); - if (*s == endc || *s == ':') { - *p = s; - loop.var = Var_NewLoopVar(var, NULL); - return &loop; - } - } - free_looparg(&loop); - return NULL; -} - static void * common_get_patternarg(const char **p, SymTable *ctxt, bool err, int endc, bool dosubst) @@ -1328,71 +1031,6 @@ common_get_patternarg(const char **p, Sy return NULL; } -static void * -assign_get_value(const char **p, SymTable *ctxt, bool err, int endc) -{ - const char *s; - int flags; - VarPattern *arg; - - s = *p + 1; - if (s[0] == '=') - flags = VAR_EQUAL; - else if (s[0] == '?' && s[1] == '=') - flags = VAR_MAY_EQUAL; - else if (s[0] == '+' && s[1] == '=') - flags = VAR_ADD_EQUAL; - else if (s[0] == '!' && s[1] == '=') - flags = VAR_BANG_EQUAL; - else - return NULL; - - arg = get_value(&s, ctxt, err, endc); - if (arg != NULL) { - *p = s; - arg->flags = flags; - } - return arg; -} - -static void * -get_value(const char **p, SymTable *ctxt, bool err, int endc) -{ - VarPattern *pattern; - const char *s; - - pattern = emalloc(sizeof(VarPattern)); - s = *p + 1; - pattern->rhs = NULL; - pattern->lbuffer = VarGetPattern(ctxt, err, &s, ':', endc, - &pattern->leftLen, NULL); - if (s[-1] == endc || s[-1] == ':') { - *p = s-1; - return pattern; - } - free_patternarg(pattern); - return NULL; -} - -static void * -get_cmd(const char **p, SymTable *ctxt, bool err, int endc UNUSED) -{ - VarPattern *pattern; - const char *s; - - pattern = emalloc(sizeof(VarPattern)); - s = *p + 1; - pattern->rhs = NULL; - pattern->lbuffer = VarGetPattern(ctxt, err, &s, '!', '!', - &pattern->leftLen, NULL); - if (s[-1] == '!') { - *p = s-1; - return pattern; - } - free_patternarg(pattern); - return NULL; -} - static void free_patternarg(void *p) { @@ -1435,7 +1073,6 @@ VarModifiers_Apply(char *str, const stru bool err, bool *freePtr, const char **pscan, int paren) { const char *tstr; - bool atstart; /* Some ODE modifiers only make sense at start */ char endc = paren == '(' ? ')' : '}'; const char *start = *pscan; @@ -1462,7 +1099,6 @@ VarModifiers_Apply(char *str, const stru * the invocation. */ - atstart = true; while (*tstr != endc && *tstr != '\0') { struct modifier *mod; void *arg; @@ -1479,15 +1115,14 @@ VarModifiers_Apply(char *str, const stru mod = choose_mod[(unsigned char)*tstr]; arg = NULL; - if (mod != NULL && (!mod->atstart || atstart)) + if (mod != NULL) arg = mod->getarg(&tstr, ctxt, err, endc); - if (FEATURES(FEATURE_SYSVVARSUB) && arg == NULL) { + if (arg == NULL) { mod = &sysv_mod; arg = mod->getarg(&tstr, ctxt, err, endc); } - atstart = false; if (arg != NULL) { - if (str != NULL || (mod->atstart && name != NULL)) { + if (str != NULL) { if (mod->word_apply != NULL) { newStr = VarModify(str, mod->word_apply, arg); Index: varname.c =================================================================== RCS file: /cvs/src/usr.bin/make/varname.c,v retrieving revision 1.6 diff -u -p -r1.6 varname.c --- varname.c 25 Aug 2012 08:12:56 -0000 1.6 +++ varname.c 31 Aug 2023 06:56:03 -0000 @@ -25,7 +25,6 @@ */ #include <stdlib.h> -#include "config.h" #include "defines.h" #include "var.h" #include "buf.h" @@ -39,11 +38,6 @@ VarName_Get(const char *start, struct Na size_t len; p = cont(start); - /* If we don't want recursive variables, we skip over '$' */ - if (!FEATURES(FEATURE_RECVARS)) { - while (*p == '$') - p = cont(p+1); - } if (*p != '$') { name->s = start; name->e = p; Index: lst.lib/lstInt.h =================================================================== RCS file: /cvs/src/usr.bin/make/lst.lib/lstInt.h,v retrieving revision 1.15 diff -u -p -r1.15 lstInt.h --- lst.lib/lstInt.h 19 Jul 2010 19:46:44 -0000 1.15 +++ lst.lib/lstInt.h 31 Aug 2023 06:56:03 -0000 @@ -42,7 +42,6 @@ #ifndef _LSTINT_H_ #define _LSTINT_H_ -#include "config.h" #include "defines.h" #include "lst.h"