dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / make / lib / mksh / mksh.cc
blob9c0ec1397994d056dd74ab0fe082290cf860bd3d
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 * mksh.cc
30 * Execute the command(s) of one Make or DMake rule
34 * Included files
36 #include <mksh/dosys.h> /* redirect_io() */
37 #include <mksh/misc.h> /* retmem() */
38 #include <mksh/mksh.h>
39 #include <errno.h>
40 #include <signal.h>
44 * Workaround for NFS bug. Sometimes, when running 'chdir' on a remote
45 * dmake server, it fails with "Stale NFS file handle" error.
46 * The second attempt seems to work.
48 int
49 my_chdir(char * dir) {
50 int res = chdir(dir);
51 if (res != 0 && (errno == ESTALE || errno == EAGAIN)) {
52 /* Stale NFS file handle. Try again */
53 res = chdir(dir);
55 return res;
60 * File table of contents
62 static void change_sunpro_dependencies_value(char *oldpath, char *newpath);
63 static void init_mksh_globals(char *shell);
64 static void set_env_vars(char *env_list[]);
67 static void
68 set_env_vars(char *env_list[])
70 char **env_list_p;
72 for (env_list_p = env_list;
73 *env_list_p != (char *) NULL;
74 env_list_p++) {
75 putenv(*env_list_p);
79 static void
80 init_mksh_globals(char *shell)
83 MBSTOWCS(wcs_buffer, "SHELL");
84 shell_name = GETNAME(wcs_buffer, FIND_LENGTH);
85 MBSTOWCS(wcs_buffer, shell);
86 (void) SETVAR(shell_name, GETNAME(wcs_buffer, FIND_LENGTH), false);
88 char * dmake_shell;
89 if ((dmake_shell = getenv("DMAKE_SHELL")) == NULL) {
90 dmake_shell = shell;
92 MBSTOWCS(wcs_buffer, dmake_shell);
93 shell_name = GETNAME(wcs_buffer, FIND_LENGTH);
97 * Change the pathname in the value of the SUNPRO_DEPENDENCIES env variable
98 * from oldpath to newpath.
100 static void
101 change_sunpro_dependencies_value(char *oldpath, char *newpath)
103 char buf[MAXPATHLEN];
104 static char *env;
105 int length;
106 int oldpathlen;
107 char *sp_dep_value;
109 /* check if SUNPRO_DEPENDENCIES is set in the environment */
110 if ((sp_dep_value = getenv("SUNPRO_DEPENDENCIES")) != NULL) {
111 oldpathlen = strlen(oldpath);
112 /* check if oldpath is indeed in the value of SUNPRO_DEPENDENCIES */
113 if (strncmp(oldpath, sp_dep_value, oldpathlen) == 0) {
114 (void) sprintf(buf,
115 "%s%s",
116 newpath,
117 sp_dep_value + oldpathlen);
118 length = 2 +
119 strlen("SUNPRO_DEPENDENCIES") +
120 strlen(buf);
121 env = getmem(length);
122 (void) sprintf(env,
123 "%s=%s",
124 "SUNPRO_DEPENDENCIES",
125 buf);
126 (void) putenv(env);