Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): no declaration-after-statement anymore



details:   https://anonhg.NetBSD.org/src/rev/8ebbedf0f641
branches:  trunk
changeset: 936982:8ebbedf0f641
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 03 20:26:09 2020 +0000

description:
make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89.  This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments.  These will be fixed in a follow-up commit.

diffstat:

 usr.bin/make/Makefile |    4 +-
 usr.bin/make/arch.c   |   13 +-
 usr.bin/make/buf.c    |    9 +-
 usr.bin/make/cond.c   |    8 +-
 usr.bin/make/dir.c    |   21 +-
 usr.bin/make/for.c    |   16 +-
 usr.bin/make/main.c   |   31 ++-
 usr.bin/make/meta.c   |    9 +-
 usr.bin/make/parse.c  |   17 +-
 usr.bin/make/str.c    |   33 ++-
 usr.bin/make/trace.c  |    8 +-
 usr.bin/make/var.c    |  352 +++++++++++++++++++++++++++++++------------------
 12 files changed, 325 insertions(+), 196 deletions(-)

diffs (truncated from 1713 to 300 lines):

diff -r 1e882ce4307f -r 8ebbedf0f641 usr.bin/make/Makefile
--- a/usr.bin/make/Makefile     Mon Aug 03 19:44:06 2020 +0000
+++ b/usr.bin/make/Makefile     Mon Aug 03 20:26:09 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.78 2020/08/01 21:48:17 rillig Exp $
+#      $NetBSD: Makefile,v 1.79 2020/08/03 20:26:09 rillig Exp $
 #      @(#)Makefile    5.2 (Berkeley) 12/28/90
 
 PROG=  make
@@ -73,6 +73,8 @@
 COPTS.meta.c+= ${GCC_NO_FORMAT_TRUNCATION}
 COPTS.parse.c+=        ${GCC_NO_FORMAT_TRUNCATION}
 
+COPTS+=                -Wdeclaration-after-statement
+
 # A simple unit-test driver to help catch regressions
 test: .MAKE
        cd ${.CURDIR}/unit-tests \
diff -r 1e882ce4307f -r 8ebbedf0f641 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Mon Aug 03 19:44:06 2020 +0000
+++ b/usr.bin/make/arch.c       Mon Aug 03 20:26:09 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.80 2020/08/01 14:47:49 rillig Exp $ */
+/*     $NetBSD: arch.c,v 1.81 2020/08/03 20:26:09 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.80 2020/08/01 14:47:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.81 2020/08/03 20:26:09 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c     8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.80 2020/08/01 14:47:49 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.81 2020/08/03 20:26:09 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -624,6 +624,8 @@
             */
            goto badarch;
        } else {
+           char *nameend;
+
            /*
             * We need to advance the stream's pointer to the start of the
             * next header. Files are padded with newlines to an even-byte
@@ -634,7 +636,7 @@
            size = (int)strtol(arh.ar_size, NULL, 10);
 
            memcpy(memName, arh.ar_name, sizeof(arh.ar_name));
-           char *nameend = memName + AR_MAX_NAME_LEN;
+           nameend = memName + AR_MAX_NAME_LEN;
            while (*nameend == ' ') {
                nameend--;
            }
@@ -851,6 +853,7 @@
     int                  size;       /* Size of archive member */
     char         magic[SARMAG];
     size_t       len, tlen;
+    const char *  base;
 
     arch = fopen(archive, mode);
     if (arch == NULL) {
@@ -873,7 +876,7 @@
      * to point 'member' to the final component, if there is one, to make
      * the comparisons easier...
      */
-    const char *base = strrchr(member, '/');
+    base = strrchr(member, '/');
     if (base != NULL) {
        member = base + 1;
     }
diff -r 1e882ce4307f -r 8ebbedf0f641 usr.bin/make/buf.c
--- a/usr.bin/make/buf.c        Mon Aug 03 19:44:06 2020 +0000
+++ b/usr.bin/make/buf.c        Mon Aug 03 20:26:09 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: buf.c,v 1.30 2020/08/01 21:51:22 rillig Exp $  */
+/*     $NetBSD: buf.c,v 1.31 2020/08/03 20:26:09 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: buf.c,v 1.30 2020/08/01 21:51:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: buf.c,v 1.31 2020/08/03 20:26:09 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)buf.c      8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: buf.c,v 1.30 2020/08/01 21:51:22 rillig Exp $");
+__RCSID("$NetBSD: buf.c,v 1.31 2020/08/03 20:26:09 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -107,13 +107,14 @@
 Buf_AddBytesZ(Buffer *bp, const Byte *bytesPtr, size_t numBytes)
 {
     size_t count = bp->count;
+    Byte *ptr;
 
     if (__predict_false(count + numBytes >= bp->size)) {
        bp->size += max(bp->size, numBytes + 16);
        bp->buffer = bmake_realloc(bp->buffer, bp->size);
     }
 
-    Byte *ptr = bp->buffer + count;
+    ptr = bp->buffer + count;
     bp->count = count + numBytes;
     memcpy(ptr, bytesPtr, numBytes);
     ptr[numBytes] = '\0';
diff -r 1e882ce4307f -r 8ebbedf0f641 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Mon Aug 03 19:44:06 2020 +0000
+++ b/usr.bin/make/cond.c       Mon Aug 03 20:26:09 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.87 2020/08/01 21:40:49 rillig Exp $ */
+/*     $NetBSD: cond.c,v 1.88 2020/08/03 20:26:09 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: cond.c,v 1.87 2020/08/01 21:40:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.88 2020/08/03 20:26:09 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c     8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.87 2020/08/01 21:40:49 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.88 2020/08/03 20:26:09 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -241,6 +241,7 @@
     Buffer       buf;
     int           paren_depth;
     char          ch;
+    size_t       argLen;
 
     cp = *linePtr;
     if (func != NULL)
@@ -300,7 +301,6 @@
        cp++;
     }
 
-    size_t argLen;
     *argPtr = Buf_GetAllZ(&buf, &argLen);
     Buf_Destroy(&buf, FALSE);
 
diff -r 1e882ce4307f -r 8ebbedf0f641 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Mon Aug 03 19:44:06 2020 +0000
+++ b/usr.bin/make/dir.c        Mon Aug 03 20:26:09 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.83 2020/08/01 14:47:49 rillig Exp $  */
+/*     $NetBSD: dir.c,v 1.84 2020/08/03 20:26:09 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.83 2020/08/01 14:47:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.84 2020/08/03 20:26:09 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c      8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.83 2020/08/01 14:47:49 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.84 2020/08/03 20:26:09 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -733,6 +733,11 @@
     const char *middle = brace + 1;
     const char *middle_end = closing_brace(middle);
     size_t middle_len = (size_t)(middle_end - middle);
+    const char *prefix;
+    size_t prefix_len;
+    const char *suffix;
+    size_t suffix_len;
+    const char *piece;
 
     if (DEBUG(DIR)) {
        fprintf(debug_file, "%s: word=\"%s\" middle=\"%.*s\"\n",
@@ -744,14 +749,14 @@
        return;
     }
 
-    const char *prefix = word;
-    size_t prefix_len = (size_t)(brace - prefix);
-    const char *suffix = middle_end + 1;
-    size_t suffix_len = strlen(suffix);
+    prefix = word;
+    prefix_len = (size_t)(brace - prefix);
+    suffix = middle_end + 1;
+    suffix_len = strlen(suffix);
 
     /* Split the middle into pieces, separated by commas. */
 
-    const char *piece = middle;
+    piece = middle;
     while (piece < middle_end + 1) {
        const char *piece_end = separator_comma(piece);
        size_t piece_len = (size_t)(piece_end - piece);
diff -r 1e882ce4307f -r 8ebbedf0f641 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Mon Aug 03 19:44:06 2020 +0000
+++ b/usr.bin/make/for.c        Mon Aug 03 20:26:09 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: for.c,v 1.60 2020/08/02 08:10:36 rillig Exp $  */
+/*     $NetBSD: for.c,v 1.61 2020/08/03 20:26:09 rillig Exp $  */
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.60 2020/08/02 08:10:36 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.61 2020/08/03 20:26:09 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)for.c      8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: for.c,v 1.60 2020/08/02 08:10:36 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.61 2020/08/03 20:26:09 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -316,6 +316,8 @@
 for_var_len(const char *var)
 {
     char ch, var_start, var_end;
+    int depth;
+    size_t len;
 
     var_start = *var;
     if (var_start == 0)
@@ -330,8 +332,7 @@
        /* Single char variable */
        return 1;
 
-    int depth = 1;
-    size_t len;
+    depth = 1;
     for (len = 1; (ch = var[len++]) != 0;) {
        if (ch == var_start)
            depth++;
@@ -346,6 +347,8 @@
 static void
 for_substitute(Buffer *cmds, strlist_t *items, unsigned int item_no, char ech)
 {
+    char ch;
+
     const char *item = strlist_str(items, item_no);
 
     /* If there were no escapes, or the only escape is the other variable
@@ -357,7 +360,6 @@
     }
 
     /* Escape ':', '$', '\\' and 'ech' - removed by :U processing */
-    char ch;
     while ((ch = *item++) != 0) {
        if (ch == '$') {
            size_t len = for_var_len(item);
@@ -384,6 +386,7 @@
     char *body_end;
     char ch;
     Buffer cmds;
+    size_t cmd_len;
 
     if (arg->sub_next + strlist_num(&arg->vars) > strlist_num(&arg->items)) {
        /* No more iterations */
@@ -406,7 +409,6 @@
      * to contrive a makefile where an unwanted substitution happens.
      */
 
-    size_t cmd_len;
     cmd_cp = Buf_GetAllZ(&arg->buf, &cmd_len);
     body_end = cmd_cp + cmd_len;
     Buf_InitZ(&cmds, cmd_len + 256);
diff -r 1e882ce4307f -r 8ebbedf0f641 usr.bin/make/main.c



Home | Main Index | Thread Index | Old Index