Date: Fri, 9 Jul 2004 13:54:56 +0200 From: dada@sbox.tugraz.at To: FreeBSD problem reports <freebsd-gnats-submit@FreeBSD.org> Subject: bin/68853: [PATCH] make(1) can not pass command line variables to subprocesses Message-ID: <20040709135456.h6q8cgc8cgoosg8o@webmail.tugraz.at> Resent-Message-ID: <200407091200.i69C0x21045117@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 68853 >Category: bin >Synopsis: [PATCH] make(1) can not pass command line variables to submakes >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jul 09 12:00:58 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Martin Kammerhofer >Release: FreeBSD 4.10-STABLE i386 >Organization: Graz UNI >Environment: System: FreeBSD Martin.liebt.Susi 4.10-STABLE FreeBSD 4.10-STABLE #2: Wed Jul 7 19:43:28 CEST 2004 toor@Martin.liebt.Susi:/usr/src/sys/compile/GEIDORF4 i386 >Description: Make Variables (aka "Macros" in SUS) specified on the command line (e.g. "make CFLAGS=...") override assignments in Makefiles or environment variables. According to the manpage an SUSv3 they should override in the context of recursive make invocations too! Quote from the make(1) manpage: The environment variable MAKEFLAGS may contain anything that may be specified on make's command line. Its contents are stored in make's .MAKEFLAGS variable. Anything specified on make's command line is appended to the .MAKEFLAGS variable which is then entered into the environment as MAKEFLAGS for all programs which make executes. Current behavior is that sub-makes get command line assignments only via environ where they have lower precedence than assignments in Makefile (unless option -e is used). This can lead to different variable values (and make behavior) even with the same Makefile. (Btw, I noticed this long standing bug because PMake sometimes behaves different than GNU Make on identical Automake-generated Makefiles.) >How-To-Repeat: /var/tmp$ cat Makefile # This -*-Makefile-*- is understood by PMake and GNU Make A = changed from Makefile main: Makefile echo "MAKEFLAGS='$(MAKEFLAGS)' $(MAKE)" $(MAKE) -f $? print print: echo "A = '$(A)'" /var/tmp$ make -s A="KEEP THIS" MAKEFLAGS=' -s' make A = 'changed from Makefile' >Fix: Quote shell meta characters of command line variable assignments and put them into ${.MAKEFLAGS}. Use existing function VarQuote for this purpose. (Renamed as Var_Quote to follow existing extern vs. static function naming convention.) Bump MAKE_VERSION. Patch below is against -current: diff -ruN make.orig/Makefile make/Makefile --- make.orig/Makefile Tue Oct 29 00:33:57 2002 +++ make/Makefile Fri Jul 9 00:43:50 2004 @@ -15,7 +15,7 @@ NOSHARED?= YES -CFLAGS+=-DMAKE_VERSION=\"5200209170\" +CFLAGS+=-DMAKE_VERSION=\"5200407090\" .if defined(_UPGRADING) CFLAGS+=-D__FBSDID=__RCSID .endif diff -ruN make.orig/main.c make/main.c --- make.orig/main.c Mon Apr 5 19:02:08 2004 +++ make/main.c Fri Jul 9 01:01:20 2004 @@ -348,8 +348,10 @@ * on the end of the "create" list. */ for (argv += optind, argc -= optind; *argv; ++argv, --argc) - if (Parse_IsVar(*argv)) + if (Parse_IsVar(*argv)) { + Var_Append(MAKEFLAGS, Var_Quote(*argv), VAR_GLOBAL); Parse_DoVar(*argv, VAR_CMD); + } else { if (!**argv) Punt("illegal (null) argument."); diff -ruN make.orig/nonints.h make/nonints.h --- make.orig/nonints.h Wed Mar 10 22:51:06 2004 +++ make/nonints.h Fri Jul 9 01:11:31 2004 @@ -139,6 +139,7 @@ char *Var_Subst(char *, char *, GNode *, Boolean); char *Var_GetTail(char *); char *Var_GetHead(char *); +char *Var_Quote(const char *); void Var_Init(void); void Var_End(void); void Var_Dump(GNode *); diff -ruN make.orig/var.c make/var.c --- make.orig/var.c Mon Jan 12 11:35:46 2004 +++ make/var.c Fri Jul 9 01:01:20 2004 @@ -137,7 +137,6 @@ static void VarDelete(void *); static char *VarGetPattern(GNode *, int, char **, int, int *, int *, VarPattern *); -static char *VarQuote(const char *); static char *VarModify(char *, Boolean (*)(const char *, Boolean, Buffer, void *), void *); @@ -773,7 +772,7 @@ /*- *----------------------------------------------------------------------- - * VarQuote -- + * Var_Quote -- * Quote shell meta-characters in the string * * Results: @@ -784,8 +783,8 @@ * *----------------------------------------------------------------------- */ -static char * -VarQuote(const char *str) +char * +Var_Quote(const char *str) { Buffer buf; @@ -1488,7 +1487,7 @@ /* FALLTHROUGH */ case 'Q': if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarQuote (str); + newStr = Var_Quote (str); cp = tstr + 1; termc = *cp; break; --=_44uo0lf1o0w0-- >Release-Note: >Audit-Trail: >Unformatted: This message is in MIME format. --=_44uo0lf1o0w0 Content-Type: text/plain; charset="ISO-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 7bit --=_44uo0lf1o0w0 Content-Type: text/plain; charset="ISO-8859-1"; name="make-PR" Content-Disposition: inline; filename="make-PR" Content-Transfer-Encoding: 7bit
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040709135456.h6q8cgc8cgoosg8o>