From owner-freebsd-standards@FreeBSD.ORG Sun Sep 28 14:50:21 2003 Return-Path: Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B576316A4B3 for ; Sun, 28 Sep 2003 14:50:21 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 24FE144029 for ; Sun, 28 Sep 2003 14:50:21 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h8SLoKFY009742 for ; Sun, 28 Sep 2003 14:50:20 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h8SLoKKG009740; Sun, 28 Sep 2003 14:50:20 -0700 (PDT) (envelope-from gnats) Date: Sun, 28 Sep 2003 14:50:20 -0700 (PDT) Message-Id: <200309282150.h8SLoKKG009740@freefall.freebsd.org> To: freebsd-standards@FreeBSD.org From: "James E. Flemer" Subject: Re: standards/57295: [patch] make does not include cmd line variables in MAKEFLAGS X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: "James E. Flemer" List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Sep 2003 21:50:21 -0000 The following reply was made to PR standards/57295; it has been noted by GNATS. From: "James E. Flemer" To: FreeBSD-gnats-submit@freebsd.org Cc: Subject: Re: standards/57295: [patch] make does not include cmd line variables in MAKEFLAGS Date: Sun, 28 Sep 2003 17:42:45 -0400 (EDT) The patch I submitted does not do necessary quoting when values contain spaces etc. It turns out that OpenBSD has a fix for the MAKEFLAGS issue that fits into FreeBSD make with a few modifications. Here is a patch based on the OpenBSD solution. Some changes were needed to match our data structures, but the functionality is directly from the OpenBSD commit. Obtained From: OpenBSD $OpenBSD: var.c,v 1.46 2000/07/18 20:17:20 espie Exp $ $OpenBSD: main.c,v 1.39 2000/07/18 20:17:20 espie Exp $ --- make.diff begins here --- Index: main.c =================================================================== RCS file: /home/ncvs/src/usr.bin/make/main.c,v retrieving revision 1.84 diff -u -r1.84 main.c --- main.c 14 Sep 2003 12:31:33 -0000 1.84 +++ main.c 28 Sep 2003 21:17:09 -0000 @@ -616,6 +616,10 @@ MainParseArgs(argc, argv); +#ifdef POSIX + Var_AddCmdline(MAKEFLAGS); +#endif + /* * Find where we are... * All this code is so that we know where we are when we start up Index: nonints.h =================================================================== RCS file: /home/ncvs/src/usr.bin/make/nonints.h,v retrieving revision 1.19 diff -u -r1.19 nonints.h --- nonints.h 28 Oct 2002 23:33:57 -0000 1.19 +++ nonints.h 28 Sep 2003 21:17:09 -0000 @@ -135,6 +135,7 @@ void Var_Append(char *, char *, GNode *); Boolean Var_Exists(char *, GNode *); char *Var_Value(char *, GNode *, char **); +void Var_AddCmdLine(char *); char *Var_Parse(char *, GNode *, Boolean, int *, Boolean *); char *Var_Subst(char *, char *, GNode *, Boolean); char *Var_GetTail(char *); Index: var.c =================================================================== RCS file: /home/ncvs/src/usr.bin/make/var.c,v retrieving revision 1.43 diff -u -r1.43 var.c --- var.c 18 Sep 2003 03:15:57 -0000 1.43 +++ var.c 28 Sep 2003 21:17:09 -0000 @@ -832,6 +832,42 @@ } +#ifdef POSIX + + +/* In POSIX mode, variable assignments passed on the command line are + * propagated to sub makes through MAKEFLAGS. + */ +void +Var_AddCmdline(char *name) +{ + const Var *v; + LstNode ln; + unsigned int i; + Buffer buf; + static const char quotable[] = " \t\n\\'\""; + char *s; + + buf = Buf_Init (MAKE_BSIZE); + + for (ln = Lst_First(VAR_CMD->context); ln != NULL; + ln = Lst_Succ(ln)) { + /* We assume variable names don't need quoting */ + v = (Var *)Lst_Datum(ln); + Buf_AddBytes(buf, strlen(v->name), v->name); + Buf_AddByte(buf, '='); + for (s = Buf_GetAll(v->val, (int *)NULL); *s != '\0'; s++) { + if (strchr(quotable, *s)) + Buf_AddByte(buf, '\\'); + Buf_AddByte(buf, *s); + } + Buf_AddByte(buf, ' '); + } + Var_Append(name, Buf_GetAll(buf, (int *)NULL), VAR_GLOBAL); + Buf_Destroy(buf, 1); +} +#endif + /*- *----------------------------------------------------------------------- * Var_Parse -- --- make.diff ends here ---