make: unifdef for MAKETOOL and DISTRIBUTED (undefined)
1 /*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26
27 /*
28 * mksh.cc
29 *
30 * Execute the command(s) of one Make or DMake rule
31 */
32
33 /*
34 * Included files
35 */
36 #include <mksh/dosys.h> /* redirect_io() */
37 #include <mksh/misc.h> /* retmem() */
38 #include <mksh/mksh.h>
39 #include <mksdmsi18n/mksdmsi18n.h>
40 #include <errno.h>
41 #include <signal.h>
42
43
44 /*
45 * Workaround for NFS bug. Sometimes, when running 'chdir' on a remote
46 * dmake server, it fails with "Stale NFS file handle" error.
47 * The second attempt seems to work.
48 */
49 int
50 my_chdir(char * dir) {
51 int res = chdir(dir);
52 if (res != 0 && (errno == ESTALE || errno == EAGAIN)) {
53 /* Stale NFS file handle. Try again */
54 res = chdir(dir);
55 }
56 return res;
57 }
58
59
60 /*
61 * File table of contents
62 */
63 static void change_sunpro_dependencies_value(char *oldpath, char *newpath);
64 static void init_mksh_globals(char *shell);
65 static void set_env_vars(char *env_list[]);
66
67
68 static void
69 set_env_vars(char *env_list[])
70 {
71 char **env_list_p;
72
73 for (env_list_p = env_list;
74 *env_list_p != (char *) NULL;
75 env_list_p++) {
76 putenv(*env_list_p);
77 }
78 }
79
80 static void
81 init_mksh_globals(char *shell)
82 {
83 /*
84 MBSTOWCS(wcs_buffer, NOCATGETS("SHELL"));
85 shell_name = GETNAME(wcs_buffer, FIND_LENGTH);
86 MBSTOWCS(wcs_buffer, shell);
87 (void) SETVAR(shell_name, GETNAME(wcs_buffer, FIND_LENGTH), false);
88 */
89 char * dmake_shell;
90 if ((dmake_shell = getenv(NOCATGETS("DMAKE_SHELL"))) == NULL) {
91 dmake_shell = shell;
92 }
93 MBSTOWCS(wcs_buffer, dmake_shell);
94 shell_name = GETNAME(wcs_buffer, FIND_LENGTH);
95 }
96
97 /*
98 * Change the pathname in the value of the SUNPRO_DEPENDENCIES env variable
99 * from oldpath to newpath.
100 */
101 static void
102 change_sunpro_dependencies_value(char *oldpath, char *newpath)
103 {
104 char buf[MAXPATHLEN];
105 static char *env;
106 int length;
107 int oldpathlen;
108 char *sp_dep_value;
109
110 /* check if SUNPRO_DEPENDENCIES is set in the environment */
111 if ((sp_dep_value = getenv(NOCATGETS("SUNPRO_DEPENDENCIES"))) != NULL) {
112 oldpathlen = strlen(oldpath);
113 /* check if oldpath is indeed in the value of SUNPRO_DEPENDENCIES */
114 if (strncmp(oldpath, sp_dep_value, oldpathlen) == 0) {
115 (void) sprintf(buf,
116 "%s%s",
117 newpath,
118 sp_dep_value + oldpathlen);
119 length = 2 +
120 strlen(NOCATGETS("SUNPRO_DEPENDENCIES")) +
121 strlen(buf);
122 env = getmem(length);
123 (void) sprintf(env,
124 "%s=%s",
125 NOCATGETS("SUNPRO_DEPENDENCIES"),
126 buf);
127 (void) putenv(env);
128 }
129 }
130 }
131
132
--- EOF ---