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 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * main.cc
28 *
29 * make program main routine plus some helper routines
30 */
31
32 /*
33 * Included files
34 */
35 #if defined(TEAMWARE_MAKE_CMN)
36 # include <avo/intl.h>
37 #endif
38
39 #include <bsd/bsd.h> /* bsd_signal() */
40
41
42 #include <locale.h> /* setlocale() */
43 #include <libgen.h>
44 #include <mk/defs.h>
45 #include <mksdmsi18n/mksdmsi18n.h> /* libmksdmsi18n_init() */
46 #include <mksh/macro.h> /* getvar() */
47 #include <mksh/misc.h> /* getmem(), setup_char_semantics() */
48
49 #if defined(TEAMWARE_MAKE_CMN)
50 #endif
51
52 #include <pwd.h> /* getpwnam() */
53 #include <setjmp.h>
54 #include <signal.h>
55 #include <stdlib.h>
56 #include <sys/errno.h> /* ENOENT */
57 #include <sys/stat.h> /* fstat() */
58 #include <fcntl.h> /* open() */
59
60 # include <sys/systeminfo.h> /* sysinfo() */
61
62 #include <sys/types.h> /* stat() */
63 #include <sys/wait.h> /* wait() */
64 #include <unistd.h> /* execv(), unlink(), access() */
65 #include <vroot/report.h> /* report_dependency(), get_report_file() */
66
67 // From read2.cc
68 extern Name normalize_name(register wchar_t *name_string, register int length);
69
70 // From parallel.cc
71 #define MAXJOBS_ADJUST_RFE4694000
72
73 #ifdef MAXJOBS_ADJUST_RFE4694000
74 extern void job_adjust_fini();
75 #endif /* MAXJOBS_ADJUST_RFE4694000 */
76
77
78 /*
79 * Defined macros
80 */
81 #define MAKE_PREFIX NOCATGETS("/usr")
82 #define LD_SUPPORT_ENV_VAR NOCATGETS("SGS_SUPPORT_32")
83 #define LD_SUPPORT_ENV_VAR_32 NOCATGETS("SGS_SUPPORT_32")
84 #define LD_SUPPORT_ENV_VAR_64 NOCATGETS("SGS_SUPPORT_64")
85 #define LD_SUPPORT_MAKE_LIB NOCATGETS("libmakestate.so.1")
86 #ifdef __i386
87 #define LD_SUPPORT_MAKE_ARCH NOCATGETS("i386")
88 #elif __sparc
89 #define LD_SUPPORT_MAKE_ARCH NOCATGETS("sparc")
90 #else
91 #error "Unsupported architecture"
92 #endif
93
94 /*
95 * typedefs & structs
96 */
97
98 /*
99 * Static variables
100 */
101 static char *argv_zero_string;
102 static Boolean build_failed_ever_seen;
103 static Boolean continue_after_error_ever_seen; /* `-k' */
104 static Boolean dmake_group_specified; /* `-g' */
105 static Boolean dmake_max_jobs_specified; /* `-j' */
106 static Boolean dmake_mode_specified; /* `-m' */
107 static Boolean dmake_add_mode_specified; /* `-x' */
108 static Boolean dmake_output_mode_specified; /* `-x DMAKE_OUTPUT_MODE=' */
109 static Boolean dmake_compat_mode_specified; /* `-x SUN_MAKE_COMPAT_MODE=' */
146 static void append_makeflags_string(Name, String);
147 static void doalarm(int);
148 static void enter_argv_values(int , char **, ASCII_Dyn_Array *);
149 static void make_targets(int, char **, Boolean);
150 static int parse_command_option(char);
151 static void read_command_options(int, char **);
152 static void read_environment(Boolean);
153 static void read_files_and_state(int, char **);
154 static Boolean read_makefile(Name, Boolean, Boolean, Boolean);
155 static void report_recursion(Name);
156 static void set_sgs_support(void);
157 static void setup_for_projectdir(void);
158 static void setup_makeflags_argv(void);
159 static void report_dir_enter_leave(Boolean entering);
160
161 extern void expand_value(Name, register String , Boolean);
162
163 static const char verstring[] = "illumos make";
164
165 jmp_buf jmpbuffer;
166 extern nl_catd catd;
167
168 /*
169 * main(argc, argv)
170 *
171 * Parameters:
172 * argc You know what this is
173 * argv You know what this is
174 *
175 * Static variables used:
176 * list_all_targets make -T seen
177 * trace_status make -p seen
178 *
179 * Global variables used:
180 * debug_level Should we trace make actions?
181 * keep_state Set if .KEEP_STATE seen
182 * makeflags The Name "MAKEFLAGS", used to get macro
183 * remote_command_name Name of remote invocation cmd ("on")
184 * running_list List of parallel running processes
185 * stdout_stderr_same true if stdout and stderr are the same
186 * auto_dependencies The Name "SUNPRO_DEPENDENCIES"
201 char *prognameptr;
202 char *slash_ptr;
203 mode_t um;
204 int i;
205 struct itimerval value;
206 char def_dmakerc_path[MAXPATHLEN];
207 Name dmake_name, dmake_name2;
208 Name dmake_value, dmake_value2;
209 Property prop, prop2;
210 struct stat statbuf;
211 int statval;
212
213 struct stat out_stat, err_stat;
214 hostid = gethostid();
215 bsd_signals();
216
217 (void) setlocale(LC_ALL, "");
218
219
220 #ifdef DMAKE_STATISTICS
221 if (getenv(NOCATGETS("DMAKE_STATISTICS"))) {
222 getname_stat = true;
223 }
224 #endif
225
226 catd = catopen(AVO_DOMAIN_DMAKE, NL_CAT_LOCALE);
227
228 // ---> fprintf(stderr, catgets(catd, 15, 666, "--- SUN make ---\n"));
229
230
231 /*
232 * I put libmksdmsi18n_init() under #ifdef because it requires avo_i18n_init()
233 * from avo_util library.
234 */
235 libmksdmsi18n_init();
236
237
238 textdomain(NOCATGETS("SUNW_SPRO_MAKE"));
239
240 g_argc = argc;
241 g_argv = (char **) malloc((g_argc + 1) * sizeof(char *));
242 for (i = 0; i < argc; i++) {
243 g_argv[i] = argv[i];
244 }
245 g_argv[i] = NULL;
246
247 /*
248 * Set argv_zero_string to some form of argv[0] for
249 * recursive MAKE builds.
250 */
251
252 if (*argv[0] == (int) slash_char) {
253 /* argv[0] starts with a slash */
254 argv_zero_string = strdup(argv[0]);
255 } else if (strchr(argv[0], (int) slash_char) == NULL) {
256 /* argv[0] contains no slashes */
257 argv_zero_string = strdup(argv[0]);
258 } else {
278 * The following flags are reset if we don't have the
279 * (.nse_depinfo or .make.state) files locked and only set
280 * AFTER the file has been locked. This ensures that if the user
281 * interrupts the program while file_lock() is waiting to lock
282 * the file, the interrupt handler doesn't remove a lock
283 * that doesn't belong to us.
284 */
285 make_state_lockfile = NULL;
286 make_state_locked = false;
287
288
289 /*
290 * look for last slash char in the path to look at the binary
291 * name. This is to resolve the hard link and invoke make
292 * in svr4 mode.
293 */
294
295 /* Sun OS make standart */
296 svr4 = false;
297 posix = false;
298 if(!strcmp(argv_zero_string, NOCATGETS("/usr/xpg4/bin/make"))) {
299 svr4 = false;
300 posix = true;
301 } else {
302 prognameptr = strrchr(argv[0], '/');
303 if(prognameptr) {
304 prognameptr++;
305 } else {
306 prognameptr = argv[0];
307 }
308 if(!strcmp(prognameptr, NOCATGETS("svr4.make"))) {
309 svr4 = true;
310 posix = false;
311 }
312 }
313 if (getenv(USE_SVR4_MAKE) || getenv(NOCATGETS("USE_SVID"))){
314 svr4 = true;
315 posix = false;
316 }
317
318 /*
319 * Find the dmake_compat_mode: posix, sun, svr4, or gnu_style, .
320 */
321 char * dmake_compat_mode_var = getenv(NOCATGETS("SUN_MAKE_COMPAT_MODE"));
322 if (dmake_compat_mode_var != NULL) {
323 if (0 == strcasecmp(dmake_compat_mode_var, NOCATGETS("GNU"))) {
324 gnu_style = true;
325 }
326 //svr4 = false;
327 //posix = false;
328 }
329
330 /*
331 * Temporary directory set up.
332 */
333 char * tmpdir_var = getenv(NOCATGETS("TMPDIR"));
334 if (tmpdir_var != NULL && *tmpdir_var == '/' && strlen(tmpdir_var) < MAXPATHLEN) {
335 strcpy(mbs_buffer, tmpdir_var);
336 for (tmpdir_var = mbs_buffer+strlen(mbs_buffer);
337 *(--tmpdir_var) == '/' && tmpdir_var > mbs_buffer;
338 *tmpdir_var = '\0');
339 if (strlen(mbs_buffer) + 32 < MAXPATHLEN) { /* 32 = strlen("/dmake.stdout.%d.%d.XXXXXX") */
340 sprintf(mbs_buffer2, NOCATGETS("%s/dmake.tst.%d.XXXXXX"),
341 mbs_buffer, getpid());
342 int fd = mkstemp(mbs_buffer2);
343 if (fd >= 0) {
344 close(fd);
345 unlink(mbs_buffer2);
346 tmpdir = strdup(mbs_buffer);
347 }
348 }
349 }
350
351 /* find out if stdout and stderr point to the same place */
352 if (fstat(1, &out_stat) < 0) {
353 fatal(catgets(catd, 1, 165, "fstat of standard out failed: %s"), errmsg(errno));
354 }
355 if (fstat(2, &err_stat) < 0) {
356 fatal(catgets(catd, 1, 166, "fstat of standard error failed: %s"), errmsg(errno));
357 }
358 if ((out_stat.st_dev == err_stat.st_dev) &&
359 (out_stat.st_ino == err_stat.st_ino)) {
360 stdout_stderr_same = true;
361 } else {
362 stdout_stderr_same = false;
363 }
364 /* Make the vroot package scan the path using shell semantics */
365 set_path_style(0);
366
367 setup_char_semantics();
368
369 setup_for_projectdir();
370
371 /*
372 * If running with .KEEP_STATE, curdir will be set with
373 * the connected directory.
374 */
375 (void) atexit(cleanup_after_exit);
376
377 load_cached_names();
378
379 /*
380 * Set command line flags
381 */
382 setup_makeflags_argv();
383 read_command_options(mf_argc, mf_argv);
384 read_command_options(argc, argv);
385 if (debug_level > 0) {
386 cp = getenv(makeflags->string_mb);
387 (void) printf(catgets(catd, 1, 167, "MAKEFLAGS value: %s\n"), cp == NULL ? "" : cp);
388 }
389
390 setup_interrupt(handle_interrupt);
391
392 read_files_and_state(argc, argv);
393
394 /*
395 * Find the dmake_output_mode: TXT1, TXT2 or HTML1.
396 */
397 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_OUTPUT_MODE"));
398 dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
399 prop2 = get_prop(dmake_name2->prop, macro_prop);
400 if (prop2 == NULL) {
401 /* DMAKE_OUTPUT_MODE not defined, default to TXT1 mode */
402 output_mode = txt1_mode;
403 } else {
404 dmake_value2 = prop2->body.macro.value;
405 if ((dmake_value2 == NULL) ||
406 (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT1")))) {
407 output_mode = txt1_mode;
408 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT2"))) {
409 output_mode = txt2_mode;
410 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("HTML1"))) {
411 output_mode = html1_mode;
412 } else {
413 warning(catgets(catd, 1, 352, "Unsupported value `%s' for DMAKE_OUTPUT_MODE after -x flag (ignored)"),
414 dmake_value2->string_mb);
415 }
416 }
417 /*
418 * Find the dmake_mode: parallel, or serial.
419 */
420 if ((!pmake_cap_r_specified) &&
421 (!pmake_machinesfile_specified)) {
422 char *s = strdup(argv[0]);
423
424 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE"));
425 dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
426 prop2 = get_prop(dmake_name2->prop, macro_prop);
427 // If we're invoked as 'make' run serially, regardless of DMAKE_MODE
428 // If we're invoked as 'make' but passed -j, run parallel
429 // If we're invoked as 'dmake', without DMAKE_MODE, default parallel
430 // If we're invoked as 'dmake' and DMAKE_MODE is set, honour it.
431 if ((strcmp(basename(s), NOCATGETS("make")) == 0) &&
432 !dmake_max_jobs_specified) {
433 dmake_mode_type = serial_mode;
434 no_parallel = true;
435 } else if (prop2 == NULL) {
436 /* DMAKE_MODE not defined, default based on our name */
437 char *s = strdup(argv[0]);
438
439 if (strcmp(basename(s), NOCATGETS("dmake")) == 0) {
440 dmake_mode_type = parallel_mode;
441 no_parallel = false;
442 }
443 } else {
444 dmake_value2 = prop2->body.macro.value;
445 if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("parallel"))) {
446 dmake_mode_type = parallel_mode;
447 no_parallel = false;
448 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("serial"))) {
449 dmake_mode_type = serial_mode;
450 no_parallel = true;
451 } else {
452 fatal(catgets(catd, 1, 307, "Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb);
453 }
454 }
455 free(s);
456 }
457
458 parallel_flag = true;
459 putenv(strdup(NOCATGETS("DMAKE_CHILD=TRUE")));
460
461 //
462 // If dmake is running with -t option, set dmake_mode_type to serial.
463 // This is done because doname() calls touch_command() that runs serially.
464 // If we do not do that, maketool will have problems.
465 //
466 if(touch) {
467 dmake_mode_type = serial_mode;
468 no_parallel = true;
469 }
470
471 /*
472 * Check whether stdout and stderr are physically same.
473 * This is in order to decide whether we need to redirect
474 * stderr separately from stdout.
475 * This check is performed only if __DMAKE_SEPARATE_STDERR
476 * is not set. This variable may be used in order to preserve
477 * the 'old' behaviour.
478 */
479 out_err_same = true;
480 char * dmake_sep_var = getenv(NOCATGETS("__DMAKE_SEPARATE_STDERR"));
481 if (dmake_sep_var == NULL || (0 != strcasecmp(dmake_sep_var, NOCATGETS("NO")))) {
482 struct stat stdout_stat;
483 struct stat stderr_stat;
484 if( (fstat(1, &stdout_stat) == 0)
485 && (fstat(2, &stderr_stat) == 0) )
486 {
487 if( (stdout_stat.st_dev != stderr_stat.st_dev)
488 || (stdout_stat.st_ino != stderr_stat.st_ino) )
489 {
490 out_err_same = false;
491 }
492 }
493 }
494
495
496 /*
497 * Enable interrupt handler for alarms
498 */
499 (void) bsd_signal(SIGALRM, (SIG_PF)doalarm);
500
501 /*
593 * Called from exit(), performs cleanup actions.
594 *
595 * Parameters:
596 * status The argument exit() was called with
597 * arg Address of an argument vector to
598 * cleanup_after_exit()
599 *
600 * Global variables used:
601 * command_changed Set if we think .make.state should be rewritten
602 * current_line Is set we set commands_changed
603 * do_not_exec_rule
604 * True if -n flag on
605 * done The Name ".DONE", rule we run
606 * keep_state Set if .KEEP_STATE seen
607 * parallel True if building in parallel
608 * quest If -q is on we do not run .DONE
609 * report_dependencies
610 * True if -P flag on
611 * running_list List of parallel running processes
612 * temp_file_name The temp file is removed, if any
613 * catd the message catalog file
614 */
615 extern "C" void
616 cleanup_after_exit(void)
617 {
618 Running rp;
619
620 extern long getname_bytes_count;
621 extern long getname_names_count;
622 extern long getname_struct_count;
623 extern long freename_bytes_count;
624 extern long freename_names_count;
625 extern long freename_struct_count;
626 extern long other_alloc;
627
628 extern long env_alloc_num;
629 extern long env_alloc_bytes;
630
631
632 #ifdef DMAKE_STATISTICS
633 if(getname_stat) {
634 printf(NOCATGETS(">>> Getname statistics:\n"));
635 printf(NOCATGETS(" Allocated:\n"));
636 printf(NOCATGETS(" Names: %ld\n"), getname_names_count);
637 printf(NOCATGETS(" Strings: %ld Kb (%ld bytes)\n"), getname_bytes_count/1000, getname_bytes_count);
638 printf(NOCATGETS(" Structs: %ld Kb (%ld bytes)\n"), getname_struct_count/1000, getname_struct_count);
639 printf(NOCATGETS(" Total bytes: %ld Kb (%ld bytes)\n"), getname_struct_count/1000 + getname_bytes_count/1000, getname_struct_count + getname_bytes_count);
640
641 printf(NOCATGETS("\n Unallocated: %ld\n"), freename_names_count);
642 printf(NOCATGETS(" Names: %ld\n"), freename_names_count);
643 printf(NOCATGETS(" Strings: %ld Kb (%ld bytes)\n"), freename_bytes_count/1000, freename_bytes_count);
644 printf(NOCATGETS(" Structs: %ld Kb (%ld bytes)\n"), freename_struct_count/1000, freename_struct_count);
645 printf(NOCATGETS(" Total bytes: %ld Kb (%ld bytes)\n"), freename_struct_count/1000 + freename_bytes_count/1000, freename_struct_count + freename_bytes_count);
646
647 printf(NOCATGETS("\n Total used: %ld Kb (%ld bytes)\n"), (getname_struct_count/1000 + getname_bytes_count/1000) - (freename_struct_count/1000 + freename_bytes_count/1000), (getname_struct_count + getname_bytes_count) - (freename_struct_count + freename_bytes_count));
648
649 printf(NOCATGETS("\n>>> Other:\n"));
650 printf(
651 NOCATGETS(" Env (%ld): %ld Kb (%ld bytes)\n"),
652 env_alloc_num,
653 env_alloc_bytes/1000,
654 env_alloc_bytes
655 );
656
657 }
658 #endif
659
660 parallel = false;
661 /* If we used the SVR4_MAKE, don't build .DONE or .FAILED */
662 if (!getenv(USE_SVR4_MAKE)){
663 /* Build the target .DONE or .FAILED if we caught an error */
664 if (!quest && !list_all_targets) {
665 Name failed_name;
666
667 MBSTOWCS(wcs_buffer, NOCATGETS(".FAILED"));
668 failed_name = GETNAME(wcs_buffer, FIND_LENGTH);
669 if ((exit_status != 0) && (failed_name->prop != NULL)) {
670 /*
671 * [tolik] switch DMake to serial mode
672 */
673 dmake_mode_type = serial_mode;
674 no_parallel = true;
675 (void) doname(failed_name, false, true);
676 } else {
677 if (!trace_status) {
678 /*
679 * Switch DMake to serial mode
680 */
681 dmake_mode_type = serial_mode;
682 no_parallel = true;
683 (void) doname(done, false, true);
684 }
685 }
686 }
687 }
721 command_changed = true;
722 /*
723 line = get_prop(rp->target->prop, line_prop);
724 if (line != NULL) {
725 line->body.line.command_used = NULL;
726 }
727 */
728 }
729 /* Remove the statefile lock file if the file has been locked */
730 if ((make_state_lockfile != NULL) && (make_state_locked)) {
731 (void) unlink(make_state_lockfile);
732 make_state_lockfile = NULL;
733 make_state_locked = false;
734 }
735 /* Write .make.state */
736 write_state_file(1, (Boolean) 1);
737
738 #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
739 job_adjust_fini();
740 #endif
741
742 #ifdef TEAMWARE_MAKE_CMN
743 catclose(catd);
744 #endif
745 }
746
747 /*
748 * handle_interrupt()
749 *
750 * This is where C-C traps are caught.
751 *
752 * Parameters:
753 *
754 * Global variables used (except DMake 1.0):
755 * current_target Sometimes the current target is removed
756 * do_not_exec_rule But not if -n is on
757 * quest or -q
758 * running_list List of parallel running processes
759 * touch Current target is not removed if -t on
760 */
761 void
762 handle_interrupt(int)
763 {
764 Property member;
793 current_target->is_member &&
794 ((member = get_prop(current_target->prop, member_prop)) != NULL)) {
795 current_target = member->body.member.library;
796 }
797 if (!do_not_exec_rule &&
798 !touch &&
799 !quest &&
800 (current_target != NULL) &&
801 !(current_target->stat.is_precious || all_precious)) {
802
803 /* BID_1030811 */
804 /* azv 16 Oct 95 */
805 current_target->stat.time = file_no_time;
806
807 if (exists(current_target) != file_doesnt_exist) {
808 (void) fprintf(stderr,
809 "\n*** %s ",
810 current_target->string_mb);
811 if (current_target->stat.is_dir) {
812 (void) fprintf(stderr,
813 catgets(catd, 1, 168, "not removed.\n"),
814 current_target->string_mb);
815 } else if (unlink(current_target->string_mb) == 0) {
816 (void) fprintf(stderr,
817 catgets(catd, 1, 169, "removed.\n"),
818 current_target->string_mb);
819 } else {
820 (void) fprintf(stderr,
821 catgets(catd, 1, 170, "could not be removed: %s.\n"),
822 current_target->string_mb,
823 errmsg(errno));
824 }
825 }
826 }
827 for (rp = running_list; rp != NULL; rp = rp->next) {
828 if (rp->state != build_running) {
829 continue;
830 }
831 if (rp->target->is_member &&
832 ((member = get_prop(rp->target->prop, member_prop)) !=
833 NULL)) {
834 rp->target = member->body.member.library;
835 }
836 if (!do_not_exec_rule &&
837 !touch &&
838 !quest &&
839 !(rp->target->stat.is_precious || all_precious)) {
840
841 rp->target->stat.time = file_no_time;
842 if (exists(rp->target) != file_doesnt_exist) {
843 (void) fprintf(stderr,
844 "\n*** %s ",
845 rp->target->string_mb);
846 if (rp->target->stat.is_dir) {
847 (void) fprintf(stderr,
848 catgets(catd, 1, 171, "not removed.\n"),
849 rp->target->string_mb);
850 } else if (unlink(rp->target->string_mb) == 0) {
851 (void) fprintf(stderr,
852 catgets(catd, 1, 172, "removed.\n"),
853 rp->target->string_mb);
854 } else {
855 (void) fprintf(stderr,
856 catgets(catd, 1, 173, "could not be removed: %s.\n"),
857 rp->target->string_mb,
858 errmsg(errno));
859 }
860 }
861 }
862 }
863
864
865 /* Have we locked .make.state or .nse_depinfo? */
866 if ((make_state_lockfile != NULL) && (make_state_locked)) {
867 unlink(make_state_lockfile);
868 make_state_lockfile = NULL;
869 make_state_locked = false;
870 }
871 /*
872 * Re-read .make.state file (it might be changed by recursive make)
873 */
874 check_state(NULL);
875
876 report_dir_enter_leave(false);
996 /* Eliminate first hyphen character */
997 for (j=0; argv[i][j] != '\0'; j++) {
998 argv[i][j] = argv[i][j+1];
999 }
1000
1001 /* Repeat the processing of this argument */
1002 optind=last_optind;
1003 current_optind=last_current_optind;
1004 continue;
1005 }
1006 }
1007 }
1008 }
1009 }
1010 }
1011 }
1012
1013 if (ch == '?') {
1014 if (svr4) {
1015 fprintf(stderr,
1016 catgets(catd, 1, 267, "Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1017 fprintf(stderr,
1018 catgets(catd, 1, 268, " [ -j dmake_max_jobs ][ -m dmake_mode ][ -o dmake_odir ]...\n"));
1019 fprintf(stderr,
1020 catgets(catd, 1, 269, " [ -e ][ -i ][ -k ][ -n ][ -p ][ -q ][ -r ][ -s ][ -t ][ -v ]\n"));
1021 tptr = strchr(SVR4_CMD_OPTS, optopt);
1022 } else {
1023 fprintf(stderr,
1024 catgets(catd, 1, 272, "Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1025 fprintf(stderr,
1026 catgets(catd, 1, 273, " [ -j dmake_max_jobs ][ -K statefile ][ -m dmake_mode ][ -x MODE_NAME=VALUE ][ -o dmake_odir ]...\n"));
1027 fprintf(stderr,
1028 catgets(catd, 1, 274, " [ -d ][ -dd ][ -D ][ -DD ][ -e ][ -i ][ -k ][ -n ][ -p ][ -P ][ -u ][ -w ]\n"));
1029 fprintf(stderr,
1030 catgets(catd, 1, 275, " [ -q ][ -r ][ -s ][ -S ][ -t ][ -v ][ -V ][ target... ][ macro=value... ][ \"macro +=value\"... ]\n"));
1031 tptr = strchr(SUNPRO_CMD_OPTS, optopt);
1032 }
1033 if (!tptr) {
1034 fatal(catgets(catd, 1, 279, "Unknown option `-%c'"), optopt);
1035 } else {
1036 fatal(catgets(catd, 1, 280, "Missing argument after `-%c'"), optopt);
1037 }
1038 }
1039
1040
1041
1042 makefile_next |= parse_command_option(ch);
1043 /*
1044 * If we're done processing all of the options of
1045 * ONE argument string...
1046 */
1047 if (current_optind < optind) {
1048 i = current_optind;
1049 k = 0;
1050 /* If there's an argument for an option... */
1051 if ((optind - current_optind) > 1) {
1052 k = i + 1;
1053 }
1054 switch (makefile_next) {
1055 case 0:
1056 argv[i] = NULL;
1057 /* This shouldn't happen */
1058 if (k) {
1059 argv[k] = NULL;
1060 }
1061 break;
1062 case 1: /* -f seen */
1063 argv[i] = (char *)NOCATGETS("-f");
1064 break;
1065 case 2: /* -c seen */
1066 argv[i] = (char *)NOCATGETS("-c");
1067 break;
1068 case 4: /* -g seen */
1069 argv[i] = (char *)NOCATGETS("-g");
1070 break;
1071 case 8: /* -j seen */
1072 argv[i] = (char *)NOCATGETS("-j");
1073 break;
1074 case 16: /* -M seen */
1075 argv[i] = (char *)NOCATGETS("-M");
1076 break;
1077 case 32: /* -m seen */
1078 argv[i] = (char *)NOCATGETS("-m");
1079 break;
1080 case 128: /* -O seen */
1081 argv[i] = (char *)NOCATGETS("-O");
1082 break;
1083 case 256: /* -K seen */
1084 argv[i] = (char *)NOCATGETS("-K");
1085 break;
1086 case 512: /* -o seen */
1087 argv[i] = (char *)NOCATGETS("-o");
1088 break;
1089 case 1024: /* -x seen */
1090 argv[i] = (char *)NOCATGETS("-x");
1091 break;
1092 default: /* > 1 of -c, f, g, j, K, M, m, O, o, x seen */
1093 fatal(catgets(catd, 1, 286, "Illegal command line. More than one option requiring\nan argument given in the same argument group"));
1094 }
1095
1096 makefile_next = 0;
1097 current_optind = optind;
1098 }
1099 }
1100 }
1101
1102 static void
1103 quote_str(char *str, char *qstr)
1104 {
1105 char *to;
1106 char *from;
1107
1108 to = qstr;
1109 for (from = str; *from; from++) {
1110 switch (*from) {
1111 case ';': /* End of command */
1112 case '(': /* Start group */
1113 case ')': /* End group */
1223 /* Find the number of arguments in MAKEFLAGS */
1224 while (cp && *cp) {
1225 /* Skip white spaces */
1226 while (cp && *cp && isspace(*cp)) {
1227 cp++;
1228 }
1229 if (cp && *cp) {
1230 /* Increment arg count */
1231 mf_argc++;
1232 /* Go to next white space */
1233 while (cp && *cp && !isspace(*cp)) {
1234 if(*cp == (int) backslash_char) {
1235 cp++;
1236 }
1237 cp++;
1238 }
1239 }
1240 }
1241 /* Allocate memory for the new MAKEFLAGS argv */
1242 mf_argv = (char **) malloc((mf_argc + 1) * sizeof(char *));
1243 mf_argv[0] = (char *)NOCATGETS("MAKEFLAGS");
1244 /*
1245 * Convert the MAKEFLAGS string value into a vector of char *,
1246 * similar to argv.
1247 */
1248 cp = cp_orig;
1249 for (i = 1; i < mf_argc; i++) {
1250 /* Skip white spaces */
1251 while (cp && *cp && isspace(*cp)) {
1252 cp++;
1253 }
1254 if (cp && *cp) {
1255 cp_orig = cp;
1256 /* Go to next white space */
1257 while (cp && *cp && !isspace(*cp)) {
1258 if(*cp == (int) backslash_char) {
1259 cp++;
1260 }
1261 cp++;
1262 }
1263 tmp_char = *cp;
1510 case 't': /* Touch flag */
1511 if (invert_this) {
1512 touch = false;
1513 } else {
1514 touch = true;
1515 }
1516 return 0;
1517 case 'u': /* Unconditional flag */
1518 if (invert_this) {
1519 build_unconditional = false;
1520 } else {
1521 build_unconditional = true;
1522 }
1523 return 0;
1524 case 'V': /* SVR4 mode */
1525 svr4 = true;
1526 return 0;
1527 case 'v': /* Version flag */
1528 if (invert_this) {
1529 } else {
1530 fprintf(stdout, NOCATGETS("dmake: %s\n"), verstring);
1531 exit_status = 0;
1532 exit(0);
1533 }
1534 return 0;
1535 case 'w': /* Unconditional flag */
1536 if (invert_this) {
1537 report_cwd = false;
1538 } else {
1539 report_cwd = true;
1540 }
1541 return 0;
1542 #if 0
1543 case 'X': /* Filter stdout */
1544 if (invert_this) {
1545 filter_stderr = false;
1546 } else {
1547 filter_stderr = true;
1548 }
1549 return 0;
1550 #endif
1556
1557 /*
1558 * setup_for_projectdir()
1559 *
1560 * Read the PROJECTDIR variable, if defined, and set the sccs path
1561 *
1562 * Parameters:
1563 *
1564 * Global variables used:
1565 * sccs_dir_path Set to point to SCCS dir to use
1566 */
1567 static void
1568 setup_for_projectdir(void)
1569 {
1570 static char path[MAXPATHLEN];
1571 char cwdpath[MAXPATHLEN];
1572 uid_t uid;
1573 int done=0;
1574
1575 /* Check if we should use PROJECTDIR when reading the SCCS dir. */
1576 sccs_dir_path = getenv(NOCATGETS("PROJECTDIR"));
1577 if ((sccs_dir_path != NULL) &&
1578 (sccs_dir_path[0] != (int) slash_char)) {
1579 struct passwd *pwent;
1580
1581 {
1582 uid = getuid();
1583 pwent = getpwuid(uid);
1584 if (pwent == NULL) {
1585 fatal(catgets(catd, 1, 188, "Bogus USERID "));
1586 }
1587 if ((pwent = getpwnam(sccs_dir_path)) == NULL) {
1588 /*empty block : it'll go & check cwd */
1589 }
1590 else {
1591 (void) sprintf(path, NOCATGETS("%s/src"), pwent->pw_dir);
1592 if (access(path, F_OK) == 0) {
1593 sccs_dir_path = path;
1594 done = 1;
1595 } else {
1596 (void) sprintf(path, NOCATGETS("%s/source"), pwent->pw_dir);
1597 if (access(path, F_OK) == 0) {
1598 sccs_dir_path = path;
1599 done = 1;
1600 }
1601 }
1602 }
1603 if (!done) {
1604 if (getcwd(cwdpath, MAXPATHLEN - 1 )) {
1605
1606 (void) sprintf(path, NOCATGETS("%s/%s"), cwdpath,sccs_dir_path);
1607 if (access(path, F_OK) == 0) {
1608 sccs_dir_path = path;
1609 done = 1;
1610 } else {
1611 fatal(catgets(catd, 1, 189, "Bogus PROJECTDIR '%s'"), sccs_dir_path);
1612 }
1613 }
1614 }
1615 }
1616 }
1617 }
1618
1619 char *
1620 make_install_prefix(void)
1621 {
1622 int ret;
1623 char origin[PATH_MAX];
1624 char *dir;
1625
1626 if ((ret = readlink("/proc/self/path/a.out", origin,
1627 PATH_MAX - 1)) < 0)
1628 fatal("failed to read origin from /proc\n");
1629
1630
1631 origin[ret] = '\0';
1793 Name new_make_value;
1794 Boolean save_do_not_exec_rule;
1795 Name sdotMakefile;
1796 Name sdotmakefile_name;
1797 static wchar_t state_file_str;
1798 static char state_file_str_mb[MAXPATHLEN];
1799 static struct _Name state_filename;
1800 Boolean temp;
1801 char tmp_char;
1802 wchar_t *tmp_wcs_buffer;
1803 register Name value;
1804 ASCII_Dyn_Array makeflags_and_macro;
1805 Boolean is_xpg4;
1806
1807 /*
1808 * Remember current mode. It may be changed after reading makefile
1809 * and we will have to correct MAKEFLAGS variable.
1810 */
1811 is_xpg4 = posix;
1812
1813 MBSTOWCS(wcs_buffer, NOCATGETS("KEEP_STATE"));
1814 keep_state_name = GETNAME(wcs_buffer, FIND_LENGTH);
1815 MBSTOWCS(wcs_buffer, NOCATGETS("Makefile"));
1816 Makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1817 MBSTOWCS(wcs_buffer, NOCATGETS("makefile"));
1818 makefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
1819 MBSTOWCS(wcs_buffer, NOCATGETS("s.makefile"));
1820 sdotmakefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
1821 MBSTOWCS(wcs_buffer, NOCATGETS("s.Makefile"));
1822 sdotMakefile = GETNAME(wcs_buffer, FIND_LENGTH);
1823
1824 /*
1825 * initialize global dependency entry for .NOT_AUTO
1826 */
1827 not_auto_depen->next = NULL;
1828 not_auto_depen->name = not_auto;
1829 not_auto_depen->automatic = not_auto_depen->stale = false;
1830
1831 /*
1832 * Read internal definitions and rules.
1833 */
1834 if (read_trace_level > 1) {
1835 trace_reader = true;
1836 }
1837 if (!ignore_default_mk) {
1838 if (svr4) {
1839 MBSTOWCS(wcs_buffer, NOCATGETS("svr4.make.rules"));
1840 default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1841 } else {
1842 MBSTOWCS(wcs_buffer, NOCATGETS("make.rules"));
1843 default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1844 }
1845 default_makefile->stat.is_file = true;
1846
1847 (void) read_makefile(default_makefile,
1848 true,
1849 false,
1850 true);
1851 }
1852
1853 /*
1854 * If the user did not redefine the MAKE macro in the
1855 * default makefile (make.rules), then we'd like to
1856 * change the macro value of MAKE to be some form
1857 * of argv[0] for recursive MAKE builds.
1858 */
1859 MBSTOWCS(wcs_buffer, NOCATGETS("MAKE"));
1860 def_make_name = GETNAME(wcs_buffer, wslen(wcs_buffer));
1861 def_make_macro = get_prop(def_make_name->prop, macro_prop);
1862 if ((def_make_macro != NULL) &&
1863 (IS_EQUAL(def_make_macro->body.macro.value->string_mb,
1864 NOCATGETS("make")))) {
1865 MBSTOWCS(wcs_buffer, argv_zero_string);
1866 new_make_value = GETNAME(wcs_buffer, wslen(wcs_buffer));
1867 (void) SETVAR(def_make_name,
1868 new_make_value,
1869 false);
1870 }
1871
1872 default_target_to_build = NULL;
1873 trace_reader = false;
1874
1875 /*
1876 * Read environment args. Let file args which follow override unless
1877 * -e option seen. If -e option is not mentioned.
1878 */
1879 read_environment(env_wins);
1880 if (getvar(virtual_root)->hash.length == 0) {
1881 maybe_append_prop(virtual_root, macro_prop)
1882 ->body.macro.exported = true;
1883 MBSTOWCS(wcs_buffer, "/");
1884 (void) SETVAR(virtual_root,
1976 append_char('q', &makeflags_string_posix);
1977 }
1978 if (silent_all) {
1979 append_char('s', &makeflags_string);
1980 append_char('s', &makeflags_string_posix);
1981 }
1982 if (touch) {
1983 append_char('t', &makeflags_string);
1984 append_char('t', &makeflags_string_posix);
1985 }
1986 if (build_unconditional) {
1987 append_char('u', &makeflags_string);
1988 append_char('u', &makeflags_string_posix);
1989 }
1990 if (report_cwd) {
1991 append_char('w', &makeflags_string);
1992 append_char('w', &makeflags_string_posix);
1993 }
1994 /* -c dmake_rcfile */
1995 if (dmake_rcfile_specified) {
1996 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_RCFILE"));
1997 dmake_rcfile = GETNAME(wcs_buffer, FIND_LENGTH);
1998 append_makeflags_string(dmake_rcfile, &makeflags_string);
1999 append_makeflags_string(dmake_rcfile, &makeflags_string_posix);
2000 }
2001 /* -g dmake_group */
2002 if (dmake_group_specified) {
2003 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_GROUP"));
2004 dmake_group = GETNAME(wcs_buffer, FIND_LENGTH);
2005 append_makeflags_string(dmake_group, &makeflags_string);
2006 append_makeflags_string(dmake_group, &makeflags_string_posix);
2007 }
2008 /* -j dmake_max_jobs */
2009 if (dmake_max_jobs_specified) {
2010 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MAX_JOBS"));
2011 dmake_max_jobs = GETNAME(wcs_buffer, FIND_LENGTH);
2012 append_makeflags_string(dmake_max_jobs, &makeflags_string);
2013 append_makeflags_string(dmake_max_jobs, &makeflags_string_posix);
2014 }
2015 /* -m dmake_mode */
2016 if (dmake_mode_specified) {
2017 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE"));
2018 dmake_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2019 append_makeflags_string(dmake_mode, &makeflags_string);
2020 append_makeflags_string(dmake_mode, &makeflags_string_posix);
2021 }
2022 /* -x dmake_compat_mode */
2023 // if (dmake_compat_mode_specified) {
2024 // MBSTOWCS(wcs_buffer, NOCATGETS("SUN_MAKE_COMPAT_MODE"));
2025 // dmake_compat_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2026 // append_makeflags_string(dmake_compat_mode, &makeflags_string);
2027 // append_makeflags_string(dmake_compat_mode, &makeflags_string_posix);
2028 // }
2029 /* -x dmake_output_mode */
2030 if (dmake_output_mode_specified) {
2031 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_OUTPUT_MODE"));
2032 dmake_output_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2033 append_makeflags_string(dmake_output_mode, &makeflags_string);
2034 append_makeflags_string(dmake_output_mode, &makeflags_string_posix);
2035 }
2036 /* -o dmake_odir */
2037 if (dmake_odir_specified) {
2038 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_ODIR"));
2039 dmake_odir = GETNAME(wcs_buffer, FIND_LENGTH);
2040 append_makeflags_string(dmake_odir, &makeflags_string);
2041 append_makeflags_string(dmake_odir, &makeflags_string_posix);
2042 }
2043 /* -M pmake_machinesfile */
2044 if (pmake_machinesfile_specified) {
2045 MBSTOWCS(wcs_buffer, NOCATGETS("PMAKE_MACHINESFILE"));
2046 pmake_machinesfile = GETNAME(wcs_buffer, FIND_LENGTH);
2047 append_makeflags_string(pmake_machinesfile, &makeflags_string);
2048 append_makeflags_string(pmake_machinesfile, &makeflags_string_posix);
2049 }
2050 /* -R */
2051 if (pmake_cap_r_specified) {
2052 append_char((int) space_char, &makeflags_string);
2053 append_char((int) hyphen_char, &makeflags_string);
2054 append_char('R', &makeflags_string);
2055 append_char((int) space_char, &makeflags_string_posix);
2056 append_char((int) hyphen_char, &makeflags_string_posix);
2057 append_char('R', &makeflags_string_posix);
2058 }
2059
2060 /*
2061 * Make sure MAKEFLAGS is exported
2062 */
2063 maybe_append_prop(makeflags, macro_prop)->
2064 body.macro.exported = true;
2065
2066 if (makeflags_string.buffer.start[1] != (int) nul_char) {
2067 if (makeflags_string.buffer.start[1] != (int) space_char) {
2068 MBSTOWCS(wcs_buffer, NOCATGETS("MFLAGS"));
2069 (void) SETVAR(GETNAME(wcs_buffer, FIND_LENGTH),
2070 GETNAME(makeflags_string.buffer.start,
2071 FIND_LENGTH),
2072 false);
2073 } else {
2074 MBSTOWCS(wcs_buffer, NOCATGETS("MFLAGS"));
2075 (void) SETVAR(GETNAME(wcs_buffer, FIND_LENGTH),
2076 GETNAME(makeflags_string.buffer.start + 2,
2077 FIND_LENGTH),
2078 false);
2079 }
2080 }
2081
2082 /*
2083 * Add command line macro to POSIX makeflags_string
2084 */
2085 if (makeflags_and_macro.start) {
2086 tmp_char = (char) space_char;
2087 cp = makeflags_and_macro.start;
2088 do {
2089 append_char(tmp_char, &makeflags_string_posix);
2090 } while ( tmp_char = *cp++ );
2091 retmem_mb(makeflags_and_macro.start);
2092 }
2093
2094 /*
2126 , false
2127 );
2128 macro->body.macro.read_only = temp;
2129
2130 /*
2131 * Read command line "-f" arguments and ignore -c, g, j, K, M, m, O and o args.
2132 */
2133 save_do_not_exec_rule = do_not_exec_rule;
2134 do_not_exec_rule = false;
2135 if (read_trace_level > 0) {
2136 trace_reader = true;
2137 }
2138
2139 for (i = 1; i < argc; i++) {
2140 if (argv[i] &&
2141 (argv[i][0] == (int) hyphen_char) &&
2142 (argv[i][1] == 'f') &&
2143 (argv[i][2] == (int) nul_char)) {
2144 argv[i] = NULL; /* Remove -f */
2145 if (i >= argc - 1) {
2146 fatal(catgets(catd, 1, 190, "No filename argument after -f flag"));
2147 }
2148 MBSTOWCS(wcs_buffer, argv[++i]);
2149 primary_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
2150 (void) read_makefile(primary_makefile, true, true, true);
2151 argv[i] = NULL; /* Remove filename */
2152 makefile_read = true;
2153 } else if (argv[i] &&
2154 (argv[i][0] == (int) hyphen_char) &&
2155 (argv[i][1] == 'c' ||
2156 argv[i][1] == 'g' ||
2157 argv[i][1] == 'j' ||
2158 argv[i][1] == 'K' ||
2159 argv[i][1] == 'M' ||
2160 argv[i][1] == 'm' ||
2161 argv[i][1] == 'O' ||
2162 argv[i][1] == 'o') &&
2163 (argv[i][2] == (int) nul_char)) {
2164 argv[i] = NULL;
2165 argv[++i] = NULL;
2166 }
2167 }
2168
2169 /*
2170 * If no command line "-f" args then look for "makefile", and then for
2171 * "Makefile" if "makefile" isn't found.
2172 */
2173 if (!makefile_read) {
2174 (void) read_dir(dot,
2175 (wchar_t *) NULL,
2176 (Property) NULL,
2177 (wchar_t *) NULL);
2178 if (!posix) {
2179 if (makefile_name->stat.is_file) {
2180 if (Makefile->stat.is_file) {
2181 warning(catgets(catd, 1, 310, "Both `makefile' and `Makefile' exist"));
2182 }
2183 primary_makefile = makefile_name;
2184 makefile_read = read_makefile(makefile_name,
2185 false,
2186 false,
2187 true);
2188 }
2189 if (!makefile_read &&
2190 Makefile->stat.is_file) {
2191 primary_makefile = Makefile;
2192 makefile_read = read_makefile(Makefile,
2193 false,
2194 false,
2195 true);
2196 }
2197 } else {
2198
2199 enum sccs_stat save_m_has_sccs = NO_SCCS;
2200 enum sccs_stat save_M_has_sccs = NO_SCCS;
2201
2202 if (makefile_name->stat.is_file) {
2203 if (Makefile->stat.is_file) {
2204 warning(catgets(catd, 1, 191, "Both `makefile' and `Makefile' exist"));
2205 }
2206 }
2207 if (makefile_name->stat.is_file) {
2208 if (makefile_name->stat.has_sccs == NO_SCCS) {
2209 primary_makefile = makefile_name;
2210 makefile_read = read_makefile(makefile_name,
2211 false,
2212 false,
2213 true);
2214 } else {
2215 save_m_has_sccs = makefile_name->stat.has_sccs;
2216 makefile_name->stat.has_sccs = NO_SCCS;
2217 primary_makefile = makefile_name;
2218 makefile_read = read_makefile(makefile_name,
2219 false,
2220 false,
2221 true);
2222 }
2223 }
2224 if (!makefile_read &&
2294 }
2295 }
2296 }
2297
2298 if (makeflags_string.free_after_use) {
2299 retmem(makeflags_string.buffer.start);
2300 }
2301 if (makeflags_string_posix.free_after_use) {
2302 retmem(makeflags_string_posix.buffer.start);
2303 }
2304 makeflags_string.buffer.start = NULL;
2305 makeflags_string_posix.buffer.start = NULL;
2306
2307 if (posix) {
2308 /*
2309 * If the user did not redefine the ARFLAGS macro in the
2310 * default makefile (make.rules), then we'd like to
2311 * change the macro value of ARFLAGS to be in accordance
2312 * with "POSIX" requirements.
2313 */
2314 MBSTOWCS(wcs_buffer, NOCATGETS("ARFLAGS"));
2315 name = GETNAME(wcs_buffer, wslen(wcs_buffer));
2316 macro = get_prop(name->prop, macro_prop);
2317 if ((macro != NULL) && /* Maybe (macro == NULL) || ? */
2318 (IS_EQUAL(macro->body.macro.value->string_mb,
2319 NOCATGETS("rv")))) {
2320 MBSTOWCS(wcs_buffer, NOCATGETS("-rv"));
2321 value = GETNAME(wcs_buffer, wslen(wcs_buffer));
2322 (void) SETVAR(name,
2323 value,
2324 false);
2325 }
2326 }
2327
2328 if (!posix && !svr4) {
2329 set_sgs_support();
2330 }
2331
2332
2333 /*
2334 * Make sure KEEP_STATE is in the environment if KEEP_STATE is on.
2335 */
2336 macro = get_prop(keep_state_name->prop, macro_prop);
2337 if ((macro != NULL) &&
2338 macro->body.macro.exported) {
2339 keep_state = true;
2340 }
2360 */
2361 INIT_STRING_FROM_STACK(dest, destbuffer);
2362 expand_value(make_state, &dest, false);
2363
2364 make_state = GETNAME(dest.buffer.start, FIND_LENGTH);
2365
2366 if(!stat(make_state->string_mb, &make_state_stat)) {
2367 if(!(make_state_stat.st_mode & S_IFREG) ) {
2368 /* copy the make_state structure to the other
2369 ** and then let make_state point to the new
2370 ** one.
2371 */
2372 memcpy(&state_filename, make_state,sizeof(state_filename));
2373 state_filename.string_mb = state_file_str_mb;
2374 /* Just a kludge to avoid two slashes back to back */
2375 if((make_state->hash.length == 1)&&
2376 (make_state->string_mb[0] == '/')) {
2377 make_state->hash.length = 0;
2378 make_state->string_mb[0] = '\0';
2379 }
2380 sprintf(state_file_str_mb,NOCATGETS("%s%s"),
2381 make_state->string_mb,NOCATGETS("/.make.state"));
2382 make_state = &state_filename;
2383 /* adjust the length to reflect the appended string */
2384 make_state->hash.length += 12;
2385 }
2386 } else { /* the file doesn't exist or no permission */
2387 char tmp_path[MAXPATHLEN];
2388 char *slashp;
2389
2390 if (slashp = strrchr(make_state->string_mb, '/')) {
2391 strncpy(tmp_path, make_state->string_mb,
2392 (slashp - make_state->string_mb));
2393 tmp_path[slashp - make_state->string_mb]=0;
2394 if(strlen(tmp_path)) {
2395 if(stat(tmp_path, &make_state_stat)) {
2396 warning(catgets(catd, 1, 192, "directory %s for .KEEP_STATE_FILE does not exist"),tmp_path);
2397 }
2398 if (access(tmp_path, F_OK) != 0) {
2399 warning(catgets(catd, 1, 193, "can't access dir %s"),tmp_path);
2400 }
2401 }
2402 }
2403 }
2404 if (report_dependencies_level != 1) {
2405 Makefile_type makefile_type_temp = makefile_type;
2406 makefile_type = reading_statefile;
2407 if (read_trace_level > 1) {
2408 trace_reader = true;
2409 }
2410 (void) read_simple_file(make_state,
2411 false,
2412 false,
2413 false,
2414 false,
2415 false,
2416 true);
2417 trace_reader = false;
2418 makefile_type = makefile_type_temp;
2419 }
2443 makefile_type = reading_nothing;
2444 for (i = 1; i < argc; ++i) {
2445 append = false;
2446 if (argv[i] == NULL) {
2447 continue;
2448 } else if (((argv[i][0] == '-') && (argv[i][1] == '-')) ||
2449 ((argv[i][0] == (int) ' ') &&
2450 (argv[i][1] == (int) '-') &&
2451 (argv[i][2] == (int) ' ') &&
2452 (argv[i][3] == (int) '-'))) {
2453 argv[i] = NULL;
2454 opt_separator = i;
2455 continue;
2456 } else if ((i < opt_separator) && (argv[i][0] == (int) hyphen_char)) {
2457 switch (parse_command_option(argv[i][1])) {
2458 case 1: /* -f seen */
2459 ++i;
2460 continue;
2461 case 2: /* -c seen */
2462 if (argv[i+1] == NULL) {
2463 fatal(catgets(catd, 1, 194, "No dmake rcfile argument after -c flag"));
2464 }
2465 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_RCFILE"));
2466 name = GETNAME(wcs_buffer, FIND_LENGTH);
2467 break;
2468 case 4: /* -g seen */
2469 if (argv[i+1] == NULL) {
2470 fatal(catgets(catd, 1, 195, "No dmake group argument after -g flag"));
2471 }
2472 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_GROUP"));
2473 name = GETNAME(wcs_buffer, FIND_LENGTH);
2474 break;
2475 case 8: /* -j seen */
2476 if (argv[i+1] == NULL) {
2477 fatal(catgets(catd, 1, 196, "No dmake max jobs argument after -j flag"));
2478 }
2479 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MAX_JOBS"));
2480 name = GETNAME(wcs_buffer, FIND_LENGTH);
2481 break;
2482 case 16: /* -M seen */
2483 if (argv[i+1] == NULL) {
2484 fatal(catgets(catd, 1, 323, "No pmake machinesfile argument after -M flag"));
2485 }
2486 MBSTOWCS(wcs_buffer, NOCATGETS("PMAKE_MACHINESFILE"));
2487 name = GETNAME(wcs_buffer, FIND_LENGTH);
2488 break;
2489 case 32: /* -m seen */
2490 if (argv[i+1] == NULL) {
2491 fatal(catgets(catd, 1, 197, "No dmake mode argument after -m flag"));
2492 }
2493 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE"));
2494 name = GETNAME(wcs_buffer, FIND_LENGTH);
2495 break;
2496 case 256: /* -K seen */
2497 if (argv[i+1] == NULL) {
2498 fatal(catgets(catd, 1, 288, "No makestate filename argument after -K flag"));
2499 }
2500 MBSTOWCS(wcs_buffer, argv[i+1]);
2501 make_state = GETNAME(wcs_buffer, FIND_LENGTH);
2502 keep_state = true;
2503 argv[i] = NULL;
2504 argv[i+1] = NULL;
2505 continue;
2506 case 512: /* -o seen */
2507 if (argv[i+1] == NULL) {
2508 fatal(catgets(catd, 1, 312, "No dmake output dir argument after -o flag"));
2509 }
2510 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_ODIR"));
2511 name = GETNAME(wcs_buffer, FIND_LENGTH);
2512 break;
2513 case 1024: /* -x seen */
2514 if (argv[i+1] == NULL) {
2515 fatal(catgets(catd, 1, 351, "No argument after -x flag"));
2516 }
2517 length = strlen( NOCATGETS("SUN_MAKE_COMPAT_MODE="));
2518 if (strncmp(argv[i+1], NOCATGETS("SUN_MAKE_COMPAT_MODE="), length) == 0) {
2519 argv[i+1] = &argv[i+1][length];
2520 MBSTOWCS(wcs_buffer, NOCATGETS("SUN_MAKE_COMPAT_MODE"));
2521 name = GETNAME(wcs_buffer, FIND_LENGTH);
2522 dmake_compat_mode_specified = dmake_add_mode_specified;
2523 break;
2524 }
2525 length = strlen( NOCATGETS("DMAKE_OUTPUT_MODE="));
2526 if (strncmp(argv[i+1], NOCATGETS("DMAKE_OUTPUT_MODE="), length) == 0) {
2527 argv[i+1] = &argv[i+1][length];
2528 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_OUTPUT_MODE"));
2529 name = GETNAME(wcs_buffer, FIND_LENGTH);
2530 dmake_output_mode_specified = dmake_add_mode_specified;
2531 } else {
2532 warning(catgets(catd, 1, 354, "Unknown argument `%s' after -x flag (ignored)"),
2533 argv[i+1]);
2534 argv[i] = argv[i + 1] = NULL;
2535 continue;
2536 }
2537 break;
2538 default: /* Shouldn't reach here */
2539 argv[i] = NULL;
2540 continue;
2541 }
2542 argv[i] = NULL;
2543 if (i == (argc - 1)) {
2544 break;
2545 }
2546 if ((length = strlen(argv[i+1])) >= MAXPATHLEN) {
2547 tmp_wcs_buffer = ALLOC_WC(length + 1);
2548 (void) mbstowcs(tmp_wcs_buffer, argv[i+1], length + 1);
2549 value = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
2550 retmem(tmp_wcs_buffer);
2551 } else {
2552 MBSTOWCS(wcs_buffer, argv[i+1]);
2598 }
2599 if(append) {
2600 setvar_append(name, value);
2601 append = false;
2602 } else {
2603 macro = maybe_append_prop(name, macro_prop);
2604 macro->body.macro.exported = true;
2605 SETVAR(name, value, false)->body.macro.read_only = true;
2606 }
2607 }
2608 }
2609
2610 /*
2611 * Append the DMake option and value to the MAKEFLAGS string.
2612 */
2613 static void
2614 append_makeflags_string(Name name, register String makeflags_string)
2615 {
2616 const char *option;
2617
2618 if (strcmp(name->string_mb, NOCATGETS("DMAKE_GROUP")) == 0) {
2619 option = NOCATGETS(" -g ");
2620 } else if (strcmp(name->string_mb, NOCATGETS("DMAKE_MAX_JOBS")) == 0) {
2621 option = NOCATGETS(" -j ");
2622 } else if (strcmp(name->string_mb, NOCATGETS("DMAKE_MODE")) == 0) {
2623 option = NOCATGETS(" -m ");
2624 } else if (strcmp(name->string_mb, NOCATGETS("DMAKE_ODIR")) == 0) {
2625 option = NOCATGETS(" -o ");
2626 } else if (strcmp(name->string_mb, NOCATGETS("DMAKE_RCFILE")) == 0) {
2627 option = NOCATGETS(" -c ");
2628 } else if (strcmp(name->string_mb, NOCATGETS("PMAKE_MACHINESFILE")) == 0) {
2629 option = NOCATGETS(" -M ");
2630 } else if (strcmp(name->string_mb, NOCATGETS("DMAKE_OUTPUT_MODE")) == 0) {
2631 option = NOCATGETS(" -x DMAKE_OUTPUT_MODE=");
2632 } else if (strcmp(name->string_mb, NOCATGETS("SUN_MAKE_COMPAT_MODE")) == 0) {
2633 option = NOCATGETS(" -x SUN_MAKE_COMPAT_MODE=");
2634 } else {
2635 fatal(catgets(catd, 1, 289, "Internal error: name not recognized in append_makeflags_string()"));
2636 }
2637 Property prop = maybe_append_prop(name, macro_prop);
2638 if( prop == 0 || prop->body.macro.value == 0 ||
2639 prop->body.macro.value->string_mb == 0 ) {
2640 return;
2641 }
2642 char mbs_value[MAXPATHLEN + 100];
2643 strcpy(mbs_value, option);
2644 strcat(mbs_value, prop->body.macro.value->string_mb);
2645 MBSTOWCS(wcs_buffer, mbs_value);
2646 append_string(wcs_buffer, makeflags_string, FIND_LENGTH);
2647 }
2648
2649 /*
2650 * read_environment(read_only)
2651 *
2652 * This routine reads the process environment when make starts and enters
2653 * it as make macros. The environment variable SHELL is ignored.
2654 *
2655 * Parameters:
2676 for (; *environment; environment++) {
2677 read_only_saved = read_only;
2678 if ((length = strlen(*environment)) >= MAXPATHLEN) {
2679 tmp_wcs_buffer = ALLOC_WC(length + 1);
2680 alloced_tmp_wcs_buffer = true;
2681 (void) mbstowcs(tmp_wcs_buffer, *environment, length + 1);
2682 name = tmp_wcs_buffer;
2683 } else {
2684 MBSTOWCS(wcs_buffer, *environment);
2685 name = wcs_buffer;
2686 }
2687 value = (wchar_t *) wschr(name, (int) equal_char);
2688
2689 /*
2690 * Looks like there's a bug in the system, but sometimes
2691 * you can get blank lines in *environment.
2692 */
2693 if (!value) {
2694 continue;
2695 }
2696 MBSTOWCS(wcs_buffer2, NOCATGETS("SHELL="));
2697 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2698 continue;
2699 }
2700 MBSTOWCS(wcs_buffer2, NOCATGETS("MAKEFLAGS="));
2701 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2702 report_pwd = true;
2703 /*
2704 * In POSIX mode we do not want MAKEFLAGS to be readonly.
2705 * If the MAKEFLAGS macro is subsequently set by the makefile,
2706 * it replaces the MAKEFLAGS variable currently found in the
2707 * environment.
2708 * See Assertion 50 in section 6.2.5.3 of standard P1003.3.2/D8.
2709 */
2710 if(posix) {
2711 read_only_saved = false;
2712 }
2713 }
2714
2715 /*
2716 * We ignore SUNPRO_DEPENDENCIES. This environment variable is
2717 * set by make and read by cpp which then writes info to
2718 * .make.dependency.xxx. When make is invoked by another make
2719 * (recursive make), we don't want to read this because then
2720 * the child make will end up writing to the parent
2721 * directory's .make.state and clobbering them.
2722 */
2723 MBSTOWCS(wcs_buffer2, NOCATGETS("SUNPRO_DEPENDENCIES"));
2724 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2725 continue;
2726 }
2727
2728 macro = GETNAME(name, value - name);
2729 maybe_append_prop(macro, macro_prop)->body.macro.exported =
2730 true;
2731 if ((value == NULL) || ((value + 1)[0] == (int) nul_char)) {
2732 val = setvar_daemon(macro,
2733 (Name) NULL,
2734 false, no_daemon, false, debug_level);
2735 } else {
2736 val = setvar_daemon(macro,
2737 GETNAME(value + 1, FIND_LENGTH),
2738 false, no_daemon, false, debug_level);
2739 }
2740 val->body.macro.read_only = read_only_saved;
2741 if (alloced_tmp_wcs_buffer) {
2742 retmem(tmp_wcs_buffer);
2743 alloced_tmp_wcs_buffer = false;
2851 * parallel, hold off the target processing
2852 * to preserve the order of the targets as they appeared
2853 * in command line.
2854 */
2855 if (!parallel_ok(default_target_to_build, false)
2856 && parallel_process_cnt > 0) {
2857 finish_running();
2858 }
2859 result = doname_check(default_target_to_build,
2860 true,
2861 false,
2862 false);
2863 gather_recursive_deps();
2864 if (/* !commands_done && */
2865 (result == build_ok) &&
2866 !quest &&
2867 (report_dependencies_level == 0) /* &&
2868 (exists(default_target_to_build) > file_doesnt_exist) */) {
2869 if (posix) {
2870 if (!commands_done) {
2871 (void) printf(catgets(catd, 1, 293, "`%s' is updated.\n"),
2872 default_target_to_build->string_mb);
2873 } else {
2874 if (no_action_was_taken) {
2875 (void) printf(catgets(catd, 1, 294, "`%s': no action was taken.\n"),
2876 default_target_to_build->string_mb);
2877 }
2878 }
2879 } else {
2880 default_target_to_build->stat.time = file_no_time;
2881 if (!commands_done &&
2882 (exists(default_target_to_build) > file_doesnt_exist)) {
2883 (void) printf(catgets(catd, 1, 295, "`%s' is up to date.\n"),
2884 default_target_to_build->string_mb);
2885 }
2886 }
2887 }
2888 }
2889 }
2890 /* Now wait for all of the targets to finish running */
2891 finish_running();
2892 // setjmp(jmpbuffer);
2893
2894 }
2895 for (i = 1; i < argc; i++) {
2896 if ((cp = argv[i]) != NULL) {
2897 target_to_make_found = true;
2898 if ((cp[0] == (int) period_char) &&
2899 (cp[1] == (int) slash_char)) {
2900 cp += 2;
2901 }
2902 if((cp[0] == (int) ' ') &&
2903 (cp[1] == (int) '-') &&
2905 (cp[3] == (int) '-')) {
2906 argv[i] = NULL;
2907 continue;
2908 }
2909 MBSTOWCS(wcs_buffer, cp);
2910 default_target_to_build = normalize_name(wcs_buffer, wslen(wcs_buffer));
2911 top_level_target = get_wstring(default_target_to_build->string_mb);
2912 report_recursion(default_target_to_build);
2913 commands_done = false;
2914 if (parallel) {
2915 result = (Doname) default_target_to_build->state;
2916 } else {
2917 result = doname_check(default_target_to_build,
2918 true,
2919 false,
2920 false);
2921 }
2922 gather_recursive_deps();
2923 if (build_failed_seen) {
2924 build_failed_ever_seen = true;
2925 warning(catgets(catd, 1, 200, "Target `%s' not remade because of errors"),
2926 default_target_to_build->string_mb);
2927 }
2928 build_failed_seen = false;
2929 if (report_dependencies_level > 0) {
2930 print_dependencies(default_target_to_build,
2931 get_prop(default_target_to_build->prop,
2932 line_prop));
2933 }
2934 default_target_to_build->stat.time =
2935 file_no_time;
2936 if (default_target_to_build->colon_splits > 0) {
2937 default_target_to_build->state =
2938 build_dont_know;
2939 }
2940 if (!parallel &&
2941 /* !commands_done && */
2942 (result == build_ok) &&
2943 !quest &&
2944 (report_dependencies_level == 0) /* &&
2945 (exists(default_target_to_build) > file_doesnt_exist) */) {
2946 if (posix) {
2947 if (!commands_done) {
2948 (void) printf(catgets(catd, 1, 296, "`%s' is updated.\n"),
2949 default_target_to_build->string_mb);
2950 } else {
2951 if (no_action_was_taken) {
2952 (void) printf(catgets(catd, 1, 297, "`%s': no action was taken.\n"),
2953 default_target_to_build->string_mb);
2954 }
2955 }
2956 } else {
2957 if (!commands_done &&
2958 (exists(default_target_to_build) > file_doesnt_exist)) {
2959 (void) printf(catgets(catd, 1, 298, "`%s' is up to date.\n"),
2960 default_target_to_build->string_mb);
2961 }
2962 }
2963 }
2964 }
2965 }
2966
2967 /*
2968 * If no file arguments have been encountered,
2969 * make the first name encountered that doesnt start with a dot
2970 */
2971 if (!target_to_make_found) {
2972 if (default_target_to_build == NULL) {
2973 fatal(catgets(catd, 1, 202, "No arguments to build"));
2974 }
2975 commands_done = false;
2976 top_level_target = get_wstring(default_target_to_build->string_mb);
2977 report_recursion(default_target_to_build);
2978
2979
2980 if (getenv(NOCATGETS("SPRO_EXPAND_ERRORS"))){
2981 (void) printf(NOCATGETS("::(%s)\n"),
2982 default_target_to_build->string_mb);
2983 }
2984
2985
2986 result = doname_parallel(default_target_to_build, true, false);
2987 gather_recursive_deps();
2988 if (build_failed_seen) {
2989 build_failed_ever_seen = true;
2990 warning(catgets(catd, 1, 203, "Target `%s' not remade because of errors"),
2991 default_target_to_build->string_mb);
2992 }
2993 build_failed_seen = false;
2994 if (report_dependencies_level > 0) {
2995 print_dependencies(default_target_to_build,
2996 get_prop(default_target_to_build->
2997 prop,
2998 line_prop));
2999 }
3000 default_target_to_build->stat.time = file_no_time;
3001 if (default_target_to_build->colon_splits > 0) {
3002 default_target_to_build->state = build_dont_know;
3003 }
3004 if (/* !commands_done && */
3005 (result == build_ok) &&
3006 !quest &&
3007 (report_dependencies_level == 0) /* &&
3008 (exists(default_target_to_build) > file_doesnt_exist) */) {
3009 if (posix) {
3010 if (!commands_done) {
3011 (void) printf(catgets(catd, 1, 299, "`%s' is updated.\n"),
3012 default_target_to_build->string_mb);
3013 } else {
3014 if (no_action_was_taken) {
3015 (void) printf(catgets(catd, 1, 300, "`%s': no action was taken.\n"),
3016 default_target_to_build->string_mb);
3017 }
3018 }
3019 } else {
3020 if (!commands_done &&
3021 (exists(default_target_to_build) > file_doesnt_exist)) {
3022 (void) printf(catgets(catd, 1, 301, "`%s' is up to date.\n"),
3023 default_target_to_build->string_mb);
3024 }
3025 }
3026 }
3027 }
3028 }
3029
3030 /*
3031 * report_recursion(target)
3032 *
3033 * If this is a recursive make and the parent make has KEEP_STATE on
3034 * this routine reports the dependency to the parent make
3035 *
3036 * Parameters:
3037 * target Target to report
3038 *
3039 * Global variables used:
3040 * makefiles_used List of makefiles read
3041 * recursive_name The Name ".RECURSIVE", printed
3042 * report_dependency dwight
3179 if (len_array + len_macro + esc_len + 5 >= Ar->size) goto ALLOC_ARRAY;
3180 strcat(Ar->start, " ");
3181 strncat(Ar->start, name, cp0-name);
3182 strcat(Ar->start, "=");
3183 strncat(Ar->start, esc_value, strlen(esc_value));
3184 free(esc_value);
3185 return;
3186 ERROR_MACRO:
3187 /* Macro without '=' or with invalid left/right part */
3188 return;
3189 }
3190
3191 static void
3192 report_dir_enter_leave(Boolean entering)
3193 {
3194 char rcwd[MAXPATHLEN];
3195 static char * mlev = NULL;
3196 char * make_level_str = NULL;
3197 int make_level_val = 0;
3198
3199 make_level_str = getenv(NOCATGETS("MAKELEVEL"));
3200 if(make_level_str) {
3201 make_level_val = atoi(make_level_str);
3202 }
3203 if(mlev == NULL) {
3204 mlev = (char*) malloc(MAXPATHLEN);
3205 }
3206 if(entering) {
3207 sprintf(mlev, NOCATGETS("MAKELEVEL=%d"), make_level_val + 1);
3208 } else {
3209 make_level_val--;
3210 sprintf(mlev, NOCATGETS("MAKELEVEL=%d"), make_level_val);
3211 }
3212 putenv(mlev);
3213
3214 if(report_cwd) {
3215 if(make_level_val <= 0) {
3216 if(entering) {
3217 sprintf( rcwd
3218 , catgets(catd, 1, 329, "dmake: Entering directory `%s'\n")
3219 , get_current_path());
3220 } else {
3221 sprintf( rcwd
3222 , catgets(catd, 1, 331, "dmake: Leaving directory `%s'\n")
3223 , get_current_path());
3224 }
3225 } else {
3226 if(entering) {
3227 sprintf( rcwd
3228 , catgets(catd, 1, 333, "dmake[%d]: Entering directory `%s'\n")
3229 , make_level_val, get_current_path());
3230 } else {
3231 sprintf( rcwd
3232 , catgets(catd, 1, 335, "dmake[%d]: Leaving directory `%s'\n")
3233 , make_level_val, get_current_path());
3234 }
3235 }
3236 printf(NOCATGETS("%s"), rcwd);
3237 }
3238 }
|
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 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * main.cc
28 *
29 * make program main routine plus some helper routines
30 */
31
32 /*
33 * Included files
34 */
35 #include <bsd/bsd.h> /* bsd_signal() */
36
37
38 #include <locale.h> /* setlocale() */
39 #include <libgen.h>
40 #include <mk/defs.h>
41 #include <mksh/macro.h> /* getvar() */
42 #include <mksh/misc.h> /* getmem(), setup_char_semantics() */
43
44 #include <pwd.h> /* getpwnam() */
45 #include <setjmp.h>
46 #include <signal.h>
47 #include <stdlib.h>
48 #include <sys/errno.h> /* ENOENT */
49 #include <sys/stat.h> /* fstat() */
50 #include <fcntl.h> /* open() */
51
52 # include <sys/systeminfo.h> /* sysinfo() */
53
54 #include <sys/types.h> /* stat() */
55 #include <sys/wait.h> /* wait() */
56 #include <unistd.h> /* execv(), unlink(), access() */
57 #include <vroot/report.h> /* report_dependency(), get_report_file() */
58
59 // From read2.cc
60 extern Name normalize_name(register wchar_t *name_string, register int length);
61
62 // From parallel.cc
63 #define MAXJOBS_ADJUST_RFE4694000
64
65 #ifdef MAXJOBS_ADJUST_RFE4694000
66 extern void job_adjust_fini();
67 #endif /* MAXJOBS_ADJUST_RFE4694000 */
68
69
70 /*
71 * Defined macros
72 */
73 #define LD_SUPPORT_ENV_VAR "SGS_SUPPORT_32"
74 #define LD_SUPPORT_ENV_VAR_32 "SGS_SUPPORT_32"
75 #define LD_SUPPORT_ENV_VAR_64 "SGS_SUPPORT_64"
76 #define LD_SUPPORT_MAKE_LIB "libmakestate.so.1"
77 #ifdef __i386
78 #define LD_SUPPORT_MAKE_ARCH "i386"
79 #elif __sparc
80 #define LD_SUPPORT_MAKE_ARCH "sparc"
81 #else
82 #error "Unsupported architecture"
83 #endif
84
85 /*
86 * typedefs & structs
87 */
88
89 /*
90 * Static variables
91 */
92 static char *argv_zero_string;
93 static Boolean build_failed_ever_seen;
94 static Boolean continue_after_error_ever_seen; /* `-k' */
95 static Boolean dmake_group_specified; /* `-g' */
96 static Boolean dmake_max_jobs_specified; /* `-j' */
97 static Boolean dmake_mode_specified; /* `-m' */
98 static Boolean dmake_add_mode_specified; /* `-x' */
99 static Boolean dmake_output_mode_specified; /* `-x DMAKE_OUTPUT_MODE=' */
100 static Boolean dmake_compat_mode_specified; /* `-x SUN_MAKE_COMPAT_MODE=' */
137 static void append_makeflags_string(Name, String);
138 static void doalarm(int);
139 static void enter_argv_values(int , char **, ASCII_Dyn_Array *);
140 static void make_targets(int, char **, Boolean);
141 static int parse_command_option(char);
142 static void read_command_options(int, char **);
143 static void read_environment(Boolean);
144 static void read_files_and_state(int, char **);
145 static Boolean read_makefile(Name, Boolean, Boolean, Boolean);
146 static void report_recursion(Name);
147 static void set_sgs_support(void);
148 static void setup_for_projectdir(void);
149 static void setup_makeflags_argv(void);
150 static void report_dir_enter_leave(Boolean entering);
151
152 extern void expand_value(Name, register String , Boolean);
153
154 static const char verstring[] = "illumos make";
155
156 jmp_buf jmpbuffer;
157
158 /*
159 * main(argc, argv)
160 *
161 * Parameters:
162 * argc You know what this is
163 * argv You know what this is
164 *
165 * Static variables used:
166 * list_all_targets make -T seen
167 * trace_status make -p seen
168 *
169 * Global variables used:
170 * debug_level Should we trace make actions?
171 * keep_state Set if .KEEP_STATE seen
172 * makeflags The Name "MAKEFLAGS", used to get macro
173 * remote_command_name Name of remote invocation cmd ("on")
174 * running_list List of parallel running processes
175 * stdout_stderr_same true if stdout and stderr are the same
176 * auto_dependencies The Name "SUNPRO_DEPENDENCIES"
191 char *prognameptr;
192 char *slash_ptr;
193 mode_t um;
194 int i;
195 struct itimerval value;
196 char def_dmakerc_path[MAXPATHLEN];
197 Name dmake_name, dmake_name2;
198 Name dmake_value, dmake_value2;
199 Property prop, prop2;
200 struct stat statbuf;
201 int statval;
202
203 struct stat out_stat, err_stat;
204 hostid = gethostid();
205 bsd_signals();
206
207 (void) setlocale(LC_ALL, "");
208
209
210 #ifdef DMAKE_STATISTICS
211 if (getenv("DMAKE_STATISTICS")) {
212 getname_stat = true;
213 }
214 #endif
215
216 #ifndef TEXT_DOMAIN
217 #define TEXT_DOMAIN "SYS_TEST"
218 #endif
219 textdomain(TEXT_DOMAIN);
220
221 g_argc = argc;
222 g_argv = (char **) malloc((g_argc + 1) * sizeof(char *));
223 for (i = 0; i < argc; i++) {
224 g_argv[i] = argv[i];
225 }
226 g_argv[i] = NULL;
227
228 /*
229 * Set argv_zero_string to some form of argv[0] for
230 * recursive MAKE builds.
231 */
232
233 if (*argv[0] == (int) slash_char) {
234 /* argv[0] starts with a slash */
235 argv_zero_string = strdup(argv[0]);
236 } else if (strchr(argv[0], (int) slash_char) == NULL) {
237 /* argv[0] contains no slashes */
238 argv_zero_string = strdup(argv[0]);
239 } else {
259 * The following flags are reset if we don't have the
260 * (.nse_depinfo or .make.state) files locked and only set
261 * AFTER the file has been locked. This ensures that if the user
262 * interrupts the program while file_lock() is waiting to lock
263 * the file, the interrupt handler doesn't remove a lock
264 * that doesn't belong to us.
265 */
266 make_state_lockfile = NULL;
267 make_state_locked = false;
268
269
270 /*
271 * look for last slash char in the path to look at the binary
272 * name. This is to resolve the hard link and invoke make
273 * in svr4 mode.
274 */
275
276 /* Sun OS make standart */
277 svr4 = false;
278 posix = false;
279 if(!strcmp(argv_zero_string, "/usr/xpg4/bin/make")) {
280 svr4 = false;
281 posix = true;
282 } else {
283 prognameptr = strrchr(argv[0], '/');
284 if(prognameptr) {
285 prognameptr++;
286 } else {
287 prognameptr = argv[0];
288 }
289 if(!strcmp(prognameptr, "svr4.make")) {
290 svr4 = true;
291 posix = false;
292 }
293 }
294 if (getenv(USE_SVR4_MAKE) || getenv("USE_SVID")){
295 svr4 = true;
296 posix = false;
297 }
298
299 /*
300 * Find the dmake_compat_mode: posix, sun, svr4, or gnu_style, .
301 */
302 char * dmake_compat_mode_var = getenv("SUN_MAKE_COMPAT_MODE");
303 if (dmake_compat_mode_var != NULL) {
304 if (0 == strcasecmp(dmake_compat_mode_var, "GNU")) {
305 gnu_style = true;
306 }
307 //svr4 = false;
308 //posix = false;
309 }
310
311 /*
312 * Temporary directory set up.
313 */
314 char * tmpdir_var = getenv("TMPDIR");
315 if (tmpdir_var != NULL && *tmpdir_var == '/' && strlen(tmpdir_var) < MAXPATHLEN) {
316 strcpy(mbs_buffer, tmpdir_var);
317 for (tmpdir_var = mbs_buffer+strlen(mbs_buffer);
318 *(--tmpdir_var) == '/' && tmpdir_var > mbs_buffer;
319 *tmpdir_var = '\0');
320 if (strlen(mbs_buffer) + 32 < MAXPATHLEN) { /* 32 = strlen("/dmake.stdout.%d.%d.XXXXXX") */
321 sprintf(mbs_buffer2, "%s/dmake.tst.%d.XXXXXX",
322 mbs_buffer, getpid());
323 int fd = mkstemp(mbs_buffer2);
324 if (fd >= 0) {
325 close(fd);
326 unlink(mbs_buffer2);
327 tmpdir = strdup(mbs_buffer);
328 }
329 }
330 }
331
332 /* find out if stdout and stderr point to the same place */
333 if (fstat(1, &out_stat) < 0) {
334 fatal(gettext("fstat of standard out failed: %s"), errmsg(errno));
335 }
336 if (fstat(2, &err_stat) < 0) {
337 fatal(gettext("fstat of standard error failed: %s"), errmsg(errno));
338 }
339 if ((out_stat.st_dev == err_stat.st_dev) &&
340 (out_stat.st_ino == err_stat.st_ino)) {
341 stdout_stderr_same = true;
342 } else {
343 stdout_stderr_same = false;
344 }
345 /* Make the vroot package scan the path using shell semantics */
346 set_path_style(0);
347
348 setup_char_semantics();
349
350 setup_for_projectdir();
351
352 /*
353 * If running with .KEEP_STATE, curdir will be set with
354 * the connected directory.
355 */
356 (void) atexit(cleanup_after_exit);
357
358 load_cached_names();
359
360 /*
361 * Set command line flags
362 */
363 setup_makeflags_argv();
364 read_command_options(mf_argc, mf_argv);
365 read_command_options(argc, argv);
366 if (debug_level > 0) {
367 cp = getenv(makeflags->string_mb);
368 (void) printf(gettext("MAKEFLAGS value: %s\n"), cp == NULL ? "" : cp);
369 }
370
371 setup_interrupt(handle_interrupt);
372
373 read_files_and_state(argc, argv);
374
375 /*
376 * Find the dmake_output_mode: TXT1, TXT2 or HTML1.
377 */
378 MBSTOWCS(wcs_buffer, "DMAKE_OUTPUT_MODE");
379 dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
380 prop2 = get_prop(dmake_name2->prop, macro_prop);
381 if (prop2 == NULL) {
382 /* DMAKE_OUTPUT_MODE not defined, default to TXT1 mode */
383 output_mode = txt1_mode;
384 } else {
385 dmake_value2 = prop2->body.macro.value;
386 if ((dmake_value2 == NULL) ||
387 (IS_EQUAL(dmake_value2->string_mb, "TXT1"))) {
388 output_mode = txt1_mode;
389 } else if (IS_EQUAL(dmake_value2->string_mb, "TXT2")) {
390 output_mode = txt2_mode;
391 } else if (IS_EQUAL(dmake_value2->string_mb, "HTML1")) {
392 output_mode = html1_mode;
393 } else {
394 warning(gettext("Unsupported value `%s' for DMAKE_OUTPUT_MODE after -x flag (ignored)"),
395 dmake_value2->string_mb);
396 }
397 }
398 /*
399 * Find the dmake_mode: parallel, or serial.
400 */
401 if ((!pmake_cap_r_specified) &&
402 (!pmake_machinesfile_specified)) {
403 char *s = strdup(argv[0]);
404
405 MBSTOWCS(wcs_buffer, "DMAKE_MODE");
406 dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
407 prop2 = get_prop(dmake_name2->prop, macro_prop);
408 // If we're invoked as 'make' run serially, regardless of DMAKE_MODE
409 // If we're invoked as 'make' but passed -j, run parallel
410 // If we're invoked as 'dmake', without DMAKE_MODE, default parallel
411 // If we're invoked as 'dmake' and DMAKE_MODE is set, honour it.
412 if ((strcmp(basename(s), "make") == 0) &&
413 !dmake_max_jobs_specified) {
414 dmake_mode_type = serial_mode;
415 no_parallel = true;
416 } else if (prop2 == NULL) {
417 /* DMAKE_MODE not defined, default based on our name */
418 char *s = strdup(argv[0]);
419
420 if (strcmp(basename(s), "dmake") == 0) {
421 dmake_mode_type = parallel_mode;
422 no_parallel = false;
423 }
424 } else {
425 dmake_value2 = prop2->body.macro.value;
426 if (IS_EQUAL(dmake_value2->string_mb, "parallel")) {
427 dmake_mode_type = parallel_mode;
428 no_parallel = false;
429 } else if (IS_EQUAL(dmake_value2->string_mb, "serial")) {
430 dmake_mode_type = serial_mode;
431 no_parallel = true;
432 } else {
433 fatal(gettext("Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb);
434 }
435 }
436 free(s);
437 }
438
439 parallel_flag = true;
440 putenv(strdup("DMAKE_CHILD=TRUE"));
441
442 //
443 // If dmake is running with -t option, set dmake_mode_type to serial.
444 // This is done because doname() calls touch_command() that runs serially.
445 // If we do not do that, maketool will have problems.
446 //
447 if(touch) {
448 dmake_mode_type = serial_mode;
449 no_parallel = true;
450 }
451
452 /*
453 * Check whether stdout and stderr are physically same.
454 * This is in order to decide whether we need to redirect
455 * stderr separately from stdout.
456 * This check is performed only if __DMAKE_SEPARATE_STDERR
457 * is not set. This variable may be used in order to preserve
458 * the 'old' behaviour.
459 */
460 out_err_same = true;
461 char * dmake_sep_var = getenv("__DMAKE_SEPARATE_STDERR");
462 if (dmake_sep_var == NULL || (0 != strcasecmp(dmake_sep_var, "NO"))) {
463 struct stat stdout_stat;
464 struct stat stderr_stat;
465 if( (fstat(1, &stdout_stat) == 0)
466 && (fstat(2, &stderr_stat) == 0) )
467 {
468 if( (stdout_stat.st_dev != stderr_stat.st_dev)
469 || (stdout_stat.st_ino != stderr_stat.st_ino) )
470 {
471 out_err_same = false;
472 }
473 }
474 }
475
476
477 /*
478 * Enable interrupt handler for alarms
479 */
480 (void) bsd_signal(SIGALRM, (SIG_PF)doalarm);
481
482 /*
574 * Called from exit(), performs cleanup actions.
575 *
576 * Parameters:
577 * status The argument exit() was called with
578 * arg Address of an argument vector to
579 * cleanup_after_exit()
580 *
581 * Global variables used:
582 * command_changed Set if we think .make.state should be rewritten
583 * current_line Is set we set commands_changed
584 * do_not_exec_rule
585 * True if -n flag on
586 * done The Name ".DONE", rule we run
587 * keep_state Set if .KEEP_STATE seen
588 * parallel True if building in parallel
589 * quest If -q is on we do not run .DONE
590 * report_dependencies
591 * True if -P flag on
592 * running_list List of parallel running processes
593 * temp_file_name The temp file is removed, if any
594 */
595 extern "C" void
596 cleanup_after_exit(void)
597 {
598 Running rp;
599
600 extern long getname_bytes_count;
601 extern long getname_names_count;
602 extern long getname_struct_count;
603 extern long freename_bytes_count;
604 extern long freename_names_count;
605 extern long freename_struct_count;
606 extern long other_alloc;
607
608 extern long env_alloc_num;
609 extern long env_alloc_bytes;
610
611
612 #ifdef DMAKE_STATISTICS
613 if(getname_stat) {
614 printf(">>> Getname statistics:\n");
615 printf(" Allocated:\n");
616 printf(" Names: %ld\n", getname_names_count);
617 printf(" Strings: %ld Kb (%ld bytes)\n", getname_bytes_count/1000, getname_bytes_count);
618 printf(" Structs: %ld Kb (%ld bytes)\n", getname_struct_count/1000, getname_struct_count);
619 printf(" Total bytes: %ld Kb (%ld bytes)\n", getname_struct_count/1000 + getname_bytes_count/1000, getname_struct_count + getname_bytes_count);
620
621 printf("\n Unallocated: %ld\n", freename_names_count);
622 printf(" Names: %ld\n", freename_names_count);
623 printf(" Strings: %ld Kb (%ld bytes)\n", freename_bytes_count/1000, freename_bytes_count);
624 printf(" Structs: %ld Kb (%ld bytes)\n", freename_struct_count/1000, freename_struct_count);
625 printf(" Total bytes: %ld Kb (%ld bytes)\n", freename_struct_count/1000 + freename_bytes_count/1000, freename_struct_count + freename_bytes_count);
626
627 printf("\n Total used: %ld Kb (%ld bytes)\n", (getname_struct_count/1000 + getname_bytes_count/1000) - (freename_struct_count/1000 + freename_bytes_count/1000), (getname_struct_count + getname_bytes_count) - (freename_struct_count + freename_bytes_count));
628
629 printf("\n>>> Other:\n");
630 printf(
631 " Env (%ld): %ld Kb (%ld bytes)\n",
632 env_alloc_num,
633 env_alloc_bytes/1000,
634 env_alloc_bytes
635 );
636
637 }
638 #endif
639
640 parallel = false;
641 /* If we used the SVR4_MAKE, don't build .DONE or .FAILED */
642 if (!getenv(USE_SVR4_MAKE)){
643 /* Build the target .DONE or .FAILED if we caught an error */
644 if (!quest && !list_all_targets) {
645 Name failed_name;
646
647 MBSTOWCS(wcs_buffer, ".FAILED");
648 failed_name = GETNAME(wcs_buffer, FIND_LENGTH);
649 if ((exit_status != 0) && (failed_name->prop != NULL)) {
650 /*
651 * [tolik] switch DMake to serial mode
652 */
653 dmake_mode_type = serial_mode;
654 no_parallel = true;
655 (void) doname(failed_name, false, true);
656 } else {
657 if (!trace_status) {
658 /*
659 * Switch DMake to serial mode
660 */
661 dmake_mode_type = serial_mode;
662 no_parallel = true;
663 (void) doname(done, false, true);
664 }
665 }
666 }
667 }
701 command_changed = true;
702 /*
703 line = get_prop(rp->target->prop, line_prop);
704 if (line != NULL) {
705 line->body.line.command_used = NULL;
706 }
707 */
708 }
709 /* Remove the statefile lock file if the file has been locked */
710 if ((make_state_lockfile != NULL) && (make_state_locked)) {
711 (void) unlink(make_state_lockfile);
712 make_state_lockfile = NULL;
713 make_state_locked = false;
714 }
715 /* Write .make.state */
716 write_state_file(1, (Boolean) 1);
717
718 #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
719 job_adjust_fini();
720 #endif
721 }
722
723 /*
724 * handle_interrupt()
725 *
726 * This is where C-C traps are caught.
727 *
728 * Parameters:
729 *
730 * Global variables used (except DMake 1.0):
731 * current_target Sometimes the current target is removed
732 * do_not_exec_rule But not if -n is on
733 * quest or -q
734 * running_list List of parallel running processes
735 * touch Current target is not removed if -t on
736 */
737 void
738 handle_interrupt(int)
739 {
740 Property member;
769 current_target->is_member &&
770 ((member = get_prop(current_target->prop, member_prop)) != NULL)) {
771 current_target = member->body.member.library;
772 }
773 if (!do_not_exec_rule &&
774 !touch &&
775 !quest &&
776 (current_target != NULL) &&
777 !(current_target->stat.is_precious || all_precious)) {
778
779 /* BID_1030811 */
780 /* azv 16 Oct 95 */
781 current_target->stat.time = file_no_time;
782
783 if (exists(current_target) != file_doesnt_exist) {
784 (void) fprintf(stderr,
785 "\n*** %s ",
786 current_target->string_mb);
787 if (current_target->stat.is_dir) {
788 (void) fprintf(stderr,
789 gettext("not removed.\n"),
790 current_target->string_mb);
791 } else if (unlink(current_target->string_mb) == 0) {
792 (void) fprintf(stderr,
793 gettext("removed.\n"),
794 current_target->string_mb);
795 } else {
796 (void) fprintf(stderr,
797 gettext("could not be removed: %s.\n"),
798 current_target->string_mb,
799 errmsg(errno));
800 }
801 }
802 }
803 for (rp = running_list; rp != NULL; rp = rp->next) {
804 if (rp->state != build_running) {
805 continue;
806 }
807 if (rp->target->is_member &&
808 ((member = get_prop(rp->target->prop, member_prop)) !=
809 NULL)) {
810 rp->target = member->body.member.library;
811 }
812 if (!do_not_exec_rule &&
813 !touch &&
814 !quest &&
815 !(rp->target->stat.is_precious || all_precious)) {
816
817 rp->target->stat.time = file_no_time;
818 if (exists(rp->target) != file_doesnt_exist) {
819 (void) fprintf(stderr,
820 "\n*** %s ",
821 rp->target->string_mb);
822 if (rp->target->stat.is_dir) {
823 (void) fprintf(stderr,
824 gettext("not removed.\n"),
825 rp->target->string_mb);
826 } else if (unlink(rp->target->string_mb) == 0) {
827 (void) fprintf(stderr,
828 gettext("removed.\n"),
829 rp->target->string_mb);
830 } else {
831 (void) fprintf(stderr,
832 gettext("could not be removed: %s.\n"),
833 rp->target->string_mb,
834 errmsg(errno));
835 }
836 }
837 }
838 }
839
840
841 /* Have we locked .make.state or .nse_depinfo? */
842 if ((make_state_lockfile != NULL) && (make_state_locked)) {
843 unlink(make_state_lockfile);
844 make_state_lockfile = NULL;
845 make_state_locked = false;
846 }
847 /*
848 * Re-read .make.state file (it might be changed by recursive make)
849 */
850 check_state(NULL);
851
852 report_dir_enter_leave(false);
972 /* Eliminate first hyphen character */
973 for (j=0; argv[i][j] != '\0'; j++) {
974 argv[i][j] = argv[i][j+1];
975 }
976
977 /* Repeat the processing of this argument */
978 optind=last_optind;
979 current_optind=last_current_optind;
980 continue;
981 }
982 }
983 }
984 }
985 }
986 }
987 }
988
989 if (ch == '?') {
990 if (svr4) {
991 fprintf(stderr,
992 gettext("Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
993 fprintf(stderr,
994 gettext(" [ -j dmake_max_jobs ][ -m dmake_mode ][ -o dmake_odir ]...\n"));
995 fprintf(stderr,
996 gettext(" [ -e ][ -i ][ -k ][ -n ][ -p ][ -q ][ -r ][ -s ][ -t ][ -v ]\n"));
997 tptr = strchr(SVR4_CMD_OPTS, optopt);
998 } else {
999 fprintf(stderr,
1000 gettext("Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1001 fprintf(stderr,
1002 gettext(" [ -j dmake_max_jobs ][ -K statefile ][ -m dmake_mode ][ -x MODE_NAME=VALUE ][ -o dmake_odir ]...\n"));
1003 fprintf(stderr,
1004 gettext(" [ -d ][ -dd ][ -D ][ -DD ][ -e ][ -i ][ -k ][ -n ][ -p ][ -P ][ -u ][ -w ]\n"));
1005 fprintf(stderr,
1006 gettext(" [ -q ][ -r ][ -s ][ -S ][ -t ][ -v ][ -V ][ target... ][ macro=value... ][ \"macro +=value\"... ]\n"));
1007 tptr = strchr(SUNPRO_CMD_OPTS, optopt);
1008 }
1009 if (!tptr) {
1010 fatal(gettext("Unknown option `-%c'"), optopt);
1011 } else {
1012 fatal(gettext("Missing argument after `-%c'"), optopt);
1013 }
1014 }
1015
1016
1017
1018 makefile_next |= parse_command_option(ch);
1019 /*
1020 * If we're done processing all of the options of
1021 * ONE argument string...
1022 */
1023 if (current_optind < optind) {
1024 i = current_optind;
1025 k = 0;
1026 /* If there's an argument for an option... */
1027 if ((optind - current_optind) > 1) {
1028 k = i + 1;
1029 }
1030 switch (makefile_next) {
1031 case 0:
1032 argv[i] = NULL;
1033 /* This shouldn't happen */
1034 if (k) {
1035 argv[k] = NULL;
1036 }
1037 break;
1038 case 1: /* -f seen */
1039 argv[i] = (char *)"-f";
1040 break;
1041 case 2: /* -c seen */
1042 argv[i] = (char *)"-c";
1043 break;
1044 case 4: /* -g seen */
1045 argv[i] = (char *)"-g";
1046 break;
1047 case 8: /* -j seen */
1048 argv[i] = (char *)"-j";
1049 break;
1050 case 16: /* -M seen */
1051 argv[i] = (char *)"-M";
1052 break;
1053 case 32: /* -m seen */
1054 argv[i] = (char *)"-m";
1055 break;
1056 case 128: /* -O seen */
1057 argv[i] = (char *)"-O";
1058 break;
1059 case 256: /* -K seen */
1060 argv[i] = (char *)"-K";
1061 break;
1062 case 512: /* -o seen */
1063 argv[i] = (char *)"-o";
1064 break;
1065 case 1024: /* -x seen */
1066 argv[i] = (char *)"-x";
1067 break;
1068 default: /* > 1 of -c, f, g, j, K, M, m, O, o, x seen */
1069 fatal(gettext("Illegal command line. More than one option requiring\nan argument given in the same argument group"));
1070 }
1071
1072 makefile_next = 0;
1073 current_optind = optind;
1074 }
1075 }
1076 }
1077
1078 static void
1079 quote_str(char *str, char *qstr)
1080 {
1081 char *to;
1082 char *from;
1083
1084 to = qstr;
1085 for (from = str; *from; from++) {
1086 switch (*from) {
1087 case ';': /* End of command */
1088 case '(': /* Start group */
1089 case ')': /* End group */
1199 /* Find the number of arguments in MAKEFLAGS */
1200 while (cp && *cp) {
1201 /* Skip white spaces */
1202 while (cp && *cp && isspace(*cp)) {
1203 cp++;
1204 }
1205 if (cp && *cp) {
1206 /* Increment arg count */
1207 mf_argc++;
1208 /* Go to next white space */
1209 while (cp && *cp && !isspace(*cp)) {
1210 if(*cp == (int) backslash_char) {
1211 cp++;
1212 }
1213 cp++;
1214 }
1215 }
1216 }
1217 /* Allocate memory for the new MAKEFLAGS argv */
1218 mf_argv = (char **) malloc((mf_argc + 1) * sizeof(char *));
1219 mf_argv[0] = (char *)"MAKEFLAGS";
1220 /*
1221 * Convert the MAKEFLAGS string value into a vector of char *,
1222 * similar to argv.
1223 */
1224 cp = cp_orig;
1225 for (i = 1; i < mf_argc; i++) {
1226 /* Skip white spaces */
1227 while (cp && *cp && isspace(*cp)) {
1228 cp++;
1229 }
1230 if (cp && *cp) {
1231 cp_orig = cp;
1232 /* Go to next white space */
1233 while (cp && *cp && !isspace(*cp)) {
1234 if(*cp == (int) backslash_char) {
1235 cp++;
1236 }
1237 cp++;
1238 }
1239 tmp_char = *cp;
1486 case 't': /* Touch flag */
1487 if (invert_this) {
1488 touch = false;
1489 } else {
1490 touch = true;
1491 }
1492 return 0;
1493 case 'u': /* Unconditional flag */
1494 if (invert_this) {
1495 build_unconditional = false;
1496 } else {
1497 build_unconditional = true;
1498 }
1499 return 0;
1500 case 'V': /* SVR4 mode */
1501 svr4 = true;
1502 return 0;
1503 case 'v': /* Version flag */
1504 if (invert_this) {
1505 } else {
1506 fprintf(stdout, "dmake: %s\n", verstring);
1507 exit_status = 0;
1508 exit(0);
1509 }
1510 return 0;
1511 case 'w': /* Unconditional flag */
1512 if (invert_this) {
1513 report_cwd = false;
1514 } else {
1515 report_cwd = true;
1516 }
1517 return 0;
1518 #if 0
1519 case 'X': /* Filter stdout */
1520 if (invert_this) {
1521 filter_stderr = false;
1522 } else {
1523 filter_stderr = true;
1524 }
1525 return 0;
1526 #endif
1532
1533 /*
1534 * setup_for_projectdir()
1535 *
1536 * Read the PROJECTDIR variable, if defined, and set the sccs path
1537 *
1538 * Parameters:
1539 *
1540 * Global variables used:
1541 * sccs_dir_path Set to point to SCCS dir to use
1542 */
1543 static void
1544 setup_for_projectdir(void)
1545 {
1546 static char path[MAXPATHLEN];
1547 char cwdpath[MAXPATHLEN];
1548 uid_t uid;
1549 int done=0;
1550
1551 /* Check if we should use PROJECTDIR when reading the SCCS dir. */
1552 sccs_dir_path = getenv("PROJECTDIR");
1553 if ((sccs_dir_path != NULL) &&
1554 (sccs_dir_path[0] != (int) slash_char)) {
1555 struct passwd *pwent;
1556
1557 {
1558 uid = getuid();
1559 pwent = getpwuid(uid);
1560 if (pwent == NULL) {
1561 fatal(gettext("Bogus USERID "));
1562 }
1563 if ((pwent = getpwnam(sccs_dir_path)) == NULL) {
1564 /*empty block : it'll go & check cwd */
1565 }
1566 else {
1567 (void) sprintf(path, "%s/src", pwent->pw_dir);
1568 if (access(path, F_OK) == 0) {
1569 sccs_dir_path = path;
1570 done = 1;
1571 } else {
1572 (void) sprintf(path, "%s/source", pwent->pw_dir);
1573 if (access(path, F_OK) == 0) {
1574 sccs_dir_path = path;
1575 done = 1;
1576 }
1577 }
1578 }
1579 if (!done) {
1580 if (getcwd(cwdpath, MAXPATHLEN - 1 )) {
1581
1582 (void) sprintf(path, "%s/%s", cwdpath,sccs_dir_path);
1583 if (access(path, F_OK) == 0) {
1584 sccs_dir_path = path;
1585 done = 1;
1586 } else {
1587 fatal(gettext("Bogus PROJECTDIR '%s'"), sccs_dir_path);
1588 }
1589 }
1590 }
1591 }
1592 }
1593 }
1594
1595 char *
1596 make_install_prefix(void)
1597 {
1598 int ret;
1599 char origin[PATH_MAX];
1600 char *dir;
1601
1602 if ((ret = readlink("/proc/self/path/a.out", origin,
1603 PATH_MAX - 1)) < 0)
1604 fatal("failed to read origin from /proc\n");
1605
1606
1607 origin[ret] = '\0';
1769 Name new_make_value;
1770 Boolean save_do_not_exec_rule;
1771 Name sdotMakefile;
1772 Name sdotmakefile_name;
1773 static wchar_t state_file_str;
1774 static char state_file_str_mb[MAXPATHLEN];
1775 static struct _Name state_filename;
1776 Boolean temp;
1777 char tmp_char;
1778 wchar_t *tmp_wcs_buffer;
1779 register Name value;
1780 ASCII_Dyn_Array makeflags_and_macro;
1781 Boolean is_xpg4;
1782
1783 /*
1784 * Remember current mode. It may be changed after reading makefile
1785 * and we will have to correct MAKEFLAGS variable.
1786 */
1787 is_xpg4 = posix;
1788
1789 MBSTOWCS(wcs_buffer, "KEEP_STATE");
1790 keep_state_name = GETNAME(wcs_buffer, FIND_LENGTH);
1791 MBSTOWCS(wcs_buffer, "Makefile");
1792 Makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1793 MBSTOWCS(wcs_buffer, "makefile");
1794 makefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
1795 MBSTOWCS(wcs_buffer, "s.makefile");
1796 sdotmakefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
1797 MBSTOWCS(wcs_buffer, "s.Makefile");
1798 sdotMakefile = GETNAME(wcs_buffer, FIND_LENGTH);
1799
1800 /*
1801 * initialize global dependency entry for .NOT_AUTO
1802 */
1803 not_auto_depen->next = NULL;
1804 not_auto_depen->name = not_auto;
1805 not_auto_depen->automatic = not_auto_depen->stale = false;
1806
1807 /*
1808 * Read internal definitions and rules.
1809 */
1810 if (read_trace_level > 1) {
1811 trace_reader = true;
1812 }
1813 if (!ignore_default_mk) {
1814 if (svr4) {
1815 MBSTOWCS(wcs_buffer, "svr4.make.rules");
1816 default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1817 } else {
1818 MBSTOWCS(wcs_buffer, "make.rules");
1819 default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1820 }
1821 default_makefile->stat.is_file = true;
1822
1823 (void) read_makefile(default_makefile,
1824 true,
1825 false,
1826 true);
1827 }
1828
1829 /*
1830 * If the user did not redefine the MAKE macro in the
1831 * default makefile (make.rules), then we'd like to
1832 * change the macro value of MAKE to be some form
1833 * of argv[0] for recursive MAKE builds.
1834 */
1835 MBSTOWCS(wcs_buffer, "MAKE");
1836 def_make_name = GETNAME(wcs_buffer, wslen(wcs_buffer));
1837 def_make_macro = get_prop(def_make_name->prop, macro_prop);
1838 if ((def_make_macro != NULL) &&
1839 (IS_EQUAL(def_make_macro->body.macro.value->string_mb,
1840 "make"))) {
1841 MBSTOWCS(wcs_buffer, argv_zero_string);
1842 new_make_value = GETNAME(wcs_buffer, wslen(wcs_buffer));
1843 (void) SETVAR(def_make_name,
1844 new_make_value,
1845 false);
1846 }
1847
1848 default_target_to_build = NULL;
1849 trace_reader = false;
1850
1851 /*
1852 * Read environment args. Let file args which follow override unless
1853 * -e option seen. If -e option is not mentioned.
1854 */
1855 read_environment(env_wins);
1856 if (getvar(virtual_root)->hash.length == 0) {
1857 maybe_append_prop(virtual_root, macro_prop)
1858 ->body.macro.exported = true;
1859 MBSTOWCS(wcs_buffer, "/");
1860 (void) SETVAR(virtual_root,
1952 append_char('q', &makeflags_string_posix);
1953 }
1954 if (silent_all) {
1955 append_char('s', &makeflags_string);
1956 append_char('s', &makeflags_string_posix);
1957 }
1958 if (touch) {
1959 append_char('t', &makeflags_string);
1960 append_char('t', &makeflags_string_posix);
1961 }
1962 if (build_unconditional) {
1963 append_char('u', &makeflags_string);
1964 append_char('u', &makeflags_string_posix);
1965 }
1966 if (report_cwd) {
1967 append_char('w', &makeflags_string);
1968 append_char('w', &makeflags_string_posix);
1969 }
1970 /* -c dmake_rcfile */
1971 if (dmake_rcfile_specified) {
1972 MBSTOWCS(wcs_buffer, "DMAKE_RCFILE");
1973 dmake_rcfile = GETNAME(wcs_buffer, FIND_LENGTH);
1974 append_makeflags_string(dmake_rcfile, &makeflags_string);
1975 append_makeflags_string(dmake_rcfile, &makeflags_string_posix);
1976 }
1977 /* -g dmake_group */
1978 if (dmake_group_specified) {
1979 MBSTOWCS(wcs_buffer, "DMAKE_GROUP");
1980 dmake_group = GETNAME(wcs_buffer, FIND_LENGTH);
1981 append_makeflags_string(dmake_group, &makeflags_string);
1982 append_makeflags_string(dmake_group, &makeflags_string_posix);
1983 }
1984 /* -j dmake_max_jobs */
1985 if (dmake_max_jobs_specified) {
1986 MBSTOWCS(wcs_buffer, "DMAKE_MAX_JOBS");
1987 dmake_max_jobs = GETNAME(wcs_buffer, FIND_LENGTH);
1988 append_makeflags_string(dmake_max_jobs, &makeflags_string);
1989 append_makeflags_string(dmake_max_jobs, &makeflags_string_posix);
1990 }
1991 /* -m dmake_mode */
1992 if (dmake_mode_specified) {
1993 MBSTOWCS(wcs_buffer, "DMAKE_MODE");
1994 dmake_mode = GETNAME(wcs_buffer, FIND_LENGTH);
1995 append_makeflags_string(dmake_mode, &makeflags_string);
1996 append_makeflags_string(dmake_mode, &makeflags_string_posix);
1997 }
1998 /* -x dmake_compat_mode */
1999 // if (dmake_compat_mode_specified) {
2000 // MBSTOWCS(wcs_buffer, "SUN_MAKE_COMPAT_MODE");
2001 // dmake_compat_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2002 // append_makeflags_string(dmake_compat_mode, &makeflags_string);
2003 // append_makeflags_string(dmake_compat_mode, &makeflags_string_posix);
2004 // }
2005 /* -x dmake_output_mode */
2006 if (dmake_output_mode_specified) {
2007 MBSTOWCS(wcs_buffer, "DMAKE_OUTPUT_MODE");
2008 dmake_output_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2009 append_makeflags_string(dmake_output_mode, &makeflags_string);
2010 append_makeflags_string(dmake_output_mode, &makeflags_string_posix);
2011 }
2012 /* -o dmake_odir */
2013 if (dmake_odir_specified) {
2014 MBSTOWCS(wcs_buffer, "DMAKE_ODIR");
2015 dmake_odir = GETNAME(wcs_buffer, FIND_LENGTH);
2016 append_makeflags_string(dmake_odir, &makeflags_string);
2017 append_makeflags_string(dmake_odir, &makeflags_string_posix);
2018 }
2019 /* -M pmake_machinesfile */
2020 if (pmake_machinesfile_specified) {
2021 MBSTOWCS(wcs_buffer, "PMAKE_MACHINESFILE");
2022 pmake_machinesfile = GETNAME(wcs_buffer, FIND_LENGTH);
2023 append_makeflags_string(pmake_machinesfile, &makeflags_string);
2024 append_makeflags_string(pmake_machinesfile, &makeflags_string_posix);
2025 }
2026 /* -R */
2027 if (pmake_cap_r_specified) {
2028 append_char((int) space_char, &makeflags_string);
2029 append_char((int) hyphen_char, &makeflags_string);
2030 append_char('R', &makeflags_string);
2031 append_char((int) space_char, &makeflags_string_posix);
2032 append_char((int) hyphen_char, &makeflags_string_posix);
2033 append_char('R', &makeflags_string_posix);
2034 }
2035
2036 /*
2037 * Make sure MAKEFLAGS is exported
2038 */
2039 maybe_append_prop(makeflags, macro_prop)->
2040 body.macro.exported = true;
2041
2042 if (makeflags_string.buffer.start[1] != (int) nul_char) {
2043 if (makeflags_string.buffer.start[1] != (int) space_char) {
2044 MBSTOWCS(wcs_buffer, "MFLAGS");
2045 (void) SETVAR(GETNAME(wcs_buffer, FIND_LENGTH),
2046 GETNAME(makeflags_string.buffer.start,
2047 FIND_LENGTH),
2048 false);
2049 } else {
2050 MBSTOWCS(wcs_buffer, "MFLAGS");
2051 (void) SETVAR(GETNAME(wcs_buffer, FIND_LENGTH),
2052 GETNAME(makeflags_string.buffer.start + 2,
2053 FIND_LENGTH),
2054 false);
2055 }
2056 }
2057
2058 /*
2059 * Add command line macro to POSIX makeflags_string
2060 */
2061 if (makeflags_and_macro.start) {
2062 tmp_char = (char) space_char;
2063 cp = makeflags_and_macro.start;
2064 do {
2065 append_char(tmp_char, &makeflags_string_posix);
2066 } while ( tmp_char = *cp++ );
2067 retmem_mb(makeflags_and_macro.start);
2068 }
2069
2070 /*
2102 , false
2103 );
2104 macro->body.macro.read_only = temp;
2105
2106 /*
2107 * Read command line "-f" arguments and ignore -c, g, j, K, M, m, O and o args.
2108 */
2109 save_do_not_exec_rule = do_not_exec_rule;
2110 do_not_exec_rule = false;
2111 if (read_trace_level > 0) {
2112 trace_reader = true;
2113 }
2114
2115 for (i = 1; i < argc; i++) {
2116 if (argv[i] &&
2117 (argv[i][0] == (int) hyphen_char) &&
2118 (argv[i][1] == 'f') &&
2119 (argv[i][2] == (int) nul_char)) {
2120 argv[i] = NULL; /* Remove -f */
2121 if (i >= argc - 1) {
2122 fatal(gettext("No filename argument after -f flag"));
2123 }
2124 MBSTOWCS(wcs_buffer, argv[++i]);
2125 primary_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
2126 (void) read_makefile(primary_makefile, true, true, true);
2127 argv[i] = NULL; /* Remove filename */
2128 makefile_read = true;
2129 } else if (argv[i] &&
2130 (argv[i][0] == (int) hyphen_char) &&
2131 (argv[i][1] == 'c' ||
2132 argv[i][1] == 'g' ||
2133 argv[i][1] == 'j' ||
2134 argv[i][1] == 'K' ||
2135 argv[i][1] == 'M' ||
2136 argv[i][1] == 'm' ||
2137 argv[i][1] == 'O' ||
2138 argv[i][1] == 'o') &&
2139 (argv[i][2] == (int) nul_char)) {
2140 argv[i] = NULL;
2141 argv[++i] = NULL;
2142 }
2143 }
2144
2145 /*
2146 * If no command line "-f" args then look for "makefile", and then for
2147 * "Makefile" if "makefile" isn't found.
2148 */
2149 if (!makefile_read) {
2150 (void) read_dir(dot,
2151 (wchar_t *) NULL,
2152 (Property) NULL,
2153 (wchar_t *) NULL);
2154 if (!posix) {
2155 if (makefile_name->stat.is_file) {
2156 if (Makefile->stat.is_file) {
2157 warning(gettext("Both `makefile' and `Makefile' exist"));
2158 }
2159 primary_makefile = makefile_name;
2160 makefile_read = read_makefile(makefile_name,
2161 false,
2162 false,
2163 true);
2164 }
2165 if (!makefile_read &&
2166 Makefile->stat.is_file) {
2167 primary_makefile = Makefile;
2168 makefile_read = read_makefile(Makefile,
2169 false,
2170 false,
2171 true);
2172 }
2173 } else {
2174
2175 enum sccs_stat save_m_has_sccs = NO_SCCS;
2176 enum sccs_stat save_M_has_sccs = NO_SCCS;
2177
2178 if (makefile_name->stat.is_file) {
2179 if (Makefile->stat.is_file) {
2180 warning(gettext("Both `makefile' and `Makefile' exist"));
2181 }
2182 }
2183 if (makefile_name->stat.is_file) {
2184 if (makefile_name->stat.has_sccs == NO_SCCS) {
2185 primary_makefile = makefile_name;
2186 makefile_read = read_makefile(makefile_name,
2187 false,
2188 false,
2189 true);
2190 } else {
2191 save_m_has_sccs = makefile_name->stat.has_sccs;
2192 makefile_name->stat.has_sccs = NO_SCCS;
2193 primary_makefile = makefile_name;
2194 makefile_read = read_makefile(makefile_name,
2195 false,
2196 false,
2197 true);
2198 }
2199 }
2200 if (!makefile_read &&
2270 }
2271 }
2272 }
2273
2274 if (makeflags_string.free_after_use) {
2275 retmem(makeflags_string.buffer.start);
2276 }
2277 if (makeflags_string_posix.free_after_use) {
2278 retmem(makeflags_string_posix.buffer.start);
2279 }
2280 makeflags_string.buffer.start = NULL;
2281 makeflags_string_posix.buffer.start = NULL;
2282
2283 if (posix) {
2284 /*
2285 * If the user did not redefine the ARFLAGS macro in the
2286 * default makefile (make.rules), then we'd like to
2287 * change the macro value of ARFLAGS to be in accordance
2288 * with "POSIX" requirements.
2289 */
2290 MBSTOWCS(wcs_buffer, "ARFLAGS");
2291 name = GETNAME(wcs_buffer, wslen(wcs_buffer));
2292 macro = get_prop(name->prop, macro_prop);
2293 if ((macro != NULL) && /* Maybe (macro == NULL) || ? */
2294 (IS_EQUAL(macro->body.macro.value->string_mb,
2295 "rv"))) {
2296 MBSTOWCS(wcs_buffer, "-rv");
2297 value = GETNAME(wcs_buffer, wslen(wcs_buffer));
2298 (void) SETVAR(name,
2299 value,
2300 false);
2301 }
2302 }
2303
2304 if (!posix && !svr4) {
2305 set_sgs_support();
2306 }
2307
2308
2309 /*
2310 * Make sure KEEP_STATE is in the environment if KEEP_STATE is on.
2311 */
2312 macro = get_prop(keep_state_name->prop, macro_prop);
2313 if ((macro != NULL) &&
2314 macro->body.macro.exported) {
2315 keep_state = true;
2316 }
2336 */
2337 INIT_STRING_FROM_STACK(dest, destbuffer);
2338 expand_value(make_state, &dest, false);
2339
2340 make_state = GETNAME(dest.buffer.start, FIND_LENGTH);
2341
2342 if(!stat(make_state->string_mb, &make_state_stat)) {
2343 if(!(make_state_stat.st_mode & S_IFREG) ) {
2344 /* copy the make_state structure to the other
2345 ** and then let make_state point to the new
2346 ** one.
2347 */
2348 memcpy(&state_filename, make_state,sizeof(state_filename));
2349 state_filename.string_mb = state_file_str_mb;
2350 /* Just a kludge to avoid two slashes back to back */
2351 if((make_state->hash.length == 1)&&
2352 (make_state->string_mb[0] == '/')) {
2353 make_state->hash.length = 0;
2354 make_state->string_mb[0] = '\0';
2355 }
2356 sprintf(state_file_str_mb,"%s%s",
2357 make_state->string_mb,"/.make.state");
2358 make_state = &state_filename;
2359 /* adjust the length to reflect the appended string */
2360 make_state->hash.length += 12;
2361 }
2362 } else { /* the file doesn't exist or no permission */
2363 char tmp_path[MAXPATHLEN];
2364 char *slashp;
2365
2366 if (slashp = strrchr(make_state->string_mb, '/')) {
2367 strncpy(tmp_path, make_state->string_mb,
2368 (slashp - make_state->string_mb));
2369 tmp_path[slashp - make_state->string_mb]=0;
2370 if(strlen(tmp_path)) {
2371 if(stat(tmp_path, &make_state_stat)) {
2372 warning(gettext("directory %s for .KEEP_STATE_FILE does not exist"),tmp_path);
2373 }
2374 if (access(tmp_path, F_OK) != 0) {
2375 warning(gettext("can't access dir %s"),tmp_path);
2376 }
2377 }
2378 }
2379 }
2380 if (report_dependencies_level != 1) {
2381 Makefile_type makefile_type_temp = makefile_type;
2382 makefile_type = reading_statefile;
2383 if (read_trace_level > 1) {
2384 trace_reader = true;
2385 }
2386 (void) read_simple_file(make_state,
2387 false,
2388 false,
2389 false,
2390 false,
2391 false,
2392 true);
2393 trace_reader = false;
2394 makefile_type = makefile_type_temp;
2395 }
2419 makefile_type = reading_nothing;
2420 for (i = 1; i < argc; ++i) {
2421 append = false;
2422 if (argv[i] == NULL) {
2423 continue;
2424 } else if (((argv[i][0] == '-') && (argv[i][1] == '-')) ||
2425 ((argv[i][0] == (int) ' ') &&
2426 (argv[i][1] == (int) '-') &&
2427 (argv[i][2] == (int) ' ') &&
2428 (argv[i][3] == (int) '-'))) {
2429 argv[i] = NULL;
2430 opt_separator = i;
2431 continue;
2432 } else if ((i < opt_separator) && (argv[i][0] == (int) hyphen_char)) {
2433 switch (parse_command_option(argv[i][1])) {
2434 case 1: /* -f seen */
2435 ++i;
2436 continue;
2437 case 2: /* -c seen */
2438 if (argv[i+1] == NULL) {
2439 fatal(gettext("No dmake rcfile argument after -c flag"));
2440 }
2441 MBSTOWCS(wcs_buffer, "DMAKE_RCFILE");
2442 name = GETNAME(wcs_buffer, FIND_LENGTH);
2443 break;
2444 case 4: /* -g seen */
2445 if (argv[i+1] == NULL) {
2446 fatal(gettext("No dmake group argument after -g flag"));
2447 }
2448 MBSTOWCS(wcs_buffer, "DMAKE_GROUP");
2449 name = GETNAME(wcs_buffer, FIND_LENGTH);
2450 break;
2451 case 8: /* -j seen */
2452 if (argv[i+1] == NULL) {
2453 fatal(gettext("No dmake max jobs argument after -j flag"));
2454 }
2455 MBSTOWCS(wcs_buffer, "DMAKE_MAX_JOBS");
2456 name = GETNAME(wcs_buffer, FIND_LENGTH);
2457 break;
2458 case 16: /* -M seen */
2459 if (argv[i+1] == NULL) {
2460 fatal(gettext("No pmake machinesfile argument after -M flag"));
2461 }
2462 MBSTOWCS(wcs_buffer, "PMAKE_MACHINESFILE");
2463 name = GETNAME(wcs_buffer, FIND_LENGTH);
2464 break;
2465 case 32: /* -m seen */
2466 if (argv[i+1] == NULL) {
2467 fatal(gettext("No dmake mode argument after -m flag"));
2468 }
2469 MBSTOWCS(wcs_buffer, "DMAKE_MODE");
2470 name = GETNAME(wcs_buffer, FIND_LENGTH);
2471 break;
2472 case 256: /* -K seen */
2473 if (argv[i+1] == NULL) {
2474 fatal(gettext("No makestate filename argument after -K flag"));
2475 }
2476 MBSTOWCS(wcs_buffer, argv[i+1]);
2477 make_state = GETNAME(wcs_buffer, FIND_LENGTH);
2478 keep_state = true;
2479 argv[i] = NULL;
2480 argv[i+1] = NULL;
2481 continue;
2482 case 512: /* -o seen */
2483 if (argv[i+1] == NULL) {
2484 fatal(gettext("No dmake output dir argument after -o flag"));
2485 }
2486 MBSTOWCS(wcs_buffer, "DMAKE_ODIR");
2487 name = GETNAME(wcs_buffer, FIND_LENGTH);
2488 break;
2489 case 1024: /* -x seen */
2490 if (argv[i+1] == NULL) {
2491 fatal(gettext("No argument after -x flag"));
2492 }
2493 length = strlen( "SUN_MAKE_COMPAT_MODE=");
2494 if (strncmp(argv[i+1], "SUN_MAKE_COMPAT_MODE=", length) == 0) {
2495 argv[i+1] = &argv[i+1][length];
2496 MBSTOWCS(wcs_buffer, "SUN_MAKE_COMPAT_MODE");
2497 name = GETNAME(wcs_buffer, FIND_LENGTH);
2498 dmake_compat_mode_specified = dmake_add_mode_specified;
2499 break;
2500 }
2501 length = strlen( "DMAKE_OUTPUT_MODE=");
2502 if (strncmp(argv[i+1], "DMAKE_OUTPUT_MODE=", length) == 0) {
2503 argv[i+1] = &argv[i+1][length];
2504 MBSTOWCS(wcs_buffer, "DMAKE_OUTPUT_MODE");
2505 name = GETNAME(wcs_buffer, FIND_LENGTH);
2506 dmake_output_mode_specified = dmake_add_mode_specified;
2507 } else {
2508 warning(gettext("Unknown argument `%s' after -x flag (ignored)"),
2509 argv[i+1]);
2510 argv[i] = argv[i + 1] = NULL;
2511 continue;
2512 }
2513 break;
2514 default: /* Shouldn't reach here */
2515 argv[i] = NULL;
2516 continue;
2517 }
2518 argv[i] = NULL;
2519 if (i == (argc - 1)) {
2520 break;
2521 }
2522 if ((length = strlen(argv[i+1])) >= MAXPATHLEN) {
2523 tmp_wcs_buffer = ALLOC_WC(length + 1);
2524 (void) mbstowcs(tmp_wcs_buffer, argv[i+1], length + 1);
2525 value = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
2526 retmem(tmp_wcs_buffer);
2527 } else {
2528 MBSTOWCS(wcs_buffer, argv[i+1]);
2574 }
2575 if(append) {
2576 setvar_append(name, value);
2577 append = false;
2578 } else {
2579 macro = maybe_append_prop(name, macro_prop);
2580 macro->body.macro.exported = true;
2581 SETVAR(name, value, false)->body.macro.read_only = true;
2582 }
2583 }
2584 }
2585
2586 /*
2587 * Append the DMake option and value to the MAKEFLAGS string.
2588 */
2589 static void
2590 append_makeflags_string(Name name, register String makeflags_string)
2591 {
2592 const char *option;
2593
2594 if (strcmp(name->string_mb, "DMAKE_GROUP") == 0) {
2595 option = " -g ";
2596 } else if (strcmp(name->string_mb, "DMAKE_MAX_JOBS") == 0) {
2597 option = " -j ";
2598 } else if (strcmp(name->string_mb, "DMAKE_MODE") == 0) {
2599 option = " -m ";
2600 } else if (strcmp(name->string_mb, "DMAKE_ODIR") == 0) {
2601 option = " -o ";
2602 } else if (strcmp(name->string_mb, "DMAKE_RCFILE") == 0) {
2603 option = " -c ";
2604 } else if (strcmp(name->string_mb, "PMAKE_MACHINESFILE") == 0) {
2605 option = " -M ";
2606 } else if (strcmp(name->string_mb, "DMAKE_OUTPUT_MODE") == 0) {
2607 option = " -x DMAKE_OUTPUT_MODE=";
2608 } else if (strcmp(name->string_mb, "SUN_MAKE_COMPAT_MODE") == 0) {
2609 option = " -x SUN_MAKE_COMPAT_MODE=";
2610 } else {
2611 fatal(gettext("Internal error: name not recognized in append_makeflags_string()"));
2612 }
2613 Property prop = maybe_append_prop(name, macro_prop);
2614 if( prop == 0 || prop->body.macro.value == 0 ||
2615 prop->body.macro.value->string_mb == 0 ) {
2616 return;
2617 }
2618 char mbs_value[MAXPATHLEN + 100];
2619 strcpy(mbs_value, option);
2620 strcat(mbs_value, prop->body.macro.value->string_mb);
2621 MBSTOWCS(wcs_buffer, mbs_value);
2622 append_string(wcs_buffer, makeflags_string, FIND_LENGTH);
2623 }
2624
2625 /*
2626 * read_environment(read_only)
2627 *
2628 * This routine reads the process environment when make starts and enters
2629 * it as make macros. The environment variable SHELL is ignored.
2630 *
2631 * Parameters:
2652 for (; *environment; environment++) {
2653 read_only_saved = read_only;
2654 if ((length = strlen(*environment)) >= MAXPATHLEN) {
2655 tmp_wcs_buffer = ALLOC_WC(length + 1);
2656 alloced_tmp_wcs_buffer = true;
2657 (void) mbstowcs(tmp_wcs_buffer, *environment, length + 1);
2658 name = tmp_wcs_buffer;
2659 } else {
2660 MBSTOWCS(wcs_buffer, *environment);
2661 name = wcs_buffer;
2662 }
2663 value = (wchar_t *) wschr(name, (int) equal_char);
2664
2665 /*
2666 * Looks like there's a bug in the system, but sometimes
2667 * you can get blank lines in *environment.
2668 */
2669 if (!value) {
2670 continue;
2671 }
2672 MBSTOWCS(wcs_buffer2, "SHELL=");
2673 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2674 continue;
2675 }
2676 MBSTOWCS(wcs_buffer2, "MAKEFLAGS=");
2677 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2678 report_pwd = true;
2679 /*
2680 * In POSIX mode we do not want MAKEFLAGS to be readonly.
2681 * If the MAKEFLAGS macro is subsequently set by the makefile,
2682 * it replaces the MAKEFLAGS variable currently found in the
2683 * environment.
2684 * See Assertion 50 in section 6.2.5.3 of standard P1003.3.2/D8.
2685 */
2686 if(posix) {
2687 read_only_saved = false;
2688 }
2689 }
2690
2691 /*
2692 * We ignore SUNPRO_DEPENDENCIES. This environment variable is
2693 * set by make and read by cpp which then writes info to
2694 * .make.dependency.xxx. When make is invoked by another make
2695 * (recursive make), we don't want to read this because then
2696 * the child make will end up writing to the parent
2697 * directory's .make.state and clobbering them.
2698 */
2699 MBSTOWCS(wcs_buffer2, "SUNPRO_DEPENDENCIES");
2700 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2701 continue;
2702 }
2703
2704 macro = GETNAME(name, value - name);
2705 maybe_append_prop(macro, macro_prop)->body.macro.exported =
2706 true;
2707 if ((value == NULL) || ((value + 1)[0] == (int) nul_char)) {
2708 val = setvar_daemon(macro,
2709 (Name) NULL,
2710 false, no_daemon, false, debug_level);
2711 } else {
2712 val = setvar_daemon(macro,
2713 GETNAME(value + 1, FIND_LENGTH),
2714 false, no_daemon, false, debug_level);
2715 }
2716 val->body.macro.read_only = read_only_saved;
2717 if (alloced_tmp_wcs_buffer) {
2718 retmem(tmp_wcs_buffer);
2719 alloced_tmp_wcs_buffer = false;
2827 * parallel, hold off the target processing
2828 * to preserve the order of the targets as they appeared
2829 * in command line.
2830 */
2831 if (!parallel_ok(default_target_to_build, false)
2832 && parallel_process_cnt > 0) {
2833 finish_running();
2834 }
2835 result = doname_check(default_target_to_build,
2836 true,
2837 false,
2838 false);
2839 gather_recursive_deps();
2840 if (/* !commands_done && */
2841 (result == build_ok) &&
2842 !quest &&
2843 (report_dependencies_level == 0) /* &&
2844 (exists(default_target_to_build) > file_doesnt_exist) */) {
2845 if (posix) {
2846 if (!commands_done) {
2847 (void) printf(gettext("`%s' is updated.\n"),
2848 default_target_to_build->string_mb);
2849 } else {
2850 if (no_action_was_taken) {
2851 (void) printf(gettext("`%s': no action was taken.\n"),
2852 default_target_to_build->string_mb);
2853 }
2854 }
2855 } else {
2856 default_target_to_build->stat.time = file_no_time;
2857 if (!commands_done &&
2858 (exists(default_target_to_build) > file_doesnt_exist)) {
2859 (void) printf(gettext("`%s' is up to date.\n"),
2860 default_target_to_build->string_mb);
2861 }
2862 }
2863 }
2864 }
2865 }
2866 /* Now wait for all of the targets to finish running */
2867 finish_running();
2868 // setjmp(jmpbuffer);
2869
2870 }
2871 for (i = 1; i < argc; i++) {
2872 if ((cp = argv[i]) != NULL) {
2873 target_to_make_found = true;
2874 if ((cp[0] == (int) period_char) &&
2875 (cp[1] == (int) slash_char)) {
2876 cp += 2;
2877 }
2878 if((cp[0] == (int) ' ') &&
2879 (cp[1] == (int) '-') &&
2881 (cp[3] == (int) '-')) {
2882 argv[i] = NULL;
2883 continue;
2884 }
2885 MBSTOWCS(wcs_buffer, cp);
2886 default_target_to_build = normalize_name(wcs_buffer, wslen(wcs_buffer));
2887 top_level_target = get_wstring(default_target_to_build->string_mb);
2888 report_recursion(default_target_to_build);
2889 commands_done = false;
2890 if (parallel) {
2891 result = (Doname) default_target_to_build->state;
2892 } else {
2893 result = doname_check(default_target_to_build,
2894 true,
2895 false,
2896 false);
2897 }
2898 gather_recursive_deps();
2899 if (build_failed_seen) {
2900 build_failed_ever_seen = true;
2901 warning(gettext("Target `%s' not remade because of errors"),
2902 default_target_to_build->string_mb);
2903 }
2904 build_failed_seen = false;
2905 if (report_dependencies_level > 0) {
2906 print_dependencies(default_target_to_build,
2907 get_prop(default_target_to_build->prop,
2908 line_prop));
2909 }
2910 default_target_to_build->stat.time =
2911 file_no_time;
2912 if (default_target_to_build->colon_splits > 0) {
2913 default_target_to_build->state =
2914 build_dont_know;
2915 }
2916 if (!parallel &&
2917 /* !commands_done && */
2918 (result == build_ok) &&
2919 !quest &&
2920 (report_dependencies_level == 0) /* &&
2921 (exists(default_target_to_build) > file_doesnt_exist) */) {
2922 if (posix) {
2923 if (!commands_done) {
2924 (void) printf(gettext("`%s' is updated.\n"),
2925 default_target_to_build->string_mb);
2926 } else {
2927 if (no_action_was_taken) {
2928 (void) printf(gettext("`%s': no action was taken.\n"),
2929 default_target_to_build->string_mb);
2930 }
2931 }
2932 } else {
2933 if (!commands_done &&
2934 (exists(default_target_to_build) > file_doesnt_exist)) {
2935 (void) printf(gettext("`%s' is up to date.\n"),
2936 default_target_to_build->string_mb);
2937 }
2938 }
2939 }
2940 }
2941 }
2942
2943 /*
2944 * If no file arguments have been encountered,
2945 * make the first name encountered that doesnt start with a dot
2946 */
2947 if (!target_to_make_found) {
2948 if (default_target_to_build == NULL) {
2949 fatal(gettext("No arguments to build"));
2950 }
2951 commands_done = false;
2952 top_level_target = get_wstring(default_target_to_build->string_mb);
2953 report_recursion(default_target_to_build);
2954
2955
2956 if (getenv("SPRO_EXPAND_ERRORS")){
2957 (void) printf("::(%s)\n",
2958 default_target_to_build->string_mb);
2959 }
2960
2961
2962 result = doname_parallel(default_target_to_build, true, false);
2963 gather_recursive_deps();
2964 if (build_failed_seen) {
2965 build_failed_ever_seen = true;
2966 warning(gettext("Target `%s' not remade because of errors"),
2967 default_target_to_build->string_mb);
2968 }
2969 build_failed_seen = false;
2970 if (report_dependencies_level > 0) {
2971 print_dependencies(default_target_to_build,
2972 get_prop(default_target_to_build->
2973 prop,
2974 line_prop));
2975 }
2976 default_target_to_build->stat.time = file_no_time;
2977 if (default_target_to_build->colon_splits > 0) {
2978 default_target_to_build->state = build_dont_know;
2979 }
2980 if (/* !commands_done && */
2981 (result == build_ok) &&
2982 !quest &&
2983 (report_dependencies_level == 0) /* &&
2984 (exists(default_target_to_build) > file_doesnt_exist) */) {
2985 if (posix) {
2986 if (!commands_done) {
2987 (void) printf(gettext("`%s' is updated.\n"),
2988 default_target_to_build->string_mb);
2989 } else {
2990 if (no_action_was_taken) {
2991 (void) printf(gettext("`%s': no action was taken.\n"),
2992 default_target_to_build->string_mb);
2993 }
2994 }
2995 } else {
2996 if (!commands_done &&
2997 (exists(default_target_to_build) > file_doesnt_exist)) {
2998 (void) printf(gettext("`%s' is up to date.\n"),
2999 default_target_to_build->string_mb);
3000 }
3001 }
3002 }
3003 }
3004 }
3005
3006 /*
3007 * report_recursion(target)
3008 *
3009 * If this is a recursive make and the parent make has KEEP_STATE on
3010 * this routine reports the dependency to the parent make
3011 *
3012 * Parameters:
3013 * target Target to report
3014 *
3015 * Global variables used:
3016 * makefiles_used List of makefiles read
3017 * recursive_name The Name ".RECURSIVE", printed
3018 * report_dependency dwight
3155 if (len_array + len_macro + esc_len + 5 >= Ar->size) goto ALLOC_ARRAY;
3156 strcat(Ar->start, " ");
3157 strncat(Ar->start, name, cp0-name);
3158 strcat(Ar->start, "=");
3159 strncat(Ar->start, esc_value, strlen(esc_value));
3160 free(esc_value);
3161 return;
3162 ERROR_MACRO:
3163 /* Macro without '=' or with invalid left/right part */
3164 return;
3165 }
3166
3167 static void
3168 report_dir_enter_leave(Boolean entering)
3169 {
3170 char rcwd[MAXPATHLEN];
3171 static char * mlev = NULL;
3172 char * make_level_str = NULL;
3173 int make_level_val = 0;
3174
3175 make_level_str = getenv("MAKELEVEL");
3176 if(make_level_str) {
3177 make_level_val = atoi(make_level_str);
3178 }
3179 if(mlev == NULL) {
3180 mlev = (char*) malloc(MAXPATHLEN);
3181 }
3182 if(entering) {
3183 sprintf(mlev, "MAKELEVEL=%d", make_level_val + 1);
3184 } else {
3185 make_level_val--;
3186 sprintf(mlev, "MAKELEVEL=%d", make_level_val);
3187 }
3188 putenv(mlev);
3189
3190 if(report_cwd) {
3191 if(make_level_val <= 0) {
3192 if(entering) {
3193 sprintf( rcwd
3194 , gettext("dmake: Entering directory `%s'\n")
3195 , get_current_path());
3196 } else {
3197 sprintf( rcwd
3198 , gettext("dmake: Leaving directory `%s'\n")
3199 , get_current_path());
3200 }
3201 } else {
3202 if(entering) {
3203 sprintf( rcwd
3204 , gettext("dmake[%d]: Entering directory `%s'\n")
3205 , make_level_val, get_current_path());
3206 } else {
3207 sprintf( rcwd
3208 , gettext("dmake[%d]: Leaving directory `%s'\n")
3209 , make_level_val, get_current_path());
3210 }
3211 }
3212 printf("%s", rcwd);
3213 }
3214 }
|