From 6e0296234fdf9b27f5b0d9f884223b7c2b5b3d03 Mon Sep 17 00:00:00 2001 From: "Simon J. Gerraty" Date: Wed, 1 Jul 2020 02:13:04 +0000 Subject: [PATCH 1/2] Import bmake-20200629 from ChangeLog: o cond.c: do not eval unnecessary terms of conditionals. o meta.c: report error if lseek in filemon_read fails o str.c: performance improvement for Str_Match for multiple '*' o dieQuietly: supress the failure output from make when failing node is a sub-make or a sibling failed. This cuts down greatly on unhelpful noise at the end of build log. Disabled by -dj or .MAKE.DIE_QUIETLY=no o unit test for :Or --- ChangeLog | 39 +++++++++ FILES | 3 + LICENSE | 59 +++++++++++++ VERSION | 2 +- cond.c | 28 +++--- job.c | 17 ++-- main.c | 33 +++++++- make.h | 3 +- meta.c | 20 +++-- mk/ChangeLog | 17 ++++ mk/FILES | 1 + mk/gendirdeps.mk | 12 ++- mk/install-mk | 4 +- mk/mkopt.sh | 7 +- mk/sys/AIX.mk | 92 ++++++++++---------- mk/sys/Darwin.mk | 134 ++++++++++++++--------------- mk/sys/Generic.mk | 100 +++++++++++----------- mk/sys/HP-UX.mk | 126 +++++++++++++-------------- mk/sys/IRIX.mk | 108 +++++++++++------------ mk/sys/Linux.mk | 96 ++++++++++----------- mk/sys/NetBSD.mk | 124 +++++++++++++-------------- mk/sys/OSF1.mk | 104 +++++++++++------------ mk/sys/OpenBSD.mk | 112 ++++++++++++------------ mk/sys/SunOS.mk | 108 +++++++++++------------ mk/sys/UnixWare.mk | 174 +++++++++++++++++++------------------- str.c | 36 ++++---- unit-tests/Makefile | 5 +- unit-tests/cond-short.exp | 7 ++ unit-tests/cond-short.mk | 62 ++++++++++++++ unit-tests/modmatch.mk | 7 +- unit-tests/modorder.exp | 1 + unit-tests/modorder.mk | 3 +- 32 files changed, 941 insertions(+), 703 deletions(-) create mode 100644 LICENSE create mode 100644 unit-tests/cond-short.exp create mode 100644 unit-tests/cond-short.mk diff --git a/ChangeLog b/ChangeLog index 68b1826ea2aa..ae57f180d82c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,42 @@ +2020-06-29 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20200629 + Merge with NetBSD make, pick up + o cond.c: do not eval unnecessary terms of conditionals. + +2020-06-25 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20200625 + Merge with NetBSD make, pick up + o meta.c: report error if lseek in filemon_read fails + +2020-06-22 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20200622 + Merge with NetBSD make, pick up + o dieQuietly: ignore OP_SUBMAKE as too aggressive + +2020-06-19 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20200619 + Merge with NetBSD make, pick up + o str.c: performance improvement for Str_Match for multiple '*' + o dieQuietly: supress the failure output from make + when failing node is a sub-make or a sibling failed. + This cuts down greatly on unhelpful noise at the end of + build log. Disabled by -dj or .MAKE.DIE_QUIETLY=no + +2020-06-10 Simon J Gerraty + + * FILES: add LICENSE to appease some packagers. + This is an attempt to fairly represent the license on almost + 200 files, which are almost all BSD-3-Clause + The few exceptions being more liberal. + + * VERSION (_MAKE_VERSION): 20200610 + Merge with NetBSD make, pick up + o unit test for :Or + 2020-06-06 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200606 diff --git a/FILES b/FILES index 5dd4eae97b16..0716bffa3c3b 100644 --- a/FILES +++ b/FILES @@ -1,5 +1,6 @@ ChangeLog FILES +LICENSE Makefile Makefile.config.in PSD.doc/Makefile @@ -107,6 +108,8 @@ unit-tests/cond2.exp unit-tests/cond2.mk unit-tests/cond-late.mk unit-tests/cond-late.exp +unit-tests/cond-short.mk +unit-tests/cond-short.exp unit-tests/dollar.exp unit-tests/dollar.mk unit-tests/doterror.exp diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000000..dbad0ec06a4d --- /dev/null +++ b/LICENSE @@ -0,0 +1,59 @@ +The individual files in this distribution are copyright their +original contributors or assignees. +Including: + + Copyright (c) 1993-2020, Simon J Gerraty + Copyright (c) 2009-2016, Juniper Networks, Inc. + Copyright (c) 2009, John Birrell. + Copyright (c) 1997-2020 The NetBSD Foundation, Inc. + Copyright (c) 1998 Todd C. Miller + Copyright (c) 1989 by Berkeley Softworks + Copyright (c) 1988, 1989, 1990, 1992, 1993 + The Regents of the University of California. + Copyright (c) 1988, 1989 by Adam de Boor + +With the exception of the GNU configure script, which states: + + # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. + # + # This configure script is free software; the Free Software Foundation + # gives unlimited permission to copy, distribute and modify it. + +The license for this distribution is considered to be: + + SPDX-License-Identifier: BSD-3-Clause + +example (from https://opensource.org/licenses/BSD-3-Clause): + + Copyright + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + 3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + diff --git a/VERSION b/VERSION index 161d8f01ef2c..77ce0141acef 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ # keep this compatible with sh and make -_MAKE_VERSION=20200606 +_MAKE_VERSION=20200629 diff --git a/cond.c b/cond.c index 7c9c96acc83b..27034189bfd7 100644 --- a/cond.c +++ b/cond.c @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.75 2017/04/16 20:59:04 riastradh Exp $ */ +/* $NetBSD: cond.c,v 1.76 2020/06/28 11:06:26 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: cond.c,v 1.75 2017/04/16 20:59:04 riastradh Exp $"; +static char rcsid[] = "$NetBSD: cond.c,v 1.76 2020/06/28 11:06:26 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: cond.c,v 1.75 2017/04/16 20:59:04 riastradh Exp $"); +__RCSID("$NetBSD: cond.c,v 1.76 2020/06/28 11:06:26 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -146,7 +146,7 @@ typedef enum { * last two fields are stored in condInvert and condDefProc, respectively. */ static void CondPushBack(Token); -static int CondGetArg(char **, char **, const char *); +static int CondGetArg(Boolean, char **, char **, const char *); static Boolean CondDoDefined(int, const char *); static int CondStrMatch(const void *, const void *); static Boolean CondDoMake(int, const char *); @@ -225,9 +225,6 @@ CondPushBack(Token t) * CondGetArg -- * Find the argument of a built-in function. * - * Input: - * parens TRUE if arg should be bounded by parens - * * Results: * The length of the argument and the address of the argument. * @@ -238,7 +235,7 @@ CondPushBack(Token t) *----------------------------------------------------------------------- */ static int -CondGetArg(char **linePtr, char **argPtr, const char *func) +CondGetArg(Boolean doEval, char **linePtr, char **argPtr, const char *func) { char *cp; int argLen; @@ -290,7 +287,8 @@ CondGetArg(char **linePtr, char **argPtr, const char *func) int len; void *freeIt; - cp2 = Var_Parse(cp, VAR_CMD, VARF_UNDEFERR|VARF_WANTRES, + cp2 = Var_Parse(cp, VAR_CMD, VARF_UNDEFERR| + (doEval ? VARF_WANTRES : 0), &len, &freeIt); Buf_AddBytes(&buf, strlen(cp2), cp2); free(freeIt); @@ -577,7 +575,7 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt, Boolean strictLHS) /* if we are in quotes, then an undefined variable is ok */ str = Var_Parse(condExpr, VAR_CMD, ((!qt && doEval) ? VARF_UNDEFERR : 0) | - VARF_WANTRES, &len, freeIt); + (doEval ? VARF_WANTRES : 0), &len, freeIt); if (str == var_Error) { if (*freeIt) { free(*freeIt); @@ -813,7 +811,7 @@ compare_expression(Boolean doEval) } static int -get_mpt_arg(char **linePtr, char **argPtr, const char *func MAKE_ATTR_UNUSED) +get_mpt_arg(Boolean doEval, char **linePtr, char **argPtr, const char *func MAKE_ATTR_UNUSED) { /* * Use Var_Parse to parse the spec in parens and return @@ -827,7 +825,7 @@ get_mpt_arg(char **linePtr, char **argPtr, const char *func MAKE_ATTR_UNUSED) /* We do all the work here and return the result as the length */ *argPtr = NULL; - val = Var_Parse(cp - 1, VAR_CMD, VARF_WANTRES, &length, &freeIt); + val = Var_Parse(cp - 1, VAR_CMD, doEval ? VARF_WANTRES : 0, &length, &freeIt); /* * Advance *linePtr to beyond the closing ). Note that * we subtract one because 'length' is calculated from 'cp - 1'. @@ -864,7 +862,7 @@ compare_function(Boolean doEval) static const struct fn_def { const char *fn_name; int fn_name_len; - int (*fn_getarg)(char **, char **, const char *); + int (*fn_getarg)(Boolean, char **, char **, const char *); Boolean (*fn_proc)(int, const char *); } fn_defs[] = { { "defined", 7, CondGetArg, CondDoDefined }, @@ -892,7 +890,7 @@ compare_function(Boolean doEval) if (*cp != '(') break; - arglen = fn_def->fn_getarg(&cp, &arg, fn_def->fn_name); + arglen = fn_def->fn_getarg(doEval, &cp, &arg, fn_def->fn_name); if (arglen <= 0) { condExpr = cp; return arglen < 0 ? TOK_ERROR : TOK_FALSE; @@ -917,7 +915,7 @@ compare_function(Boolean doEval) * would be invalid if we did "defined(a)" - so instead treat as an * expression. */ - arglen = CondGetArg(&cp, &arg, NULL); + arglen = CondGetArg(doEval, &cp, &arg, NULL); for (cp1 = cp; isspace(*(unsigned char *)cp1); cp1++) continue; if (*cp1 == '=' || *cp1 == '!') diff --git a/job.c b/job.c index 0469a20b2e20..feaa3a63029d 100644 --- a/job.c +++ b/job.c @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.197 2020/02/06 01:13:19 sjg Exp $ */ +/* $NetBSD: job.c,v 1.198 2020/06/19 21:17:48 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: job.c,v 1.197 2020/02/06 01:13:19 sjg Exp $"; +static char rcsid[] = "$NetBSD: job.c,v 1.198 2020/06/19 21:17:48 sjg Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: job.c,v 1.197 2020/02/06 01:13:19 sjg Exp $"); +__RCSID("$NetBSD: job.c,v 1.198 2020/06/19 21:17:48 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -1058,10 +1058,11 @@ JobFinish (Job *job, WAIT_T status) meta_job_error(job, job->node, job->flags, WEXITSTATUS(status)); } #endif - (void)printf("*** [%s] Error code %d%s\n", - job->node->name, - WEXITSTATUS(status), - (job->flags & JOB_IGNERR) ? " (ignored)" : ""); + if (!dieQuietly(job->node, -1)) + (void)printf("*** [%s] Error code %d%s\n", + job->node->name, + WEXITSTATUS(status), + (job->flags & JOB_IGNERR) ? " (ignored)" : ""); if (job->flags & JOB_IGNERR) { WAIT_STATUS(status) = 0; } else { @@ -3039,6 +3040,8 @@ Job_TokenWithdraw(void) /* And put the stopper back */ while (write(tokenWaitJob.outPipe, &tok, 1) == -1 && errno == EAGAIN) continue; + if (dieQuietly(NULL, 1)) + exit(2); Fatal("A failure has been detected in another branch of the parallel make"); } diff --git a/main.c b/main.c index 1756f7a7d32f..3e28bd5bdc15 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.274 2020/03/30 02:41:06 sjg Exp $ */ +/* $NetBSD: main.c,v 1.276 2020/06/22 20:15:25 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,7 +69,7 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: main.c,v 1.274 2020/03/30 02:41:06 sjg Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.276 2020/06/22 20:15:25 sjg Exp $"; #else #include #ifndef lint @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: main.c,v 1.274 2020/03/30 02:41:06 sjg Exp $"); +__RCSID("$NetBSD: main.c,v 1.276 2020/06/22 20:15:25 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -1889,6 +1889,8 @@ void Finish(int errors) /* number of errors encountered in Make_Make */ { + if (dieQuietly(NULL, -1)) + exit(2); Fatal("%d error%s", errors, errors == 1 ? "" : "s"); } @@ -2041,6 +2043,27 @@ addErrorCMD(void *cmdp, void *gnp MAKE_ATTR_UNUSED) return 0; } +/* + * Return true if we should die without noise. + * For example our failing child was a sub-make + * or failure happend elsewhere. + */ +int +dieQuietly(GNode *gn, int bf) +{ + static int quietly = -1; + + if (quietly < 0) { + if (DEBUG(JOB) || getBoolean(".MAKE.DIE_QUIETLY", 1) == 0) + quietly = 0; + else if (bf >= 0) + quietly = bf; + else + quietly = (gn) ? ((gn->type & (OP_MAKE)) != 0) : 0; + } + return quietly; +} + void PrintOnError(GNode *gn, const char *s) { @@ -2048,6 +2071,10 @@ PrintOnError(GNode *gn, const char *s) char tmp[64]; char *cp; + /* we generally want to keep quiet if a sub-make died */ + if (dieQuietly(gn, -1)) + return; + if (s) printf("%s", s); diff --git a/make.h b/make.h index 4a693f14a153..4057137c7a10 100644 --- a/make.h +++ b/make.h @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.107 2020/04/03 03:35:16 sjg Exp $ */ +/* $NetBSD: make.h,v 1.108 2020/06/19 21:17:48 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -503,6 +503,7 @@ void Make_DoAllVar(GNode *); Boolean Make_Run(Lst); char * Check_Cwd_Cmd(const char *); void Check_Cwd(const char **); +int dieQuietly(GNode *, int); void PrintOnError(GNode *, const char *); void Main_ExportMAKEFLAGS(Boolean); Boolean Main_SetObjdir(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2); diff --git a/meta.c b/meta.c index ca40c6dd8224..03a67f19e87b 100644 --- a/meta.c +++ b/meta.c @@ -1,4 +1,4 @@ -/* $NetBSD: meta.c,v 1.81 2020/04/03 03:32:28 sjg Exp $ */ +/* $NetBSD: meta.c,v 1.82 2020/06/25 15:45:37 sjg Exp $ */ /* * Implement 'meta' mode. @@ -174,14 +174,18 @@ filemon_read(FILE *mfp, int fd) return 0; } /* rewind */ - (void)lseek(fd, (off_t)0, SEEK_SET); + if (lseek(fd, (off_t)0, SEEK_SET) < 0) { + error = errno; + warn("Could not rewind filemon"); + fprintf(mfp, "\n"); + } else { + error = 0; + fprintf(mfp, "\n-- filemon acquired metadata --\n"); - error = 0; - fprintf(mfp, "\n-- filemon acquired metadata --\n"); - - while ((n = read(fd, buf, sizeof(buf))) > 0) { - if ((int)fwrite(buf, 1, n, mfp) < n) - error = EIO; + while ((n = read(fd, buf, sizeof(buf))) > 0) { + if ((int)fwrite(buf, 1, n, mfp) < n) + error = EIO; + } } fflush(mfp); if (close(fd) < 0) diff --git a/mk/ChangeLog b/mk/ChangeLog index f061d43949e2..bd8b1b1f5b72 100644 --- a/mk/ChangeLog +++ b/mk/ChangeLog @@ -1,3 +1,20 @@ +2020-06-28 Simon J Gerraty + + * sys/*.mk: make it easier for local*sys.mk to customize by + using ?= + +2020-06-22 Simon J Gerraty + + * gendirdeps.mk (LOCAL_DEPENDS_GUARD): if we don't build at level 0 + it is much safer to guard local depends with a simple check for + .MAKE.LEVEL > 0 + +2020-06-10 Simon J Gerraty + + * install-mk (MK_VERSION): 20200610 + + * mkopt.sh: this needs posix shell so #!/bin/sh should be ok + 2020-06-06 Simon J Gerraty * install-mk (MK_VERSION): 20200606 diff --git a/mk/FILES b/mk/FILES index dcd00ec2f581..360fb613a15e 100644 --- a/mk/FILES +++ b/mk/FILES @@ -1,5 +1,6 @@ ChangeLog FILES +LICENSE README auto.obj.mk autoconf.mk diff --git a/mk/gendirdeps.mk b/mk/gendirdeps.mk index d402cbcc4765..82618f2225a3 100644 --- a/mk/gendirdeps.mk +++ b/mk/gendirdeps.mk @@ -1,4 +1,4 @@ -# $Id: gendirdeps.mk,v 1.42 2020/05/16 23:21:48 sjg Exp $ +# $Id: gendirdeps.mk,v 1.44 2020/06/23 04:21:51 sjg Exp $ # Copyright (c) 2011-2020, Simon J. Gerraty # Copyright (c) 2010-2018, Juniper Networks, Inc. @@ -51,7 +51,7 @@ all: _CURDIR ?= ${.CURDIR} _OBJDIR ?= ${.OBJDIR} _OBJTOP ?= ${OBJTOP} -_OBJROOT ?= ${OBJROOT:U${_OBJTOP}} +_OBJROOT ?= ${OBJROOT:U${_OBJTOP:H}} .if ${_OBJROOT:M*/} _slash=/ .else @@ -339,6 +339,12 @@ CAT_DEPEND ?= .depend .PHONY: ${_DEPENDFILE} .endif +.if ${BUILD_AT_LEVEL0:Uno:tl} == "no" +LOCAL_DEPENDS_GUARD ?= _{.MAKE.LEVEL} > 0 +.else +LOCAL_DEPENDS_GUARD ?= _{DEP_RELDIR} == _{_DEP_RELDIR} +.endif + # 'cat .depend' should suffice, but if we are mixing build modes # .depend may contain things we don't want. # The sed command at the end of the stream, allows for the filters @@ -350,7 +356,7 @@ ${_DEPENDFILE}: .NOMETA ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m): ${_include_src_dirdeps} \ echo '.include '; \ echo; \ - echo '.if $${DEP_RELDIR} == $${_DEP_RELDIR}'; \ + echo '.if ${LOCAL_DEPENDS_GUARD}'; \ echo '# local dependencies - needed for -jN in clean tree'; \ [ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \ echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID} diff --git a/mk/install-mk b/mk/install-mk index 4c29ef294bd6..83542a945cd4 100644 --- a/mk/install-mk +++ b/mk/install-mk @@ -55,7 +55,7 @@ # Simon J. Gerraty # RCSid: -# $Id: install-mk,v 1.172 2020/06/06 22:41:15 sjg Exp $ +# $Id: install-mk,v 1.173 2020/06/23 04:16:35 sjg Exp $ # # @(#) Copyright (c) 1994 Simon J. Gerraty # @@ -70,7 +70,7 @@ # sjg@crufty.net # -MK_VERSION=20200606 +MK_VERSION=20200622 OWNER= GROUP= MODE=444 diff --git a/mk/mkopt.sh b/mk/mkopt.sh index ad58479c2bf0..929a5aa83a66 100755 --- a/mk/mkopt.sh +++ b/mk/mkopt.sh @@ -1,7 +1,8 @@ -: -# $Id: mkopt.sh,v 1.11 2017/03/18 21:36:42 sjg Exp $ +#!/bin/sh + +# $Id: mkopt.sh,v 1.12 2020/06/23 04:16:35 sjg Exp $ # -# @(#) Copyright (c) 2014, Simon J. Gerraty +# @(#) Copyright (c) 2014, 2020, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. diff --git a/mk/sys/AIX.mk b/mk/sys/AIX.mk index a5c49584fe2c..b848d99fb4e8 100644 --- a/mk/sys/AIX.mk +++ b/mk/sys/AIX.mk @@ -1,80 +1,80 @@ # $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ # @(#)sys.mk 5.11 (Berkeley) 3/13/91 -OS= AIX -unix= We run ${OS}. -ROOT_GROUP= system +OS ?= AIX +unix ?= We run ${OS}. +ROOT_GROUP ?= system # This needs a lot of work yet... -NOPIC=no # no shared libs? +NOPIC ?=no # no shared libs? .SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4 .LIBS: .a -AR= ar -ARFLAGS= rl -RANLIB= ranlib +AR ?= ar +ARFLAGS ?= rl +RANLIB ?= ranlib -AS= as +AS ?= as AFLAGS= -COMPILE.s= ${AS} ${AFLAGS} -LINK.s= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c -LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.s ?= ${AS} ${AFLAGS} +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} .if exists(/usr/local/bin/gcc) -CC= gcc -DBG= -O -g -STATIC?= -static +CC ?= gcc +DBG ?= -O -g +STATIC ?= -static .else -CC= cc -DBG= -g -STATIC= +CC ?= cc +DBG ?= -g +STATIC ?= .endif -CFLAGS= ${DBG} -COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CFLAGS ?= ${DBG} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -CXX= g++ -CXXFLAGS= ${CFLAGS} -COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXX ?= g++ +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -CPP= cpp +CPP ?= cpp .if defined(DESTDIR) CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include .endif -MK_DEP= mkdeps.sh -N -FC= f77 -FFLAGS= -O +MK_DEP ?= mkdeps.sh -N +FC ?= f77 +FFLAGS ?= -O RFLAGS= -COMPILE.f= ${FC} ${FFLAGS} -c -LINK.f= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -LEX= lex +LEX ?= lex LFLAGS= -LEX.l= ${LEX} ${LFLAGS} +LEX.l ?= ${LEX} ${LFLAGS} -LD= ld +LD ?= ld LDFLAGS= -LINT= lint -LINTFLAGS= -chapbx +LINT ?= lint +LINTFLAGS ?= -chapbx -PC= pc +PC ?= pc PFLAGS= -COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} -YACC= yacc -YFLAGS= -d -YACC.y= ${YACC} ${YFLAGS} +YACC ?= yacc +YFLAGS ?= -d +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/mk/sys/Darwin.mk b/mk/sys/Darwin.mk index 6d37127be13f..ea04b416ff3a 100644 --- a/mk/sys/Darwin.mk +++ b/mk/sys/Darwin.mk @@ -1,108 +1,108 @@ # $NetBSD: Darwin.sys.mk,v 1.3 2003/02/16 09:44:41 grant Exp $ # @(#)sys.mk 8.2 (Berkeley) 3/21/94 -OS= Darwin -unix?= We run ${OS}. +OS ?= Darwin +unix ?= We run ${OS}. .SUFFIXES: .out .a .ln .o .s .S .c .m ${CXX_SUFFIXES} .F .f .r .y .l .cl .p .h .SUFFIXES: .sh .m4 .dylib .LIBS: .a .dylib -SHLIBEXT = .dylib -HOST_LIBEXT = .dylib -DSHLIBEXT = .dylib +SHLIBEXT ?= .dylib +HOST_LIBEXT ?= .dylib +DSHLIBEXT ?= .dylib -AR?= ar -ARFLAGS?= rl +AR ?= ar +ARFLAGS ?= rl RANLIB = -AS?= as -AFLAGS?= -COMPILE.s?= ${AS} ${AFLAGS} -LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +AS ?= as +AFLAGS ?= +COMPILE.s ?= ${AS} ${AFLAGS} +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} -PIPE?= -pipe +PIPE ?= -pipe .if exists(/usr/bin/clang) -CC?= cc ${PIPE} -CXX?= c++ +CC ?= cc ${PIPE} +CXX ?= c++ .elif exists(/usr/bin/gcc) -CC?= gcc ${PIPE} +CC ?= gcc ${PIPE} .else -CC?= cc ${PIPE} +CC ?= cc ${PIPE} .endif -DBG?= -O2 -CFLAGS?= ${DBG} -COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +DBG ?= -O2 +CFLAGS ?= ${DBG} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} .if exists(/usr/bin/g++) -CXX?= g++ +CXX ?= g++ .else -CXX?= c++ +CXX ?= c++ .endif -CXXFLAGS?= ${CFLAGS} -COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -OBJC?= ${CC} -OBJCFLAGS?= ${CFLAGS} -COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c -LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} +OBJC ?= ${CC} +OBJCFLAGS ?= ${CFLAGS} +COMPILE.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} -CPP?= cpp -NOLINT= 1 -CPPFLAGS?= +CPP ?= cpp +NOLINT ?= 1 +CPPFLAGS ?= -MK_DEP?= mkdep +MK_DEP ?= mkdep -FC?= f77 -FFLAGS?= -O -RFLAGS?= -COMPILE.f?= ${FC} ${FFLAGS} -c -LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +FC ?= f77 +FFLAGS ?= -O +RFLAGS ?= +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -INSTALL?= install +INSTALL ?= install -LEX?= lex -LFLAGS?= -LEX.l?= ${LEX} ${LFLAGS} +LEX ?= lex +LFLAGS ?= +LEX.l ?= ${LEX} ${LFLAGS} -LD?= ld -LDFLAGS?= +LD ?= ld +LDFLAGS ?= -SHLIB_TEENY = 0 -SHLIB_MINOR = 0 +SHLIB_TEENY ?= 0 +SHLIB_MINOR ?= 0 -MKPICLIB = no -LIBEXT = .dylib +MKPICLIB ?= no +LIBEXT ?= .dylib -LINT?= lint -LINTFLAGS?= -chapbx +LINT ?= lint +LINTFLAGS ?= -chapbx -LORDER?= lorder +LORDER ?= lorder -NM?= nm +NM ?= nm -PC?= pc -PFLAGS?= -COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +PC ?= pc +PFLAGS ?= +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} -SIZE?= size +SIZE ?= size -TSORT?= tsort -q +TSORT ?= tsort -q -YACC?= bison -y -YFLAGS?= -d -YACC.y?= ${YACC} ${YFLAGS} +YACC ?= bison -y +YFLAGS ?= -d +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/mk/sys/Generic.mk b/mk/sys/Generic.mk index aa92a6246411..9a3d3bffc183 100644 --- a/mk/sys/Generic.mk +++ b/mk/sys/Generic.mk @@ -1,4 +1,4 @@ -# $Id: Generic.mk,v 1.14 2020/04/17 21:08:17 sjg Exp $ +# $Id: Generic.mk,v 1.16 2020/06/29 14:34:42 sjg Exp $ # # some reasonable defaults @@ -7,7 +7,7 @@ .LIBS: .a -tools = \ +tools ?= \ ar \ lorder \ ranlib \ @@ -27,71 +27,71 @@ MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} TSORT += -q .endif -ARFLAGS?= rl +ARFLAGS ?= rl -AS?= as -AFLAGS?= +AS ?= as +AFLAGS ?= .if ${MACHINE_ARCH} == "sparc64" AFLAGS+= -Wa,-Av9a .endif -COMPILE.s?= ${CC} ${AFLAGS} -c -LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp -LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.s ?= ${CC} ${AFLAGS} -c +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} -CC?= cc -DBG?= -O2 -CFLAGS?= ${DBG} -COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CC ?= cc +DBG ?= -O2 +CFLAGS ?= ${DBG} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -CXX?= c++ -CXXFLAGS?= ${CFLAGS} -COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXX ?= c++ +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -OBJC?= ${CC} -OBJCFLAGS?= ${CFLAGS} -COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c -LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} +OBJC ?= ${CC} +OBJCFLAGS ?= ${CFLAGS} +COMPILE.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} -CPP?= cpp -CPPFLAGS?= +CPP ?= cpp +CPPFLAGS ?= -FC?= f77 -FFLAGS?= -O -RFLAGS?= -COMPILE.f?= ${FC} ${FFLAGS} -c -LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +FC ?= f77 +FFLAGS ?= -O +RFLAGS ?= +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -INSTALL?= install +INSTALL ?= install -LEX?= lex -LFLAGS?= -LEX.l?= ${LEX} ${LFLAGS} +LEX ?= lex +LFLAGS ?= +LEX.l ?= ${LEX} ${LFLAGS} -LD?= ld -LDFLAGS?= +LD ?= ld +LDFLAGS ?= -LINT?= lint -LINTFLAGS?= -chapbxzF +LINT ?= lint +LINTFLAGS ?= -chapbxzF -NM?= nm +NM ?= nm -PC?= pc -PFLAGS?= -COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +PC ?= pc +PFLAGS ?= +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} -SIZE?= size +SIZE ?= size -YACC?= yacc -YFLAGS?= -YACC.y?= ${YACC} ${YFLAGS} +YACC ?= yacc +YFLAGS ?= +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/mk/sys/HP-UX.mk b/mk/sys/HP-UX.mk index ac5ce37b85fc..34dd2881d83d 100644 --- a/mk/sys/HP-UX.mk +++ b/mk/sys/HP-UX.mk @@ -1,122 +1,122 @@ -# $Id: HP-UX.mk,v 1.12 2020/04/17 21:08:17 sjg Exp $ +# $Id: HP-UX.mk,v 1.14 2020/06/29 14:34:42 sjg Exp $ # $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ # @(#)sys.mk 5.11 (Berkeley) 3/13/91 -OS= HP-UX -ROOT_GROUP= root -unix?= We run ${OS}. +OS ?= HP-UX +ROOT_GROUP ?= root +unix ?= We run ${OS}. # HP-UX's cc does not provide any clues as to wether this is 9.x or 10.x # nor does sys/param.h, so we'll use the existence of /hp-ux .if exists("/hp-ux") -OSMAJOR?=9 +OSMAJOR ?=9 .endif -OSMAJOR?=10 -__HPUX_VERSION?=${OSMAJOR} +OSMAJOR ?=10 +__HPUX_VERSION ?=${OSMAJOR} .SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4 -LIBMODE= 755 -LIBCRT0= /lib/crt0.o +LIBMODE ?= 755 +LIBCRT0 ?= /lib/crt0.o .LIBS: .a # +b is needed to stop the binaries from insisting on having # the build tree available :-) # +s tells the dynamic loader to use SHLIB_PATH if set -LD_bpath?=-Wl,+b/lib:/usr/lib:/usr/local/lib -LD_spath?=-Wl,+s +LD_bpath ?=-Wl,+b/lib:/usr/lib:/usr/local/lib +LD_spath ?=-Wl,+s LDADD+= ${LD_bpath} ${LD_spath} .if exists(/usr/lib/end.o) LDADD+= /usr/lib/end.o .endif -AR= ar -ARFLAGS= rl -RANLIB= : +AR ?= ar +ARFLAGS ?= rl +RANLIB ?= : AFLAGS= -COMPILE.s= ${AS} ${AFLAGS} -LINK.s= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c -LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.s ?= ${AS} ${AFLAGS} +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} .if exists(/usr/local/bin/gcc) -PIPE?= -pipe -CC?= gcc ${PIPE} -AS= gas -DBG?= -O -g -STATIC?= -static +PIPE ?= -pipe +CC ?= gcc ${PIPE} +AS ?= gas +DBG ?= -O -g +STATIC ?= -static .if defined(DESTDIR) CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include .endif .else # HP's bundled compiler knows not -g or -O -AS= as -CC= cc +AS ?= as +CC ?= cc .if exists(/opt/ansic/bin/cc) -CCMODE?=-Ae +ESlit -PICFLAG?= +z +CCMODE ?=-Ae +ESlit +PICFLAG ?= +z LD_x= -DBG?=-g -O +DBG ?=-g -O .endif -DBG?= -STATIC?= -Wl,-a,archive +DBG ?= +STATIC ?= -Wl,-a,archive .endif .if (${__HPUX_VERSION} == "10") -CCSOURCE_FLAGS?= -D_HPUX_SOURCE +CCSOURCE_FLAGS ?= -D_HPUX_SOURCE .else -CCSOURCE_FLAGS?= -D_HPUX_SOURCE -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_XOPEN_SOURCE -D_INCLUDE_XOPEN_SOURCE_EXTENDED +CCSOURCE_FLAGS ?= -D_HPUX_SOURCE -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_XOPEN_SOURCE -D_INCLUDE_XOPEN_SOURCE_EXTENDED .endif -CFLAGS= ${DBG} -CFLAGS+= ${CCMODE} -D__hpux__ -D__HPUX_VERSION=${__HPUX_VERSION} ${CCSOURCE_FLAGS} -COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CFLAGS ?= ${DBG} +CFLAGS+ ?= ${CCMODE} -D__hpux__ -D__HPUX_VERSION=${__HPUX_VERSION} ${CCSOURCE_FLAGS} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -CXX= g++ -CXXFLAGS= ${CFLAGS} -COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXX ?= g++ +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -CPP= cpp +CPP ?= cpp -MK_DEP= mkdeps.sh -N -FC= f77 -FFLAGS= -O +MK_DEP ?= mkdeps.sh -N +FC ?= f77 +FFLAGS ?= -O RFLAGS= -COMPILE.f= ${FC} ${FFLAGS} -c -LINK.f= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -LEX= lex +LEX ?= lex LFLAGS= -LEX.l= ${LEX} ${LFLAGS} +LEX.l ?= ${LEX} ${LFLAGS} -LD= ld +LD ?= ld LDFLAGS= -LINT= lint -LINTFLAGS= -chapbx +LINT ?= lint +LINTFLAGS ?= -chapbx -PC= pc +PC ?= pc PFLAGS= -COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} # HP's sh sucks ENV= -MAKE_SHELL= /bin/ksh +MAKE_SHELL ?= /bin/ksh .if exists(/usr/local/bin/bison) -YACC= bison -y +YACC ?= bison -y .else -YACC= yacc +YACC ?= yacc .endif -YFLAGS= -d -YACC.y= ${YACC} ${YFLAGS} +YFLAGS ?= -d +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/mk/sys/IRIX.mk b/mk/sys/IRIX.mk index b448fb5720cf..a194c1e78a11 100644 --- a/mk/sys/IRIX.mk +++ b/mk/sys/IRIX.mk @@ -7,7 +7,7 @@ OS!= uname -s ROOT_GROUP!= sed -n /:0:/s/:.*//p /etc/group .MAKEOVERRIDES+= OS ROOT_GROUP .endif -unix?= We run ${OS}. +unix ?= We run ${OS}. .endif .SUFFIXES: .out .a .ln .o .s .S .c ${CXX_SUFFIXES} .F .f .r .y .l .cl .p .h @@ -15,75 +15,75 @@ unix?= We run ${OS}. .LIBS: .a -AR?= ar -ARFLAGS?= rl -RANLIB?= ranlib +AR ?= ar +ARFLAGS ?= rl +RANLIB ?= ranlib -AS?= as -AFLAGS?= -COMPILE.s?= ${CC} ${AFLAGS} -c -LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp -LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +AS ?= as +AFLAGS ?= +COMPILE.s ?= ${CC} ${AFLAGS} -c +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} -CC?= cc -NOGCCERROR?= # defined -DBG?= -O2 -CFLAGS?= ${DBG} -COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CC ?= cc +NOGCCERROR ?= # defined +DBG ?= -O2 +CFLAGS ?= ${DBG} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -CXX?= CC -CXXFLAGS?= ${CFLAGS} -COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXX ?= CC +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -OBJC?= ${CC} -OBJCFLAGS?= ${CFLAGS} -COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c -LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} +OBJC ?= ${CC} +OBJCFLAGS ?= ${CFLAGS} +COMPILE.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} -CPP?= CC -CPPFLAGS?= +CPP ?= CC +CPPFLAGS ?= -FC?= f77 -FFLAGS?= -O -RFLAGS?= -COMPILE.f?= ${FC} ${FFLAGS} -c -LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +FC ?= f77 +FFLAGS ?= -O +RFLAGS ?= +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -INSTALL?= ${PREFIX}/bin/install-sh +INSTALL ?= ${PREFIX}/bin/install-sh -LEX?= lex -LFLAGS?= -LEX.l?= ${LEX} ${LFLAGS} +LEX ?= lex +LFLAGS ?= +LEX.l ?= ${LEX} ${LFLAGS} -LD?= ld -LDFLAGS?= +LD ?= ld +LDFLAGS ?= -LINT?= lint -LINTFLAGS?= -chapbxzF +LINT ?= lint +LINTFLAGS ?= -chapbxzF -LORDER?= lorder +LORDER ?= lorder -NM?= nm +NM ?= nm -PC?= pc -PFLAGS?= -COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +PC ?= pc +PFLAGS ?= +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} -SIZE?= size +SIZE ?= size -TSORT?= tsort -q +TSORT ?= tsort -q -YACC?= yacc -YFLAGS?= -YACC.y?= ${YACC} ${YFLAGS} +YACC ?= yacc +YFLAGS ?= +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/mk/sys/Linux.mk b/mk/sys/Linux.mk index 978aec098ca3..bf80bb3addce 100644 --- a/mk/sys/Linux.mk +++ b/mk/sys/Linux.mk @@ -1,83 +1,83 @@ -# $Id: Linux.mk,v 1.10 2020/04/17 21:08:17 sjg Exp $ +# $Id: Linux.mk,v 1.12 2020/06/29 14:34:42 sjg Exp $ # $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ # @(#)sys.mk 5.11 (Berkeley) 3/13/91 -OS?= Linux -unix?= We run ${OS}. +OS ?= Linux +unix ?= We run ${OS}. -ROOT_GROUP= root +ROOT_GROUP ?= root # would be better to work out where it is... -LIBCRT0= /dev/null +LIBCRT0 ?= /dev/null -NEED_SOLINKS=yes +NEED_SOLINKS ?=yes .SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4 .LIBS: .a -AR= ar -ARFLAGS= rl -RANLIB= ranlib +AR ?= ar +ARFLAGS ?= rl +RANLIB ?= ranlib -AS= as +AS ?= as AFLAGS= -COMPILE.s= ${AS} ${AFLAGS} -LINK.s= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c -LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.s ?= ${AS} ${AFLAGS} +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} .if exists(/usr/local/bin/gcc) -CC= gcc -pipe -DBG= -O -g -STATIC?= -static +CC ?= gcc -pipe +DBG ?= -O -g +STATIC ?= -static .else -CC= cc -pipe -DBG= -g -STATIC= -Bstatic +CC ?= cc -pipe +DBG ?= -g +STATIC ?= -Bstatic .endif -CFLAGS= ${DBG} -COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CFLAGS ?= ${DBG} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -CXX= g++ -CXXFLAGS= ${CFLAGS} -COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXX ?= g++ +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -CPP= cpp +CPP ?= cpp .if defined(DESTDIR) CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include .endif -MK_DEP= mkdeps.sh -N -FC= f77 -FFLAGS= -O +MK_DEP ?= mkdeps.sh -N +FC ?= f77 +FFLAGS ?= -O RFLAGS= -COMPILE.f= ${FC} ${FFLAGS} -c -LINK.f= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -LEX= lex +LEX ?= lex LFLAGS= -LEX.l= ${LEX} ${LFLAGS} +LEX.l ?= ${LEX} ${LFLAGS} -LD= ld +LD ?= ld LDFLAGS= -LINT= lint -LINTFLAGS= -chapbx +LINT ?= lint +LINTFLAGS ?= -chapbx -PC= pc +PC ?= pc PFLAGS= -COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} -YACC= yacc -YFLAGS= -d -YACC.y= ${YACC} ${YFLAGS} +YACC ?= yacc +YFLAGS ?= -d +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/mk/sys/NetBSD.mk b/mk/sys/NetBSD.mk index a1711a5ec9db..2e72cc742e4f 100644 --- a/mk/sys/NetBSD.mk +++ b/mk/sys/NetBSD.mk @@ -1,21 +1,21 @@ # $NetBSD: sys.mk,v 1.66.2.1 2002/06/05 03:31:01 lukem Exp $ # @(#)sys.mk 8.2 (Berkeley) 3/21/94 -OS= NetBSD -unix?= We run ${OS}. +OS ?= NetBSD +unix ?= We run ${OS}. .if !defined(MAKE_VERSION) # we are running native make # which defined MAKE_VERSION between 20010609 and 20090324 # so we can make a rough guess .if defined(.MAKE.LEVEL) -MAKE_VERSION = 20090908 +MAKE_VERSION ?= 20090908 .elif defined(.MAKE.MAKEFILES) # introduced 20071008 -MAKE_VERSION = 20090324 +MAKE_VERSION ?= 20090324 .else # this just before when MAKE_VERSION was introduced -MAKE_VERSION = 20010606 +MAKE_VERSION ?= 20010606 .endif .endif @@ -24,29 +24,29 @@ MAKE_VERSION = 20010606 .LIBS: .a -AR?= ar -ARFLAGS?= rl -RANLIB?= ranlib +AR ?= ar +ARFLAGS ?= rl +RANLIB ?= ranlib -AS?= as -AFLAGS?= -COMPILE.s?= ${CC} ${AFLAGS} -c -LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp -LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +AS ?= as +AFLAGS ?= +COMPILE.s ?= ${CC} ${AFLAGS} -c +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} -CC?= cc +CC ?= cc # need to make sure this is set MACHINE_ARCH.${MACHINE} ?= ${MACHINE} .if empty(MACHINE_ARCH) -MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} +MACHINE_ARCH ?= ${MACHINE_ARCH.${MACHINE}} .endif # # CPU model, derived from MACHINE_ARCH # -MACHINE_CPU= ${MACHINE_ARCH:C/mipse[bl]/mips/:C/mips64e[bl]/mips/:C/sh3e[bl]/sh3/:S/m68000/m68k/:S/armeb/arm/} +MACHINE_CPU ?= ${MACHINE_ARCH:C/mipse[bl]/mips/:C/mips64e[bl]/mips/:C/sh3e[bl]/sh3/:S/m68000/m68k/:S/armeb/arm/} .if ${MACHINE_CPU} == "alpha" || \ ${MACHINE_CPU} == "arm" || \ @@ -56,69 +56,69 @@ MACHINE_CPU= ${MACHINE_ARCH:C/mipse[bl]/mips/:C/mips64e[bl]/mips/:C/sh3e[bl]/sh3 ${MACHINE_CPU} == "powerpc" || \ ${MACHINE_CPU} == "sparc" || \ ${MACHINE_CPU} == "vax" -DBG?= -O2 +DBG ?= -O2 .elif ${MACHINE_ARCH} == "x86_64" -DBG?= +DBG ?= .elif ${MACHINE_ARCH} == "sparc64" -DBG?= -O -ffixed-g4 #Hack for embedany memory model compatibility +DBG ?= -O -ffixed-g4 #Hack for embedany memory model compatibility .else -DBG?= -O +DBG ?= -O .endif -CFLAGS?= ${DBG} -COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CFLAGS ?= ${DBG} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -CXX?= c++ -CXXFLAGS?= ${CFLAGS} -COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXX ?= c++ +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -OBJC?= ${CC} -OBJCFLAGS?= ${CFLAGS} -COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c -LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} +OBJC ?= ${CC} +OBJCFLAGS ?= ${CFLAGS} +COMPILE.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} -CPP?= cpp -CPPFLAGS?= +CPP ?= cpp +CPPFLAGS ?= -FC?= f77 -FFLAGS?= -O -RFLAGS?= -COMPILE.f?= ${FC} ${FFLAGS} -c -LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +FC ?= f77 +FFLAGS ?= -O +RFLAGS ?= +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -INSTALL?= install +INSTALL ?= install -LEX?= lex -LFLAGS?= -LEX.l?= ${LEX} ${LFLAGS} +LEX ?= lex +LFLAGS ?= +LEX.l ?= ${LEX} ${LFLAGS} -LD?= ld -LDFLAGS?= +LD ?= ld +LDFLAGS ?= -LINT?= lint -LINTFLAGS?= -chapbxzF +LINT ?= lint +LINTFLAGS ?= -chapbxzF -LORDER?= lorder +LORDER ?= lorder -NM?= nm +NM ?= nm -PC?= pc -PFLAGS?= -COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +PC ?= pc +PFLAGS ?= +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} -SIZE?= size +SIZE ?= size -TSORT?= tsort -q +TSORT ?= tsort -q -YACC?= yacc -YFLAGS?= -YACC.y?= ${YACC} ${YFLAGS} +YACC ?= yacc +YFLAGS ?= +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/mk/sys/OSF1.mk b/mk/sys/OSF1.mk index 0d0a73f40c98..4c1a09f6f5f7 100644 --- a/mk/sys/OSF1.mk +++ b/mk/sys/OSF1.mk @@ -1,15 +1,15 @@ -# $Id: OSF1.mk,v 1.9 2020/04/17 21:08:17 sjg Exp $ +# $Id: OSF1.mk,v 1.11 2020/06/29 14:34:42 sjg Exp $ # $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ # @(#)sys.mk 5.11 (Berkeley) 3/13/91 -OS?= OSF1 -unix?= We run ${OS}. -ROOT_GROUP= system +OS ?= OSF1 +unix ?= We run ${OS}. +ROOT_GROUP ?= system # can't fine one anywhere, so just stop the dependency -LIBCRT0= /dev/null +LIBCRT0 ?= /dev/null -PATH=/usr/sbin:/usr/bin:/usr/ucb:/opt/gnu/bin:/usr/ccs/bin +PATH ?=/usr/sbin:/usr/bin:/usr/ucb:/opt/gnu/bin:/usr/ccs/bin .SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4 @@ -17,78 +17,78 @@ PATH=/usr/sbin:/usr/bin:/usr/ucb:/opt/gnu/bin:/usr/ccs/bin # no -X LD_X= -LD_x= -x -LD_r= -r -AR= ar -ARFLAGS= rl -RANLIB= ranlib +LD_x ?= -x +LD_r ?= -r +AR ?= ar +ARFLAGS ?= rl +RANLIB ?= ranlib -AS= as -AS_STDIN= - +AS ?= as +AS_STDIN ?= - AFLAGS= -COMPILE.s= ${AS} ${AFLAGS} -LINK.s= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c -LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.s ?= ${AS} ${AFLAGS} +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} .if exists(/opt/gnu/bin/gcc) || exists(/usr/local/bin/gcc) -CC?= gcc +CC ?= gcc .else -CC?= cc -std +CC ?= cc -std .endif .if (${CC:T} == "gcc") -DBG= -O -g -STATIC= -static -DBG= -g -STATIC= -non_shared +DBG ?= -O -g +STATIC ?= -static +DBG ?= -g +STATIC ?= -non_shared .endif -CFLAGS= ${DBG} -COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CFLAGS ?= ${DBG} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -CXX= g++ -CXXFLAGS= ${CFLAGS} -COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXX ?= g++ +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -CPP= /usr/ccs/lib/cpp +CPP ?= /usr/ccs/lib/cpp .if defined(DESTDIR) CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include .endif -MK_DEP= mkdeps.sh -N -FC= f77 -FFLAGS= -O +MK_DEP ?= mkdeps.sh -N +FC ?= f77 +FFLAGS ?= -O RFLAGS= -COMPILE.f= ${FC} ${FFLAGS} -c -LINK.f= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -LEX= lex +LEX ?= lex LFLAGS= -LEX.l= ${LEX} ${LFLAGS} +LEX.l ?= ${LEX} ${LFLAGS} -LD= ld +LD ?= ld LDFLAGS= -LINT= lint -LINTFLAGS= -chapbx +LINT ?= lint +LINTFLAGS ?= -chapbx -PC= pc +PC ?= pc PFLAGS= -COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} .if exists(/usr/local/bin/bison) || exists(/opt/gnu/bin/bison) -YACC= bison -y +YACC ?= bison -y .else -YACC= yacc +YACC ?= yacc .endif -YFLAGS= -d -YACC.y= ${YACC} ${YFLAGS} +YFLAGS ?= -d +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/mk/sys/OpenBSD.mk b/mk/sys/OpenBSD.mk index 8b87ef3e85a4..d73bb0d82c9a 100644 --- a/mk/sys/OpenBSD.mk +++ b/mk/sys/OpenBSD.mk @@ -1,8 +1,8 @@ # $NetBSD: OpenBSD.sys.mk,v 1.1 2002/11/17 09:18:00 cjep Exp $ # @(#)sys.mk 8.2 (Berkeley) 3/21/94 -OS= OpenBSD -unix?= We run ${OS}. +OS ?= OpenBSD +unix ?= We run ${OS}. .SUFFIXES: .out .a .ln .o .s .S .c ${CXX_SUFFIXES} .F .f .r .y .l .cl .p .h .SUFFIXES: .sh .m4 @@ -12,88 +12,88 @@ unix?= We run ${OS}. # need to make sure this is set MACHINE_ARCH.${MACHINE} ?= ${MACHINE} .if empty(MACHINE_ARCH) -MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} +MACHINE_ARCH ?= ${MACHINE_ARCH.${MACHINE}} .endif -AR?= ar -ARFLAGS?= rl -RANLIB?= ranlib +AR ?= ar +ARFLAGS ?= rl +RANLIB ?= ranlib -AS?= as -AFLAGS?= +AS ?= as +AFLAGS ?= .if ${MACHINE_ARCH} == "sparc64" AFLAGS+= -Wa,-Av9a .endif -COMPILE.s?= ${CC} ${AFLAGS} -c -LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp -LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.s ?= ${CC} ${AFLAGS} -c +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} -CC?= cc +CC ?= cc .if ${MACHINE_ARCH} == "alpha" || \ ${MACHINE_ARCH} == "i386" || \ ${MACHINE_ARCH} == "m68k" || \ ${MACHINE_ARCH} == "sparc" || \ ${MACHINE_ARCH} == "vax" -DBG?= -O2 +DBG ?= -O2 .else -DBG?= -O +DBG ?= -O .endif -CFLAGS?= ${DBG} -COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CFLAGS ?= ${DBG} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -CXX?= c++ -CXXFLAGS?= ${CFLAGS} -COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXX ?= c++ +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -OBJC?= ${CC} -OBJCFLAGS?= ${CFLAGS} -COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c -LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} +OBJC ?= ${CC} +OBJCFLAGS ?= ${CFLAGS} +COMPILE.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m ?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} -CPP?= cpp -CPPFLAGS?= +CPP ?= cpp +CPPFLAGS ?= -FC?= f77 -FFLAGS?= -O -RFLAGS?= -COMPILE.f?= ${FC} ${FFLAGS} -c -LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +FC ?= f77 +FFLAGS ?= -O +RFLAGS ?= +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -INSTALL?= install +INSTALL ?= install -LEX?= lex -LFLAGS?= -LEX.l?= ${LEX} ${LFLAGS} +LEX ?= lex +LFLAGS ?= +LEX.l ?= ${LEX} ${LFLAGS} -LD?= ld -LDFLAGS?= +LD ?= ld +LDFLAGS ?= -LINT?= lint -LINTFLAGS?= -chapbxzF +LINT ?= lint +LINTFLAGS ?= -chapbxzF -LORDER?= lorder +LORDER ?= lorder -NM?= nm +NM ?= nm -PC?= pc -PFLAGS?= -COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +PC ?= pc +PFLAGS ?= +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} -SIZE?= size +SIZE ?= size -TSORT?= tsort -q +TSORT ?= tsort -q -YACC?= yacc -YFLAGS?= -YACC.y?= ${YACC} ${YFLAGS} +YACC ?= yacc +YFLAGS ?= +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/mk/sys/SunOS.mk b/mk/sys/SunOS.mk index 71c985204fc6..e79cd3a7dbd4 100644 --- a/mk/sys/SunOS.mk +++ b/mk/sys/SunOS.mk @@ -1,19 +1,19 @@ -# $Id: SunOS.mk,v 1.9 2020/04/17 21:08:17 sjg Exp $ +# $Id: SunOS.mk,v 1.11 2020/06/29 14:34:42 sjg Exp $ .if ${.PARSEFILE} == "sys.mk" .include -OS?= SunOS.${HOST_OSMAJOR} -unix?= We run ${OS}. +OS ?= SunOS.${HOST_OSMAJOR} +unix ?= We run ${OS}. .endif .if ${HOST_OSMAJOR} > 4 -ROOT_GROUP= root +ROOT_GROUP ?= root -SHLIB_FULLVERSION = ${SHLIB_MAJOR} +SHLIB_FULLVERSION ?= ${SHLIB_MAJOR} # suppress the dependency -LIBCRT0= /dev/null +LIBCRT0 ?= /dev/null .ifndef CC # the PATH below may find an ancient gcc @@ -22,21 +22,21 @@ CC := ${gcc:L:${M_whence}} .endif # the stuff in /usr/xpg4/bin is usually more sane. -PATH=/usr/xpg4/bin:/usr/sbin:/usr/bin:/usr/ucb:/usr/sfw/bin:/opt/gnu/bin:/usr/ccs/bin:/usr/local/bin +PATH ?=/usr/xpg4/bin:/usr/sbin:/usr/bin:/usr/ucb:/usr/sfw/bin:/opt/gnu/bin:/usr/ccs/bin:/usr/local/bin .export PATH -DSHLIBEXT = .so -HOST_LIBDIRS = /usr/lib /lib /usr/sfw/lib +DSHLIBEXT ?= .so +HOST_LIBDIRS ?= /usr/lib /lib /usr/sfw/lib # no -X LD_X= LD_x= -RANLIB= : -CPP= /usr/ccs/lib/cpp +RANLIB ?= : +CPP ?= /usr/ccs/lib/cpp .else -ROOT_GROUP= wheel -RANLIB= ranlib -CPP= cpp +ROOT_GROUP ?= wheel +RANLIB ?= ranlib +CPP ?= cpp .endif # the rest is common @@ -45,71 +45,71 @@ CPP= cpp .LIBS: .a -AR= ar -ARFLAGS= rl +AR ?= ar +ARFLAGS ?= rl -AS= as -AS_STDIN= - +AS ?= as +AS_STDIN ?= - AFLAGS= -COMPILE.s= ${AS} ${AFLAGS} -LINK.s= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c -LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.s ?= ${AS} ${AFLAGS} +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} .if exists(/opt/gnu/bin/gcc) || exists(/usr/local/bin/gcc) CC ?= gcc -pipe -DBG= -O -g -STATIC= -static +DBG ?= -O -g +STATIC ?= -static .else CC ?= cc -DBG= -g -STATIC= -Bstatic +DBG ?= -g +STATIC ?= -Bstatic .endif -CFLAGS= ${DBG} -COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CFLAGS ?= ${DBG} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -CXX= g++ -CXXFLAGS= ${CFLAGS} -COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXX ?= g++ +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} .if defined(DESTDIR) CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include .endif -MK_DEP= mkdeps.sh -N -FC= f77 -FFLAGS= -O +MK_DEP ?= mkdeps.sh -N +FC ?= f77 +FFLAGS ?= -O RFLAGS= -COMPILE.f= ${FC} ${FFLAGS} -c -LINK.f= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -LEX= lex +LEX ?= lex LFLAGS= -LEX.l= ${LEX} ${LFLAGS} +LEX.l ?= ${LEX} ${LFLAGS} -LD= ld +LD ?= ld LDFLAGS= -LINT= lint -LINTFLAGS= -chapbx +LINT ?= lint +LINTFLAGS ?= -chapbx -PC= pc +PC ?= pc PFLAGS= -COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} .if exists(/usr/local/bin/bison) || exists(/opt/gnu/bin/bison) -YACC= bison -y +YACC ?= bison -y .else -YACC= yacc +YACC ?= yacc .endif -YFLAGS= -d -YACC.y= ${YACC} ${YFLAGS} +YFLAGS ?= -d +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/mk/sys/UnixWare.mk b/mk/sys/UnixWare.mk index 3b1e531515df..888f0d90c0b4 100644 --- a/mk/sys/UnixWare.mk +++ b/mk/sys/UnixWare.mk @@ -1,16 +1,16 @@ -# $Id: UnixWare.mk,v 1.4 2020/04/17 21:08:17 sjg Exp $ +# $Id: UnixWare.mk,v 1.6 2020/06/29 14:34:42 sjg Exp $ # based on "Id: SunOS.5.sys.mk,v 1.6 2003/09/30 16:42:23 sjg Exp " # $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ # @(#)sys.mk 5.11 (Berkeley) 3/13/91 -OS?= UnixWare -unix?= We run ${OS}. -ROOT_GROUP= root +OS ?= UnixWare +unix ?= We run ${OS}. +ROOT_GROUP ?= root # can't fine one anywhere, so just stop the dependency -LIBCRT0= /dev/null +LIBCRT0 ?= /dev/null -PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/ccs/lib:/usr/ucb:/usr/local/bin +PATH ?=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/ccs/lib:/usr/ucb:/usr/local/bin .SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4 @@ -19,119 +19,119 @@ PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/ccs/lib:/usr/ucb:/usr/local/bin # no -X LD_X= LD_x= -AR?= ar -ARFLAGS?= rl -RANLIB?= : +AR ?= ar +ARFLAGS ?= rl +RANLIB ?= : -AS?= as -AS_STDIN?= - -AFLAGS?= -COMPILE.s?= ${AS} ${AFLAGS} -LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} -COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +AS ?= as +AS_STDIN ?= - +AFLAGS ?= +COMPILE.s ?= ${AS} ${AFLAGS} +LINK.s ?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S ?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} # at least gcc 2.95 on UnixWare has no internal macro to identify the system .if exists(/usr/local/bin/gcc) -CC?= gcc -pipe -DUNIXWARE -DBG?= -O -g -STATIC?= -static +CC ?= gcc -pipe -DUNIXWARE +DBG ?= -O -g +STATIC ?= -static .else -CC?= cc -DBG?= -g -STATIC?= -Bstatic # XXX: don't know about UDK compilers +CC ?= cc +DBG ?= -g +STATIC ?= -Bstatic # XXX: don't know about UDK compilers .endif -CFLAGS?= ${DBG} -COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c -LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CFLAGS ?= ${DBG} +COMPILE.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c ?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} .if exists(/usr/local/bin/g++) -CXX?= g++ -DUNIXWARE +CXX ?= g++ -DUNIXWARE .else -CXX?= c++ # XXX: don't know about UDK compilers +CXX ?= c++ # XXX: don't know about UDK compilers .endif -CXXFLAGS?= ${CFLAGS} -COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXXFLAGS ?= ${CFLAGS} +COMPILE.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc ?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -CPP?= /usr/ccs/lib/cpp +CPP ?= /usr/ccs/lib/cpp .if defined(DESTDIR) CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include .endif -MK_DEP?= mkdeps.sh -N +MK_DEP ?= mkdeps.sh -N .if exists(/usr/local/bin/g77) -FC?= g77 +FC ?= g77 .else -FC?= f77 # XXX: don't know about UDK compilers +FC ?= f77 # XXX: don't know about UDK compilers .endif -FFLAGS?= -O -RFLAGS?= -COMPILE.f?= ${FC} ${FFLAGS} -c -LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} -COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c -LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} -COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c -LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +FFLAGS ?= -O +RFLAGS ?= +COMPILE.f ?= ${FC} ${FFLAGS} -c +LINK.f ?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F ?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r ?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r ?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} -INSTALL?= /usr/ucb/install # BSD install +INSTALL ?= /usr/ucb/install # BSD install -LEX?= lex -LFLAGS?= -LEX.l?= ${LEX} ${LFLAGS} +LEX ?= lex +LFLAGS ?= +LEX.l ?= ${LEX} ${LFLAGS} -LD?= ld -LDFLAGS?= +LD ?= ld +LDFLAGS ?= -LIBC?= ${DESTDIR}/usr/ccs/lib/libc.a -LIBCOMPAT?= -LIBCRYPT?= ${DESTDIR}/usr/lib/libcrypt.a -LIBCURSES?= ${DESTDIR}/usr/ccs/lib/libcurses.a -LIBDBM?= -LIBDES?= -LIBEDIT?= -LIBGCC?= -LIBKDB?= -LIBKRB?= -LIBKVM?= -LIBL?= ${DESTDIR}/usr/ccs/lib/libl.a -LIBM?= ${DESTDIR}/usr/ccs/lib/libm.a -LIBMP?= -LIBPC?= -LIBPCAP?= -LIBPLOT?= -LIBRESOLV?= -LIBRPCSVC?= ${DESTDIR}/usr/lib/librpcsvc.a -LIBSKEY?= ${DESTDIR}/usr/lib/libskey.a -LIBTERMCAP?= ${DESTDIR}/usr/ccs/lib/libtermcap.a -LIBUTIL?= -LIBWRAP?= -LIBY?= ${DESTDIR}/usr/ccs/lib/liby.a -LIBZ?= +LIBC ?= ${DESTDIR}/usr/ccs/lib/libc.a +LIBCOMPAT ?= +LIBCRYPT ?= ${DESTDIR}/usr/lib/libcrypt.a +LIBCURSES ?= ${DESTDIR}/usr/ccs/lib/libcurses.a +LIBDBM ?= +LIBDES ?= +LIBEDIT ?= +LIBGCC ?= +LIBKDB ?= +LIBKRB ?= +LIBKVM ?= +LIBL ?= ${DESTDIR}/usr/ccs/lib/libl.a +LIBM ?= ${DESTDIR}/usr/ccs/lib/libm.a +LIBMP ?= +LIBPC ?= +LIBPCAP ?= +LIBPLOT ?= +LIBRESOLV ?= +LIBRPCSVC ?= ${DESTDIR}/usr/lib/librpcsvc.a +LIBSKEY ?= ${DESTDIR}/usr/lib/libskey.a +LIBTERMCAP ?= ${DESTDIR}/usr/ccs/lib/libtermcap.a +LIBUTIL ?= +LIBWRAP ?= +LIBY ?= ${DESTDIR}/usr/ccs/lib/liby.a +LIBZ ?= -LINT?= lint -LINTFLAGS?= -pF +LINT ?= lint +LINTFLAGS ?= -pF -LORDER?= lorder +LORDER ?= lorder -NM?= nm +NM ?= nm -PC?= pc # XXX: UDK probably does not have pc -PFLAGS?= -COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c -LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +PC ?= pc # XXX: UDK probably does not have pc +PFLAGS ?= +COMPILE.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p ?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} -SIZE?= size +SIZE ?= size -TSORT?= tsort +TSORT ?= tsort .if exists(/usr/local/bin/bison) -YACC?= bison -y +YACC ?= bison -y .else -YACC?= yacc +YACC ?= yacc .endif -YFLAGS?= -d -YACC.y?= ${YACC} ${YFLAGS} +YFLAGS ?= -d +YACC.y ?= ${YACC} ${YFLAGS} # C .c: diff --git a/str.c b/str.c index d3d7994a0868..bc0108a84d2c 100644 --- a/str.c +++ b/str.c @@ -1,4 +1,4 @@ -/* $NetBSD: str.c,v 1.42 2020/05/06 02:30:10 christos Exp $ */ +/* $NetBSD: str.c,v 1.48 2020/06/15 14:46:28 rillig Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: str.c,v 1.42 2020/05/06 02:30:10 christos Exp $"; +static char rcsid[] = "$NetBSD: str.c,v 1.48 2020/06/15 14:46:28 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90"; #else -__RCSID("$NetBSD: str.c,v 1.42 2020/05/06 02:30:10 christos Exp $"); +__RCSID("$NetBSD: str.c,v 1.48 2020/06/15 14:46:28 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -119,7 +119,7 @@ str_concat(const char *s1, const char *s2, int flags) /* copy second string plus EOS into place */ memcpy(result + len1, s2, len2 + 1); - return(result); + return result; } /*- @@ -304,7 +304,7 @@ Str_FindSubstring(const char *string, const char *substring) * substring. */ - for (b = substring; *string != 0; string += 1) { + for (b = substring; *string != 0; string++) { if (*string != *b) continue; a = string; @@ -344,9 +344,9 @@ Str_Match(const char *string, const char *pattern) * pattern but not at the end of the string, we failed. */ if (*pattern == 0) - return(!*string); + return !*string; if (*string == 0 && *pattern != '*') - return(0); + return 0; /* * Check for a "*" as the next pattern character. It matches * any substring. We handle this by calling ourselves @@ -354,15 +354,17 @@ Str_Match(const char *string, const char *pattern) * match or we reach the end of the string. */ if (*pattern == '*') { - pattern += 1; + pattern++; + while (*pattern == '*') + pattern++; if (*pattern == 0) - return(1); + return 1; while (*string != 0) { if (Str_Match(string, pattern)) - return(1); + return 1; ++string; } - return(0); + return 0; } /* * Check for a "?" as the next pattern character. It matches @@ -388,14 +390,14 @@ Str_Match(const char *string, const char *pattern) if ((*pattern == ']') || (*pattern == 0)) { if (nomatch) break; - return(0); + return 0; } if (*pattern == *string) break; if (pattern[1] == '-') { c2 = pattern[2]; if (c2 == 0) - return(nomatch); + return nomatch; if ((*pattern <= *string) && (c2 >= *string)) break; @@ -415,20 +417,20 @@ Str_Match(const char *string, const char *pattern) goto thisCharOK; } /* - * If the next pattern character is '/', just strip off the - * '/' so we do exact matching on the character that follows. + * If the next pattern character is a backslash, just strip it + * off so we do exact matching on the character that follows. */ if (*pattern == '\\') { ++pattern; if (*pattern == 0) - return(0); + return 0; } /* * There's no special character. Just make sure that the * next characters of each string match. */ if (*pattern != *string) - return(0); + return 0; thisCharOK: ++pattern; ++string; } diff --git a/unit-tests/Makefile b/unit-tests/Makefile index 5cf0212ce596..5c429c9648b9 100644 --- a/unit-tests/Makefile +++ b/unit-tests/Makefile @@ -1,6 +1,6 @@ -# $Id: Makefile,v 1.54 2020/05/17 17:26:14 sjg Exp $ +# $Id: Makefile,v 1.55 2020/06/29 14:47:56 sjg Exp $ # -# $NetBSD: Makefile,v 1.58 2020/05/17 12:36:26 rillig Exp $ +# $NetBSD: Makefile,v 1.59 2020/06/28 09:42:40 rillig Exp $ # # Unit tests for make(1) # The main targets are: @@ -27,6 +27,7 @@ UNIT_TESTS:= ${.PARSEDIR} TESTNAMES= \ comment \ cond-late \ + cond-short \ cond1 \ cond2 \ dollar \ diff --git a/unit-tests/cond-short.exp b/unit-tests/cond-short.exp new file mode 100644 index 000000000000..d8e3861d0c61 --- /dev/null +++ b/unit-tests/cond-short.exp @@ -0,0 +1,7 @@ +expected and +expected and exists +expected and empty +expected or +expected or exists +expected or empty +exit status 0 diff --git a/unit-tests/cond-short.mk b/unit-tests/cond-short.mk new file mode 100644 index 000000000000..45bd45bfe3ba --- /dev/null +++ b/unit-tests/cond-short.mk @@ -0,0 +1,62 @@ +# $NetBSD: cond-short.mk,v 1.2 2020/06/28 11:06:26 rillig Exp $ +# +# Demonstrates that in conditions, the right-hand side of an && or || +# is only evaluated if it can actually influence the result. +# +# Between 2015-10-11 and 2020-06-28, the right-hand side of an && or || +# operator was always evaluated, which was wrong. +# + +# The && operator. + +.if 0 && ${echo "unexpected and" 1>&2 :L:sh} +.endif + +.if 1 && ${echo "expected and" 1>&2 :L:sh} +.endif + +.if 0 && exists(nonexistent${echo "unexpected and exists" 1>&2 :L:sh}) +.endif + +.if 1 && exists(nonexistent${echo "expected and exists" 1>&2 :L:sh}) +.endif + +.if 0 && empty(${echo "unexpected and empty" 1>&2 :L:sh}) +.endif + +.if 1 && empty(${echo "expected and empty" 1>&2 :L:sh}) +.endif + +# The || operator. + +.if 1 || ${echo "unexpected or" 1>&2 :L:sh} +.endif + +.if 0 || ${echo "expected or" 1>&2 :L:sh} +.endif + +.if 1 || exists(nonexistent${echo "unexpected or exists" 1>&2 :L:sh}) +.endif + +.if 0 || exists(nonexistent${echo "expected or exists" 1>&2 :L:sh}) +.endif + +.if 1 || empty(${echo "unexpected or empty" 1>&2 :L:sh}) +.endif + +.if 0 || empty(${echo "expected or empty" 1>&2 :L:sh}) +.endif + +# Unreachable nested conditions are skipped completely as well. + +.if 0 +. if ${echo "unexpected nested and" 1>&2 :L:sh} +. endif +.endif + +.if 1 +.elif ${echo "unexpected nested or" 1>&2 :L:sh} +.endif + +all: + @:;: diff --git a/unit-tests/modmatch.mk b/unit-tests/modmatch.mk index 45199287acdb..c631bbd3440f 100644 --- a/unit-tests/modmatch.mk +++ b/unit-tests/modmatch.mk @@ -15,7 +15,7 @@ res = no res = OK .endif -all: show-libs check-cclass +all: show-libs check-cclass slow show-libs: @for x in $X; do ${.MAKE} -f ${MAKEFILE} show LIB=$$x; done @@ -32,3 +32,8 @@ check-cclass: @echo Upper=${LIST:M[A-Z]*} @echo Lower=${LIST:M[^A-Z]*} @echo nose=${LIST:M[^s]*[ex]} + +# Before 2020-06-13, this expression took quite a long time in Str_Match, +# calling itself 601080390 times for 16 asterisks. +slow: .PHONY + @:;: ${:U****************:M****************b:Q} diff --git a/unit-tests/modorder.exp b/unit-tests/modorder.exp index 411742738d63..8e0aad2e2027 100644 --- a/unit-tests/modorder.exp +++ b/unit-tests/modorder.exp @@ -1,5 +1,6 @@ LIST = one two three four five six seven eight nine ten LIST:O = eight five four nine one seven six ten three two +LIST:Or = two three ten six seven one nine four five eight LIST:Ox = Ok LIST:O:Ox = Ok LISTX = Ok diff --git a/unit-tests/modorder.mk b/unit-tests/modorder.mk index 0f809391712f..89e64b43c57c 100644 --- a/unit-tests/modorder.mk +++ b/unit-tests/modorder.mk @@ -1,4 +1,4 @@ -# $NetBSD: modorder.mk,v 1.2 2020/01/07 22:42:14 rillig Exp $ +# $NetBSD: modorder.mk,v 1.3 2020/06/09 01:48:17 sjg Exp $ LIST= one two three four five six seven eight nine ten LISTX= ${LIST:Ox} @@ -10,6 +10,7 @@ TEST_RESULT= && echo Ok || echo Failed all: @echo "LIST = ${LIST}" @echo "LIST:O = ${LIST:O}" + @echo "LIST:Or = ${LIST:Or}" # Note that 1 in every 10! trials two independently generated # randomized orderings will be the same. The test framework doesn't # support checking probabilistic output, so we accept that each of the From 1a2b743f6b4022dada4eeaa96ac47a5c1a2429f5 Mon Sep 17 00:00:00 2001 From: "Simon J. Gerraty" Date: Wed, 8 Jul 2020 18:32:15 +0000 Subject: [PATCH 2/2] Import bmake-20200704 from ChangeLog: (most of this by rillig@) o lots of style and white-space cleanup o lots more unit tests for variable modifiers o simplified description of some functions o str.c: refactor Str_Match o var.c: debugging output for :@ constify VarModify parameter fix :hash modifier on 16-bit platforms remove unnecessary forward declarations refactor ApplyModifier_SysV to have less indentation simplify code for :E and :R clean up code for :H and :T refactor ApplyModifiers * var.c: we need stdint.h on some platforms to get uint32_t * unit-test/Makefile: we need to supress the specific error for RE substitution error in modmisc, since it varies accross different OS. --- ChangeLog | 39 + VERSION | 2 +- arch.c | 48 +- buf.c | 8 +- compat.c | 32 +- cond.c | 38 +- dir.c | 56 +- for.c | 14 +- hash.c | 25 +- hash.h | 3 +- job.c | 62 +- job.h | 12 +- lst.lib/lstAppend.c | 11 +- lst.lib/lstAtEnd.c | 8 +- lst.lib/lstAtFront.c | 8 +- lst.lib/lstClose.c | 7 +- lst.lib/lstConcat.c | 11 +- lst.lib/lstDatum.c | 9 +- lst.lib/lstDeQueue.c | 9 +- lst.lib/lstDupl.c | 8 +- lst.lib/lstEnQueue.c | 11 +- lst.lib/lstFind.c | 9 +- lst.lib/lstFindFrom.c | 9 +- lst.lib/lstFirst.c | 9 +- lst.lib/lstForEach.c | 7 +- lst.lib/lstForEachFrom.c | 7 +- lst.lib/lstInit.c | 8 +- lst.lib/lstInsert.c | 11 +- lst.lib/lstIsAtEnd.c | 11 +- lst.lib/lstIsEmpty.c | 9 +- lst.lib/lstLast.c | 9 +- lst.lib/lstNext.c | 9 +- lst.lib/lstOpen.c | 11 +- lst.lib/lstPrev.c | 9 +- lst.lib/lstRemove.c | 14 +- lst.lib/lstReplace.c | 11 +- lst.lib/lstSucc.c | 9 +- main.c | 110 +- make.c | 56 +- make.h | 6 +- make_malloc.c | 10 +- meta.c | 74 +- meta.h | 18 +- nonints.h | 17 +- parse.c | 52 +- str.c | 183 +- suff.c | 76 +- targ.c | 32 +- trace.c | 8 +- unit-tests/Makefile | 5 +- unit-tests/cond-short.exp | 3 + unit-tests/cond-short.mk | 41 +- unit-tests/modmisc.exp | 25 + unit-tests/modmisc.mk | 61 +- unit-tests/sysv.exp | 1 + unit-tests/sysv.mk | 9 +- unit-tests/varmisc.exp | 1 + unit-tests/varmisc.mk | 26 +- util.c | 18 +- var.c | 3587 +++++++++++++++++-------------------- 60 files changed, 2466 insertions(+), 2526 deletions(-) diff --git a/ChangeLog b/ChangeLog index ae57f180d82c..a09f3f84a8e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,42 @@ +2020-07-04 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20200704 + Merge with NetBSD make, pick up + (most of this by rillig@) + o lots of style and white-space cleanup + o lots more unit tests for variable modifiers + o simplified description of some functions + o str.c: refactor Str_Match + o var.c: debugging output for :@ + constify VarModify parameter + fix :hash modifier on 16-bit platforms + remove unnecessary forward declarations + refactor ApplyModifier_SysV to have less indentation + simplify code for :E and :R + clean up code for :H and :T + refactor ApplyModifiers + + * var.c: we need stdint.h on some platforms to get uint32_t + * unit-test/Makefile: we need to supress the specific error + for RE substitution error in modmisc, since it varies accross + different OS. + +2020-07-02 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20200702 + Merge with NetBSD make, pick up + o var.c: more improvements to avoiding unnecessary evaluation + use enums for flags + o remove flags arg to Var_Set which outside of var.c is always 0 + +2020-07-01 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20200701 + Merge with NetBSD make, pick up + o var.c: with change to cond.c; ensure that nested variables + within a variable name are expanded. + o unit-tests/varmisc.mk: test for nested varname + 2020-06-29 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200629 diff --git a/VERSION b/VERSION index 77ce0141acef..d10ccdc95114 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ # keep this compatible with sh and make -_MAKE_VERSION=20200629 +_MAKE_VERSION=20200704 diff --git a/arch.c b/arch.c index 84321f720665..9db7ce2bd14b 100644 --- a/arch.c +++ b/arch.c @@ -1,4 +1,4 @@ -/* $NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $ */ +/* $NetBSD: arch.c,v 1.73 2020/07/03 08:02:55 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $"; +static char rcsid[] = "$NetBSD: arch.c,v 1.73 2020/07/03 08:02:55 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $"); +__RCSID("$NetBSD: arch.c,v 1.73 2020/07/03 08:02:55 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -312,7 +312,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) free(freeIt); if (result == var_Error) { - return(FAILURE); + return FAILURE; } else { subLibName = TRUE; } @@ -354,7 +354,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) free(freeIt); if (result == var_Error) { - return(FAILURE); + return FAILURE; } else { doSubst = TRUE; } @@ -372,7 +372,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) */ if (*cp == '\0') { printf("No closing parenthesis in archive specification\n"); - return (FAILURE); + return FAILURE; } /* @@ -426,7 +426,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) if (gn == NULL) { free(buf); - return(FAILURE); + return FAILURE; } else { gn->type |= OP_ARCHV; (void)Lst_AtEnd(nodeLst, gn); @@ -437,7 +437,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) * ourselves. */ free(buf); - return(FAILURE); + return FAILURE; } /* * Free buffer and continue with our work. @@ -461,7 +461,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) gn = Targ_FindNode(nameBuf, TARG_CREATE); if (gn == NULL) { free(nameBuf); - return (FAILURE); + return FAILURE; } else { /* * We've found the node, but have to make sure the rest of @@ -483,7 +483,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) gn = Targ_FindNode(nameBuf, TARG_CREATE); free(nameBuf); if (gn == NULL) { - return (FAILURE); + return FAILURE; } else { /* * We've found the node, but have to make sure the rest of the @@ -520,7 +520,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) } while (*cp != '\0' && isspace ((unsigned char)*cp)); *linePtr = cp; - return (SUCCESS); + return SUCCESS; } /*- @@ -544,7 +544,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) static int ArchFindArchive(const void *ar, const void *archName) { - return (strcmp(archName, ((const Arch *)ar)->name)); + return strcmp(archName, ((const Arch *)ar)->name); } /*- @@ -602,7 +602,7 @@ ArchStatMember(char *archive, char *member, Boolean hash) he = Hash_FindEntry(&ar->members, member); if (he != NULL) { - return ((struct ar_hdr *)Hash_GetValue(he)); + return (struct ar_hdr *)Hash_GetValue(he); } else { /* Try truncated name */ char copy[AR_MAX_NAME_LEN+1]; @@ -614,7 +614,7 @@ ArchStatMember(char *archive, char *member, Boolean hash) copy[AR_MAX_NAME_LEN] = '\0'; } if ((he = Hash_FindEntry(&ar->members, copy)) != NULL) - return ((struct ar_hdr *)Hash_GetValue(he)); + return (struct ar_hdr *)Hash_GetValue(he); return NULL; } } @@ -635,7 +635,7 @@ ArchStatMember(char *archive, char *member, Boolean hash) return NULL; } else { fclose(arch); - return (&sarh); + return &sarh; } } @@ -753,7 +753,7 @@ ArchStatMember(char *archive, char *member, Boolean hash) he = Hash_FindEntry(&ar->members, member); if (he != NULL) { - return ((struct ar_hdr *)Hash_GetValue(he)); + return (struct ar_hdr *)Hash_GetValue(he); } else { return NULL; } @@ -962,7 +962,7 @@ ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr, fclose(arch); return NULL; } - return (arch); + return arch; } } else #ifdef AR_EFMT1 @@ -996,7 +996,7 @@ ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr, fclose(arch); return NULL; } - return (arch); + return arch; } if (fseek(arch, -elen, SEEK_CUR) != 0) { fclose(arch); @@ -1152,7 +1152,7 @@ Arch_MTime(GNode *gn) } gn->mtime = modTime; - return (modTime); + return modTime; } /*- @@ -1179,7 +1179,7 @@ Arch_MemMTime(GNode *gn) if (Lst_Open(gn->parents) != SUCCESS) { gn->mtime = 0; - return (0); + return 0; } while ((ln = Lst_Next(gn->parents)) != NULL) { pgn = (GNode *)Lst_Datum(ln); @@ -1211,7 +1211,7 @@ Arch_MemMTime(GNode *gn) Lst_Close(gn->parents); - return (gn->mtime); + return gn->mtime; } /*- @@ -1252,9 +1252,9 @@ Arch_FindLib(GNode *gn, Lst path) free(libName); #ifdef LIBRARIES - Var_Set(TARGET, gn->name, gn, 0); + Var_Set(TARGET, gn->name, gn); #else - Var_Set(TARGET, gn->path == NULL ? gn->name : gn->path, gn, 0); + Var_Set(TARGET, gn->path == NULL ? gn->name : gn->path, gn); #endif /* LIBRARIES */ } @@ -1337,7 +1337,7 @@ Arch_LibOODate(GNode *gn) oodate = FALSE; #endif } - return (oodate); + return oodate; } /*- diff --git a/buf.c b/buf.c index ac95c16c1586..360b8cedde13 100644 --- a/buf.c +++ b/buf.c @@ -1,4 +1,4 @@ -/* $NetBSD: buf.c,v 1.25 2012/04/24 20:26:58 sjg Exp $ */ +/* $NetBSD: buf.c,v 1.26 2020/07/03 08:02:55 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: buf.c,v 1.25 2012/04/24 20:26:58 sjg Exp $"; +static char rcsid[] = "$NetBSD: buf.c,v 1.26 2020/07/03 08:02:55 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)buf.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: buf.c,v 1.25 2012/04/24 20:26:58 sjg Exp $"); +__RCSID("$NetBSD: buf.c,v 1.26 2020/07/03 08:02:55 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -160,7 +160,7 @@ Buf_GetAll(Buffer *bp, int *numBytesPtr) if (numBytesPtr != NULL) *numBytesPtr = bp->count; - return (bp->buffer); + return bp->buffer; } /*- diff --git a/compat.c b/compat.c index 2e9e143b787b..cd88884736f1 100644 --- a/compat.c +++ b/compat.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat.c,v 1.110 2020/01/19 19:42:32 riastradh Exp $ */ +/* $NetBSD: compat.c,v 1.113 2020/07/03 08:13:23 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: compat.c,v 1.110 2020/01/19 19:42:32 riastradh Exp $"; +static char rcsid[] = "$NetBSD: compat.c,v 1.113 2020/07/03 08:13:23 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: compat.c,v 1.110 2020/01/19 19:42:32 riastradh Exp $"); +__RCSID("$NetBSD: compat.c,v 1.113 2020/07/03 08:13:23 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -236,7 +236,7 @@ CompatRunCommand(void *cmdp, void *gnp) silent = gn->type & OP_SILENT; errCheck = !(gn->type & OP_IGNORE); doIt = FALSE; - + cmdNode = Lst_Member(gn->commands, cmd); cmdStart = Var_Subst(NULL, cmd, gn, VARF_WANTRES); @@ -249,18 +249,18 @@ CompatRunCommand(void *cmdp, void *gnp) if (*cmdStart == '\0') { free(cmdStart); - return(0); + return 0; } cmd = cmdStart; Lst_Replace(cmdNode, cmdStart); if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) { (void)Lst_AtEnd(ENDNode->commands, cmdStart); - return(0); + return 0; } if (strcmp(cmdStart, "...") == 0) { gn->type |= OP_SAVE_CMDS; - return(0); + return 0; } while ((*cmd == '@') || (*cmd == '-') || (*cmd == '+')) { @@ -287,7 +287,7 @@ CompatRunCommand(void *cmdp, void *gnp) * If we did not end up with a command, just skip it. */ if (!*cmd) - return (0); + return 0; #if !defined(MAKE_NATIVE) /* @@ -307,7 +307,7 @@ CompatRunCommand(void *cmdp, void *gnp) * go to the shell. Therefore treat '=' and ':' like shell * meta characters as documented in make(1). */ - + useShell = needshell(cmd, FALSE); #endif @@ -325,7 +325,7 @@ CompatRunCommand(void *cmdp, void *gnp) * we go... */ if (!doIt && NoExecute(gn)) { - return (0); + return 0; } if (DEBUG(JOB)) fprintf(debug_file, "Execute: '%s'\n", cmd); @@ -377,7 +377,7 @@ CompatRunCommand(void *cmdp, void *gnp) meta_compat_start(); } #endif - + /* * Fork and execute the single command. If the fork fails, we abort. */ @@ -499,8 +499,8 @@ CompatRunCommand(void *cmdp, void *gnp) bmake_signal(compatSigno, SIG_DFL); kill(myPid, compatSigno); } - - return (status); + + return status; } /*- @@ -550,7 +550,7 @@ Compat_Make(void *gnp, void *pgnp) if (Lst_Member(gn->iParents, pgn) != NULL) { char *p1; - Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0); + Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn); free(p1); } @@ -654,7 +654,7 @@ Compat_Make(void *gnp, void *pgnp) } else { if (Lst_Member(gn->iParents, pgn) != NULL) { char *p1; - Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0); + Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn); free(p1); } switch(gn->made) { @@ -681,7 +681,7 @@ Compat_Make(void *gnp, void *pgnp) cohorts: Lst_ForEach(gn->cohorts, Compat_Make, pgnp); - return (0); + return 0; } /*- diff --git a/cond.c b/cond.c index 27034189bfd7..92501e162e68 100644 --- a/cond.c +++ b/cond.c @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.76 2020/06/28 11:06:26 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.78 2020/07/03 08:13:23 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: cond.c,v 1.76 2020/06/28 11:06:26 rillig Exp $"; +static char rcsid[] = "$NetBSD: cond.c,v 1.78 2020/07/03 08:13:23 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: cond.c,v 1.76 2020/06/28 11:06:26 rillig Exp $"); +__RCSID("$NetBSD: cond.c,v 1.78 2020/07/03 08:13:23 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -186,7 +186,7 @@ static unsigned int cond_min_depth = 0; /* depth at makefile open */ * Indicate when we should be strict about lhs of comparisons. * TRUE when Cond_EvalExpression is called from Cond_Eval (.if etc) * FALSE when Cond_EvalExpression is called from var.c:ApplyModifiers - * since lhs is already expanded and we cannot tell if + * since lhs is already expanded and we cannot tell if * it was a variable reference or not. */ static Boolean lhsStrict; @@ -256,7 +256,7 @@ CondGetArg(Boolean doEval, char **linePtr, char **argPtr, const char *func) * the word 'make' or 'defined' at the beginning of a symbol... */ *argPtr = NULL; - return (0); + return 0; } while (*cp == ' ' || *cp == '\t') { @@ -314,11 +314,11 @@ CondGetArg(Boolean doEval, char **linePtr, char **argPtr, const char *func) if (func != NULL && *cp++ != ')') { Parse_Error(PARSE_WARNING, "Missing closing parenthesis for %s()", func); - return (0); + return 0; } *linePtr = cp; - return (argLen); + return argLen; } /*- @@ -347,7 +347,7 @@ CondDoDefined(int argLen MAKE_ATTR_UNUSED, const char *arg) } free(p1); - return (result); + return result; } /*- @@ -367,7 +367,7 @@ CondDoDefined(int argLen MAKE_ATTR_UNUSED, const char *arg) static int CondStrMatch(const void *string, const void *pattern) { - return(!Str_Match(string, pattern)); + return !Str_Match(string, pattern); } /*- @@ -412,14 +412,14 @@ CondDoExists(int argLen MAKE_ATTR_UNUSED, const char *arg) if (DEBUG(COND)) { fprintf(debug_file, "exists(%s) result is \"%s\"\n", arg, path ? path : ""); - } + } if (path != NULL) { result = TRUE; free(path); } else { result = FALSE; } - return (result); + return result; } /*- @@ -441,7 +441,7 @@ CondDoTarget(int argLen MAKE_ATTR_UNUSED, const char *arg) GNode *gn; gn = Targ_FindNode(arg, TARG_NOCREATE); - return (gn != NULL) && !OP_NOP(gn->type); + return gn != NULL && !OP_NOP(gn->type); } /*- @@ -465,7 +465,7 @@ CondDoCommands(int argLen MAKE_ATTR_UNUSED, const char *arg) GNode *gn; gn = Targ_FindNode(arg, TARG_NOCREATE); - return (gn != NULL) && !OP_NOP(gn->type) && !Lst_IsEmpty(gn->commands); + return gn != NULL && !OP_NOP(gn->type) && !Lst_IsEmpty(gn->commands); } /*- @@ -666,7 +666,7 @@ compare_expression(Boolean doEval) rhs = NULL; lhsFree = rhsFree = FALSE; lhsQuoted = rhsQuoted = FALSE; - + /* * Parse the variable spec and skip over it, saving its * value in lhs. @@ -709,7 +709,7 @@ compare_expression(Boolean doEval) goto done; } /* For .ifxxx compare against zero */ - if (CondCvtArg(lhs, &left)) { + if (CondCvtArg(lhs, &left)) { t = left != 0.0; goto done; } @@ -762,7 +762,7 @@ compare_expression(Boolean doEval) * rhs is either a float or an integer. Convert both the * lhs and the rhs to a double and compare the two. */ - + if (!CondCvtArg(lhs, &left) || !CondCvtArg(rhs, &right)) goto do_string_compare; @@ -1038,7 +1038,7 @@ CondT(Boolean doEval) t = TOK_TRUE; } } - return (t); + return t; } /*- @@ -1084,7 +1084,7 @@ CondF(Boolean doEval) CondPushBack(o); } } - return (l); + return l; } /*- @@ -1131,7 +1131,7 @@ CondE(Boolean doEval) CondPushBack(o); } } - return (l); + return l; } /*- diff --git a/dir.c b/dir.c index 31c19d247266..5c5e7e5c14f2 100644 --- a/dir.c +++ b/dir.c @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.74 2020/06/05 18:03:59 sjg Exp $ */ +/* $NetBSD: dir.c,v 1.76 2020/07/03 08:13:23 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: dir.c,v 1.74 2020/06/05 18:03:59 sjg Exp $"; +static char rcsid[] = "$NetBSD: dir.c,v 1.76 2020/07/03 08:13:23 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: dir.c,v 1.74 2020/06/05 18:03:59 sjg Exp $"); +__RCSID("$NetBSD: dir.c,v 1.76 2020/07/03 08:13:23 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -112,7 +112,7 @@ __RCSID("$NetBSD: dir.c,v 1.74 2020/06/05 18:03:59 sjg Exp $"); * Dir_FindHereOrAbove Search for a path in the current directory and * then all the directories above it in turn until * the path is found or we reach the root ("/"). - * + * * Dir_MTime Return the modification time of a node. The file * is searched for along the default search path. * The path and mtime fields of the node are filled @@ -377,7 +377,7 @@ void Dir_InitCur(const char *cdname) { Path *p; - + if (cdname != NULL) { /* * Our build directory is not the same as our source directory. @@ -480,7 +480,7 @@ Dir_SetPATH(void) Boolean hasLastDot = FALSE; /* true we should search dot last */ Var_Delete(".PATH", VAR_GLOBAL); - + if (Lst_Open(dirSearchPath) == SUCCESS) { if ((ln = Lst_First(dirSearchPath)) != NULL) { p = (Path *)Lst_Datum(ln); @@ -537,7 +537,7 @@ Dir_SetPATH(void) static int DirFindName(const void *p, const void *dname) { - return (strcmp(((const Path *)p)->name, dname)); + return strcmp(((const Path *)p)->name, dname); } /*- @@ -545,7 +545,7 @@ DirFindName(const void *p, const void *dname) * Dir_HasWildcards -- * see if the given name has any wildcard characters in it * be careful not to expand unmatching brackets or braces. - * XXX: This code is not 100% correct. ([^]] fails etc.) + * XXX: This code is not 100% correct. ([^]] fails etc.) * I really don't think that make(1) should be expanding * patterns, because then you have to set a mechanism for * escaping the expansion! @@ -644,7 +644,7 @@ DirMatchFiles(const char *pattern, Path *p, Lst expansions) STR_ADDSLASH))); } } - return (0); + return 0; } /*- @@ -947,7 +947,7 @@ Dir_Expand(const char *word, Lst path, Lst expansions) *----------------------------------------------------------------------- */ static char * -DirLookup(Path *p, const char *name MAKE_ATTR_UNUSED, const char *cp, +DirLookup(Path *p, const char *name MAKE_ATTR_UNUSED, const char *cp, Boolean hasSlash MAKE_ATTR_UNUSED) { char *file; /* the current filename to check */ @@ -1004,7 +1004,7 @@ DirLookupSubdir(Path *p, const char *name) if (cached_stat(file, &stb) == 0) { nearmisses += 1; - return (file); + return file; } free(file); return NULL; @@ -1061,7 +1061,7 @@ DirLookupAbs(Path *p, const char *name, const char *cp) if (DEBUG(DIR)) { fprintf(debug_file, " returning %s\n", name); } - return (bmake_strdup(name)); + return bmake_strdup(name); } /*- @@ -1087,7 +1087,7 @@ DirFindDot(Boolean hasSlash MAKE_ATTR_UNUSED, const char *name, const char *cp) } hits += 1; dot->hits += 1; - return (bmake_strdup(name)); + return bmake_strdup(name); } if (cur && Hash_FindEntry(&cur->files, cp) != NULL) { @@ -1185,7 +1185,7 @@ Dir_FindFile(const char *name, Lst path) * is found, we concatenate the directory name and the final * component and return the resulting string. If we don't find any * such thing, we go on to phase two... - * + * * No matter what, we always look for the file in the current * directory before anywhere else (unless we found the magic * DOTLAST path, in which case we search it last) and we *do not* @@ -1384,7 +1384,7 @@ Dir_FindFile(const char *name, Lst path) } if (Hash_FindEntry(&p->files, cp) != NULL) { - return (bmake_strdup(name)); + return bmake_strdup(name); } else { return NULL; } @@ -1395,7 +1395,7 @@ Dir_FindFile(const char *name, Lst path) bigmisses += 1; if (cached_stat(name, &stb) == 0) { - return (bmake_strdup(name)); + return bmake_strdup(name); } if (DEBUG(DIR)) { @@ -1409,14 +1409,14 @@ Dir_FindFile(const char *name, Lst path) /*- *----------------------------------------------------------------------- * Dir_FindHereOrAbove -- - * search for a path starting at a given directory and then working + * search for a path starting at a given directory and then working * our way up towards the root. * * Input: * here starting directory * search_path the path we are looking for * result the result of a successful search is placed here - * rlen the length of the result buffer + * rlen the length of the result buffer * (typically MAXPATHLEN + 1) * * Results: @@ -1426,7 +1426,7 @@ Dir_FindFile(const char *name, Lst path) * Side Effects: *----------------------------------------------------------------------- */ -int +int Dir_FindHereOrAbove(char *here, char *search_path, char *result, int rlen) { struct stat st; @@ -1451,7 +1451,7 @@ Dir_FindHereOrAbove(char *here, char *search_path, char *result, int rlen) { try_end = try + strlen(try); while (try_end > try && *try_end != '/') try_end--; - if (try_end > try) + if (try_end > try) *try_end = 0; /* chop! */ } @@ -1459,10 +1459,10 @@ Dir_FindHereOrAbove(char *here, char *search_path, char *result, int rlen) { * done! */ snprintf(result, rlen, "%s", try); - return(1); + return 1; } - /* + /* * nope, we didn't find it. if we used up dirbase we've * reached the root and failed. */ @@ -1479,9 +1479,9 @@ Dir_FindHereOrAbove(char *here, char *search_path, char *result, int rlen) { } /* while (1) */ /* - * we failed... + * we failed... */ - return(0); + return 0; } /*- @@ -1529,7 +1529,7 @@ Dir_MTime(GNode *gn, Boolean recheck) * see if we can find it via the current .PATH */ cp++; - + fullName = Dir_FindFile(cp, Suff_FindPath(gn)); if (fullName) { /* @@ -1572,7 +1572,7 @@ Dir_MTime(GNode *gn, Boolean recheck) } gn->mtime = stb.st_mtime; - return (gn->mtime); + return gn->mtime; } /*- @@ -1677,7 +1677,7 @@ Dir_CopyDir(void *p) { ((Path *)p)->refCount += 1; - return (p); + return p; } /*- @@ -1722,7 +1722,7 @@ Dir_MakeFlags(const char *flag, Lst path) Lst_Close(path); } - return (str); + return str; } /*- diff --git a/for.c b/for.c index fffedda7e688..f20a0f58b06b 100644 --- a/for.c +++ b/for.c @@ -1,4 +1,4 @@ -/* $NetBSD: for.c,v 1.53 2017/04/16 21:04:44 riastradh Exp $ */ +/* $NetBSD: for.c,v 1.54 2020/07/03 08:13:23 rillig Exp $ */ /* * Copyright (c) 1992, The Regents of the University of California. @@ -30,14 +30,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: for.c,v 1.53 2017/04/16 21:04:44 riastradh Exp $"; +static char rcsid[] = "$NetBSD: for.c,v 1.54 2020/07/03 08:13:23 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: for.c,v 1.53 2017/04/16 21:04:44 riastradh Exp $"); +__RCSID("$NetBSD: for.c,v 1.54 2020/07/03 08:13:23 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -224,7 +224,7 @@ For_Eval(char *line) words = brk_string(sub, &nwords, FALSE, &word_buf); free(sub); - + if (words != NULL) { for (n = 0; n < nwords; n++) { ptr = words[n]; @@ -480,9 +480,9 @@ For_Iterate(void *v_arg, size_t *ret_len) void For_Run(int lineno) -{ +{ For *arg; - + arg = accumFor; accumFor = NULL; @@ -491,6 +491,6 @@ For_Run(int lineno) For_Free(arg); return; } - + Parse_SetInput(NULL, lineno, -1, For_Iterate, arg); } diff --git a/hash.c b/hash.c index ed23644433be..f2bbebc9ece7 100644 --- a/hash.c +++ b/hash.c @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.20 2013/11/14 00:27:05 sjg Exp $ */ +/* $NetBSD: hash.c,v 1.22 2020/07/03 17:03:09 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: hash.c,v 1.20 2013/11/14 00:27:05 sjg Exp $"; +static char rcsid[] = "$NetBSD: hash.c,v 1.22 2020/07/03 17:03:09 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)hash.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: hash.c,v 1.20 2013/11/14 00:27:05 sjg Exp $"); +__RCSID("$NetBSD: hash.c,v 1.22 2020/07/03 17:03:09 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -229,7 +229,7 @@ Hash_FindEntry(Hash_Table *t, const char *key) p = key; for (e = t->bucketPtr[h & t->mask]; e != NULL; e = e->next) if (e->namehash == h && strcmp(e->name, p) == 0) - return (e); + return e; return NULL; } @@ -279,7 +279,7 @@ Hash_CreateEntry(Hash_Table *t, const char *key, Boolean *newPtr) if (e->namehash == h && strcmp(e->name, p) == 0) { if (newPtr != NULL) *newPtr = FALSE; - return (e); + return e; } } @@ -301,7 +301,7 @@ Hash_CreateEntry(Hash_Table *t, const char *key, Boolean *newPtr) if (newPtr != NULL) *newPtr = TRUE; - return (e); + return e; } /* @@ -418,7 +418,7 @@ Hash_EnumNext(Hash_Search *searchPtr) e = t->bucketPtr[searchPtr->nextIndex++]; } searchPtr->hashEntryPtr = e; - return (e); + return e; } /* @@ -464,3 +464,14 @@ RebuildTable(Hash_Table *t) } free(oldhp); } + +void Hash_ForEach(Hash_Table *t, void (*action)(void *, void *), void *data) +{ + Hash_Search search; + Hash_Entry *e; + + for (e = Hash_EnumFirst(t, &search); + e != NULL; + e = Hash_EnumNext(&search)) + action(Hash_GetValue(e), data); +} diff --git a/hash.h b/hash.h index 8ab6ffd4f556..2e4ea6a43560 100644 --- a/hash.h +++ b/hash.h @@ -1,4 +1,4 @@ -/* $NetBSD: hash.h,v 1.12 2017/05/31 21:07:03 maya Exp $ */ +/* $NetBSD: hash.h,v 1.13 2020/07/03 17:03:09 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -145,5 +145,6 @@ Hash_Entry *Hash_CreateEntry(Hash_Table *, const char *, Boolean *); void Hash_DeleteEntry(Hash_Table *, Hash_Entry *); Hash_Entry *Hash_EnumFirst(Hash_Table *, Hash_Search *); Hash_Entry *Hash_EnumNext(Hash_Search *); +void Hash_ForEach(Hash_Table *, void (*)(void *, void *), void *); #endif /* _HASH_H */ diff --git a/job.c b/job.c index feaa3a63029d..b6a0ab334a6f 100644 --- a/job.c +++ b/job.c @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.198 2020/06/19 21:17:48 sjg Exp $ */ +/* $NetBSD: job.c,v 1.201 2020/07/03 08:13:23 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: job.c,v 1.198 2020/06/19 21:17:48 sjg Exp $"; +static char rcsid[] = "$NetBSD: job.c,v 1.201 2020/07/03 08:13:23 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: job.c,v 1.198 2020/06/19 21:17:48 sjg Exp $"); +__RCSID("$NetBSD: job.c,v 1.201 2020/07/03 08:13:23 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -274,7 +274,7 @@ static Shell shells[] = { "", }, /* - * KSH description. + * KSH description. */ { "ksh", @@ -447,7 +447,7 @@ JobCreatePipe(Job *job, int minfd) job->jobPipe[i] = fd; } } - + /* Set close-on-exec flag for both */ if (fcntl(job->jobPipe[0], F_SETFD, FD_CLOEXEC) == -1) Punt("Cannot set close-on-exec: %s", strerror(errno)); @@ -457,7 +457,7 @@ JobCreatePipe(Job *job, int minfd) /* * We mark the input side of the pipe non-blocking; we poll(2) the * pipe when we're waiting for a job token, but we might lose the - * race for the token when a new one becomes available, so the read + * race for the token when a new one becomes available, so the read * from the pipe should not block. */ flags = fcntl(job->jobPipe[0], F_GETFL, 0); @@ -780,7 +780,7 @@ JobPrintCommand(void *cmdp, void *jobp) /* * If the shell doesn't have error control the alternate echo'ing will - * be done (to avoid showing additional error checking code) + * be done (to avoid showing additional error checking code) * and this will need the characters '$ ` \ "' escaped */ @@ -788,10 +788,10 @@ JobPrintCommand(void *cmdp, void *jobp) /* Worst that could happen is every char needs escaping. */ escCmd = bmake_malloc((strlen(cmd) * 2) + 1); for (i = 0, j= 0; cmd[i] != '\0'; i++, j++) { - if (cmd[i] == '$' || cmd[i] == '`' || cmd[i] == '\\' || + if (cmd[i] == '$' || cmd[i] == '`' || cmd[i] == '\\' || cmd[i] == '"') escCmd[j++] = '\\'; - escCmd[j] = cmd[i]; + escCmd[j] = cmd[i]; } escCmd[j] = 0; } @@ -864,13 +864,13 @@ JobPrintCommand(void *cmdp, void *jobp) } } else { - /* + /* * If errors are being checked and the shell doesn't have error control * but does supply an errOut template, then setup commands to run * through it. */ - if (!commandShell->hasErrCtl && commandShell->errOut && + if (!commandShell->hasErrCtl && commandShell->errOut && (*commandShell->errOut != '\0')) { if (!(job->flags & JOB_SILENT) && !shutUp) { if (commandShell->hasEchoCtl) { @@ -894,7 +894,7 @@ JobPrintCommand(void *cmdp, void *jobp) DBPRINTF("set -%s\n", "x"); job->flags |= JOB_TRACED; } - + DBPRINTF(cmdTemplate, cmd); free(cmdStart); free(escCmd); @@ -935,7 +935,7 @@ JobSaveCommand(void *cmd, void *gn) { cmd = Var_Subst(NULL, (char *)cmd, (GNode *)gn, VARF_WANTRES); (void)Lst_AtEnd(postCommands->commands, cmd); - return(0); + return 0; } @@ -1102,7 +1102,7 @@ JobFinish (Job *job, WAIT_T status) } } #endif - + return_job_token = FALSE; Trace_Log(JOBEND, job); @@ -1274,7 +1274,7 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...)) * .DEFAULT itself. */ Make_HandleUse(DEFAULT, gn); - Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), gn, 0); + Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), gn); free(p1); } else if (Dir_MTime(gn, 0) == 0 && (gn->type & OP_SPECIAL) == 0) { /* @@ -1419,7 +1419,7 @@ JobExec(Job *job, char **argv) _exit(1); } } - + /* * Set up the child's output to be routed through the pipe * we've created for it. @@ -1768,7 +1768,7 @@ JobStart(GNode *gn, int flags) JobCreatePipe(job, 3); JobExec(job, argv); - return(JOB_RUNNING); + return JOB_RUNNING; } static char * @@ -2260,11 +2260,11 @@ Shell_GetNewline(void) void Job_SetPrefix(void) { - + if (targPrefix) { free(targPrefix); } else if (!Var_Exists(MAKE_JOB_PREFIX, VAR_GLOBAL)) { - Var_Set(MAKE_JOB_PREFIX, "---", VAR_GLOBAL, 0); + Var_Set(MAKE_JOB_PREFIX, "---", VAR_GLOBAL); } targPrefix = Var_Subst(NULL, "${" MAKE_JOB_PREFIX "}", @@ -2410,7 +2410,7 @@ JobMatchShell(const char *name) for (sh = shells; sh->name != NULL; sh++) { if (strcmp(name, sh->name) == 0) - return (sh); + return sh; } return NULL; } @@ -2526,7 +2526,7 @@ Job_ParseShell(char *line) Parse_Error(PARSE_FATAL, "Unknown keyword \"%s\"", *argv); free(words); - return(FAILURE); + return FAILURE; } fullSpec = TRUE; } @@ -2542,13 +2542,13 @@ Job_ParseShell(char *line) if (newShell.name == NULL) { Parse_Error(PARSE_FATAL, "Neither path nor name specified"); free(words); - return(FAILURE); + return FAILURE; } else { if ((sh = JobMatchShell(newShell.name)) == NULL) { Parse_Error(PARSE_WARNING, "%s: No matching shell", newShell.name); free(words); - return(FAILURE); + return FAILURE; } commandShell = sh; shellName = newShell.name; @@ -2584,7 +2584,7 @@ Job_ParseShell(char *line) Parse_Error(PARSE_WARNING, "%s: No matching shell", shellName); free(words); - return(FAILURE); + return FAILURE; } commandShell = sh; } else { @@ -2701,7 +2701,7 @@ Job_Finish(void) JobRun(postCommands); } } - return(errors); + return errors; } /*- @@ -2940,7 +2940,7 @@ Job_ServerStart(int max_tokens, int jp_0, int jp_1) { int i; char jobarg[64]; - + if (jp_0 >= 0 && jp_1 >= 0) { /* Pipe passed in from parent */ tokenWaitJob.inPipe = jp_0; @@ -2956,12 +2956,12 @@ Job_ServerStart(int max_tokens, int jp_0, int jp_1) tokenWaitJob.inPipe, tokenWaitJob.outPipe); Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL); - Var_Append(MAKEFLAGS, jobarg, VAR_GLOBAL); + Var_Append(MAKEFLAGS, jobarg, VAR_GLOBAL); /* * Preload the job pipe with one token per job, save the one * "extra" token for the primary job. - * + * * XXX should clip maxJobs against PIPE_BUF -- if max_tokens is * larger than the write buffer size of the pipe, we will * deadlock here. @@ -3078,7 +3078,7 @@ Job_RunTarget(const char *target, const char *fname) { return FALSE; if (fname) - Var_Set(ALLSRC, fname, gn, 0); + Var_Set(ALLSRC, fname, gn); JobRun(gn); if (gn->made == ERROR) { @@ -3113,9 +3113,9 @@ emul_poll(struct pollfd *fd, int nfd, int timeout) if (fd[i].fd > maxfd) maxfd = fd[i].fd; } - + if (maxfd >= FD_SETSIZE) { - Punt("Ran out of fd_set slots; " + Punt("Ran out of fd_set slots; " "recompile with a larger FD_SETSIZE."); } diff --git a/job.h b/job.h index 91e2c8782723..603c09e861f1 100644 --- a/job.h +++ b/job.h @@ -1,4 +1,4 @@ -/* $NetBSD: job.h,v 1.42 2013/07/05 22:14:56 sjg Exp $ */ +/* $NetBSD: job.h,v 1.43 2020/07/03 08:13:23 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -106,7 +106,7 @@ emul_poll(struct pollfd *fd, int nfd, int timeout); /* * The POLL_MSEC constant determines the maximum number of milliseconds spent - * in poll before coming out to see if a child has finished. + * in poll before coming out to see if a child has finished. */ #define POLL_MSEC 5000 @@ -203,11 +203,11 @@ typedef struct Job { * a case, errCheck becomes a printf template for echoing the command, * should echoing be on and ignErr becomes another printf template for * executing the command while ignoring the return status. Finally errOut - * is a printf template for running the command and causing the shell to - * exit on error. If any of these strings are empty when hasErrCtl is FALSE, - * the command will be executed anyway as is and if it causes an error, so be + * is a printf template for running the command and causing the shell to + * exit on error. If any of these strings are empty when hasErrCtl is FALSE, + * the command will be executed anyway as is and if it causes an error, so be * it. Any templates setup to echo the command will escape any '$ ` \ "'i - * characters in the command string to avoid common problems with + * characters in the command string to avoid common problems with * echo "%s\n" as a template. */ typedef struct Shell { diff --git a/lst.lib/lstAppend.c b/lst.lib/lstAppend.c index 4dafe831450e..97e60d959d7d 100644 --- a/lst.lib/lstAppend.c +++ b/lst.lib/lstAppend.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstAppend.c,v 1.14 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstAppend.c,v 1.15 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstAppend.c,v 1.14 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstAppend.c,v 1.15 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstAppend.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstAppend.c,v 1.14 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstAppend.c,v 1.15 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -85,7 +85,7 @@ Lst_InsertAfter(Lst l, LstNode ln, void *d) } if (!LstValid (l) || LstIsEmpty (l) || ! LstNodeValid (ln, l)) { - return (FAILURE); + return FAILURE; } ok: @@ -117,6 +117,5 @@ Lst_InsertAfter(Lst l, LstNode ln, void *d) } } - return (SUCCESS); + return SUCCESS; } - diff --git a/lst.lib/lstAtEnd.c b/lst.lib/lstAtEnd.c index 10f191a2060c..4eadfdb0e7f3 100644 --- a/lst.lib/lstAtEnd.c +++ b/lst.lib/lstAtEnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstAtEnd.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstAtEnd.c,v 1.14 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstAtEnd.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstAtEnd.c,v 1.14 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstAtEnd.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstAtEnd.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstAtEnd.c,v 1.14 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -75,5 +75,5 @@ Lst_AtEnd(Lst l, void *d) LstNode end; end = Lst_Last(l); - return (Lst_InsertAfter(l, end, d)); + return Lst_InsertAfter(l, end, d); } diff --git a/lst.lib/lstAtFront.c b/lst.lib/lstAtFront.c index d8be16647387..724713c092ed 100644 --- a/lst.lib/lstAtFront.c +++ b/lst.lib/lstAtFront.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstAtFront.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstAtFront.c,v 1.14 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstAtFront.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstAtFront.c,v 1.14 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstAtFront.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstAtFront.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstAtFront.c,v 1.14 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -72,5 +72,5 @@ Lst_AtFront(Lst l, void *d) LstNode front; front = Lst_First(l); - return (Lst_InsertBefore(l, front, d)); + return Lst_InsertBefore(l, front, d); } diff --git a/lst.lib/lstClose.c b/lst.lib/lstClose.c index 06b68c5c038a..a1a3e9da80de 100644 --- a/lst.lib/lstClose.c +++ b/lst.lib/lstClose.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstClose.c,v 1.11 2006/10/27 21:37:25 dsl Exp $ */ +/* $NetBSD: lstClose.c,v 1.12 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstClose.c,v 1.11 2006/10/27 21:37:25 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstClose.c,v 1.12 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstClose.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstClose.c,v 1.11 2006/10/27 21:37:25 dsl Exp $"); +__RCSID("$NetBSD: lstClose.c,v 1.12 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -83,4 +83,3 @@ Lst_Close(Lst l) list->atEnd = Unknown; } } - diff --git a/lst.lib/lstConcat.c b/lst.lib/lstConcat.c index 534d34e45424..2f667c5b0119 100644 --- a/lst.lib/lstConcat.c +++ b/lst.lib/lstConcat.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstConcat.c,v 1.16 2008/12/13 15:19:29 dsl Exp $ */ +/* $NetBSD: lstConcat.c,v 1.17 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstConcat.c,v 1.16 2008/12/13 15:19:29 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstConcat.c,v 1.17 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstConcat.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstConcat.c,v 1.16 2008/12/13 15:19:29 dsl Exp $"); +__RCSID("$NetBSD: lstConcat.c,v 1.17 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -86,7 +86,7 @@ Lst_Concat(Lst l1, Lst l2, int flags) List list2 = l2; if (!LstValid (l1) || !LstValid (l2)) { - return (FAILURE); + return FAILURE; } if (flags == LST_CONCLINK) { @@ -180,6 +180,5 @@ Lst_Concat(Lst l1, Lst l2, int flags) } } - return (SUCCESS); + return SUCCESS; } - diff --git a/lst.lib/lstDatum.c b/lst.lib/lstDatum.c index 6e2d9ad0e73b..c8ccb558f3dc 100644 --- a/lst.lib/lstDatum.c +++ b/lst.lib/lstDatum.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstDatum.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstDatum.c,v 1.14 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstDatum.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstDatum.c,v 1.14 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstDatum.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstDatum.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstDatum.c,v 1.14 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -69,9 +69,8 @@ void * Lst_Datum(LstNode ln) { if (ln != NULL) { - return ((ln)->datum); + return ln->datum; } else { return NULL; } } - diff --git a/lst.lib/lstDeQueue.c b/lst.lib/lstDeQueue.c index bdb05cc1168d..0f1452e4ac7e 100644 --- a/lst.lib/lstDeQueue.c +++ b/lst.lib/lstDeQueue.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstDeQueue.c,v 1.14 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstDeQueue.c,v 1.15 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstDeQueue.c,v 1.14 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstDeQueue.c,v 1.15 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstDeQueue.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstDeQueue.c,v 1.14 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstDeQueue.c,v 1.15 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -81,7 +81,6 @@ Lst_DeQueue(Lst l) if (Lst_Remove(l, tln) == FAILURE) { return NULL; } else { - return (rd); + return rd; } } - diff --git a/lst.lib/lstDupl.c b/lst.lib/lstDupl.c index 2174ff782282..6318ee4e462a 100644 --- a/lst.lib/lstDupl.c +++ b/lst.lib/lstDupl.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstDupl.c,v 1.16 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstDupl.c,v 1.17 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstDupl.c,v 1.16 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstDupl.c,v 1.17 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstDupl.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstDupl.c,v 1.16 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstDupl.c,v 1.17 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -103,5 +103,5 @@ Lst_Duplicate(Lst l, DuplicateProc *copyProc) } } - return (nl); + return nl; } diff --git a/lst.lib/lstEnQueue.c b/lst.lib/lstEnQueue.c index be386c91a512..c6941a8eb9d3 100644 --- a/lst.lib/lstEnQueue.c +++ b/lst.lib/lstEnQueue.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstEnQueue.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstEnQueue.c,v 1.14 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstEnQueue.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstEnQueue.c,v 1.14 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstEnQueue.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstEnQueue.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstEnQueue.c,v 1.14 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -70,9 +70,8 @@ ReturnStatus Lst_EnQueue(Lst l, void *d) { if (LstValid (l) == FALSE) { - return (FAILURE); + return FAILURE; } - return (Lst_InsertAfter(l, Lst_Last(l), d)); + return Lst_InsertAfter(l, Lst_Last(l), d); } - diff --git a/lst.lib/lstFind.c b/lst.lib/lstFind.c index d07dbe7f9f8c..a1d27d3ad686 100644 --- a/lst.lib/lstFind.c +++ b/lst.lib/lstFind.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstFind.c,v 1.15 2009/01/23 21:58:28 dsl Exp $ */ +/* $NetBSD: lstFind.c,v 1.16 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstFind.c,v 1.15 2009/01/23 21:58:28 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstFind.c,v 1.16 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstFind.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstFind.c,v 1.15 2009/01/23 21:58:28 dsl Exp $"); +__RCSID("$NetBSD: lstFind.c,v 1.16 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -69,6 +69,5 @@ __RCSID("$NetBSD: lstFind.c,v 1.15 2009/01/23 21:58:28 dsl Exp $"); LstNode Lst_Find(Lst l, const void *d, int (*cProc)(const void *, const void *)) { - return (Lst_FindFrom(l, Lst_First(l), d, cProc)); + return Lst_FindFrom(l, Lst_First(l), d, cProc); } - diff --git a/lst.lib/lstFindFrom.c b/lst.lib/lstFindFrom.c index e2beab6321d5..676c07392039 100644 --- a/lst.lib/lstFindFrom.c +++ b/lst.lib/lstFindFrom.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstFindFrom.c,v 1.15 2009/01/23 21:58:28 dsl Exp $ */ +/* $NetBSD: lstFindFrom.c,v 1.16 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstFindFrom.c,v 1.15 2009/01/23 21:58:28 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstFindFrom.c,v 1.16 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstFindFrom.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstFindFrom.c,v 1.15 2009/01/23 21:58:28 dsl Exp $"); +__RCSID("$NetBSD: lstFindFrom.c,v 1.16 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -81,10 +81,9 @@ Lst_FindFrom(Lst l, LstNode ln, const void *d, do { if ((*cProc)(tln->datum, d) == 0) - return (tln); + return tln; tln = tln->nextPtr; } while (tln != ln && tln != NULL); return NULL; } - diff --git a/lst.lib/lstFirst.c b/lst.lib/lstFirst.c index 4e8334f8bcc9..a79db57120dd 100644 --- a/lst.lib/lstFirst.c +++ b/lst.lib/lstFirst.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstFirst.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */ +/* $NetBSD: lstFirst.c,v 1.13 2020/07/03 08:37:56 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstFirst.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstFirst.c,v 1.13 2020/07/03 08:37:56 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstFirst.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstFirst.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"); +__RCSID("$NetBSD: lstFirst.c,v 1.13 2020/07/03 08:37:56 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -71,7 +71,6 @@ Lst_First(Lst l) if (!LstValid (l) || LstIsEmpty (l)) { return NULL; } else { - return (l->firstPtr); + return l->firstPtr; } } - diff --git a/lst.lib/lstForEach.c b/lst.lib/lstForEach.c index 917e4ea80236..dc2fdd8bfc57 100644 --- a/lst.lib/lstForEach.c +++ b/lst.lib/lstForEach.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstForEach.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstForEach.c,v 1.14 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstForEach.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstForEach.c,v 1.14 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstForEach.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstForEach.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstForEach.c,v 1.14 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -73,4 +73,3 @@ Lst_ForEach(Lst l, int (*proc)(void *, void *), void *d) { return Lst_ForEachFrom(l, Lst_First(l), proc, d); } - diff --git a/lst.lib/lstForEachFrom.c b/lst.lib/lstForEachFrom.c index c7f44adc476a..a08ddf35935b 100644 --- a/lst.lib/lstForEachFrom.c +++ b/lst.lib/lstForEachFrom.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstForEachFrom.c,v 1.17 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstForEachFrom.c,v 1.18 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstForEachFrom.c,v 1.17 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstForEachFrom.c,v 1.18 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstForEachFrom.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstForEachFrom.c,v 1.17 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstForEachFrom.c,v 1.18 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -122,4 +122,3 @@ Lst_ForEachFrom(Lst l, LstNode ln, int (*proc)(void *, void *), return result; } - diff --git a/lst.lib/lstInit.c b/lst.lib/lstInit.c index f98ac42b06a0..3255da7e59a1 100644 --- a/lst.lib/lstInit.c +++ b/lst.lib/lstInit.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstInit.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */ +/* $NetBSD: lstInit.c,v 1.13 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstInit.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstInit.c,v 1.13 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstInit.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstInit.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"); +__RCSID("$NetBSD: lstInit.c,v 1.13 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -81,5 +81,5 @@ Lst_Init(Boolean circ) nList->isCirc = circ; nList->atEnd = Unknown; - return (nList); + return nList; } diff --git a/lst.lib/lstInsert.c b/lst.lib/lstInsert.c index 77187bb327e2..845b8899e03b 100644 --- a/lst.lib/lstInsert.c +++ b/lst.lib/lstInsert.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstInsert.c,v 1.14 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstInsert.c,v 1.15 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstInsert.c,v 1.14 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstInsert.c,v 1.15 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstInsert.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstInsert.c,v 1.14 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstInsert.c,v 1.15 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -87,7 +87,7 @@ Lst_InsertBefore(Lst l, LstNode ln, void *d) goto ok; if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) { - return (FAILURE); + return FAILURE; } ok: @@ -117,6 +117,5 @@ Lst_InsertBefore(Lst l, LstNode ln, void *d) } } - return (SUCCESS); + return SUCCESS; } - diff --git a/lst.lib/lstIsAtEnd.c b/lst.lib/lstIsAtEnd.c index 70270d2956c1..c5add4d9867f 100644 --- a/lst.lib/lstIsAtEnd.c +++ b/lst.lib/lstIsAtEnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $ */ +/* $NetBSD: lstIsAtEnd.c,v 1.14 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $"; +static char rcsid[] = "$NetBSD: lstIsAtEnd.c,v 1.14 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstIsAtEnd.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $"); +__RCSID("$NetBSD: lstIsAtEnd.c,v 1.14 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -81,7 +81,6 @@ Lst_IsAtEnd(Lst l) { List list = l; - return (!LstValid (l) || !list->isOpen || - (list->atEnd == Head) || (list->atEnd == Tail)); + return !LstValid (l) || !list->isOpen || + list->atEnd == Head || list->atEnd == Tail; } - diff --git a/lst.lib/lstIsEmpty.c b/lst.lib/lstIsEmpty.c index 8b1d6ed0dd91..ccf4525a3506 100644 --- a/lst.lib/lstIsEmpty.c +++ b/lst.lib/lstIsEmpty.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstIsEmpty.c,v 1.11 2008/12/13 15:19:29 dsl Exp $ */ +/* $NetBSD: lstIsEmpty.c,v 1.12 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstIsEmpty.c,v 1.11 2008/12/13 15:19:29 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstIsEmpty.c,v 1.12 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstIsEmpty.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstIsEmpty.c,v 1.11 2008/12/13 15:19:29 dsl Exp $"); +__RCSID("$NetBSD: lstIsEmpty.c,v 1.12 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -70,6 +70,5 @@ __RCSID("$NetBSD: lstIsEmpty.c,v 1.11 2008/12/13 15:19:29 dsl Exp $"); Boolean Lst_IsEmpty(Lst l) { - return ( ! LstValid (l) || LstIsEmpty(l)); + return !LstValid(l) || LstIsEmpty(l); } - diff --git a/lst.lib/lstLast.c b/lst.lib/lstLast.c index 096ca24d1372..1d65bf19473e 100644 --- a/lst.lib/lstLast.c +++ b/lst.lib/lstLast.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstLast.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */ +/* $NetBSD: lstLast.c,v 1.13 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstLast.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstLast.c,v 1.13 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstLast.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstLast.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"); +__RCSID("$NetBSD: lstLast.c,v 1.13 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -71,7 +71,6 @@ Lst_Last(Lst l) if (!LstValid(l) || LstIsEmpty (l)) { return NULL; } else { - return (l->lastPtr); + return l->lastPtr; } } - diff --git a/lst.lib/lstNext.c b/lst.lib/lstNext.c index 5c2e0eece592..9c180d2cfad1 100644 --- a/lst.lib/lstNext.c +++ b/lst.lib/lstNext.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstNext.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */ +/* $NetBSD: lstNext.c,v 1.13 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstNext.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstNext.c,v 1.13 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstNext.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstNext.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"); +__RCSID("$NetBSD: lstNext.c,v 1.13 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -115,6 +115,5 @@ Lst_Next(Lst l) } } - return (tln); + return tln; } - diff --git a/lst.lib/lstOpen.c b/lst.lib/lstOpen.c index 941293e7abb2..919dd6d5000c 100644 --- a/lst.lib/lstOpen.c +++ b/lst.lib/lstOpen.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstOpen.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */ +/* $NetBSD: lstOpen.c,v 1.13 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstOpen.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstOpen.c,v 1.13 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstOpen.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstOpen.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"); +__RCSID("$NetBSD: lstOpen.c,v 1.13 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -76,12 +76,11 @@ ReturnStatus Lst_Open(Lst l) { if (LstValid (l) == FALSE) { - return (FAILURE); + return FAILURE; } (l)->isOpen = TRUE; (l)->atEnd = LstIsEmpty (l) ? Head : Unknown; (l)->curPtr = NULL; - return (SUCCESS); + return SUCCESS; } - diff --git a/lst.lib/lstPrev.c b/lst.lib/lstPrev.c index 0ec865d51652..b6c548d9a523 100644 --- a/lst.lib/lstPrev.c +++ b/lst.lib/lstPrev.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstPrev.c,v 1.3 2008/12/13 15:19:29 dsl Exp $ */ +/* $NetBSD: lstPrev.c,v 1.4 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstPrev.c,v 1.3 2008/12/13 15:19:29 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstPrev.c,v 1.4 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstSucc.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstPrev.c,v 1.3 2008/12/13 15:19:29 dsl Exp $"); +__RCSID("$NetBSD: lstPrev.c,v 1.4 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -73,7 +73,6 @@ Lst_Prev(LstNode ln) if (ln == NULL) { return NULL; } else { - return (ln->prevPtr); + return ln->prevPtr; } } - diff --git a/lst.lib/lstRemove.c b/lst.lib/lstRemove.c index 7480d30ba4f4..59245499bdc4 100644 --- a/lst.lib/lstRemove.c +++ b/lst.lib/lstRemove.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstRemove.c,v 1.16 2014/09/07 20:55:34 joerg Exp $ */ +/* $NetBSD: lstRemove.c,v 1.17 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstRemove.c,v 1.16 2014/09/07 20:55:34 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstRemove.c,v 1.17 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstRemove.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstRemove.c,v 1.16 2014/09/07 20:55:34 joerg Exp $"); +__RCSID("$NetBSD: lstRemove.c,v 1.17 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -73,9 +73,8 @@ Lst_Remove(Lst l, LstNode ln) List list = l; ListNode lNode = ln; - if (!LstValid (l) || - !LstNodeValid (ln, l)) { - return (FAILURE); + if (!LstValid (l) || !LstNodeValid (ln, l)) { + return FAILURE; } /* @@ -131,6 +130,5 @@ Lst_Remove(Lst l, LstNode ln) lNode->flags |= LN_DELETED; } - return (SUCCESS); + return SUCCESS; } - diff --git a/lst.lib/lstReplace.c b/lst.lib/lstReplace.c index 090e91a72c6e..f30cb00855e3 100644 --- a/lst.lib/lstReplace.c +++ b/lst.lib/lstReplace.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstReplace.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */ +/* $NetBSD: lstReplace.c,v 1.14 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstReplace.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstReplace.c,v 1.14 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstReplace.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstReplace.c,v 1.13 2009/01/23 21:26:30 dsl Exp $"); +__RCSID("$NetBSD: lstReplace.c,v 1.14 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -69,10 +69,9 @@ ReturnStatus Lst_Replace(LstNode ln, void *d) { if (ln == NULL) { - return (FAILURE); + return FAILURE; } else { (ln)->datum = d; - return (SUCCESS); + return SUCCESS; } } - diff --git a/lst.lib/lstSucc.c b/lst.lib/lstSucc.c index 3f13aa5e7f66..b3f73bb15fd2 100644 --- a/lst.lib/lstSucc.c +++ b/lst.lib/lstSucc.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstSucc.c,v 1.13 2008/12/13 15:19:29 dsl Exp $ */ +/* $NetBSD: lstSucc.c,v 1.14 2020/07/03 08:37:57 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstSucc.c,v 1.13 2008/12/13 15:19:29 dsl Exp $"; +static char rcsid[] = "$NetBSD: lstSucc.c,v 1.14 2020/07/03 08:37:57 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)lstSucc.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstSucc.c,v 1.13 2008/12/13 15:19:29 dsl Exp $"); +__RCSID("$NetBSD: lstSucc.c,v 1.14 2020/07/03 08:37:57 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -73,7 +73,6 @@ Lst_Succ(LstNode ln) if (ln == NULL) { return NULL; } else { - return (ln->nextPtr); + return ln->nextPtr; } } - diff --git a/main.c b/main.c index 3e28bd5bdc15..25141625e55c 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.276 2020/06/22 20:15:25 sjg Exp $ */ +/* $NetBSD: main.c,v 1.279 2020/07/03 08:13:23 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,7 +69,7 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: main.c,v 1.276 2020/06/22 20:15:25 sjg Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.279 2020/07/03 08:13:23 rillig Exp $"; #else #include #ifndef lint @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: main.c,v 1.276 2020/06/22 20:15:25 sjg Exp $"); +__RCSID("$NetBSD: main.c,v 1.279 2020/07/03 08:13:23 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -245,7 +245,7 @@ explode(const char *flags) *nf = '\0'; return st; } - + static void parse_debug_options(const char *argvalue) { @@ -429,7 +429,7 @@ MainParseArgs(int argc, char **argv) /* Can't actually use getopt(3) because rescanning is not portable */ getopt_def = OPTFLAGS; -rearg: +rearg: inOption = FALSE; optscan = NULL; while(argc > 1) { @@ -465,7 +465,7 @@ MainParseArgs(int argc, char **argv) arginc = 2; } } else { - argvalue = NULL; + argvalue = NULL; } switch(c) { case '\0': @@ -475,7 +475,7 @@ MainParseArgs(int argc, char **argv) case 'B': compatMake = TRUE; Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL); - Var_Set(MAKE_MODE, "compat", VAR_GLOBAL, 0); + Var_Set(MAKE_MODE, "compat", VAR_GLOBAL); break; case 'C': if (chdir(argvalue) == -1) { @@ -499,7 +499,7 @@ MainParseArgs(int argc, char **argv) break; case 'D': if (argvalue == NULL || argvalue[0] == 0) goto noarg; - Var_Set(argvalue, "1", VAR_GLOBAL, 0); + Var_Set(argvalue, "1", VAR_GLOBAL); Var_Append(MAKEFLAGS, "-D", VAR_GLOBAL); Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL); break; @@ -598,7 +598,7 @@ MainParseArgs(int argc, char **argv) } Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL); Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL); - Var_Set(".MAKE.JOBS", argvalue, VAR_GLOBAL, 0); + Var_Set(".MAKE.JOBS", argvalue, VAR_GLOBAL); maxJobTokens = maxJobs; break; case 'k': @@ -776,7 +776,7 @@ Main_SetObjdir(const char *fmt, ...) path, strerror(errno)); } else { strncpy(objdir, path, MAXPATHLEN); - Var_Set(".OBJDIR", objdir, VAR_GLOBAL, 0); + Var_Set(".OBJDIR", objdir, VAR_GLOBAL); setenv("PWD", objdir, 1); Dir_InitDot(); purge_cached_realpaths(); @@ -822,7 +822,7 @@ Main_SetVarObjdir(const char *var, const char *suffix) static int ReadAllMakefiles(const void *p, const void *q) { - return (ReadMakefile(p, q) == 0); + return ReadMakefile(p, q) == 0; } int @@ -838,7 +838,7 @@ str2Lst_Append(Lst lp, char *str, const char *sep) (void)Lst_AtEnd(lp, cp); n++; } - return (n); + return n; } #ifdef SIGINFO @@ -901,14 +901,14 @@ doPrintVars(void) char *var = (char *)Lst_Datum(ln); char *value; char *p1; - + if (strchr(var, '$')) { value = p1 = Var_Subst(NULL, var, VAR_GLOBAL, VARF_WANTRES); } else if (expandVars) { char tmp[128]; int len = snprintf(tmp, sizeof(tmp), "${%s}", var); - + if (len >= (int)sizeof(tmp)) Fatal("%s: variable name too big: %s", progname, var); @@ -1017,7 +1017,7 @@ main(int argc, char **argv) */ gettimeofday(&rightnow, NULL); srandom(rightnow.tv_sec + rightnow.tv_usec); - + if ((progname = strrchr(argv[0], '/')) != NULL) progname++; else @@ -1067,7 +1067,7 @@ main(int argc, char **argv) static char machine_arch_buf[sizeof(utsname.machine)]; int mib[2] = { CTL_HW, HW_MACHINE_ARCH }; size_t len = sizeof(machine_arch_buf); - + if (sysctl(mib, __arraycount(mib), machine_arch_buf, &len, NULL, 0) < 0) { (void)fprintf(stderr, "%s: sysctl failed (%s).\n", progname, @@ -1096,13 +1096,13 @@ main(int argc, char **argv) */ Var_Init(); /* Initialize the lists of variables for * parsing arguments */ - Var_Set(".MAKE.OS", utsname.sysname, VAR_GLOBAL, 0); - Var_Set("MACHINE", machine, VAR_GLOBAL, 0); - Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL, 0); + Var_Set(".MAKE.OS", utsname.sysname, VAR_GLOBAL); + Var_Set("MACHINE", machine, VAR_GLOBAL); + Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL); #ifdef MAKE_VERSION - Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL, 0); + Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL); #endif - Var_Set(".newline", "\n", VAR_GLOBAL, 0); /* handy for :@ loops */ + Var_Set(".newline", "\n", VAR_GLOBAL); /* handy for :@ loops */ /* * This is the traditional preference for makefiles. */ @@ -1110,8 +1110,8 @@ main(int argc, char **argv) # define MAKEFILE_PREFERENCE_LIST "makefile Makefile" #endif Var_Set(MAKEFILE_PREFERENCE, MAKEFILE_PREFERENCE_LIST, - VAR_GLOBAL, 0); - Var_Set(MAKE_DEPENDFILE, ".depend", VAR_GLOBAL, 0); + VAR_GLOBAL); + Var_Set(MAKE_DEPENDFILE, ".depend", VAR_GLOBAL); create = Lst_Init(FALSE); makefiles = Lst_Init(FALSE); @@ -1165,14 +1165,14 @@ main(int argc, char **argv) p1 = argv[0]; /* realpath failed */ } } - Var_Set("MAKE", p1, VAR_GLOBAL, 0); - Var_Set(".MAKE", p1, VAR_GLOBAL, 0); - Var_Set(MAKEFLAGS, "", VAR_GLOBAL, 0); - Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL, 0); - Var_Set("MFLAGS", "", VAR_GLOBAL, 0); - Var_Set(".ALLTARGETS", "", VAR_GLOBAL, 0); + Var_Set("MAKE", p1, VAR_GLOBAL); + Var_Set(".MAKE", p1, VAR_GLOBAL); + Var_Set(MAKEFLAGS, "", VAR_GLOBAL); + Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL); + Var_Set("MFLAGS", "", VAR_GLOBAL); + Var_Set(".ALLTARGETS", "", VAR_GLOBAL); /* some makefiles need to know this */ - Var_Set(MAKE_LEVEL ".ENV", MAKE_LEVEL_ENV, VAR_CMD, 0); + Var_Set(MAKE_LEVEL ".ENV", MAKE_LEVEL_ENV, VAR_CMD); /* * Set some other useful macros @@ -1184,11 +1184,11 @@ main(int argc, char **argv) if (makelevel < 0) makelevel = 0; snprintf(tmp, sizeof(tmp), "%d", makelevel); - Var_Set(MAKE_LEVEL, tmp, VAR_GLOBAL, 0); + Var_Set(MAKE_LEVEL, tmp, VAR_GLOBAL); snprintf(tmp, sizeof(tmp), "%u", myPid); - Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0); + Var_Set(".MAKE.PID", tmp, VAR_GLOBAL); snprintf(tmp, sizeof(tmp), "%u", getppid()); - Var_Set(".MAKE.PPID", tmp, VAR_GLOBAL, 0); + Var_Set(".MAKE.PPID", tmp, VAR_GLOBAL); } if (makelevel > 0) { char pn[1024]; @@ -1269,7 +1269,7 @@ main(int argc, char **argv) free(ptmp2); } #endif - Var_Set(".CURDIR", curdir, VAR_GLOBAL, 0); + Var_Set(".CURDIR", curdir, VAR_GLOBAL); /* * Find the .OBJDIR. If MAKEOBJDIRPREFIX, or failing that, @@ -1303,7 +1303,7 @@ main(int argc, char **argv) (void)time(&now); Trace_Log(MAKESTART, NULL); - + /* * Set up the .TARGETS variable to contain the list of targets to be * created. If none specified, make the variable empty -- the parser @@ -1319,7 +1319,7 @@ main(int argc, char **argv) Var_Append(".TARGETS", name, VAR_GLOBAL); } } else - Var_Set(".TARGETS", "", VAR_GLOBAL, 0); + Var_Set(".TARGETS", "", VAR_GLOBAL); /* @@ -1342,7 +1342,7 @@ main(int argc, char **argv) if (strncmp(".../", start, 4) != 0) { (void)Dir_AddDir(defIncPath, start); } else { - if (Dir_FindHereOrAbove(curdir, start+4, + if (Dir_FindHereOrAbove(curdir, start+4, found_path, sizeof(found_path))) { (void)Dir_AddDir(defIncPath, found_path); } @@ -1377,7 +1377,7 @@ main(int argc, char **argv) ln = Lst_Find(makefiles, NULL, ReadAllMakefiles); if (ln != NULL) - Fatal("%s: cannot open %s.", progname, + Fatal("%s: cannot open %s.", progname, (char *)Lst_Datum(ln)); } else { p1 = Var_Subst(NULL, "${" MAKEFILE_PREFERENCE "}", @@ -1400,7 +1400,7 @@ main(int argc, char **argv) if (enterFlagObj) printf("%s: Entering directory `%s'\n", progname, objdir); - + MakeMode(NULL); Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL); @@ -1444,7 +1444,8 @@ main(int argc, char **argv) if (!printVars) Main_ExportMAKEFLAGS(TRUE); /* initial export */ - + + /* * For compatibility, look at the directories in the VPATH variable * and add them to the search path, if the variable is defined. The @@ -1552,21 +1553,21 @@ ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED) if (!strcmp(fname, "-")) { Parse_File(NULL /*stdin*/, -1); - Var_Set("MAKEFILE", "", VAR_INTERNAL, 0); + Var_Set("MAKEFILE", "", VAR_INTERNAL); } else { /* if we've chdir'd, rebuild the path name */ if (strcmp(curdir, objdir) && *fname != '/') { size_t plen = strlen(curdir) + strlen(fname) + 2; if (len < plen) path = bmake_realloc(path, len = 2 * plen); - + (void)snprintf(path, len, "%s/%s", curdir, fname); fd = open(path, O_RDONLY); if (fd != -1) { fname = path; goto found; } - + /* If curdir failed, try objdir (ala .depend) */ plen = strlen(objdir) + strlen(fname) + 2; if (len < plen) @@ -1590,7 +1591,7 @@ ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED) if (!name || (fd = open(name, O_RDONLY)) == -1) { free(name); free(path); - return(-1); + return -1; } fname = name; /* @@ -1600,11 +1601,11 @@ ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED) */ found: if (!doing_depend) - Var_Set("MAKEFILE", fname, VAR_INTERNAL, 0); + Var_Set("MAKEFILE", fname, VAR_INTERNAL); Parse_File(fname, fd); } free(path); - return(0); + return 0; } @@ -2020,8 +2021,9 @@ cached_realpath(const char *pathname, char *resolved) /* a hit */ strlcpy(resolved, rp, MAXPATHLEN); } else if ((rp = realpath(pathname, resolved)) != NULL) { - Var_Set(pathname, rp, cache, 0); - } + Var_Set(pathname, rp, cache); + } /* else should we negative-cache? */ + free(cp); return rp ? resolved : NULL; } @@ -2077,7 +2079,7 @@ PrintOnError(GNode *gn, const char *s) if (s) printf("%s", s); - + printf("\n%s: stopped in %s\n", progname, curdir); if (en) @@ -2086,7 +2088,7 @@ PrintOnError(GNode *gn, const char *s) /* * We can print this even if there is no .ERROR target. */ - Var_Set(".ERROR_TARGET", gn->name, VAR_GLOBAL, 0); + Var_Set(".ERROR_TARGET", gn->name, VAR_GLOBAL); Var_Delete(".ERROR_CMD", VAR_GLOBAL); Lst_ForEach(gn->commands, addErrorCMD, gn); } @@ -2120,7 +2122,7 @@ Main_ExportMAKEFLAGS(Boolean first) if (once != first) return; once = 0; - + strncpy(tmp, "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}", sizeof(tmp)); s = Var_Subst(NULL, tmp, VAR_CMD, VARF_WANTRES); @@ -2166,7 +2168,7 @@ mkTempFile(const char *pattern, char **fnamep) static char *tmpdir = NULL; char tfile[MAXPATHLEN]; int fd; - + if (!pattern) pattern = TMPPAT; if (!tmpdir) @@ -2222,7 +2224,7 @@ s2Boolean(const char *s, Boolean bf) break; } } - return (bf); + return bf; } /* @@ -2246,5 +2248,5 @@ getBoolean(const char *name, Boolean bf) free(cp); } } - return (bf); + return bf; } diff --git a/make.c b/make.c index 8947582013c1..9472a045c26a 100644 --- a/make.c +++ b/make.c @@ -1,4 +1,4 @@ -/* $NetBSD: make.c,v 1.96 2016/11/10 23:41:58 sjg Exp $ */ +/* $NetBSD: make.c,v 1.99 2020/07/03 08:13:23 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: make.c,v 1.96 2016/11/10 23:41:58 sjg Exp $"; +static char rcsid[] = "$NetBSD: make.c,v 1.99 2020/07/03 08:13:23 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: make.c,v 1.96 2016/11/10 23:41:58 sjg Exp $"); +__RCSID("$NetBSD: make.c,v 1.99 2020/07/03 08:13:23 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -175,7 +175,7 @@ Make_TimeStamp(GNode *pgn, GNode *cgn) if (pgn->cmgn == NULL || cgn->mtime > pgn->cmgn->mtime) { pgn->cmgn = cgn; } - return (0); + return 0; } /* @@ -264,7 +264,7 @@ Make_OODate(GNode *gn) * always out of date if no children and :: target * or non-existent. */ - oodate = (gn->mtime == 0 || Arch_LibOODate(gn) || + oodate = (gn->mtime == 0 || Arch_LibOODate(gn) || (gn->cmgn == NULL && (gn->type & OP_DOUBLEDEP))); } else if (gn->type & OP_JOIN) { /* @@ -317,7 +317,7 @@ Make_OODate(GNode *gn) } oodate = TRUE; } else { - /* + /* * When a non-existing child with no sources * (such as a typically used FORCE source) has been made and * the target of the child (usually a directory) has the same @@ -348,7 +348,7 @@ Make_OODate(GNode *gn) Lst_ForEach(gn->parents, MakeTimeStamp, gn); } - return (oodate); + return oodate; } /*- @@ -380,7 +380,7 @@ MakeAddChild(void *gnp, void *lp) gn->name, gn->cohort_num); (void)Lst_EnQueue(l, gn); } - return (0); + return 0; } /*- @@ -410,7 +410,7 @@ MakeFindChild(void *gnp, void *pgnp) Make_TimeStamp(pgn, gn); pgn->unmade--; - return (0); + return 0; } /*- @@ -535,7 +535,7 @@ MakeHandleUse(void *cgnp, void *pgnp) cgn->type |= OP_MARK; if ((cgn->type & (OP_USE|OP_USEBEFORE)) == 0) - return (0); + return 0; if (unmarked) Make_HandleUse(cgn, pgn); @@ -551,7 +551,7 @@ MakeHandleUse(void *cgnp, void *pgnp) Lst_Remove(pgn->children, ln); pgn->unmade--; } - return (0); + return 0; } @@ -831,9 +831,9 @@ Make_Update(GNode *cgn) while ((ln = Lst_Next(cgn->iParents)) != NULL) { pgn = (GNode *)Lst_Datum(ln); if (pgn->flags & REMAKE) { - Var_Set(IMPSRC, cname, pgn, 0); + Var_Set(IMPSRC, cname, pgn); if (cpref != NULL) - Var_Set(PREFIX, cpref, pgn, 0); + Var_Set(PREFIX, cpref, pgn); } } free(p1); @@ -869,7 +869,7 @@ MakeUnmark(void *cgnp, void *pgnp MAKE_ATTR_UNUSED) GNode *cgn = (GNode *)cgnp; cgn->type &= ~OP_MARK; - return (0); + return 0; } /* @@ -886,7 +886,7 @@ MakeAddAllSrc(void *cgnp, void *pgnp) GNode *pgn = (GNode *)pgnp; if (cgn->type & OP_MARK) - return (0); + return 0; cgn->type |= OP_MARK; if ((cgn->type & (OP_EXEC|OP_USE|OP_USEBEFORE|OP_INVISIBLE)) == 0) { @@ -932,7 +932,7 @@ MakeAddAllSrc(void *cgnp, void *pgnp) } free(p1); } - return (0); + return 0; } /*- @@ -962,20 +962,20 @@ Make_DoAllVar(GNode *gn) { if (gn->flags & DONE_ALLSRC) return; - + Lst_ForEach(gn->children, MakeUnmark, gn); Lst_ForEach(gn->children, MakeAddAllSrc, gn); if (!Var_Exists (OODATE, gn)) { - Var_Set(OODATE, "", gn, 0); + Var_Set(OODATE, "", gn); } if (!Var_Exists (ALLSRC, gn)) { - Var_Set(ALLSRC, "", gn, 0); + Var_Set(ALLSRC, "", gn); } if (gn->type & OP_JOIN) { char *p1; - Var_Set(TARGET, Var_Value(ALLSRC, gn, &p1), gn, 0); + Var_Set(TARGET, Var_Value(ALLSRC, gn, &p1), gn); free(p1); } gn->flags |= DONE_ALLSRC; @@ -1119,7 +1119,7 @@ MakeStartJobs(void) fprintf(debug_file, "out-of-date\n"); } if (queryFlag) { - return (TRUE); + return TRUE; } Make_DoAllVar(gn); Job_Make(gn); @@ -1145,7 +1145,7 @@ MakeStartJobs(void) if (have_token) Job_TokenReturn(); - return (FALSE); + return FALSE; } /*- @@ -1293,7 +1293,7 @@ Make_ExpandUse(Lst targs) */ while (!Lst_IsEmpty (examine)) { gn = (GNode *)Lst_DeQueue(examine); - + if (gn->flags & REMAKE) /* We've looked at this one already */ continue; @@ -1324,14 +1324,14 @@ Make_ExpandUse(Lst targs) continue; *eoa = '\0'; *eon = '\0'; - Var_Set(MEMBER, eoa + 1, gn, 0); - Var_Set(ARCHIVE, gn->name, gn, 0); + Var_Set(MEMBER, eoa + 1, gn); + Var_Set(ARCHIVE, gn->name, gn); *eoa = '('; *eon = ')'; } (void)Dir_MTime(gn, 0); - Var_Set(TARGET, gn->path ? gn->path : gn->name, gn, 0); + Var_Set(TARGET, gn->path ? gn->path : gn->name, gn); Lst_ForEach(gn->children, MakeUnmark, gn); Lst_ForEach(gn->children, MakeHandleUse, gn); @@ -1429,7 +1429,7 @@ Make_ProcessWait(Lst targs) while (!Lst_IsEmpty (examine)) { pgn = Lst_DeQueue(examine); - + /* We only want to process each child-list once */ if (pgn->flags & DONE_WAIT) continue; @@ -1509,7 +1509,7 @@ Make_Run(Lst targs) * next loop... (we won't actually start any, of course, this is just * to see if any of the targets was out of date) */ - return (MakeStartJobs()); + return MakeStartJobs(); } /* * Initialization. At the moment, no jobs are running and until some diff --git a/make.h b/make.h index 4057137c7a10..eafa761ea36a 100644 --- a/make.h +++ b/make.h @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.108 2020/06/19 21:17:48 sjg Exp $ */ +/* $NetBSD: make.h,v 1.109 2020/07/02 15:14:38 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -512,10 +512,6 @@ int str2Lst_Append(Lst, char *, const char *); int cached_lstat(const char *, void *); int cached_stat(const char *, void *); -#define VARF_UNDEFERR 1 -#define VARF_WANTRES 2 -#define VARF_ASSIGN 4 - #ifdef __GNUC__ #define UNCONST(ptr) ({ \ union __unconst { \ diff --git a/make_malloc.c b/make_malloc.c index 035d519b9c12..7e2f75ff85e0 100644 --- a/make_malloc.c +++ b/make_malloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: make_malloc.c,v 1.11 2017/04/16 20:20:24 dholland Exp $ */ +/* $NetBSD: make_malloc.c,v 1.12 2020/07/03 08:02:55 rillig Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ #ifdef MAKE_NATIVE #include -__RCSID("$NetBSD: make_malloc.c,v 1.11 2017/04/16 20:20:24 dholland Exp $"); +__RCSID("$NetBSD: make_malloc.c,v 1.12 2020/07/03 08:02:55 rillig Exp $"); #endif #include @@ -63,7 +63,7 @@ bmake_malloc(size_t len) if ((p = malloc(len)) == NULL) enomem(); - return(p); + return p; } /* @@ -102,7 +102,7 @@ bmake_strndup(const char *str, size_t max_len) memcpy(p, str, len); p[len] = '\0'; - return(p); + return p; } /* @@ -114,6 +114,6 @@ bmake_realloc(void *ptr, size_t size) { if ((ptr = realloc(ptr, size)) == NULL) enomem(); - return(ptr); + return ptr; } #endif diff --git a/meta.c b/meta.c index 03a67f19e87b..7f555e71269e 100644 --- a/meta.c +++ b/meta.c @@ -1,4 +1,4 @@ -/* $NetBSD: meta.c,v 1.82 2020/06/25 15:45:37 sjg Exp $ */ +/* $NetBSD: meta.c,v 1.85 2020/07/03 08:13:23 rillig Exp $ */ /* * Implement 'meta' mode. @@ -8,16 +8,16 @@ /* * Copyright (c) 2009-2016, Juniper Networks, Inc. * Portions Copyright (c) 2009, John Birrell. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * modification, are permitted provided that the following conditions + * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * + * documentation and/or other materials provided with the distribution. + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -28,7 +28,7 @@ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(USE_META) @@ -113,7 +113,7 @@ extern char **environ; * * See meta_oodate below - we mainly care about 'E' and 'R'. * - * We can still use meta mode without filemon, but + * We can still use meta mode without filemon, but * the benefits are more limited. */ #ifdef USE_FILEMON @@ -218,7 +218,7 @@ eat_dots(char *buf, size_t bufsz, int dots) default: return; } - + do { cp = strstr(buf, eat); if (cp) { @@ -308,7 +308,7 @@ meta_name(char *mname, size_t mnamelen, } } free(tp); - return (mname); + return mname; } /* @@ -359,7 +359,7 @@ is_submake(void *cmdp, void *gnp) } } free(mp); - return (rc); + return rc; } typedef struct meta_file_s { @@ -407,7 +407,7 @@ meta_needed(GNode *gn, const char *dname, if (verbose) verbose = DEBUG(META); - + /* This may be a phony node which we don't want meta data for... */ /* Skip .meta for .BEGIN, .END, .ERROR etc as well. */ /* Or it may be explicitly flagged as .NOMETA */ @@ -458,7 +458,7 @@ meta_needed(GNode *gn, const char *dname, return TRUE; } - + static FILE * meta_create(BuildMon *pbm, GNode *gn) { @@ -549,7 +549,7 @@ meta_create(BuildMon *pbm, GNode *gn) free(p[i]); } - return (mf.fp); + return mf.fp; } static Boolean @@ -574,7 +574,7 @@ meta_init(void) { #ifdef USE_FILEMON /* this allows makefiles to test if we have filemon support */ - Var_Set(".MAKE.PATH_FILEMON", filemon_path(), VAR_GLOBAL, 0); + Var_Set(".MAKE.PATH_FILEMON", filemon_path(), VAR_GLOBAL); #endif } @@ -620,7 +620,7 @@ meta_mode_init(const char *make_mode) * This works be cause :H will generate '.' if there is no / * and :tA will resolve that to cwd. */ - Var_Set(MAKE_META_PREFIX, "Building ${.TARGET:H:tA}/${.TARGET:T}", VAR_GLOBAL, 0); + Var_Set(MAKE_META_PREFIX, "Building ${.TARGET:H:tA}/${.TARGET:T}", VAR_GLOBAL); } if (once) return; @@ -794,12 +794,12 @@ meta_job_error(Job *job, GNode *gn, int flags, int status) "(ignored)" : ""); } if (gn) { - Var_Set(".ERROR_TARGET", gn->path ? gn->path : gn->name, VAR_GLOBAL, 0); + Var_Set(".ERROR_TARGET", gn->path ? gn->path : gn->name, VAR_GLOBAL); } getcwd(cwd, sizeof(cwd)); - Var_Set(".ERROR_CWD", cwd, VAR_GLOBAL, 0); + Var_Set(".ERROR_CWD", cwd, VAR_GLOBAL); if (pbm->meta_fname[0]) { - Var_Set(".ERROR_META_FILE", pbm->meta_fname, VAR_GLOBAL, 0); + Var_Set(".ERROR_META_FILE", pbm->meta_fname, VAR_GLOBAL); } meta_job_finish(job); } @@ -808,7 +808,7 @@ void meta_job_output(Job *job, char *cp, const char *nl) { BuildMon *pbm; - + if (job != NULL) { pbm = &job->bm; } else { @@ -904,7 +904,7 @@ meta_finish(void) * Fetch a full line from fp - growing bufp if needed * Return length in bufp. */ -static int +static int fgetLine(char **bufp, size_t *szp, int o, FILE *fp) { char *buf = *bufp; @@ -955,7 +955,7 @@ prefix_match(void *p, void *q) const char *path = q; size_t n = strlen(prefix); - return (0 == strncmp(path, prefix, n)); + return strncmp(path, prefix, n) == 0; } /* @@ -1017,7 +1017,7 @@ meta_ignore(GNode *gn, const char *p) if (metaIgnorePatterns) { char *pm; - Var_Set(".p.", p, gn, 0); + Var_Set(".p.", p, gn); pm = Var_Subst(NULL, "${" MAKE_META_IGNORE_PATTERNS ":@m@${.p.:M$m}@}", gn, VARF_WANTRES); @@ -1192,7 +1192,7 @@ meta_oodate(GNode *gn, Boolean oodate) have_filemon = TRUE; continue; } - } + } /* Delimit the record type. */ p = buf; @@ -1242,11 +1242,11 @@ meta_oodate(GNode *gn, Boolean oodate) if (pid > 0 && pid != lastpid) { char *ldir; char *tp; - + if (lastpid > 0) { /* We need to remember these. */ - Var_Set(lcwd_vname, lcwd, VAR_GLOBAL, 0); - Var_Set(ldir_vname, latestdir, VAR_GLOBAL, 0); + Var_Set(lcwd_vname, lcwd, VAR_GLOBAL); + Var_Set(ldir_vname, latestdir, VAR_GLOBAL); } snprintf(lcwd_vname, sizeof(lcwd_vname), LCWD_VNAME_FMT, pid); snprintf(ldir_vname, sizeof(ldir_vname), LDIR_VNAME_FMT, pid); @@ -1292,9 +1292,9 @@ meta_oodate(GNode *gn, Boolean oodate) child = atoi(p); if (child > 0) { snprintf(cldir, sizeof(cldir), LCWD_VNAME_FMT, child); - Var_Set(cldir, lcwd, VAR_GLOBAL, 0); + Var_Set(cldir, lcwd, VAR_GLOBAL); snprintf(cldir, sizeof(cldir), LDIR_VNAME_FMT, child); - Var_Set(cldir, latestdir, VAR_GLOBAL, 0); + Var_Set(cldir, latestdir, VAR_GLOBAL); #ifdef DEBUG_META_MODE if (DEBUG(META)) fprintf(debug_file, "%s: %d: %d: cwd=%s lcwd=%s ldir=%s\n", @@ -1307,10 +1307,10 @@ meta_oodate(GNode *gn, Boolean oodate) case 'C': /* Chdir */ /* Update lcwd and latest directory. */ - strlcpy(latestdir, p, sizeof(latestdir)); + strlcpy(latestdir, p, sizeof(latestdir)); strlcpy(lcwd, p, sizeof(lcwd)); - Var_Set(lcwd_vname, lcwd, VAR_GLOBAL, 0); - Var_Set(ldir_vname, lcwd, VAR_GLOBAL, 0); + Var_Set(lcwd_vname, lcwd, VAR_GLOBAL); + Var_Set(ldir_vname, lcwd, VAR_GLOBAL); #ifdef DEBUG_META_MODE if (DEBUG(META)) fprintf(debug_file, "%s: %d: cwd=%s ldir=%s\n", fname, lineno, cwd, lcwd); @@ -1387,7 +1387,7 @@ meta_oodate(GNode *gn, Boolean oodate) /* * If a file we generated within our bailiwick * but outside of .OBJDIR is missing, - * we need to do it again. + * we need to do it again. */ /* ignore non-absolute paths */ if (*p != '/') @@ -1436,7 +1436,7 @@ meta_oodate(GNode *gn, Boolean oodate) */ if (meta_ignore(gn, p)) break; - + /* * The rest of the record is the file name. * Check if it's not an absolute path. @@ -1637,7 +1637,7 @@ meta_oodate(GNode *gn, Boolean oodate) * All we can sanely do is set it to .ALLSRC. */ Var_Delete(OODATE, gn); - Var_Set(OODATE, Var_Value(ALLSRC, gn, &cp), gn, 0); + Var_Set(OODATE, Var_Value(ALLSRC, gn, &cp), gn); free(cp); } @@ -1660,7 +1660,7 @@ meta_compat_start(void) * We need to re-open filemon for each cmd. */ BuildMon *pbm = &Mybm; - + if (pbm->mfp != NULL && useFilemon) { meta_open_filemon(pbm); } else { diff --git a/meta.h b/meta.h index 80c774f1a308..71c9bc9a9c2f 100644 --- a/meta.h +++ b/meta.h @@ -1,23 +1,23 @@ -/* $NetBSD: meta.h,v 1.6 2020/01/19 19:42:32 riastradh Exp $ */ +/* $NetBSD: meta.h,v 1.7 2020/07/03 08:13:23 rillig Exp $ */ /* * Things needed for 'meta' mode. */ /* * Copyright (c) 2009-2010, Juniper Networks, Inc. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * modification, are permitted provided that the following conditions + * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * documentation and/or other materials provided with the distribution. * 3. Neither the name of the copyright holders nor the names of its * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * + * from this software without specific prior written permission. + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -28,7 +28,7 @@ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ typedef struct BuildMon { diff --git a/nonints.h b/nonints.h index ae9869d6e8d6..3126650c9b59 100644 --- a/nonints.h +++ b/nonints.h @@ -1,4 +1,4 @@ -/* $NetBSD: nonints.h,v 1.75 2020/04/25 18:20:57 christos Exp $ */ +/* $NetBSD: nonints.h,v 1.78 2020/07/03 07:40:13 rillig Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -139,7 +139,7 @@ Lst Parse_MainName(void); char *str_concat(const char *, const char *, int); char **brk_string(const char *, int *, Boolean, char **); char *Str_FindSubstring(const char *, const char *); -int Str_Match(const char *, const char *); +Boolean Str_Match(const char *, const char *); char *Str_SYSVMatch(const char *, const char *, size_t *, Boolean *); void Str_SYSVSubst(Buffer *, char *, char *, size_t, Boolean); @@ -185,13 +185,20 @@ void Targ_Propagate(void); void Targ_Propagate_Wait(void); /* var.c */ + +typedef enum { + VARF_UNDEFERR = 1, + VARF_WANTRES = 2, + VARF_ASSIGN = 4 +} Varf_Flags; + void Var_Delete(const char *, GNode *); -void Var_Set(const char *, const char *, GNode *, int); +void Var_Set(const char *, const char *, GNode *); void Var_Append(const char *, const char *, GNode *); Boolean Var_Exists(const char *, GNode *); char *Var_Value(const char *, GNode *, char **); -char *Var_Parse(const char *, GNode *, int, int *, void **); -char *Var_Subst(const char *, const char *, GNode *, int); +char *Var_Parse(const char *, GNode *, Varf_Flags, int *, void **); +char *Var_Subst(const char *, const char *, GNode *, Varf_Flags); char *Var_GetTail(const char *); char *Var_GetHead(const char *); void Var_Init(void); diff --git a/parse.c b/parse.c index 146ce13c647e..348595824507 100644 --- a/parse.c +++ b/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.233 2019/09/26 21:09:55 sjg Exp $ */ +/* $NetBSD: parse.c,v 1.236 2020/07/03 08:13:23 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: parse.c,v 1.233 2019/09/26 21:09:55 sjg Exp $"; +static char rcsid[] = "$NetBSD: parse.c,v 1.236 2020/07/03 08:13:23 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: parse.c,v 1.233 2019/09/26 21:09:55 sjg Exp $"); +__RCSID("$NetBSD: parse.c,v 1.236 2020/07/03 08:13:23 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -657,14 +657,14 @@ ParseFindKeyword(const char *str) diff = strcmp(str, parseKeywords[cur].name); if (diff == 0) { - return (cur); + return cur; } else if (diff < 0) { end = cur - 1; } else { start = cur + 1; } } while (start <= end); - return (-1); + return -1; } /*- @@ -889,7 +889,7 @@ ParseLinkSrc(void *pgnp, void *cgnp) Targ_PrintNode(pgn, 0); Targ_PrintNode(cgn, 0); } - return (0); + return 0; } /*- @@ -926,7 +926,7 @@ ParseDoOp(void *gnp, void *opp) !OP_NOP(gn->type) && !OP_NOP(op)) { Parse_Error(PARSE_FATAL, "Inconsistent operator for %s", gn->name); - return (1); + return 1; } if ((op == OP_DOUBLEDEP) && ((gn->type & OP_OPMASK) == OP_DOUBLEDEP)) { @@ -970,7 +970,7 @@ ParseDoOp(void *gnp, void *opp) gn->type |= op; } - return (0); + return 0; } /*- @@ -1146,7 +1146,7 @@ static int ParseAddDir(void *path, void *name) { (void)Dir_AddDir((Lst) path, (char *)name); - return(0); + return 0; } /*- @@ -1605,7 +1605,7 @@ ParseDoDependency(char *line) break; #ifdef POSIX case Posix: - Var_Set("%POSIX", "1003.2", VAR_GLOBAL, 0); + Var_Set("%POSIX", "1003.2", VAR_GLOBAL); break; #endif default: @@ -1980,13 +1980,13 @@ Parse_DoVar(char *line, GNode *ctxt) * so that it gets substituted! */ if (!Var_Exists(line, ctxt)) - Var_Set(line, "", ctxt, 0); + Var_Set(line, "", ctxt); cp = Var_Subst(NULL, cp, ctxt, VARF_WANTRES|VARF_ASSIGN); oldVars = oldOldVars; freeCp = TRUE; - Var_Set(line, cp, ctxt, 0); + Var_Set(line, cp, ctxt); } else if (type == VAR_SHELL) { char *res; const char *error; @@ -2002,7 +2002,7 @@ Parse_DoVar(char *line, GNode *ctxt) } res = Cmd_Exec(cp, &error); - Var_Set(line, res, ctxt, 0); + Var_Set(line, res, ctxt); free(res); if (error) @@ -2011,7 +2011,7 @@ Parse_DoVar(char *line, GNode *ctxt) /* * Normal assignment -- just do it. */ - Var_Set(line, cp, ctxt, 0); + Var_Set(line, cp, ctxt); } if (strcmp(line, MAKEOVERRIDES) == 0) Main_ExportMAKEFLAGS(FALSE); /* re-export MAKEFLAGS */ @@ -2115,7 +2115,7 @@ ParseAddCmd(void *gnp, void *cmd) gn->name); #endif } - return(0); + return 0; } /*- @@ -2367,9 +2367,9 @@ ParseSetIncludedFile(void) char *pd, *dp = NULL; pf = Var_Value(".PARSEFILE", VAR_GLOBAL, &fp); - Var_Set(".INCLUDEDFROMFILE", pf, VAR_GLOBAL, 0); + Var_Set(".INCLUDEDFROMFILE", pf, VAR_GLOBAL); pd = Var_Value(".PARSEDIR", VAR_GLOBAL, &dp); - Var_Set(".INCLUDEDFROMDIR", pd, VAR_GLOBAL, 0); + Var_Set(".INCLUDEDFROMDIR", pd, VAR_GLOBAL); if (DEBUG(PARSE)) fprintf(debug_file, "%s: ${.INCLUDEDFROMDIR} = `%s' " @@ -2401,16 +2401,16 @@ ParseSetParseFile(const char *filename) slash = strrchr(filename, '/'); if (slash == NULL) { - Var_Set(".PARSEDIR", pd = curdir, VAR_GLOBAL, 0); - Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL, 0); + Var_Set(".PARSEDIR", pd = curdir, VAR_GLOBAL); + Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL); dirname= NULL; } else { len = slash - filename; dirname = bmake_malloc(len + 1); memcpy(dirname, filename, len); dirname[len] = '\0'; - Var_Set(".PARSEDIR", pd = dirname, VAR_GLOBAL, 0); - Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL, 0); + Var_Set(".PARSEDIR", pd = dirname, VAR_GLOBAL); + Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL); } if (DEBUG(PARSE)) fprintf(debug_file, "%s: ${.PARSEDIR} = `%s' ${.PARSEFILE} = `%s'\n", @@ -2431,7 +2431,7 @@ ParseTrackInput(const char *name) char *ep; char *fp = NULL; size_t name_len = strlen(name); - + old = Var_Value(MAKE_MAKEFILES, VAR_GLOBAL, &fp); if (old) { ep = old + strlen(old) - name_len; @@ -2772,7 +2772,7 @@ ParseEOF(void) /* Restore the PARSEDIR/PARSEFILE variables */ ParseSetParseFile(curFile->fname); - return (CONTINUE); + return CONTINUE; } #define PARSE_RAW 1 @@ -3009,7 +3009,7 @@ ParseReadLine(void) /* Read next line from for-loop buffer */ continue; } - return (line); + return line; } } @@ -3119,7 +3119,7 @@ Parse_File(const char *name, int fd) strncmp(cp, "warning", 7) == 0) { if (ParseMessage(cp)) continue; - } + } } if (*line == '\t') { @@ -3350,7 +3350,7 @@ Parse_MainName(void) else (void)Lst_AtEnd(mainList, mainNode); Var_Append(".TARGETS", mainNode->name, VAR_GLOBAL); - return (mainList); + return mainList; } /*- diff --git a/str.c b/str.c index bc0108a84d2c..c3138b67b95b 100644 --- a/str.c +++ b/str.c @@ -1,4 +1,4 @@ -/* $NetBSD: str.c,v 1.48 2020/06/15 14:46:28 rillig Exp $ */ +/* $NetBSD: str.c,v 1.51 2020/07/03 07:40:13 rillig Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: str.c,v 1.48 2020/06/15 14:46:28 rillig Exp $"; +static char rcsid[] = "$NetBSD: str.c,v 1.51 2020/07/03 07:40:13 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90"; #else -__RCSID("$NetBSD: str.c,v 1.48 2020/06/15 14:46:28 rillig Exp $"); +__RCSID("$NetBSD: str.c,v 1.51 2020/07/03 07:40:13 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -320,123 +320,110 @@ Str_FindSubstring(const char *string, const char *substring) } /* - * Str_Match -- - * - * See if a particular string matches a particular pattern. - * - * Results: Non-zero is returned if string matches pattern, 0 otherwise. The - * matching operation permits the following special characters in the - * pattern: *?\[] (see the man page for details on what these mean). + * Str_Match -- Test if a string matches a pattern like "*.[ch]". * * XXX this function does not detect or report malformed patterns. * + * Results: + * Non-zero is returned if string matches the pattern, 0 otherwise. The + * matching operation permits the following special characters in the + * pattern: *?\[] (as in fnmatch(3)). + * * Side effects: None. */ -int -Str_Match(const char *string, const char *pattern) +Boolean +Str_Match(const char *str, const char *pat) { - char c2; - for (;;) { /* * See if we're at the end of both the pattern and the * string. If, we succeeded. If we're at the end of the * pattern but not at the end of the string, we failed. */ - if (*pattern == 0) - return !*string; - if (*string == 0 && *pattern != '*') - return 0; - /* - * Check for a "*" as the next pattern character. It matches - * any substring. We handle this by calling ourselves - * recursively for each postfix of string, until either we - * match or we reach the end of the string. - */ - if (*pattern == '*') { - pattern++; - while (*pattern == '*') - pattern++; - if (*pattern == 0) - return 1; - while (*string != 0) { - if (Str_Match(string, pattern)) - return 1; - ++string; - } - return 0; - } - /* - * Check for a "?" as the next pattern character. It matches - * any single character. - */ - if (*pattern == '?') - goto thisCharOK; - /* - * Check for a "[" as the next pattern character. It is - * followed by a list of characters that are acceptable, or - * by a range (two characters separated by "-"). - */ - if (*pattern == '[') { - int nomatch; + if (*pat == 0) + return *str == 0; + if (*str == 0 && *pat != '*') + return FALSE; - ++pattern; - if (*pattern == '^') { - ++pattern; - nomatch = 1; - } else - nomatch = 0; - for (;;) { - if ((*pattern == ']') || (*pattern == 0)) { - if (nomatch) - break; - return 0; - } - if (*pattern == *string) - break; - if (pattern[1] == '-') { - c2 = pattern[2]; - if (c2 == 0) - return nomatch; - if ((*pattern <= *string) && - (c2 >= *string)) - break; - if ((*pattern >= *string) && - (c2 <= *string)) - break; - pattern += 2; - } - ++pattern; + /* + * A '*' in the pattern matches any substring. We handle this + * by calling ourselves for each suffix of the string. + */ + if (*pat == '*') { + pat++; + while (*pat == '*') + pat++; + if (*pat == 0) + return TRUE; + while (*str != 0) { + if (Str_Match(str, pat)) + return TRUE; + str++; } - if (nomatch && (*pattern != ']') && (*pattern != 0)) - return 0; - while ((*pattern != ']') && (*pattern != 0)) - ++pattern; - if (*pattern == 0) - --pattern; + return FALSE; + } + + /* A '?' in the pattern matches any single character. */ + if (*pat == '?') + goto thisCharOK; + + /* + * A '[' in the pattern matches a character from a list. + * The '[' is followed by the list of acceptable characters, + * or by ranges (two characters separated by '-'). In these + * character lists, the backslash is an ordinary character. + */ + if (*pat == '[') { + Boolean neg = pat[1] == '^'; + pat += 1 + neg; + + for (;;) { + if (*pat == ']' || *pat == 0) { + if (neg) + break; + return FALSE; + } + if (*pat == *str) + break; + if (pat[1] == '-') { + if (pat[2] == 0) + return neg; + if (*pat <= *str && pat[2] >= *str) + break; + if (*pat >= *str && pat[2] <= *str) + break; + pat += 2; + } + pat++; + } + if (neg && *pat != ']' && *pat != 0) + return FALSE; + while (*pat != ']' && *pat != 0) + pat++; + if (*pat == 0) + pat--; goto thisCharOK; } + /* - * If the next pattern character is a backslash, just strip it - * off so we do exact matching on the character that follows. + * A backslash in the pattern matches the character following + * it exactly. */ - if (*pattern == '\\') { - ++pattern; - if (*pattern == 0) - return 0; + if (*pat == '\\') { + pat++; + if (*pat == 0) + return FALSE; } - /* - * There's no special character. Just make sure that the - * next characters of each string match. - */ - if (*pattern != *string) - return 0; -thisCharOK: ++pattern; - ++string; + + if (*pat != *str) + return FALSE; + + thisCharOK: + pat++; + str++; } } - /*- *----------------------------------------------------------------------- * Str_SYSVMatch -- diff --git a/suff.c b/suff.c index df0306af131e..5a40b73d788d 100644 --- a/suff.c +++ b/suff.c @@ -1,4 +1,4 @@ -/* $NetBSD: suff.c,v 1.86 2017/04/16 20:38:18 riastradh Exp $ */ +/* $NetBSD: suff.c,v 1.88 2020/07/03 08:02:55 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: suff.c,v 1.86 2017/04/16 20:38:18 riastradh Exp $"; +static char rcsid[] = "$NetBSD: suff.c,v 1.88 2020/07/03 08:02:55 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; #else -__RCSID("$NetBSD: suff.c,v 1.86 2017/04/16 20:38:18 riastradh Exp $"); +__RCSID("$NetBSD: suff.c,v 1.88 2020/07/03 08:02:55 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -266,7 +266,7 @@ SuffStrIsPrefix(const char *pref, const char *str) str++; } - return (*pref ? NULL : str); + return *pref ? NULL : str; } /*- @@ -304,7 +304,7 @@ SuffSuffIsSuffix(const Suff *s, const SuffixCmpData *sd) p2--; } - return (p1 == s->name - 1 ? p2 : NULL); + return p1 == s->name - 1 ? p2 : NULL; } /*- @@ -324,7 +324,7 @@ SuffSuffIsSuffix(const Suff *s, const SuffixCmpData *sd) static int SuffSuffIsSuffixP(const void *s, const void *sd) { - return(!SuffSuffIsSuffix(s, sd)); + return !SuffSuffIsSuffix(s, sd); } /*- @@ -347,7 +347,7 @@ SuffSuffIsSuffixP(const void *s, const void *sd) static int SuffSuffHasNameP(const void *s, const void *sname) { - return (strcmp(sname, ((const Suff *)s)->name)); + return strcmp(sname, ((const Suff *)s)->name); } /*- @@ -394,7 +394,7 @@ SuffSuffIsPrefix(const void *s, const void *str) static int SuffGNHasNameP(const void *gn, const void *name) { - return (strcmp(name, ((const GNode *)gn)->name)); + return strcmp(name, ((const GNode *)gn)->name); } /*********** Maintenance Functions ************/ @@ -632,9 +632,9 @@ SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr) */ *srcPtr = single; *targPtr = suffNull; - return(TRUE); + return TRUE; } - return (FALSE); + return FALSE; } src = (Suff *)Lst_Datum(srcLn); str2 = str + src->nameLen; @@ -646,7 +646,7 @@ SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr) if (targLn != NULL) { *srcPtr = src; *targPtr = (Suff *)Lst_Datum(targLn); - return (TRUE); + return TRUE; } } } @@ -674,7 +674,7 @@ Suff_IsTransform(char *str) { Suff *src, *targ; - return (SuffParseTransform(str, &src, &targ)); + return SuffParseTransform(str, &src, &targ); } /*- @@ -738,7 +738,7 @@ Suff_AddTransform(char *line) SuffInsert(t->children, s); SuffInsert(s->parents, t); - return (gn); + return gn; } /*- @@ -860,7 +860,7 @@ SuffRebuildGraph(void *transformp, void *sp) s2 = (Suff *)Lst_Datum(ln); SuffInsert(s2->children, s); SuffInsert(s->parents, s2); - return(0); + return 0; } } @@ -889,7 +889,7 @@ SuffRebuildGraph(void *transformp, void *sp) SuffInsert(s2->parents, s); } } - return(0); + return 0; } /*- @@ -1035,7 +1035,7 @@ Suff_GetPath(char *sname) return NULL; } else { s = (Suff *)Lst_Datum(ln); - return (s->searchPath); + return s->searchPath; } } @@ -1093,9 +1093,9 @@ Suff_DoPaths(void) } } - Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL, 0); + Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL); free(ptr); - Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", inLibs), VAR_GLOBAL, 0); + Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", inLibs), VAR_GLOBAL); free(ptr); Lst_Destroy(inIncludes, Dir_Destroy); @@ -1239,7 +1239,7 @@ SuffAddSrc(void *sp, void *lsp) fprintf(debug_file, "\n"); #endif - return(0); + return 0; } /*- @@ -1399,7 +1399,7 @@ SuffFindThem(Lst srcs, Lst slst) if (DEBUG(SUFF) && rs) { fprintf(debug_file, "got it\n"); } - return (rs); + return rs; } /*- @@ -1505,7 +1505,7 @@ SuffFindCmds(Src *targ, Lst slst) if (DEBUG(SUFF)) { fprintf(debug_file, "\tusing existing source %s\n", s->name); } - return (ret); + return ret; } /*- @@ -1831,7 +1831,7 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s) * called to link an OP_MEMBER and OP_ARCHV node), so return * FALSE. */ - return(FALSE); + return FALSE; } gn = (GNode *)Lst_Datum(ln); @@ -1864,7 +1864,7 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s) */ (void)Lst_AtEnd(sGn->iParents, tGn); - return(TRUE); + return TRUE; } @@ -1941,7 +1941,7 @@ SuffFindArchiveDeps(GNode *gn, Lst slst) */ for (i = (sizeof(copy)/sizeof(copy[0]))-1; i >= 0; i--) { char *p1; - Var_Set(copy[i], Var_Value(copy[i], mem, &p1), gn, 0); + Var_Set(copy[i], Var_Value(copy[i], mem, &p1), gn); free(p1); } @@ -1961,13 +1961,13 @@ SuffFindArchiveDeps(GNode *gn, Lst slst) /* * Set the other two local variables required for this target. */ - Var_Set(MEMBER, name, gn, 0); - Var_Set(ARCHIVE, gn->name, gn, 0); + Var_Set(MEMBER, name, gn); + Var_Set(ARCHIVE, gn->name, gn); /* * Set $@ for compatibility with other makes */ - Var_Set(TARGET, gn->name, gn, 0); + Var_Set(TARGET, gn->name, gn); /* * Now we've got the important local variables set, expand any sources @@ -2213,10 +2213,10 @@ SuffFindNormalDeps(GNode *gn, Lst slst) } } - Var_Set(TARGET, gn->path ? gn->path : gn->name, gn, 0); + Var_Set(TARGET, gn->path ? gn->path : gn->name, gn); pref = (targ != NULL) ? targ->pref : gn->name; - Var_Set(PREFIX, pref, gn, 0); + Var_Set(PREFIX, pref, gn); /* * Now we've got the important local variables set, expand any sources @@ -2246,7 +2246,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst) targ->suff->searchPath)); if (gn->path != NULL) { char *ptr; - Var_Set(TARGET, gn->path, gn, 0); + Var_Set(TARGET, gn->path, gn); if (targ != NULL) { /* @@ -2269,7 +2269,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst) else ptr = gn->path; - Var_Set(PREFIX, ptr, gn, 0); + Var_Set(PREFIX, ptr, gn); gn->path[savep] = savec; } else { @@ -2286,7 +2286,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst) else ptr = gn->path; - Var_Set(PREFIX, ptr, gn, 0); + Var_Set(PREFIX, ptr, gn); } } } @@ -2373,9 +2373,9 @@ SuffFindNormalDeps(GNode *gn, Lst slst) */ targ->node->type |= OP_DEPS_FOUND; - Var_Set(PREFIX, targ->pref, targ->node, 0); + Var_Set(PREFIX, targ->pref, targ->node); - Var_Set(TARGET, targ->node->name, targ->node, 0); + Var_Set(TARGET, targ->node->name, targ->node); } } @@ -2458,8 +2458,8 @@ SuffFindDeps(GNode *gn, Lst slst) /* * Make sure we have these set, may get revised below. */ - Var_Set(TARGET, gn->path ? gn->path : gn->name, gn, 0); - Var_Set(PREFIX, gn->name, gn, 0); + Var_Set(TARGET, gn->path ? gn->path : gn->name, gn); + Var_Set(PREFIX, gn->name, gn); if (DEBUG(SUFF)) { fprintf(debug_file, "SuffFindDeps (%s)\n", gn->name); @@ -2488,14 +2488,14 @@ SuffFindDeps(GNode *gn, Lst slst) Arch_FindLib(gn, s->searchPath); } else { gn->suffix = NULL; - Var_Set(TARGET, gn->name, gn, 0); + Var_Set(TARGET, gn->name, gn); } /* * Because a library (-lfoo) target doesn't follow the standard * filesystem conventions, we don't set the regular variables for * the thing. .PREFIX is simply made empty... */ - Var_Set(PREFIX, "", gn, 0); + Var_Set(PREFIX, "", gn); } else { SuffFindNormalDeps(gn, slst); } diff --git a/targ.c b/targ.c index 01c3d1c5ecdf..15dc01f0e08d 100644 --- a/targ.c +++ b/targ.c @@ -1,4 +1,4 @@ -/* $NetBSD: targ.c,v 1.62 2017/04/16 19:53:58 riastradh Exp $ */ +/* $NetBSD: targ.c,v 1.63 2020/07/03 08:02:55 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: targ.c,v 1.62 2017/04/16 19:53:58 riastradh Exp $"; +static char rcsid[] = "$NetBSD: targ.c,v 1.63 2020/07/03 08:02:55 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: targ.c,v 1.62 2017/04/16 19:53:58 riastradh Exp $"); +__RCSID("$NetBSD: targ.c,v 1.63 2020/07/03 08:02:55 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -269,7 +269,7 @@ Targ_NewGN(const char *name) Lst_AtEnd(allGNs, gn); #endif - return (gn); + return gn; } #ifdef CLEANUP @@ -389,7 +389,7 @@ Targ_FindList(Lst names, int flags) nodes = Lst_Init(FALSE); if (Lst_Open(names) == FAILURE) { - return (nodes); + return nodes; } while ((ln = Lst_Next(names)) != NULL) { name = (char *)Lst_Datum(ln); @@ -406,7 +406,7 @@ Targ_FindList(Lst names, int flags) } } Lst_Close(names); - return (nodes); + return nodes; } /*- @@ -428,9 +428,9 @@ Boolean Targ_Ignore(GNode *gn) { if (ignoreErrors || gn->type & OP_IGNORE) { - return (TRUE); + return TRUE; } else { - return (FALSE); + return FALSE; } } @@ -453,9 +453,9 @@ Boolean Targ_Silent(GNode *gn) { if (beSilent || gn->type & OP_SILENT) { - return (TRUE); + return TRUE; } else { - return (FALSE); + return FALSE; } } @@ -478,9 +478,9 @@ Boolean Targ_Precious(GNode *gn) { if (allPrecious || (gn->type & (OP_PRECIOUS|OP_DOUBLEDEP))) { - return (TRUE); + return TRUE; } else { - return (FALSE); + return FALSE; } } @@ -549,7 +549,7 @@ Targ_FmtTime(time_t tm) parts = localtime(&tm); (void)strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts); - return(buf); + return buf; } /*- @@ -698,7 +698,7 @@ Targ_PrintNode(void *gnp, void *passp) Lst_ForEach(gn->cohorts, Targ_PrintNode, &pass); } } - return (0); + return 0; } /*- @@ -794,7 +794,7 @@ TargPropagateNode(void *gnp, void *junk MAKE_ATTR_UNUSED) if (gn->type & OP_DOUBLEDEP) Lst_ForEach(gn->cohorts, TargPropagateCohort, gnp); - return (0); + return 0; } /*- @@ -822,7 +822,7 @@ TargPropagateCohort(void *cgnp, void *pgnp) GNode *pgn = (GNode *)pgnp; cgn->type |= pgn->type & ~OP_OPMASK; - return (0); + return 0; } /*- diff --git a/trace.c b/trace.c index 267177ff5618..3ef210f02a8c 100644 --- a/trace.c +++ b/trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: trace.c,v 1.11 2008/12/28 18:31:51 christos Exp $ */ +/* $NetBSD: trace.c,v 1.12 2020/07/03 08:13:23 rillig Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -31,11 +31,11 @@ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: trace.c,v 1.11 2008/12/28 18:31:51 christos Exp $"; +static char rcsid[] = "$NetBSD: trace.c,v 1.12 2020/07/03 08:13:23 rillig Exp $"; #else #include #ifndef lint -__RCSID("$NetBSD: trace.c,v 1.11 2008/12/28 18:31:51 christos Exp $"); +__RCSID("$NetBSD: trace.c,v 1.12 2020/07/03 08:13:23 rillig Exp $"); #endif /* not lint */ #endif @@ -90,7 +90,7 @@ void Trace_Log(TrEvent event, Job *job) { struct timeval rightnow; - + if (trfile == NULL) return; diff --git a/unit-tests/Makefile b/unit-tests/Makefile index 5c429c9648b9..0f85d9ef8dfb 100644 --- a/unit-tests/Makefile +++ b/unit-tests/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.55 2020/06/29 14:47:56 sjg Exp $ +# $Id: Makefile,v 1.58 2020/07/04 22:33:00 sjg Exp $ # # $NetBSD: Makefile,v 1.59 2020/06/28 09:42:40 rillig Exp $ # @@ -105,6 +105,9 @@ LANG= C SED_CMDS.varshell = -e 's,^[a-z]*sh: ,,' \ -e '/command/s,No such.*,not found,' +# the detailed error message can vary across systems +SED_CMDS.modmisc = -e 's,\(substitution error:\).*,\1 details omitted,' + # the tests are actually done with sub-makes. .SUFFIXES: .mk .rawout .out .mk.rawout: diff --git a/unit-tests/cond-short.exp b/unit-tests/cond-short.exp index d8e3861d0c61..0c8c47a449fe 100644 --- a/unit-tests/cond-short.exp +++ b/unit-tests/cond-short.exp @@ -1,6 +1,9 @@ expected and expected and exists expected and empty +expected U23 condition +expected VAR23 +expected M pattern expected or expected or exists expected or empty diff --git a/unit-tests/cond-short.mk b/unit-tests/cond-short.mk index 45bd45bfe3ba..9ff5f54b715c 100644 --- a/unit-tests/cond-short.mk +++ b/unit-tests/cond-short.mk @@ -1,4 +1,4 @@ -# $NetBSD: cond-short.mk,v 1.2 2020/06/28 11:06:26 rillig Exp $ +# $NetBSD: cond-short.mk,v 1.6 2020/07/02 16:37:56 rillig Exp $ # # Demonstrates that in conditions, the right-hand side of an && or || # is only evaluated if it can actually influence the result. @@ -27,6 +27,45 @@ .if 1 && empty(${echo "expected and empty" 1>&2 :L:sh}) .endif +# "VAR U11" is not evaluated; it was evaluated before 2020-07-02. +# The whole !empty condition is only parsed and then discarded. +VAR= ${VAR${:U11${echo "unexpected VAR U11" 1>&2 :L:sh}}} +VAR13= ${VAR${:U12${echo "unexpected VAR13" 1>&2 :L:sh}}} +.if 0 && !empty(VAR${:U13${echo "unexpected U13 condition" 1>&2 :L:sh}}) +.endif + +VAR= ${VAR${:U21${echo "unexpected VAR U21" 1>&2 :L:sh}}} +VAR23= ${VAR${:U22${echo "expected VAR23" 1>&2 :L:sh}}} +.if 1 && !empty(VAR${:U23${echo "expected U23 condition" 1>&2 :L:sh}}) +.endif +VAR= # empty again, for the following tests + +# The :M modifier is only parsed, not evaluated. +# Before 2020-07-02, it was wrongly evaluated. +.if 0 && !empty(VAR:M${:U${echo "unexpected M pattern" 1>&2 :L:sh}}) +.endif + +.if 1 && !empty(VAR:M${:U${echo "expected M pattern" 1>&2 :L:sh}}) +.endif + +.if 0 && !empty(VAR:S,from,${:U${echo "unexpected S modifier" 1>&2 :L:sh}},) +.endif + +.if 0 && !empty(VAR:C,from,${:U${echo "unexpected C modifier" 1>&2 :L:sh}},) +.endif + +.if 0 && !empty("" == "" :? ${:U${echo "unexpected ? modifier" 1>&2 :L:sh}} :) +.endif + +.if 0 && !empty(VAR:old=${:U${echo "unexpected = modifier" 1>&2 :L:sh}}) +.endif + +.if 0 && !empty(1 2 3:L:@var@${:U${echo "unexpected @ modifier" 1>&2 :L:sh}}@) +.endif + +.if 0 && !empty(:U${:!echo "unexpected exclam modifier" 1>&2 !}) +.endif + # The || operator. .if 1 || ${echo "unexpected or" 1>&2 :L:sh} diff --git a/unit-tests/modmisc.exp b/unit-tests/modmisc.exp index e406647bc41f..fbe4edeab8b4 100644 --- a/unit-tests/modmisc.exp +++ b/unit-tests/modmisc.exp @@ -7,4 +7,29 @@ path_/usr/xbin=/opt/xbin/ paths=/bin /tmp / /no/such/dir /opt/xbin PATHS=/BIN /TMP / /NO/SUCH/DIR /OPT/XBIN The answer is 42 +dirname of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'a/b . . a.b . . . . .' +basename of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'c def a.b.c c a a.a .gitignore a a.a' +suffix of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'c b/c a gitignore a' +root of 'a/b/c def a.b.c a.b/c a a.a .gitignore a a.a' is 'a/b/c def a.b a a a a a' +S: +C: +@: +S:empty +C:empty +@: +:a b b c: +:a b b c: +: b c: +:a c: +:x__ 3 x__ 3: +:a b b c: +:a b b c: +: b c: +make: RE substitution error: details omitted +make: Unclosed substitution for (, missing) +:C,word,____,:Q}: +:a c: +:x__ 3 x__ 3: +:+one+ +two+ +three+: +mod-at-resolve:w1d2d3w w2i3w w1i2d3 2i${RES3}w w1d2d3 2i${RES3} 1i${RES2}w: exit status 0 diff --git a/unit-tests/modmisc.mk b/unit-tests/modmisc.mk index 043498fb1af4..8c20304ba1ef 100644 --- a/unit-tests/modmisc.mk +++ b/unit-tests/modmisc.mk @@ -1,4 +1,4 @@ -# $Id: modmisc.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $ +# $Id: modmisc.mk,v 1.1.1.2 2020/07/04 17:52:46 sjg Exp $ # # miscellaneous modifier tests @@ -15,7 +15,8 @@ MOD_HOMES=S,/home/,/homes/, MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@ MOD_SEP=S,:, ,g -all: modvar modvarloop modsysv +all: modvar modvarloop modsysv mod-HTE emptyvar undefvar +all: mod-S mod-C mod-at-varname mod-at-resolve modsysv: @echo "The answer is ${libfoo.a:L:libfoo.a=42}" @@ -36,3 +37,59 @@ modvarloop: @echo "path_/usr/xbin=${path_/usr/xbin}" @echo "paths=${paths}" @echo "PATHS=${paths:tu}" + +PATHNAMES= a/b/c def a.b.c a.b/c a a.a .gitignore a a.a +mod-HTE: + @echo "dirname of '"${PATHNAMES:Q}"' is '"${PATHNAMES:H:Q}"'" + @echo "basename of '"${PATHNAMES:Q}"' is '"${PATHNAMES:T:Q}"'" + @echo "suffix of '"${PATHNAMES:Q}"' is '"${PATHNAMES:E:Q}"'" + @echo "root of '"${PATHNAMES:Q}"' is '"${PATHNAMES:R:Q}"'" + +# When a modifier is applied to the "" variable, the result is discarded. +emptyvar: + @echo S:${:S,^$,empty,} + @echo C:${:C,^$,empty,} + @echo @:${:@var@${var}@} + +# The :U modifier turns even the "" variable into something that has a value. +# The resulting variable is empty, but is still considered to contain a +# single empty word. This word can be accessed by the :S and :C modifiers, +# but not by the :@ modifier since it explicitly skips empty words. +undefvar: + @echo S:${:U:S,^$,empty,} + @echo C:${:U:C,^$,empty,} + @echo @:${:U:@var@empty@} + +mod-S: + @echo :${:Ua b b c:S,a b,,:Q}: + @echo :${:Ua b b c:S,a b,,1:Q}: + @echo :${:Ua b b c:S,a b,,W:Q}: + @echo :${:Ua b b c:S,b,,g:Q}: + @echo :${:U1 2 3 1 2 3:S,1 2,___,Wg:S,_,x,:Q}: + +mod-C: + @echo :${:Ua b b c:C,a b,,:Q}: + @echo :${:Ua b b c:C,a b,,1:Q}: + @echo :${:Ua b b c:C,a b,,W:Q}: + @echo :${:Uword1 word2:C,****,____,g:C,word,____,:Q}: + @echo :${:Ua b b c:C,b,,g:Q}: + @echo :${:U1 2 3 1 2 3:C,1 2,___,Wg:C,_,x,:Q}: + +# In the :@ modifier, the name of the loop variable can even be generated +# dynamically. There's no practical use-case for this, and hopefully nobody +# will ever depend on this, but technically it's possible. +mod-at-varname: + @echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}: + +# The :@ modifier resolves the variables a little more often than expected. +# In particular, it resolves _all_ variables from the context, and not only +# the loop variable (in this case v). +# +# The d means direct reference, the i means indirect reference. +RESOLVE= ${RES1} $${RES1} +RES1= 1d${RES2} 1i$${RES2} +RES2= 2d${RES3} 2i$${RES3} +RES3= 3 + +mod-at-resolve: + @echo $@:${RESOLVE:@v@w${v}w@:Q}: diff --git a/unit-tests/sysv.exp b/unit-tests/sysv.exp index 610f97c39e85..780a187783f3 100644 --- a/unit-tests/sysv.exp +++ b/unit-tests/sysv.exp @@ -12,4 +12,5 @@ asam.c.c asam.c a.c.c +ax:Q b c d eb exit status 0 diff --git a/unit-tests/sysv.mk b/unit-tests/sysv.mk index 2bd128eb7130..3a987441ee42 100644 --- a/unit-tests/sysv.mk +++ b/unit-tests/sysv.mk @@ -1,4 +1,4 @@ -# $Id: sysv.mk,v 1.4 2020/05/07 01:17:51 sjg Exp $ +# $Id: sysv.mk,v 1.5 2020/07/04 18:16:55 sjg Exp $ FOO ?= FOOBAR = ${FOO:=bar} @@ -11,7 +11,7 @@ FUN = ${B}${S}fun SUN = the Sun # we expect nothing when FOO is empty -all: foo fun sam bla +all: foo fun sam bla words foo: @echo FOOBAR = ${FOOBAR} @@ -41,3 +41,8 @@ BLA= bla: @echo $(BLA:%=foo/%x) + +# The :Q looks like a modifier but isn't. +# It is part of the replacement string. +words: + @echo a${a b c d e:L:%a=x:Q}b diff --git a/unit-tests/varmisc.exp b/unit-tests/varmisc.exp index ffe8f8b867c8..b9a29141ce6b 100644 --- a/unit-tests/varmisc.exp +++ b/unit-tests/varmisc.exp @@ -22,4 +22,5 @@ date=20160401 Version=123.456.789 == 123456789 Literal=3.4.5 == 3004005 We have target specific vars +MAN= make.1 exit status 0 diff --git a/unit-tests/varmisc.mk b/unit-tests/varmisc.mk index a0b8f2dc84f4..ab591db5c4fd 100644 --- a/unit-tests/varmisc.mk +++ b/unit-tests/varmisc.mk @@ -1,9 +1,9 @@ -# $Id: varmisc.mk,v 1.9 2017/02/01 18:44:54 sjg Exp $ +# $Id: varmisc.mk,v 1.11 2020/07/02 15:43:43 sjg Exp $ # # Miscellaneous variable tests. all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \ - strftime cmpv + strftime cmpv manok unmatched_var_paren: @echo ${foo::=foo-text} @@ -60,3 +60,25 @@ cmpv: @echo Version=${Version} == ${Version:${M_cmpv}} @echo Literal=3.4.5 == ${3.4.5:L:${M_cmpv}} @echo We have ${${.TARGET:T}.only} + +# catch misshandling of nested vars in .for loop +MAN= +MAN1= make.1 +.for s in 1 2 +.if defined(MAN$s) && !empty(MAN$s) +MAN+= ${MAN$s} +.endif +.endfor + +manok: + @echo MAN=${MAN} + +# This is an expanded variant of the above .for loop. +# Between 2020-08-28 and 2020-07-02 this paragraph generated a wrong +# error message "Variable VARNAME is recursive". +# When evaluating the !empty expression, the ${:U1} was not expanded and +# thus resulted in the seeming definition VARNAME=${VARNAME}, which is +# obviously recursive. +VARNAME= ${VARNAME${:U1}} +.if defined(VARNAME${:U2}) && !empty(VARNAME${:U2}) +.endif diff --git a/util.c b/util.c index 31d2b9a06080..d674a6c21aac 100644 --- a/util.c +++ b/util.c @@ -1,9 +1,9 @@ -/* $NetBSD: util.c,v 1.55 2020/01/07 21:24:16 rillig Exp $ */ +/* $NetBSD: util.c,v 1.57 2020/07/03 08:13:23 rillig Exp $ */ /* * Missing stuff from OS's * - * $Id: util.c,v 1.34 2020/01/22 01:19:25 sjg Exp $ + * $Id: util.c,v 1.35 2020/07/04 18:16:55 sjg Exp $ */ #if defined(__MINT__) || defined(__linux__) #include @@ -12,10 +12,10 @@ #include "make.h" #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: util.c,v 1.55 2020/01/07 21:24:16 rillig Exp $"; +static char rcsid[] = "$NetBSD: util.c,v 1.57 2020/07/03 08:13:23 rillig Exp $"; #else #ifndef lint -__RCSID("$NetBSD: util.c,v 1.55 2020/01/07 21:24:16 rillig Exp $"); +__RCSID("$NetBSD: util.c,v 1.57 2020/07/03 08:13:23 rillig Exp $"); #endif #endif @@ -68,7 +68,7 @@ getenv(const char *name) { int offset; - return(findenv(name, &offset)); + return findenv(name, &offset); } int @@ -173,7 +173,7 @@ strrcpy(char *ptr, char *str) while (len) *--ptr = str[--len]; - return (ptr); + return ptr; } /* end strrcpy */ @@ -276,7 +276,7 @@ getwd(char *pathname) if (st_cur.st_ino == st_root.st_ino && DEV_DEV_COMPARE(st_cur.st_dev, st_root.st_dev)) { (void)strcpy(pathname, *pathptr != '/' ? "/" : pathptr); - return (pathname); + return pathname; } /* open the parent directory */ @@ -399,7 +399,7 @@ vsnprintf(char *s, size_t n, const char *fmt, va_list args) putc('\0', &fakebuf); if (fakebuf._cnt<0) fakebuf._cnt = 0; - return (n-fakebuf._cnt-1); + return n-fakebuf._cnt-1; #else #ifndef _PATH_DEVNULL # define _PATH_DEVNULL "/dev/null" @@ -442,7 +442,7 @@ size_t strftime(char *buf, size_t len, const char *fmt, const struct tm *tm) { static char months[][4] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; diff --git a/var.c b/var.c index 441aae9c9371..c7e6b1b34fd4 100644 --- a/var.c +++ b/var.c @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $ */ +/* $NetBSD: var.c,v 1.255 2020/07/04 17:41:04 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.255 2020/07/04 17:41:04 rillig Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $"); +__RCSID("$NetBSD: var.c,v 1.255 2020/07/04 17:41:04 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -102,11 +102,9 @@ __RCSID("$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $"); * Var_Value Return the value of a variable in a context or * NULL if the variable is undefined. * - * Var_Subst Substitute named variable, or all variables if - * NULL in a string using - * the given context as the top-most one. If the - * third argument is non-zero, Parse_Error is - * called if any variables are undefined. + * Var_Subst Substitute either a single variable or all + * variables in a string, using the given context as + * the top-most one. * * Var_Parse Parse a variable expansion from a string and * return the result and the number of characters @@ -124,8 +122,8 @@ __RCSID("$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $"); */ #include -#ifndef NO_REGEX #include +#ifndef NO_REGEX #include #endif #include @@ -134,6 +132,11 @@ __RCSID("$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $"); #include #include "make.h" + +#ifdef HAVE_STDINT_H +#include +#endif + #include "buf.h" #include "dir.h" #include "job.h" @@ -151,14 +154,14 @@ char **savedEnv = NULL; * to determine if there was an error in parsing -- easier than returning * a flag, as things outside this module don't give a hoot. */ -char var_Error[] = ""; +char var_Error[] = ""; /* * Similar to var_Error, but returned when the 'VARF_UNDEFERR' flag for * Var_Parse is not set. Why not just use a constant? Well, gcc likes * to condense identical string instances... */ -static char varNoError[] = ""; +static char varNoError[] = ""; /* * Traditionally we consume $$ during := like any other expansion. @@ -186,33 +189,35 @@ static Boolean save_dollars = FALSE; * The four contexts are searched in the reverse order from which they are * listed. */ -GNode *VAR_INTERNAL; /* variables from make itself */ -GNode *VAR_GLOBAL; /* variables from the makefile */ -GNode *VAR_CMD; /* variables defined on the command-line */ +GNode *VAR_INTERNAL; /* variables from make itself */ +GNode *VAR_GLOBAL; /* variables from the makefile */ +GNode *VAR_CMD; /* variables defined on the command-line */ -#define FIND_CMD 0x1 /* look in VAR_CMD when searching */ -#define FIND_GLOBAL 0x2 /* look in VAR_GLOBAL as well */ -#define FIND_ENV 0x4 /* look in the environment also */ +#define FIND_CMD 0x1 /* look in VAR_CMD when searching */ +#define FIND_GLOBAL 0x2 /* look in VAR_GLOBAL as well */ +#define FIND_ENV 0x4 /* look in the environment also */ + +typedef enum { + VAR_IN_USE = 0x01, /* Variable's value is currently being used. + * Used to avoid endless recursion */ + VAR_FROM_ENV = 0x02, /* Variable comes from the environment */ + VAR_JUNK = 0x04, /* Variable is a junk variable that + * should be destroyed when done with + * it. Used by Var_Parse for undefined, + * modified variables */ + VAR_KEEP = 0x08, /* Variable is VAR_JUNK, but we found + * a use for it in some modifier and + * the value is therefore valid */ + VAR_EXPORTED = 0x10, /* Variable is exported */ + VAR_REEXPORT = 0x20, /* Indicate if var needs re-export. + * This would be true if it contains $'s */ + VAR_FROM_CMD = 0x40 /* Variable came from command line */ +} Var_Flags; typedef struct Var { char *name; /* the variable's name */ Buffer val; /* its value */ - int flags; /* miscellaneous status flags */ -#define VAR_IN_USE 1 /* Variable's value currently being used. - * Used to avoid recursion */ -#define VAR_FROM_ENV 2 /* Variable comes from the environment */ -#define VAR_JUNK 4 /* Variable is a junk variable that - * should be destroyed when done with - * it. Used by Var_Parse for undefined, - * modified variables */ -#define VAR_KEEP 8 /* Variable is VAR_JUNK, but we found - * a use for it in some modifier and - * the value is therefore valid */ -#define VAR_EXPORTED 16 /* Variable is exported */ -#define VAR_REEXPORT 32 /* Indicate if var needs re-export. - * This would be true if it contains $'s - */ -#define VAR_FROM_CMD 64 /* Variable came from command line */ + Var_Flags flags; /* miscellaneous status flags */ } Var; /* @@ -232,16 +237,18 @@ static int var_exportedVars = VAR_EXPORTED_NONE; */ #define VAR_EXPORT_LITERAL 2 -/* Var*Pattern flags */ -#define VAR_SUB_GLOBAL 0x01 /* Apply substitution globally */ -#define VAR_SUB_ONE 0x02 /* Apply substitution to one word */ -#define VAR_SUB_MATCHED 0x04 /* There was a match */ -#define VAR_MATCH_START 0x08 /* Match at start of word */ -#define VAR_MATCH_END 0x10 /* Match at end of word */ -#define VAR_NOSUBST 0x20 /* don't expand vars in VarGetPattern */ +typedef enum { + VAR_SUB_GLOBAL = 0x01, /* Apply substitution globally */ + VAR_SUB_ONE = 0x02, /* Apply substitution to one word */ + VAR_SUB_MATCHED = 0x04, /* There was a match */ + VAR_MATCH_START = 0x08, /* Match at start of word */ + VAR_MATCH_END = 0x10, /* Match at end of word */ + VAR_NOSUBST = 0x20 /* don't expand vars in VarGetPattern */ +} VarPattern_Flags; -/* Var_Set flags */ -#define VAR_NO_EXPORT 0x01 /* do not export */ +typedef enum { + VAR_NO_EXPORT = 0x01 /* do not export */ +} VarSet_Flags; typedef struct { /* @@ -260,11 +267,11 @@ typedef struct { /* struct passed as 'void *' to VarSubstitute() for ":S/lhs/rhs/", * to VarSYSVMatch() for ":lhs=rhs". */ typedef struct { - const char *lhs; /* String to match */ - int leftLen; /* Length of string */ - const char *rhs; /* Replacement string (w/ &'s removed) */ - int rightLen; /* Length of replacement */ - int flags; + const char *lhs; /* String to match */ + int leftLen; /* Length of string */ + const char *rhs; /* Replacement string (w/ &'s removed) */ + int rightLen; /* Length of replacement */ + VarPattern_Flags flags; } VarPattern; /* struct passed as 'void *' to VarLoopExpand() for ":@tvar@str@" */ @@ -274,8 +281,8 @@ typedef struct { int tvarLen; char *str; /* string to expand */ int strLen; - int errnum; /* errnum for not defined */ -} VarLoop_t; + Varf_Flags flags; +} VarLoop; #ifndef NO_REGEX /* struct passed as 'void *' to VarRESubstitute() for ":C///" */ @@ -294,47 +301,6 @@ typedef struct { int end; /* last word to select */ } VarSelectWords_t; -static Var *VarFind(const char *, GNode *, int); -static void VarAdd(const char *, const char *, GNode *); -static Boolean VarHead(GNode *, Var_Parse_State *, - char *, Boolean, Buffer *, void *); -static Boolean VarTail(GNode *, Var_Parse_State *, - char *, Boolean, Buffer *, void *); -static Boolean VarSuffix(GNode *, Var_Parse_State *, - char *, Boolean, Buffer *, void *); -static Boolean VarRoot(GNode *, Var_Parse_State *, - char *, Boolean, Buffer *, void *); -static Boolean VarMatch(GNode *, Var_Parse_State *, - char *, Boolean, Buffer *, void *); -#ifdef SYSVVARSUB -static Boolean VarSYSVMatch(GNode *, Var_Parse_State *, - char *, Boolean, Buffer *, void *); -#endif -static Boolean VarNoMatch(GNode *, Var_Parse_State *, - char *, Boolean, Buffer *, void *); -#ifndef NO_REGEX -static void VarREError(int, regex_t *, const char *); -static Boolean VarRESubstitute(GNode *, Var_Parse_State *, - char *, Boolean, Buffer *, void *); -#endif -static Boolean VarSubstitute(GNode *, Var_Parse_State *, - char *, Boolean, Buffer *, void *); -static Boolean VarLoopExpand(GNode *, Var_Parse_State *, - char *, Boolean, Buffer *, void *); -static char *VarGetPattern(GNode *, Var_Parse_State *, - int, const char **, int, int *, int *, - VarPattern *); -static char *VarQuote(char *, Boolean); -static char *VarHash(char *); -static char *VarModify(GNode *, Var_Parse_State *, - const char *, - Boolean (*)(GNode *, Var_Parse_State *, char *, Boolean, Buffer *, void *), - void *); -static char *VarOrder(const char *, const char); -static char *VarUniq(const char *); -static int VarWordCompare(const void *, const void *); -static void VarPrintVar(void *); - #define BROPEN '{' #define BRCLOSE '}' #define PROPEN '(' @@ -368,45 +334,47 @@ VarFind(const char *name, GNode *ctxt, int flags) Hash_Entry *var; Var *v; - /* - * If the variable name begins with a '.', it could very well be one of - * the local ones. We check the name against all the local variables - * and substitute the short version in for 'name' if it matches one of - * them. - */ - if (*name == '.' && isupper((unsigned char) name[1])) - switch (name[1]) { - case 'A': - if (!strcmp(name, ".ALLSRC")) - name = ALLSRC; - if (!strcmp(name, ".ARCHIVE")) - name = ARCHIVE; - break; - case 'I': - if (!strcmp(name, ".IMPSRC")) - name = IMPSRC; - break; - case 'M': - if (!strcmp(name, ".MEMBER")) - name = MEMBER; - break; - case 'O': - if (!strcmp(name, ".OODATE")) - name = OODATE; - break; - case 'P': - if (!strcmp(name, ".PREFIX")) - name = PREFIX; - break; - case 'T': - if (!strcmp(name, ".TARGET")) - name = TARGET; - break; - } + /* + * If the variable name begins with a '.', it could very well be one of + * the local ones. We check the name against all the local variables + * and substitute the short version in for 'name' if it matches one of + * them. + */ + if (*name == '.' && isupper((unsigned char) name[1])) { + switch (name[1]) { + case 'A': + if (!strcmp(name, ".ALLSRC")) + name = ALLSRC; + if (!strcmp(name, ".ARCHIVE")) + name = ARCHIVE; + break; + case 'I': + if (!strcmp(name, ".IMPSRC")) + name = IMPSRC; + break; + case 'M': + if (!strcmp(name, ".MEMBER")) + name = MEMBER; + break; + case 'O': + if (!strcmp(name, ".OODATE")) + name = OODATE; + break; + case 'P': + if (!strcmp(name, ".PREFIX")) + name = PREFIX; + break; + case 'T': + if (!strcmp(name, ".TARGET")) + name = TARGET; + break; + } + } + #ifdef notyet /* for compatibility with gmake */ if (name[0] == '^' && name[1] == '\0') - name = ALLSRC; + name = ALLSRC; #endif /* @@ -416,19 +384,19 @@ VarFind(const char *name, GNode *ctxt, int flags) */ var = Hash_FindEntry(&ctxt->context, name); - if ((var == NULL) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) { + if (var == NULL && (flags & FIND_CMD) && ctxt != VAR_CMD) { var = Hash_FindEntry(&VAR_CMD->context, name); } - if (!checkEnvFirst && (var == NULL) && (flags & FIND_GLOBAL) && - (ctxt != VAR_GLOBAL)) + if (!checkEnvFirst && var == NULL && (flags & FIND_GLOBAL) && + ctxt != VAR_GLOBAL) { var = Hash_FindEntry(&VAR_GLOBAL->context, name); - if ((var == NULL) && (ctxt != VAR_INTERNAL)) { + if (var == NULL && ctxt != VAR_INTERNAL) { /* VAR_INTERNAL is subordinate to VAR_GLOBAL */ var = Hash_FindEntry(&VAR_INTERNAL->context, name); } } - if ((var == NULL) && (flags & FIND_ENV)) { + if (var == NULL && (flags & FIND_ENV)) { char *env; if ((env = getenv(name)) != NULL) { @@ -443,18 +411,18 @@ VarFind(const char *name, GNode *ctxt, int flags) Buf_AddBytes(&v->val, len, env); v->flags = VAR_FROM_ENV; - return (v); + return v; } else if (checkEnvFirst && (flags & FIND_GLOBAL) && - (ctxt != VAR_GLOBAL)) + ctxt != VAR_GLOBAL) { var = Hash_FindEntry(&VAR_GLOBAL->context, name); - if ((var == NULL) && (ctxt != VAR_INTERNAL)) { + if (var == NULL && ctxt != VAR_INTERNAL) { var = Hash_FindEntry(&VAR_INTERNAL->context, name); } if (var == NULL) { return NULL; } else { - return ((Var *)Hash_GetValue(var)); + return (Var *)Hash_GetValue(var); } } else { return NULL; @@ -462,7 +430,7 @@ VarFind(const char *name, GNode *ctxt, int flags) } else if (var == NULL) { return NULL; } else { - return ((Var *)Hash_GetValue(var)); + return (Var *)Hash_GetValue(var); } } @@ -503,9 +471,6 @@ VarFreeEnv(Var *v, Boolean destroy) * val value to set it to * ctxt context in which to set it * - * Results: - * None - * * Side Effects: * The new variable is placed at the front of the given context * The name and val arguments are duplicated so they may @@ -522,7 +487,7 @@ VarAdd(const char *name, const char *val, GNode *ctxt) v = bmake_malloc(sizeof(Var)); len = val ? strlen(val) : 0; - Buf_Init(&v->val, len+1); + Buf_Init(&v->val, len + 1); Buf_AddBytes(&v->val, len, val); v->flags = 0; @@ -540,9 +505,6 @@ VarAdd(const char *name, const char *val, GNode *ctxt) * Var_Delete -- * Remove a variable from a context. * - * Results: - * None. - * * Side Effects: * The Var structure is removed and freed. * @@ -553,7 +515,7 @@ Var_Delete(const char *name, GNode *ctxt) { Hash_Entry *ln; char *cp; - + if (strchr(name, '$')) { cp = Var_Subst(NULL, name, VAR_GLOBAL, VARF_WANTRES); } else { @@ -578,7 +540,7 @@ Var_Delete(const char *name, GNode *ctxt) var_exportedVars = VAR_EXPORTED_NONE; } if (v->name != ln->name) - free(v->name); + free(v->name); Hash_DeleteEntry(&ctxt->context, ln); Buf_Destroy(&v->val, TRUE); free(v); @@ -603,7 +565,7 @@ Var_Export1(const char *name, int flags) int parent = (flags & VAR_EXPORT_PARENT); if (*name == '.') - return 0; /* skip internals */ + return 0; /* skip internals */ if (!name[1]) { /* * A single char. @@ -668,6 +630,13 @@ Var_Export1(const char *name, int flags) return 1; } +static void +Var_ExportVars_callback(void *entry, void *unused MAKE_ATTR_UNUSED) +{ + Var *var = entry; + Var_Export1(var->name, 0); +} + /* * This gets called from our children. */ @@ -675,9 +644,6 @@ void Var_ExportVars(void) { char tmp[BUFSIZ]; - Hash_Entry *var; - Hash_Search state; - Var *v; char *val; int n; @@ -694,15 +660,8 @@ Var_ExportVars(void) return; if (VAR_EXPORTED_ALL == var_exportedVars) { - /* - * Ouch! This is crazy... - */ - for (var = Hash_EnumFirst(&VAR_GLOBAL->context, &state); - var != NULL; - var = Hash_EnumNext(&state)) { - v = (Var *)Hash_GetValue(var); - Var_Export1(v->name, 0); - } + /* Ouch! This is crazy... */ + Hash_ForEach(&VAR_GLOBAL->context, Var_ExportVars_callback, NULL); return; } /* @@ -808,7 +767,7 @@ Var_UnExport(char *str) int n; if (!str || !str[0]) { - return; /* assert? */ + return; /* assert? */ } vlist = NULL; @@ -880,7 +839,7 @@ Var_UnExport(char *str) "${" MAKE_EXPORTED ":N%s}", v->name); if (n < (int)sizeof(tmp)) { cp = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES); - Var_Set(MAKE_EXPORTED, cp, VAR_GLOBAL, 0); + Var_Set(MAKE_EXPORTED, cp, VAR_GLOBAL); free(cp); } } @@ -894,38 +853,11 @@ Var_UnExport(char *str) } } -/*- - *----------------------------------------------------------------------- - * Var_Set -- - * Set the variable name to the value val in the given context. - * - * Input: - * name name of variable to set - * val value to give to the variable - * ctxt context in which to set it - * - * Results: - * None. - * - * Side Effects: - * If the variable doesn't yet exist, a new record is created for it. - * Else the old value is freed and the new one stuck in its place - * - * Notes: - * The variable is searched for only in its context before being - * created in that context. I.e. if the context is VAR_GLOBAL, - * only VAR_GLOBAL->context is searched. Likewise if it is VAR_CMD, only - * VAR_CMD->context is searched. This is done to avoid the literally - * thousands of unnecessary strcmp's that used to be done to - * set, say, $(@) or $(<). - * If the context is VAR_GLOBAL though, we check if the variable - * was set in VAR_CMD from the command line and skip it if so. - *----------------------------------------------------------------------- - */ -void -Var_Set(const char *name, const char *val, GNode *ctxt, int flags) +static void +Var_Set_with_flags(const char *name, const char *val, GNode *ctxt, + VarSet_Flags flags) { - Var *v; + Var *v; char *expanded_name = NULL; /* @@ -1008,12 +940,43 @@ Var_Set(const char *name, const char *val, GNode *ctxt, int flags) save_dollars = s2Boolean(val, save_dollars); } - out: +out: free(expanded_name); if (v != NULL) VarFreeEnv(v, TRUE); } +/*- + *----------------------------------------------------------------------- + * Var_Set -- + * Set the variable name to the value val in the given context. + * + * Input: + * name name of variable to set + * val value to give to the variable + * ctxt context in which to set it + * + * Side Effects: + * If the variable doesn't yet exist, a new record is created for it. + * Else the old value is freed and the new one stuck in its place + * + * Notes: + * The variable is searched for only in its context before being + * created in that context. I.e. if the context is VAR_GLOBAL, + * only VAR_GLOBAL->context is searched. Likewise if it is VAR_CMD, only + * VAR_CMD->context is searched. This is done to avoid the literally + * thousands of unnecessary strcmp's that used to be done to + * set, say, $(@) or $(<). + * If the context is VAR_GLOBAL though, we check if the variable + * was set in VAR_CMD from the command line and skip it if so. + *----------------------------------------------------------------------- + */ +void +Var_Set(const char *name, const char *val, GNode *ctxt) +{ + Var_Set_with_flags(name, val, ctxt, 0); +} + /*- *----------------------------------------------------------------------- * Var_Append -- @@ -1025,9 +988,6 @@ Var_Set(const char *name, const char *val, GNode *ctxt, int flags) * val String to append to it * ctxt Context in which this should occur * - * Results: - * None - * * Side Effects: * If the variable doesn't exist, it is created. Else the strings * are concatenated (with a space in between). @@ -1044,8 +1004,8 @@ Var_Set(const char *name, const char *val, GNode *ctxt, int flags) void Var_Append(const char *name, const char *val, GNode *ctxt) { - Var *v; - Hash_Entry *h; + Var *v; + Hash_Entry *h; char *expanded_name = NULL; if (strchr(name, '$') != NULL) { @@ -1062,17 +1022,17 @@ Var_Append(const char *name, const char *val, GNode *ctxt) name = expanded_name; } - v = VarFind(name, ctxt, (ctxt == VAR_GLOBAL) ? (FIND_CMD|FIND_ENV) : 0); + v = VarFind(name, ctxt, ctxt == VAR_GLOBAL ? (FIND_CMD|FIND_ENV) : 0); if (v == NULL) { - Var_Set(name, val, ctxt, 0); + Var_Set(name, val, ctxt); } else if (ctxt == VAR_CMD || !(v->flags & VAR_FROM_CMD)) { Buf_AddByte(&v->val, ' '); Buf_AddBytes(&v->val, strlen(val), val); if (DEBUG(VAR)) { fprintf(debug_file, "%s:%s = %s\n", ctxt->name, name, - Buf_GetAll(&v->val, NULL)); + Buf_GetAll(&v->val, NULL)); } if (v->flags & VAR_FROM_ENV) { @@ -1119,11 +1079,11 @@ Var_Exists(const char *name, GNode *ctxt) v = VarFind(cp ? cp : name, ctxt, FIND_CMD|FIND_GLOBAL|FIND_ENV); free(cp); if (v == NULL) { - return(FALSE); - } else { - (void)VarFreeEnv(v, TRUE); + return FALSE; } - return(TRUE); + + (void)VarFreeEnv(v, TRUE); + return TRUE; } /*- @@ -1145,355 +1105,173 @@ Var_Exists(const char *name, GNode *ctxt) char * Var_Value(const char *name, GNode *ctxt, char **frp) { - Var *v; + Var *v; v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); *frp = NULL; - if (v != NULL) { - char *p = (Buf_GetAll(&v->val, NULL)); - if (VarFreeEnv(v, FALSE)) - *frp = p; - return p; - } else { + if (v == NULL) return NULL; - } + + char *p = (Buf_GetAll(&v->val, NULL)); + if (VarFreeEnv(v, FALSE)) + *frp = p; + return p; } -/*- - *----------------------------------------------------------------------- - * VarHead -- - * Remove the tail of the given word and place the result in the given - * buffer. + +/* This callback for VarModify gets a single word from an expression and + * typically adds a modification of this word to the buffer. It may also do + * nothing or add several words. * - * Input: - * word Word to trim - * addSpace True if need to add a space to the buffer - * before sticking in the head - * buf Buffer in which to store it + * If addSpaces is TRUE, it must add a space before adding anything else to + * the buffer. * - * Results: - * TRUE if characters were added to the buffer (a space needs to be - * added to the buffer before the next word). - * - * Side Effects: - * The trimmed word is added to the buffer. - * - *----------------------------------------------------------------------- - */ + * It returns the addSpace value for the next call of this callback. Typical + * return values are the current addSpaces or TRUE. */ +typedef Boolean (*VarModifyCallback)(GNode *ctxt, Var_Parse_State *vpstate, + const char *word, Boolean addSpace, Buffer *buf, void *data); + + +/* Callback function for VarModify to implement the :H modifier. + * Add the dirname of the given word to the buffer. */ static Boolean VarHead(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer *buf, + const char *word, Boolean addSpace, Buffer *buf, void *dummy MAKE_ATTR_UNUSED) { - char *slash; + const char *slash = strrchr(word, '/'); - slash = strrchr(word, '/'); - if (slash != NULL) { - if (addSpace && vpstate->varSpace) { - Buf_AddByte(buf, vpstate->varSpace); - } - *slash = '\0'; - Buf_AddBytes(buf, strlen(word), word); - *slash = '/'; - return (TRUE); - } else { - /* - * If no directory part, give . (q.v. the POSIX standard) - */ - if (addSpace && vpstate->varSpace) - Buf_AddByte(buf, vpstate->varSpace); + if (addSpace && vpstate->varSpace) + Buf_AddByte(buf, vpstate->varSpace); + if (slash != NULL) + Buf_AddBytes(buf, slash - word, word); + else Buf_AddByte(buf, '.'); - } + return TRUE; } -/*- - *----------------------------------------------------------------------- - * VarTail -- - * Remove the head of the given word and place the result in the given - * buffer. - * - * Input: - * word Word to trim - * addSpace True if need to add a space to the buffer - * before adding the tail - * buf Buffer in which to store it - * - * Results: - * TRUE if characters were added to the buffer (a space needs to be - * added to the buffer before the next word). - * - * Side Effects: - * The trimmed word is added to the buffer. - * - *----------------------------------------------------------------------- - */ +/* Callback function for VarModify to implement the :T modifier. + * Add the basename of the given word to the buffer. */ static Boolean VarTail(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer *buf, + const char *word, Boolean addSpace, Buffer *buf, void *dummy MAKE_ATTR_UNUSED) { - char *slash; + const char *slash = strrchr(word, '/'); + const char *base = slash != NULL ? slash + 1 : word; - if (addSpace && vpstate->varSpace) { + if (addSpace && vpstate->varSpace) Buf_AddByte(buf, vpstate->varSpace); - } - - slash = strrchr(word, '/'); - if (slash != NULL) { - *slash++ = '\0'; - Buf_AddBytes(buf, strlen(slash), slash); - slash[-1] = '/'; - } else { - Buf_AddBytes(buf, strlen(word), word); - } + Buf_AddBytes(buf, strlen(base), base); return TRUE; } -/*- - *----------------------------------------------------------------------- - * VarSuffix -- - * Place the suffix of the given word in the given buffer. - * - * Input: - * word Word to trim - * addSpace TRUE if need to add a space before placing the - * suffix in the buffer - * buf Buffer in which to store it - * - * Results: - * TRUE if characters were added to the buffer (a space needs to be - * added to the buffer before the next word). - * - * Side Effects: - * The suffix from the word is placed in the buffer. - * - *----------------------------------------------------------------------- - */ +/* Callback function for VarModify to implement the :E modifier. + * Add the filename suffix of the given word to the buffer, if it exists. */ static Boolean VarSuffix(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer *buf, + const char *word, Boolean addSpace, Buffer *buf, void *dummy MAKE_ATTR_UNUSED) { - char *dot; + const char *dot = strrchr(word, '.'); + if (dot == NULL) + return addSpace; - dot = strrchr(word, '.'); - if (dot != NULL) { - if (addSpace && vpstate->varSpace) { - Buf_AddByte(buf, vpstate->varSpace); - } - *dot++ = '\0'; - Buf_AddBytes(buf, strlen(dot), dot); - dot[-1] = '.'; - addSpace = TRUE; - } - return addSpace; -} - -/*- - *----------------------------------------------------------------------- - * VarRoot -- - * Remove the suffix of the given word and place the result in the - * buffer. - * - * Input: - * word Word to trim - * addSpace TRUE if need to add a space to the buffer - * before placing the root in it - * buf Buffer in which to store it - * - * Results: - * TRUE if characters were added to the buffer (a space needs to be - * added to the buffer before the next word). - * - * Side Effects: - * The trimmed word is added to the buffer. - * - *----------------------------------------------------------------------- - */ -static Boolean -VarRoot(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer *buf, - void *dummy MAKE_ATTR_UNUSED) -{ - char *dot; - - if (addSpace && vpstate->varSpace) { + if (addSpace && vpstate->varSpace) Buf_AddByte(buf, vpstate->varSpace); - } - - dot = strrchr(word, '.'); - if (dot != NULL) { - *dot = '\0'; - Buf_AddBytes(buf, strlen(word), word); - *dot = '.'; - } else { - Buf_AddBytes(buf, strlen(word), word); - } + Buf_AddBytes(buf, strlen(dot + 1), dot + 1); return TRUE; } -/*- - *----------------------------------------------------------------------- - * VarMatch -- - * Place the word in the buffer if it matches the given pattern. - * Callback function for VarModify to implement the :M modifier. - * - * Input: - * word Word to examine - * addSpace TRUE if need to add a space to the buffer - * before adding the word, if it matches - * buf Buffer in which to store it - * pattern Pattern the word must match - * - * Results: - * TRUE if a space should be placed in the buffer before the next - * word. - * - * Side Effects: - * The word may be copied to the buffer. - * - *----------------------------------------------------------------------- - */ +/* Callback function for VarModify to implement the :R modifier. + * Add the filename basename of the given word to the buffer. */ +static Boolean +VarRoot(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, + const char *word, Boolean addSpace, Buffer *buf, + void *dummy MAKE_ATTR_UNUSED) +{ + char *dot = strrchr(word, '.'); + size_t len = dot != NULL ? (size_t)(dot - word) : strlen(word); + + if (addSpace && vpstate->varSpace) + Buf_AddByte(buf, vpstate->varSpace); + Buf_AddBytes(buf, len, word); + return TRUE; +} + +/* Callback function for VarModify to implement the :M modifier. + * Place the word in the buffer if it matches the given pattern. */ static Boolean VarMatch(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer *buf, - void *pattern) + const char *word, Boolean addSpace, Buffer *buf, + void *data) { + const char *pattern = data; if (DEBUG(VAR)) - fprintf(debug_file, "VarMatch [%s] [%s]\n", word, (char *)pattern); - if (Str_Match(word, (char *)pattern)) { - if (addSpace && vpstate->varSpace) { - Buf_AddByte(buf, vpstate->varSpace); - } - addSpace = TRUE; - Buf_AddBytes(buf, strlen(word), word); - } - return(addSpace); + fprintf(debug_file, "VarMatch [%s] [%s]\n", word, pattern); + if (!Str_Match(word, pattern)) + return addSpace; + if (addSpace && vpstate->varSpace) + Buf_AddByte(buf, vpstate->varSpace); + Buf_AddBytes(buf, strlen(word), word); + return TRUE; } #ifdef SYSVVARSUB -/*- - *----------------------------------------------------------------------- - * VarSYSVMatch -- - * Place the word in the buffer if it matches the given pattern. - * Callback function for VarModify to implement the System V % - * modifiers. - * - * Input: - * word Word to examine - * addSpace TRUE if need to add a space to the buffer - * before adding the word, if it matches - * buf Buffer in which to store it - * patp Pattern the word must match - * - * Results: - * TRUE if a space should be placed in the buffer before the next - * word. - * - * Side Effects: - * The word may be copied to the buffer. - * - *----------------------------------------------------------------------- - */ +/* Callback function for VarModify to implement the :%.from=%.to modifier. */ static Boolean VarSYSVMatch(GNode *ctx, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer *buf, - void *patp) + const char *word, Boolean addSpace, Buffer *buf, + void *data) { size_t len; char *ptr; Boolean hasPercent; - VarPattern *pat = (VarPattern *)patp; - char *varexp; + VarPattern *pat = data; if (addSpace && vpstate->varSpace) Buf_AddByte(buf, vpstate->varSpace); - addSpace = TRUE; - if ((ptr = Str_SYSVMatch(word, pat->lhs, &len, &hasPercent)) != NULL) { - varexp = Var_Subst(NULL, pat->rhs, ctx, VARF_WANTRES); + char *varexp = Var_Subst(NULL, pat->rhs, ctx, VARF_WANTRES); Str_SYSVSubst(buf, varexp, ptr, len, hasPercent); free(varexp); } else { Buf_AddBytes(buf, strlen(word), word); } - return(addSpace); + return TRUE; } #endif - -/*- - *----------------------------------------------------------------------- - * VarNoMatch -- - * Place the word in the buffer if it doesn't match the given pattern. - * Callback function for VarModify to implement the :N modifier. - * - * Input: - * word Word to examine - * addSpace TRUE if need to add a space to the buffer - * before adding the word, if it matches - * buf Buffer in which to store it - * pattern Pattern the word must match - * - * Results: - * TRUE if a space should be placed in the buffer before the next - * word. - * - * Side Effects: - * The word may be copied to the buffer. - * - *----------------------------------------------------------------------- - */ +/* Callback function for VarModify to implement the :N modifier. + * Place the word in the buffer if it doesn't match the given pattern. */ static Boolean VarNoMatch(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer *buf, - void *pattern) + const char *word, Boolean addSpace, Buffer *buf, + void *data) { - if (!Str_Match(word, (char *)pattern)) { - if (addSpace && vpstate->varSpace) { - Buf_AddByte(buf, vpstate->varSpace); - } - addSpace = TRUE; - Buf_AddBytes(buf, strlen(word), word); - } - return(addSpace); + const char *pattern = data; + if (Str_Match(word, pattern)) + return addSpace; + if (addSpace && vpstate->varSpace) + Buf_AddByte(buf, vpstate->varSpace); + Buf_AddBytes(buf, strlen(word), word); + return TRUE; } - -/*- - *----------------------------------------------------------------------- - * VarSubstitute -- - * Perform a string-substitution on the given word, placing the - * result in the passed buffer. - * - * Input: - * word Word to modify - * addSpace True if space should be added before - * other characters - * buf Buffer for result - * patternp Pattern for substitution - * - * Results: - * TRUE if a space is needed before more characters are added. - * - * Side Effects: - * None. - * - *----------------------------------------------------------------------- - */ +/* Callback function for VarModify to implement the :S,from,to, modifier. + * Perform a string substitution on the given word. */ static Boolean VarSubstitute(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer *buf, - void *patternp) + const char *word, Boolean addSpace, Buffer *buf, + void *data) { - int wordLen; /* Length of word */ - char *cp; /* General pointer */ - VarPattern *pattern = (VarPattern *)patternp; + int wordLen = strlen(word); + const char *cp; /* General pointer */ + VarPattern *pattern = data; - wordLen = strlen(word); if ((pattern->flags & (VAR_SUB_ONE|VAR_SUB_MATCHED)) != (VAR_SUB_ONE|VAR_SUB_MATCHED)) { /* @@ -1502,44 +1280,44 @@ VarSubstitute(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, */ if ((pattern->flags & VAR_MATCH_START) && (strncmp(word, pattern->lhs, pattern->leftLen) == 0)) { + /* + * Anchored at start and beginning of word matches pattern + */ + if ((pattern->flags & VAR_MATCH_END) && + (wordLen == pattern->leftLen)) { /* - * Anchored at start and beginning of word matches pattern + * Also anchored at end and matches to the end (word + * is same length as pattern) add space and rhs only + * if rhs is non-null. */ - if ((pattern->flags & VAR_MATCH_END) && - (wordLen == pattern->leftLen)) { - /* - * Also anchored at end and matches to the end (word - * is same length as pattern) add space and rhs only - * if rhs is non-null. - */ - if (pattern->rightLen != 0) { - if (addSpace && vpstate->varSpace) { - Buf_AddByte(buf, vpstate->varSpace); - } - addSpace = TRUE; - Buf_AddBytes(buf, pattern->rightLen, pattern->rhs); - } - pattern->flags |= VAR_SUB_MATCHED; - } else if (pattern->flags & VAR_MATCH_END) { - /* - * Doesn't match to end -- copy word wholesale - */ - goto nosub; - } else { - /* - * Matches at start but need to copy in trailing characters - */ - if ((pattern->rightLen + wordLen - pattern->leftLen) != 0){ - if (addSpace && vpstate->varSpace) { - Buf_AddByte(buf, vpstate->varSpace); - } - addSpace = TRUE; + if (pattern->rightLen != 0) { + if (addSpace && vpstate->varSpace) { + Buf_AddByte(buf, vpstate->varSpace); } + addSpace = TRUE; Buf_AddBytes(buf, pattern->rightLen, pattern->rhs); - Buf_AddBytes(buf, wordLen - pattern->leftLen, - (word + pattern->leftLen)); - pattern->flags |= VAR_SUB_MATCHED; } + pattern->flags |= VAR_SUB_MATCHED; + } else if (pattern->flags & VAR_MATCH_END) { + /* + * Doesn't match to end -- copy word wholesale + */ + goto nosub; + } else { + /* + * Matches at start but need to copy in trailing characters + */ + if ((pattern->rightLen + wordLen - pattern->leftLen) != 0) { + if (addSpace && vpstate->varSpace) { + Buf_AddByte(buf, vpstate->varSpace); + } + addSpace = TRUE; + } + Buf_AddBytes(buf, pattern->rightLen, pattern->rhs); + Buf_AddBytes(buf, wordLen - pattern->leftLen, + (word + pattern->leftLen)); + pattern->flags |= VAR_SUB_MATCHED; + } } else if (pattern->flags & VAR_MATCH_START) { /* * Had to match at start of word and didn't -- copy whole word. @@ -1596,11 +1374,11 @@ VarSubstitute(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, while (!done) { cp = Str_FindSubstring(word, pattern->lhs); if (cp != NULL) { - if (addSpace && (((cp - word) + pattern->rightLen) != 0)){ + if (addSpace && (((cp - word) + pattern->rightLen) != 0)) { Buf_AddByte(buf, vpstate->varSpace); addSpace = FALSE; } - Buf_AddBytes(buf, cp-word, word); + Buf_AddBytes(buf, cp - word, word); Buf_AddBytes(buf, pattern->rightLen, pattern->rhs); wordLen -= (cp - word) + pattern->leftLen; word = cp + pattern->leftLen; @@ -1626,16 +1404,16 @@ VarSubstitute(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, * before we add any more. If we didn't add any, just return * the previous value of addSpace. */ - return ((Buf_Size(buf) != origSize) || addSpace); + return (Buf_Size(buf) != origSize) || addSpace; } - return (addSpace); + return addSpace; } - nosub: +nosub: if (addSpace && vpstate->varSpace) { Buf_AddByte(buf, vpstate->varSpace); } Buf_AddBytes(buf, wordLen, word); - return(TRUE); + return TRUE; } #ifndef NO_REGEX @@ -1644,9 +1422,6 @@ VarSubstitute(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, * VarREError -- * Print the error caused by a regcomp or regexec call. * - * Results: - * None. - * * Side Effects: * An error gets printed. * @@ -1665,32 +1440,19 @@ VarREError(int reerr, regex_t *pat, const char *str) free(errbuf); } - -/*- - *----------------------------------------------------------------------- - * VarRESubstitute -- - * Perform a regex substitution on the given word, placing the - * result in the passed buffer. - * - * Results: - * TRUE if a space is needed before more characters are added. - * - * Side Effects: - * None. - * - *----------------------------------------------------------------------- - */ +/* Callback function for VarModify to implement the :C/from/to/ modifier. + * Perform a regex substitution on the given word. */ static Boolean VarRESubstitute(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate MAKE_ATTR_UNUSED, - char *word, Boolean addSpace, Buffer *buf, - void *patternp) + const char *word, Boolean addSpace, Buffer *buf, + void *data) { - VarREPattern *pat; + VarREPattern *pat = data; int xrv; - char *wp; + const char *wp = word; char *rp; - int added; + int added = 0; int flags = 0; #define MAYBE_ADD_SPACE() \ @@ -1698,10 +1460,6 @@ VarRESubstitute(GNode *ctx MAKE_ATTR_UNUSED, Buf_AddByte(buf, ' '); \ added = 1 - added = 0; - wp = word; - pat = patternp; - if ((pat->flags & (VAR_SUB_ONE|VAR_SUB_MATCHED)) == (VAR_SUB_ONE|VAR_SUB_MATCHED)) xrv = REG_NOMATCH; @@ -1721,10 +1479,9 @@ VarRESubstitute(GNode *ctx MAKE_ATTR_UNUSED, for (rp = pat->replace; *rp; rp++) { if ((*rp == '\\') && ((rp[1] == '&') || (rp[1] == '\\'))) { MAYBE_ADD_SPACE(); - Buf_AddByte(buf,rp[1]); + Buf_AddByte(buf, rp[1]); rp++; - } - else if ((*rp == '&') || + } else if ((*rp == '&') || ((*rp == '\\') && isdigit((unsigned char)rp[1]))) { int n; const char *subbuf; @@ -1752,7 +1509,7 @@ VarRESubstitute(GNode *ctx MAKE_ATTR_UNUSED, Error("No match for subexpression %s", &errstr[0]); subbuf = ""; sublen = 0; - } else { + } else { subbuf = wp + pat->matches[n].rm_so; sublen = pat->matches[n].rm_eo - pat->matches[n].rm_so; } @@ -1785,61 +1542,47 @@ VarRESubstitute(GNode *ctx MAKE_ATTR_UNUSED, break; default: VarREError(xrv, &pat->re, "Unexpected regex error"); - /* fall through */ + /* fall through */ case REG_NOMATCH: if (*wp) { MAYBE_ADD_SPACE(); - Buf_AddBytes(buf,strlen(wp),wp); + Buf_AddBytes(buf, strlen(wp), wp); } break; } - return(addSpace||added); + return addSpace || added; } #endif - -/*- - *----------------------------------------------------------------------- - * VarLoopExpand -- - * Implements the :@@@ modifier of ODE make. - * We set the temp variable named in pattern.lhs to word and expand - * pattern.rhs storing the result in the passed buffer. - * - * Input: - * word Word to modify - * addSpace True if space should be added before - * other characters - * buf Buffer for result - * pattern Datafor substitution - * - * Results: - * TRUE if a space is needed before more characters are added. - * - * Side Effects: - * None. - * - *----------------------------------------------------------------------- - */ +/* Callback function for VarModify to implement the :@var@...@ modifier of + * ODE make. We set the temp variable named in pattern.lhs to word and + * expand pattern.rhs. */ static Boolean VarLoopExpand(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate MAKE_ATTR_UNUSED, - char *word, Boolean addSpace, Buffer *buf, - void *loopp) + const char *word, Boolean addSpace, Buffer *buf, + void *data) { - VarLoop_t *loop = (VarLoop_t *)loopp; + VarLoop *loop = data; char *s; int slen; - if (word && *word) { - Var_Set(loop->tvar, word, loop->ctxt, VAR_NO_EXPORT); - s = Var_Subst(NULL, loop->str, loop->ctxt, loop->errnum | VARF_WANTRES); - if (s != NULL && *s != '\0') { - if (addSpace && *s != '\n') - Buf_AddByte(buf, ' '); - Buf_AddBytes(buf, (slen = strlen(s)), s); - addSpace = (slen > 0 && s[slen - 1] != '\n'); - } + if (*word) { + Var_Set_with_flags(loop->tvar, word, loop->ctxt, VAR_NO_EXPORT); + s = Var_Subst(NULL, loop->str, loop->ctxt, loop->flags); + if (DEBUG(VAR)) { + fprintf(debug_file, + "VarLoopExpand: in \"%s\", replace \"%s\" with \"%s\" " + "to \"%s\"\n", + word, loop->tvar, loop->str, s ? s : "(null)"); + } + if (s != NULL && *s != '\0') { + if (addSpace && *s != '\n') + Buf_AddByte(buf, ' '); + Buf_AddBytes(buf, (slen = strlen(s)), s); + addSpace = (slen > 0 && s[slen - 1] != '\n'); + } free(s); } return addSpace; @@ -1869,12 +1612,12 @@ static char * VarSelectWords(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, const char *str, VarSelectWords_t *seldata) { - Buffer buf; /* Buffer for the new string */ - Boolean addSpace; /* TRUE if need to add a space to the - * buffer before adding the trimmed - * word */ - char **av; /* word list */ - char *as; /* word list memory */ + Buffer buf; /* Buffer for the new string */ + Boolean addSpace; /* TRUE if need to add a space to the + * buffer before adding the trimmed + * word */ + char **av; /* word list */ + char *as; /* word list memory */ int ac, i; int start, end, step; @@ -1884,7 +1627,7 @@ VarSelectWords(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, if (vpstate->oneBigWord) { /* fake what brk_string() would do if there were only one word */ ac = 1; - av = bmake_malloc((ac + 1) * sizeof(char *)); + av = bmake_malloc((ac + 1) * sizeof(char *)); as = bmake_strdup(str); av[0] = as; av[1] = NULL; @@ -1935,42 +1678,35 @@ VarSelectWords(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, } -/*- - * VarRealpath -- - * Replace each word with the result of realpath() - * if successful. - */ +/* Callback function for VarModify to implement the :tA modifier. + * Replace each word with the result of realpath() if successful. */ static Boolean VarRealpath(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer *buf, + const char *word, Boolean addSpace, Buffer *buf, void *patternp MAKE_ATTR_UNUSED) { - struct stat st; - char rbuf[MAXPATHLEN]; - char *rp; - - if (addSpace && vpstate->varSpace) { - Buf_AddByte(buf, vpstate->varSpace); - } - addSpace = TRUE; - rp = cached_realpath(word, rbuf); - if (rp && *rp == '/' && stat(rp, &st) == 0) - word = rp; - - Buf_AddBytes(buf, strlen(word), word); - return(addSpace); + struct stat st; + char rbuf[MAXPATHLEN]; + char *rp; + + if (addSpace && vpstate->varSpace) + Buf_AddByte(buf, vpstate->varSpace); + rp = cached_realpath(word, rbuf); + if (rp && *rp == '/' && stat(rp, &st) == 0) + word = rp; + + Buf_AddBytes(buf, strlen(word), word); + return TRUE; } /*- *----------------------------------------------------------------------- - * VarModify -- - * Modify each of the words of the passed string using the given - * function. Used to implement all modifiers. + * Modify each of the words of the passed string using the given function. * * Input: * str String whose words should be trimmed * modProc Function to use to modify them - * datum Datum to pass it + * data Custom data for the modProc * * Results: * A string of all the words modified appropriately. @@ -1982,17 +1718,13 @@ VarRealpath(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate, */ static char * VarModify(GNode *ctx, Var_Parse_State *vpstate, - const char *str, - Boolean (*modProc)(GNode *, Var_Parse_State *, char *, - Boolean, Buffer *, void *), - void *datum) + const char *str, VarModifyCallback modProc, void *datum) { - Buffer buf; /* Buffer for the new string */ - Boolean addSpace; /* TRUE if need to add a space to the - * buffer before adding the trimmed - * word */ - char **av; /* word list */ - char *as; /* word list memory */ + Buffer buf; /* Buffer for the new string */ + Boolean addSpace; /* TRUE if need to add a space to the + * buffer before adding the trimmed word */ + char **av; /* word list */ + char *as; /* word list memory */ int ac, i; Buf_Init(&buf, 0); @@ -2001,7 +1733,7 @@ VarModify(GNode *ctx, Var_Parse_State *vpstate, if (vpstate->oneBigWord) { /* fake what brk_string() would do if there were only one word */ ac = 1; - av = bmake_malloc((ac + 1) * sizeof(char *)); + av = bmake_malloc((ac + 1) * sizeof(char *)); as = bmake_strdup(str); av[0] = as; av[1] = NULL; @@ -2009,10 +1741,14 @@ VarModify(GNode *ctx, Var_Parse_State *vpstate, av = brk_string(str, &ac, FALSE, &as); } - for (i = 0; i < ac; i++) { - addSpace = (*modProc)(ctx, vpstate, av[i], addSpace, &buf, datum); + if (DEBUG(VAR)) { + fprintf(debug_file, "VarModify: split \"%s\" into %d words\n", + str, ac); } + for (i = 0; i < ac; i++) + addSpace = modProc(ctx, vpstate, av[i], addSpace, &buf, datum); + free(as); free(av); @@ -2023,15 +1759,15 @@ VarModify(GNode *ctx, Var_Parse_State *vpstate, static int VarWordCompare(const void *a, const void *b) { - int r = strcmp(*(const char * const *)a, *(const char * const *)b); - return r; + int r = strcmp(*(const char * const *)a, *(const char * const *)b); + return r; } static int VarWordCompareReverse(const void *a, const void *b) { - int r = strcmp(*(const char * const *)b, *(const char * const *)a); - return r; + int r = strcmp(*(const char * const *)b, *(const char * const *)a); + return r; } /*- @@ -2054,44 +1790,40 @@ VarWordCompareReverse(const void *a, const void *b) static char * VarOrder(const char *str, const char otype) { - Buffer buf; /* Buffer for the new string */ - char **av; /* word list [first word does not count] */ - char *as; /* word list memory */ + Buffer buf; /* Buffer for the new string */ + char **av; /* word list [first word does not count] */ + char *as; /* word list memory */ int ac, i; Buf_Init(&buf, 0); av = brk_string(str, &ac, FALSE, &as); - if (ac > 0) + if (ac > 0) { switch (otype) { - case 'r': /* reverse sort alphabetically */ + case 'r': /* reverse sort alphabetically */ qsort(av, ac, sizeof(char *), VarWordCompareReverse); break; - case 's': /* sort alphabetically */ + case 's': /* sort alphabetically */ qsort(av, ac, sizeof(char *), VarWordCompare); break; - case 'x': /* randomize */ - { - int rndidx; - char *t; - - /* - * We will use [ac..2] range for mod factors. This will produce - * random numbers in [(ac-1)..0] interval, and minimal - * reasonable value for mod factor is 2 (the mod 1 will produce - * 0 with probability 1). - */ - for (i = ac-1; i > 0; i--) { - rndidx = random() % (i + 1); - if (i != rndidx) { - t = av[i]; + case 'x': /* randomize */ + { + /* + * We will use [ac..2] range for mod factors. This will produce + * random numbers in [(ac-1)..0] interval, and minimal + * reasonable value for mod factor is 2 (the mod 1 will produce + * 0 with probability 1). + */ + for (i = ac - 1; i > 0; i--) { + int rndidx = random() % (i + 1); + char *t = av[i]; av[i] = av[rndidx]; av[rndidx] = t; } } } - } /* end of switch */ + } for (i = 0; i < ac; i++) { Buf_AddBytes(&buf, strlen(av[i]), av[i]); @@ -2125,9 +1857,9 @@ VarOrder(const char *str, const char otype) static char * VarUniq(const char *str) { - Buffer buf; /* Buffer for new string */ - char **av; /* List of words to affect */ - char *as; /* Word list memory */ + Buffer buf; /* Buffer for new string */ + char **av; /* List of words to affect */ + char *as; /* Word list memory */ int ac, i, j; Buf_Init(&buf, 0); @@ -2169,10 +1901,10 @@ VarUniq(const char *str) static char * VarRange(const char *str, int ac) { - Buffer buf; /* Buffer for new string */ - char tmp[32]; /* each element */ - char **av; /* List of words to affect */ - char *as; /* Word list memory */ + Buffer buf; /* Buffer for new string */ + char tmp[32]; /* each element */ + char **av; /* List of words to affect */ + char *as; /* Word list memory */ int i, n; Buf_Init(&buf, 0); @@ -2201,7 +1933,8 @@ VarRange(const char *str, int ac) /*- *----------------------------------------------------------------------- * VarGetPattern -- - * Pass through the tstr looking for 1) escaped delimiters, + * During the parsing of a part of a modifier such as :S or :@, + * pass through the tstr looking for 1) escaped delimiters, * '$'s and backslashes (place the escaped character in * uninterpreted) and 2) unescaped $'s that aren't before * the delimiter (expand the variable substitution unless flags @@ -2222,8 +1955,8 @@ VarRange(const char *str, int ac) */ static char * VarGetPattern(GNode *ctxt, Var_Parse_State *vpstate MAKE_ATTR_UNUSED, - int flags, const char **tstr, int delim, int *vflags, - int *length, VarPattern *pattern) + VarPattern_Flags flags, const char **tstr, int delim, + VarPattern_Flags *vflags, int *length, VarPattern *pattern) { const char *cp; char *rstr; @@ -2270,8 +2003,8 @@ VarGetPattern(GNode *ctxt, Var_Parse_State *vpstate MAKE_ATTR_UNUSED, * delimiter, assume it's a variable * substitution and recurse. */ - cp2 = Var_Parse(cp, ctxt, errnum | VARF_WANTRES, &len, - &freeIt); + cp2 = Var_Parse(cp, ctxt, errnum | (flags & VARF_WANTRES), + &len, &freeIt); Buf_AddBytes(&buf, strlen(cp2), cp2); free(freeIt); cp += len - 1; @@ -2282,7 +2015,7 @@ VarGetPattern(GNode *ctxt, Var_Parse_State *vpstate MAKE_ATTR_UNUSED, /* * Find the end of this variable reference * and suck it in without further ado. - * It will be interperated later. + * It will be interpreted later. */ int have = *cp2; int want = (*cp2 == PROPEN) ? PRCLOSE : BRCLOSE; @@ -2302,8 +2035,7 @@ VarGetPattern(GNode *ctxt, Var_Parse_State *vpstate MAKE_ATTR_UNUSED, Buf_AddByte(&buf, *cp); } } - } - else if (pattern && *cp == '&') + } else if (pattern && *cp == '&') Buf_AddBytes(&buf, pattern->leftLen, pattern->lhs); else Buf_AddByte(&buf, *cp); @@ -2346,7 +2078,7 @@ VarQuote(char *str, Boolean quoteDollar) size_t nlen; if ((newline = Shell_GetNewline()) == NULL) - newline = "\\\n"; + newline = "\\\n"; nlen = strlen(newline); Buf_Init(&buf, 0); @@ -2387,13 +2119,13 @@ VarQuote(char *str, Boolean quoteDollar) *----------------------------------------------------------------------- */ static char * -VarHash(char *str) +VarHash(const char *str) { static const char hexdigits[16] = "0123456789abcdef"; Buffer buf; size_t len, len2; - unsigned char *ustr = (unsigned char *)str; - unsigned int h, k, c1, c2; + const unsigned char *ustr = (const unsigned char *)str; + uint32_t h, k, c1, c2; h = 0x971e137bU; c1 = 0x95543787U; @@ -2404,18 +2136,21 @@ VarHash(char *str) k = 0; switch (len) { default: - k = (ustr[3] << 24) | (ustr[2] << 16) | (ustr[1] << 8) | ustr[0]; + k = ((uint32_t)ustr[3] << 24) | + ((uint32_t)ustr[2] << 16) | + ((uint32_t)ustr[1] << 8) | + (uint32_t)ustr[0]; len -= 4; ustr += 4; break; case 3: - k |= (ustr[2] << 16); + k |= (uint32_t)ustr[2] << 16; /* FALLTHROUGH */ case 2: - k |= (ustr[1] << 8); + k |= (uint32_t)ustr[1] << 8; /* FALLTHROUGH */ case 1: - k |= ustr[0]; + k |= (uint32_t)ustr[0]; len = 0; } c1 = c1 * 5 + 0x7b7d159cU; @@ -2426,20 +2161,20 @@ VarHash(char *str) h = (h << 13) ^ (h >> 19); h = h * 5 + 0x52dce729U; h ^= k; - } - h ^= len2; - h *= 0x85ebca6b; - h ^= h >> 13; - h *= 0xc2b2ae35; - h ^= h >> 16; + } + h ^= len2; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + h ^= h >> 16; - Buf_Init(&buf, 0); - for (len = 0; len < 8; ++len) { - Buf_AddByte(&buf, hexdigits[h & 15]); - h >>= 4; - } + Buf_Init(&buf, 0); + for (len = 0; len < 8; ++len) { + Buf_AddByte(&buf, hexdigits[h & 15]); + h >>= 4; + } - return Buf_Destroy(&buf, FALSE); + return Buf_Destroy(&buf, FALSE); } static char * @@ -2452,11 +2187,1022 @@ VarStrftime(const char *fmt, int zulu, time_t utc) if (!*fmt) fmt = "%c"; strftime(buf, sizeof(buf), fmt, zulu ? gmtime(&utc) : localtime(&utc)); - + buf[sizeof(buf) - 1] = '\0'; return bmake_strdup(buf); } +typedef struct { + /* const parameters */ + int startc; + int endc; + Var *v; + GNode *ctxt; + int flags; + int *lengthPtr; + void **freePtr; + + /* read-write */ + char *nstr; + const char *tstr; + const char *start; + const char *cp; /* Secondary pointer into str (place marker + * for tstr) */ + char termc; /* Character which terminated scan */ + int cnt; /* Used to count brace pairs when variable in + * in parens or braces */ + char delim; + int modifier; /* that we are processing */ + Var_Parse_State parsestate; /* Flags passed to helper functions */ + + /* result */ + char *newStr; /* New value to return */ +} ApplyModifiersState; + +/* we now have some modifiers with long names */ +#define STRMOD_MATCH(s, want, n) \ + (strncmp(s, want, n) == 0 && (s[n] == st->endc || s[n] == ':')) +#define STRMOD_MATCHX(s, want, n) \ + (strncmp(s, want, n) == 0 && \ + (s[n] == st->endc || s[n] == ':' || s[n] == '=')) +#define CHARMOD_MATCH(c) (c == st->endc || c == ':') + +/* :@var@...${var}...@ */ +static Boolean +ApplyModifier_At(ApplyModifiersState *st) { + VarLoop loop; + VarPattern_Flags vflags = VAR_NOSUBST; + + st->cp = ++(st->tstr); + st->delim = '@'; + loop.tvar = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + &vflags, &loop.tvarLen, NULL); + if (loop.tvar == NULL) + return FALSE; + + loop.str = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + &vflags, &loop.strLen, NULL); + if (loop.str == NULL) + return FALSE; + + st->termc = *st->cp; + st->delim = '\0'; + + loop.flags = st->flags & (VARF_UNDEFERR | VARF_WANTRES); + loop.ctxt = st->ctxt; + st->newStr = VarModify( + st->ctxt, &st->parsestate, st->nstr, VarLoopExpand, &loop); + Var_Delete(loop.tvar, st->ctxt); + free(loop.tvar); + free(loop.str); + return TRUE; +} + +/* :Ddefined or :Uundefined */ +static void +ApplyModifier_Defined(ApplyModifiersState *st) +{ + Buffer buf; /* Buffer for patterns */ + int nflags; + + if (st->flags & VARF_WANTRES) { + int wantres; + if (*st->tstr == 'U') + wantres = ((st->v->flags & VAR_JUNK) != 0); + else + wantres = ((st->v->flags & VAR_JUNK) == 0); + nflags = st->flags & ~VARF_WANTRES; + if (wantres) + nflags |= VARF_WANTRES; + } else + nflags = st->flags; + + /* + * Pass through tstr looking for 1) escaped delimiters, + * '$'s and backslashes (place the escaped character in + * uninterpreted) and 2) unescaped $'s that aren't before + * the delimiter (expand the variable substitution). + * The result is left in the Buffer buf. + */ + Buf_Init(&buf, 0); + for (st->cp = st->tstr + 1; + *st->cp != st->endc && *st->cp != ':' && *st->cp != '\0'; + st->cp++) { + if (*st->cp == '\\' && + (st->cp[1] == ':' || st->cp[1] == '$' || st->cp[1] == st->endc || + st->cp[1] == '\\')) { + Buf_AddByte(&buf, st->cp[1]); + st->cp++; + } else if (*st->cp == '$') { + /* + * If unescaped dollar sign, assume it's a + * variable substitution and recurse. + */ + char *cp2; + int len; + void *freeIt; + + cp2 = Var_Parse(st->cp, st->ctxt, nflags, &len, &freeIt); + Buf_AddBytes(&buf, strlen(cp2), cp2); + free(freeIt); + st->cp += len - 1; + } else { + Buf_AddByte(&buf, *st->cp); + } + } + + st->termc = *st->cp; + + if ((st->v->flags & VAR_JUNK) != 0) + st->v->flags |= VAR_KEEP; + if (nflags & VARF_WANTRES) { + st->newStr = Buf_Destroy(&buf, FALSE); + } else { + st->newStr = st->nstr; + Buf_Destroy(&buf, TRUE); + } +} + +/* :gmtime */ +static Boolean +ApplyModifier_Gmtime(ApplyModifiersState *st) +{ + time_t utc; + char *ep; + + st->cp = st->tstr + 1; /* make sure it is set */ + if (!STRMOD_MATCHX(st->tstr, "gmtime", 6)) + return FALSE; + if (st->tstr[6] == '=') { + utc = strtoul(&st->tstr[7], &ep, 10); + st->cp = ep; + } else { + utc = 0; + st->cp = st->tstr + 6; + } + st->newStr = VarStrftime(st->nstr, 1, utc); + st->termc = *st->cp; + return TRUE; +} + +/* :localtime */ +static Boolean +ApplyModifier_Localtime(ApplyModifiersState *st) +{ + time_t utc; + char *ep; + + st->cp = st->tstr + 1; /* make sure it is set */ + if (!STRMOD_MATCHX(st->tstr, "localtime", 9)) + return FALSE; + + if (st->tstr[9] == '=') { + utc = strtoul(&st->tstr[10], &ep, 10); + st->cp = ep; + } else { + utc = 0; + st->cp = st->tstr + 9; + } + st->newStr = VarStrftime(st->nstr, 0, utc); + st->termc = *st->cp; + return TRUE; +} + +/* :hash */ +static Boolean +ApplyModifier_Hash(ApplyModifiersState *st) +{ + st->cp = st->tstr + 1; /* make sure it is set */ + if (!STRMOD_MATCH(st->tstr, "hash", 4)) + return FALSE; + st->newStr = VarHash(st->nstr); + st->cp = st->tstr + 4; + st->termc = *st->cp; + return TRUE; +} + +/* :P */ +static void +ApplyModifier_Path(ApplyModifiersState *st) +{ + GNode *gn; + + if ((st->v->flags & VAR_JUNK) != 0) + st->v->flags |= VAR_KEEP; + gn = Targ_FindNode(st->v->name, TARG_NOCREATE); + if (gn == NULL || gn->type & OP_NOPATH) { + st->newStr = NULL; + } else if (gn->path) { + st->newStr = bmake_strdup(gn->path); + } else { + st->newStr = Dir_FindFile(st->v->name, Suff_FindPath(gn)); + } + if (!st->newStr) + st->newStr = bmake_strdup(st->v->name); + st->cp = ++st->tstr; + st->termc = *st->tstr; +} + +/* :!cmd! */ +static Boolean +ApplyModifier_Exclam(ApplyModifiersState *st) +{ + const char *emsg; + VarPattern pattern; + + pattern.flags = 0; + + st->delim = '!'; + emsg = NULL; + st->cp = ++st->tstr; + pattern.rhs = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + NULL, &pattern.rightLen, NULL); + if (pattern.rhs == NULL) + return FALSE; + if (st->flags & VARF_WANTRES) + st->newStr = Cmd_Exec(pattern.rhs, &emsg); + else + st->newStr = varNoError; + free(UNCONST(pattern.rhs)); + if (emsg) + Error(emsg, st->nstr); + st->termc = *st->cp; + st->delim = '\0'; + if (st->v->flags & VAR_JUNK) + st->v->flags |= VAR_KEEP; + return TRUE; +} + +/* :range */ +static Boolean +ApplyModifier_Range(ApplyModifiersState *st) +{ + int n; + char *ep; + + st->cp = st->tstr + 1; /* make sure it is set */ + if (!STRMOD_MATCHX(st->tstr, "range", 5)) + return FALSE; + + if (st->tstr[5] == '=') { + n = strtoul(&st->tstr[6], &ep, 10); + st->cp = ep; + } else { + n = 0; + st->cp = st->tstr + 5; + } + st->newStr = VarRange(st->nstr, n); + st->termc = *st->cp; + return TRUE; +} + +/* :Mpattern or :Npattern */ +static void +ApplyModifier_Match(ApplyModifiersState *st) +{ + char *pattern; + const char *endpat; /* points just after end of pattern */ + char *cp2; + Boolean copy; /* pattern should be, or has been, copied */ + Boolean needSubst; + int nest; + + copy = FALSE; + needSubst = FALSE; + nest = 1; + /* + * In the loop below, ignore ':' unless we are at + * (or back to) the original brace level. + * XXX This will likely not work right if $() and ${} + * are intermixed. + */ + for (st->cp = st->tstr + 1; + *st->cp != '\0' && !(*st->cp == ':' && nest == 1); + st->cp++) { + if (*st->cp == '\\' && + (st->cp[1] == ':' || st->cp[1] == st->endc || + st->cp[1] == st->startc)) { + if (!needSubst) + copy = TRUE; + st->cp++; + continue; + } + if (*st->cp == '$') + needSubst = TRUE; + if (*st->cp == '(' || *st->cp == '{') + ++nest; + if (*st->cp == ')' || *st->cp == '}') { + --nest; + if (nest == 0) + break; + } + } + st->termc = *st->cp; + endpat = st->cp; + if (copy) { + /* + * Need to compress the \:'s out of the pattern, so + * allocate enough room to hold the uncompressed + * pattern (note that st->cp started at st->tstr+1, so + * st->cp - st->tstr takes the null byte into account) and + * compress the pattern into the space. + */ + pattern = bmake_malloc(st->cp - st->tstr); + for (cp2 = pattern, st->cp = st->tstr + 1; + st->cp < endpat; + st->cp++, cp2++) { + if ((*st->cp == '\\') && (st->cp+1 < endpat) && + (st->cp[1] == ':' || st->cp[1] == st->endc)) + st->cp++; + *cp2 = *st->cp; + } + *cp2 = '\0'; + endpat = cp2; + } else { + /* + * Either Var_Subst or VarModify will need a + * nul-terminated string soon, so construct one now. + */ + pattern = bmake_strndup(st->tstr+1, endpat - (st->tstr + 1)); + } + if (needSubst) { + /* pattern contains embedded '$', so use Var_Subst to expand it. */ + cp2 = pattern; + pattern = Var_Subst(NULL, cp2, st->ctxt, st->flags); + free(cp2); + } + if (DEBUG(VAR)) + fprintf(debug_file, "Pattern[%s] for [%s] is [%s]\n", + st->v->name, st->nstr, pattern); + if (*st->tstr == 'M') { + st->newStr = VarModify(st->ctxt, &st->parsestate, st->nstr, VarMatch, + pattern); + } else { + st->newStr = VarModify(st->ctxt, &st->parsestate, st->nstr, VarNoMatch, + pattern); + } + free(pattern); +} + +/* :S,from,to, */ +static Boolean +ApplyModifier_Subst(ApplyModifiersState *st) +{ + VarPattern pattern; + Var_Parse_State tmpparsestate; + + pattern.flags = 0; + tmpparsestate = st->parsestate; + st->delim = st->tstr[1]; + st->tstr += 2; + + /* + * If pattern begins with '^', it is anchored to the + * start of the word -- skip over it and flag pattern. + */ + if (*st->tstr == '^') { + pattern.flags |= VAR_MATCH_START; + st->tstr += 1; + } + + st->cp = st->tstr; + pattern.lhs = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + &pattern.flags, &pattern.leftLen, NULL); + if (pattern.lhs == NULL) + return FALSE; + + pattern.rhs = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + NULL, &pattern.rightLen, &pattern); + if (pattern.rhs == NULL) + return FALSE; + + /* + * Check for global substitution. If 'g' after the final + * delimiter, substitution is global and is marked that + * way. + */ + for (;; st->cp++) { + switch (*st->cp) { + case 'g': + pattern.flags |= VAR_SUB_GLOBAL; + continue; + case '1': + pattern.flags |= VAR_SUB_ONE; + continue; + case 'W': + tmpparsestate.oneBigWord = TRUE; + continue; + } + break; + } + + st->termc = *st->cp; + st->newStr = VarModify( + st->ctxt, &tmpparsestate, st->nstr, VarSubstitute, &pattern); + + /* Free the two strings. */ + free(UNCONST(pattern.lhs)); + free(UNCONST(pattern.rhs)); + st->delim = '\0'; + return TRUE; +} + +#ifndef NO_REGEX +/* :C,from,to, */ +static Boolean +ApplyModifier_Regex(ApplyModifiersState *st) +{ + VarREPattern pattern; + char *re; + int error; + Var_Parse_State tmpparsestate; + + pattern.flags = 0; + tmpparsestate = st->parsestate; + st->delim = st->tstr[1]; + st->tstr += 2; + + st->cp = st->tstr; + + re = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + NULL, NULL, NULL); + if (re == NULL) + return FALSE; + + pattern.replace = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + NULL, NULL, NULL); + if (pattern.replace == NULL) { + free(re); + return FALSE; + } + + for (;; st->cp++) { + switch (*st->cp) { + case 'g': + pattern.flags |= VAR_SUB_GLOBAL; + continue; + case '1': + pattern.flags |= VAR_SUB_ONE; + continue; + case 'W': + tmpparsestate.oneBigWord = TRUE; + continue; + } + break; + } + + st->termc = *st->cp; + + error = regcomp(&pattern.re, re, REG_EXTENDED); + free(re); + if (error) { + *st->lengthPtr = st->cp - st->start + 1; + VarREError(error, &pattern.re, "RE substitution error"); + free(pattern.replace); + return FALSE; + } + + pattern.nsub = pattern.re.re_nsub + 1; + if (pattern.nsub < 1) + pattern.nsub = 1; + if (pattern.nsub > 10) + pattern.nsub = 10; + pattern.matches = bmake_malloc(pattern.nsub * sizeof(regmatch_t)); + st->newStr = VarModify( + st->ctxt, &tmpparsestate, st->nstr, VarRESubstitute, &pattern); + regfree(&pattern.re); + free(pattern.replace); + free(pattern.matches); + st->delim = '\0'; + return TRUE; +} +#endif + +/* :tA, :tu, :tl, etc. */ +static Boolean +ApplyModifier_To(ApplyModifiersState *st) +{ + st->cp = st->tstr + 1; /* make sure it is set */ + if (st->tstr[1] != st->endc && st->tstr[1] != ':') { + if (st->tstr[1] == 's') { + /* Use the char (if any) at st->tstr[2] as the word separator. */ + VarPattern pattern; + + if (st->tstr[2] != st->endc && + (st->tstr[3] == st->endc || st->tstr[3] == ':')) { + /* ":ts" or + * ":ts:" */ + st->parsestate.varSpace = st->tstr[2]; + st->cp = st->tstr + 3; + } else if (st->tstr[2] == st->endc || st->tstr[2] == ':') { + /* ":ts" or ":ts:" */ + st->parsestate.varSpace = 0; /* no separator */ + st->cp = st->tstr + 2; + } else if (st->tstr[2] == '\\') { + const char *xp = &st->tstr[3]; + int base = 8; /* assume octal */ + + switch (st->tstr[3]) { + case 'n': + st->parsestate.varSpace = '\n'; + st->cp = st->tstr + 4; + break; + case 't': + st->parsestate.varSpace = '\t'; + st->cp = st->tstr + 4; + break; + case 'x': + base = 16; + xp++; + goto get_numeric; + case '0': + base = 0; + goto get_numeric; + default: + if (isdigit((unsigned char)st->tstr[3])) { + char *ep; + get_numeric: + st->parsestate.varSpace = strtoul(xp, &ep, base); + if (*ep != ':' && *ep != st->endc) + return FALSE; + st->cp = ep; + } else { + /* ":ts". */ + return FALSE; + } + break; + } + } else { + /* Found ":ts". */ + return FALSE; + } + + st->termc = *st->cp; + + /* + * We cannot be certain that VarModify will be used - even if there + * is a subsequent modifier, so do a no-op VarSubstitute now to for + * str to be re-expanded without the spaces. + */ + pattern.flags = VAR_SUB_ONE; + pattern.lhs = pattern.rhs = "\032"; + pattern.leftLen = pattern.rightLen = 1; + + st->newStr = VarModify( + st->ctxt, &st->parsestate, st->nstr, VarSubstitute, &pattern); + } else if (st->tstr[2] == st->endc || st->tstr[2] == ':') { + /* Check for two-character options: ":tu", ":tl" */ + if (st->tstr[1] == 'A') { /* absolute path */ + st->newStr = VarModify( + st->ctxt, &st->parsestate, st->nstr, VarRealpath, NULL); + st->cp = st->tstr + 2; + st->termc = *st->cp; + } else if (st->tstr[1] == 'u') { + char *dp = bmake_strdup(st->nstr); + for (st->newStr = dp; *dp; dp++) + *dp = toupper((unsigned char)*dp); + st->cp = st->tstr + 2; + st->termc = *st->cp; + } else if (st->tstr[1] == 'l') { + char *dp = bmake_strdup(st->nstr); + for (st->newStr = dp; *dp; dp++) + *dp = tolower((unsigned char)*dp); + st->cp = st->tstr + 2; + st->termc = *st->cp; + } else if (st->tstr[1] == 'W' || st->tstr[1] == 'w') { + st->parsestate.oneBigWord = (st->tstr[1] == 'W'); + st->newStr = st->nstr; + st->cp = st->tstr + 2; + st->termc = *st->cp; + } else { + /* Found ":t:" or ":t". */ + return FALSE; + } + } else { + /* Found ":t". */ + return FALSE; + } + } else { + /* Found ":t" or ":t:". */ + return FALSE; + } + return TRUE; +} + +/* :[#], :[1], etc. */ +static int +ApplyModifier_Words(ApplyModifiersState *st) +{ + /* + * Look for the closing ']', recursively + * expanding any embedded variables. + * + * estr is a pointer to the expanded result, + * which we must free(). + */ + char *estr; + + st->cp = st->tstr + 1; /* point to char after '[' */ + st->delim = ']'; /* look for closing ']' */ + estr = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + NULL, NULL, NULL); + if (estr == NULL) + return 'c'; /* report missing ']' */ + /* now st->cp points just after the closing ']' */ + st->delim = '\0'; + if (st->cp[0] != ':' && st->cp[0] != st->endc) { + /* Found junk after ']' */ + free(estr); + return 'b'; + } + if (estr[0] == '\0') { + /* Found empty square brackets in ":[]". */ + free(estr); + return 'b'; + } else if (estr[0] == '#' && estr[1] == '\0') { + /* Found ":[#]" */ + + /* + * We will need enough space for the decimal + * representation of an int. We calculate the + * space needed for the octal representation, + * and add enough slop to cope with a '-' sign + * (which should never be needed) and a '\0' + * string terminator. + */ + int newStrSize = (sizeof(int) * CHAR_BIT + 2) / 3 + 2; + + st->newStr = bmake_malloc(newStrSize); + if (st->parsestate.oneBigWord) { + strncpy(st->newStr, "1", newStrSize); + } else { + /* XXX: brk_string() is a rather expensive + * way of counting words. */ + char **av; + char *as; + int ac; + + av = brk_string(st->nstr, &ac, FALSE, &as); + snprintf(st->newStr, newStrSize, "%d", ac); + free(as); + free(av); + } + st->termc = *st->cp; + free(estr); + return 0; + } else if (estr[0] == '*' && estr[1] == '\0') { + /* Found ":[*]" */ + st->parsestate.oneBigWord = TRUE; + st->newStr = st->nstr; + st->termc = *st->cp; + free(estr); + return 0; + } else if (estr[0] == '@' && estr[1] == '\0') { + /* Found ":[@]" */ + st->parsestate.oneBigWord = FALSE; + st->newStr = st->nstr; + st->termc = *st->cp; + free(estr); + return 0; + } else { + char *ep; + /* + * We expect estr to contain a single + * integer for :[N], or two integers + * separated by ".." for :[start..end]. + */ + VarSelectWords_t seldata = { 0, 0 }; + + seldata.start = strtol(estr, &ep, 0); + if (ep == estr) { + /* Found junk instead of a number */ + free(estr); + return 'b'; + } else if (ep[0] == '\0') { + /* Found only one integer in :[N] */ + seldata.end = seldata.start; + } else if (ep[0] == '.' && ep[1] == '.' && ep[2] != '\0') { + /* Expecting another integer after ".." */ + ep += 2; + seldata.end = strtol(ep, &ep, 0); + if (ep[0] != '\0') { + /* Found junk after ".." */ + free(estr); + return 'b'; + } + } else { + /* Found junk instead of ".." */ + free(estr); + return 'b'; + } + /* + * Now seldata is properly filled in, + * but we still have to check for 0 as + * a special case. + */ + if (seldata.start == 0 && seldata.end == 0) { + /* ":[0]" or perhaps ":[0..0]" */ + st->parsestate.oneBigWord = TRUE; + st->newStr = st->nstr; + st->termc = *st->cp; + free(estr); + return 0; + } else if (seldata.start == 0 || seldata.end == 0) { + /* ":[0..N]" or ":[N..0]" */ + free(estr); + return 'b'; + } + /* Normal case: select the words described by seldata. */ + st->newStr = VarSelectWords( + st->ctxt, &st->parsestate, st->nstr, &seldata); + + st->termc = *st->cp; + free(estr); + return 0; + } +} + +/* :O or :Ox */ +static Boolean +ApplyModifier_Order(ApplyModifiersState *st) +{ + char otype; + + st->cp = st->tstr + 1; /* skip to the rest in any case */ + if (st->tstr[1] == st->endc || st->tstr[1] == ':') { + otype = 's'; + st->termc = *st->cp; + } else if ((st->tstr[1] == 'r' || st->tstr[1] == 'x') && + (st->tstr[2] == st->endc || st->tstr[2] == ':')) { + otype = st->tstr[1]; + st->cp = st->tstr + 2; + st->termc = *st->cp; + } else { + return FALSE; + } + st->newStr = VarOrder(st->nstr, otype); + return TRUE; +} + +/* :? then : else */ +static Boolean +ApplyModifier_IfElse(ApplyModifiersState *st) +{ + VarPattern pattern; + Boolean value; + int cond_rc; + VarPattern_Flags lhs_flags, rhs_flags; + + /* find ':', and then substitute accordingly */ + if (st->flags & VARF_WANTRES) { + cond_rc = Cond_EvalExpression(NULL, st->v->name, &value, 0, FALSE); + if (cond_rc == COND_INVALID) { + lhs_flags = rhs_flags = VAR_NOSUBST; + } else if (value) { + lhs_flags = 0; + rhs_flags = VAR_NOSUBST; + } else { + lhs_flags = VAR_NOSUBST; + rhs_flags = 0; + } + } else { + /* we are just consuming and discarding */ + cond_rc = value = 0; + lhs_flags = rhs_flags = VAR_NOSUBST; + } + pattern.flags = 0; + + st->cp = ++st->tstr; + st->delim = ':'; + pattern.lhs = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + &lhs_flags, &pattern.leftLen, NULL); + if (pattern.lhs == NULL) + return FALSE; + + /* BROPEN or PROPEN */ + st->delim = st->endc; + pattern.rhs = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + &rhs_flags, &pattern.rightLen, NULL); + if (pattern.rhs == NULL) + return FALSE; + + st->termc = *--st->cp; + st->delim = '\0'; + if (cond_rc == COND_INVALID) { + Error("Bad conditional expression `%s' in %s?%s:%s", + st->v->name, st->v->name, pattern.lhs, pattern.rhs); + return FALSE; + } + + if (value) { + st->newStr = UNCONST(pattern.lhs); + free(UNCONST(pattern.rhs)); + } else { + st->newStr = UNCONST(pattern.rhs); + free(UNCONST(pattern.lhs)); + } + if (st->v->flags & VAR_JUNK) + st->v->flags |= VAR_KEEP; + return TRUE; +} + +/* "::=", "::!=", "::+=", or "::?=" */ +static int +ApplyModifier_Assign(ApplyModifiersState *st) +{ + if (st->tstr[1] == '=' || + (st->tstr[2] == '=' && + (st->tstr[1] == '!' || st->tstr[1] == '+' || st->tstr[1] == '?'))) { + GNode *v_ctxt; /* context where v belongs */ + const char *emsg; + char *sv_name; + VarPattern pattern; + int how; + VarPattern_Flags vflags; + + if (st->v->name[0] == 0) + return 'b'; + + v_ctxt = st->ctxt; + sv_name = NULL; + ++st->tstr; + if (st->v->flags & VAR_JUNK) { + /* + * We need to bmake_strdup() it incase + * VarGetPattern() recurses. + */ + sv_name = st->v->name; + st->v->name = bmake_strdup(st->v->name); + } else if (st->ctxt != VAR_GLOBAL) { + Var *gv = VarFind(st->v->name, st->ctxt, 0); + if (gv == NULL) + v_ctxt = VAR_GLOBAL; + else + VarFreeEnv(gv, TRUE); + } + + switch ((how = *st->tstr)) { + case '+': + case '?': + case '!': + st->cp = &st->tstr[2]; + break; + default: + st->cp = ++st->tstr; + break; + } + st->delim = st->startc == PROPEN ? PRCLOSE : BRCLOSE; + pattern.flags = 0; + + vflags = (st->flags & VARF_WANTRES) ? 0 : VAR_NOSUBST; + pattern.rhs = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + &vflags, &pattern.rightLen, NULL); + if (st->v->flags & VAR_JUNK) { + /* restore original name */ + free(st->v->name); + st->v->name = sv_name; + } + if (pattern.rhs == NULL) + return 'c'; + + st->termc = *--st->cp; + st->delim = '\0'; + + if (st->flags & VARF_WANTRES) { + switch (how) { + case '+': + Var_Append(st->v->name, pattern.rhs, v_ctxt); + break; + case '!': + st->newStr = Cmd_Exec(pattern.rhs, &emsg); + if (emsg) + Error(emsg, st->nstr); + else + Var_Set(st->v->name, st->newStr, v_ctxt); + free(st->newStr); + break; + case '?': + if ((st->v->flags & VAR_JUNK) == 0) + break; + /* FALLTHROUGH */ + default: + Var_Set(st->v->name, pattern.rhs, v_ctxt); + break; + } + } + free(UNCONST(pattern.rhs)); + st->newStr = varNoError; + return 0; + } + return 'd'; /* "::" */ +} + +/* remember current value */ +static Boolean +ApplyModifier_Remember(ApplyModifiersState *st) +{ + st->cp = st->tstr + 1; /* make sure it is set */ + if (!STRMOD_MATCHX(st->tstr, "_", 1)) + return FALSE; + + if (st->tstr[1] == '=') { + char *np; + int n; + + st->cp++; + n = strcspn(st->cp, ":)}"); + np = bmake_strndup(st->cp, n + 1); + np[n] = '\0'; + st->cp = st->tstr + 2 + n; + Var_Set(np, st->nstr, st->ctxt); + free(np); + } else { + Var_Set("_", st->nstr, st->ctxt); + } + st->newStr = st->nstr; + st->termc = *st->cp; + return TRUE; +} + +#ifdef SYSVVARSUB +/* :from=to */ +static int +ApplyModifier_SysV(ApplyModifiersState *st) +{ + /* + * This can either be a bogus modifier or a System-V + * substitution command. + */ + VarPattern pattern; + Boolean eqFound = FALSE; + + pattern.flags = 0; + + /* + * First we make a pass through the string trying + * to verify it is a SYSV-make-style translation: + * it must be: =) + */ + st->cp = st->tstr; + st->cnt = 1; + while (*st->cp != '\0' && st->cnt) { + if (*st->cp == '=') { + eqFound = TRUE; + /* continue looking for st->endc */ + } else if (*st->cp == st->endc) + st->cnt--; + else if (*st->cp == st->startc) + st->cnt++; + if (st->cnt) + st->cp++; + } + if (*st->cp != st->endc || !eqFound) + return 0; + + st->delim = '='; + st->cp = st->tstr; + pattern.lhs = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + &pattern.flags, &pattern.leftLen, NULL); + if (pattern.lhs == NULL) + return 'c'; + + st->delim = st->endc; + pattern.rhs = VarGetPattern( + st->ctxt, &st->parsestate, st->flags, &st->cp, st->delim, + NULL, &pattern.rightLen, &pattern); + if (pattern.rhs == NULL) + return 'c'; + + /* + * SYSV modifications happen through the whole + * string. Note the pattern is anchored at the end. + */ + st->termc = *--st->cp; + st->delim = '\0'; + if (pattern.leftLen == 0 && *st->nstr == '\0') { + st->newStr = st->nstr; /* special case */ + } else { + st->newStr = VarModify( + st->ctxt, &st->parsestate, st->nstr, VarSYSVMatch, &pattern); + } + free(UNCONST(pattern.lhs)); + free(UNCONST(pattern.rhs)); + return '='; +} +#endif + /* * Now we need to apply any modifiers the user wants applied. * These are: @@ -2541,42 +3287,21 @@ VarStrftime(const char *fmt, int zulu, time_t utc) * ::!= Assigns output of as the new value of * variable. */ - -/* we now have some modifiers with long names */ -#define STRMOD_MATCH(s, want, n) \ - (strncmp(s, want, n) == 0 && (s[n] == endc || s[n] == ':')) -#define STRMOD_MATCHX(s, want, n) \ - (strncmp(s, want, n) == 0 && (s[n] == endc || s[n] == ':' || s[n] == '=')) -#define CHARMOD_MATCH(c) (c == endc || c == ':') - static char * ApplyModifiers(char *nstr, const char *tstr, - int startc, int endc, - Var *v, GNode *ctxt, int flags, - int *lengthPtr, void **freePtr) + int const startc, int const endc, + Var * const v, GNode * const ctxt, int const flags, + int * const lengthPtr, void ** const freePtr) { - const char *start; - const char *cp; /* Secondary pointer into str (place marker - * for tstr) */ - char *newStr; /* New value to return */ - char *ep; - char termc; /* Character which terminated scan */ - int cnt; /* Used to count brace pairs when variable in - * in parens or braces */ - char delim; - int modifier; /* that we are processing */ - Var_Parse_State parsestate; /* Flags passed to helper functions */ - time_t utc; /* for VarStrftime */ + ApplyModifiersState st = { + startc, endc, v, ctxt, flags, lengthPtr, freePtr, + nstr, tstr, tstr, tstr, + '\0', 0, '\0', 0, {' ', FALSE}, NULL + }; - delim = '\0'; - parsestate.oneBigWord = FALSE; - parsestate.varSpace = ' '; /* word separator */ + while (*st.tstr && *st.tstr != st.endc) { - start = cp = tstr; - - while (*tstr && *tstr != endc) { - - if (*tstr == '$') { + if (*st.tstr == '$') { /* * We may have some complex modifiers in a variable. */ @@ -2585,1145 +3310,275 @@ ApplyModifiers(char *nstr, const char *tstr, int rlen; int c; - rval = Var_Parse(tstr, ctxt, flags, &rlen, &freeIt); + rval = Var_Parse(st.tstr, st.ctxt, st.flags, &rlen, &freeIt); /* - * If we have not parsed up to endc or ':', + * If we have not parsed up to st.endc or ':', * we are not interested. */ if (rval != NULL && *rval && - (c = tstr[rlen]) != '\0' && + (c = st.tstr[rlen]) != '\0' && c != ':' && - c != endc) { + c != st.endc) { free(freeIt); goto apply_mods; } if (DEBUG(VAR)) { fprintf(debug_file, "Got '%s' from '%.*s'%.*s\n", - rval, rlen, tstr, rlen, tstr + rlen); + rval, rlen, st.tstr, rlen, st.tstr + rlen); } - tstr += rlen; + st.tstr += rlen; if (rval != NULL && *rval) { int used; - nstr = ApplyModifiers(nstr, rval, - 0, 0, v, ctxt, flags, &used, freePtr); - if (nstr == var_Error - || (nstr == varNoError && (flags & VARF_UNDEFERR) == 0) + st.nstr = ApplyModifiers(st.nstr, rval, 0, 0, st.v, + st.ctxt, st.flags, &used, st.freePtr); + if (st.nstr == var_Error + || (st.nstr == varNoError && (st.flags & VARF_UNDEFERR) == 0) || strlen(rval) != (size_t) used) { free(freeIt); - goto out; /* error already reported */ + goto out; /* error already reported */ } } free(freeIt); - if (*tstr == ':') - tstr++; - else if (!*tstr && endc) { - Error("Unclosed variable specification after complex modifier (expecting '%c') for %s", endc, v->name); + if (*st.tstr == ':') + st.tstr++; + else if (!*st.tstr && st.endc) { + Error("Unclosed variable specification after complex " + "modifier (expecting '%c') for %s", st.endc, st.v->name); goto out; } continue; } apply_mods: if (DEBUG(VAR)) { - fprintf(debug_file, "Applying[%s] :%c to \"%s\"\n", v->name, - *tstr, nstr); + fprintf(debug_file, "Applying[%s] :%c to \"%s\"\n", st.v->name, + *st.tstr, st.nstr); } - newStr = var_Error; - switch ((modifier = *tstr)) { + st.newStr = var_Error; + switch ((st.modifier = *st.tstr)) { case ':': { - if (tstr[1] == '=' || - (tstr[2] == '=' && - (tstr[1] == '!' || tstr[1] == '+' || tstr[1] == '?'))) { - /* - * "::=", "::!=", "::+=", or "::?=" - */ - GNode *v_ctxt; /* context where v belongs */ - const char *emsg; - char *sv_name; - VarPattern pattern; - int how; - int vflags; - - if (v->name[0] == 0) - goto bad_modifier; - - v_ctxt = ctxt; - sv_name = NULL; - ++tstr; - if (v->flags & VAR_JUNK) { - /* - * We need to bmake_strdup() it incase - * VarGetPattern() recurses. - */ - sv_name = v->name; - v->name = bmake_strdup(v->name); - } else if (ctxt != VAR_GLOBAL) { - Var *gv = VarFind(v->name, ctxt, 0); - if (gv == NULL) - v_ctxt = VAR_GLOBAL; - else - VarFreeEnv(gv, TRUE); - } - - switch ((how = *tstr)) { - case '+': - case '?': - case '!': - cp = &tstr[2]; - break; - default: - cp = ++tstr; - break; - } - delim = startc == PROPEN ? PRCLOSE : BRCLOSE; - pattern.flags = 0; - - vflags = (flags & VARF_WANTRES) ? 0 : VAR_NOSUBST; - pattern.rhs = VarGetPattern(ctxt, &parsestate, flags, - &cp, delim, &vflags, - &pattern.rightLen, - NULL); - if (v->flags & VAR_JUNK) { - /* restore original name */ - free(v->name); - v->name = sv_name; - } - if (pattern.rhs == NULL) - goto cleanup; - - termc = *--cp; - delim = '\0'; - - if (flags & VARF_WANTRES) { - switch (how) { - case '+': - Var_Append(v->name, pattern.rhs, v_ctxt); - break; - case '!': - newStr = Cmd_Exec(pattern.rhs, &emsg); - if (emsg) - Error(emsg, nstr); - else - Var_Set(v->name, newStr, v_ctxt, 0); - free(newStr); - break; - case '?': - if ((v->flags & VAR_JUNK) == 0) - break; - /* FALLTHROUGH */ - default: - Var_Set(v->name, pattern.rhs, v_ctxt, 0); - break; - } - } - free(UNCONST(pattern.rhs)); - newStr = varNoError; - break; - } - goto default_case; /* "::" */ + int res = ApplyModifier_Assign(&st); + if (res == 'b') + goto bad_modifier; + if (res == 'c') + goto cleanup; + if (res == 'd') + goto default_case; + break; } case '@': - { - VarLoop_t loop; - int vflags = VAR_NOSUBST; - - cp = ++tstr; - delim = '@'; - if ((loop.tvar = VarGetPattern(ctxt, &parsestate, flags, - &cp, delim, - &vflags, &loop.tvarLen, - NULL)) == NULL) - goto cleanup; - - if ((loop.str = VarGetPattern(ctxt, &parsestate, flags, - &cp, delim, - &vflags, &loop.strLen, - NULL)) == NULL) - goto cleanup; - - termc = *cp; - delim = '\0'; - - loop.errnum = flags & VARF_UNDEFERR; - loop.ctxt = ctxt; - newStr = VarModify(ctxt, &parsestate, nstr, VarLoopExpand, - &loop); - Var_Delete(loop.tvar, ctxt); - free(loop.tvar); - free(loop.str); - break; - } - case '_': /* remember current value */ - cp = tstr + 1; /* make sure it is set */ - if (STRMOD_MATCHX(tstr, "_", 1)) { - if (tstr[1] == '=') { - char *np; - int n; - - cp++; - n = strcspn(cp, ":)}"); - np = bmake_strndup(cp, n+1); - np[n] = '\0'; - cp = tstr + 2 + n; - Var_Set(np, nstr, ctxt, 0); - free(np); - } else { - Var_Set("_", nstr, ctxt, 0); - } - newStr = nstr; - termc = *cp; - break; - } - goto default_case; + ApplyModifier_At(&st); + break; + case '_': + if (!ApplyModifier_Remember(&st)) + goto default_case; + break; case 'D': case 'U': - { - Buffer buf; /* Buffer for patterns */ - int nflags; - - if (flags & VARF_WANTRES) { - int wantres; - if (*tstr == 'U') - wantres = ((v->flags & VAR_JUNK) != 0); - else - wantres = ((v->flags & VAR_JUNK) == 0); - nflags = flags & ~VARF_WANTRES; - if (wantres) - nflags |= VARF_WANTRES; - } else - nflags = flags; - /* - * Pass through tstr looking for 1) escaped delimiters, - * '$'s and backslashes (place the escaped character in - * uninterpreted) and 2) unescaped $'s that aren't before - * the delimiter (expand the variable substitution). - * The result is left in the Buffer buf. - */ - Buf_Init(&buf, 0); - for (cp = tstr + 1; - *cp != endc && *cp != ':' && *cp != '\0'; - cp++) { - if ((*cp == '\\') && - ((cp[1] == ':') || - (cp[1] == '$') || - (cp[1] == endc) || - (cp[1] == '\\'))) - { - Buf_AddByte(&buf, cp[1]); - cp++; - } else if (*cp == '$') { - /* - * If unescaped dollar sign, assume it's a - * variable substitution and recurse. - */ - char *cp2; - int len; - void *freeIt; - - cp2 = Var_Parse(cp, ctxt, nflags, &len, &freeIt); - Buf_AddBytes(&buf, strlen(cp2), cp2); - free(freeIt); - cp += len - 1; - } else { - Buf_AddByte(&buf, *cp); - } - } - - termc = *cp; - - if ((v->flags & VAR_JUNK) != 0) - v->flags |= VAR_KEEP; - if (nflags & VARF_WANTRES) { - newStr = Buf_Destroy(&buf, FALSE); - } else { - newStr = nstr; - Buf_Destroy(&buf, TRUE); - } - break; - } + ApplyModifier_Defined(&st); + break; case 'L': { - if ((v->flags & VAR_JUNK) != 0) - v->flags |= VAR_KEEP; - newStr = bmake_strdup(v->name); - cp = ++tstr; - termc = *tstr; + if ((st.v->flags & VAR_JUNK) != 0) + st.v->flags |= VAR_KEEP; + st.newStr = bmake_strdup(st.v->name); + st.cp = ++st.tstr; + st.termc = *st.tstr; break; } case 'P': - { - GNode *gn; - - if ((v->flags & VAR_JUNK) != 0) - v->flags |= VAR_KEEP; - gn = Targ_FindNode(v->name, TARG_NOCREATE); - if (gn == NULL || gn->type & OP_NOPATH) { - newStr = NULL; - } else if (gn->path) { - newStr = bmake_strdup(gn->path); - } else { - newStr = Dir_FindFile(v->name, Suff_FindPath(gn)); - } - if (!newStr) { - newStr = bmake_strdup(v->name); - } - cp = ++tstr; - termc = *tstr; - break; - } + ApplyModifier_Path(&st); + break; case '!': - { - const char *emsg; - VarPattern pattern; - pattern.flags = 0; - - delim = '!'; - emsg = NULL; - cp = ++tstr; - if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, flags, - &cp, delim, - NULL, &pattern.rightLen, - NULL)) == NULL) - goto cleanup; - if (flags & VARF_WANTRES) - newStr = Cmd_Exec(pattern.rhs, &emsg); - else - newStr = varNoError; - free(UNCONST(pattern.rhs)); - if (emsg) - Error(emsg, nstr); - termc = *cp; - delim = '\0'; - if (v->flags & VAR_JUNK) { - v->flags |= VAR_KEEP; - } - break; - } + if (!ApplyModifier_Exclam(&st)) + goto cleanup; + break; case '[': { - /* - * Look for the closing ']', recursively - * expanding any embedded variables. - * - * estr is a pointer to the expanded result, - * which we must free(). - */ - char *estr; - - cp = tstr+1; /* point to char after '[' */ - delim = ']'; /* look for closing ']' */ - estr = VarGetPattern(ctxt, &parsestate, - flags, &cp, delim, - NULL, NULL, NULL); - if (estr == NULL) - goto cleanup; /* report missing ']' */ - /* now cp points just after the closing ']' */ - delim = '\0'; - if (cp[0] != ':' && cp[0] != endc) { - /* Found junk after ']' */ - free(estr); + int res = ApplyModifier_Words(&st); + if (res == 'b') goto bad_modifier; - } - if (estr[0] == '\0') { - /* Found empty square brackets in ":[]". */ - free(estr); - goto bad_modifier; - } else if (estr[0] == '#' && estr[1] == '\0') { - /* Found ":[#]" */ - - /* - * We will need enough space for the decimal - * representation of an int. We calculate the - * space needed for the octal representation, - * and add enough slop to cope with a '-' sign - * (which should never be needed) and a '\0' - * string terminator. - */ - int newStrSize = - (sizeof(int) * CHAR_BIT + 2) / 3 + 2; - - newStr = bmake_malloc(newStrSize); - if (parsestate.oneBigWord) { - strncpy(newStr, "1", newStrSize); - } else { - /* XXX: brk_string() is a rather expensive - * way of counting words. */ - char **av; - char *as; - int ac; - - av = brk_string(nstr, &ac, FALSE, &as); - snprintf(newStr, newStrSize, "%d", ac); - free(as); - free(av); - } - termc = *cp; - free(estr); - break; - } else if (estr[0] == '*' && estr[1] == '\0') { - /* Found ":[*]" */ - parsestate.oneBigWord = TRUE; - newStr = nstr; - termc = *cp; - free(estr); - break; - } else if (estr[0] == '@' && estr[1] == '\0') { - /* Found ":[@]" */ - parsestate.oneBigWord = FALSE; - newStr = nstr; - termc = *cp; - free(estr); - break; - } else { - /* - * We expect estr to contain a single - * integer for :[N], or two integers - * separated by ".." for :[start..end]. - */ - VarSelectWords_t seldata = { 0, 0 }; - - seldata.start = strtol(estr, &ep, 0); - if (ep == estr) { - /* Found junk instead of a number */ - free(estr); - goto bad_modifier; - } else if (ep[0] == '\0') { - /* Found only one integer in :[N] */ - seldata.end = seldata.start; - } else if (ep[0] == '.' && ep[1] == '.' && - ep[2] != '\0') { - /* Expecting another integer after ".." */ - ep += 2; - seldata.end = strtol(ep, &ep, 0); - if (ep[0] != '\0') { - /* Found junk after ".." */ - free(estr); - goto bad_modifier; - } - } else { - /* Found junk instead of ".." */ - free(estr); - goto bad_modifier; - } - /* - * Now seldata is properly filled in, - * but we still have to check for 0 as - * a special case. - */ - if (seldata.start == 0 && seldata.end == 0) { - /* ":[0]" or perhaps ":[0..0]" */ - parsestate.oneBigWord = TRUE; - newStr = nstr; - termc = *cp; - free(estr); - break; - } else if (seldata.start == 0 || - seldata.end == 0) { - /* ":[0..N]" or ":[N..0]" */ - free(estr); - goto bad_modifier; - } - /* - * Normal case: select the words - * described by seldata. - */ - newStr = VarSelectWords(ctxt, &parsestate, - nstr, &seldata); - - termc = *cp; - free(estr); - break; - } - + if (res == 'c') + goto cleanup; + break; } case 'g': - cp = tstr + 1; /* make sure it is set */ - if (STRMOD_MATCHX(tstr, "gmtime", 6)) { - if (tstr[6] == '=') { - utc = strtoul(&tstr[7], &ep, 10); - cp = ep; - } else { - utc = 0; - cp = tstr + 6; - } - newStr = VarStrftime(nstr, 1, utc); - termc = *cp; - } else { + if (!ApplyModifier_Gmtime(&st)) goto default_case; - } break; case 'h': - cp = tstr + 1; /* make sure it is set */ - if (STRMOD_MATCH(tstr, "hash", 4)) { - newStr = VarHash(nstr); - cp = tstr + 4; - termc = *cp; - } else { + if (!ApplyModifier_Hash(&st)) goto default_case; - } break; case 'l': - cp = tstr + 1; /* make sure it is set */ - if (STRMOD_MATCHX(tstr, "localtime", 9)) { - if (tstr[9] == '=') { - utc = strtoul(&tstr[10], &ep, 10); - cp = ep; - } else { - utc = 0; - cp = tstr + 9; - } - newStr = VarStrftime(nstr, 0, utc); - termc = *cp; - } else { + if (!ApplyModifier_Localtime(&st)) goto default_case; - } break; case 't': - { - cp = tstr + 1; /* make sure it is set */ - if (tstr[1] != endc && tstr[1] != ':') { - if (tstr[1] == 's') { - /* - * Use the char (if any) at tstr[2] - * as the word separator. - */ - VarPattern pattern; - - if (tstr[2] != endc && - (tstr[3] == endc || tstr[3] == ':')) { - /* ":ts" or - * ":ts:" */ - parsestate.varSpace = tstr[2]; - cp = tstr + 3; - } else if (tstr[2] == endc || tstr[2] == ':') { - /* ":ts" or ":ts:" */ - parsestate.varSpace = 0; /* no separator */ - cp = tstr + 2; - } else if (tstr[2] == '\\') { - const char *xp = &tstr[3]; - int base = 8; /* assume octal */ - - switch (tstr[3]) { - case 'n': - parsestate.varSpace = '\n'; - cp = tstr + 4; - break; - case 't': - parsestate.varSpace = '\t'; - cp = tstr + 4; - break; - case 'x': - base = 16; - xp++; - goto get_numeric; - case '0': - base = 0; - goto get_numeric; - default: - if (isdigit((unsigned char)tstr[3])) { - - get_numeric: - parsestate.varSpace = - strtoul(xp, &ep, base); - if (*ep != ':' && *ep != endc) - goto bad_modifier; - cp = ep; - } else { - /* - * ":ts". - */ - goto bad_modifier; - } - break; - } - } else { - /* - * Found ":ts". - */ - goto bad_modifier; - } - - termc = *cp; - - /* - * We cannot be certain that VarModify - * will be used - even if there is a - * subsequent modifier, so do a no-op - * VarSubstitute now to for str to be - * re-expanded without the spaces. - */ - pattern.flags = VAR_SUB_ONE; - pattern.lhs = pattern.rhs = "\032"; - pattern.leftLen = pattern.rightLen = 1; - - newStr = VarModify(ctxt, &parsestate, nstr, - VarSubstitute, - &pattern); - } else if (tstr[2] == endc || tstr[2] == ':') { - /* - * Check for two-character options: - * ":tu", ":tl" - */ - if (tstr[1] == 'A') { /* absolute path */ - newStr = VarModify(ctxt, &parsestate, nstr, - VarRealpath, NULL); - cp = tstr + 2; - termc = *cp; - } else if (tstr[1] == 'u') { - char *dp = bmake_strdup(nstr); - for (newStr = dp; *dp; dp++) - *dp = toupper((unsigned char)*dp); - cp = tstr + 2; - termc = *cp; - } else if (tstr[1] == 'l') { - char *dp = bmake_strdup(nstr); - for (newStr = dp; *dp; dp++) - *dp = tolower((unsigned char)*dp); - cp = tstr + 2; - termc = *cp; - } else if (tstr[1] == 'W' || tstr[1] == 'w') { - parsestate.oneBigWord = (tstr[1] == 'W'); - newStr = nstr; - cp = tstr + 2; - termc = *cp; - } else { - /* Found ":t:" or - * ":t". */ - goto bad_modifier; - } - } else { - /* - * Found ":t". - */ - goto bad_modifier; - } - } else { - /* - * Found ":t" or ":t:". - */ - goto bad_modifier; - } - break; - } + if (!ApplyModifier_To(&st)) + goto bad_modifier; + break; case 'N': case 'M': - { - char *pattern; - const char *endpat; /* points just after end of pattern */ - char *cp2; - Boolean copy; /* pattern should be, or has been, copied */ - Boolean needSubst; - int nest; - - copy = FALSE; - needSubst = FALSE; - nest = 1; - /* - * In the loop below, ignore ':' unless we are at - * (or back to) the original brace level. - * XXX This will likely not work right if $() and ${} - * are intermixed. - */ - for (cp = tstr + 1; - *cp != '\0' && !(*cp == ':' && nest == 1); - cp++) - { - if (*cp == '\\' && - (cp[1] == ':' || - cp[1] == endc || cp[1] == startc)) { - if (!needSubst) { - copy = TRUE; - } - cp++; - continue; - } - if (*cp == '$') { - needSubst = TRUE; - } - if (*cp == '(' || *cp == '{') - ++nest; - if (*cp == ')' || *cp == '}') { - --nest; - if (nest == 0) - break; - } - } - termc = *cp; - endpat = cp; - if (copy) { - /* - * Need to compress the \:'s out of the pattern, so - * allocate enough room to hold the uncompressed - * pattern (note that cp started at tstr+1, so - * cp - tstr takes the null byte into account) and - * compress the pattern into the space. - */ - pattern = bmake_malloc(cp - tstr); - for (cp2 = pattern, cp = tstr + 1; - cp < endpat; - cp++, cp2++) - { - if ((*cp == '\\') && (cp+1 < endpat) && - (cp[1] == ':' || cp[1] == endc)) { - cp++; - } - *cp2 = *cp; - } - *cp2 = '\0'; - endpat = cp2; - } else { - /* - * Either Var_Subst or VarModify will need a - * nul-terminated string soon, so construct one now. - */ - pattern = bmake_strndup(tstr+1, endpat - (tstr + 1)); - } - if (needSubst) { - /* - * pattern contains embedded '$', so use Var_Subst to - * expand it. - */ - cp2 = pattern; - pattern = Var_Subst(NULL, cp2, ctxt, flags | VARF_WANTRES); - free(cp2); - } - if (DEBUG(VAR)) - fprintf(debug_file, "Pattern[%s] for [%s] is [%s]\n", - v->name, nstr, pattern); - if (*tstr == 'M') { - newStr = VarModify(ctxt, &parsestate, nstr, VarMatch, - pattern); - } else { - newStr = VarModify(ctxt, &parsestate, nstr, VarNoMatch, - pattern); - } - free(pattern); - break; - } + ApplyModifier_Match(&st); + break; case 'S': - { - VarPattern pattern; - Var_Parse_State tmpparsestate; - - pattern.flags = 0; - tmpparsestate = parsestate; - delim = tstr[1]; - tstr += 2; - - /* - * If pattern begins with '^', it is anchored to the - * start of the word -- skip over it and flag pattern. - */ - if (*tstr == '^') { - pattern.flags |= VAR_MATCH_START; - tstr += 1; - } - - cp = tstr; - if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, flags, - &cp, delim, - &pattern.flags, - &pattern.leftLen, - NULL)) == NULL) - goto cleanup; - - if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, flags, - &cp, delim, NULL, - &pattern.rightLen, - &pattern)) == NULL) - goto cleanup; - - /* - * Check for global substitution. If 'g' after the final - * delimiter, substitution is global and is marked that - * way. - */ - for (;; cp++) { - switch (*cp) { - case 'g': - pattern.flags |= VAR_SUB_GLOBAL; - continue; - case '1': - pattern.flags |= VAR_SUB_ONE; - continue; - case 'W': - tmpparsestate.oneBigWord = TRUE; - continue; - } - break; - } - - termc = *cp; - newStr = VarModify(ctxt, &tmpparsestate, nstr, - VarSubstitute, - &pattern); - - /* - * Free the two strings. - */ - free(UNCONST(pattern.lhs)); - free(UNCONST(pattern.rhs)); - delim = '\0'; - break; - } + if (!ApplyModifier_Subst(&st)) + goto cleanup; + break; case '?': - { - VarPattern pattern; - Boolean value; - int cond_rc; - int lhs_flags, rhs_flags; - - /* find ':', and then substitute accordingly */ - if (flags & VARF_WANTRES) { - cond_rc = Cond_EvalExpression(NULL, v->name, &value, 0, FALSE); - if (cond_rc == COND_INVALID) { - lhs_flags = rhs_flags = VAR_NOSUBST; - } else if (value) { - lhs_flags = 0; - rhs_flags = VAR_NOSUBST; - } else { - lhs_flags = VAR_NOSUBST; - rhs_flags = 0; - } - } else { - /* we are just consuming and discarding */ - cond_rc = value = 0; - lhs_flags = rhs_flags = VAR_NOSUBST; - } - pattern.flags = 0; - - cp = ++tstr; - delim = ':'; - if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, flags, - &cp, delim, &lhs_flags, - &pattern.leftLen, - NULL)) == NULL) - goto cleanup; - - /* BROPEN or PROPEN */ - delim = endc; - if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, flags, - &cp, delim, &rhs_flags, - &pattern.rightLen, - NULL)) == NULL) - goto cleanup; - - termc = *--cp; - delim = '\0'; - if (cond_rc == COND_INVALID) { - Error("Bad conditional expression `%s' in %s?%s:%s", - v->name, v->name, pattern.lhs, pattern.rhs); - goto cleanup; - } - - if (value) { - newStr = UNCONST(pattern.lhs); - free(UNCONST(pattern.rhs)); - } else { - newStr = UNCONST(pattern.rhs); - free(UNCONST(pattern.lhs)); - } - if (v->flags & VAR_JUNK) { - v->flags |= VAR_KEEP; - } - break; - } + if (!ApplyModifier_IfElse(&st)) + goto cleanup; + break; #ifndef NO_REGEX case 'C': - { - VarREPattern pattern; - char *re; - int error; - Var_Parse_State tmpparsestate; - - pattern.flags = 0; - tmpparsestate = parsestate; - delim = tstr[1]; - tstr += 2; - - cp = tstr; - - if ((re = VarGetPattern(ctxt, &parsestate, flags, &cp, delim, - NULL, NULL, NULL)) == NULL) - goto cleanup; - - if ((pattern.replace = VarGetPattern(ctxt, &parsestate, - flags, &cp, delim, NULL, - NULL, NULL)) == NULL){ - free(re); - goto cleanup; - } - - for (;; cp++) { - switch (*cp) { - case 'g': - pattern.flags |= VAR_SUB_GLOBAL; - continue; - case '1': - pattern.flags |= VAR_SUB_ONE; - continue; - case 'W': - tmpparsestate.oneBigWord = TRUE; - continue; - } - break; - } - - termc = *cp; - - error = regcomp(&pattern.re, re, REG_EXTENDED); - free(re); - if (error) { - *lengthPtr = cp - start + 1; - VarREError(error, &pattern.re, "RE substitution error"); - free(pattern.replace); - goto cleanup; - } - - pattern.nsub = pattern.re.re_nsub + 1; - if (pattern.nsub < 1) - pattern.nsub = 1; - if (pattern.nsub > 10) - pattern.nsub = 10; - pattern.matches = bmake_malloc(pattern.nsub * - sizeof(regmatch_t)); - newStr = VarModify(ctxt, &tmpparsestate, nstr, - VarRESubstitute, - &pattern); - regfree(&pattern.re); - free(pattern.replace); - free(pattern.matches); - delim = '\0'; - break; - } + if (!ApplyModifier_Regex(&st)) + goto cleanup; + break; #endif case 'q': case 'Q': - if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarQuote(nstr, modifier == 'q'); - cp = tstr + 1; - termc = *cp; + if (st.tstr[1] == st.endc || st.tstr[1] == ':') { + st.newStr = VarQuote(st.nstr, st.modifier == 'q'); + st.cp = st.tstr + 1; + st.termc = *st.cp; break; } goto default_case; case 'T': - if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarModify(ctxt, &parsestate, nstr, VarTail, + if (st.tstr[1] == st.endc || st.tstr[1] == ':') { + st.newStr = VarModify(st.ctxt, &st.parsestate, st.nstr, VarTail, NULL); - cp = tstr + 1; - termc = *cp; + st.cp = st.tstr + 1; + st.termc = *st.cp; break; } goto default_case; case 'H': - if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarModify(ctxt, &parsestate, nstr, VarHead, + if (st.tstr[1] == st.endc || st.tstr[1] == ':') { + st.newStr = VarModify(st.ctxt, &st.parsestate, st.nstr, VarHead, NULL); - cp = tstr + 1; - termc = *cp; + st.cp = st.tstr + 1; + st.termc = *st.cp; break; } goto default_case; case 'E': - if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarModify(ctxt, &parsestate, nstr, VarSuffix, + if (st.tstr[1] == st.endc || st.tstr[1] == ':') { + st.newStr = VarModify(st.ctxt, &st.parsestate, st.nstr, VarSuffix, NULL); - cp = tstr + 1; - termc = *cp; + st.cp = st.tstr + 1; + st.termc = *st.cp; break; } goto default_case; case 'R': - if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarModify(ctxt, &parsestate, nstr, VarRoot, + if (st.tstr[1] == st.endc || st.tstr[1] == ':') { + st.newStr = VarModify(st.ctxt, &st.parsestate, st.nstr, VarRoot, NULL); - cp = tstr + 1; - termc = *cp; + st.cp = st.tstr + 1; + st.termc = *st.cp; break; } goto default_case; case 'r': - cp = tstr + 1; /* make sure it is set */ - if (STRMOD_MATCHX(tstr, "range", 5)) { - int n; - - if (tstr[5] == '=') { - n = strtoul(&tstr[6], &ep, 10); - cp = ep; - } else { - n = 0; - cp = tstr + 5; - } - newStr = VarRange(nstr, n); - termc = *cp; - break; - } - goto default_case; + if (!ApplyModifier_Range(&st)) + goto default_case; + break; case 'O': - { - char otype; - - cp = tstr + 1; /* skip to the rest in any case */ - if (tstr[1] == endc || tstr[1] == ':') { - otype = 's'; - termc = *cp; - } else if ( (tstr[1] == 'r' || tstr[1] == 'x') && - (tstr[2] == endc || tstr[2] == ':') ) { - otype = tstr[1]; - cp = tstr + 2; - termc = *cp; - } else { - goto bad_modifier; - } - newStr = VarOrder(nstr, otype); - break; - } + if (!ApplyModifier_Order(&st)) + goto bad_modifier; + break; case 'u': - if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarUniq(nstr); - cp = tstr + 1; - termc = *cp; + if (st.tstr[1] == st.endc || st.tstr[1] == ':') { + st.newStr = VarUniq(st.nstr); + st.cp = st.tstr + 1; + st.termc = *st.cp; break; } goto default_case; #ifdef SUNSHCMD case 's': - if (tstr[1] == 'h' && (tstr[2] == endc || tstr[2] == ':')) { + if (st.tstr[1] == 'h' && (st.tstr[2] == st.endc || st.tstr[2] == ':')) { const char *emsg; - if (flags & VARF_WANTRES) { - newStr = Cmd_Exec(nstr, &emsg); + if (st.flags & VARF_WANTRES) { + st.newStr = Cmd_Exec(st.nstr, &emsg); if (emsg) - Error(emsg, nstr); + Error(emsg, st.nstr); } else - newStr = varNoError; - cp = tstr + 2; - termc = *cp; + st.newStr = varNoError; + st.cp = st.tstr + 2; + st.termc = *st.cp; break; } goto default_case; #endif default: default_case: - { + { #ifdef SYSVVARSUB - /* - * This can either be a bogus modifier or a System-V - * substitution command. - */ - VarPattern pattern; - Boolean eqFound; - - pattern.flags = 0; - eqFound = FALSE; - /* - * First we make a pass through the string trying - * to verify it is a SYSV-make-style translation: - * it must be: =) - */ - cp = tstr; - cnt = 1; - while (*cp != '\0' && cnt) { - if (*cp == '=') { - eqFound = TRUE; - /* continue looking for endc */ - } - else if (*cp == endc) - cnt--; - else if (*cp == startc) - cnt++; - if (cnt) - cp++; - } - if (*cp == endc && eqFound) { - - /* - * Now we break this sucker into the lhs and - * rhs. We must null terminate them of course. - */ - delim='='; - cp = tstr; - if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, - flags, &cp, delim, &pattern.flags, - &pattern.leftLen, NULL)) == NULL) + int res = ApplyModifier_SysV(&st); + if (res == 'c') goto cleanup; - delim = endc; - if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, - flags, &cp, delim, NULL, &pattern.rightLen, - &pattern)) == NULL) - goto cleanup; - - /* - * SYSV modifications happen through the whole - * string. Note the pattern is anchored at the end. - */ - termc = *--cp; - delim = '\0'; - if (pattern.leftLen == 0 && *nstr == '\0') { - newStr = nstr; /* special case */ - } else { - newStr = VarModify(ctxt, &parsestate, nstr, - VarSYSVMatch, - &pattern); - } - free(UNCONST(pattern.lhs)); - free(UNCONST(pattern.rhs)); - } else + if (res != '=') #endif { - Error("Unknown modifier '%c'", *tstr); - for (cp = tstr+1; - *cp != ':' && *cp != endc && *cp != '\0'; - cp++) + Error("Unknown modifier '%c'", *st.tstr); + for (st.cp = st.tstr+1; + *st.cp != ':' && *st.cp != st.endc && *st.cp != '\0'; + st.cp++) continue; - termc = *cp; - newStr = var_Error; + st.termc = *st.cp; + st.newStr = var_Error; } } } if (DEBUG(VAR)) { fprintf(debug_file, "Result[%s] of :%c is \"%s\"\n", - v->name, modifier, newStr); + st.v->name, st.modifier, st.newStr); } - if (newStr != nstr) { - if (*freePtr) { - free(nstr); - *freePtr = NULL; + if (st.newStr != st.nstr) { + if (*st.freePtr) { + free(st.nstr); + *st.freePtr = NULL; } - nstr = newStr; - if (nstr != var_Error && nstr != varNoError) { - *freePtr = nstr; + st.nstr = st.newStr; + if (st.nstr != var_Error && st.nstr != varNoError) { + *st.freePtr = st.nstr; } } - if (termc == '\0' && endc != '\0') { - Error("Unclosed variable specification (expecting '%c') for \"%s\" (value \"%s\") modifier %c", endc, v->name, nstr, modifier); - } else if (termc == ':') { - cp++; + if (st.termc == '\0' && st.endc != '\0') { + Error("Unclosed variable specification (expecting '%c') " + "for \"%s\" (value \"%s\") modifier %c", + st.endc, st.v->name, st.nstr, st.modifier); + } else if (st.termc == ':') { + st.cp++; } - tstr = cp; + st.tstr = st.cp; } - out: - *lengthPtr = tstr - start; - return (nstr); +out: + *st.lengthPtr = st.tstr - st.start; + return st.nstr; - bad_modifier: +bad_modifier: /* "{(" */ - Error("Bad modifier `:%.*s' for %s", (int)strcspn(tstr, ":)}"), tstr, - v->name); + Error("Bad modifier `:%.*s' for %s", (int)strcspn(st.tstr, ":)}"), st.tstr, + st.v->name); - cleanup: - *lengthPtr = cp - start; - if (delim != '\0') +cleanup: + *st.lengthPtr = st.cp - st.start; + if (st.delim != '\0') Error("Unclosed substitution for %s (%c missing)", - v->name, delim); - free(*freePtr); - *freePtr = NULL; - return (var_Error); + st.v->name, st.delim); + free(*st.freePtr); + *st.freePtr = NULL; + return var_Error; } /*- @@ -3757,25 +3612,25 @@ ApplyModifiers(char *nstr, const char *tstr, */ /* coverity[+alloc : arg-*4] */ char * -Var_Parse(const char *str, GNode *ctxt, int flags, +Var_Parse(const char *str, GNode *ctxt, Varf_Flags flags, int *lengthPtr, void **freePtr) { - const char *tstr; /* Pointer into str */ - Var *v; /* Variable in invocation */ - Boolean haveModifier;/* TRUE if have modifiers for the variable */ - char endc; /* Ending character when variable in parens + const char *tstr; /* Pointer into str */ + Var *v; /* Variable in invocation */ + Boolean haveModifier; /* TRUE if have modifiers for the variable */ + char endc; /* Ending character when variable in parens * or braces */ - char startc; /* Starting character when variable in parens + char startc; /* Starting character when variable in parens * or braces */ - int vlen; /* Length of variable name */ - const char *start; /* Points to original start of str */ - char *nstr; /* New string, used during expansion */ - Boolean dynamic; /* TRUE if the variable is local and we're + int vlen; /* Length of variable name */ + const char *start; /* Points to original start of str */ + char *nstr; /* New string, used during expansion */ + Boolean dynamic; /* TRUE if the variable is local and we're * expanding it in a non-local context. This * is done to support dynamic sources. The * result is just the invocation, unaltered */ - const char *extramodifiers; /* extra modifiers to apply first */ - char name[2]; + const char *extramodifiers; /* extra modifiers to apply first */ + char name[2]; *freePtr = NULL; extramodifiers = NULL; @@ -3813,19 +3668,16 @@ Var_Parse(const char *str, GNode *ctxt, int flags, * when dynamic sources are expanded. */ switch (str[1]) { - case '@': - return UNCONST("$(.TARGET)"); - case '%': - return UNCONST("$(.MEMBER)"); - case '*': - return UNCONST("$(.PREFIX)"); - case '!': - return UNCONST("$(.ARCHIVE)"); + case '@': + return UNCONST("$(.TARGET)"); + case '%': + return UNCONST("$(.MEMBER)"); + case '*': + return UNCONST("$(.PREFIX)"); + case '!': + return UNCONST("$(.ARCHIVE)"); } } - /* - * Error - */ return (flags & VARF_UNDEFERR) ? var_Error : varNoError; } else { haveModifier = FALSE; @@ -3833,7 +3685,7 @@ Var_Parse(const char *str, GNode *ctxt, int flags, endc = str[1]; } } else { - Buffer buf; /* Holds the variable name */ + Buffer buf; /* Holds the variable name */ int depth = 1; endc = startc == PROPEN ? PRCLOSE : BRCLOSE; @@ -3842,35 +3694,26 @@ Var_Parse(const char *str, GNode *ctxt, int flags, /* * Skip to the end character or a colon, whichever comes first. */ - for (tstr = str + 2; *tstr != '\0'; tstr++) - { - /* - * Track depth so we can spot parse errors. - */ - if (*tstr == startc) { + for (tstr = str + 2; *tstr != '\0'; tstr++) { + /* Track depth so we can spot parse errors. */ + if (*tstr == startc) depth++; - } if (*tstr == endc) { if (--depth == 0) break; } - if (depth == 1 && *tstr == ':') { + if (depth == 1 && *tstr == ':') break; - } - /* - * A variable inside a variable, expand - */ + /* A variable inside a variable, expand. */ if (*tstr == '$') { int rlen; void *freeIt; - char *rval = Var_Parse(tstr, ctxt, flags, &rlen, &freeIt); - if (rval != NULL) { + char *rval = Var_Parse(tstr, ctxt, flags, &rlen, &freeIt); + if (rval != NULL) Buf_AddBytes(&buf, strlen(rval), rval); - } free(freeIt); tstr += rlen - 1; - } - else + } else Buf_AddByte(&buf, *tstr); } if (*tstr == ':') { @@ -3885,7 +3728,7 @@ Var_Parse(const char *str, GNode *ctxt, int flags, */ *lengthPtr = tstr - str; Buf_Destroy(&buf, TRUE); - return (var_Error); + return var_Error; } str = Buf_GetAll(&buf, &vlen); @@ -3917,10 +3760,9 @@ Var_Parse(const char *str, GNode *ctxt, int flags, if (v != NULL) { if (str[1] == 'D') { - extramodifiers = "H:"; - } - else { /* F */ - extramodifiers = "T:"; + extramodifiers = "H:"; + } else { /* F */ + extramodifiers = "T:"; } } } @@ -3940,20 +3782,18 @@ Var_Parse(const char *str, GNode *ctxt, int flags, * when dynamic sources are expanded. */ switch (*str) { - case '@': - case '%': - case '*': - case '!': - dynamic = TRUE; - break; + case '@': + case '%': + case '*': + case '!': + dynamic = TRUE; + break; } - } else if ((vlen > 2) && (*str == '.') && + } else if (vlen > 2 && *str == '.' && isupper((unsigned char) str[1]) && - ((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL))) + (ctxt == VAR_CMD || ctxt == VAR_GLOBAL)) { - int len; - - len = vlen - 1; + int len = vlen - 1; if ((strncmp(str, ".TARGET", len) == 0) || (strncmp(str, ".ARCHIVE", len) == 0) || (strncmp(str, ".PREFIX", len) == 0) || @@ -3973,7 +3813,7 @@ Var_Parse(const char *str, GNode *ctxt, int flags, char *pstr = bmake_strndup(start, *lengthPtr); *freePtr = pstr; Buf_Destroy(&buf, TRUE); - return(pstr); + return pstr; } else { Buf_Destroy(&buf, TRUE); return (flags & VARF_UNDEFERR) ? var_Error : varNoError; @@ -4009,43 +3849,39 @@ Var_Parse(const char *str, GNode *ctxt, int flags, * return. */ nstr = Buf_GetAll(&v->val, NULL); - if (strchr(nstr, '$') != NULL) { + if (strchr(nstr, '$') != NULL && (flags & VARF_WANTRES) != 0) { nstr = Var_Subst(NULL, nstr, ctxt, flags); *freePtr = nstr; } v->flags &= ~VAR_IN_USE; - if ((nstr != NULL) && (haveModifier || extramodifiers != NULL)) { + if (nstr != NULL && (haveModifier || extramodifiers != NULL)) { void *extraFree; int used; extraFree = NULL; if (extramodifiers != NULL) { - nstr = ApplyModifiers(nstr, extramodifiers, '(', ')', - v, ctxt, flags, &used, &extraFree); + nstr = ApplyModifiers(nstr, extramodifiers, '(', ')', + v, ctxt, flags, &used, &extraFree); } if (haveModifier) { - /* Skip initial colon. */ - tstr++; + /* Skip initial colon. */ + tstr++; - nstr = ApplyModifiers(nstr, tstr, startc, endc, - v, ctxt, flags, &used, freePtr); - tstr += used; - free(extraFree); + nstr = ApplyModifiers(nstr, tstr, startc, endc, + v, ctxt, flags, &used, freePtr); + tstr += used; + free(extraFree); } else { - *freePtr = extraFree; + *freePtr = extraFree; } } - if (*tstr) { - *lengthPtr = tstr - start + 1; - } else { - *lengthPtr = tstr - start; - } + *lengthPtr = tstr - start + (*tstr ? 1 : 0); if (v->flags & VAR_FROM_ENV) { - Boolean destroy = FALSE; + Boolean destroy = FALSE; if (nstr != Buf_GetAll(&v->val, NULL)) { destroy = TRUE; @@ -4080,13 +3916,13 @@ Var_Parse(const char *str, GNode *ctxt, int flags, free(v->name); free(v); } - return (nstr); + return nstr; } /*- *----------------------------------------------------------------------- * Var_Subst -- - * Substitute for all variables in the given string in the given context + * Substitute for all variables in the given string in the given context. * If flags & VARF_UNDEFERR, Parse_Error will be called when an undefined * variable is encountered. * @@ -4102,20 +3938,20 @@ Var_Parse(const char *str, GNode *ctxt, int flags, * The resulting string. * * Side Effects: - * None. The old string must be freed by the caller + * None. *----------------------------------------------------------------------- */ char * -Var_Subst(const char *var, const char *str, GNode *ctxt, int flags) +Var_Subst(const char *var, const char *str, GNode *ctxt, Varf_Flags flags) { - Buffer buf; /* Buffer for forming things */ - char *val; /* Value to substitute for a variable */ - int length; /* Length of the variable invocation */ - Boolean trailingBslash; /* variable ends in \ */ - void *freeIt = NULL; /* Set if it should be freed */ - static Boolean errorReported; /* Set true if an error has already - * been reported to prevent a plethora - * of messages when recursing */ + Buffer buf; /* Buffer for forming things */ + char *val; /* Value to substitute for a variable */ + int length; /* Length of the variable invocation */ + Boolean trailingBslash; /* variable ends in \ */ + void *freeIt = NULL; /* Set if it should be freed */ + static Boolean errorReported; /* Set true if an error has already + * been reported to prevent a plethora + * of messages when recursing */ Buf_Init(&buf, 0); errorReported = FALSE; @@ -4140,7 +3976,7 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, int flags) * Skip as many characters as possible -- either to the end of * the string or to the next dollar sign (variable invocation). */ - const char *cp; + const char *cp; for (cp = str++; *str != '$' && *str != '\0'; str++) continue; @@ -4159,17 +3995,13 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, int flags) Buf_AddBytes(&buf, 2, str); str += 2; expand = FALSE; - } - else + } else expand = TRUE; break; - } - else { + } else { const char *p; - /* - * Scan up to the end of the variable name. - */ + /* Scan up to the end of the variable name. */ for (p = &str[2]; *p && *p != ':' && *p != PRCLOSE && *p != BRCLOSE; p++) if (*p == '$') @@ -4191,13 +4023,12 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, int flags) * Not the variable we want to expand, scan * until the next variable */ - for (;*p != '$' && *p != '\0'; p++) + for (; *p != '$' && *p != '\0'; p++) continue; Buf_AddBytes(&buf, p - str, str); str = p; expand = FALSE; - } - else + } else expand = TRUE; break; } @@ -4230,8 +4061,8 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, int flags) * when the file is parsed. */ if (!errorReported) { - Parse_Error(PARSE_FATAL, - "Undefined variable \"%.*s\"",length,str); + Parse_Error(PARSE_FATAL, "Undefined variable \"%.*s\"", + length, str); } str += length; errorReported = TRUE; @@ -4262,74 +4093,13 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, int flags) return Buf_DestroyCompact(&buf); } -/*- - *----------------------------------------------------------------------- - * Var_GetTail -- - * Return the tail from each of a list of words. Used to set the - * System V local variables. - * - * Input: - * file Filename to modify - * - * Results: - * The resulting string. - * - * Side Effects: - * None. - * - *----------------------------------------------------------------------- - */ -#if 0 -char * -Var_GetTail(char *file) -{ - return(VarModify(file, VarTail, NULL)); -} - -/*- - *----------------------------------------------------------------------- - * Var_GetHead -- - * Find the leading components of a (list of) filename(s). - * XXX: VarHead does not replace foo by ., as (sun) System V make - * does. - * - * Input: - * file Filename to manipulate - * - * Results: - * The leading components. - * - * Side Effects: - * None. - * - *----------------------------------------------------------------------- - */ -char * -Var_GetHead(char *file) -{ - return(VarModify(file, VarHead, NULL)); -} -#endif - -/*- - *----------------------------------------------------------------------- - * Var_Init -- - * Initialize the module - * - * Results: - * None - * - * Side Effects: - * The VAR_CMD and VAR_GLOBAL contexts are created - *----------------------------------------------------------------------- - */ +/* Initialize the module. */ void Var_Init(void) { VAR_INTERNAL = Targ_NewGN("Internal"); VAR_GLOBAL = Targ_NewGN("Global"); VAR_CMD = Targ_NewGN("Command"); - } @@ -4341,9 +4111,9 @@ Var_End(void) /****************** PRINT DEBUGGING INFO *****************/ static void -VarPrintVar(void *vp) +VarPrintVar(void *vp, void *data MAKE_ATTR_UNUSED) { - Var *v = (Var *)vp; + Var *v = (Var *)vp; fprintf(debug_file, "%-16s = %s\n", v->name, Buf_GetAll(&v->val, NULL)); } @@ -4356,12 +4126,5 @@ VarPrintVar(void *vp) void Var_Dump(GNode *ctxt) { - Hash_Search search; - Hash_Entry *h; - - for (h = Hash_EnumFirst(&ctxt->context, &search); - h != NULL; - h = Hash_EnumNext(&search)) { - VarPrintVar(Hash_GetValue(h)); - } + Hash_ForEach(&ctxt->context, VarPrintVar, NULL); }