Print this page
make: unifdef for other OSes (undefined)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/bin/pmake.cc
+++ new/usr/src/cmd/make/bin/pmake.cc
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #ifdef TEAMWARE_MAKE_CMN
27 27
28 28 /*
29 29 * Included files
30 30 */
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
31 31 #include <arpa/inet.h>
32 32 #include <mk/defs.h>
33 33 #include <mksh/misc.h>
34 34 #include <netdb.h>
35 35 #include <netinet/in.h>
36 36 #include <sys/socket.h>
37 37 #include <sys/stat.h>
38 38 #include <sys/types.h>
39 39 #include <sys/utsname.h>
40 40 #include <rpc/rpc.h> /* host2netname(), netname2host() */
41 -#ifdef linux
42 -# include <unistd.h> /* getdomainname() */
43 -#endif
44 41
45 42 /*
46 43 * Defined macros
47 44 */
48 45
49 46 /*
50 47 * typedefs & structs
51 48 */
52 49
53 50 /*
54 51 * Static variables
55 52 */
56 53
57 54 /*
58 55 * File table of contents
59 56 */
60 57 static int get_max(wchar_t **ms_address, wchar_t *hostname);
61 58 static Boolean pskip_comment(wchar_t **cp_address);
62 59 static void pskip_till_next_word(wchar_t **cp);
63 60 static Boolean pskip_white_space(wchar_t **cp_address);
64 61
65 62
66 63 /*
67 64 * read_make_machines(Name make_machines_name)
68 65 *
69 66 * For backwards compatibility w/ PMake 1.x, when DMake 2.x is
70 67 * being run in parallel mode, DMake should parse the PMake startup
71 68 * file $(HOME)/.make.machines to get the PMake max jobs.
72 69 *
73 70 * Return value:
74 71 * int of PMake max jobs
75 72 *
76 73 * Parameters:
77 74 * make_machines_name Name of .make.machines file
78 75 *
79 76 */
80 77 int
81 78 read_make_machines(Name make_machines_name)
82 79 {
83 80 wchar_t c;
84 81 Boolean default_make_machines;
85 82 struct hostent *hp;
86 83 wchar_t local_host[MAX_HOSTNAMELEN + 1];
87 84 char local_host_mb[MAX_HOSTNAMELEN + 1] = "";
88 85 int local_host_wslen;
89 86 wchar_t full_host[MAXNETNAMELEN + 1];
90 87 int full_host_wslen = 0;
91 88 char *homedir;
92 89 Name MAKE_MACHINES;
93 90 struct stat make_machines_buf;
94 91 FILE *make_machines_file;
95 92 wchar_t *make_machines_list = NULL;
96 93 char *make_machines_list_mb = NULL;
97 94 wchar_t make_machines_path[MAXPATHLEN];
98 95 char mb_make_machines_path[MAXPATHLEN];
99 96 wchar_t *mp;
100 97 wchar_t *ms;
101 98 int pmake_max_jobs = 0;
102 99 struct utsname uts_info;
103 100
104 101
105 102 MBSTOWCS(wcs_buffer, NOCATGETS("MAKE_MACHINES"));
106 103 MAKE_MACHINES = GETNAME(wcs_buffer, FIND_LENGTH);
107 104 /* Did the user specify a .make.machines file on the command line? */
108 105 default_make_machines = false;
109 106 if (make_machines_name == NULL) {
110 107 /* Try reading the default .make.machines file, in $(HOME). */
111 108 homedir = getenv(NOCATGETS("HOME"));
112 109 if ((homedir != NULL) && (strlen(homedir) < (sizeof(mb_make_machines_path) - 16))) {
113 110 sprintf(mb_make_machines_path,
114 111 NOCATGETS("%s/.make.machines"), homedir);
115 112 MBSTOWCS(make_machines_path, mb_make_machines_path);
116 113 make_machines_name = GETNAME(make_machines_path, FIND_LENGTH);
117 114 default_make_machines = true;
118 115 }
119 116 if (make_machines_name == NULL) {
120 117 /*
121 118 * No $(HOME)/.make.machines file.
122 119 * Return 0 for PMake max jobs.
123 120 */
124 121 return(0);
125 122 }
126 123 }
127 124 /*
128 125 make_machines_list_mb = getenv(MAKE_MACHINES->string_mb);
129 126 */
130 127 /* Open the .make.machines file. */
131 128 if ((make_machines_file = fopen(make_machines_name->string_mb, "r")) == NULL) {
132 129 if (!default_make_machines) {
133 130 /* Error opening .make.machines file. */
134 131 fatal(catgets(catd, 1, 314, "Open of %s failed: %s"),
135 132 make_machines_name->string_mb,
136 133 errmsg(errno));
137 134 } else {
138 135 /*
139 136 * No $(HOME)/.make.machines file.
140 137 * Return 0 for PMake max jobs.
141 138 */
142 139 return(0);
143 140 }
144 141 /* Stat the .make.machines file to get the size of the file. */
145 142 } else if (fstat(fileno(make_machines_file), &make_machines_buf) < 0) {
146 143 /* Error stat'ing .make.machines file. */
147 144 fatal(catgets(catd, 1, 315, "Stat of %s failed: %s"),
148 145 make_machines_name->string_mb,
149 146 errmsg(errno));
150 147 } else {
151 148 /* Allocate memory for "MAKE_MACHINES=<contents of .m.m>" */
152 149 make_machines_list_mb =
153 150 (char *) getmem((int) (strlen(MAKE_MACHINES->string_mb) +
154 151 2 +
155 152 make_machines_buf.st_size));
156 153 sprintf(make_machines_list_mb,
157 154 "%s=",
158 155 MAKE_MACHINES->string_mb);
159 156 /* Read in the .make.machines file. */
160 157 if (fread(make_machines_list_mb + strlen(MAKE_MACHINES->string_mb) + 1,
161 158 sizeof(char),
162 159 (int) make_machines_buf.st_size,
163 160 make_machines_file) != make_machines_buf.st_size) {
164 161 /*
165 162 * Error reading .make.machines file.
166 163 * Return 0 for PMake max jobs.
167 164 */
168 165 warning(catgets(catd, 1, 316, "Unable to read %s"),
169 166 make_machines_name->string_mb);
170 167 (void) fclose(make_machines_file);
171 168 retmem_mb((caddr_t) make_machines_list_mb);
172 169 return(0);
173 170 } else {
174 171 (void) fclose(make_machines_file);
175 172 /* putenv "MAKE_MACHINES=<contents of .m.m>" */
176 173 *(make_machines_list_mb +
177 174 strlen(MAKE_MACHINES->string_mb) +
178 175 1 +
179 176 make_machines_buf.st_size) = (int) nul_char;
180 177 if (putenv(make_machines_list_mb) != 0) {
181 178 warning(catgets(catd, 1, 317, "Couldn't put contents of %s in environment"),
182 179 make_machines_name->string_mb);
183 180 } else {
184 181 make_machines_list_mb += strlen(MAKE_MACHINES->string_mb) + 1;
185 182 make_machines_list = ALLOC_WC(strlen(make_machines_list_mb) + 1);
186 183 (void) mbstowcs(make_machines_list,
187 184 make_machines_list_mb,
188 185 (strlen(make_machines_list_mb) + 1));
189 186 }
190 187 }
↓ open down ↓ |
137 lines elided |
↑ open up ↑ |
191 188 }
192 189
193 190 uname(&uts_info);
194 191 strcpy(local_host_mb, &uts_info.nodename[0]);
195 192 MBSTOWCS(local_host, local_host_mb);
196 193 local_host_wslen = wslen(local_host);
197 194
198 195 // There is no getdomainname() function on Solaris.
199 196 // And netname2host() function does not work on Linux.
200 197 // So we have to use different APIs.
201 -#ifdef linux
202 - if (getdomainname(mbs_buffer, MAXNETNAMELEN+1) == 0) {
203 - sprintf(mbs_buffer2, "%s.%s", local_host_mb, mbs_buffer);
204 -#else
205 198 if (host2netname(mbs_buffer, NULL, NULL) &&
206 199 netname2host(mbs_buffer, mbs_buffer2, MAXNETNAMELEN+1)) {
207 -#endif
208 200 MBSTOWCS(full_host, mbs_buffer2);
209 201 full_host_wslen = wslen(full_host);
210 202 }
211 203
212 204 for (ms = make_machines_list;
213 205 (ms) && (*ms );
214 206 ) {
215 207 /*
216 208 * Skip white space and comments till you reach
217 209 * a machine name.
218 210 */
219 211 pskip_till_next_word(&ms);
220 212
221 213 /*
222 214 * If we haven't reached the end of file, process the
223 215 * machine name.
224 216 */
225 217 if (*ms) {
226 218 /*
227 219 * If invalid machine name decrement counter
228 220 * and skip line.
229 221 */
230 222 mp = ms;
231 223 SKIPWORD(ms);
232 224 c = *ms;
233 225 *ms++ = '\0'; /* Append null to machine name. */
234 226 /*
235 227 * If this was the beginning of a comment
236 228 * (we overwrote a # sign) and it's not
237 229 * end of line yet, shift the # sign.
238 230 */
239 231 if ((c == '#') && (*ms != '\n') && (*ms)) {
240 232 *ms = '#';
241 233 }
242 234 WCSTOMBS(mbs_buffer, mp);
243 235 /*
244 236 * Print "Ignoring unknown host" if:
245 237 * 1) hostname is longer than MAX_HOSTNAMELEN, or
246 238 * 2) hostname is unknown
247 239 */
248 240 if ((wslen(mp) > MAX_HOSTNAMELEN) ||
249 241 ((hp = gethostbyname(mbs_buffer)) == NULL)) {
250 242 warning(catgets(catd, 1, 318, "Ignoring unknown host %s"),
251 243 mbs_buffer);
252 244 SKIPTOEND(ms);
253 245 /* Increment ptr if not end of file. */
254 246 if (*ms) {
255 247 ms++;
256 248 }
257 249 } else {
258 250 /* Compare current hostname with local_host. */
259 251 if (wslen(mp) == local_host_wslen &&
260 252 IS_WEQUALN(mp, local_host, local_host_wslen)) {
261 253 /*
262 254 * Bingo, local_host is in .make.machines.
263 255 * Continue reading.
264 256 */
265 257 pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
266 258 /* Compare current hostname with full_host. */
267 259 } else if (wslen(mp) == full_host_wslen &&
268 260 IS_WEQUALN(mp, full_host, full_host_wslen)) {
269 261 /*
270 262 * Bingo, full_host is in .make.machines.
271 263 * Continue reading.
272 264 */
273 265 pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
274 266 } else {
275 267 if (c != '\n') {
276 268 SKIPTOEND(ms);
277 269 if (*ms) {
278 270 ms++;
279 271 }
280 272 }
281 273 continue;
282 274 }
283 275 /* If we get here, local_host is in .make.machines. */
284 276 if (c != '\n') {
285 277 /* Now look for keyword 'max'. */
286 278 MBSTOWCS(wcs_buffer, NOCATGETS("max"));
287 279 SKIPSPACE(ms);
288 280 while ((*ms != '\n') && (*ms)) {
289 281 if (*ms == '#') {
290 282 pskip_comment(&ms);
291 283 } else if (IS_WEQUALN(ms, wcs_buffer, 3)) {
292 284 /* Skip "max". */
293 285 ms += 3;
294 286 pmake_max_jobs = get_max(&ms, mp);
295 287 SKIPSPACE(ms);
296 288 } else {
297 289 warning(catgets(catd, 1, 322, "unknown option for host %s"), mbs_buffer);
298 290 SKIPTOEND(ms);
299 291 break;
300 292 }
301 293 }
302 294 }
303 295 break; /* out of outermost for() loop. */
304 296 }
305 297 }
306 298 }
307 299 retmem(make_machines_list);
308 300 return(pmake_max_jobs);
309 301 }
310 302
311 303 /*
312 304 * pskip_till_next_word(cp)
313 305 *
314 306 * Parameters:
315 307 * cp the address of the string pointer.
316 308 *
317 309 * On return:
318 310 * cp points to beginning of machine name.
319 311 *
320 312 */
321 313 static void
322 314 pskip_till_next_word(wchar_t **cp)
323 315 {
324 316 /*
325 317 * Keep recursing until all combinations of white spaces
326 318 * and comments have been skipped.
327 319 */
328 320 if (pskip_white_space(cp) || pskip_comment(cp)) {
329 321 pskip_till_next_word(cp);
330 322 }
331 323 }
332 324
333 325 /*
334 326 * pskip_white_space(cp_address)
335 327 *
336 328 * Advances the string pointer so that it points to the first
337 329 * non white character (space/tab/linefeed).
338 330 *
339 331 * Parameters:
340 332 * cp_address the address of the string pointer.
341 333 *
342 334 * Return Value:
343 335 * True if the pointer was changed.
344 336 *
345 337 */
346 338 static Boolean
347 339 pskip_white_space(wchar_t **cp_address)
348 340 {
349 341 wchar_t *cp = *cp_address;
350 342
351 343 while (*cp && iswspace(*cp)) {
352 344 cp++;
353 345 }
354 346 /* Have we skipped any characters? */
355 347 if (cp != *cp_address) {
356 348 *cp_address = cp;
357 349 return(true);
358 350 } else {
359 351 return(false);
360 352 }
361 353 }
362 354
363 355 /*
364 356 * pskip_comment(cp_address)
365 357 *
366 358 * If cp_address is pointing to '#' (the beginning of a comment),
367 359 * increment the pointer till you reach end of line.
368 360 *
369 361 * Parameters:
370 362 * cp_address the address of the string pointer.
371 363 *
372 364 * Return Value:
373 365 * True if the pointer was changed.
374 366 *
375 367 */
376 368 static Boolean
377 369 pskip_comment(wchar_t **cp_address)
378 370 {
379 371 wchar_t *cp = *cp_address;
380 372
381 373 /* Is this the beginning of a comment? Skip till end of line. */
382 374 if (*cp == '#') {
383 375 SKIPTOEND(cp);
384 376 }
385 377 /* Have we skipped a comment line? */
386 378 if (cp != *cp_address) {
387 379 *cp_address = cp;
388 380 return(true);
389 381 } else {
390 382 return(false);
391 383 }
392 384 }
393 385
394 386 static int
395 387 get_max(wchar_t **ms_address, wchar_t *hostname)
396 388 {
397 389 wchar_t *ms = *ms_address;
398 390 int limit = PMAKE_DEF_MAX_JOBS; /* Default setting. */
399 391
400 392 WCSTOMBS(mbs_buffer, hostname);
401 393 /* Look for `='. */
402 394 SKIPSPACE(ms);
403 395 if ((!*ms) || (*ms == '\n') || (*ms != '=')) {
404 396 SKIPTOEND(ms);
405 397 warning(catgets(catd, 1, 319, "expected `=' after max, ignoring rest of line for host %s"),
406 398 mbs_buffer);
407 399 *ms_address = ms;
408 400 return((int) limit);
409 401 } else {
410 402 ms++;
411 403 SKIPSPACE(ms);
412 404 if ((*ms != '\n') && (*ms != '\0')) {
413 405 /* We've found, hopefully, a valid "max" value. */
414 406 limit = (int) wcstol(ms, &ms, 10);
415 407 if (limit < 1) {
416 408 limit = PMAKE_DEF_MAX_JOBS;
417 409 warning(catgets(catd, 1, 320, "max value cannot be less than or equal to zero for host %s"), mbs_buffer);
418 410 }
419 411 } else {
420 412 /* No "max" value after "max=". */
421 413 warning(catgets(catd, 1, 321, "no max value specified for host %s"), mbs_buffer);
422 414 }
423 415 *ms_address = ms;
424 416 return(limit);
425 417 }
426 418 }
427 419
428 420 #endif
429 421
↓ open down ↓ |
212 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX