Module Name:    src
Committed By:   sjg
Date:           Wed Aug 26 23:17:11 UTC 2009

Modified Files:
        src/usr.bin/make: main.c make.1

Log Message:
Add -C directory, same as gmake and freebsd make.


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/usr.bin/make/main.c
cvs rdiff -u -r1.158 -r1.159 src/usr.bin/make/make.1

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/main.c
diff -u src/usr.bin/make/main.c:1.170 src/usr.bin/make/main.c:1.171
--- src/usr.bin/make/main.c:1.170	Tue Mar 24 13:53:21 2009
+++ src/usr.bin/make/main.c	Wed Aug 26 23:17:11 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.170 2009/03/24 13:53:21 perry Exp $	*/
+/*	$NetBSD: main.c,v 1.171 2009/08/26 23:17:11 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.170 2009/03/24 13:53:21 perry Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.171 2009/08/26 23:17:11 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.170 2009/03/24 13:53:21 perry Exp $");
+__RCSID("$NetBSD: main.c,v 1.171 2009/08/26 23:17:11 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -333,7 +333,7 @@
 	Boolean inOption, dashDash = FALSE;
 	char found_path[MAXPATHLEN + 1];	/* for searching for sys.mk */
 
-#define OPTFLAGS "BD:I:J:NST:V:WXd:ef:ij:km:nqrst"
+#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrst"
 /* Can't actually use getopt(3) because rescanning is not portable */
 
 	getopt_def = OPTFLAGS;
@@ -384,6 +384,15 @@
 			compatMake = TRUE;
 			Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL);
 			break;
+		case 'C':
+			if (chdir(argvalue) == -1) {
+				(void)fprintf(stderr,
+					      "%s: chdir %s: %s\n",
+					      progname, argvalue,
+					      strerror(errno));
+				exit(1);
+			}
+			break;
 		case 'D':
 			if (argvalue == NULL || argvalue[0] == 0) goto noarg;
 			Var_Set(argvalue, "1", VAR_GLOBAL, 0);
@@ -1773,7 +1782,8 @@
 usage(void)
 {
 	(void)fprintf(stderr,
-"usage: %s [-BeikNnqrstWX] [-D variable] [-d flags] [-f makefile]\n\
+"usage: %s [-BeikNnqrstWX] \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);
 	exit(2);

Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.158 src/usr.bin/make/make.1:1.159
--- src/usr.bin/make/make.1:1.158	Mon Jun  1 23:28:39 2009
+++ src/usr.bin/make/make.1	Wed Aug 26 23:17:11 2009
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.158 2009/06/01 23:28:39 sjg Exp $
+.\"	$NetBSD: make.1,v 1.159 2009/08/26 23:17:11 sjg Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -39,6 +39,9 @@
 .Nm
 .Op Fl BeikNnqrstWX
 .Bk -words
+.Op Fl C Ar directory
+.Ek
+.Bk -words
 .Op Fl D Ar variable
 .Ek
 .Bk -words
@@ -104,6 +107,16 @@
 .It Fl B
 Try to be backwards compatible by executing a single shell per command and
 by executing the commands to make the sources of a dependency line in sequence.
+.It Fl C Ar directory
+Change to
+.Ar directory
+before reading the makefiles or doing anything else.
+If multiple
+.Fl C
+options are specified, each is interpreted relative to the previous one:
+.Fl C Pa / Fl C Pa etc
+is equivalent to
+.Fl C Pa /etc .
 .It Fl D Ar variable
 Define
 .Ar variable

Reply via email to