aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2013-08-02 05:23:57 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2013-08-02 05:23:57 +0000
commite0f69e1d23f496f590728b9bb0cf0778e4df1210 (patch)
tree9f9944063b4983031d8155b70d2f48d1bc3f290e /main.c
parent45f33ab2b2f3f9436d40a229bf4ac6dca9411c05 (diff)
downloadsrc-e0f69e1d23f496f590728b9bb0cf0778e4df1210.tar.gz
src-e0f69e1d23f496f590728b9bb0cf0778e4df1210.zip
Import bmake-20130730 - allows folk to supress job tokens.vendor/NetBSD/bmake/20130730
Notes
Notes: svn path=/vendor/NetBSD/bmake/dist/; revision=253879 svn path=/vendor/NetBSD/bmake/20130730/; revision=253880; tag=vendor/NetBSD/bmake/20130730
Diffstat (limited to 'main.c')
-rw-r--r--main.c111
1 files changed, 85 insertions, 26 deletions
diff --git a/main.c b/main.c
index 84c6935f81e4..3a164ce33f5d 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.210 2013/03/23 05:31:29 sjg Exp $ */
+/* $NetBSD: main.c,v 1.222 2013/07/18 15:31:49 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.210 2013/03/23 05:31:29 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.222 2013/07/18 15:31:49 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: main.c,v 1.210 2013/03/23 05:31:29 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.222 2013/07/18 15:31:49 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -117,17 +117,18 @@ __RCSID("$NetBSD: main.c,v 1.210 2013/03/23 05:31:29 sjg Exp $");
#include <sys/time.h>
#include <sys/param.h>
#include <sys/resource.h>
-#include <signal.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include "wait.h"
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+#include <ctype.h>
#include "make.h"
#include "hash.h"
@@ -163,6 +164,7 @@ Boolean noRecursiveExecute; /* -N flag */
Boolean keepgoing; /* -k flag */
Boolean queryFlag; /* -q flag */
Boolean touchFlag; /* -t flag */
+Boolean enterFlag; /* -w flag */
Boolean ignoreErrors; /* -i flag */
Boolean beSilent; /* -s flag */
Boolean oldVars; /* variable substitution style */
@@ -184,6 +186,7 @@ char curdir[MAXPATHLEN + 1]; /* Startup directory */
char *progname; /* the program name */
char *makeDependfile;
pid_t myPid;
+int makelevel;
Boolean forceJobs = FALSE;
@@ -198,6 +201,38 @@ Boolean forceJobs = FALSE;
extern Lst parseIncPath;
+/*
+ * For compatibility with the POSIX version of MAKEFLAGS that includes
+ * all the options with out -, convert flags to -f -l -a -g -s.
+ */
+static char *
+explode(const char *flags)
+{
+ size_t len;
+ char *nf, *st;
+ const char *f;
+
+ if (flags == NULL)
+ return NULL;
+
+ for (f = flags; *f; f++)
+ if (!isalpha((unsigned char)*f))
+ break;
+
+ if (*f)
+ return bmake_strdup(flags);
+
+ len = strlen(flags);
+ st = nf = bmake_malloc(len * 3 + 1);
+ while (*flags) {
+ *nf++ = '-';
+ *nf++ = *flags++;
+ *nf++ = ' ';
+ }
+ *nf = '\0';
+ return st;
+}
+
static void
parse_debug_options(const char *argvalue)
{
@@ -350,7 +385,7 @@ MainParseArgs(int argc, char **argv)
Boolean inOption, dashDash = FALSE;
char found_path[MAXPATHLEN + 1]; /* for searching for sys.mk */
-#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrst"
+#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrstw"
/* Can't actually use getopt(3) because rescanning is not portable */
getopt_def = OPTFLAGS;
@@ -558,6 +593,10 @@ rearg:
touchFlag = TRUE;
Var_Append(MAKEFLAGS, "-t", VAR_GLOBAL);
break;
+ case 'w':
+ enterFlag = TRUE;
+ Var_Append(MAKEFLAGS, "-w", VAR_GLOBAL);
+ break;
case '-':
dashDash = TRUE;
break;
@@ -796,7 +835,7 @@ main(int argc, char **argv)
Lst targs; /* target nodes to create -- passed to Make_Init */
Boolean outOfDate = FALSE; /* FALSE if all targets up to date */
struct stat sb, sa;
- char *p1, *path, *pwd;
+ char *p1, *path;
char mdpath[MAXPATHLEN];
#ifdef FORCE_MACHINE
const char *machine = FORCE_MACHINE;
@@ -963,26 +1002,30 @@ main(int argc, char **argv)
Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL, 0);
Var_Set("MFLAGS", "", VAR_GLOBAL, 0);
Var_Set(".ALLTARGETS", "", VAR_GLOBAL, 0);
+ /* some makefiles need to know this */
+ Var_Set(MAKE_LEVEL ".ENV", MAKE_LEVEL_ENV, VAR_CMD, 0);
/*
* Set some other useful macros
*/
{
- char tmp[64];
- const char *ep;
+ char tmp[64], *ep;
- if (!(ep = getenv(MAKE_LEVEL))) {
-#ifdef MAKE_LEVEL_SAFE
- if (!(ep = getenv(MAKE_LEVEL_SAFE)))
-#endif
- ep = "0";
- }
- Var_Set(MAKE_LEVEL, ep, VAR_GLOBAL, 0);
+ makelevel = ((ep = getenv(MAKE_LEVEL_ENV)) && *ep) ? atoi(ep) : 0;
+ if (makelevel < 0)
+ makelevel = 0;
+ snprintf(tmp, sizeof(tmp), "%d", makelevel);
+ Var_Set(MAKE_LEVEL, tmp, VAR_GLOBAL, 0);
snprintf(tmp, sizeof(tmp), "%u", myPid);
Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0);
snprintf(tmp, sizeof(tmp), "%u", getppid());
Var_Set(".MAKE.PPID", tmp, VAR_GLOBAL, 0);
}
+ if (makelevel > 0) {
+ char pn[1024];
+ snprintf(pn, sizeof(pn), "%s[%d]", progname, makelevel);
+ progname = bmake_strdup(pn);
+ }
Job_SetPrefix();
#ifdef USE_META
@@ -994,7 +1037,9 @@ main(int argc, char **argv)
* in a different format).
*/
#ifdef POSIX
- Main_ParseArgLine(getenv("MAKEFLAGS"));
+ p1 = explode(getenv("MAKEFLAGS"));
+ Main_ParseArgLine(p1);
+ free(p1);
#else
Main_ParseArgLine(getenv("MAKE"));
#endif
@@ -1011,6 +1056,9 @@ main(int argc, char **argv)
MainParseArgs(argc, argv);
+ if (enterFlag)
+ printf("%s: Entering directory `%s'\n", progname, curdir);
+
/*
* Verify that cwd is sane.
*/
@@ -1032,15 +1080,19 @@ main(int argc, char **argv)
* MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a transform.
*/
#ifndef NO_PWD_OVERRIDE
- if (!ignorePWD &&
- (pwd = getenv("PWD")) != NULL &&
- getenv("MAKEOBJDIRPREFIX") == NULL) {
- const char *makeobjdir = getenv("MAKEOBJDIR");
-
- if (makeobjdir == NULL || !strchr(makeobjdir, '$')) {
- if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino &&
- sa.st_dev == sb.st_dev)
- (void)strncpy(curdir, pwd, MAXPATHLEN);
+ if (!ignorePWD) {
+ char *pwd;
+
+ if ((pwd = getenv("PWD")) != NULL &&
+ getenv("MAKEOBJDIRPREFIX") == NULL) {
+ const char *makeobjdir = getenv("MAKEOBJDIR");
+
+ if (makeobjdir == NULL || !strchr(makeobjdir, '$')) {
+ if (stat(pwd, &sb) == 0 &&
+ sa.st_ino == sb.st_ino &&
+ sa.st_dev == sb.st_dev)
+ (void)strncpy(curdir, pwd, MAXPATHLEN);
+ }
}
}
#endif
@@ -1328,6 +1380,9 @@ main(int argc, char **argv)
Trace_Log(MAKEEND, 0);
+ if (enterFlag)
+ printf("%s: Leaving directory `%s'\n", progname, curdir);
+
Suff_End();
Targ_End();
Arch_End();
@@ -1756,8 +1811,12 @@ execError(const char *af, const char *av)
static void
usage(void)
{
+ char *p;
+ if ((p = strchr(progname, '[')) != NULL)
+ *p = '\0';
+
(void)fprintf(stderr,
-"usage: %s [-BeikNnqrstWX] \n\
+"usage: %s [-BeikNnqrstWwX] \n\
[-C directory] [-D variable] [-d flags] [-f makefile]\n\
[-I directory] [-J private] [-j max_jobs] [-m directory] [-T file]\n\
[-V variable] [variable=value] [target ...]\n", progname);