BSD 4_4_Lite1 release
[unix-history] / usr / src / usr.bin / make / main.c
index 1908f0e..7b3f5a5 100644 (file)
@@ -1,35 +1,49 @@
 /*
 /*
- * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
- * Copyright (c) 1988, 1989 by Adam de Boor
+ * Copyright (c) 1988, 1989, 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  * Copyright (c) 1989 by Berkeley Softworks
  * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Adam de Boor.
  *
  * Copyright (c) 1989 by Berkeley Softworks
  * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Adam de Boor.
  *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement:  ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * Neither the name of the University nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.22 (Berkeley) 6/28/90";
+static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #endif /* not lint */
 
 /*-
 #endif /* not lint */
 
 /*-
@@ -59,13 +73,24 @@ static char sccsid[] = "@(#)main.c  5.22 (Berkeley) 6/28/90";
  *                             exiting.
  */
 
  *                             exiting.
  */
 
+#include <sys/types.h>
+#include <sys/time.h>
 #include <sys/param.h>
 #include <sys/param.h>
+#include <sys/resource.h>
 #include <sys/signal.h>
 #include <sys/stat.h>
 #include <sys/signal.h>
 #include <sys/stat.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <stdio.h>
+#if __STDC__
+#include <stdarg.h>
+#else
 #include <varargs.h>
 #include <varargs.h>
+#endif
 #include "make.h"
 #include "make.h"
+#include "hash.h"
+#include "dir.h"
+#include "job.h"
 #include "pathnames.h"
 
 #ifndef        DEFMAXLOCAL
 #include "pathnames.h"
 
 #ifndef        DEFMAXLOCAL
@@ -83,6 +108,7 @@ static Boolean               noBuiltins;     /* -r flag */
 static Lst             makefiles;      /* ordered list of makefiles to read */
 int                    maxJobs;        /* -J argument */
 static int             maxLocal;       /* -L argument */
 static Lst             makefiles;      /* ordered list of makefiles to read */
 int                    maxJobs;        /* -J argument */
 static int             maxLocal;       /* -L argument */
+Boolean                        compatMake;     /* -B argument */
 Boolean                        debug;          /* -d flag */
 Boolean                        noExecute;      /* -n flag */
 Boolean                        keepgoing;      /* -k flag */
 Boolean                        debug;          /* -d flag */
 Boolean                        noExecute;      /* -n flag */
 Boolean                        keepgoing;      /* -k flag */
@@ -96,8 +122,10 @@ Boolean                     checkEnvFirst;  /* -e flag */
 static Boolean         jobsRunning;    /* TRUE if the jobs might be running */
 
 static Boolean         ReadMakefile();
 static Boolean         jobsRunning;    /* TRUE if the jobs might be running */
 
 static Boolean         ReadMakefile();
+static void            usage();
 
 
-static char *curdir;                   /* if chdir'd for an architecture */
+static char *curdir;                   /* startup directory */
+static char *objdir;                   /* where we chdir'ed to */
 
 /*-
  * MainParseArgs --
 
 /*-
  * MainParseArgs --
@@ -120,12 +148,15 @@ MainParseArgs(argc, argv)
 {
        extern int optind;
        extern char *optarg;
 {
        extern int optind;
        extern char *optarg;
-       register int i;
-       register char *cp;
        char c;
 
        optind = 1;     /* since we're called more than once */
        char c;
 
        optind = 1;     /* since we're called more than once */
-rearg: while((c = getopt(argc, argv, "D:I:d:ef:ij:knqrst")) != -1) {
+#ifdef notyet
+# define OPTFLAGS "BD:I:L:PSd:ef:ij:knqrst"
+#else
+# define OPTFLAGS "D:I:d:ef:ij:knqrst"
+#endif
+rearg: while ((c = getopt(argc, argv, OPTFLAGS)) != EOF) {
                switch(c) {
                case 'D':
                        Var_Set(optarg, "1", VAR_GLOBAL);
                switch(c) {
                case 'D':
                        Var_Set(optarg, "1", VAR_GLOBAL);
@@ -137,7 +168,10 @@ rearg:     while((c = getopt(argc, argv, "D:I:d:ef:ij:knqrst")) != -1) {
                        Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL);
                        Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
                        break;
                        Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL);
                        Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
                        break;
-#ifdef notdef
+#ifdef notyet
+               case 'B':
+                       compatMake = TRUE;
+                       break;
                case 'L':
                        maxLocal = atoi(optarg);
                        Var_Append(MAKEFLAGS, "-L", VAR_GLOBAL);
                case 'L':
                        maxLocal = atoi(optarg);
                        Var_Append(MAKEFLAGS, "-L", VAR_GLOBAL);
@@ -169,6 +203,9 @@ rearg:      while((c = getopt(argc, argv, "D:I:d:ef:ij:knqrst")) != -1) {
                                case 'd':
                                        debug |= DEBUG_DIR;
                                        break;
                                case 'd':
                                        debug |= DEBUG_DIR;
                                        break;
+                               case 'f':
+                                       debug |= DEBUG_FOR;
+                                       break;
                                case 'g':
                                        if (modules[1] == '1') {
                                                debug |= DEBUG_GRAPH1;
                                case 'g':
                                        if (modules[1] == '1') {
                                                debug |= DEBUG_GRAPH1;
@@ -194,6 +231,11 @@ rearg:     while((c = getopt(argc, argv, "D:I:d:ef:ij:knqrst")) != -1) {
                                case 'v':
                                        debug |= DEBUG_VAR;
                                        break;
                                case 'v':
                                        debug |= DEBUG_VAR;
                                        break;
+                               default:
+                                       (void)fprintf(stderr,
+                               "make: illegal argument to d option -- %c\n",
+                                           *modules);
+                                       usage();
                                }
                        Var_Append(MAKEFLAGS, "-d", VAR_GLOBAL);
                        Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
                                }
                        Var_Append(MAKEFLAGS, "-d", VAR_GLOBAL);
                        Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
@@ -212,7 +254,7 @@ rearg:      while((c = getopt(argc, argv, "D:I:d:ef:ij:knqrst")) != -1) {
                        break;
                case 'j':
                        maxJobs = atoi(optarg);
                        break;
                case 'j':
                        maxJobs = atoi(optarg);
-                       Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL);
+                       Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL);
                        Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
                        break;
                case 'k':
                        Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
                        break;
                case 'k':
@@ -260,7 +302,10 @@ rearg:     while((c = getopt(argc, argv, "D:I:d:ef:ij:knqrst")) != -1) {
                        if (!**argv)
                                Punt("illegal (null) argument.");
                        if (**argv == '-') {
                        if (!**argv)
                                Punt("illegal (null) argument.");
                        if (**argv == '-') {
-                               optind = 0;
+                               if ((*argv)[1])
+                                       optind = 0;     /* -flag... */
+                               else
+                                       optind = 1;     /* - */
                                goto rearg;
                        }
                        (void)Lst_AtEnd(create, (ClientData)*argv);
                                goto rearg;
                        }
                        (void)Lst_AtEnd(create, (ClientData)*argv);
@@ -291,7 +336,8 @@ Main_ParseArgLine(line)
 
        if (line == NULL)
                return;
 
        if (line == NULL)
                return;
-       for (; *line == ' '; ++line);
+       for (; *line == ' '; ++line)
+               continue;
        if (!*line)
                return;
 
        if (!*line)
                return;
 
@@ -316,14 +362,42 @@ Main_ParseArgLine(line)
  * Side Effects:
  *     The program exits when done. Targets are created. etc. etc. etc.
  */
  * Side Effects:
  *     The program exits when done. Targets are created. etc. etc. etc.
  */
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
        Lst targs;      /* target nodes to create -- passed to Make_Init */
 main(argc, argv)
        int argc;
        char **argv;
 {
        Lst targs;      /* target nodes to create -- passed to Make_Init */
-       Boolean outOfDate;      /* FALSE if all targets up to date */
-       struct stat sb;
-       char *p, *path, *getenv();
+       Boolean outOfDate = TRUE;       /* FALSE if all targets up to date */
+       struct stat sb, sa;
+       char *p, *path, *pwd, *getenv(), *getwd();
+       char mdpath[MAXPATHLEN + 1];
+       char obpath[MAXPATHLEN + 1];
+       char cdpath[MAXPATHLEN + 1];
+
+       /*
+        * Find where we are and take care of PWD for the automounter...
+        * All this code is so that we know where we are when we start up
+        * on a different machine with pmake.
+        */
+       curdir = cdpath;
+       if (getwd(curdir) == NULL) {
+               (void)fprintf(stderr, "make: %s.\n", curdir);
+               exit(2);
+       }
+
+       if (stat(curdir, &sa) == -1) {
+           (void)fprintf(stderr, "make: %s: %s.\n",
+                         curdir, strerror(errno));
+           exit(2);
+       }
+
+       if ((pwd = getenv("PWD")) != NULL) {
+           if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino &&
+               sa.st_dev == sb.st_dev) 
+               (void) strcpy(curdir, pwd);
+       }
+
 
        /*
         * if the MAKEOBJDIR (or by default, the _PATH_OBJDIR) directory
 
        /*
         * if the MAKEOBJDIR (or by default, the _PATH_OBJDIR) directory
@@ -332,27 +406,53 @@ main(argc, argv)
         * and modify the paths for the Makefiles apropriately.  The
         * current directory is also placed as a variable for make scripts.
         */
         * and modify the paths for the Makefiles apropriately.  The
         * current directory is also placed as a variable for make scripts.
         */
-       if (!(path = getenv("MAKEOBJDIR")))
+       if (!(path = getenv("MAKEOBJDIR"))) {
                path = _PATH_OBJDIR;
                path = _PATH_OBJDIR;
-       if (!lstat(path, &sb)) {
-               if (S_ISDIR(sb.st_mode))
-                       curdir = "..";
+               (void) sprintf(mdpath, "%s.%s", path, MACHINE);
+       }
+       else
+               (void) strncpy(mdpath, path, MAXPATHLEN + 1);
+       
+       if (stat(mdpath, &sb) == 0 && S_ISDIR(sb.st_mode)) {
+
+               if (chdir(mdpath)) {
+                       (void)fprintf(stderr, "make warning: %s: %s.\n",
+                                     mdpath, strerror(errno));
+                       objdir = curdir;
+               }
                else {
                else {
-                       curdir = emalloc((u_int)MAXPATHLEN + 1);
-                       if (!getwd(curdir)) {
-                               (void)fprintf(stderr, "make: %s.\n", curdir);
-                               exit(2);
+                       if (mdpath[0] != '/') {
+                               (void) sprintf(obpath, "%s/%s", curdir, mdpath);
+                               objdir = obpath;
                        }
                        }
+                       else
+                               objdir = mdpath;
                }
                }
-               if (chdir(path)) {
-                       extern int errno;
+       }
+       else {
+               if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
 
 
-                       (void)fprintf(stderr, "make: %s: %s.\n",
-                           path, strerror(errno));
-                       exit(2);
+                       if (chdir(path)) {
+                               (void)fprintf(stderr, "make warning: %s: %s.\n",
+                                             path, strerror(errno));
+                               objdir = curdir;
+                       }
+                       else {
+                               if (path[0] != '/') {
+                                       (void) sprintf(obpath, "%s/%s", curdir,
+                                                      path);
+                                       objdir = obpath;
+                               }
+                               else
+                                       objdir = obpath;
+                       }
                }
                }
+               else
+                       objdir = curdir;
        }
 
        }
 
+       setenv("PWD", objdir, 1);
+
        create = Lst_Init(FALSE);
        makefiles = Lst_Init(FALSE);
        beSilent = FALSE;               /* Print commands as executed */
        create = Lst_Init(FALSE);
        makefiles = Lst_Init(FALSE);
        beSilent = FALSE;               /* Print commands as executed */
@@ -369,7 +469,13 @@ main(argc, argv)
 
        maxJobs = DEFMAXJOBS;           /* Set default max concurrency */
        maxLocal = DEFMAXLOCAL;         /* Set default local max concurrency */
 
        maxJobs = DEFMAXJOBS;           /* Set default max concurrency */
        maxLocal = DEFMAXLOCAL;         /* Set default local max concurrency */
+#ifdef notyet
+       compatMake = FALSE;             /* No compat mode */
+#else
+       compatMake = TRUE;              /* No compat mode */
+#endif
     
     
+
        /*
         * Initialize the parsing, directory and variable modules to prepare
         * for the reading of inclusion paths and variable settings on the
        /*
         * Initialize the parsing, directory and variable modules to prepare
         * for the reading of inclusion paths and variable settings on the
@@ -381,12 +487,10 @@ main(argc, argv)
                                 * directories */
        Var_Init();             /* As well as the lists of variables for
                                 * parsing arguments */
                                 * directories */
        Var_Init();             /* As well as the lists of variables for
                                 * parsing arguments */
-
-       if (curdir) {
+       if (objdir != curdir)
                Dir_AddDir(dirSearchPath, curdir);
                Dir_AddDir(dirSearchPath, curdir);
-               Var_Set(".CURDIR", curdir, VAR_GLOBAL);
-       } else
-               Var_Set(".CURDIR", ".", VAR_GLOBAL);
+       Var_Set(".CURDIR", curdir, VAR_GLOBAL);
+       Var_Set(".OBJDIR", objdir, VAR_GLOBAL);
 
        /*
         * Initialize various variables.
 
        /*
         * Initialize various variables.
@@ -397,7 +501,12 @@ main(argc, argv)
        Var_Set("MAKE", argv[0], VAR_GLOBAL);
        Var_Set(MAKEFLAGS, "", VAR_GLOBAL);
        Var_Set("MFLAGS", "", VAR_GLOBAL);
        Var_Set("MAKE", argv[0], VAR_GLOBAL);
        Var_Set(MAKEFLAGS, "", VAR_GLOBAL);
        Var_Set("MFLAGS", "", VAR_GLOBAL);
+#ifdef MACHINE
        Var_Set("MACHINE", MACHINE, VAR_GLOBAL);
        Var_Set("MACHINE", MACHINE, VAR_GLOBAL);
+#endif
+#ifdef MACHINE_ARCH
+       Var_Set("MACHINE_ARCH", MACHINE_ARCH, VAR_GLOBAL);
+#endif
 
        /*
         * First snag any flags out of the MAKE environment variable.
 
        /*
         * First snag any flags out of the MAKE environment variable.
@@ -462,7 +571,7 @@ main(argc, argv)
        Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL), VAR_GLOBAL);
 
        /* Install all the flags into the MAKE envariable. */
        Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL), VAR_GLOBAL);
 
        /* Install all the flags into the MAKE envariable. */
-       if ((p = Var_Value(MAKEFLAGS, VAR_GLOBAL)) && *p)
+       if (((p = Var_Value(MAKEFLAGS, VAR_GLOBAL)) != NULL) && *p)
 #ifdef POSIX
                setenv("MAKEFLAGS", p, 1);
 #else
 #ifdef POSIX
                setenv("MAKEFLAGS", p, 1);
 #else
@@ -484,11 +593,12 @@ main(argc, argv)
                 */
                static char VPATH[] = "${VPATH}";
 
                 */
                static char VPATH[] = "${VPATH}";
 
-               vpath = Var_Subst(VPATH, VAR_CMD, FALSE);
+               vpath = Var_Subst(NULL, VPATH, VAR_CMD, FALSE);
                path = vpath;
                do {
                        /* skip to end of directory */
                path = vpath;
                do {
                        /* skip to end of directory */
-                       for (cp = path; *cp != ':' && *cp != '\0'; cp++);
+                       for (cp = path; *cp != ':' && *cp != '\0'; cp++)
+                               continue;
                        /* Save terminator character so know when to stop */
                        savec = *cp;
                        *cp = '\0';
                        /* Save terminator character so know when to stop */
                        savec = *cp;
                        *cp = '\0';
@@ -524,7 +634,7 @@ main(argc, argv)
  * this was original amMake -- want to allow parallelism, so put this
  * back in, eventually.
  */
  * this was original amMake -- want to allow parallelism, so put this
  * back in, eventually.
  */
-       if (0) {
+       if (!compatMake) {
                /*
                 * Initialize job module before traversing the graph, now that
                 * any .BEGIN and .END targets have been read.  This is done
                /*
                 * Initialize job module before traversing the graph, now that
                 * any .BEGIN and .END targets have been read.  This is done
@@ -552,9 +662,9 @@ main(argc, argv)
                Targ_PrintGraph(2);
 
        if (queryFlag && outOfDate)
                Targ_PrintGraph(2);
 
        if (queryFlag && outOfDate)
-               exit(1);
+               return(1);
        else
        else
-               exit(0);
+               return(0);
 }
 
 /*-
 }
 
 /*-
@@ -579,12 +689,12 @@ ReadMakefile(fname)
                Parse_File("(stdin)", stdin);
                Var_Set("MAKEFILE", "", VAR_GLOBAL);
        } else {
                Parse_File("(stdin)", stdin);
                Var_Set("MAKEFILE", "", VAR_GLOBAL);
        } else {
-               if (stream = fopen(fname, "r"))
+               if ((stream = fopen(fname, "r")) != NULL)
                        goto found;
                /* if we've chdir'd, rebuild the path name */
                        goto found;
                /* if we've chdir'd, rebuild the path name */
-               if (curdir && *fname != '/') {
+               if (curdir != objdir && *fname != '/') {
                        (void)sprintf(path, "%s/%s", curdir, fname);
                        (void)sprintf(path, "%s/%s", curdir, fname);
-                       if (stream = fopen(path, "r")) {
+                       if ((stream = fopen(path, "r")) != NULL) {
                                fname = path;
                                goto found;
                        }
                                fname = path;
                                goto found;
                        }
@@ -620,14 +730,22 @@ found:            Var_Set("MAKEFILE", fname, VAR_GLOBAL);
  */
 /* VARARGS */
 void
  */
 /* VARARGS */
 void
+#if __STDC__
+Error(const char *fmt, ...)
+#else
 Error(va_alist)
        va_dcl
 Error(va_alist)
        va_dcl
+#endif
 {
        va_list ap;
 {
        va_list ap;
+#if __STDC__
+       va_start(ap, fmt);
+#else
        char *fmt;
 
        va_start(ap);
        fmt = va_arg(ap, char *);
        char *fmt;
 
        va_start(ap);
        fmt = va_arg(ap, char *);
+#endif
        (void)vfprintf(stderr, fmt, ap);
        va_end(ap);
        (void)fprintf(stderr, "\n");
        (void)vfprintf(stderr, fmt, ap);
        va_end(ap);
        (void)fprintf(stderr, "\n");
@@ -647,17 +765,25 @@ Error(va_alist)
  */
 /* VARARGS */
 void
  */
 /* VARARGS */
 void
+#if __STDC__
+Fatal(const char *fmt, ...)
+#else
 Fatal(va_alist)
        va_dcl
 Fatal(va_alist)
        va_dcl
+#endif
 {
        va_list ap;
 {
        va_list ap;
+#if __STDC__
+       va_start(ap, fmt);
+#else
        char *fmt;
 
        char *fmt;
 
+       va_start(ap);
+       fmt = va_arg(ap, char *);
+#endif
        if (jobsRunning)
                Job_Wait();
 
        if (jobsRunning)
                Job_Wait();
 
-       va_start(ap);
-       fmt = va_arg(ap, char *);
        (void)vfprintf(stderr, fmt, ap);
        va_end(ap);
        (void)fprintf(stderr, "\n");
        (void)vfprintf(stderr, fmt, ap);
        va_end(ap);
        (void)fprintf(stderr, "\n");
@@ -681,15 +807,24 @@ Fatal(va_alist)
  */
 /* VARARGS */
 void
  */
 /* VARARGS */
 void
+#if __STDC__
+Punt(const char *fmt, ...)
+#else
 Punt(va_alist)
        va_dcl
 Punt(va_alist)
        va_dcl
+#endif
 {
        va_list ap;
 {
        va_list ap;
+#if __STDC__
+       va_start(ap, fmt);
+#else
        char *fmt;
 
        char *fmt;
 
-       (void)fprintf(stderr, "make: ");
        va_start(ap);
        fmt = va_arg(ap, char *);
        va_start(ap);
        fmt = va_arg(ap, char *);
+#endif
+
+       (void)fprintf(stderr, "make: ");
        (void)vfprintf(stderr, fmt, ap);
        va_end(ap);
        (void)fprintf(stderr, "\n");
        (void)vfprintf(stderr, fmt, ap);
        va_end(ap);
        (void)fprintf(stderr, "\n");
@@ -744,8 +879,7 @@ char *
 emalloc(len)
        u_int len;
 {
 emalloc(len)
        u_int len;
 {
-       extern int errno;
-       char *p, *malloc();
+       char *p;
 
        if (!(p = malloc(len)))
                enomem();
 
        if (!(p = malloc(len)))
                enomem();
@@ -756,6 +890,7 @@ emalloc(len)
  * enomem --
  *     die when out of memory.
  */
  * enomem --
  *     die when out of memory.
  */
+void
 enomem()
 {
        (void)fprintf(stderr, "make: %s.\n", strerror(errno));
 enomem()
 {
        (void)fprintf(stderr, "make: %s.\n", strerror(errno));
@@ -766,10 +901,11 @@ enomem()
  * usage --
  *     exit with usage message
  */
  * usage --
  *     exit with usage message
  */
+static void
 usage()
 {
        (void)fprintf(stderr,
 usage()
 {
        (void)fprintf(stderr,
-"usage: make [-eiknqrst] [-D variable] [-d flags] [-f makefile ]\n\t\
-[-I directory] [-j max_jobs] [variable=value]\n");
+"usage: make [-eiknqrst] [-D variable] [-d flags] [-f makefile ]\n\
+            [-I directory] [-j max_jobs] [variable=value]\n");
        exit(2);
 }
        exit(2);
 }