50
51 #include <pwd.h> /* getpwnam() */
52 #include <setjmp.h>
53 #include <signal.h>
54 #include <stdlib.h>
55 #include <sys/errno.h> /* ENOENT */
56 #include <sys/stat.h> /* fstat() */
57 #include <fcntl.h> /* open() */
58
59 # include <sys/systeminfo.h> /* sysinfo() */
60
61 #include <sys/types.h> /* stat() */
62 #include <sys/wait.h> /* wait() */
63 #include <unistd.h> /* execv(), unlink(), access() */
64 #include <vroot/report.h> /* report_dependency(), get_report_file() */
65
66 // From read2.cc
67 extern Name normalize_name(register wchar_t *name_string, register int length);
68
69 // From parallel.cc
70 #if defined(TEAMWARE_MAKE_CMN)
71 #define MAXJOBS_ADJUST_RFE4694000
72
73 #ifdef MAXJOBS_ADJUST_RFE4694000
74 extern void job_adjust_fini();
75 #endif /* MAXJOBS_ADJUST_RFE4694000 */
76 #endif /* TEAMWARE_MAKE_CMN */
77
78
79 /*
80 * Defined macros
81 */
82 #define MAKE_PREFIX NOCATGETS("/usr")
83 #define LD_SUPPORT_ENV_VAR NOCATGETS("SGS_SUPPORT_32")
84 #define LD_SUPPORT_ENV_VAR_32 NOCATGETS("SGS_SUPPORT_32")
85 #define LD_SUPPORT_ENV_VAR_64 NOCATGETS("SGS_SUPPORT_64")
86 #define LD_SUPPORT_MAKE_LIB NOCATGETS("libmakestate.so.1")
87 #define LD_SUPPORT_MAKE_LIB_DIR NOCATGETS("/lib")
88 #define LD_SUPPORT_MAKE_LIB_DIR_64 NOCATGETS("/64")
89
90 /*
91 * typedefs & structs
92 */
93
94 /*
95 * Static variables
96 */
104 static Boolean dmake_output_mode_specified; /* `-x DMAKE_OUTPUT_MODE=' */
105 static Boolean dmake_compat_mode_specified; /* `-x SUN_MAKE_COMPAT_MODE=' */
106 static Boolean dmake_odir_specified; /* `-o' */
107 static Boolean dmake_rcfile_specified; /* `-c' */
108 static Boolean env_wins; /* `-e' */
109 static Boolean ignore_default_mk; /* `-r' */
110 static Boolean list_all_targets; /* `-T' */
111 static int mf_argc;
112 static char **mf_argv;
113 static Dependency_rec not_auto_depen_struct;
114 static Dependency not_auto_depen = ¬_auto_depen_struct;
115 static Boolean pmake_cap_r_specified; /* `-R' */
116 static Boolean pmake_machinesfile_specified; /* `-M' */
117 static Boolean stop_after_error_ever_seen; /* `-S' */
118 static Boolean trace_status; /* `-p' */
119
120 #ifdef DMAKE_STATISTICS
121 static Boolean getname_stat = false;
122 #endif
123
124 #if defined(TEAMWARE_MAKE_CMN)
125 static time_t start_time;
126 static int g_argc;
127 static char **g_argv;
128 #endif
129
130 /*
131 * File table of contents
132 */
133 extern "C" void cleanup_after_exit(void);
134
135 #ifdef TEAMWARE_MAKE_CMN
136 extern "C" {
137 extern void dmake_exit_callback(void);
138 extern void dmake_message_callback(char *);
139 }
140 #endif
141
142 extern Name normalize_name(register wchar_t *name_string, register int length);
143
144 extern int main(int, char * []);
145
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 #ifdef TEAMWARE_MAKE_CMN
164 static const char verstring[] = "illumos make";
165 #endif
166
167 jmp_buf jmpbuffer;
168 extern nl_catd catd;
169
170 /*
171 * main(argc, argv)
172 *
173 * Parameters:
174 * argc You know what this is
175 * argv You know what this is
176 *
177 * Static variables used:
178 * list_all_targets make -T seen
179 * trace_status make -p seen
180 *
181 * Global variables used:
182 * debug_level Should we trace make actions?
183 * keep_state Set if .KEEP_STATE seen
184 * makeflags The Name "MAKEFLAGS", used to get macro
185 * remote_command_name Name of remote invocation cmd ("on")
187 * stdout_stderr_same true if stdout and stderr are the same
188 * auto_dependencies The Name "SUNPRO_DEPENDENCIES"
189 * temp_file_directory Set to the dir where we create tmp file
190 * trace_reader Set to reflect tracing status
191 * working_on_targets Set when building user targets
192 */
193 int
194 main(int argc, char *argv[])
195 {
196 /*
197 * cp is a -> to the value of the MAKEFLAGS env var,
198 * which has to be regular chars.
199 */
200 register char *cp;
201 char make_state_dir[MAXPATHLEN];
202 Boolean parallel_flag = false;
203 char *prognameptr;
204 char *slash_ptr;
205 mode_t um;
206 int i;
207 #ifdef TEAMWARE_MAKE_CMN
208 struct itimerval value;
209 char def_dmakerc_path[MAXPATHLEN];
210 Name dmake_name, dmake_name2;
211 Name dmake_value, dmake_value2;
212 Property prop, prop2;
213 struct stat statbuf;
214 int statval;
215 #endif
216
217 struct stat out_stat, err_stat;
218 hostid = gethostid();
219 bsd_signals();
220
221 (void) setlocale(LC_ALL, "");
222
223
224 #ifdef DMAKE_STATISTICS
225 if (getenv(NOCATGETS("DMAKE_STATISTICS"))) {
226 getname_stat = true;
227 }
228 #endif
229
230 #if defined(TEAMWARE_MAKE_CMN)
231 catd = catopen(AVO_DOMAIN_DMAKE, NL_CAT_LOCALE);
232 #endif
233
234 // ---> fprintf(stderr, catgets(catd, 15, 666, "--- SUN make ---\n"));
235
236
237 #if defined(TEAMWARE_MAKE_CMN)
238 /*
239 * I put libmksdmsi18n_init() under #ifdef because it requires avo_i18n_init()
240 * from avo_util library.
241 */
242 libmksdmsi18n_init();
243 #endif
244
245
246 #ifndef TEAMWARE_MAKE_CMN
247 textdomain(NOCATGETS("SUNW_SPRO_MAKE"));
248 #endif /* TEAMWARE_MAKE_CMN */
249
250 #ifdef TEAMWARE_MAKE_CMN
251 g_argc = argc;
252 g_argv = (char **) malloc((g_argc + 1) * sizeof(char *));
253 for (i = 0; i < argc; i++) {
254 g_argv[i] = argv[i];
255 }
256 g_argv[i] = NULL;
257 #endif /* TEAMWARE_MAKE_CMN */
258
259 /*
260 * Set argv_zero_string to some form of argv[0] for
261 * recursive MAKE builds.
262 */
263
264 if (*argv[0] == (int) slash_char) {
265 /* argv[0] starts with a slash */
266 argv_zero_string = strdup(argv[0]);
267 } else if (strchr(argv[0], (int) slash_char) == NULL) {
268 /* argv[0] contains no slashes */
269 argv_zero_string = strdup(argv[0]);
270 } else {
271 /*
272 * argv[0] contains at least one slash,
273 * but doesn't start with a slash
274 */
275 char *tmp_current_path;
276 char *tmp_string;
277
386 */
387 (void) atexit(cleanup_after_exit);
388
389 load_cached_names();
390
391 /*
392 * Set command line flags
393 */
394 setup_makeflags_argv();
395 read_command_options(mf_argc, mf_argv);
396 read_command_options(argc, argv);
397 if (debug_level > 0) {
398 cp = getenv(makeflags->string_mb);
399 (void) printf(catgets(catd, 1, 167, "MAKEFLAGS value: %s\n"), cp == NULL ? "" : cp);
400 }
401
402 setup_interrupt(handle_interrupt);
403
404 read_files_and_state(argc, argv);
405
406 #ifdef TEAMWARE_MAKE_CMN
407 /*
408 * Find the dmake_output_mode: TXT1, TXT2 or HTML1.
409 */
410 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_OUTPUT_MODE"));
411 dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
412 prop2 = get_prop(dmake_name2->prop, macro_prop);
413 if (prop2 == NULL) {
414 /* DMAKE_OUTPUT_MODE not defined, default to TXT1 mode */
415 output_mode = txt1_mode;
416 } else {
417 dmake_value2 = prop2->body.macro.value;
418 if ((dmake_value2 == NULL) ||
419 (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT1")))) {
420 output_mode = txt1_mode;
421 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT2"))) {
422 output_mode = txt2_mode;
423 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("HTML1"))) {
424 output_mode = html1_mode;
425 } else {
426 warning(catgets(catd, 1, 352, "Unsupported value `%s' for DMAKE_OUTPUT_MODE after -x flag (ignored)"),
454 } else {
455 fatal(catgets(catd, 1, 307, "Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb);
456 }
457 }
458
459 if ((!list_all_targets) &&
460 (report_dependencies_level == 0)) {
461 /*
462 * Check to see if either DMAKE_RCFILE or DMAKE_MODE is defined.
463 * They could be defined in the env, in the makefile, or on the
464 * command line.
465 * If neither is defined, and $(HOME)/.dmakerc does not exists,
466 * then print a message, and default to parallel mode.
467 */
468 if(dmake_mode_type == distributed_mode) {
469 dmake_mode_type = parallel_mode;
470 no_parallel = false;
471 }
472 }
473 }
474 #endif
475
476 #ifdef TEAMWARE_MAKE_CMN
477 parallel_flag = true;
478 putenv(strdup(NOCATGETS("DMAKE_CHILD=TRUE")));
479
480 //
481 // If dmake is running with -t option, set dmake_mode_type to serial.
482 // This is done because doname() calls touch_command() that runs serially.
483 // If we do not do that, maketool will have problems.
484 //
485 if(touch) {
486 dmake_mode_type = serial_mode;
487 no_parallel = true;
488 }
489 #else
490 parallel_flag = false;
491 #endif
492
493 #if defined (TEAMWARE_MAKE_CMN)
494 /*
495 * Check whether stdout and stderr are physically same.
496 * This is in order to decide whether we need to redirect
497 * stderr separately from stdout.
498 * This check is performed only if __DMAKE_SEPARATE_STDERR
499 * is not set. This variable may be used in order to preserve
500 * the 'old' behaviour.
501 */
502 out_err_same = true;
503 char * dmake_sep_var = getenv(NOCATGETS("__DMAKE_SEPARATE_STDERR"));
504 if (dmake_sep_var == NULL || (0 != strcasecmp(dmake_sep_var, NOCATGETS("NO")))) {
505 struct stat stdout_stat;
506 struct stat stderr_stat;
507 if( (fstat(1, &stdout_stat) == 0)
508 && (fstat(2, &stderr_stat) == 0) )
509 {
510 if( (stdout_stat.st_dev != stderr_stat.st_dev)
511 || (stdout_stat.st_ino != stderr_stat.st_ino) )
512 {
513 out_err_same = false;
514 }
515 }
516 }
517 #endif
518
519
520 /*
521 * Enable interrupt handler for alarms
522 */
523 (void) bsd_signal(SIGALRM, (SIG_PF)doalarm);
524
525 /*
526 * Check if make should report
527 */
528 if (getenv(sunpro_dependencies->string_mb) != NULL) {
529 FILE *report_file;
530
531 report_dependency("");
532 report_file = get_report_file();
533 if ((report_file != NULL) && (report_file != (FILE*)-1)) {
534 (void) fprintf(report_file, "\n");
535 }
536 }
537
674 printf(
675 NOCATGETS(" Env (%ld): %ld Kb (%ld bytes)\n"),
676 env_alloc_num,
677 env_alloc_bytes/1000,
678 env_alloc_bytes
679 );
680
681 }
682 #endif
683
684 parallel = false;
685 /* If we used the SVR4_MAKE, don't build .DONE or .FAILED */
686 if (!getenv(USE_SVR4_MAKE)){
687 /* Build the target .DONE or .FAILED if we caught an error */
688 if (!quest && !list_all_targets) {
689 Name failed_name;
690
691 MBSTOWCS(wcs_buffer, NOCATGETS(".FAILED"));
692 failed_name = GETNAME(wcs_buffer, FIND_LENGTH);
693 if ((exit_status != 0) && (failed_name->prop != NULL)) {
694 #ifdef TEAMWARE_MAKE_CMN
695 /*
696 * [tolik] switch DMake to serial mode
697 */
698 dmake_mode_type = serial_mode;
699 no_parallel = true;
700 #endif
701 (void) doname(failed_name, false, true);
702 } else {
703 if (!trace_status) {
704 #ifdef TEAMWARE_MAKE_CMN
705 /*
706 * Switch DMake to serial mode
707 */
708 dmake_mode_type = serial_mode;
709 no_parallel = true;
710 #endif
711 (void) doname(done, false, true);
712 }
713 }
714 }
715 }
716 /*
717 * Remove the temp file utilities report dependencies thru if it
718 * is still around
719 */
720 if (temp_file_name != NULL) {
721 (void) unlink(temp_file_name->string_mb);
722 }
723 /*
724 * Do not save the current command in .make.state if make
725 * was interrupted.
726 */
727 if (current_line != NULL) {
728 command_changed = true;
729 current_line->body.line.command_used = NULL;
730 }
793 Running rp;
794
795 (void) fflush(stdout);
796 if (childPid > 0) {
797 kill(childPid, SIGTERM);
798 childPid = -1;
799 }
800 for (rp = running_list; rp != NULL; rp = rp->next) {
801 if (rp->state != build_running) {
802 continue;
803 }
804 if (rp->pid > 0) {
805 kill(rp->pid, SIGTERM);
806 rp->pid = -1;
807 }
808 }
809 if (getpid() == getpgrp()) {
810 bsd_signal(SIGTERM, SIG_IGN);
811 kill (-getpid(), SIGTERM);
812 }
813 #ifdef TEAMWARE_MAKE_CMN
814 /* Clean up all parallel/distributed children already finished */
815 finish_children(false);
816 #endif
817
818 /* Make sure the processes running under us terminate first */
819
820 while (wait((int *) NULL) != -1);
821 /* Delete the current targets unless they are precious */
822 if ((current_target != NULL) &&
823 current_target->is_member &&
824 ((member = get_prop(current_target->prop, member_prop)) != NULL)) {
825 current_target = member->body.member.library;
826 }
827 if (!do_not_exec_rule &&
828 !touch &&
829 !quest &&
830 (current_target != NULL) &&
831 !(current_target->stat.is_precious || all_precious)) {
832
833 /* BID_1030811 */
834 /* azv 16 Oct 95 */
835 current_target->stat.time = file_no_time;
836
948 register int ch;
949 int current_optind = 1;
950 int last_optind_with_double_hyphen = 0;
951 int last_optind;
952 int last_current_optind;
953 register int i;
954 register int j;
955 register int k;
956 register int makefile_next = 0; /*
957 * flag to note options:
958 * -c, f, g, j, m, o
959 */
960 const char *tptr;
961 const char *CMD_OPTS;
962
963 extern char *optarg;
964 extern int optind, opterr, optopt;
965
966 #define SUNPRO_CMD_OPTS "-~Bbc:Ddef:g:ij:K:kM:m:NnO:o:PpqRrSsTtuVvwx:"
967
968 #ifdef TEAMWARE_MAKE_CMN
969 # define SVR4_CMD_OPTS "-c:ef:g:ij:km:nO:o:pqrsTtVv"
970 #else
971 # define SVR4_CMD_OPTS "-ef:iknpqrstV"
972 #endif
973
974 /*
975 * Added V in SVR4_CMD_OPTS also, which is going to be a hidden
976 * option, just to make sure that the getopt doesn't fail when some
977 * users leave their USE_SVR4_MAKE set and try to use the makefiles
978 * that are designed to issue commands like $(MAKE) -V. Anyway it
979 * sets the same flag but ensures that getopt doesn't fail.
980 */
981
982 opterr = 0;
983 optind = 1;
984 while (1) {
985 last_optind=optind; /* Save optind and current_optind values */
986 last_current_optind=current_optind; /* in case we have to repeat this round. */
987 if (svr4) {
988 CMD_OPTS=SVR4_CMD_OPTS;
989 ch = getopt(argc, argv, SVR4_CMD_OPTS);
990 } else {
991 CMD_OPTS=SUNPRO_CMD_OPTS;
992 ch = getopt(argc, argv, SUNPRO_CMD_OPTS);
1029
1030 /* Eliminate first hyphen character */
1031 for (j=0; argv[i][j] != '\0'; j++) {
1032 argv[i][j] = argv[i][j+1];
1033 }
1034
1035 /* Repeat the processing of this argument */
1036 optind=last_optind;
1037 current_optind=last_current_optind;
1038 continue;
1039 }
1040 }
1041 }
1042 }
1043 }
1044 }
1045 }
1046
1047 if (ch == '?') {
1048 if (svr4) {
1049 #ifdef TEAMWARE_MAKE_CMN
1050 fprintf(stderr,
1051 catgets(catd, 1, 267, "Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1052 fprintf(stderr,
1053 catgets(catd, 1, 268, " [ -j dmake_max_jobs ][ -m dmake_mode ][ -o dmake_odir ]...\n"));
1054 fprintf(stderr,
1055 catgets(catd, 1, 269, " [ -e ][ -i ][ -k ][ -n ][ -p ][ -q ][ -r ][ -s ][ -t ][ -v ]\n"));
1056 #else
1057 fprintf(stderr,
1058 catgets(catd, 1, 270, "Usage : make [ -f makefile ]... [ -e ][ -i ][ -k ][ -n ][ -p ][ -q ][ -r ]\n"));
1059 fprintf(stderr,
1060 catgets(catd, 1, 271, " [ -s ][ -t ]\n"));
1061 #endif
1062 tptr = strchr(SVR4_CMD_OPTS, optopt);
1063 } else {
1064 #ifdef TEAMWARE_MAKE_CMN
1065 fprintf(stderr,
1066 catgets(catd, 1, 272, "Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1067 fprintf(stderr,
1068 catgets(catd, 1, 273, " [ -j dmake_max_jobs ][ -K statefile ][ -m dmake_mode ][ -x MODE_NAME=VALUE ][ -o dmake_odir ]...\n"));
1069 fprintf(stderr,
1070 catgets(catd, 1, 274, " [ -d ][ -dd ][ -D ][ -DD ][ -e ][ -i ][ -k ][ -n ][ -p ][ -P ][ -u ][ -w ]\n"));
1071 fprintf(stderr,
1072 catgets(catd, 1, 275, " [ -q ][ -r ][ -s ][ -S ][ -t ][ -v ][ -V ][ target... ][ macro=value... ][ \"macro +=value\"... ]\n"));
1073 #else
1074 fprintf(stderr,
1075 catgets(catd, 1, 276, "Usage : make [ -f makefile ][ -K statefile ]... [ -d ][ -dd ][ -D ][ -DD ]\n"));
1076 fprintf(stderr,
1077 catgets(catd, 1, 277, " [ -e ][ -i ][ -k ][ -n ][ -p ][ -P ][ -q ][ -r ][ -s ][ -S ][ -t ]\n"));
1078 fprintf(stderr,
1079 catgets(catd, 1, 278, " [ -u ][ -w ][ -V ][ target... ][ macro=value... ][ \"macro +=value\"... ]\n"));
1080 #endif
1081 tptr = strchr(SUNPRO_CMD_OPTS, optopt);
1082 }
1083 if (!tptr) {
1084 fatal(catgets(catd, 1, 279, "Unknown option `-%c'"), optopt);
1085 } else {
1086 fatal(catgets(catd, 1, 280, "Missing argument after `-%c'"), optopt);
1087 }
1088 }
1089
1090
1091
1092 makefile_next |= parse_command_option(ch);
1093 /*
1094 * If we're done processing all of the options of
1095 * ONE argument string...
1096 */
1097 if (current_optind < optind) {
1098 i = current_optind;
1099 k = 0;
1100 /* If there's an argument for an option... */
1101 if ((optind - current_optind) > 1) {
1102 k = i + 1;
1103 }
1104 switch (makefile_next) {
1105 case 0:
1106 argv[i] = NULL;
1107 /* This shouldn't happen */
1108 if (k) {
1109 argv[k] = NULL;
1110 }
1111 break;
1112 case 1: /* -f seen */
1113 argv[i] = (char *)NOCATGETS("-f");
1114 break;
1115 case 2: /* -c seen */
1116 argv[i] = (char *)NOCATGETS("-c");
1117 #ifndef TEAMWARE_MAKE_CMN
1118 warning(catgets(catd, 1, 281, "Ignoring DistributedMake -c option"));
1119 #endif
1120 break;
1121 case 4: /* -g seen */
1122 argv[i] = (char *)NOCATGETS("-g");
1123 #ifndef TEAMWARE_MAKE_CMN
1124 warning(catgets(catd, 1, 282, "Ignoring DistributedMake -g option"));
1125 #endif
1126 break;
1127 case 8: /* -j seen */
1128 argv[i] = (char *)NOCATGETS("-j");
1129 #ifndef TEAMWARE_MAKE_CMN
1130 warning(catgets(catd, 1, 283, "Ignoring DistributedMake -j option"));
1131 #endif
1132 break;
1133 case 16: /* -M seen */
1134 argv[i] = (char *)NOCATGETS("-M");
1135 #ifndef TEAMWARE_MAKE_CMN
1136 warning(catgets(catd, 1, 284, "Ignoring ParallelMake -M option"));
1137 #endif
1138 break;
1139 case 32: /* -m seen */
1140 argv[i] = (char *)NOCATGETS("-m");
1141 #ifndef TEAMWARE_MAKE_CMN
1142 warning(catgets(catd, 1, 285, "Ignoring DistributedMake -m option"));
1143 #endif
1144 break;
1145 case 128: /* -O seen */
1146 argv[i] = (char *)NOCATGETS("-O");
1147 break;
1148 case 256: /* -K seen */
1149 argv[i] = (char *)NOCATGETS("-K");
1150 break;
1151 case 512: /* -o seen */
1152 argv[i] = (char *)NOCATGETS("-o");
1153 #ifndef TEAMWARE_MAKE_CMN
1154 warning(catgets(catd, 1, 311, "Ignoring DistributedMake -o option"));
1155 #endif
1156 break;
1157 case 1024: /* -x seen */
1158 argv[i] = (char *)NOCATGETS("-x");
1159 #ifndef TEAMWARE_MAKE_CMN
1160 warning(catgets(catd, 1, 353, "Ignoring DistributedMake -x option"));
1161 #endif
1162 break;
1163 default: /* > 1 of -c, f, g, j, K, M, m, O, o, x seen */
1164 fatal(catgets(catd, 1, 286, "Illegal command line. More than one option requiring\nan argument given in the same argument group"));
1165 }
1166
1167 makefile_next = 0;
1168 current_optind = optind;
1169 }
1170 }
1171 }
1172
1173 static void
1174 quote_str(char *str, char *qstr)
1175 {
1176 char *to;
1177 char *from;
1178
1179 to = qstr;
1180 for (from = str; *from; from++) {
1181 switch (*from) {
1524 report_dependencies_level++;
1525 }
1526 return 0;
1527 case 'p': /* Print description */
1528 if (invert_this) {
1529 trace_status = false;
1530 do_not_exec_rule = false;
1531 } else {
1532 trace_status = true;
1533 do_not_exec_rule = true;
1534 }
1535 return 0;
1536 case 'q': /* Question flag */
1537 if (invert_this) {
1538 quest = false;
1539 } else {
1540 quest = true;
1541 }
1542 return 0;
1543 case 'R': /* Don't run in parallel */
1544 #ifdef TEAMWARE_MAKE_CMN
1545 if (invert_this) {
1546 pmake_cap_r_specified = false;
1547 no_parallel = false;
1548 } else {
1549 pmake_cap_r_specified = true;
1550 dmake_mode_type = serial_mode;
1551 no_parallel = true;
1552 }
1553 #else
1554 warning(catgets(catd, 1, 182, "Ignoring ParallelMake -R option"));
1555 #endif
1556 return 0;
1557 case 'r': /* Turn off internal rules */
1558 if (invert_this) {
1559 ignore_default_mk = false;
1560 } else {
1561 ignore_default_mk = true;
1562 }
1563 return 0;
1564 case 'S': /* Reverse -k */
1565 if (invert_this) {
1566 continue_after_error = true;
1567 } else {
1568 continue_after_error = false;
1569 stop_after_error_ever_seen = true;
1570 }
1571 return 0;
1572 case 's': /* Silent flag */
1573 if (invert_this) {
1574 silent_all = false;
1575 } else {
1588 case 't': /* Touch flag */
1589 if (invert_this) {
1590 touch = false;
1591 } else {
1592 touch = true;
1593 }
1594 return 0;
1595 case 'u': /* Unconditional flag */
1596 if (invert_this) {
1597 build_unconditional = false;
1598 } else {
1599 build_unconditional = true;
1600 }
1601 return 0;
1602 case 'V': /* SVR4 mode */
1603 svr4 = true;
1604 return 0;
1605 case 'v': /* Version flag */
1606 if (invert_this) {
1607 } else {
1608 #ifdef TEAMWARE_MAKE_CMN
1609 fprintf(stdout, NOCATGETS("dmake: %s\n"), verstring);
1610 exit_status = 0;
1611 exit(0);
1612 #else
1613 warning(catgets(catd, 1, 324, "Ignoring DistributedMake -v option"));
1614 #endif
1615 }
1616 return 0;
1617 case 'w': /* Unconditional flag */
1618 if (invert_this) {
1619 report_cwd = false;
1620 } else {
1621 report_cwd = true;
1622 }
1623 return 0;
1624 #if 0
1625 case 'X': /* Filter stdout */
1626 if (invert_this) {
1627 filter_stderr = false;
1628 } else {
1629 filter_stderr = true;
1630 }
1631 return 0;
1632 #endif
1633 default:
1634 break;
2859 * init The Name ".INIT", use to run command
2860 * parallel Global parallel building flag
2861 * quest make -q, suppresses messages
2862 * recursion_level Initialized, used for tracing
2863 * report_dependencies make -P, regroves whole process
2864 */
2865 static void
2866 make_targets(int argc, char **argv, Boolean parallel_flag)
2867 {
2868 int i;
2869 char *cp;
2870 Doname result;
2871 register Boolean target_to_make_found = false;
2872
2873 (void) doname(init, true, true);
2874 recursion_level = 1;
2875 parallel = parallel_flag;
2876 /*
2877 * make remaining args
2878 */
2879 #ifdef TEAMWARE_MAKE_CMN
2880 /*
2881 if ((report_dependencies_level == 0) && parallel) {
2882 */
2883 if (parallel) {
2884 /*
2885 * If building targets in parallel, start all of the
2886 * remaining args to build in parallel.
2887 */
2888 for (i = 1; i < argc; i++) {
2889 if ((cp = argv[i]) != NULL) {
2890 commands_done = false;
2891 if ((cp[0] == (int) period_char) &&
2892 (cp[1] == (int) slash_char)) {
2893 cp += 2;
2894 }
2895 if((cp[0] == (int) ' ') &&
2896 (cp[1] == (int) '-') &&
2897 (cp[2] == (int) ' ') &&
2898 (cp[3] == (int) '-')) {
2899 argv[i] = NULL;
2940 (void) printf(catgets(catd, 1, 294, "`%s': no action was taken.\n"),
2941 default_target_to_build->string_mb);
2942 }
2943 }
2944 } else {
2945 default_target_to_build->stat.time = file_no_time;
2946 if (!commands_done &&
2947 (exists(default_target_to_build) > file_doesnt_exist)) {
2948 (void) printf(catgets(catd, 1, 295, "`%s' is up to date.\n"),
2949 default_target_to_build->string_mb);
2950 }
2951 }
2952 }
2953 }
2954 }
2955 /* Now wait for all of the targets to finish running */
2956 finish_running();
2957 // setjmp(jmpbuffer);
2958
2959 }
2960 #endif
2961 for (i = 1; i < argc; i++) {
2962 if ((cp = argv[i]) != NULL) {
2963 target_to_make_found = true;
2964 if ((cp[0] == (int) period_char) &&
2965 (cp[1] == (int) slash_char)) {
2966 cp += 2;
2967 }
2968 if((cp[0] == (int) ' ') &&
2969 (cp[1] == (int) '-') &&
2970 (cp[2] == (int) ' ') &&
2971 (cp[3] == (int) '-')) {
2972 argv[i] = NULL;
2973 continue;
2974 }
2975 MBSTOWCS(wcs_buffer, cp);
2976 default_target_to_build = normalize_name(wcs_buffer, wslen(wcs_buffer));
2977 top_level_target = get_wstring(default_target_to_build->string_mb);
2978 report_recursion(default_target_to_build);
2979 commands_done = false;
2980 if (parallel) {
3032
3033 /*
3034 * If no file arguments have been encountered,
3035 * make the first name encountered that doesnt start with a dot
3036 */
3037 if (!target_to_make_found) {
3038 if (default_target_to_build == NULL) {
3039 fatal(catgets(catd, 1, 202, "No arguments to build"));
3040 }
3041 commands_done = false;
3042 top_level_target = get_wstring(default_target_to_build->string_mb);
3043 report_recursion(default_target_to_build);
3044
3045
3046 if (getenv(NOCATGETS("SPRO_EXPAND_ERRORS"))){
3047 (void) printf(NOCATGETS("::(%s)\n"),
3048 default_target_to_build->string_mb);
3049 }
3050
3051
3052 #ifdef TEAMWARE_MAKE_CMN
3053 result = doname_parallel(default_target_to_build, true, false);
3054 #else
3055 result = doname_check(default_target_to_build, true,
3056 false, false);
3057 #endif
3058 gather_recursive_deps();
3059 if (build_failed_seen) {
3060 build_failed_ever_seen = true;
3061 warning(catgets(catd, 1, 203, "Target `%s' not remade because of errors"),
3062 default_target_to_build->string_mb);
3063 }
3064 build_failed_seen = false;
3065 if (report_dependencies_level > 0) {
3066 print_dependencies(default_target_to_build,
3067 get_prop(default_target_to_build->
3068 prop,
3069 line_prop));
3070 }
3071 default_target_to_build->stat.time = file_no_time;
3072 if (default_target_to_build->colon_splits > 0) {
3073 default_target_to_build->state = build_dont_know;
3074 }
3075 if (/* !commands_done && */
3076 (result == build_ok) &&
3077 !quest &&
3305 int make_level_val = 0;
3306
3307 make_level_str = getenv(NOCATGETS("MAKELEVEL"));
3308 if(make_level_str) {
3309 make_level_val = atoi(make_level_str);
3310 }
3311 if(mlev == NULL) {
3312 mlev = (char*) malloc(MAXPATHLEN);
3313 }
3314 if(entering) {
3315 sprintf(mlev, NOCATGETS("MAKELEVEL=%d"), make_level_val + 1);
3316 } else {
3317 make_level_val--;
3318 sprintf(mlev, NOCATGETS("MAKELEVEL=%d"), make_level_val);
3319 }
3320 putenv(mlev);
3321
3322 if(report_cwd) {
3323 if(make_level_val <= 0) {
3324 if(entering) {
3325 #ifdef TEAMWARE_MAKE_CMN
3326 sprintf( rcwd
3327 , catgets(catd, 1, 329, "dmake: Entering directory `%s'\n")
3328 , get_current_path());
3329 #else
3330 sprintf( rcwd
3331 , catgets(catd, 1, 330, "make: Entering directory `%s'\n")
3332 , get_current_path());
3333 #endif
3334 } else {
3335 #ifdef TEAMWARE_MAKE_CMN
3336 sprintf( rcwd
3337 , catgets(catd, 1, 331, "dmake: Leaving directory `%s'\n")
3338 , get_current_path());
3339 #else
3340 sprintf( rcwd
3341 , catgets(catd, 1, 332, "make: Leaving directory `%s'\n")
3342 , get_current_path());
3343 #endif
3344 }
3345 } else {
3346 if(entering) {
3347 #ifdef TEAMWARE_MAKE_CMN
3348 sprintf( rcwd
3349 , catgets(catd, 1, 333, "dmake[%d]: Entering directory `%s'\n")
3350 , make_level_val, get_current_path());
3351 #else
3352 sprintf( rcwd
3353 , catgets(catd, 1, 334, "make[%d]: Entering directory `%s'\n")
3354 , make_level_val, get_current_path());
3355 #endif
3356 } else {
3357 #ifdef TEAMWARE_MAKE_CMN
3358 sprintf( rcwd
3359 , catgets(catd, 1, 335, "dmake[%d]: Leaving directory `%s'\n")
3360 , make_level_val, get_current_path());
3361 #else
3362 sprintf( rcwd
3363 , catgets(catd, 1, 336, "make[%d]: Leaving directory `%s'\n")
3364 , make_level_val, get_current_path());
3365 #endif
3366 }
3367 }
3368 printf(NOCATGETS("%s"), rcwd);
3369 }
3370 }
|
50
51 #include <pwd.h> /* getpwnam() */
52 #include <setjmp.h>
53 #include <signal.h>
54 #include <stdlib.h>
55 #include <sys/errno.h> /* ENOENT */
56 #include <sys/stat.h> /* fstat() */
57 #include <fcntl.h> /* open() */
58
59 # include <sys/systeminfo.h> /* sysinfo() */
60
61 #include <sys/types.h> /* stat() */
62 #include <sys/wait.h> /* wait() */
63 #include <unistd.h> /* execv(), unlink(), access() */
64 #include <vroot/report.h> /* report_dependency(), get_report_file() */
65
66 // From read2.cc
67 extern Name normalize_name(register wchar_t *name_string, register int length);
68
69 // From parallel.cc
70 #define MAXJOBS_ADJUST_RFE4694000
71
72 #ifdef MAXJOBS_ADJUST_RFE4694000
73 extern void job_adjust_fini();
74 #endif /* MAXJOBS_ADJUST_RFE4694000 */
75
76
77 /*
78 * Defined macros
79 */
80 #define MAKE_PREFIX NOCATGETS("/usr")
81 #define LD_SUPPORT_ENV_VAR NOCATGETS("SGS_SUPPORT_32")
82 #define LD_SUPPORT_ENV_VAR_32 NOCATGETS("SGS_SUPPORT_32")
83 #define LD_SUPPORT_ENV_VAR_64 NOCATGETS("SGS_SUPPORT_64")
84 #define LD_SUPPORT_MAKE_LIB NOCATGETS("libmakestate.so.1")
85 #define LD_SUPPORT_MAKE_LIB_DIR NOCATGETS("/lib")
86 #define LD_SUPPORT_MAKE_LIB_DIR_64 NOCATGETS("/64")
87
88 /*
89 * typedefs & structs
90 */
91
92 /*
93 * Static variables
94 */
102 static Boolean dmake_output_mode_specified; /* `-x DMAKE_OUTPUT_MODE=' */
103 static Boolean dmake_compat_mode_specified; /* `-x SUN_MAKE_COMPAT_MODE=' */
104 static Boolean dmake_odir_specified; /* `-o' */
105 static Boolean dmake_rcfile_specified; /* `-c' */
106 static Boolean env_wins; /* `-e' */
107 static Boolean ignore_default_mk; /* `-r' */
108 static Boolean list_all_targets; /* `-T' */
109 static int mf_argc;
110 static char **mf_argv;
111 static Dependency_rec not_auto_depen_struct;
112 static Dependency not_auto_depen = ¬_auto_depen_struct;
113 static Boolean pmake_cap_r_specified; /* `-R' */
114 static Boolean pmake_machinesfile_specified; /* `-M' */
115 static Boolean stop_after_error_ever_seen; /* `-S' */
116 static Boolean trace_status; /* `-p' */
117
118 #ifdef DMAKE_STATISTICS
119 static Boolean getname_stat = false;
120 #endif
121
122 static time_t start_time;
123 static int g_argc;
124 static char **g_argv;
125
126 /*
127 * File table of contents
128 */
129 extern "C" void cleanup_after_exit(void);
130
131 extern "C" {
132 extern void dmake_exit_callback(void);
133 extern void dmake_message_callback(char *);
134 }
135
136 extern Name normalize_name(register wchar_t *name_string, register int length);
137
138 extern int main(int, char * []);
139
140 static void append_makeflags_string(Name, String);
141 static void doalarm(int);
142 static void enter_argv_values(int , char **, ASCII_Dyn_Array *);
143 static void make_targets(int, char **, Boolean);
144 static int parse_command_option(char);
145 static void read_command_options(int, char **);
146 static void read_environment(Boolean);
147 static void read_files_and_state(int, char **);
148 static Boolean read_makefile(Name, Boolean, Boolean, Boolean);
149 static void report_recursion(Name);
150 static void set_sgs_support(void);
151 static void setup_for_projectdir(void);
152 static void setup_makeflags_argv(void);
153 static void report_dir_enter_leave(Boolean entering);
154
155 extern void expand_value(Name, register String , Boolean);
156
157 static const char verstring[] = "illumos make";
158
159 jmp_buf jmpbuffer;
160 extern nl_catd catd;
161
162 /*
163 * main(argc, argv)
164 *
165 * Parameters:
166 * argc You know what this is
167 * argv You know what this is
168 *
169 * Static variables used:
170 * list_all_targets make -T seen
171 * trace_status make -p seen
172 *
173 * Global variables used:
174 * debug_level Should we trace make actions?
175 * keep_state Set if .KEEP_STATE seen
176 * makeflags The Name "MAKEFLAGS", used to get macro
177 * remote_command_name Name of remote invocation cmd ("on")
179 * stdout_stderr_same true if stdout and stderr are the same
180 * auto_dependencies The Name "SUNPRO_DEPENDENCIES"
181 * temp_file_directory Set to the dir where we create tmp file
182 * trace_reader Set to reflect tracing status
183 * working_on_targets Set when building user targets
184 */
185 int
186 main(int argc, char *argv[])
187 {
188 /*
189 * cp is a -> to the value of the MAKEFLAGS env var,
190 * which has to be regular chars.
191 */
192 register char *cp;
193 char make_state_dir[MAXPATHLEN];
194 Boolean parallel_flag = false;
195 char *prognameptr;
196 char *slash_ptr;
197 mode_t um;
198 int i;
199 struct itimerval value;
200 char def_dmakerc_path[MAXPATHLEN];
201 Name dmake_name, dmake_name2;
202 Name dmake_value, dmake_value2;
203 Property prop, prop2;
204 struct stat statbuf;
205 int statval;
206
207 struct stat out_stat, err_stat;
208 hostid = gethostid();
209 bsd_signals();
210
211 (void) setlocale(LC_ALL, "");
212
213
214 #ifdef DMAKE_STATISTICS
215 if (getenv(NOCATGETS("DMAKE_STATISTICS"))) {
216 getname_stat = true;
217 }
218 #endif
219
220 catd = catopen(AVO_DOMAIN_DMAKE, NL_CAT_LOCALE);
221
222 // ---> fprintf(stderr, catgets(catd, 15, 666, "--- SUN make ---\n"));
223
224
225 /*
226 * I put libmksdmsi18n_init() under #ifdef because it requires avo_i18n_init()
227 * from avo_util library.
228 */
229 libmksdmsi18n_init();
230
231
232 textdomain(NOCATGETS("SUNW_SPRO_MAKE"));
233
234 g_argc = argc;
235 g_argv = (char **) malloc((g_argc + 1) * sizeof(char *));
236 for (i = 0; i < argc; i++) {
237 g_argv[i] = argv[i];
238 }
239 g_argv[i] = NULL;
240
241 /*
242 * Set argv_zero_string to some form of argv[0] for
243 * recursive MAKE builds.
244 */
245
246 if (*argv[0] == (int) slash_char) {
247 /* argv[0] starts with a slash */
248 argv_zero_string = strdup(argv[0]);
249 } else if (strchr(argv[0], (int) slash_char) == NULL) {
250 /* argv[0] contains no slashes */
251 argv_zero_string = strdup(argv[0]);
252 } else {
253 /*
254 * argv[0] contains at least one slash,
255 * but doesn't start with a slash
256 */
257 char *tmp_current_path;
258 char *tmp_string;
259
368 */
369 (void) atexit(cleanup_after_exit);
370
371 load_cached_names();
372
373 /*
374 * Set command line flags
375 */
376 setup_makeflags_argv();
377 read_command_options(mf_argc, mf_argv);
378 read_command_options(argc, argv);
379 if (debug_level > 0) {
380 cp = getenv(makeflags->string_mb);
381 (void) printf(catgets(catd, 1, 167, "MAKEFLAGS value: %s\n"), cp == NULL ? "" : cp);
382 }
383
384 setup_interrupt(handle_interrupt);
385
386 read_files_and_state(argc, argv);
387
388 /*
389 * Find the dmake_output_mode: TXT1, TXT2 or HTML1.
390 */
391 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_OUTPUT_MODE"));
392 dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
393 prop2 = get_prop(dmake_name2->prop, macro_prop);
394 if (prop2 == NULL) {
395 /* DMAKE_OUTPUT_MODE not defined, default to TXT1 mode */
396 output_mode = txt1_mode;
397 } else {
398 dmake_value2 = prop2->body.macro.value;
399 if ((dmake_value2 == NULL) ||
400 (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT1")))) {
401 output_mode = txt1_mode;
402 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT2"))) {
403 output_mode = txt2_mode;
404 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("HTML1"))) {
405 output_mode = html1_mode;
406 } else {
407 warning(catgets(catd, 1, 352, "Unsupported value `%s' for DMAKE_OUTPUT_MODE after -x flag (ignored)"),
435 } else {
436 fatal(catgets(catd, 1, 307, "Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb);
437 }
438 }
439
440 if ((!list_all_targets) &&
441 (report_dependencies_level == 0)) {
442 /*
443 * Check to see if either DMAKE_RCFILE or DMAKE_MODE is defined.
444 * They could be defined in the env, in the makefile, or on the
445 * command line.
446 * If neither is defined, and $(HOME)/.dmakerc does not exists,
447 * then print a message, and default to parallel mode.
448 */
449 if(dmake_mode_type == distributed_mode) {
450 dmake_mode_type = parallel_mode;
451 no_parallel = false;
452 }
453 }
454 }
455
456 parallel_flag = true;
457 putenv(strdup(NOCATGETS("DMAKE_CHILD=TRUE")));
458
459 //
460 // If dmake is running with -t option, set dmake_mode_type to serial.
461 // This is done because doname() calls touch_command() that runs serially.
462 // If we do not do that, maketool will have problems.
463 //
464 if(touch) {
465 dmake_mode_type = serial_mode;
466 no_parallel = true;
467 }
468
469 /*
470 * Check whether stdout and stderr are physically same.
471 * This is in order to decide whether we need to redirect
472 * stderr separately from stdout.
473 * This check is performed only if __DMAKE_SEPARATE_STDERR
474 * is not set. This variable may be used in order to preserve
475 * the 'old' behaviour.
476 */
477 out_err_same = true;
478 char * dmake_sep_var = getenv(NOCATGETS("__DMAKE_SEPARATE_STDERR"));
479 if (dmake_sep_var == NULL || (0 != strcasecmp(dmake_sep_var, NOCATGETS("NO")))) {
480 struct stat stdout_stat;
481 struct stat stderr_stat;
482 if( (fstat(1, &stdout_stat) == 0)
483 && (fstat(2, &stderr_stat) == 0) )
484 {
485 if( (stdout_stat.st_dev != stderr_stat.st_dev)
486 || (stdout_stat.st_ino != stderr_stat.st_ino) )
487 {
488 out_err_same = false;
489 }
490 }
491 }
492
493
494 /*
495 * Enable interrupt handler for alarms
496 */
497 (void) bsd_signal(SIGALRM, (SIG_PF)doalarm);
498
499 /*
500 * Check if make should report
501 */
502 if (getenv(sunpro_dependencies->string_mb) != NULL) {
503 FILE *report_file;
504
505 report_dependency("");
506 report_file = get_report_file();
507 if ((report_file != NULL) && (report_file != (FILE*)-1)) {
508 (void) fprintf(report_file, "\n");
509 }
510 }
511
648 printf(
649 NOCATGETS(" Env (%ld): %ld Kb (%ld bytes)\n"),
650 env_alloc_num,
651 env_alloc_bytes/1000,
652 env_alloc_bytes
653 );
654
655 }
656 #endif
657
658 parallel = false;
659 /* If we used the SVR4_MAKE, don't build .DONE or .FAILED */
660 if (!getenv(USE_SVR4_MAKE)){
661 /* Build the target .DONE or .FAILED if we caught an error */
662 if (!quest && !list_all_targets) {
663 Name failed_name;
664
665 MBSTOWCS(wcs_buffer, NOCATGETS(".FAILED"));
666 failed_name = GETNAME(wcs_buffer, FIND_LENGTH);
667 if ((exit_status != 0) && (failed_name->prop != NULL)) {
668 /*
669 * [tolik] switch DMake to serial mode
670 */
671 dmake_mode_type = serial_mode;
672 no_parallel = true;
673 (void) doname(failed_name, false, true);
674 } else {
675 if (!trace_status) {
676 /*
677 * Switch DMake to serial mode
678 */
679 dmake_mode_type = serial_mode;
680 no_parallel = true;
681 (void) doname(done, false, true);
682 }
683 }
684 }
685 }
686 /*
687 * Remove the temp file utilities report dependencies thru if it
688 * is still around
689 */
690 if (temp_file_name != NULL) {
691 (void) unlink(temp_file_name->string_mb);
692 }
693 /*
694 * Do not save the current command in .make.state if make
695 * was interrupted.
696 */
697 if (current_line != NULL) {
698 command_changed = true;
699 current_line->body.line.command_used = NULL;
700 }
763 Running rp;
764
765 (void) fflush(stdout);
766 if (childPid > 0) {
767 kill(childPid, SIGTERM);
768 childPid = -1;
769 }
770 for (rp = running_list; rp != NULL; rp = rp->next) {
771 if (rp->state != build_running) {
772 continue;
773 }
774 if (rp->pid > 0) {
775 kill(rp->pid, SIGTERM);
776 rp->pid = -1;
777 }
778 }
779 if (getpid() == getpgrp()) {
780 bsd_signal(SIGTERM, SIG_IGN);
781 kill (-getpid(), SIGTERM);
782 }
783 /* Clean up all parallel/distributed children already finished */
784 finish_children(false);
785
786 /* Make sure the processes running under us terminate first */
787
788 while (wait((int *) NULL) != -1);
789 /* Delete the current targets unless they are precious */
790 if ((current_target != NULL) &&
791 current_target->is_member &&
792 ((member = get_prop(current_target->prop, member_prop)) != NULL)) {
793 current_target = member->body.member.library;
794 }
795 if (!do_not_exec_rule &&
796 !touch &&
797 !quest &&
798 (current_target != NULL) &&
799 !(current_target->stat.is_precious || all_precious)) {
800
801 /* BID_1030811 */
802 /* azv 16 Oct 95 */
803 current_target->stat.time = file_no_time;
804
916 register int ch;
917 int current_optind = 1;
918 int last_optind_with_double_hyphen = 0;
919 int last_optind;
920 int last_current_optind;
921 register int i;
922 register int j;
923 register int k;
924 register int makefile_next = 0; /*
925 * flag to note options:
926 * -c, f, g, j, m, o
927 */
928 const char *tptr;
929 const char *CMD_OPTS;
930
931 extern char *optarg;
932 extern int optind, opterr, optopt;
933
934 #define SUNPRO_CMD_OPTS "-~Bbc:Ddef:g:ij:K:kM:m:NnO:o:PpqRrSsTtuVvwx:"
935
936 # define SVR4_CMD_OPTS "-c:ef:g:ij:km:nO:o:pqrsTtVv"
937
938 /*
939 * Added V in SVR4_CMD_OPTS also, which is going to be a hidden
940 * option, just to make sure that the getopt doesn't fail when some
941 * users leave their USE_SVR4_MAKE set and try to use the makefiles
942 * that are designed to issue commands like $(MAKE) -V. Anyway it
943 * sets the same flag but ensures that getopt doesn't fail.
944 */
945
946 opterr = 0;
947 optind = 1;
948 while (1) {
949 last_optind=optind; /* Save optind and current_optind values */
950 last_current_optind=current_optind; /* in case we have to repeat this round. */
951 if (svr4) {
952 CMD_OPTS=SVR4_CMD_OPTS;
953 ch = getopt(argc, argv, SVR4_CMD_OPTS);
954 } else {
955 CMD_OPTS=SUNPRO_CMD_OPTS;
956 ch = getopt(argc, argv, SUNPRO_CMD_OPTS);
993
994 /* Eliminate first hyphen character */
995 for (j=0; argv[i][j] != '\0'; j++) {
996 argv[i][j] = argv[i][j+1];
997 }
998
999 /* Repeat the processing of this argument */
1000 optind=last_optind;
1001 current_optind=last_current_optind;
1002 continue;
1003 }
1004 }
1005 }
1006 }
1007 }
1008 }
1009 }
1010
1011 if (ch == '?') {
1012 if (svr4) {
1013 fprintf(stderr,
1014 catgets(catd, 1, 267, "Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1015 fprintf(stderr,
1016 catgets(catd, 1, 268, " [ -j dmake_max_jobs ][ -m dmake_mode ][ -o dmake_odir ]...\n"));
1017 fprintf(stderr,
1018 catgets(catd, 1, 269, " [ -e ][ -i ][ -k ][ -n ][ -p ][ -q ][ -r ][ -s ][ -t ][ -v ]\n"));
1019 tptr = strchr(SVR4_CMD_OPTS, optopt);
1020 } else {
1021 fprintf(stderr,
1022 catgets(catd, 1, 272, "Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1023 fprintf(stderr,
1024 catgets(catd, 1, 273, " [ -j dmake_max_jobs ][ -K statefile ][ -m dmake_mode ][ -x MODE_NAME=VALUE ][ -o dmake_odir ]...\n"));
1025 fprintf(stderr,
1026 catgets(catd, 1, 274, " [ -d ][ -dd ][ -D ][ -DD ][ -e ][ -i ][ -k ][ -n ][ -p ][ -P ][ -u ][ -w ]\n"));
1027 fprintf(stderr,
1028 catgets(catd, 1, 275, " [ -q ][ -r ][ -s ][ -S ][ -t ][ -v ][ -V ][ target... ][ macro=value... ][ \"macro +=value\"... ]\n"));
1029 tptr = strchr(SUNPRO_CMD_OPTS, optopt);
1030 }
1031 if (!tptr) {
1032 fatal(catgets(catd, 1, 279, "Unknown option `-%c'"), optopt);
1033 } else {
1034 fatal(catgets(catd, 1, 280, "Missing argument after `-%c'"), optopt);
1035 }
1036 }
1037
1038
1039
1040 makefile_next |= parse_command_option(ch);
1041 /*
1042 * If we're done processing all of the options of
1043 * ONE argument string...
1044 */
1045 if (current_optind < optind) {
1046 i = current_optind;
1047 k = 0;
1048 /* If there's an argument for an option... */
1049 if ((optind - current_optind) > 1) {
1050 k = i + 1;
1051 }
1052 switch (makefile_next) {
1053 case 0:
1054 argv[i] = NULL;
1055 /* This shouldn't happen */
1056 if (k) {
1057 argv[k] = NULL;
1058 }
1059 break;
1060 case 1: /* -f seen */
1061 argv[i] = (char *)NOCATGETS("-f");
1062 break;
1063 case 2: /* -c seen */
1064 argv[i] = (char *)NOCATGETS("-c");
1065 break;
1066 case 4: /* -g seen */
1067 argv[i] = (char *)NOCATGETS("-g");
1068 break;
1069 case 8: /* -j seen */
1070 argv[i] = (char *)NOCATGETS("-j");
1071 break;
1072 case 16: /* -M seen */
1073 argv[i] = (char *)NOCATGETS("-M");
1074 break;
1075 case 32: /* -m seen */
1076 argv[i] = (char *)NOCATGETS("-m");
1077 break;
1078 case 128: /* -O seen */
1079 argv[i] = (char *)NOCATGETS("-O");
1080 break;
1081 case 256: /* -K seen */
1082 argv[i] = (char *)NOCATGETS("-K");
1083 break;
1084 case 512: /* -o seen */
1085 argv[i] = (char *)NOCATGETS("-o");
1086 break;
1087 case 1024: /* -x seen */
1088 argv[i] = (char *)NOCATGETS("-x");
1089 break;
1090 default: /* > 1 of -c, f, g, j, K, M, m, O, o, x seen */
1091 fatal(catgets(catd, 1, 286, "Illegal command line. More than one option requiring\nan argument given in the same argument group"));
1092 }
1093
1094 makefile_next = 0;
1095 current_optind = optind;
1096 }
1097 }
1098 }
1099
1100 static void
1101 quote_str(char *str, char *qstr)
1102 {
1103 char *to;
1104 char *from;
1105
1106 to = qstr;
1107 for (from = str; *from; from++) {
1108 switch (*from) {
1451 report_dependencies_level++;
1452 }
1453 return 0;
1454 case 'p': /* Print description */
1455 if (invert_this) {
1456 trace_status = false;
1457 do_not_exec_rule = false;
1458 } else {
1459 trace_status = true;
1460 do_not_exec_rule = true;
1461 }
1462 return 0;
1463 case 'q': /* Question flag */
1464 if (invert_this) {
1465 quest = false;
1466 } else {
1467 quest = true;
1468 }
1469 return 0;
1470 case 'R': /* Don't run in parallel */
1471 if (invert_this) {
1472 pmake_cap_r_specified = false;
1473 no_parallel = false;
1474 } else {
1475 pmake_cap_r_specified = true;
1476 dmake_mode_type = serial_mode;
1477 no_parallel = true;
1478 }
1479 return 0;
1480 case 'r': /* Turn off internal rules */
1481 if (invert_this) {
1482 ignore_default_mk = false;
1483 } else {
1484 ignore_default_mk = true;
1485 }
1486 return 0;
1487 case 'S': /* Reverse -k */
1488 if (invert_this) {
1489 continue_after_error = true;
1490 } else {
1491 continue_after_error = false;
1492 stop_after_error_ever_seen = true;
1493 }
1494 return 0;
1495 case 's': /* Silent flag */
1496 if (invert_this) {
1497 silent_all = false;
1498 } else {
1511 case 't': /* Touch flag */
1512 if (invert_this) {
1513 touch = false;
1514 } else {
1515 touch = true;
1516 }
1517 return 0;
1518 case 'u': /* Unconditional flag */
1519 if (invert_this) {
1520 build_unconditional = false;
1521 } else {
1522 build_unconditional = true;
1523 }
1524 return 0;
1525 case 'V': /* SVR4 mode */
1526 svr4 = true;
1527 return 0;
1528 case 'v': /* Version flag */
1529 if (invert_this) {
1530 } else {
1531 fprintf(stdout, NOCATGETS("dmake: %s\n"), verstring);
1532 exit_status = 0;
1533 exit(0);
1534 }
1535 return 0;
1536 case 'w': /* Unconditional flag */
1537 if (invert_this) {
1538 report_cwd = false;
1539 } else {
1540 report_cwd = true;
1541 }
1542 return 0;
1543 #if 0
1544 case 'X': /* Filter stdout */
1545 if (invert_this) {
1546 filter_stderr = false;
1547 } else {
1548 filter_stderr = true;
1549 }
1550 return 0;
1551 #endif
1552 default:
1553 break;
2778 * init The Name ".INIT", use to run command
2779 * parallel Global parallel building flag
2780 * quest make -q, suppresses messages
2781 * recursion_level Initialized, used for tracing
2782 * report_dependencies make -P, regroves whole process
2783 */
2784 static void
2785 make_targets(int argc, char **argv, Boolean parallel_flag)
2786 {
2787 int i;
2788 char *cp;
2789 Doname result;
2790 register Boolean target_to_make_found = false;
2791
2792 (void) doname(init, true, true);
2793 recursion_level = 1;
2794 parallel = parallel_flag;
2795 /*
2796 * make remaining args
2797 */
2798 /*
2799 if ((report_dependencies_level == 0) && parallel) {
2800 */
2801 if (parallel) {
2802 /*
2803 * If building targets in parallel, start all of the
2804 * remaining args to build in parallel.
2805 */
2806 for (i = 1; i < argc; i++) {
2807 if ((cp = argv[i]) != NULL) {
2808 commands_done = false;
2809 if ((cp[0] == (int) period_char) &&
2810 (cp[1] == (int) slash_char)) {
2811 cp += 2;
2812 }
2813 if((cp[0] == (int) ' ') &&
2814 (cp[1] == (int) '-') &&
2815 (cp[2] == (int) ' ') &&
2816 (cp[3] == (int) '-')) {
2817 argv[i] = NULL;
2858 (void) printf(catgets(catd, 1, 294, "`%s': no action was taken.\n"),
2859 default_target_to_build->string_mb);
2860 }
2861 }
2862 } else {
2863 default_target_to_build->stat.time = file_no_time;
2864 if (!commands_done &&
2865 (exists(default_target_to_build) > file_doesnt_exist)) {
2866 (void) printf(catgets(catd, 1, 295, "`%s' is up to date.\n"),
2867 default_target_to_build->string_mb);
2868 }
2869 }
2870 }
2871 }
2872 }
2873 /* Now wait for all of the targets to finish running */
2874 finish_running();
2875 // setjmp(jmpbuffer);
2876
2877 }
2878 for (i = 1; i < argc; i++) {
2879 if ((cp = argv[i]) != NULL) {
2880 target_to_make_found = true;
2881 if ((cp[0] == (int) period_char) &&
2882 (cp[1] == (int) slash_char)) {
2883 cp += 2;
2884 }
2885 if((cp[0] == (int) ' ') &&
2886 (cp[1] == (int) '-') &&
2887 (cp[2] == (int) ' ') &&
2888 (cp[3] == (int) '-')) {
2889 argv[i] = NULL;
2890 continue;
2891 }
2892 MBSTOWCS(wcs_buffer, cp);
2893 default_target_to_build = normalize_name(wcs_buffer, wslen(wcs_buffer));
2894 top_level_target = get_wstring(default_target_to_build->string_mb);
2895 report_recursion(default_target_to_build);
2896 commands_done = false;
2897 if (parallel) {
2949
2950 /*
2951 * If no file arguments have been encountered,
2952 * make the first name encountered that doesnt start with a dot
2953 */
2954 if (!target_to_make_found) {
2955 if (default_target_to_build == NULL) {
2956 fatal(catgets(catd, 1, 202, "No arguments to build"));
2957 }
2958 commands_done = false;
2959 top_level_target = get_wstring(default_target_to_build->string_mb);
2960 report_recursion(default_target_to_build);
2961
2962
2963 if (getenv(NOCATGETS("SPRO_EXPAND_ERRORS"))){
2964 (void) printf(NOCATGETS("::(%s)\n"),
2965 default_target_to_build->string_mb);
2966 }
2967
2968
2969 result = doname_parallel(default_target_to_build, true, false);
2970 gather_recursive_deps();
2971 if (build_failed_seen) {
2972 build_failed_ever_seen = true;
2973 warning(catgets(catd, 1, 203, "Target `%s' not remade because of errors"),
2974 default_target_to_build->string_mb);
2975 }
2976 build_failed_seen = false;
2977 if (report_dependencies_level > 0) {
2978 print_dependencies(default_target_to_build,
2979 get_prop(default_target_to_build->
2980 prop,
2981 line_prop));
2982 }
2983 default_target_to_build->stat.time = file_no_time;
2984 if (default_target_to_build->colon_splits > 0) {
2985 default_target_to_build->state = build_dont_know;
2986 }
2987 if (/* !commands_done && */
2988 (result == build_ok) &&
2989 !quest &&
3217 int make_level_val = 0;
3218
3219 make_level_str = getenv(NOCATGETS("MAKELEVEL"));
3220 if(make_level_str) {
3221 make_level_val = atoi(make_level_str);
3222 }
3223 if(mlev == NULL) {
3224 mlev = (char*) malloc(MAXPATHLEN);
3225 }
3226 if(entering) {
3227 sprintf(mlev, NOCATGETS("MAKELEVEL=%d"), make_level_val + 1);
3228 } else {
3229 make_level_val--;
3230 sprintf(mlev, NOCATGETS("MAKELEVEL=%d"), make_level_val);
3231 }
3232 putenv(mlev);
3233
3234 if(report_cwd) {
3235 if(make_level_val <= 0) {
3236 if(entering) {
3237 sprintf( rcwd
3238 , catgets(catd, 1, 329, "dmake: Entering directory `%s'\n")
3239 , get_current_path());
3240 } else {
3241 sprintf( rcwd
3242 , catgets(catd, 1, 331, "dmake: Leaving directory `%s'\n")
3243 , get_current_path());
3244 }
3245 } else {
3246 if(entering) {
3247 sprintf( rcwd
3248 , catgets(catd, 1, 333, "dmake[%d]: Entering directory `%s'\n")
3249 , make_level_val, get_current_path());
3250 } else {
3251 sprintf( rcwd
3252 , catgets(catd, 1, 335, "dmake[%d]: Leaving directory `%s'\n")
3253 , make_level_val, get_current_path());
3254 }
3255 }
3256 printf(NOCATGETS("%s"), rcwd);
3257 }
3258 }
|