From owner-freebsd-hackers Sat Apr 13 7:18:43 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from snark.ratmir.ru (snark.ratmir.ru [213.24.248.177]) by hub.freebsd.org (Postfix) with ESMTP id 203D537B400 for ; Sat, 13 Apr 2002 07:18:37 -0700 (PDT) Received: from snark.ratmir.ru (freebsd@localhost [127.0.0.1]) by snark.ratmir.ru (8.12.2/8.12.2) with ESMTP id g3DEIZF8018110 for ; Sat, 13 Apr 2002 18:18:35 +0400 (MSD) (envelope-from freebsd@snark.ratmir.ru) Received: (from freebsd@localhost) by snark.ratmir.ru (8.12.2/8.12.2/Submit) id g3DEIYV9018109 for freebsd-hackers@FreeBSD.ORG; Sat, 13 Apr 2002 18:18:34 +0400 (MSD) Date: Sat, 13 Apr 2002 18:18:34 +0400 From: Alex Semenyaka To: freebsd-hackers@FreeBSD.ORG Subject: make(1) command-line variables Message-ID: <20020413141834.GA16339@snark.ratmir.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.28i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Dear Colleagues, I need some help. Consider I have a Makefile for application that can be build with different options. Some of them I need just to define via -D flag of the ``make'', but other need to be set to some specific values (for example, it can be path to my temporary dir). So I use make -DFIRST MYTMPDIR=/special/tmp And I want just to keep track of the parameters used to build that application. Nothing difficult to obtain the name of Makefile from .MAKEFILE, as well as make flags of make (including those -D, defining some variables) from the .MAKEFLAGS var. But I did NOT found the normal way to obtain the list of variables defined in the command line through the VAR=VAL construction. Strange, right? Man says that .MAKEFLAGS 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. That is wrong, .MAKEFLAGS does not contain anything. It _is_ reasonable to cut the -f flag from there, for example. But a bit strange to cut the value assignments, I think. Mayby I am wrong so I would appreciate explanation why Actually I did a small patch to gather the information about that variables (with quoted values where necessary) into the new internal variable .MAKECMDVARS; if people will tell me that this is the Good Thing or explain how to do the Good Thing from it - I would glad to make final variant and to share it with other. Just a note: I decided not to change the .MAKEFLAGS variable just for the backward compatibility. Of course there is nothing special to store same information there (as well or instead). Here is my current patch: diff -u /usr/src/usr.bin/make/main.c Make/main.c --- /usr/src/usr.bin/make/main.c Sun Mar 4 12:40:32 2001 +++ Make/main.c Sat Apr 13 13:10:53 2002 @@ -113,6 +113,7 @@ #endif /* DEFMAXLOCAL */ #define MAKEFLAGS ".MAKEFLAGS" +#define MAKECMDVARS ".MAKECMDVARS" Lst create; /* Targets to be made */ time_t now; /* Time at start of make */ @@ -171,8 +172,9 @@ { extern int optind; extern char *optarg; + char *peq, *pval, *escvar; char *p; - int c; + int c, offs; optind = 1; /* since we're called more than once */ #ifdef REMOTE @@ -369,8 +371,21 @@ * on the end of the "create" list. */ for (argv += optind, argc -= optind; *argv; ++argv, --argc) - if (Parse_IsVar(*argv)) - Parse_DoVar(*argv, VAR_CMD); + if (Parse_IsVar(*argv)) { + peq = strchr(*argv,'=') + 1; + offs = (int) (peq - (*argv)); + pval = VarQuote(peq); + + escvar = malloc(offs + strlen(pval) + 1); + strncpy(escvar, *argv, offs); + strcat(escvar, pval); + + Var_Append(MAKECMDVARS, escvar, VAR_GLOBAL); + + free(pval); free(escvar); + + Parse_DoVar(*argv, VAR_CMD); + } else { if (!**argv) Punt("illegal (null) argument."); diff -u /usr/src/usr.bin/make/nonints.h Make/nonints.h --- /usr/src/usr.bin/make/nonints.h Sat Aug 28 05:03:35 1999 +++ Make/nonints.h Sat Apr 13 12:54:41 2002 @@ -146,3 +146,4 @@ void Var_Init __P((void)); void Var_End __P((void)); void Var_Dump __P((GNode *)); +char *VarQuote __P((char *)); diff -u /usr/src/usr.bin/make/var.c Make/var.c --- /usr/src/usr.bin/make/var.c Thu Feb 28 02:43:45 2002 +++ Make/var.c Sat Apr 13 12:58:06 2002 @@ -188,7 +188,6 @@ static Boolean VarSubstitute __P((char *, Boolean, Buffer, ClientData)); static char *VarGetPattern __P((GNode *, int, char **, int, int *, int *, VarPattern *)); -static char *VarQuote __P((char *)); static char *VarModify __P((char *, Boolean (*)(char *, Boolean, Buffer, ClientData), ClientData)); @@ -1411,7 +1410,7 @@ * *----------------------------------------------------------------------- */ -static char * +char * VarQuote(str) char *str; { Sincerely yours, Alex Semenyaka. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message