[Midnightbsd-cvs] src: usr.bin/make: Sync make with freebsd $MidnightBSD$ <limits.h> is

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Mon Sep 29 16:36:54 EDT 2008


Log Message:
-----------
Sync make with freebsd

$MidnightBSD$

<limits.h> is necessary for using INT_MIN, so included it here
explicitly rather than relying on name space pollution to pull it in
for us.

No need to tell make to DTRT with "make love", just do it.
Also remove the 2002/08/31 bootstrapping aid for upgrades from
year old (mid-2001) systems.

Fix splitting into words of the .for expression to allow for
spaces in values.  Without this change, the following valid
call broke due to parsing of .MAKEFLAGS in bsd.symver.mk:

cd /usr/src/lib/libc && make -n DEBUG_FLAGS="-DFOO -DBAR"

If the special target .MAKEFILEDEPS exists, then enable the
"remaking makefiles" feature.  Otherwise, follow traditional Pmake behavior.

Modified Files:
--------------
    src/usr.bin/make:
        GNode.h (r1.1.1.1 -> r1.2)
        Makefile (r1.1.1.2 -> r1.2)
        Makefile.dist (r1.1.1.1 -> r1.2)
        arch.c (r1.1.1.1 -> r1.2)
        arch.h (r1.1.1.1 -> r1.2)
        buf.c (r1.1.1.1 -> r1.2)
        buf.h (r1.1.1.1 -> r1.2)
        cond.c (r1.1.1.1 -> r1.2)
        cond.h (r1.1.1.1 -> r1.2)
        config.h (r1.1.1.1 -> r1.2)
        dir.c (r1.1.1.1 -> r1.2)
        dir.h (r1.1.1.1 -> r1.2)
        for.c (r1.1.1.1 -> r1.2)
        for.h (r1.1.1.1 -> r1.2)
        globals.h (r1.1.1.1 -> r1.2)
        hash.c (r1.1.1.1 -> r1.2)
        hash.h (r1.1.1.1 -> r1.2)
        hash_tables.c (r1.1.1.1 -> r1.2)
        hash_tables.h (r1.1.1.1 -> r1.2)
        job.c (r1.1.1.1 -> r1.2)
        job.h (r1.1.1.1 -> r1.2)
        lst.c (r1.1.1.1 -> r1.2)
        main.c (r1.1.1.1 -> r1.2)
        make.1 (r1.1.1.2 -> r1.2)
        make.c (r1.1.1.1 -> r1.2)
        make.h (r1.1.1.1 -> r1.2)
        parse.c (r1.1.1.1 -> r1.2)
        parse.h (r1.1.1.1 -> r1.2)
        pathnames.h (r1.1.1.1 -> r1.2)
        proc.c (r1.1.1.1 -> r1.2)
        proc.h (r1.1.1.1 -> r1.2)
        shell.c (r1.1.1.1 -> r1.2)
        shell.h (r1.1.1.1 -> r1.2)
        str.c (r1.1.1.1 -> r1.2)
        str.h (r1.1.1.1 -> r1.2)
        suff.c (r1.1.1.1 -> r1.2)
        suff.h (r1.1.1.1 -> r1.2)
        targ.c (r1.1.1.1 -> r1.2)
        targ.h (r1.1.1.1 -> r1.2)
        util.c (r1.1.1.1 -> r1.2)
        util.h (r1.1.1.1 -> r1.2)
        var.c (r1.1.1.1 -> r1.2)
        var.h (r1.1.1.1 -> r1.2)

-------------- next part --------------
Index: suff.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/suff.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/suff.c -L usr.bin/make/suff.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/suff.c
+++ usr.bin/make/suff.c
@@ -39,8 +39,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/suff.c,v 1.64 2005/05/24 15:58:35 harti Exp $");
-
+/* $FreeBSD: src/usr.bin/make/suff.c,v 1.64 2005/05/24 15:58:35 harti Exp $ */
+__MBSDID("$MidnightBSD$");
 /*-
  * suff.c --
  *	Functions to maintain suffix lists and find implicit dependents
Index: arch.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/arch.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/arch.h -L usr.bin/make/arch.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/arch.h
+++ usr.bin/make/arch.h
@@ -35,6 +35,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/arch.h,v 1.5 2005/05/18 06:50:38 harti Exp $
  */
 
Index: util.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/util.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/util.h -L usr.bin/make/util.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/util.h
+++ usr.bin/make/util.h
@@ -35,6 +35,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$ 
  * $FreeBSD: src/usr.bin/make/util.h,v 1.10 2005/05/18 06:50:39 harti Exp $
  */
 
Index: proc.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/proc.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/proc.h -L usr.bin/make/proc.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/proc.h
+++ usr.bin/make/proc.h
@@ -23,6 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/proc.h,v 1.1 2005/05/24 15:41:34 harti Exp $
  */
 
Index: arch.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/arch.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/arch.c -L usr.bin/make/arch.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/arch.c
+++ usr.bin/make/arch.c
@@ -39,7 +39,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/arch.c,v 1.66 2005/05/24 15:58:34 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/arch.c,v 1.67 2008/03/04 15:56:17 imp Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*-
  * arch.c --
@@ -94,6 +95,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <inttypes.h>
+#include <limits.h>
 #include <regex.h>
 #include <stdlib.h>
 #include <stdio.h>
Index: buf.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/buf.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/buf.c -L usr.bin/make/buf.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/buf.c
+++ usr.bin/make/buf.c
@@ -41,7 +41,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/buf.c,v 1.36 2005/05/13 08:53:00 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/buf.c,v 1.36 2005/05/13 08:53:00 harti Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*
  * buf.c
Index: cond.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/cond.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/cond.c -L usr.bin/make/cond.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/cond.c
+++ usr.bin/make/cond.c
@@ -40,7 +40,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/cond.c,v 1.54 2005/05/25 16:06:14 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/cond.c,v 1.54 2005/05/25 16:06:14 harti Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*
  * Functions to handle conditionals in a makefile.
Index: main.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/main.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/main.c -L usr.bin/make/main.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/main.c
+++ usr.bin/make/main.c
@@ -46,7 +46,8 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/main.c,v 1.155 2005/05/24 16:05:51 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/main.c,v 1.169 2008/07/30 21:18:38 ed Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*
  * main.c
@@ -61,15 +62,13 @@
  *			the .MFLAGS target.
  */
 
-#ifndef MACHINE
-#include <sys/utsname.h>
-#endif
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/sysctl.h>
 #include <sys/time.h>
 #include <sys/queue.h>
 #include <sys/resource.h>
+#include <sys/utsname.h>
 #include <sys/wait.h>
 #include <err.h>
 #include <errno.h>
@@ -82,6 +81,7 @@
 #include "config.h"
 #include "dir.h"
 #include "globals.h"
+#include "GNode.h"
 #include "job.h"
 #include "make.h"
 #include "parse.h"
@@ -95,21 +95,26 @@
 
 extern char **environ;	/* XXX what header declares this variable? */
 
-#define WANT_ENV_MKLVL	1
+#define	WANT_ENV_MKLVL	1
 #define	MKLVL_MAXVAL	500
 #define	MKLVL_ENVVAR	"__MKLVL__"
 
 /* ordered list of makefiles to read */
 static Lst makefiles = Lst_Initializer(makefiles);
 
+/* ordered list of source makefiles */
+static Lst source_makefiles = Lst_Initializer(source_makefiles);
+
 /* list of variables to print */
 static Lst variables = Lst_Initializer(variables);
 
 static Boolean	expandVars;	/* fully expand printed variables */
 static Boolean	noBuiltins;	/* -r flag */
-static Boolean	forceJobs;      /* -j argument given */
+static Boolean	forceJobs;	/* -j argument given */
 static char	*curdir;	/* startup directory */
 static char	*objdir;	/* where we chdir'ed to */
+static char	**save_argv;	/* saved argv */
+static char	*save_makeflags;/* saved MAKEFLAGS */
 
 /* (-E) vars to override from env */
 Lst envFirstVars = Lst_Initializer(envFirstVars);
@@ -118,15 +123,18 @@
 Lst create = Lst_Initializer(create);
 
 Boolean		allPrecious;	/* .PRECIOUS given on line by itself */
+Boolean		is_posix;	/* .POSIX target seen */
+Boolean		mfAutoDeps;	/* .MAKEFILEDEPS target seen */
 Boolean		beSilent;	/* -s flag */
 Boolean		beVerbose;	/* -v flag */
 Boolean		compatMake;	/* -B argument */
-Boolean		debug;		/* -d flag */
+int		debug;		/* -d flag */
 Boolean		ignoreErrors;	/* -i flag */
 int		jobLimit;	/* -j argument */
 Boolean		jobsRunning;	/* TRUE if the jobs might be running */
 Boolean		keepgoing;	/* -k flag */
 Boolean		noExecute;	/* -n flag */
+Boolean		printGraphOnly;	/* -p flag */
 Boolean		queryFlag;	/* -q flag */
 Boolean		touchFlag;	/* -t flag */
 Boolean		usePipes;	/* !-P flag */
@@ -144,7 +152,7 @@
 usage(void)
 {
 	fprintf(stderr,
-	    "usage: make [-BPSXeiknqrstv] [-C directory] [-D variable]\n"
+	    "usage: make [-BPSXeiknpqrstv] [-C directory] [-D variable]\n"
 	    "\t[-d flags] [-E variable] [-f makefile] [-I directory]\n"
 	    "\t[-j max_jobs] [-m directory] [-V variable]\n"
 	    "\t[variable=value] [target ...]\n");
@@ -236,14 +244,14 @@
 static Boolean
 ReadMakefile(const char p[])
 {
-	char *fname;			/* makefile to read */
+	char *fname, *fnamesave;	/* makefile to read */
 	FILE *stream;
 	char *name, path[MAXPATHLEN];
 	char *MAKEFILE;
 	int setMAKEFILE;
 
 	/* XXX - remove this once constification is done */
-	fname = estrdup(p);
+	fnamesave = fname = estrdup(p);
 
 	if (!strcmp(fname, "-")) {
 		Parse_File("(stdin)", stdin);
@@ -298,8 +306,10 @@
 		name = Path_FindFile(fname, &parseIncPath);
 		if (!name)
 			name = Path_FindFile(fname, &sysIncPath);
-		if (!name || !(stream = fopen(name, "r")))
+		if (!name || !(stream = fopen(name, "r"))) {
+			free(fnamesave);
 			return (FALSE);
+		}
 		MAKEFILE = fname = name;
 		/*
 		 * set the MAKEFILE variable desired by System V fans -- the
@@ -310,8 +320,33 @@
 		if (setMAKEFILE)
 			Var_SetGlobal("MAKEFILE", MAKEFILE);
 		Parse_File(fname, stream);
-		fclose(stream);
 	}
+	free(fnamesave);
+	return (TRUE);
+}
+
+/**
+ * Open and parse the given makefile.
+ * If open is successful add it to the list of makefiles.
+ *
+ * Results:
+ *	TRUE if ok. FALSE if couldn't open file.
+ */
+static Boolean
+TryReadMakefile(const char p[])
+{
+	char *data;
+	LstNode *last = Lst_Last(&source_makefiles);
+
+	if (!ReadMakefile(p))
+		return (FALSE);
+
+	data = estrdup(p);
+	if (last == NULL) {
+		LstNode *first = Lst_First(&source_makefiles);
+		Lst_Insert(&source_makefiles, first, data);
+	} else
+		Lst_Append(&source_makefiles, last, estrdup(p));
 	return (TRUE);
 }
 
@@ -335,7 +370,7 @@
 rearg:
 	optind = 1;	/* since we're called more than once */
 	optreset = 1;
-#define OPTFLAGS "ABC:D:E:I:PSV:Xd:ef:ij:km:nqrstvx:"
+#define OPTFLAGS "ABC:D:E:I:PSV:Xd:ef:ij:km:npqrstvx:"
 	for (;;) {
 		if ((optind < argc) && strcmp(argv[optind], "--") == 0) {
 			found_dd = TRUE;
@@ -477,6 +512,10 @@
 			noExecute = TRUE;
 			MFLAGS_append("-n", NULL);
 			break;
+		case 'p':
+			printGraphOnly = TRUE;
+			debug |= DEBUG_GRAPH1;
+			break;
 		case 'q':
 			queryFlag = TRUE;
 			/* Kind of nonsensical, wot? */
@@ -502,7 +541,7 @@
 			if (Main_ParseWarn(optarg, 1) != -1)
 				MFLAGS_append("-x", optarg);
 			break;
-				
+
 		default:
 		case '?':
 			usage();
@@ -517,16 +556,18 @@
 	 * Parse the rest of the arguments.
 	 *	o Check for variable assignments and perform them if so.
 	 *	o Check for more flags and restart getopt if so.
-	 *      o Anything else is taken to be a target and added
+	 *	o Anything else is taken to be a target and added
 	 *	  to the end of the "create" list.
 	 */
 	for (; *argv != NULL; ++argv, --argc) {
 		if (Parse_IsVar(*argv)) {
 			char *ptr = MAKEFLAGS_quote(*argv);
+			char *v = estrdup(*argv);
 
 			Var_Append(".MAKEFLAGS", ptr, VAR_GLOBAL);
-			Parse_DoVar(*argv, VAR_CMD);
+			Parse_DoVar(v, VAR_CMD);
 			free(ptr);
+			free(v);
 
 		} else if ((*argv)[0] == '-') {
 			if ((*argv)[1] == '\0') {
@@ -563,10 +604,10 @@
 
 /**
  * Main_ParseArgLine
- *  	Used by the parse module when a .MFLAGS or .MAKEFLAGS target
+ *	Used by the parse module when a .MFLAGS or .MAKEFLAGS target
  *	is encountered and by main() when reading the .MAKEFLAGS envariable.
  *	Takes a line of arguments and breaks it into its
- * 	component words and passes those words and the number of them to the
+ *	component words and passes those words and the number of them to the
  *	MainParseArgs function.
  *	The line should have all its leading whitespace removed.
  *
@@ -640,6 +681,184 @@
 }
 
 /**
+ * Main_AddSourceMakefile
+ *	Add a file to the list of source makefiles
+ */
+void
+Main_AddSourceMakefile(const char *name)
+{
+
+	Lst_AtEnd(&source_makefiles, estrdup(name));
+}
+
+/**
+ * Remake_Makefiles
+ *	Remake all the makefiles
+ */
+static void
+Remake_Makefiles(void)
+{
+	LstNode *ln;
+	int error_cnt = 0;
+	int remade_cnt = 0;
+
+	Compat_InstallSignalHandlers();
+	if (curdir != objdir) {
+		if (chdir(curdir) < 0)
+			Fatal("Failed to change directory to %s.", curdir);
+	}
+
+	LST_FOREACH(ln, &source_makefiles) {
+		LstNode *ln2;
+		struct GNode *gn;
+		const char *name = Lst_Datum(ln);
+		Boolean saveTouchFlag = touchFlag;
+		Boolean saveQueryFlag = queryFlag;
+		Boolean saveNoExecute = noExecute;
+		int mtime;
+
+		/*
+		 * Create node
+		 */
+		gn = Targ_FindNode(name, TARG_CREATE);
+		DEBUGF(MAKE, ("Checking %s...", gn->name));
+		Suff_FindDeps(gn);
+
+		/*
+		 * ! dependencies as well as
+		 * dependencies with .FORCE, .EXEC and .PHONY attributes
+		 * are skipped to prevent infinite loops
+		 */
+		if (gn->type & (OP_FORCE | OP_EXEC | OP_PHONY)) {
+			DEBUGF(MAKE, ("skipping (force, exec or phony).\n",
+			    gn->name));
+			continue;
+		}
+
+		/*
+		 * Skip :: targets that have commands and no children
+		 * because such targets are always out-of-date
+		 */
+		if ((gn->type & OP_DOUBLEDEP) &&
+		    !Lst_IsEmpty(&gn->commands) &&
+		    Lst_IsEmpty(&gn->children)) {
+			DEBUGF(MAKE, ("skipping (doubledep, no sources "
+			    "and has commands).\n"));
+			continue;
+		}
+
+		/*
+		 * Skip targets without sources and without commands
+		 */
+		if (Lst_IsEmpty(&gn->commands) &&
+		    Lst_IsEmpty(&gn->children)) {
+			DEBUGF(MAKE,
+			    ("skipping (no sources and no commands).\n"));
+			continue;
+		}
+
+		DEBUGF(MAKE, ("\n"));
+
+		/*
+		 * -t, -q and -n has no effect unless the makefile is
+		 * specified as one of the targets explicitly in the
+		 * command line
+		 */
+		LST_FOREACH(ln2, &create) {
+			if (!strcmp(gn->name, Lst_Datum(ln2))) {
+				/* found as a target */
+				break;
+			}
+		}
+		if (ln2 == NULL) {
+			touchFlag = FALSE;
+			queryFlag = FALSE;
+			noExecute = FALSE;
+		}
+
+		/*
+		 * Check and remake the makefile
+		 */
+		mtime = Dir_MTime(gn);
+		Compat_Make(gn, gn);
+
+		/*
+		 * Restore -t, -q and -n behaviour
+		 */
+		touchFlag = saveTouchFlag;
+		queryFlag = saveQueryFlag;
+		noExecute = saveNoExecute;
+
+		/*
+		 * Compat_Make will leave the 'made' field of gn
+		 * in one of the following states:
+		 *	UPTODATE  gn was already up-to-date
+		 *	MADE	  gn was recreated successfully
+		 *	ERROR	  An error occurred while gn was being created
+		 *	ABORTED	  gn was not remade because one of its inferiors
+		 *		  could not be made due to errors.
+		 */
+		if (gn->made == MADE) {
+			if (mtime != Dir_MTime(gn)) {
+				DEBUGF(MAKE,
+				    ("%s updated (%d -> %d).\n",
+				     gn->name, mtime, gn->mtime));
+				remade_cnt++;
+			} else {
+				DEBUGF(MAKE,
+				    ("%s not updated: skipping restart.\n",
+				     gn->name));
+			}
+		} else if (gn->made == ERROR)
+			error_cnt++;
+		else if (gn->made == ABORTED) {
+			printf("`%s' not remade because of errors.\n",
+			    gn->name);
+			error_cnt++;
+		} else if (gn->made == UPTODATE) {
+			Lst examine;
+
+			Lst_Init(&examine);
+			Lst_EnQueue(&examine, gn);
+			while (!Lst_IsEmpty(&examine)) {
+				LstNode	*eln;
+				GNode *egn = Lst_DeQueue(&examine);
+
+				egn->make = FALSE;
+				LST_FOREACH(eln, &egn->children) {
+					GNode *cgn = Lst_Datum(eln);
+
+					Lst_EnQueue(&examine, cgn);
+				}
+			}
+		}
+	}
+
+	if (error_cnt > 0)
+		Fatal("Failed to remake Makefiles.");
+	if (remade_cnt > 0) {
+		DEBUGF(MAKE, ("Restarting `%s'.\n", save_argv[0]));
+
+		/*
+		 * Some of makefiles were remade -- restart from clean state
+		 */
+		if (save_makeflags != NULL)
+			setenv("MAKEFLAGS", save_makeflags, 1);
+		else
+			unsetenv("MAKEFLAGS");
+		if (execvp(save_argv[0], save_argv) < 0) {
+			Fatal("Can't restart `%s': %s.",
+			    save_argv[0], strerror(errno));
+		}
+	}
+
+	if (curdir != objdir) {
+		if (chdir(objdir) < 0)
+			Fatal("Failed to change directory to %s.", objdir);
+	}
+}
+
+/**
  * main
  *	The main function, for obvious reasons. Initializes variables
  *	and a few modules, then parses the arguments give it in the
@@ -659,10 +878,10 @@
 int
 main(int argc, char **argv)
 {
-    	const char *machine;
+	const char *machine;
 	const char *machine_arch;
 	const char *machine_cpu;
-	Boolean outOfDate = TRUE; 	/* FALSE if all targets up to date */
+	Boolean outOfDate = TRUE;	/* FALSE if all targets up to date */
 	const char *p;
 	const char *pathp;
 	const char *path;
@@ -671,12 +890,17 @@
 	char cdpath[MAXPATHLEN];
 	char *cp = NULL, *start;
 
+	save_argv = argv;
+	save_makeflags = getenv("MAKEFLAGS");
+	if (save_makeflags != NULL)
+		save_makeflags = estrdup(save_makeflags);
+
 	/*
 	 * Initialize file global variables.
 	 */
 	expandVars = TRUE;
 	noBuiltins = FALSE;		/* Read the built-in rules */
-	forceJobs = FALSE;              /* No -j flag */
+	forceJobs = FALSE;		/* No -j flag */
 	curdir = cdpath;
 
 	/*
@@ -685,6 +909,7 @@
 	beSilent = FALSE;		/* Print commands as executed */
 	ignoreErrors = FALSE;		/* Pay attention to non-zero returns */
 	noExecute = FALSE;		/* Execute all commands */
+	printGraphOnly = FALSE;		/* Don't stop after printing graph */
 	keepgoing = FALSE;		/* Stop on error */
 	allPrecious = FALSE;		/* Remove targets when interrupted */
 	queryFlag = FALSE;		/* This is not just a check-run */
@@ -715,13 +940,13 @@
 #endif
 
 	/*
-	 * PC-98 kernel sets the `i386' string to the utsname.machine and
-	 * it cannot be distinguished from IBM-PC by uname(3).  Therefore,
-	 * we check machine.ispc98 and adjust the machine variable before
-	 * using usname(3) below.
-	 * NOTE: machdep.ispc98 was defined on 1998/8/31. At that time,
-	 * __FreeBSD_version was defined as 300003. So, this check can
-	 * safely be done with any kernel with version > 300003.
+	 * Prior to 7.0, FreeBSD/pc98 kernel used to set the
+	 * utsname.machine to "i386", and MACHINE was defined as
+	 * "i386", so it could not be distinguished from FreeBSD/i386.
+	 * Therefore, we had to check machine.ispc98 and adjust the
+	 * MACHINE variable.  NOTE: The code is still here to be able
+	 * to compile new make binary on old FreeBSD/pc98 systems, and
+	 * have the MACHINE variable set properly.
 	 */
 	if ((machine = getenv("MACHINE")) == NULL) {
 		int	ispc98;
@@ -739,19 +964,15 @@
 	 * so we can share an executable for similar machines.
 	 * (i.e. m68k: amiga hp300, mac68k, sun3, ...)
 	 *
-	 * Note that while MACHINE is decided at run-time,
-	 * MACHINE_ARCH is always known at compile time.
+	 * Note that both MACHINE and MACHINE_ARCH are decided at
+	 * run-time.
 	 */
 	if (machine == NULL) {
-#ifdef MACHINE
-		machine = MACHINE;
-#else
 		static struct utsname utsname;
 
 		if (uname(&utsname) == -1)
 			err(2, "uname");
 		machine = utsname.machine;
-#endif
 	}
 
 	if ((machine_arch = getenv("MACHINE_ARCH")) == NULL) {
@@ -961,20 +1182,22 @@
 		LstNode *ln;
 
 		LST_FOREACH(ln, &makefiles) {
-			if (!ReadMakefile(Lst_Datum(ln)))
+			if (!TryReadMakefile(Lst_Datum(ln)))
 				break;
 		}
 		if (ln != NULL)
 			Fatal("make: cannot open %s.", (char *)Lst_Datum(ln));
-	} else if (!ReadMakefile("BSDmakefile"))
-	    if (!ReadMakefile("makefile"))
-		ReadMakefile("Makefile");
+	} else if (!TryReadMakefile("BSDmakefile"))
+	    if (!TryReadMakefile("makefile"))
+		TryReadMakefile("Makefile");
 
 	ReadMakefile(".depend");
 
-	/* Install all the flags into the MAKE envariable. */
+	/* Install all the flags into the MAKEFLAGS envariable. */
 	if (((p = Var_Value(".MAKEFLAGS", VAR_GLOBAL)) != NULL) && *p)
 		setenv("MAKEFLAGS", p, 1);
+	else
+		setenv("MAKEFLAGS", "", 1);
 
 	/*
 	 * For compatibility, look at the directories in the VPATH variable
@@ -1026,7 +1249,7 @@
 		Targ_PrintGraph(1);
 
 	/* print the values of any variables requested by the user */
-	if (Lst_IsEmpty(&variables)) {
+	if (Lst_IsEmpty(&variables) && !printGraphOnly) {
 		/*
 		 * Since the user has not requested that any variables
 		 * be printed, we can build targets.
@@ -1037,6 +1260,13 @@
 		 */
 		Lst targs = Lst_Initializer(targs);
 
+		if (!is_posix && mfAutoDeps) {
+			/*
+			 * Check if any of the makefiles are out-of-date.
+			 */
+			Remake_Makefiles();
+		}
+
 		if (Lst_IsEmpty(&create))
 			Parse_MainName(&targs);
 		else
@@ -1075,6 +1305,7 @@
 
 	Lst_Destroy(&variables, free);
 	Lst_Destroy(&makefiles, free);
+	Lst_Destroy(&source_makefiles, free);
 	Lst_Destroy(&create, free);
 
 	/* print the graph now it's been processed if the user requested it */
Index: dir.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/dir.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/dir.h -L usr.bin/make/dir.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/dir.h
+++ usr.bin/make/dir.h
@@ -38,6 +38,7 @@
  *
  *	@(#)dir.h	8.2 (Berkeley) 4/28/95
  * $FreeBSD: src/usr.bin/make/dir.h,v 1.21 2005/03/23 12:56:15 harti Exp $
+ * $MidnightBSD$
  */
 
 #ifndef dir_h_6002e3b8
Index: Makefile
===================================================================
RCS file: /home/cvs/src/usr.bin/make/Makefile,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L usr.bin/make/Makefile -L usr.bin/make/Makefile -u -r1.1.1.2 -r1.2
--- usr.bin/make/Makefile
+++ usr.bin/make/Makefile
@@ -1,6 +1,7 @@
 #	@(#)Makefile	5.2 (Berkeley) 12/28/90
 #	$Id: Makefile,v 1.6 1994/06/30 05:33:39 cgd Exp $
-# $FreeBSD: src/usr.bin/make/Makefile,v 1.61 2005/05/25 08:46:31 harti Exp $
+# $FreeBSD: src/usr.bin/make/Makefile,v 1.66 2008/03/04 22:32:58 obrien Exp $
+# $MidnightBSD$
 
 PROG=	make
 CFLAGS+=-I${.CURDIR}
@@ -13,10 +14,6 @@
 NO_SHARED?=	YES
 
 CFLAGS+=-DMAKE_VERSION=\"5200408120\"
-.if defined(_UPGRADING)
-CFLAGS+=-D__FBSDID=__RCSID
-.endif
-
 # There is no obvious performance improvement currently.
 # CFLAGS+=-DUSE_KQUEUE
 
@@ -29,7 +26,7 @@
 main.o shell.o: ${MAKEFILE}
 
 # Directive and keyword tables. We use hash tables. These hash tables have been
-# generated with mph which can be found on the usual GNU mirrors.
+# generated with mph (ports/devel/mph)
 # If you change the directives or keywords (adding, deleting, reordering) you
 # need to create new tables and hash functions (directive_hash, keyword_hash).
 #
Index: make.1
===================================================================
RCS file: /home/cvs/src/usr.bin/make/make.1,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L usr.bin/make/make.1 -L usr.bin/make/make.1 -u -r1.1.1.2 -r1.2
--- usr.bin/make/make.1
+++ usr.bin/make/make.1
@@ -30,9 +30,10 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)make.1	8.8 (Berkeley) 6/13/95
-.\" $FreeBSD: src/usr.bin/make/make.1,v 1.89.2.2 2006/01/22 16:33:46 yar Exp $
+.\" $FreeBSD: src/usr.bin/make/make.1,v 1.112 2008/07/30 21:18:38 ed Exp $
+.\" $MidnightBSD$
 .\"
-.Dd October 14, 2005
+.Dd March 24, 2008
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -40,7 +41,7 @@
 .Nd maintain program dependencies
 .Sh SYNOPSIS
 .Nm
-.Op Fl ABPSXeiknqrstv
+.Op Fl ABPSXeiknpqrstv
 .Op Fl C Ar directory
 .Op Fl D Ar variable
 .Op Fl d Ar flags
@@ -198,6 +199,13 @@
 .Fl f
 options can be supplied,
 and the makefiles will be read in that order.
+Unlike the other command-line options,
+.Fl f
+is neither stored in
+.Va .MAKEFLAGS
+nor pushed down to sub-makes via
+.Ev MAKEFLAGS .
+See below for more details on these variables.
 .It Fl I Ar directory
 Specify a directory in which to search for makefiles and included makefiles.
 Multiple
@@ -216,7 +224,7 @@
 .Nm
 may have running at any one time.
 Turns compatibility mode off, unless the
-.Ar B
+.Fl B
 flag is also specified.
 .It Fl k
 Continue processing after errors are encountered, but only on those targets
@@ -242,6 +250,15 @@
 This option has no effect unless
 .Fl j
 is used too.
+.It Fl p
+Only print the input graph, not executing any commands.
+The output is the same as
+.Fl d Ar g1 .
+When combined with
+.Fl f Pa /dev/null ,
+only the builtin rules of
+.Nm
+are displayed.
 .It Fl q
 Do not execute any commands, but exit 0 if the specified targets are
 up-to-date and 1, otherwise.
@@ -343,7 +360,7 @@
 The target is removed if
 .Nm
 is interrupted.
-.It Ic \&::
+.It Ic ::
 If no sources are specified, the target is always re-created.
 Otherwise, a target is considered out-of-date if any of its sources has
 been modified more recently than the target.
@@ -408,18 +425,18 @@
 The five operators that can be used to assign values to variables are as
 follows:
 .Bl -tag -width Ds
-.It Ic \&=
+.It Ic =
 Assign the value to the variable.
 Any previous value is overridden.
-.It Ic \&+=
+.It Ic +=
 Append the value to the current value of the variable.
-.It Ic \&?=
+.It Ic ?=
 Assign the value to the variable if it is not already defined.
-.It Ic \&:=
+.It Ic :=
 Assign with expansion, i.e., expand the value before assigning it
 to the variable.
 Normally, expansion is not done until the variable is referenced.
-.It Ic \&!=
+.It Ic !=
 Expand the value and pass it to the shell for execution and assign
 the result to the variable.
 Any newlines in the result are replaced with spaces.
@@ -437,7 +454,7 @@
 .Pq Ql ()
 and preceding it with
 a dollar sign
-.Pq Ql \&$ .
+.Pq Ql $ .
 If the variable name contains only a single letter, the surrounding
 braces or parentheses are not required.
 This shorter form is not recommended.
@@ -466,11 +483,25 @@
 target.
 .It Local variables
 Variables that are defined specific to a certain target.
-The seven local variables are as follows:
+.El
+.Pp
+If the name of an environment variable appears in a makefile
+on the left-hand side of an assignment,
+a global variable with the same name is created, and the latter
+shadows the former as per their relative precedences.
+The environment is not changed in this case, and the change
+is not exported to programs executed by
+.Nm .
+However, a command-line variable actually replaces
+the environment variable of the same name if the latter exists,
+which is visible to child programs.
+.Pp
+There are seven local variables in
+.Nm :
 .Bl -tag -width ".ARCHIVE"
 .It Va .ALLSRC
 The list of all sources for this target; also known as
-.Sq Va \&> .
+.Sq Va > .
 .It Va .ARCHIVE
 The name of the archive file; also known as
 .Sq Va \&! .
@@ -479,10 +510,10 @@
 (the
 .Dq implied
 source); also known as
-.Sq Va \&< .
+.Sq Va < .
 .It Va .MEMBER
 The name of the archive member; also known as
-.Sq Va \&% .
+.Sq Va % .
 .It Va .OODATE
 The list of sources for this target that were deemed out-of-date; also
 known as
@@ -499,10 +530,10 @@
 The shorter forms
 .Sq Va @ ,
 .Sq Va \&! ,
-.Sq Va \&< ,
-.Sq Va \&% ,
+.Sq Va < ,
+.Sq Va % ,
 .Sq Va \&? ,
-.Sq Va \&> ,
+.Sq Va > ,
 and
 .Sq Va *
 are permitted for backward
@@ -528,18 +559,17 @@
 .Va .ARCHIVE ,
 and
 .Va .MEMBER .
-.El
 .Pp
 In addition,
 .Nm
 sets or knows about the following internal variables or environment
 variables:
 .Bl -tag -width ".Va .MAKEFILE_LIST"
-.It Va \&$
+.It Va $
 A single dollar sign
-.Ql \&$ ,
+.Ql $ ,
 i.e.\&
-.Ql \&$$
+.Ql $$
 expands to a single dollar
 sign.
 .It Va MAKE
@@ -616,6 +646,8 @@
 reads various makefiles, including the default files and any
 obtained from the command line and
 .Ic .include
+and
+.Ic .sinclude
 directives, their names will be automatically appended to the
 .Va .MAKEFILE_LIST
 variable.
@@ -623,36 +655,51 @@
 .Nm
 begins to parse them, so that the name of the current makefile is the
 last word in this variable.
-.It Va .MAKEFLAGS
+.It Ev MAKEFLAGS
 The environment variable
 .Ev MAKEFLAGS
-may contain anything that
+may initially contain anything that
 may be specified on
 .Nm Ns 's
-command line.
-Its contents are stored in
-.Nm Ns 's
+command line,
+including
+.Fl f
+option(s).
+After processing, its contents are stored in the
 .Va .MAKEFLAGS
-variable.
-All options and variable assignments specified on
+global variable, although any
+.Fl f
+options are omitted.
+Then all options and variable assignments specified on
 .Nm Ns 's
-command line are appended to the
+command line, except for
+.Fl f ,
+are appended to the
 .Va .MAKEFLAGS
-variable which is then
-entered into the environment as
-.Ev MAKEFLAGS
-for all programs which
+variable.
+.Pp
+Whenever
 .Nm
-executes.
-By modifying the contents of the
+executes a program, it sets
+.Ev MAKEFLAGS
+in the program's environment to the current value of the
 .Va .MAKEFLAGS
-variable, makefile can alter the contents of the
-.Va MAKEFLAGS
-environment variable made available for all programs which
+global variable.
+Thus, if
+.Ev MAKEFLAGS
+in
+.Nm Ns 's
+environment contains any
+.Fl f
+options, they will not be pushed down to child programs automatically.
+The
 .Nm
-executes; compare with the
-.Ic .MAKEFLAGS
-special target below.
+utility effectively filters out
+.Fl f
+options from the environment and command line although it
+passes the rest of its options down to sub-makes via
+.Ev MAKEFLAGS
+by default.
 .Pp
 When passing macro definitions and flag arguments in the
 .Ev MAKEFLAGS
@@ -667,6 +714,49 @@
 Any other occurrences of a backslash are retained.
 Groups of unquoted space, tab and newline characters cause word
 breaking.
+.It Va .MAKEFLAGS
+Initially, this global variable contains
+.Nm Ns 's
+current run-time options from the environment
+and command line as described above, under
+.Ev MAKEFLAGS .
+By modifying the contents of the
+.Va .MAKEFLAGS
+global variable, the makefile can alter the contents of the
+.Ev MAKEFLAGS
+environment variable made available for all programs which
+.Nm
+executes.
+This includes adding
+.Fl f
+option(s).
+The current value of
+.Va .MAKEFLAGS
+is just copied verbatim to
+.Ev MAKEFLAGS
+in the environment of child programs.
+.Pp
+Note that any options entered to
+.Va .MAKEFLAGS
+neither affect the current instance of
+.Nm
+nor show up in its own copy of
+.Ev MAKEFLAGS
+instantly.
+However, they do show up in the
+.Ev MAKEFLAGS
+environment variable of programs executed by
+.Nm .
+On the other hand, a direct assignment to
+.Ev MAKEFLAGS
+neither affects the current instance of
+.Nm
+nor is passed down to
+.Nm Ns 's
+children.
+Compare with the
+.Ic .MAKEFLAGS
+special target below.
 .It Va MFLAGS
 This variable is provided for backward compatibility and
 contains all the options from the
@@ -720,9 +810,9 @@
 .Pq Ql \e .
 .Bl -tag -width Cm
 .Sm off
-.It Cm C No \&/ Ar pattern Xo
-.No \&/ Ar replacement
-.No \&/ Op Cm 1g
+.It Cm C No / Ar pattern Xo
+.No / Ar replacement
+.No / Op Cm 1g
 .Xc
 .Sm on
 Modify each word of the value,
@@ -780,9 +870,9 @@
 .It Cm R
 Replaces each word in the variable with everything but its suffix.
 .Sm off
-.It Cm S No \&/ Ar old_string Xo
-.No \&/ Ar new_string
-.No \&/ Op Cm g
+.It Cm S No / Ar old_string Xo
+.No / Ar new_string
+.No / Op Cm g
 .Xc
 .Sm on
 Modify the first occurrence of
@@ -802,7 +892,7 @@
 If
 .Ar old_string
 ends with a dollar sign
-.Pq Ql \&$ ,
+.Pq Ql $ ,
 it is anchored at the end of each word.
 Inside
 .Ar new_string ,
@@ -822,7 +912,7 @@
 .Ar new_string
 with the single exception that a backslash is used to prevent the expansion
 of a dollar sign
-.Pq Ql \&$ ,
+.Pq Ql $ ,
 not a preceding dollar sign as is usual.
 .It Ar old_string=new_string
 This is the
@@ -848,6 +938,9 @@
 Replaces each word in the variable with its last component.
 .It Cm U
 Converts variable to upper-case letters.
+.It Cm u
+Remove adjacent duplicate words (like
+.Xr uniq 1 ) .
 .El
 .Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
 Directives, conditionals, and for loops reminiscent
@@ -859,8 +952,8 @@
 character.
 The following directives are supported:
 .Bl -tag -width Ds
-.It Ic \&.include Ar <file>
-.It Ic \&.include Ar \*qfile\*q
+.It Ic .include Ar <file>
+.It Ic .include Ar \*qfile\*q
 Include the specified makefile.
 Variables between the angle brackets
 or double quotes are expanded to form the file name.
@@ -872,6 +965,11 @@
 .Fl I
 option are searched before the system
 makefile directory.
+.It Ic .sinclude Ar <file>
+.It Ic .sinclude Ar \*qfile\*q
+Like
+.Ic .include ,
+but silently ignored if the file cannot be found and opened.
 .It Ic .undef Ar variable
 Un-define the specified global variable.
 Only global variables may be un-defined.
@@ -1158,7 +1256,7 @@
 .It Ic .WAIT
 If special
 .Ic .WAIT
-source is appears in a dependency line, the sources that precede it are
+source appears in a dependency line, the sources that precede it are
 made before the sources that succeed it in the line.
 Loops are not being
 detected and targets that form loops will be silently ignored.
@@ -1224,6 +1322,12 @@
 .Nm
 selects the default target, to give the user a way to refer to the default
 target on the command line.
+.It Ic .MAKEFILEDEPS
+Enable the
+.Dq Remaking Makefiles
+functionality, as explained in the
+.Sx REMAKING MAKEFILES
+section below.
 .It Ic .MAKEFLAGS
 This target provides a way to specify flags for
 .Nm
@@ -1293,6 +1397,15 @@
 attribute to any specified sources.
 Targets with this attribute are always
 considered to be out of date.
+.It Ic .POSIX
+Adjust
+.Nm Ap s
+behavior to match the applicable
+.Tn POSIX
+specifications.
+(Note this disables the
+.Dq Remaking Makefiles
+feature.)
 .It Ic .PRECIOUS
 Apply the
 .Ic .PRECIOUS
@@ -1455,6 +1568,58 @@
 .Ic .WARN
 target by seperating them with blanks.
 .El
+.Sh REMAKING MAKEFILES
+If the special target
+.Ic .MAKEFILEDEPS
+exists in the Makefile,
+.Nm
+enables the
+.Dq Remaking Makefiles
+feature.
+After reading Makefile and all the files that are included using
+.Ic .include
+or
+.Ic .sinclude
+directives (source Makefiles)
+.Nm
+considers each source Makefile as a target and tries to rebuild it.
+Both explicit and implicit rules are checked and all source Makefiles
+are updated if necessary. If any of the source Makefiles were rebuilt,
+.Nm
+restarts from clean state.
+.Pp
+To prevent infinite loops the following source Makefile targets are ignored:
+.Bl -bullet
+.It
+.Ic ::
+targets that have no prerequisites but have commands
+.It
+.Ic !
+targets
+.It
+targets that have
+.Ic .PHONY
+or
+.Ic .EXEC
+attributes
+.It
+targets without prerequisites and without commands
+.El
+.Pp
+When remaking a source Makefile options
+.Ic -t
+(touch target),
+.Ic -q
+(query mode), and
+.Ic -n
+(no exec) do not take effect, unless source Makefile is specified
+explicitly as a target in
+.Nm
+command line.
+.Pp
+Additionally, system makefiles and
+.Ic .depend
+are not considered as Makefiles that can be rebuilt.
 .Sh ENVIRONMENT
 The
 .Nm
@@ -1500,7 +1665,9 @@
 .Ev MAKE
 instead of
 .Ev MAKEFLAGS .
-This was removed for POSIX compatibility.
+This was removed for
+.Tn POSIX
+compatibility.
 The internal variable
 .Va MAKE
 is set to the same value as
@@ -1581,7 +1748,7 @@
 A trailing backslash in a variable value defined on the command line causes
 the delimiting space in the
 .Ev MAKEFLAGS
-environment variable to be preceeded by that backslash.
+environment variable to be preceded by that backslash.
 That causes a submake to not treat that space as a word delimiter.
 Fixing this requires a larger rewrite of the code handling command line
 macros and assignments to
Index: make.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/make.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/make.c -L usr.bin/make/make.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/make.c
+++ usr.bin/make/make.c
@@ -39,7 +39,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/make.c,v 1.38 2005/05/24 16:05:51 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/make.c,v 1.39 2007/04/20 06:33:25 fjoe Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*
  * make.c
@@ -118,6 +119,7 @@
 
 	if (cgn->mtime > pgn->cmtime) {
 		pgn->cmtime = cgn->mtime;
+		pgn->cmtime_gn = cgn;
 	}
 	return (0);
 }
@@ -223,7 +225,8 @@
 		 * Make does it.
 		 */
 		if (gn->mtime < gn->cmtime) {
-			DEBUGF(MAKE, ("modified before source..."));
+			DEBUGF(MAKE, ("modified before source (%s)...",
+			    gn->cmtime_gn ? gn->cmtime_gn->path : "???"));
 		} else if (gn->mtime == 0) {
 			DEBUGF(MAKE, ("non-existent and no sources..."));
 		} else {
@@ -421,14 +424,9 @@
 			pgn->unmade -= 1;
 
 			if (!(cgn->type & (OP_EXEC | OP_USE))) {
-				if (cgn->made == MADE) {
+				if (cgn->made == MADE)
 					pgn->childMade = TRUE;
-					if (pgn->cmtime < cgn->mtime) {
-						pgn->cmtime = cgn->mtime;
-					}
-				} else {
-					Make_TimeStamp(pgn, cgn);
-				}
+				Make_TimeStamp(pgn, cgn);
 			}
 			if (pgn->unmade == 0) {
 				/*
Index: str.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/str.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/str.h -L usr.bin/make/str.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/str.h
+++ usr.bin/make/str.h
@@ -35,6 +35,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/str.h,v 1.6 2005/05/23 13:27:52 harti Exp $
  */
 
Index: Makefile.dist
===================================================================
RCS file: /home/cvs/src/usr.bin/make/Makefile.dist,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/Makefile.dist -L usr.bin/make/Makefile.dist -u -r1.1.1.1 -r1.2
--- usr.bin/make/Makefile.dist
+++ usr.bin/make/Makefile.dist
@@ -1,7 +1,11 @@
-# $FreeBSD: src/usr.bin/make/Makefile.dist,v 1.4 2005/05/24 13:19:40 harti Exp $
-# a very simple makefile...
+# $MidnightBSD$
+# $FreeBSD: src/usr.bin/make/Makefile.dist,v 1.6 2008/03/04 05:35:27 imp Exp $
+# a simple makefile to help builds on !FreeBSD systems
 pmake:
 	@echo 'make started.'
-	cc -DDEFSHELLNAME=\"sh\" -I. -c *.c
+	cc -D__dead2="" -D__unused="" -Darc4random=random -D__FBSDID="static const char *id=" -DDEFSHELLNAME=\"sh\" -I. -c *.c
 	cc *.o -o pmake
 	@echo 'make completed.'
+
+clean:
+	@rm -f *.o pmake
Index: parse.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/parse.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/parse.h -L usr.bin/make/parse.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/parse.h
+++ usr.bin/make/parse.h
@@ -35,6 +35,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/parse.h,v 1.6 2005/05/13 08:53:00 harti Exp $
  */
 
Index: targ.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/targ.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/targ.h -L usr.bin/make/targ.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/targ.h
+++ usr.bin/make/targ.h
@@ -35,6 +35,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/targ.h,v 1.2 2005/02/04 07:51:00 harti Exp $
  */
 
Index: suff.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/suff.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/suff.h -L usr.bin/make/suff.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/suff.h
+++ usr.bin/make/suff.h
@@ -35,6 +35,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/suff.h,v 1.3 2005/03/23 12:56:15 harti Exp $
  */
 
Index: job.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/job.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/job.c -L usr.bin/make/job.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/job.c
+++ usr.bin/make/job.c
@@ -40,11 +40,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/job.c,v 1.122.2.1 2005/07/20 19:05:23 harti Exp $");
-
-#ifndef OLD_JOKE
-#define	OLD_JOKE 0
-#endif /* OLD_JOKE */
+/* $FreeBSD: src/usr.bin/make/job.c,v 1.130 2008/09/29 16:13:28 ache Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*-
  * job.c --
@@ -415,7 +412,12 @@
 	 * them with random characters until there are no more 'X'.
 	 */
 	while (ptr >= template && *ptr == 'X') {
-		uint32_t rand_num = arc4random() % (sizeof(padchar) - 1);
+		uint32_t rand_num =
+#if __FreeBSD_version < 800041
+			arc4random() % (sizeof(padchar) - 1);
+#else
+			arc4random_uniform(sizeof(padchar) - 1);
+#endif
 		*ptr-- = padchar[rand_num];
 	}
 	start = ptr + 1;
@@ -1271,7 +1273,7 @@
 				fflush(stdout);
 				return (FALSE);
 			} else {
-#if OLD_JOKE
+#ifndef WITHOUT_OLD_JOKE
 				if (strcmp(gn->name,"love") == 0)
 					(*abortProc)("Not war.");
 				else
@@ -2338,7 +2340,7 @@
 			jobFull = FALSE;
 		}
 	}
-	if (fifoFd <= 0) {
+	if (fifoFd < 0) {
 		maxJobs = maxproc;
 		jobFull = FALSE;
 	} else {
@@ -2528,6 +2530,8 @@
 			}
 		}
 	}
+	if (fifoMaster)
+		unlink(fifoName);
 }
 
 /**
@@ -3068,7 +3072,7 @@
 
 /*-
  *-----------------------------------------------------------------------
- * CompatMake --
+ * Compat_Make --
  *	Make a target, given the parent, to abort if necessary.
  *
  * Side Effects:
@@ -3076,8 +3080,8 @@
  *
  *-----------------------------------------------------------------------
  */
-static int
-CompatMake(GNode *gn, GNode *pgn)
+int
+Compat_Make(GNode *gn, GNode *pgn)
 {
 	LstNode	*ln;
 
@@ -3097,7 +3101,7 @@
 		gn->made = BEINGMADE;
 		Suff_FindDeps(gn);
 		LST_FOREACH(ln, &gn->children)
-			CompatMake(Lst_Datum(ln), gn);
+			Compat_Make(Lst_Datum(ln), gn);
 		if (!gn->make) {
 			gn->made = ABORTED;
 			pgn->make = FALSE;
@@ -3287,6 +3291,27 @@
 }
 
 /*-
+ * Install signal handlers for Compat_Run
+ */
+void
+Compat_InstallSignalHandlers(void)
+{
+
+	if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
+		signal(SIGINT, CompatCatchSig);
+	}
+	if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
+		signal(SIGTERM, CompatCatchSig);
+	}
+	if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
+		signal(SIGHUP, CompatCatchSig);
+	}
+	if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
+		signal(SIGQUIT, CompatCatchSig);
+	}
+}
+
+/*-
  *-----------------------------------------------------------------------
  * Compat_Run --
  *	Start making again, given a list of target nodes.
@@ -3306,19 +3331,7 @@
 	int	error_cnt;		/* Number of targets not remade due to errors */
 	LstNode	*ln;
 
-	if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
-		signal(SIGINT, CompatCatchSig);
-	}
-	if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
-		signal(SIGTERM, CompatCatchSig);
-	}
-	if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
-		signal(SIGHUP, CompatCatchSig);
-	}
-	if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
-		signal(SIGQUIT, CompatCatchSig);
-	}
-
+	Compat_InstallSignalHandlers();
 	ENDNode = Targ_FindNode(".END", TARG_CREATE);
 	/*
 	 * If the user has defined a .BEGIN target, execute the commands
@@ -3339,8 +3352,8 @@
 	}
 
 	/*
-	 * For each entry in the list of targets to create, call CompatMake on
-	 * it to create the thing. CompatMake will leave the 'made' field of gn
+	 * For each entry in the list of targets to create, call Compat_Make on
+	 * it to create the thing. Compat_Make will leave the 'made' field of gn
 	 * in one of several states:
 	 *	UPTODATE  gn was already up-to-date
 	 *	MADE	  gn was recreated successfully
@@ -3351,7 +3364,7 @@
 	error_cnt = 0;
 	while (!Lst_IsEmpty(targs)) {
 		gn = Lst_DeQueue(targs);
-		CompatMake(gn, gn);
+		Compat_Make(gn, gn);
 
 		if (gn->made == UPTODATE) {
 			printf("`%s' is up to date.\n", gn->name);
Index: cond.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/cond.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/cond.h -L usr.bin/make/cond.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/cond.h
+++ usr.bin/make/cond.h
@@ -35,6 +35,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/cond.h,v 1.3 2005/04/11 07:20:09 harti Exp $
  */
 
Index: for.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/for.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/for.c -L usr.bin/make/for.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/for.c
+++ usr.bin/make/for.c
@@ -33,7 +33,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/for.c,v 1.43 2005/05/10 12:02:15 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/for.c,v 1.44 2008/03/24 12:33:28 ru Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*-
  * for.c --
@@ -56,6 +57,7 @@
 #include "lst.h"
 #include "make.h"
 #include "parse.h"
+#include "str.h"
 #include "util.h"
 #include "var.h"
 
@@ -97,6 +99,8 @@
 	char	*sub;
 	Buffer	*buf;
 	size_t	varlen;
+	int	i;
+	ArgArray words;
 
 	ptr = line;
 
@@ -148,33 +152,16 @@
 
 	/*
 	 * Make a list with the remaining words
-	 * XXX should use brk_string here.
 	 */
 	sub = Buf_Peel(Var_Subst(ptr, VAR_CMD, FALSE));
-	for (ptr = sub; *ptr != '\0' && isspace((u_char)*ptr); ptr++)
-		;
-
+	brk_string(&words, sub, FALSE);
 	Lst_Init(&forLst);
-	buf = Buf_Init(0);
-	for (wrd = ptr; *ptr != '\0'; ptr++) {
-		if (isspace((u_char)*ptr)) {
-			Buf_AppendRange(buf, wrd, ptr);
-			Lst_AtFront(&forLst, Buf_Peel(buf));
-
-			buf = Buf_Init(0);
-			while (*ptr != '\0' && isspace((u_char)*ptr))
-				ptr++;
-			wrd = ptr--;
-		}
+	for (i = 1; i < words.argc; i++) {
+		if (words.argv[i][0] != '\0')
+			Lst_AtFront(&forLst, estrdup(words.argv[i]));
 	}
+	ArgArray_Done(&words);
 	DEBUGF(FOR, ("For: Iterator %s List %s\n", forVar, sub));
-
-	if (ptr - wrd > 0) {
-		Buf_AppendRange(buf, wrd, ptr);
-		Lst_AtFront(&forLst, Buf_Peel(buf));
-	} else {
-		Buf_Destroy(buf, TRUE);
-	}
 	free(sub);
 
 	forBuf = Buf_Init(0);
Index: hash_tables.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/hash_tables.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/hash_tables.h -L usr.bin/make/hash_tables.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/hash_tables.h
+++ usr.bin/make/hash_tables.h
@@ -23,6 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/hash_tables.h,v 1.1 2005/04/29 15:15:28 harti Exp $
  */
 #ifndef hash_tables_h_
Index: globals.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/globals.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/globals.h -L usr.bin/make/globals.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/globals.h
+++ usr.bin/make/globals.h
@@ -35,7 +35,8 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/usr.bin/make/globals.h,v 1.10 2005/05/13 08:53:00 harti Exp $
+ * $MidnightBSD$
+ * $FreeBSD: src/usr.bin/make/globals.h,v 1.12 2008/03/12 14:50:58 obrien Exp $
  */
 
 #ifndef globals_h_1c1edb96
@@ -77,6 +78,8 @@
 extern Boolean	beVerbose;	/* True if should print extra cruft */
 extern Boolean	noExecute;	/* True if should execute nothing */
 extern Boolean	allPrecious;	/* True if every target is precious */
+extern Boolean	is_posix;	/* .POSIX target seen */
+extern Boolean	mfAutoDeps;	/* .MAKEFILEDEPS target seen */
 
 /* True if should continue on unaffected portions of the graph
  * when have an error in one portion */
Index: proc.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/proc.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/proc.c -L usr.bin/make/proc.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/proc.c
+++ usr.bin/make/proc.c
@@ -25,7 +25,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/proc.c,v 1.1 2005/05/24 15:41:34 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/proc.c,v 1.1 2005/05/24 15:41:34 harti Exp $ */
+__MBSDID("$MidnightBSD$");
 
 #include <unistd.h>
 #include <errno.h>
Index: pathnames.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/pathnames.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/pathnames.h -L usr.bin/make/pathnames.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/pathnames.h
+++ usr.bin/make/pathnames.h
@@ -28,6 +28,7 @@
  *
  *	@(#)pathnames.h	8.2 (Berkeley) 4/28/95
  * $FreeBSD: src/usr.bin/make/pathnames.h,v 1.14 2005/03/11 13:02:38 harti Exp $
+ * $MidnightBSD$
  */
 
 #ifndef pathnames_h_235b888a
Index: util.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/util.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/util.c -L usr.bin/make/util.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/util.c
+++ usr.bin/make/util.c
@@ -40,7 +40,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/util.c,v 1.19 2005/05/13 13:47:41 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/util.c,v 1.19 2005/05/13 13:47:41 harti Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*-
  * util.c --
Index: targ.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/targ.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/targ.c -L usr.bin/make/targ.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/targ.c
+++ usr.bin/make/targ.c
@@ -39,7 +39,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/targ.c,v 1.41 2005/05/13 13:47:41 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/targ.c,v 1.42 2007/04/20 06:33:25 fjoe Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*
  * Functions for maintaining the Lst allTargets. Target nodes are
@@ -141,6 +142,7 @@
 	gn->childMade = FALSE;
 	gn->order = 0;
 	gn->mtime = gn->cmtime = 0;
+	gn->cmtime_gn = NULL;
 	Lst_Init(&gn->iParents);
 	Lst_Init(&gn->cohorts);
 	Lst_Init(&gn->parents);
Index: config.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/config.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/config.h -L usr.bin/make/config.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/config.h
+++ usr.bin/make/config.h
@@ -38,6 +38,7 @@
  *
  *	@(#)config.h	8.2 (Berkeley) 4/28/95
  * $FreeBSD: src/usr.bin/make/config.h,v 1.16 2005/02/01 10:50:35 harti Exp $
+ * $MidnightBSD$
  */
 
 #ifndef config_h_efe0765e
Index: var.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/var.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/var.h -L usr.bin/make/var.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/var.h
+++ usr.bin/make/var.h
@@ -36,6 +36,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/var.h,v 1.29 2005/05/24 16:05:51 harti Exp $
  */
 
Index: make.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/make.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/make.h -L usr.bin/make/make.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/make.h
+++ usr.bin/make/make.h
@@ -36,7 +36,8 @@
  * SUCH DAMAGE.
  *
  *	@(#)make.h	8.3 (Berkeley) 6/13/95
- * $FreeBSD: src/usr.bin/make/make.h,v 1.34 2005/05/13 08:53:00 harti Exp $
+ * $FreeBSD: src/usr.bin/make/make.h,v 1.35 2007/03/08 09:16:10 fjoe Exp $
+ * $MidnightBSD$
  */
 
 #ifndef make_h_a91074b9
@@ -68,5 +69,6 @@
 Boolean Make_Run(struct Lst *);
 void Main_ParseArgLine(char *, int);
 int Main_ParseWarn(const char *, int);
+void Main_AddSourceMakefile(const char *);
 
 #endif /* make_h_a91074b9 */
Index: job.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/job.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/job.h -L usr.bin/make/job.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/job.h
+++ usr.bin/make/job.h
@@ -37,7 +37,8 @@
  * SUCH DAMAGE.
  *
  *	@(#)job.h	8.1 (Berkeley) 6/6/93
- * $FreeBSD: src/usr.bin/make/job.h,v 1.45 2005/05/24 15:30:03 harti Exp $
+ * $FreeBSD: src/usr.bin/make/job.h,v 1.46 2007/03/08 09:16:10 fjoe Exp $
+ * $MidnightBSD$
  */
 
 #ifndef job_h_4678dfd1
@@ -72,6 +73,8 @@
 
 struct Buffer *Cmd_Exec(const char *, const char **);
 
+int Compat_Make(struct GNode *gn, struct GNode *pgn);
+void Compat_InstallSignalHandlers(void);
 void Compat_Run(struct Lst *);
 
 #endif /* job_h_4678dfd1 */
Index: dir.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/dir.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/dir.c -L usr.bin/make/dir.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/dir.c
+++ usr.bin/make/dir.c
@@ -40,7 +40,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/dir.c,v 1.52 2005/03/23 12:56:15 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/dir.c,v 1.52 2005/03/23 12:56:15 harti Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*-
  * dir.c --
Index: lst.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/lst.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/lst.c -L usr.bin/make/lst.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/lst.c
+++ usr.bin/make/lst.c
@@ -29,6 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/lst.c,v 1.7 2005/05/18 06:50:39 harti Exp $
  */
 
Index: for.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/for.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/for.h -L usr.bin/make/for.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/for.h
+++ usr.bin/make/for.h
@@ -36,6 +36,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.bin/make/for.h,v 1.3 2005/05/13 08:53:00 harti Exp $
+ * $MidnightBSD$
  */
 
 #ifndef for_h_9d770f33
Index: hash_tables.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/hash_tables.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/hash_tables.c -L usr.bin/make/hash_tables.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/hash_tables.c
+++ usr.bin/make/hash_tables.c
@@ -1,7 +1,7 @@
 /*
  * DO NOT EDIT
- * $FreeBSD: src/usr.bin/make/hash_tables.c,v 1.2 2005/05/06 18:30:05 harti Exp $
- * auto-generated from FreeBSD: src/usr.bin/make/parse.c,v 1.100 2005/04/29 15:15:28 harti Exp 
+ * $FreeBSD: src/usr.bin/make/hash_tables.c,v 1.4 2008/03/12 14:51:47 obrien Exp $
+ * auto-generated from FreeBSD: src/usr.bin/make/parse.c,v 1.114 2008/03/12 14:50:58 obrien Exp 
  * DO NOT EDIT
  */
 #include <sys/types.h>
@@ -10,8 +10,8 @@
 
 /*
  * d=2
- * n=38
- * m=18
+ * n=40
+ * m=19
  * c=2.09
  * maxlen=1
  * minklen=2
@@ -19,27 +19,27 @@
  * minchar=97
  * maxchar=119
  * loop=0
- * numiter=2
+ * numiter=1
  * seed=
  */
 
 static const signed char directive_g[] = {
-	16, 0, -1, 14, 5, 2, 2, -1, 0, 0,
-	-1, -1, 16, 11, -1, 15, -1, 14, 7, -1,
-	8, 6, 1, -1, -1, 0, 4, 6, -1, 0,
-	0, 2, 0, 13, -1, 14, -1, 0, 
+	8, 0, 0, 5, 6, -1, 17, 15, 10, 6,
+	-1, -1, 10, 0, 0, -1, 18, 2, 3, 0,
+	7, -1, -1, -1, 0, 14, -1, -1, 11, 16,
+	-1, -1, 0, -1, 0, 0, 17, 0, -1, 1,
 };
 
 static const u_char directive_T0[] = {
-	11, 25, 14, 30, 14, 26, 23, 15, 9, 37,
-	27, 32, 27, 1, 17, 27, 35, 13, 8, 22,
-	8, 28, 7, 
+	26, 14, 19, 35, 10, 34, 18, 27, 1, 17,
+	22, 37, 12, 12, 36, 21, 0, 6, 1, 25,
+	9, 4, 19, 
 };
 
 static const u_char directive_T1[] = {
-	19, 20, 31, 17, 29, 2, 7, 12, 1, 31,
-	11, 18, 11, 20, 10, 2, 15, 19, 4, 10,
-	13, 36, 3, 
+	25, 22, 19, 0, 2, 18, 33, 18, 30, 4,
+	30, 9, 21, 19, 16, 12, 35, 34, 4, 19,
+	9, 33, 16, 
 };
 
 
@@ -59,19 +59,19 @@
 		f1 += directive_T1[-97 + *kp];
 	}
 
-	f0 %= 38;
-	f1 %= 38;
+	f0 %= 40;
+	f1 %= 40;
 
-	return (directive_g[f0] + directive_g[f1]) % 18;
+	return (directive_g[f0] + directive_g[f1]) % 19;
 }
 /*
  * d=2
- * n=72
- * m=34
+ * n=74
+ * m=35
  * c=2.09
  * maxlen=1
  * minklen=4
- * maxklen=12
+ * maxklen=13
  * minchar=46
  * maxchar=95
  * loop=0
@@ -80,30 +80,30 @@
  */
 
 static const signed char keyword_g[] = {
-	8, 15, -1, 25, 22, 20, -1, 33, 16, -1,
-	21, 31, 0, 0, 0, 29, 30, 8, -1, 0,
-	-1, 21, -1, 0, -1, -1, -1, -1, -1, 4,
-	-1, -1, 25, 28, -1, 27, 11, 23, 0, 0,
-	24, -1, -1, 0, 3, 0, -1, 24, 0, 0,
-	-1, 28, 12, -1, 20, 13, -1, 5, -1, 1,
-	0, 0, -1, 0, 10, 19, 13, 9, -1, 2,
-	-1, -1, 
+	12, 18, 7, 25, 30, 5, -1, -1, -1, 7,
+	-1, 0, 33, 0, 4, -1, -1, 13, 29, 0,
+	-1, 28, -1, 28, -1, 0, -1, 27, 4, 34,
+	-1, -1, -1, 30, 13, 10, -1, -1, 0, 10,
+	24, -1, -1, -1, 0, 6, 0, 0, -1, 23,
+	-1, -1, -1, 0, -1, 23, -1, -1, 19, 4,
+	-1, 31, 12, 16, -1, 20, 22, 9, 0, -1,
+	-1, 9, 4, 0, 
 };
 
 static const u_char keyword_T0[] = {
-	32, 10, 54, 61, 2, 35, 62, 50, 52, 53,
-	70, 7, 62, 18, 24, 30, 31, 66, 10, 61,
-	52, 71, 56, 56, 28, 6, 33, 67, 12, 41,
-	39, 45, 51, 21, 34, 53, 56, 40, 47, 52,
-	21, 61, 60, 12, 7, 28, 42, 38, 38, 52,
+	34, 28, 50, 61, 14, 57, 48, 60, 20, 67,
+	60, 63, 0, 24, 28, 2, 49, 64, 18, 23,
+	36, 33, 40, 14, 38, 42, 71, 49, 2, 53,
+	53, 37, 7, 29, 24, 21, 12, 50, 59, 10,
+	43, 23, 0, 44, 47, 6, 46, 22, 48, 64,
 };
 
 static const u_char keyword_T1[] = {
-	0, 39, 65, 48, 13, 62, 46, 42, 5, 50,
-	69, 69, 69, 43, 2, 46, 12, 6, 11, 9,
-	24, 10, 25, 64, 68, 13, 57, 55, 17, 33,
-	1, 18, 0, 67, 10, 14, 57, 56, 0, 6,
-	50, 13, 3, 47, 56, 22, 37, 13, 28, 48,
+	18, 67, 39, 60, 7, 70, 2, 26, 31, 18,
+	73, 47, 61, 17, 38, 50, 22, 52, 13, 55,
+	56, 32, 63, 4, 64, 55, 49, 21, 47, 67,
+	33, 66, 60, 73, 30, 68, 69, 32, 72, 4,
+	28, 49, 51, 15, 66, 68, 43, 67, 46, 56,
 };
 
 
@@ -113,7 +113,7 @@
 	unsigned f0, f1;
 	const u_char *kp = key;
 
-	if (len < 4 || len > 12)
+	if (len < 4 || len > 13)
 		return -1;
 
 	for (f0=f1=0; *kp; ++kp) {
@@ -123,8 +123,8 @@
 		f1 += keyword_T1[-46 + *kp];
 	}
 
-	f0 %= 72;
-	f1 %= 72;
+	f0 %= 74;
+	f1 %= 74;
 
-	return (keyword_g[f0] + keyword_g[f1]) % 34;
+	return (keyword_g[f0] + keyword_g[f1]) % 35;
 }
Index: buf.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/buf.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/buf.h -L usr.bin/make/buf.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/buf.h
+++ usr.bin/make/buf.h
@@ -38,6 +38,7 @@
  *
  *	@(#)buf.h	8.2 (Berkeley) 4/28/95
  * $FreeBSD: src/usr.bin/make/buf.h,v 1.27 2005/05/13 08:53:00 harti Exp $
+ * $MidnightBSD$
  */
 
 #ifndef buf_h_a61a6812
Index: hash.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/hash.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/hash.h -L usr.bin/make/hash.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/hash.h
+++ usr.bin/make/hash.h
@@ -38,6 +38,7 @@
  *
  *	@(#)hash.h	8.1 (Berkeley) 6/6/93
  * $FreeBSD: src/usr.bin/make/hash.h,v 1.20 2005/05/13 08:53:00 harti Exp $
+ * $MidnightBSD$
  */
 
 #ifndef hash_h_f6312f46
Index: parse.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/parse.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/parse.c -L usr.bin/make/parse.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/parse.c
+++ usr.bin/make/parse.c
@@ -39,7 +39,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/parse.c,v 1.108.2.1 2005/11/16 08:25:19 ru Exp $");
+/* $FreeBSD: src/usr.bin/make/parse.c,v 1.114 2008/03/12 14:50:58 obrien Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*-
  * parse.c --
@@ -168,6 +169,7 @@
 	ExPath,		/* .PATH */
 	Phony,		/* .PHONY */
 	Posix,		/* .POSIX */
+	MakefileDeps,	/* .MAKEFILEDEPS */
 	Precious,	/* .PRECIOUS */
 	ExShell,	/* .SHELL */
 	Silent,		/* .SILENT */
@@ -213,6 +215,7 @@
 	{ ".LIBS",		Libs,		0 },
 	{ ".MAIN",		Main,		0 },
 	{ ".MAKE",		Attribute,	OP_MAKE },
+	{ ".MAKEFILEDEPS",	MakefileDeps,	0 },
 	{ ".MAKEFLAGS",		MFlags,		0 },
 	{ ".MFLAGS",		MFlags,		0 },
 	{ ".NOTMAIN",		Attribute,	OP_NOTMAIN },
@@ -239,6 +242,7 @@
 #define	NKEYWORDS	(sizeof(parseKeywords) / sizeof(parseKeywords[0]))
 
 static void parse_include(char *, int, int);
+static void parse_sinclude(char *, int, int);
 static void parse_message(char *, int, int);
 static void parse_undef(char *, int, int);
 static void parse_for(char *, int, int);
@@ -267,6 +271,7 @@
 	{ "ifndef",	COND_IFNDEF,	TRUE,	Cond_If },
 	{ "ifnmake",	COND_IFNMAKE,	TRUE,	Cond_If },
 	{ "include",	0,		FALSE,	parse_include },
+	{ "sinclude",	0,		FALSE,	parse_sinclude },
 	{ "undef",	0,		FALSE,	parse_undef },
 	{ "warning",	0,		FALSE,	parse_message },
 	/* DIRECTIVES-END-TAG */
@@ -1067,7 +1072,11 @@
 			LST_FOREACH(ln, &paths)
 			Path_Clear(Lst_Datum(ln));
 			break;
+		  case MakefileDeps:
+			mfAutoDeps = TRUE;
+			break;
 		  case Posix:
+			is_posix = TRUE;
 			Var_Set("%POSIX", "1003.2", VAR_GLOBAL);
 			break;
 		  default:
@@ -2057,7 +2066,7 @@
 }
 
 /**
- * parse_include
+ * xparse_include
  *	Parse an .include directive and push the file onto the input stack.
  *	The input is the line minus the .include. A file spec is a string
  *	enclosed in <> or "". The former is looked for only in sysIncPath.
@@ -2065,7 +2074,7 @@
  *	options
  */
 static void
-parse_include(char *file, int code __unused, int lineno __unused)
+xparse_include(char *file, int sinclude)
 {
 	char	*fullname;	/* full pathname of file */
 	char	endc;		/* the character which ends the file spec */
@@ -2180,10 +2189,14 @@
 
 	if (fullname == NULL) {
 		*cp = endc;
-		Parse_Error(PARSE_FATAL, "Could not find %s", file);
+		if (!sinclude)
+			Parse_Error(PARSE_FATAL, "Could not find %s", file);
+		else
+			Main_AddSourceMakefile(file);
 		free(file);
 		return;
 	}
+	Main_AddSourceMakefile(fullname);
 	free(file);
 
 	/*
@@ -2192,6 +2205,19 @@
 	 * place.
 	 */
 	ParsePushInput(fullname, NULL, NULL, 0);
+	DEBUGF(DIR, (".include %s\n", fullname));
+}
+
+static void
+parse_include(char *file, int code __unused, int lineno __unused)
+{
+	xparse_include(file, 0);
+}
+
+static void
+parse_sinclude(char *file, int code __unused, int lineno __unused)
+{
+	xparse_include(file, 1);
 }
 
 /**
@@ -2215,7 +2241,7 @@
 	while (isspace((u_char)*line))
 		line++;
 
-	line = Buf_Peel(Var_Subst(line, VAR_GLOBAL, FALSE));
+	line = Buf_Peel(Var_Subst(line, VAR_CMD, FALSE));
 	Parse_Error(iserror ? PARSE_FATAL : PARSE_WARNING, "%s", line);
 	free(line);
 
Index: shell.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/shell.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/shell.h -L usr.bin/make/shell.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/shell.h
+++ usr.bin/make/shell.h
@@ -36,6 +36,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * $MidnightBSD$
  * $FreeBSD: src/usr.bin/make/shell.h,v 1.1 2005/05/24 15:30:03 harti Exp $
  */
 
Index: shell.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/shell.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/shell.c -L usr.bin/make/shell.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/shell.c
+++ usr.bin/make/shell.c
@@ -38,7 +38,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/shell.c,v 1.1 2005/05/24 15:30:03 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/shell.c,v 1.1 2005/05/24 15:30:03 harti Exp $ */
+__MBSDID("$MidnightBSD$");
 
 #include <sys/queue.h>
 #include <stdio.h>
Index: var.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/var.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/var.c -L usr.bin/make/var.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/var.c
+++ usr.bin/make/var.c
@@ -40,7 +40,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/var.c,v 1.159 2005/05/24 16:05:51 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/var.c,v 1.163 2006/07/17 21:05:27 obrien Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /**
  * var.c --
@@ -1025,10 +1026,9 @@
 			 */
 			setenv(n, val, 1);
 		}
-
+		DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, val));
 	}
 
-	DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, val));
 	free(n);
 }
 
@@ -1232,6 +1232,41 @@
 }
 
 /**
+ * Remove adjacent duplicate words.
+ *
+ * Results:
+ *	A string containing the resulting words.
+ */
+static char *
+VarUniq(const char *str)
+{
+	ArgArray	aa;
+	Buffer		*buf;		    /* Buffer for new string */
+	int		i, j;
+
+	buf = Buf_Init(0);
+	brk_string(&aa, str, FALSE);
+
+	if (aa.argc > 2) {
+		for (j = 1, i = 2; i < aa.argc; i++) {
+			if (strcmp(aa.argv[i], aa.argv[j]) != 0 && (++j != i))
+				aa.argv[j] = aa.argv[i];
+		}
+		aa.argc = j + 1;
+	}
+
+	for (i = 1; i < aa.argc; i++) {
+		Buf_AddBytes(buf, strlen(aa.argv[i]), (Byte *)aa.argv[i]);
+		if (i != aa.argc - 1)
+			Buf_AddByte(buf, ' ');
+	}
+	Buf_AddByte(buf, '\0');
+
+	ArgArray_Done(&aa);
+	return (Buf_Peel(buf));
+}
+
+/**
  * Pass through the tstr looking for 1) escaped delimiters,
  * '$'s and backslashes (place the escaped character in
  * uninterpreted) and 2) unescaped $'s that aren't before
@@ -1666,6 +1701,10 @@
  *		words which match the given <pattern>.
  *		<pattern> is of the standard file
  *		wildcarding form.
+ *	:N<pattern>
+ *		words which do not match the given <pattern>
+ *		<pattern> is of the standard file
+ *		wildcarding form.
  *	:S<d><pat1><d><pat2><d>[g]
  *		Substitute <pat2> for <pat1> in the value
  *	:C<d><pat1><d><pat2><d>[g]
@@ -1681,8 +1720,8 @@
  *		the invocation.
  *	:U	Converts variable to upper-case.
  *	:L	Converts variable to lower-case.
- *
- * XXXHB update this comment or remove it and point to the man page.
+ *	:O	("Order") Alphabeticaly sort words in variable.
+ *	:u	("uniq") Remove adjacent duplicate words.
  */
 static char *
 ParseModifier(VarParser *vp, char startc, Var *v, Boolean *freeResult)
@@ -1793,6 +1832,10 @@
 				newStr = VarModify(value, VarRoot, NULL);
 				vp->ptr++;
 				break;
+			case 'u':
+				newStr = VarUniq(value);
+				vp->ptr++;
+				break;
 			default:
 				newStr = sysVvarsub(vp, startc, v, value);
 				break;
@@ -2246,7 +2289,7 @@
 				   str[0] == CLOSE_BRACE) {
 				len = str - (start + 2);
 
-				if (var[len] == '\0' && strncmp(var, start + 2, len) == 0) {
+				if (strncmp(var, start + 2, len) == 0 && var[len] == '\0') {
 					return (0);	/* match */
 				} else {
 					/*
Index: str.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/str.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/str.c -L usr.bin/make/str.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/str.c
+++ usr.bin/make/str.c
@@ -39,7 +39,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/str.c,v 1.45 2005/05/23 13:27:52 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/str.c,v 1.46 2006/10/09 19:37:26 ru Exp $ */
+__MBSDID("$MidnightBSD$");
 
 #include <ctype.h>
 #include <stdlib.h>
@@ -260,8 +261,10 @@
 				}
 			} else {
 				*arg++ = str[0];
-				++str;
-				*arg++ = str[0];
+				if (str[1] != '\0') {
+					++str;
+					*arg++ = str[0];
+				}
 			}
 			break;
 		default:
Index: hash.c
===================================================================
RCS file: /home/cvs/src/usr.bin/make/hash.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/hash.c -L usr.bin/make/hash.c -u -r1.1.1.1 -r1.2
--- usr.bin/make/hash.c
+++ usr.bin/make/hash.c
@@ -40,7 +40,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/make/hash.c,v 1.25 2005/05/13 08:53:00 harti Exp $");
+/* $FreeBSD: src/usr.bin/make/hash.c,v 1.25 2005/05/13 08:53:00 harti Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /* hash.c --
  *
Index: GNode.h
===================================================================
RCS file: /home/cvs/src/usr.bin/make/GNode.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/make/GNode.h -L usr.bin/make/GNode.h -u -r1.1.1.1 -r1.2
--- usr.bin/make/GNode.h
+++ usr.bin/make/GNode.h
@@ -35,7 +35,8 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/usr.bin/make/GNode.h,v 1.4 2005/05/13 08:53:00 harti Exp $
+ * $MidnightBSD$
+ * $FreeBSD: src/usr.bin/make/GNode.h,v 1.5 2007/04/20 06:33:25 fjoe Exp $
  */
 
 #ifndef GNode_h_39503bf2
@@ -170,6 +171,7 @@
 	int	unmade;		/* The number of unmade children */
 	int	mtime;		/* Its modification time */
 	int	cmtime;		/* Modification time of its youngest child */
+	struct GNode *cmtime_gn;/* Youngest child */
 
 	/*
 	 * Links to parents for which this is an implied source, if any. (nodes


More information about the Midnightbsd-cvs mailing list