Module Name:    src
Committed By:   sjg
Date:           Sat Dec 22 00:36:32 UTC 2018

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

Log Message:
ParseVErrorInternal: use .PARSEDIR and
apply realpath(3) if not absolute,
and use .PARSEFILE for consitent results.

Reviewed by: christos


To generate a diff of this commit:
cvs rdiff -u -r1.230 -r1.231 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/parse.c
diff -u src/usr.bin/make/parse.c:1.230 src/usr.bin/make/parse.c:1.231
--- src/usr.bin/make/parse.c:1.230	Mon Dec 17 02:06:00 2018
+++ src/usr.bin/make/parse.c	Sat Dec 22 00:36:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.230 2018/12/17 02:06:00 christos Exp $	*/
+/*	$NetBSD: parse.c,v 1.231 2018/12/22 00:36:32 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.230 2018/12/17 02:06:00 christos Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.231 2018/12/22 00:36:32 sjg 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.230 2018/12/17 02:06:00 christos Exp $");
+__RCSID("$NetBSD: parse.c,v 1.231 2018/12/22 00:36:32 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -676,21 +676,32 @@ ParseVErrorInternal(FILE *f, const char 
 	if (cfname != NULL) {
 		(void)fprintf(f, "\"");
 		if (*cfname != '/' && strcmp(cfname, "(stdin)") != 0) {
-			char *cp;
-			const char *dir;
+			char *cp, *cp2;
+			const char *dir, *fname;
 
 			/*
 			 * Nothing is more annoying than not knowing
 			 * which Makefile is the culprit; we try ${.PARSEDIR}
-			 * first and if that's not absolute, we try ${.CURDIR}
+			 * and apply realpath(3) if not absolute.
 			 */
 			dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &cp);
-			if (dir == NULL || *dir == '\0' || *dir != '/')
-				dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp);
 			if (dir == NULL)
 				dir = ".";
-
-			(void)fprintf(f, "%s/%s", dir, cfname);
+			if (*dir != '/') {
+				dir = cp2 = realpath(dir, NULL);
+				free(cp);
+				cp = cp2; /* cp2 set to NULL by Var_Value */
+			}
+			fname = Var_Value(".PARSEFILE", VAR_GLOBAL, &cp2);
+			if (fname == NULL) {
+				if ((fname = strrchr(cfname, '/')))
+					fname++;
+				else
+					fname = cfname;
+			}
+			(void)fprintf(f, "%s/%s", dir, fname);
+			free(cp2);
+			free(cp);
 		} else
 			(void)fprintf(f, "%s", cfname);
 

Reply via email to