Module Name:    src
Committed By:   rillig
Date:           Mon Nov 23 19:27:20 UTC 2020

Modified Files:
        src/usr.bin/make: compat.c

Log Message:
make(1): split Compat_Make into smaller functions


To generate a diff of this commit:
cvs rdiff -u -r1.184 -r1.185 src/usr.bin/make/compat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/compat.c
diff -u src/usr.bin/make/compat.c:1.184 src/usr.bin/make/compat.c:1.185
--- src/usr.bin/make/compat.c:1.184	Mon Nov 23 19:14:24 2020
+++ src/usr.bin/make/compat.c	Mon Nov 23 19:27:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.184 2020/11/23 19:14:24 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.185 2020/11/23 19:27:20 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -96,7 +96,7 @@
 #include "pathnames.h"
 
 /*	"@(#)compat.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: compat.c,v 1.184 2020/11/23 19:14:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.185 2020/11/23 19:27:20 rillig Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -461,21 +461,9 @@ MakeNodes(GNodeList *gnodes, GNode *pgn)
     }
 }
 
-/* Make a target.
- *
- * If an error is detected and not being ignored, the process exits.
- *
- * Input:
- *	gn		The node to make
- *	pgn		Parent to abort if necessary
- */
-void
-Compat_Make(GNode *gn, GNode *pgn)
+static Boolean
+MakeUnmade(GNode *const gn, GNode *const pgn)
 {
-    if (shellName == NULL)	/* we came here from jobs */
-	Shell_Init();
-
-    if (gn->made == UNMADE && (gn == pgn || !(pgn->type & OP_MADE))) {
 	/*
 	 * First mark ourselves to be made, then apply whatever transformations
 	 * the suffix module thinks are necessary. Once that's done, we can
@@ -487,16 +475,16 @@ Compat_Make(GNode *gn, GNode *pgn)
 	gn->flags |= REMAKE;
 	gn->made = BEINGMADE;
 	if (!(gn->type & OP_MADE))
-	    Suff_FindDeps(gn);
+		Suff_FindDeps(gn);
 	MakeNodes(gn->children, gn);
 	if (!(gn->flags & REMAKE)) {
-	    gn->made = ABORTED;
-	    pgn->flags &= ~(unsigned)REMAKE;
-	    goto cohorts;
+		gn->made = ABORTED;
+		pgn->flags &= ~(unsigned)REMAKE;
+		return FALSE;
 	}
 
 	if (Lst_FindDatum(gn->implicitParents, pgn) != NULL)
-	    Var_Set(IMPSRC, GNode_VarTarget(gn), pgn);
+		Var_Set(IMPSRC, GNode_VarTarget(gn), pgn);
 
 	/*
 	 * All the children were made ok. Now youngestChild->mtime contains the
@@ -506,18 +494,18 @@ Compat_Make(GNode *gn, GNode *pgn)
 	 */
 	DEBUG1(MAKE, "Examining %s...", gn->name);
 	if (!GNode_IsOODate(gn)) {
-	    gn->made = UPTODATE;
-	    DEBUG0(MAKE, "up-to-date.\n");
-	    goto cohorts;
+		gn->made = UPTODATE;
+		DEBUG0(MAKE, "up-to-date.\n");
+		return FALSE;
 	} else
-	    DEBUG0(MAKE, "out-of-date.\n");
+		DEBUG0(MAKE, "out-of-date.\n");
 
 	/*
 	 * If the user is just seeing if something is out-of-date, exit now
 	 * to tell him/her "yes".
 	 */
 	if (opts.queryFlag)
-	    exit(1);
+		exit(1);
 
 	/*
 	 * We need to be re-made. We also have to make sure we've got a $?
@@ -531,83 +519,111 @@ Compat_Make(GNode *gn, GNode *pgn)
 	 * should not be printed so CompatRunCommand knows what to do.
 	 */
 	if (Targ_Ignore(gn))
-	    gn->type |= OP_IGNORE;
+		gn->type |= OP_IGNORE;
 	if (Targ_Silent(gn))
-	    gn->type |= OP_SILENT;
+		gn->type |= OP_SILENT;
 
 	if (Job_CheckCommands(gn, Fatal)) {
-	    /*
-	     * Our commands are ok, but we still have to worry about the -t
-	     * flag...
-	     */
-	    if (!opts.touchFlag || (gn->type & OP_MAKE)) {
-		curTarg = gn;
+		/*
+		 * Our commands are ok, but we still have to worry about
+		 * the -t flag.
+		 */
+		if (!opts.touchFlag || (gn->type & OP_MAKE)) {
+			curTarg = gn;
 #ifdef USE_META
-		if (useMeta && GNode_ShouldExecute(gn)) {
-		    meta_job_start(NULL, gn);
-		}
+			if (useMeta && GNode_ShouldExecute(gn)) {
+				meta_job_start(NULL, gn);
+			}
 #endif
-		RunCommands(gn);
-		curTarg = NULL;
-	    } else {
-		Job_Touch(gn, (gn->type & OP_SILENT) != 0);
-	    }
+			RunCommands(gn);
+			curTarg = NULL;
+		} else {
+			Job_Touch(gn, (gn->type & OP_SILENT) != 0);
+		}
 	} else {
-	    gn->made = ERROR;
+		gn->made = ERROR;
 	}
 #ifdef USE_META
 	if (useMeta && GNode_ShouldExecute(gn)) {
-	    if (meta_job_finish(NULL) != 0)
-		gn->made = ERROR;
+		if (meta_job_finish(NULL) != 0)
+			gn->made = ERROR;
 	}
 #endif
 
 	if (gn->made != ERROR) {
-	    /*
-	     * If the node was made successfully, mark it so, update
-	     * its modification time and timestamp all its parents.
-	     * This is to keep its state from affecting that of its parent.
-	     */
-	    gn->made = MADE;
-	    if (Make_Recheck(gn) == 0)
-		pgn->flags |= FORCE;
-	    if (!(gn->type & OP_EXEC)) {
-		pgn->flags |= CHILDMADE;
-		GNode_UpdateYoungestChild(pgn, gn);
-	    }
+		/*
+		 * If the node was made successfully, mark it so, update
+		 * its modification time and timestamp all its parents.
+		 * This is to keep its state from affecting that of its parent.
+		 */
+		gn->made = MADE;
+		if (Make_Recheck(gn) == 0)
+			pgn->flags |= FORCE;
+		if (!(gn->type & OP_EXEC)) {
+			pgn->flags |= CHILDMADE;
+			GNode_UpdateYoungestChild(pgn, gn);
+		}
 	} else if (opts.keepgoing) {
-	    pgn->flags &= ~(unsigned)REMAKE;
+		pgn->flags &= ~(unsigned)REMAKE;
 	} else {
-	    PrintOnError(gn, "\nStop.");
-	    exit(1);
+		PrintOnError(gn, "\nStop.");
+		exit(1);
 	}
-    } else if (gn->made == ERROR) {
-	/* Already had an error when making this. Tell the parent to abort. */
-	pgn->flags &= ~(unsigned)REMAKE;
-    } else {
+	return TRUE;
+}
+
+static void
+MakeOther(GNode *gn, GNode *pgn)
+{
+
 	if (Lst_FindDatum(gn->implicitParents, pgn) != NULL) {
-	    const char *target = GNode_VarTarget(gn);
-	    Var_Set(IMPSRC, target != NULL ? target : "", pgn);
+		const char *target = GNode_VarTarget(gn);
+		Var_Set(IMPSRC, target != NULL ? target : "", pgn);
 	}
+
 	switch(gn->made) {
-	    case BEINGMADE:
+	case BEINGMADE:
 		Error("Graph cycles through %s", gn->name);
 		gn->made = ERROR;
 		pgn->flags &= ~(unsigned)REMAKE;
 		break;
-	    case MADE:
+	case MADE:
 		if (!(gn->type & OP_EXEC)) {
-		    pgn->flags |= CHILDMADE;
-		    GNode_UpdateYoungestChild(pgn, gn);
+			pgn->flags |= CHILDMADE;
+			GNode_UpdateYoungestChild(pgn, gn);
 		}
 		break;
-	    case UPTODATE:
+	case UPTODATE:
 		if (!(gn->type & OP_EXEC))
-		    GNode_UpdateYoungestChild(pgn, gn);
+			GNode_UpdateYoungestChild(pgn, gn);
 		break;
-	    default:
+	default:
 		break;
 	}
+}
+
+/* Make a target.
+ *
+ * If an error is detected and not being ignored, the process exits.
+ *
+ * Input:
+ *	gn		The node to make
+ *	pgn		Parent to abort if necessary
+ */
+void
+Compat_Make(GNode *gn, GNode *pgn)
+{
+    if (shellName == NULL)	/* we came here from jobs */
+	Shell_Init();
+
+    if (gn->made == UNMADE && (gn == pgn || !(pgn->type & OP_MADE))) {
+	if (!MakeUnmade(gn, pgn))
+	    goto cohorts;
+    } else if (gn->made == ERROR) {
+	/* Already had an error when making this. Tell the parent to abort. */
+	pgn->flags &= ~(unsigned)REMAKE;
+    } else {
+    	MakeOther(gn, pgn);
     }
 
 cohorts:

Reply via email to