Module Name:    src
Committed By:   christos
Date:           Fri Jan 10 16:12:52 UTC 2014

Modified Files:
        src/usr.bin/make: make.1 parse.c

Log Message:
add .INCLUDEDFROM{FILE,DIR}


To generate a diff of this commit:
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/make/make.1
cvs rdiff -u -r1.192 -r1.193 src/usr.bin/make/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.226 src/usr.bin/make/make.1:1.227
--- src/usr.bin/make/make.1:1.226	Thu Nov  7 13:50:46 2013
+++ src/usr.bin/make/make.1	Fri Jan 10 11:12:52 2014
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.226 2013/11/07 18:50:46 dholland Exp $
+.\"	$NetBSD: make.1,v 1.227 2014/01/10 16:12:52 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -638,6 +638,10 @@ target is to be transformed (the
 source); also known as
 .Ql Va \&\*[Lt] .
 It is not defined in explicit rules.
+.It Va .INCLUDEDFROMDIR
+The directory of the file this Makefile was included from.
+.It Va .INCLUDEDFROMFILE
+The filename of the file this Makefile was included from.
 .It Va .MEMBER
 The name of the archive member.
 .It Va .OODATE

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.192 src/usr.bin/make/parse.c:1.193
--- src/usr.bin/make/parse.c:1.192	Fri Oct 18 16:47:06 2013
+++ src/usr.bin/make/parse.c	Fri Jan 10 11:12:52 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.192 2013/10/18 20:47:06 christos Exp $	*/
+/*	$NetBSD: parse.c,v 1.193 2014/01/10 16:12:52 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.192 2013/10/18 20:47:06 christos Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.193 2014/01/10 16:12:52 christos Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.192 2013/10/18 20:47:06 christos Exp $");
+__RCSID("$NetBSD: parse.c,v 1.193 2014/01/10 16:12:52 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -361,6 +361,7 @@ static int ParseAddCmd(void *, void *);
 static void ParseHasCommands(void *);
 static void ParseDoInclude(char *);
 static void ParseSetParseFile(const char *);
+static void ParseSetIncludedFile(void);
 #ifdef SYSVINCLUDE
 static void ParseTraditionalInclude(char *);
 #endif
@@ -845,7 +846,8 @@ ParseLinkSrc(void *pgnp, void *cgnp)
 	    (void)Lst_AtEnd(cgn->parents, pgn);
     pgn->unmade += 1;
     if (DEBUG(PARSE)) {
-	fprintf(debug_file, "# ParseLinkSrc: added child %s - %s\n", pgn->name, cgn->name);
+	fprintf(debug_file, "# %s: added child %s - %s\n", __func__,
+	    pgn->name, cgn->name);
 	Targ_PrintNode(pgn, 0);
 	Targ_PrintNode(cgn, 0);
     }
@@ -1020,8 +1022,8 @@ ParseDoSrc(int tOp, const char *src)
 	    (void)Lst_AtEnd(predecessor->order_succ, gn);
 	    (void)Lst_AtEnd(gn->order_pred, predecessor);
 	    if (DEBUG(PARSE)) {
-		fprintf(debug_file, "# ParseDoSrc: added Order dependency %s - %s\n",
-			predecessor->name, gn->name);
+		fprintf(debug_file, "# %s: added Order dependency %s - %s\n",
+		    __func__, predecessor->name, gn->name);
 		Targ_PrintNode(predecessor, 0);
 		Targ_PrintNode(gn, 0);
 	    }
@@ -2164,6 +2166,7 @@ Parse_include_file(char *file, Boolean i
     /* load it */
     lf = loadfile(fullname, fd);
 
+    ParseSetIncludedFile();
     /* Start reading from this file next */
     Parse_SetInput(fullname, 0, -1, loadedfile_nextbuf, lf);
     curFile->lf = lf;
@@ -2223,6 +2226,41 @@ ParseDoInclude(char *line)
 
 /*-
  *---------------------------------------------------------------------
+ * ParseSetIncludedFile  --
+ *	Set the .INCLUDEDFROMFILE variable to the contents of .PARSEFILE
+ *	and the .INCLUDEDFROMDIR variable to the contents of .PARSEDIR
+ *
+ * Results:
+ *	None
+ *
+ * Side Effects:
+ *	The .INCLUDEDFROMFILE variable is overwritten by the contents
+ *	of .PARSEFILE and the .INCLUDEDFROMDIR variable is overwriten
+ *	but the contents of .PARSEDIR
+ *---------------------------------------------------------------------
+ */
+static void
+ParseSetIncludedFile(void)
+{
+    char *pf, *fp = NULL;
+    char *pd, *dp = NULL;
+
+    pf = Var_Value(".PARSEFILE", VAR_GLOBAL, &fp);
+    Var_Set(".INCLUDEDFROMFILE", pf, VAR_GLOBAL, 0);
+    pd = Var_Value(".PARSEDIR", VAR_GLOBAL, &dp);
+    Var_Set(".INCLUDEDFROMDIR", pd, VAR_GLOBAL, 0);
+
+    if (DEBUG(PARSE))
+	fprintf(debug_file, "%s: ${.INCLUDEDFROMDIR} = `%s' "
+	    "${.INCLUDEDFROMFILE} = `%s'\n", __func__, pd, pf);
+
+    if (fp)
+	free(fp);
+    if (dp)
+	free(dp);
+}
+/*-
+ *---------------------------------------------------------------------
  * ParseSetParseFile  --
  *	Set the .PARSEDIR and .PARSEFILE variables to the dirname and
  *	basename of the given filename
@@ -2256,8 +2294,8 @@ ParseSetParseFile(const char *filename)
 	Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL, 0);
     }
     if (DEBUG(PARSE))
-	fprintf(debug_file, "ParseSetParseFile: ${.PARSEDIR} = `%s' "
-	    "${.PARSEFILE} = `%s'\n", pd, pf);
+	fprintf(debug_file, "%s: ${.PARSEDIR} = `%s' ${.PARSEFILE} = `%s'\n",
+	    __func__, pd, pf);
     free(dirname);
 }
 
@@ -2319,8 +2357,8 @@ Parse_SetInput(const char *name, int lin
 	ParseTrackInput(name);
 
     if (DEBUG(PARSE))
-	fprintf(debug_file, "Parse_SetInput: file %s, line %d, fd %d, nextbuf %p, arg %p\n",
-		name, line, fd, nextbuf, arg);
+	fprintf(debug_file, "%s: file %s, line %d, fd %d, nextbuf %p, arg %p\n",
+	    __func__, name, line, fd, nextbuf, arg);
 
     if (fd == -1 && nextbuf == NULL)
 	/* sanity */
@@ -2392,7 +2430,7 @@ ParseTraditionalInclude(char *line)
     char	  *all_files;
 
     if (DEBUG(PARSE)) {
-	    fprintf(debug_file, "ParseTraditionalInclude: %s\n", file);
+	    fprintf(debug_file, "%s: %s\n", __func__, file);
     }
 
     /*
@@ -2451,7 +2489,7 @@ ParseGmakeExport(char *line)
     char	  *value;
 
     if (DEBUG(PARSE)) {
-	    fprintf(debug_file, "ParseGmakeExport: %s\n", variable);
+	    fprintf(debug_file, "%s: %s\n", __func__, variable);
     }
 
     /*
@@ -2531,6 +2569,7 @@ ParseEOF(void)
 	/* We've run out of input */
 	Var_Delete(".PARSEDIR", VAR_GLOBAL);
 	Var_Delete(".PARSEFILE", VAR_GLOBAL);
+	Var_Delete(".INCLUDED_FROM", VAR_GLOBAL);
 	return DONE;
     }
 

Reply via email to