This is somewhat nasty. bsdmake used to have a simplistic approach to
whitespace (kill everything at end of line).

Unfortunately, that's not how other makes work. nor is it how posix
finally standardized it.

Specifically, for variable definitions: make should strip spaces around
the equal sign (as our make does), but there's nothing that prevents a
space at the end of the line from being preserved.

So I've been running with this fix. I had to fix about 20 makefiles in
our whole system (mostly in ports). NONE were using the whitespace
stripping for anything significant.  They just had "sloppy spaces" at 
end of lines.

There's exactly ZERO makefile in 3rd party software that relies on
whitespace stripping, but the opposite is true: I did add a regress
test concerning this a few years ago...

This brings us closer to having a better, more portable make.
More tests and okays are welcome.



Index: buf.c
===================================================================
RCS file: /home/openbsd/cvs/src/usr.bin/make/buf.c,v
retrieving revision 1.24
diff -u -p -r1.24 buf.c
--- buf.c       21 Sep 2012 07:55:20 -0000      1.24
+++ buf.c       18 Oct 2012 17:55:13 -0000
@@ -161,13 +161,3 @@ Buf_Init(Buffer bp, size_t size)
        bp->inPtr = bp->endPtr = bp->buffer = emalloc(size);
        bp->endPtr += size;
 }
-
-void
-Buf_KillTrailingSpaces(Buffer bp)
-{
-       while (bp->inPtr > bp->buffer + 1 && isspace(bp->inPtr[-1])) {
-               if (bp->inPtr[-2] == '\\')
-                   break;
-               bp->inPtr--;
-       }
-}
Index: buf.h
===================================================================
RCS file: /home/openbsd/cvs/src/usr.bin/make/buf.h,v
retrieving revision 1.21
diff -u -p -r1.21 buf.h
--- buf.h       2 Oct 2012 10:29:30 -0000       1.21
+++ buf.h       18 Oct 2012 17:55:13 -0000
@@ -131,10 +131,6 @@ do {                                               \
  *     Adds characters between s and e to buffer.  */
 #define Buf_Addi(b, s, e)      Buf_AddChars((b), (e) - (s), (s))
 
-/* Buf_KillTrailingSpaces(buf);
- *     Removes non-backslashed spaces at the end of a buffer. */
-extern void Buf_KillTrailingSpaces(Buffer);
-
 extern void Buf_printf(Buffer, const char *, ...);
 #define Buf_puts(b, s) Buf_AddChars((b), strlen(s), (s))
 
Index: lowparse.c
===================================================================
RCS file: /home/openbsd/cvs/src/usr.bin/make/lowparse.c,v
retrieving revision 1.31
diff -u -p -r1.31 lowparse.c
--- lowparse.c  18 Oct 2012 17:54:43 -0000      1.31
+++ lowparse.c  18 Oct 2012 17:55:23 -0000
@@ -450,7 +452,6 @@ Parse_ReadNormalLine(Buffer linebuf)
                return NULL;
        else {
                read_logical_line(linebuf, c);
-               Buf_KillTrailingSpaces(linebuf);
                return Buf_Retrieve(linebuf);
        }
 }
Index: parse.c
===================================================================
RCS file: /home/openbsd/cvs/src/usr.bin/make/parse.c,v
retrieving revision 1.107
diff -u -p -r1.107 parse.c
--- parse.c     9 Oct 2012 19:45:34 -0000       1.107
+++ parse.c     23 Oct 2012 17:01:50 -0000
@@ -1048,7 +1049,6 @@ strip_comments(Buffer copy, const char *
                                break;
                }
                Buf_Addi(copy, line, p);
-               Buf_KillTrailingSpaces(copy);
                return Buf_Retrieve(copy);
        }
 }

Reply via email to