summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/make/bin/globals.cc4
-rw-r--r--usr/src/cmd/make/bin/main.cc53
-rw-r--r--usr/src/cmd/make/bin/misc.cc14
-rw-r--r--usr/src/cmd/make/include/mk/defs.h4
-rw-r--r--usr/src/man/man1/make.121
5 files changed, 84 insertions, 12 deletions
diff --git a/usr/src/cmd/make/bin/globals.cc b/usr/src/cmd/make/bin/globals.cc
index b0c28c64bb..9b1045909e 100644
--- a/usr/src/cmd/make/bin/globals.cc
+++ b/usr/src/cmd/make/bin/globals.cc
@@ -21,6 +21,8 @@
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2019, Joyent, Inc.
*/
/*
@@ -174,6 +176,8 @@
wchar_t *wcs_ptr;
wchar_t *wcs_ptr2;
long int hostid;
+ Boolean path_reset = false;
+ Boolean rebuild_arg0 = false;
/*
* File table of contents
diff --git a/usr/src/cmd/make/bin/main.cc b/usr/src/cmd/make/bin/main.cc
index ed0afc0dbc..4e61262dfa 100644
--- a/usr/src/cmd/make/bin/main.cc
+++ b/usr/src/cmd/make/bin/main.cc
@@ -21,6 +21,8 @@
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2019, Joyent, Inc.
*/
/*
@@ -183,6 +185,7 @@ main(int argc, char *argv[])
register char *cp;
char make_state_dir[MAXPATHLEN];
Boolean parallel_flag = false;
+ Boolean argv_zero_relative = false;
char *prognameptr;
char *slash_ptr;
mode_t um;
@@ -248,6 +251,7 @@ main(int argc, char *argv[])
argv[0]);
argv_zero_string = strdup(tmp_string);
retmem_mb(tmp_string);
+ argv_zero_relative = true;
}
/*
@@ -342,8 +346,6 @@ main(int argc, char *argv[])
setup_char_semantics();
- setup_for_projectdir();
-
/*
* If running with .KEEP_STATE, curdir will be set with
* the connected directory.
@@ -363,6 +365,28 @@ main(int argc, char *argv[])
(void) printf(gettext("MAKEFLAGS value: %s\n"), cp == NULL ? "" : cp);
}
+ /*
+ * Reset argv_zero_string if it was built from a relative path and the
+ * -C option was specified.
+ */
+ if (argv_zero_relative && rebuild_arg0) {
+ char *tmp_current_path;
+ char *tmp_string;
+
+ free(argv_zero_string);
+ tmp_current_path = get_current_path();
+ tmp_string = getmem(strlen(tmp_current_path) + 1 +
+ strlen(argv[0]) + 1);
+ (void) sprintf(tmp_string,
+ "%s/%s",
+ tmp_current_path,
+ argv[0]);
+ argv_zero_string = strdup(tmp_string);
+ retmem_mb(tmp_string);
+ }
+
+ setup_for_projectdir();
+
setup_interrupt(handle_interrupt);
read_files_and_state(argc, argv);
@@ -905,9 +929,9 @@ read_command_options(register int argc, register char **argv)
extern char *optarg;
extern int optind, opterr, optopt;
-#define SUNPRO_CMD_OPTS "-~Bbc:Ddef:g:ij:K:kM:m:NnO:o:PpqRrSsTtuVvwx:"
+#define SUNPRO_CMD_OPTS "-~Bbc:C:Ddef:g:ij:K:kM:m:NnO:o:PpqRrSsTtuVvwx:"
-# define SVR4_CMD_OPTS "-c:ef:g:ij:km:nO:o:pqrsTtVv"
+# define SVR4_CMD_OPTS "-c:C:ef:g:ij:km:nO:o:pqrsTtVv"
/*
* Added V in SVR4_CMD_OPTS also, which is going to be a hidden
@@ -985,7 +1009,7 @@ read_command_options(register int argc, register char **argv)
if (ch == '?') {
if (svr4) {
fprintf(stderr,
- gettext("Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
+ gettext("Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ][-C directory]\n"));
fprintf(stderr,
gettext(" [ -j dmake_max_jobs ][ -m dmake_mode ][ -o dmake_odir ]...\n"));
fprintf(stderr,
@@ -993,7 +1017,7 @@ read_command_options(register int argc, register char **argv)
tptr = strchr(SVR4_CMD_OPTS, optopt);
} else {
fprintf(stderr,
- gettext("Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
+ gettext("Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ][-C directory]\n"));
fprintf(stderr,
gettext(" [ -j dmake_max_jobs ][ -K statefile ][ -m dmake_mode ][ -x MODE_NAME=VALUE ][ -o dmake_odir ]...\n"));
fprintf(stderr,
@@ -1061,6 +1085,9 @@ read_command_options(register int argc, register char **argv)
case 1024: /* -x seen */
argv[i] = (char *)"-x";
break;
+ case 2048:
+ argv[i] = (char *)"-C";
+ break;
default: /* > 1 of -c, f, g, j, K, M, m, O, o, x seen */
fatal(gettext("Illegal command line. More than one option requiring\nan argument given in the same argument group"));
}
@@ -1314,6 +1341,8 @@ parse_command_option(register char ch)
dmake_rcfile_specified = true;
}
return 2;
+ case 'C': /* Change directory */
+ return 2048;
case 'D': /* Show lines read */
if (invert_this) {
read_trace_level--;
@@ -2508,6 +2537,18 @@ enter_argv_values(int argc, char *argv[], ASCII_Dyn_Array *makeflags_and_macro)
continue;
}
break;
+ case 2048: /* -C seen */
+ if (argv[i + 1] == NULL) {
+ fatal(gettext("No argument after -C flag"));
+ }
+ if (chdir(argv[i + 1]) != 0) {
+ fatal(gettext("failed to change to directory %s: %s"),
+ argv[i + 1], strerror(errno));
+ }
+ path_reset = true;
+ rebuild_arg0 = true;
+ (void) get_current_path();
+ break;
default: /* Shouldn't reach here */
argv[i] = NULL;
continue;
diff --git a/usr/src/cmd/make/bin/misc.cc b/usr/src/cmd/make/bin/misc.cc
index 25bad0ae3a..97e7ce1e0b 100644
--- a/usr/src/cmd/make/bin/misc.cc
+++ b/usr/src/cmd/make/bin/misc.cc
@@ -21,6 +21,8 @@
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2019, Joyent, Inc.
*/
/*
@@ -250,15 +252,23 @@ char *
get_current_path(void)
{
char pwd[(MAXPATHLEN * MB_LEN_MAX)];
- static char *current_path;
+ static char *current_path = NULL;
- if (current_path == NULL) {
+ /*
+ * When we hit this with path_reset to true, we do not free the older
+ * version of current_path at this time, as we don't have confidence
+ * that we've properly caught all users of it and they haven't cached
+ * the pointer somewhere. As such, since this is only currently set with
+ * the -C option is passed in, it seems OK to just let that bit go.
+ */
+ if (current_path == NULL || path_reset == true) {
getcwd(pwd, sizeof(pwd));
if (pwd[0] == (int) nul_char) {
pwd[0] = (int) slash_char;
pwd[1] = (int) nul_char;
}
current_path = strdup(pwd);
+ path_reset = false;
}
return current_path;
}
diff --git a/usr/src/cmd/make/include/mk/defs.h b/usr/src/cmd/make/include/mk/defs.h
index 8af6b0f5a3..fb8745db8e 100644
--- a/usr/src/cmd/make/include/mk/defs.h
+++ b/usr/src/cmd/make/include/mk/defs.h
@@ -21,6 +21,8 @@
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2019, Joyent, Inc.
*/
#ifndef _MK_DEFS_H
@@ -293,6 +295,8 @@ extern wchar_t wcs_buffer2[];
extern wchar_t *wcs_ptr;
extern wchar_t *wcs_ptr2;
extern long int hostid;
+extern Boolean path_reset;
+extern Boolean rebuild_arg0;
/*
* Declarations of system defined variables
diff --git a/usr/src/man/man1/make.1 b/usr/src/man/man1/make.1
index 6e0d52369b..532c3368c1 100644
--- a/usr/src/man/man1/make.1
+++ b/usr/src/man/man1/make.1
@@ -43,14 +43,15 @@
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
.\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
+.\" Copyright 2019, Joyent, Inc.
.\"
-.TH MAKE 1 "Jun 24, 2015"
+.TH MAKE 1 "March 8, 2019"
.SH NAME
make \- maintain, update, and regenerate related programs and files
.SH SYNOPSIS
.LP
.nf
-\fB/usr/bin/make\fR [\fB-d\fR] [\fB-dd\fR] [\fB-D\fR] [\fB-DD\fR] [\fB-e\fR]
+\fB/usr/bin/make\fR [\fB-C\fR \fIdirectory\fR] [\fB-d\fR] [\fB-dd\fR] [\fB-D\fR] [\fB-DD\fR] [\fB-e\fR]
[\fB-i\fR] [\fB-j\fR \fImaxjobs\fR] [\fB-k\fR] [\fB-m\fR \fI{serial | parallel}\fR]
[\fB-n\fR] [\fB-p\fR] [\fB-P\fR] [\fB-q\fR] [\fB-r\fR] [\fB-s\fR] [\fB-S\fR] [\fB-t\fR] [\fB-V\fR]
[\fB-f\fR \fImakefile\fR]... [\fB-K\fR \fIstatefile\fR]... [\fItarget\fR]...
@@ -58,7 +59,7 @@ make \- maintain, update, and regenerate related programs and files
.fi
.nf
-\fB/usr/bin/dmake\fR [\fB-d\fR] [\fB-dd\fR] [\fB-D\fR] [\fB-DD\fR] [\fB-e\fR]
+\fB/usr/bin/dmake\fR [\fB-C\fR \fIdirectory\fR] [\fB-d\fR] [\fB-dd\fR] [\fB-D\fR] [\fB-DD\fR] [\fB-e\fR]
[\fB-i\fR] [\fB-j\fR \fImaxjobs\fR] [\fB-k\fR] [\fB-m\fR \fI{serial | parallel}\fR]
[\fB-n\fR] [\fB-p\fR] [\fB-P\fR] [\fB-q\fR] [\fB-r\fR] [\fB-s\fR] [\fB-S\fR] [\fB-t\fR] [\fB-V\fR]
[\fB-f\fR \fImakefile\fR]... [\fB-K\fR \fIstatefile\fR]... [\fItarget\fR]...
@@ -151,6 +152,18 @@ The following options are supported:
.sp
.ne 2
.na
+\fB\fB-C\fR \fIdirectory\fR\fR
+.ad
+.RS 16n
+Changes the current working directory to the directory \fIdirectory\fR before
+attempting to open and process the Makefile or run any targets. This option may
+be specified more than once, each subsequent occurrence of the option is
+dependent on those that came before it.
+.RE
+
+.sp
+.ne 2
+.na
\fB\fB-d\fR\fR
.ad
.RS 16n
@@ -430,7 +443,7 @@ The usage of \fBmake\fR is described below:
.SS "Reading Makefiles and the Environment"
.LP
When \fBmake\fR first starts, it reads the \fBMAKEFLAGS\fR environment variable
-to obtain any of the following options specified present in its value:
+to obtain any of the following options specified present in its value: \fB-C\fR,
\fB-d\fR, \fB-D\fR, \fB-e\fR, \fB-i\fR, \fB-k\fR, \fB-n\fR, \fB-p\fR, \fB-q\fR,
\fB-r\fR, \fB-s\fR, \fB-S\fR, or \fB-t\fR. Due to the implementation of POSIX.2
(see \fBPOSIX.2\fR(5), the \fBMAKEFLAGS\fR values contains a leading \fB\(mi\fR