tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bmake: variable modifiers in SysV include



In article <77437.1522782722%kaos.jnpr.net@localhost>,
Simon J. Gerraty <sjg%juniper.net@localhost> wrote:
>Simon J. Gerraty <sjg%juniper.net@localhost> wrote:
>> > It doesn't require historical memory. The test is there is so rules
>> > like
>> > 
>> >    include lib bin sbin etc:
>> >            mkdir $@ && cd $@ && $(MAKE) -f $(SRC)/$@/Makefile
>> > 
>> > are not mishandled as inclusions. Use the bmake include syntax; it was
>> > put there for a reason.
>> > 
>> > If you're trying to write a portable makefile, you should limit
>> > yourself to reliable constructions; I very much doubt your own example
>> > will work reliably in vintage make dialects.
>> 
>> FWIW the existing test could ignore ':' if followed by non-white-space.
>
>Something like?
>
>Index: parse.c
>===================================================================
>RCS file: /cvsroot/src/usr.bin/make/parse.c,v
>retrieving revision 1.227
>diff -u -p -r1.227 parse.c
>--- parse.c	22 Feb 2018 01:59:28 -0000	1.227
>+++ parse.c	3 Apr 2018 19:09:09 -0000
>@@ -3073,7 +3073,8 @@ Parse_File(const char *name, int fd)
> 			((line[0] == 's' || line[0] == '-') &&
> 			    strncmp(&line[1], "include", 7) == 0 &&
> 			    isspace((unsigned char) line[8]))) &&
>-		    strchr(line, ':') == NULL) {
>+		((cp = strchr(line, ':')) == NULL ||
>+		 (cp[1] != '\0' && !isspace((int)cp[1])))) {

Let's clean up the mess...

christos

Index: parse.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/parse.c,v
retrieving revision 1.227
diff -u -u -r1.227 parse.c
--- parse.c	22 Feb 2018 01:59:28 -0000	1.227
+++ parse.c	3 Apr 2018 20:48:43 -0000
@@ -2950,6 +2950,40 @@
 }
 
 
+#ifdef SYSVINCLUDE
+/*-
+ *-----------------------------------------------------------------------
+ * IsSysVInclude --
+ *	Check if the line is a SYSV include directive
+ *
+ * Results:
+ *	TRUE if it is.
+ *
+ * Side Effects:
+ *	None
+ *
+ *-----------------------------------------------------------------------
+ */
+static Boolean
+IsSysVInclude(const char *line)
+{
+	size_t o = line[0] == 's' || line[0] == '-' ? 1 : 0;
+	char *p;
+
+	if (strncmp(line + o, "include", 7) != 0)
+		return FALSE;
+	if (!isspace((unsigned char) line[7 + o]))
+		return FALSE;
+
+	/* Avoid interpeting a dependency line as an include */
+	if ((p = strchr(line, ':')) == NULL)
+		return TRUE;
+
+	/* Heuristic: looking for a : followed by a space */
+	return p[1] != '\0' && !isspace((unsigned char)p[1]);
+}
+#endif
+
 /*-
  *---------------------------------------------------------------------
  * Parse_File --
@@ -3068,12 +3102,8 @@
 	    }
 
 #ifdef SYSVINCLUDE
-	    if (((strncmp(line, "include", 7) == 0 &&
-		    isspace((unsigned char) line[7])) ||
-			((line[0] == 's' || line[0] == '-') &&
-			    strncmp(&line[1], "include", 7) == 0 &&
-			    isspace((unsigned char) line[8]))) &&
-		    strchr(line, ':') == NULL) {
+	    if (IsSysVInclude(line)) {
+
 		/*
 		 * It's an S3/S5-style "include".
 		 */



Home | Main Index | Thread Index | Old Index