dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / make / bin / macro.cc
bloba33484a9795f7187d3259fd727e038b0638be181
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.
27 * macro.cc
29 * Handle expansion of make macros
33 * Included files
35 #include <mk/defs.h>
36 #include <mksh/macro.h> /* getvar(), expand_value() */
37 #include <mksh/misc.h> /* getmem() */
40 * Defined macros
44 * typedefs & structs
48 * Static variables
52 * File table of contents
55 void
56 setvar_append(register Name name, register Name value)
58 register Property macro_apx = get_prop(name->prop, macro_append_prop);
59 register Property macro = get_prop(name->prop, macro_prop);
60 int length;
61 String_rec destination;
62 wchar_t buffer[STRING_BUFFER_LENGTH];
63 register Chain chain;
64 Name val = NULL;
66 if(macro_apx == NULL) {
67 macro_apx = append_prop(name, macro_append_prop);
68 if(macro != NULL) {
69 macro_apx->body.macro_appendix.value = macro->body.macro.value;
73 val = macro_apx->body.macro_appendix.value_to_append;
75 INIT_STRING_FROM_STACK(destination, buffer);
76 buffer[0] = 0;
77 if (val != NULL) {
78 APPEND_NAME(val,
79 &destination,
80 (int) val->hash.length);
81 if (value != NULL) {
82 MBTOWC(wcs_buffer, " ");
83 append_char(wcs_buffer[0], &destination);
86 if (value != NULL) {
87 APPEND_NAME(value,
88 &destination,
89 (int) value->hash.length);
91 value = GETNAME(destination.buffer.start, FIND_LENGTH);
92 if (destination.free_after_use) {
93 retmem(destination.buffer.start);
95 macro_apx->body.macro_appendix.value_to_append = value;
97 SETVAR(name, empty_name, true);
101 * setvar_envvar()
103 * This function scans the list of environment variables that have
104 * dynamic values and sets them.
106 * Parameters:
108 * Global variables used:
109 * envvar A list of environment vars with $ in value
111 void
112 setvar_envvar(void)
114 wchar_t buffer[STRING_BUFFER_LENGTH];
115 int length;
116 register char *mbs, *tmp_mbs_buffer = NULL;
117 register char *env, *tmp_mbs_buffer2 = NULL;
118 Envvar p;
119 String_rec value;
121 for (p = envvar; p != NULL; p = p->next) {
122 if (p->already_put
124 continue;
126 INIT_STRING_FROM_STACK(value, buffer);
127 expand_value(p->value, &value, false);
128 if ((length = wcslen(value.buffer.start)) >= MAXPATHLEN) {
129 mbs = tmp_mbs_buffer = getmem((length + 1) * MB_LEN_MAX);
130 (void) wcstombs(mbs,
131 value.buffer.start,
132 (length + 1) * MB_LEN_MAX);
133 } else {
134 mbs = mbs_buffer;
135 WCSTOMBS(mbs, value.buffer.start);
137 length = 2 + strlen(p->name->string_mb) + strlen(mbs);
138 if (!p->already_put || length > (MAXPATHLEN * MB_LEN_MAX)) {
139 env = tmp_mbs_buffer2 = getmem(length);
140 } else {
141 env = mbs_buffer2;
143 (void) sprintf(env,
144 "%s=%s",
145 p->name->string_mb,
146 mbs);
147 if (!p->already_put) {
148 (void) putenv(env);
149 p->already_put = true;
150 if (p->env_string) {
151 retmem_mb(p->env_string);
153 p->env_string = env;
154 tmp_mbs_buffer2 = NULL; // We should not return this memory now
156 if (tmp_mbs_buffer2) {
157 retmem_mb(tmp_mbs_buffer2);
158 tmp_mbs_buffer2 = NULL;
160 if (tmp_mbs_buffer) {
161 retmem_mb(tmp_mbs_buffer);
162 tmp_mbs_buffer = NULL;