Subject: new make variables
To: None <tech-userlevel@NetBSD.org>
From: Aidan Cully <aidan@kublai.com>
List: tech-userlevel
Date: 08/08/1999 03:03:37
--p3P2qPhRSkvwRMAI
Content-Type: text/plain; charset=us-ascii

I'd like to modify make so that it'll define two new variables for name
and directory of the Makefile currently being parsed.  This would be
used for a modification to the Makefile.frag's in domestic/*/, where
SUBDIR+=${CRYPTOPATH}/libkrb
could be replaced with
USLIBDIR:=${.PARSEDIR}
SUBDIR+=${USLIBDIR}/libkrb

Then CRYPTOBASE could be replaced with a list of crypto trees, in the
order you'd like them applied, with a bit of foo in the src/lib/Makefile
&c., like this (untested):

.for BASE in ${CRYPTOBASES}
.sinclude "${SRCTOP}/${BASE}/lib/Makefile.frag"
.endfor

Patches for this follow.  Feedback?

--aidan

--p3P2qPhRSkvwRMAI
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="parse.patch"

--- parse.c.orig	Sat Aug  7 19:36:55 1999
+++ parse.c	Sat Aug  7 19:50:31 1999
@@ -1664,6 +1664,7 @@
     Boolean 	  isSystem; 	/* TRUE if makefile is a system makefile */
     int		  silent = (*line != 'i') ? 1 : 0;
     char	  *file = &line[7 + silent];
+    char	  *slash;
 
     /*
      * Skip to delimiter character so we know where to look
@@ -1808,6 +1809,17 @@
     fname = fullname;
     lineno = 0;
 
+    slash = strrchr(fullname, '/');
+    if (slash == 0) {
+	Var_Set(".PARSEDIR", ".", VAR_GLOBAL);
+	Var_Set(".PARSEFILE", fullname, VAR_GLOBAL);
+    } else {
+	*slash = '\0';
+	Var_Set(".PARSEDIR", fullname, VAR_GLOBAL);
+	Var_Set(".PARSEFILE", slash+1, VAR_GLOBAL);
+	*slash = '/';
+    }
+
     curFILE = fopen (fullname, "r");
     curPTR = NULL;
     if (curFILE == (FILE * ) NULL) {
@@ -2039,8 +2051,11 @@
     int opened;
 {
     IFile     *ifile;	/* the state on the top of the includes stack */
+    char      *slash;
 
     if (Lst_IsEmpty (includes)) {
+	Var_Delete(".PARSEDIR", VAR_GLOBAL);
+	Var_Delete(".PARSEFILE", VAR_GLOBAL);
 	return (DONE);
     }
 
@@ -2057,6 +2072,18 @@
     curFILE = ifile->F;
     curPTR = ifile->p;
     free ((Address)ifile);
+
+    /* pop the PARSEDIR/PARSEFILE variables */
+    slash = strrchr(fname, '/');
+    if (slash == 0) {
+	Var_Set(".PARSEDIR", ".", VAR_GLOBAL);
+	Var_Set(".PARSEFILE", fname, VAR_GLOBAL);
+    } else {
+	*slash = '\0';
+	Var_Set(".PARSEDIR", fname, VAR_GLOBAL);
+	Var_Set(".PARSEFILE", slash+1, VAR_GLOBAL);
+	*slash = '/';
+    }
     return (CONTINUE);
 }
 
@@ -2468,12 +2495,24 @@
 {
     register char *cp,		/* pointer into the line */
                   *line;	/* the line we're working on */
+    char          *slash;
 
     inLine = FALSE;
     fname = name;
     curFILE = stream;
     lineno = 0;
     fatals = 0;
+
+    slash = strrchr(fname, '/');
+    if (slash == 0) {
+	Var_Set(".PARSEDIR", ".", VAR_GLOBAL);
+	Var_Set(".PARSEFILE", fname, VAR_GLOBAL);
+    } else {
+	*slash = '\0';
+	Var_Set(".PARSEDIR", fname, VAR_GLOBAL);
+	Var_Set(".PARSEFILE", slash+1, VAR_GLOBAL);
+	*slash = '/';
+    }
 
     do {
 	while ((line = ParseReadLine ()) != NULL) {

--p3P2qPhRSkvwRMAI--