summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2000-07-18 20:17:21 +0000
committerMarc Espie <espie@cvs.openbsd.org>2000-07-18 20:17:21 +0000
commit5e93edace0c28c6895e3cd95e34e9141fa3de5c1 (patch)
tree30365324027966d9225042882ce338073612767b
parent065ca2170e4b2938226fed71fb44859bcaca2181 (diff)
Handle MAKEFLAGS variation mandated by POSIX.
Code to pass variable definitions to submakes through make flags. Not activated yet, need to fix src/ first.
-rw-r--r--usr.bin/make/extern.h3
-rw-r--r--usr.bin/make/main.c126
-rw-r--r--usr.bin/make/var.c39
3 files changed, 116 insertions, 52 deletions
diff --git a/usr.bin/make/extern.h b/usr.bin/make/extern.h
index edf99b8eed3..cb5dcbe0dbd 100644
--- a/usr.bin/make/extern.h
+++ b/usr.bin/make/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.28 2000/07/17 22:57:37 espie Exp $ */
+/* $OpenBSD: extern.h,v 1.29 2000/07/18 20:17:19 espie Exp $ */
/* $NetBSD: nonints.h,v 1.12 1996/11/06 17:59:19 christos Exp $ */
/*-
@@ -161,3 +161,4 @@ void Var_End __P((void));
void Var_Dump __P((GSymT *));
void SymTable_Init __P((SymTable *));
void SymTable_Destroy __P((SymTable *));
+extern void Var_AddCmdline __P((const char *));
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index f4b6c2dd024..d089cb3bf4a 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.38 2000/07/01 00:21:22 espie Exp $ */
+/* $OpenBSD: main.c,v 1.39 2000/07/18 20:17:20 espie Exp $ */
/* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */
/*
@@ -49,7 +49,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.38 2000/07/01 00:21:22 espie Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.39 2000/07/18 20:17:20 espie Exp $";
#endif
#endif /* not lint */
@@ -140,11 +140,67 @@ static void MainParseArgs __P((int, char **));
char * chdir_verify_path __P((char *, char *));
static int ReadMakefile __P((void *, void *));
static void usage __P((void));
+static void posixParseOptLetter __P((char));
int main __P((int, char **));
static char *curdir; /* startup directory */
static char *objdir; /* where we chdir'ed to */
+static void
+posixParseOptLetter(c)
+ char c;
+{
+ switch(c) {
+ case 'B':
+ compatMake = TRUE;
+ break;
+ case 'P':
+ usePipes = FALSE;
+ Var_Append(MAKEFLAGS, "-P", VAR_GLOBAL);
+ break;
+ case 'S':
+ keepgoing = FALSE;
+ Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL);
+ break;
+ case 'e':
+ checkEnvFirst = TRUE;
+ Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL);
+ break;
+ case 'i':
+ ignoreErrors = TRUE;
+ Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL);
+ break;
+ case 'k':
+ keepgoing = TRUE;
+ Var_Append(MAKEFLAGS, "-k", VAR_GLOBAL);
+ break;
+ case 'n':
+ noExecute = TRUE;
+ Var_Append(MAKEFLAGS, "-n", VAR_GLOBAL);
+ break;
+ case 'q':
+ queryFlag = TRUE;
+ /* Kind of nonsensical, wot? */
+ Var_Append(MAKEFLAGS, "-q", VAR_GLOBAL);
+ break;
+ case 'r':
+ noBuiltins = TRUE;
+ Var_Append(MAKEFLAGS, "-r", VAR_GLOBAL);
+ break;
+ case 's':
+ beSilent = TRUE;
+ Var_Append(MAKEFLAGS, "-s", VAR_GLOBAL);
+ break;
+ case 't':
+ touchFlag = TRUE;
+ Var_Append(MAKEFLAGS, "-t", VAR_GLOBAL);
+ break;
+ default:
+ case '?':
+ usage();
+ }
+}
+
/*-
* MainParseArgs --
* Parse a given argument vector. Called from main() and from
@@ -175,6 +231,7 @@ MainParseArgs(argc, argv)
#else
# define OPTFLAGS "BD:I:PSV:d:ef:ij:km:nqrst"
#endif
+# define OPTLETTERS "BPSiknqrst"
rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
switch(c) {
case 'D':
@@ -193,9 +250,6 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
break;
- case 'B':
- compatMake = TRUE;
- break;
#ifdef REMOTE
case 'L': {
char *endptr;
@@ -212,14 +266,6 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
break;
}
#endif
- case 'P':
- usePipes = FALSE;
- Var_Append(MAKEFLAGS, "-P", VAR_GLOBAL);
- break;
- case 'S':
- keepgoing = FALSE;
- Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL);
- break;
case 'd': {
char *modules = optarg;
@@ -275,17 +321,9 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
break;
}
- case 'e':
- checkEnvFirst = TRUE;
- Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL);
- break;
case 'f':
Lst_AtEnd(&makefiles, optarg);
break;
- case 'i':
- ignoreErrors = TRUE;
- Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL);
- break;
case 'j': {
char *endptr;
@@ -305,39 +343,13 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
break;
}
- case 'k':
- keepgoing = TRUE;
- Var_Append(MAKEFLAGS, "-k", VAR_GLOBAL);
- break;
case 'm':
Dir_AddDir(&sysIncPath, optarg);
Var_Append(MAKEFLAGS, "-m", VAR_GLOBAL);
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
break;
- case 'n':
- noExecute = TRUE;
- Var_Append(MAKEFLAGS, "-n", VAR_GLOBAL);
- break;
- case 'q':
- queryFlag = TRUE;
- /* Kind of nonsensical, wot? */
- Var_Append(MAKEFLAGS, "-q", VAR_GLOBAL);
- break;
- case 'r':
- noBuiltins = TRUE;
- Var_Append(MAKEFLAGS, "-r", VAR_GLOBAL);
- break;
- case 's':
- beSilent = TRUE;
- Var_Append(MAKEFLAGS, "-s", VAR_GLOBAL);
- break;
- case 't':
- touchFlag = TRUE;
- Var_Append(MAKEFLAGS, "-t", VAR_GLOBAL);
- break;
default:
- case '?':
- usage();
+ posixParseOptLetter(c);
}
}
@@ -398,7 +410,8 @@ Main_ParseArgLine(line)
int argc; /* Number of arguments in argv */
char *args; /* Space used by the args */
char *buf;
- char *argv0 = Var_Value(".MAKE", VAR_GLOBAL);
+ char *argv0;
+ char *s;
if (line == NULL)
return;
@@ -407,6 +420,18 @@ Main_ParseArgLine(line)
if (!*line)
return;
+ /* POSIX rule: MAKEFLAGS can hold a set of option letters without
+ * any blanks or dashes. */
+ for (s = line;; s++) {
+ if (*s == '\0') {
+ while (line != s)
+ posixParseOptLetter(*line++);
+ return;
+ }
+ if (strchr(OPTLETTERS, *s) == NULL)
+ break;
+ }
+ argv0 = Var_Value(".MAKE", VAR_GLOBAL);
buf = emalloc(strlen(line) + strlen(argv0) + 2);
(void)sprintf(buf, "%s %s", argv0, line);
@@ -654,6 +679,9 @@ main(argc, argv)
MainParseArgs(argc, argv);
+#ifdef NotYet
+ Var_AddCmdline(MAKEFLAGS);
+#endif
/*
* Initialize archive, target and suffix modules in preparation for
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index 04fcc7d29b0..8a36521d5a1 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: var.c,v 1.45 2000/07/17 23:29:35 espie Exp $ */
+/* $OpenBSD: var.c,v 1.46 2000/07/18 20:17:20 espie Exp $ */
/* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */
/*
@@ -70,7 +70,7 @@
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: var.c,v 1.45 2000/07/17 23:29:35 espie Exp $";
+static char rcsid[] = "$OpenBSD: var.c,v 1.46 2000/07/18 20:17:20 espie Exp $";
#endif
#endif /* not lint */
@@ -1186,3 +1186,38 @@ Var_Dump(ctxt)
VarPrintVar(v);
}
+
+#ifdef POSIX
+
+static const char *quotable = " \t\n\\'\"";
+
+/* In POSIX mode, variable assignments passed on the command line are
+ * propagated to sub makes through MAKEFLAGS.
+ */
+void
+Var_AddCmdline(name)
+ const char *name;
+{
+ Var *v;
+ unsigned int i;
+ BUFFER buf;
+ char *s;
+
+ Buf_Init(&buf, MAKE_BSIZE);
+
+ for (v = hash_first(VAR_CMD, &i); v != NULL;
+ v = hash_next(VAR_CMD, &i)) {
+ /* We assume variable names don't need quoting */
+ Buf_AddString(&buf, v->name);
+ Buf_AddChar(&buf, '=');
+ for (s = VarValue(v); *s != '\0'; s++) {
+ if (strchr(quotable, *s))
+ Buf_AddChar(&buf, '\\');
+ Buf_AddChar(&buf, *s);
+ }
+ Buf_AddSpace(&buf);
+ }
+ Var_Append(name, Buf_Retrieve(&buf), VAR_GLOBAL);
+ Buf_Destroy(&buf);
+}
+#endif