4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
29 * make program main routine plus some helper routines
35 #include <bsd/bsd.h> /* bsd_signal() */
38 #include <locale.h> /* setlocale() */
41 #include <mksh/macro.h> /* getvar() */
42 #include <mksh/misc.h> /* getmem(), setup_char_semantics() */
44 #include <pwd.h> /* getpwnam() */
48 #include <sys/errno.h> /* ENOENT */
49 #include <sys/stat.h> /* fstat() */
50 #include <fcntl.h> /* open() */
52 # include <sys/systeminfo.h> /* sysinfo() */
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() */
60 extern Name
normalize_name(register wchar_t *name_string
, register int length
);
62 extern void job_adjust_fini();
68 #define LD_SUPPORT_ENV_VAR "SGS_SUPPORT_32"
69 #define LD_SUPPORT_ENV_VAR_32 "SGS_SUPPORT_32"
70 #define LD_SUPPORT_ENV_VAR_64 "SGS_SUPPORT_64"
71 #define LD_SUPPORT_MAKE_LIB "libmakestate.so.1"
73 #define LD_SUPPORT_MAKE_ARCH "i386"
75 #define LD_SUPPORT_MAKE_ARCH "sparc"
77 #error "Unsupported architecture"
87 static char *argv_zero_string
;
88 static Boolean build_failed_ever_seen
;
89 static Boolean continue_after_error_ever_seen
; /* `-k' */
90 static Boolean dmake_group_specified
; /* `-g' */
91 static Boolean dmake_max_jobs_specified
; /* `-j' */
92 static Boolean dmake_mode_specified
; /* `-m' */
93 static Boolean dmake_add_mode_specified
; /* `-x' */
94 static Boolean dmake_output_mode_specified
; /* `-x DMAKE_OUTPUT_MODE=' */
95 static Boolean dmake_compat_mode_specified
; /* `-x SUN_MAKE_COMPAT_MODE=' */
96 static Boolean dmake_odir_specified
; /* `-o' */
97 static Boolean dmake_rcfile_specified
; /* `-c' */
98 static Boolean env_wins
; /* `-e' */
99 static Boolean ignore_default_mk
; /* `-r' */
100 static Boolean list_all_targets
; /* `-T' */
102 static char **mf_argv
;
103 static Dependency_rec not_auto_depen_struct
;
104 static Dependency not_auto_depen
= ¬_auto_depen_struct
;
105 static Boolean pmake_cap_r_specified
; /* `-R' */
106 static Boolean pmake_machinesfile_specified
; /* `-M' */
107 static Boolean stop_after_error_ever_seen
; /* `-S' */
108 static Boolean trace_status
; /* `-p' */
109 static char *working_dir
; /* `-C' */
111 #ifdef DMAKE_STATISTICS
112 static Boolean getname_stat
= false;
115 static time_t start_time
;
117 static char **g_argv
;
120 * File table of contents
122 extern "C" void cleanup_after_exit(void);
125 extern void dmake_exit_callback(void);
126 extern void dmake_message_callback(char *);
129 extern Name
normalize_name(register wchar_t *name_string
, register int length
);
131 extern int main(int, char * []);
133 static void append_makeflags_string(Name
, String
);
134 static void doalarm(int);
135 static void enter_argv_values(int , char **, ASCII_Dyn_Array
*);
136 static void make_targets(int, char **, Boolean
);
137 static int parse_command_option(char);
138 static void read_command_options(int, char **);
139 static void read_environment(Boolean
);
140 static void read_files_and_state(int, char **);
141 static Boolean
read_makefile(Name
, Boolean
, Boolean
, Boolean
);
142 static void report_recursion(Name
);
143 static void set_sgs_support(void);
144 static void setup_for_projectdir(void);
145 static void setup_makeflags_argv(void);
146 static void report_dir_enter_leave(Boolean entering
);
148 extern void expand_value(Name
, register String
, Boolean
);
150 static const char verstring
[] = "illumos make";
158 * argc You know what this is
159 * argv You know what this is
161 * Static variables used:
162 * list_all_targets make -T seen
163 * trace_status make -p seen
165 * Global variables used:
166 * debug_level Should we trace make actions?
167 * keep_state Set if .KEEP_STATE seen
168 * makeflags The Name "MAKEFLAGS", used to get macro
169 * remote_command_name Name of remote invocation cmd ("on")
170 * running_list List of parallel running processes
171 * stdout_stderr_same true if stdout and stderr are the same
172 * auto_dependencies The Name "SUNPRO_DEPENDENCIES"
173 * temp_file_directory Set to the dir where we create tmp file
174 * trace_reader Set to reflect tracing status
175 * working_on_targets Set when building user targets
178 main(int argc
, char *argv
[])
181 * cp is a -> to the value of the MAKEFLAGS env var,
182 * which has to be regular chars.
185 char make_state_dir
[MAXPATHLEN
];
186 Boolean parallel_flag
= false;
191 struct itimerval value
;
192 char def_dmakerc_path
[MAXPATHLEN
];
193 Name dmake_name
, dmake_name2
;
194 Name dmake_value
, dmake_value2
;
195 Property prop
, prop2
;
199 struct stat out_stat
, err_stat
;
200 hostid
= gethostid();
203 (void) setlocale(LC_ALL
, "");
206 #ifdef DMAKE_STATISTICS
207 if (getenv("DMAKE_STATISTICS")) {
213 #define TEXT_DOMAIN "SYS_TEST"
215 textdomain(TEXT_DOMAIN
);
218 g_argv
= (char **) malloc((g_argc
+ 1) * sizeof(char *));
219 for (i
= 0; i
< argc
; i
++) {
225 * Set argv_zero_string to some form of argv[0] for
226 * recursive MAKE builds.
229 if (*argv
[0] == (int) slash_char
) {
230 /* argv[0] starts with a slash */
231 argv_zero_string
= strdup(argv
[0]);
232 } else if (strchr(argv
[0], (int) slash_char
) == NULL
) {
233 /* argv[0] contains no slashes */
234 argv_zero_string
= strdup(argv
[0]);
237 * argv[0] contains at least one slash,
238 * but doesn't start with a slash
240 char *tmp_current_path
;
243 tmp_current_path
= get_current_path();
244 tmp_string
= getmem(strlen(tmp_current_path
) + 1 +
245 strlen(argv
[0]) + 1);
246 (void) sprintf(tmp_string
,
250 argv_zero_string
= strdup(tmp_string
);
251 retmem_mb(tmp_string
);
255 * The following flags are reset if we don't have the
256 * (.nse_depinfo or .make.state) files locked and only set
257 * AFTER the file has been locked. This ensures that if the user
258 * interrupts the program while file_lock() is waiting to lock
259 * the file, the interrupt handler doesn't remove a lock
260 * that doesn't belong to us.
262 make_state_lockfile
= NULL
;
263 make_state_locked
= false;
267 * look for last slash char in the path to look at the binary
268 * name. This is to resolve the hard link and invoke make
272 /* Sun OS make standart */
275 if(!strcmp(argv_zero_string
, "/usr/bin/make")) {
279 prognameptr
= strrchr(argv
[0], '/');
283 prognameptr
= argv
[0];
285 if(!strcmp(prognameptr
, "svr4.make")) {
290 if (getenv(USE_SVR4_MAKE
) || getenv("USE_SVID")){
296 * Find the dmake_compat_mode: posix, sun, svr4, or gnu_style, .
298 char * dmake_compat_mode_var
= getenv("SUN_MAKE_COMPAT_MODE");
299 if (dmake_compat_mode_var
!= NULL
) {
300 if (0 == strcasecmp(dmake_compat_mode_var
, "GNU")) {
308 * Temporary directory set up.
310 char * tmpdir_var
= getenv("TMPDIR");
311 if (tmpdir_var
!= NULL
&& *tmpdir_var
== '/' && strlen(tmpdir_var
) < MAXPATHLEN
) {
312 strcpy(mbs_buffer
, tmpdir_var
);
313 for (tmpdir_var
= mbs_buffer
+strlen(mbs_buffer
);
314 *(--tmpdir_var
) == '/' && tmpdir_var
> mbs_buffer
;
316 if (strlen(mbs_buffer
) + 32 < MAXPATHLEN
) { /* 32 = strlen("/dmake.stdout.%d.%d.XXXXXX") */
317 sprintf(mbs_buffer2
, "%s/dmake.tst.%d.XXXXXX",
318 mbs_buffer
, getpid());
319 int fd
= mkstemp(mbs_buffer2
);
323 tmpdir
= strdup(mbs_buffer
);
328 /* find out if stdout and stderr point to the same place */
329 if (fstat(1, &out_stat
) < 0) {
330 fatal(gettext("fstat of standard out failed: %s"), errmsg(errno
));
332 if (fstat(2, &err_stat
) < 0) {
333 fatal(gettext("fstat of standard error failed: %s"), errmsg(errno
));
335 if ((out_stat
.st_dev
== err_stat
.st_dev
) &&
336 (out_stat
.st_ino
== err_stat
.st_ino
)) {
337 stdout_stderr_same
= true;
339 stdout_stderr_same
= false;
341 /* Make the vroot package scan the path using shell semantics */
344 setup_char_semantics();
346 setup_for_projectdir();
349 * If running with .KEEP_STATE, curdir will be set with
350 * the connected directory.
352 (void) atexit(cleanup_after_exit
);
357 * Set command line flags
359 setup_makeflags_argv();
360 read_command_options(mf_argc
, mf_argv
);
361 read_command_options(argc
, argv
);
362 if (debug_level
> 0) {
363 cp
= getenv(makeflags
->string_mb
);
364 (void) printf(gettext("MAKEFLAGS value: %s\n"), cp
== NULL
? "" : cp
);
367 setup_interrupt(handle_interrupt
);
371 report_dir_enter_leave(true);
372 printf(gettext("%s: Entering directory `%s'\n"),
373 getprogname(), get_current_path());
376 read_files_and_state(argc
, argv
);
379 * Find the dmake_output_mode: TXT1, TXT2 or HTML1.
381 MBSTOWCS(wcs_buffer
, "DMAKE_OUTPUT_MODE");
382 dmake_name2
= GETNAME(wcs_buffer
, FIND_LENGTH
);
383 prop2
= get_prop(dmake_name2
->prop
, macro_prop
);
385 /* DMAKE_OUTPUT_MODE not defined, default to TXT1 mode */
386 output_mode
= txt1_mode
;
388 dmake_value2
= prop2
->body
.macro
.value
;
389 if ((dmake_value2
== NULL
) ||
390 (IS_EQUAL(dmake_value2
->string_mb
, "TXT1"))) {
391 output_mode
= txt1_mode
;
392 } else if (IS_EQUAL(dmake_value2
->string_mb
, "TXT2")) {
393 output_mode
= txt2_mode
;
394 } else if (IS_EQUAL(dmake_value2
->string_mb
, "HTML1")) {
395 output_mode
= html1_mode
;
397 warning(gettext("Unsupported value `%s' for DMAKE_OUTPUT_MODE after -x flag (ignored)"),
398 dmake_value2
->string_mb
);
402 * Find the dmake_mode: parallel, or serial.
404 if ((!pmake_cap_r_specified
) &&
405 (!pmake_machinesfile_specified
)) {
408 if ((s
= strdup(argv
[0])) == NULL
)
409 fatal(gettext("Out of memory"));
413 MBSTOWCS(wcs_buffer
, "DMAKE_MODE");
414 dmake_name2
= GETNAME(wcs_buffer
, FIND_LENGTH
);
415 prop2
= get_prop(dmake_name2
->prop
, macro_prop
);
416 // If we're invoked as 'make' run serially, regardless of DMAKE_MODE
417 // If we're invoked as 'make' but passed -j, run parallel
418 // If we're invoked as 'dmake', without DMAKE_MODE, default parallel
419 // If we're invoked as 'dmake' and DMAKE_MODE is set, honour it.
420 if ((strcmp(b
, "make") == 0) &&
421 !dmake_max_jobs_specified
) {
422 dmake_mode_type
= serial_mode
;
424 } else if (prop2
== NULL
) {
425 /* DMAKE_MODE not defined, default based on our name */
426 if (strcmp(b
, "dmake") == 0) {
427 dmake_mode_type
= parallel_mode
;
431 dmake_value2
= prop2
->body
.macro
.value
;
432 if (IS_EQUAL(dmake_value2
->string_mb
, "parallel")) {
433 dmake_mode_type
= parallel_mode
;
435 } else if (IS_EQUAL(dmake_value2
->string_mb
, "serial")) {
436 dmake_mode_type
= serial_mode
;
439 fatal(gettext("Unknown dmake mode argument `%s' after -m flag"), dmake_value2
->string_mb
);
445 parallel_flag
= true;
446 putenv(strdup("DMAKE_CHILD=TRUE"));
449 // If dmake is running with -t option, set dmake_mode_type to serial.
450 // This is done because doname() calls touch_command() that runs serially.
451 // If we do not do that, maketool will have problems.
454 dmake_mode_type
= serial_mode
;
459 * Check whether stdout and stderr are physically same.
460 * This is in order to decide whether we need to redirect
461 * stderr separately from stdout.
462 * This check is performed only if __DMAKE_SEPARATE_STDERR
463 * is not set. This variable may be used in order to preserve
464 * the 'old' behaviour.
467 char * dmake_sep_var
= getenv("__DMAKE_SEPARATE_STDERR");
468 if (dmake_sep_var
== NULL
|| (0 != strcasecmp(dmake_sep_var
, "NO"))) {
469 struct stat stdout_stat
;
470 struct stat stderr_stat
;
471 if( (fstat(1, &stdout_stat
) == 0)
472 && (fstat(2, &stderr_stat
) == 0) )
474 if( (stdout_stat
.st_dev
!= stderr_stat
.st_dev
)
475 || (stdout_stat
.st_ino
!= stderr_stat
.st_ino
) )
477 out_err_same
= false;
484 * Enable interrupt handler for alarms
486 (void) bsd_signal(SIGALRM
, (SIG_PF
)doalarm
);
489 * Check if make should report
491 if (getenv(sunpro_dependencies
->string_mb
) != NULL
) {
494 report_dependency("");
495 report_file
= get_report_file();
496 if ((report_file
!= NULL
) && (report_file
!= (FILE*)-1)) {
497 (void) fprintf(report_file
, "\n");
502 * Make sure SUNPRO_DEPENDENCIES is exported (or not) properly.
505 maybe_append_prop(sunpro_dependencies
, macro_prop
)->
506 body
.macro
.exported
= true;
508 maybe_append_prop(sunpro_dependencies
, macro_prop
)->
509 body
.macro
.exported
= false;
512 working_on_targets
= true;
520 if (list_all_targets
) {
527 trace_reader
= false;
530 * Set temp_file_directory to the directory the .make.state
531 * file is written to.
533 if ((slash_ptr
= strrchr(make_state
->string_mb
, (int) slash_char
)) == NULL
) {
534 temp_file_directory
= strdup(get_current_path());
536 *slash_ptr
= (int) nul_char
;
537 (void) strcpy(make_state_dir
, make_state
->string_mb
);
538 *slash_ptr
= (int) slash_char
;
539 /* when there is only one slash and it's the first
540 ** character, make_state_dir should point to '/'.
542 if(make_state_dir
[0] == '\0') {
543 make_state_dir
[0] = '/';
544 make_state_dir
[1] = '\0';
546 if (make_state_dir
[0] == (int) slash_char
) {
547 temp_file_directory
= strdup(make_state_dir
);
549 char tmp_current_path2
[MAXPATHLEN
];
551 (void) sprintf(tmp_current_path2
,
555 temp_file_directory
= strdup(tmp_current_path2
);
560 report_dir_enter_leave(true);
562 make_targets(argc
, argv
, parallel_flag
);
564 report_dir_enter_leave(false);
566 if (build_failed_ever_seen
) {
578 * cleanup_after_exit()
580 * Called from exit(), performs cleanup actions.
583 * status The argument exit() was called with
584 * arg Address of an argument vector to
585 * cleanup_after_exit()
587 * Global variables used:
588 * command_changed Set if we think .make.state should be rewritten
589 * current_line Is set we set commands_changed
592 * done The Name ".DONE", rule we run
593 * keep_state Set if .KEEP_STATE seen
594 * parallel True if building in parallel
595 * quest If -q is on we do not run .DONE
596 * report_dependencies
598 * running_list List of parallel running processes
599 * temp_file_name The temp file is removed, if any
602 cleanup_after_exit(void)
606 extern long getname_bytes_count
;
607 extern long getname_names_count
;
608 extern long getname_struct_count
;
609 extern long freename_bytes_count
;
610 extern long freename_names_count
;
611 extern long freename_struct_count
;
612 extern long other_alloc
;
614 extern long env_alloc_num
;
615 extern long env_alloc_bytes
;
618 #ifdef DMAKE_STATISTICS
620 printf(">>> Getname statistics:\n");
621 printf(" Allocated:\n");
622 printf(" Names: %ld\n", getname_names_count
);
623 printf(" Strings: %ld Kb (%ld bytes)\n", getname_bytes_count
/1000, getname_bytes_count
);
624 printf(" Structs: %ld Kb (%ld bytes)\n", getname_struct_count
/1000, getname_struct_count
);
625 printf(" Total bytes: %ld Kb (%ld bytes)\n", getname_struct_count
/1000 + getname_bytes_count
/1000, getname_struct_count
+ getname_bytes_count
);
627 printf("\n Unallocated: %ld\n", freename_names_count
);
628 printf(" Names: %ld\n", freename_names_count
);
629 printf(" Strings: %ld Kb (%ld bytes)\n", freename_bytes_count
/1000, freename_bytes_count
);
630 printf(" Structs: %ld Kb (%ld bytes)\n", freename_struct_count
/1000, freename_struct_count
);
631 printf(" Total bytes: %ld Kb (%ld bytes)\n", freename_struct_count
/1000 + freename_bytes_count
/1000, freename_struct_count
+ freename_bytes_count
);
633 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
));
635 printf("\n>>> Other:\n");
637 " Env (%ld): %ld Kb (%ld bytes)\n",
639 env_alloc_bytes
/1000,
647 /* If we used the SVR4_MAKE, don't build .DONE or .FAILED */
648 if (!getenv(USE_SVR4_MAKE
)){
649 /* Build the target .DONE or .FAILED if we caught an error */
650 if (!quest
&& !list_all_targets
) {
653 MBSTOWCS(wcs_buffer
, ".FAILED");
654 failed_name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
655 if ((exit_status
!= 0) && (failed_name
->prop
!= NULL
)) {
657 * [tolik] switch DMake to serial mode
659 dmake_mode_type
= serial_mode
;
661 (void) doname(failed_name
, false, true);
665 * Switch DMake to serial mode
667 dmake_mode_type
= serial_mode
;
669 (void) doname(done
, false, true);
675 * Remove the temp file utilities report dependencies thru if it
678 if (temp_file_name
!= NULL
) {
679 (void) unlink(temp_file_name
->string_mb
);
682 * Do not save the current command in .make.state if make
685 if (current_line
!= NULL
) {
686 command_changed
= true;
687 current_line
->body
.line
.command_used
= NULL
;
690 * For each parallel build process running, remove the temp files
691 * and zap the command line so it won't be put in .make.state
693 for (rp
= running_list
; rp
!= NULL
; rp
= rp
->next
) {
694 if (rp
->temp_file
!= NULL
) {
695 (void) unlink(rp
->temp_file
->string_mb
);
697 if (rp
->stdout_file
!= NULL
) {
698 (void) unlink(rp
->stdout_file
);
699 retmem_mb(rp
->stdout_file
);
700 rp
->stdout_file
= NULL
;
702 if (rp
->stderr_file
!= NULL
) {
703 (void) unlink(rp
->stderr_file
);
704 retmem_mb(rp
->stderr_file
);
705 rp
->stderr_file
= NULL
;
707 command_changed
= true;
709 line = get_prop(rp->target->prop, line_prop);
711 line->body.line.command_used = NULL;
715 /* Remove the statefile lock file if the file has been locked */
716 if ((make_state_lockfile
!= NULL
) && (make_state_locked
)) {
717 (void) unlink(make_state_lockfile
);
718 make_state_lockfile
= NULL
;
719 make_state_locked
= false;
721 /* Write .make.state */
722 write_state_file(1, (Boolean
) 1);
730 * This is where C-C traps are caught.
734 * Global variables used (except DMake 1.0):
735 * current_target Sometimes the current target is removed
736 * do_not_exec_rule But not if -n is on
738 * running_list List of parallel running processes
739 * touch Current target is not removed if -t on
742 handle_interrupt(int)
747 (void) fflush(stdout
);
749 kill(childPid
, SIGTERM
);
752 for (rp
= running_list
; rp
!= NULL
; rp
= rp
->next
) {
753 if (rp
->state
!= build_running
) {
757 kill(rp
->pid
, SIGTERM
);
761 if (getpid() == getpgrp()) {
762 bsd_signal(SIGTERM
, SIG_IGN
);
763 kill (-getpid(), SIGTERM
);
765 /* Clean up all parallel children already finished */
766 finish_children(false);
768 /* Make sure the processes running under us terminate first */
770 while (wait((int *) NULL
) != -1);
771 /* Delete the current targets unless they are precious */
772 if ((current_target
!= NULL
) &&
773 current_target
->is_member
&&
774 ((member
= get_prop(current_target
->prop
, member_prop
)) != NULL
)) {
775 current_target
= member
->body
.member
.library
;
777 if (!do_not_exec_rule
&&
780 (current_target
!= NULL
) &&
781 !(current_target
->stat
.is_precious
|| all_precious
)) {
785 current_target
->stat
.time
= file_no_time
;
787 if (exists(current_target
) != file_doesnt_exist
) {
788 (void) fprintf(stderr
,
790 current_target
->string_mb
);
791 if (current_target
->stat
.is_dir
) {
792 (void) fprintf(stderr
,
793 gettext("not removed.\n"),
794 current_target
->string_mb
);
795 } else if (unlink(current_target
->string_mb
) == 0) {
796 (void) fprintf(stderr
,
797 gettext("removed.\n"),
798 current_target
->string_mb
);
800 (void) fprintf(stderr
,
801 gettext("could not be removed: %s.\n"),
802 current_target
->string_mb
,
807 for (rp
= running_list
; rp
!= NULL
; rp
= rp
->next
) {
808 if (rp
->state
!= build_running
) {
811 if (rp
->target
->is_member
&&
812 ((member
= get_prop(rp
->target
->prop
, member_prop
)) !=
814 rp
->target
= member
->body
.member
.library
;
816 if (!do_not_exec_rule
&&
819 !(rp
->target
->stat
.is_precious
|| all_precious
)) {
821 rp
->target
->stat
.time
= file_no_time
;
822 if (exists(rp
->target
) != file_doesnt_exist
) {
823 (void) fprintf(stderr
,
825 rp
->target
->string_mb
);
826 if (rp
->target
->stat
.is_dir
) {
827 (void) fprintf(stderr
,
828 gettext("not removed.\n"),
829 rp
->target
->string_mb
);
830 } else if (unlink(rp
->target
->string_mb
) == 0) {
831 (void) fprintf(stderr
,
832 gettext("removed.\n"),
833 rp
->target
->string_mb
);
835 (void) fprintf(stderr
,
836 gettext("could not be removed: %s.\n"),
837 rp
->target
->string_mb
,
845 /* Have we locked .make.state or .nse_depinfo? */
846 if ((make_state_lockfile
!= NULL
) && (make_state_locked
)) {
847 unlink(make_state_lockfile
);
848 make_state_lockfile
= NULL
;
849 make_state_locked
= false;
852 * Re-read .make.state file (it might be changed by recursive make)
856 report_dir_enter_leave(false);
865 * Handle the alarm interrupt but do nothing. Side effect is to
866 * cause return from wait3.
871 * Global variables used:
882 * read_command_options(argc, argv)
884 * Scan the cmd line options and process the ones that start with "-"
887 * -M argument, if any
890 * argc You know what this is
891 * argv You know what this is
893 * Global variables used:
896 read_command_options(register int argc
, register char **argv
)
899 int current_optind
= 1;
900 int last_optind_with_double_hyphen
= 0;
902 int last_current_optind
;
906 register int makefile_next
= 0; /*
907 * flag to note options:
911 const char *CMD_OPTS
;
914 extern int optind
, opterr
, optopt
;
916 #define SUNPRO_CMD_OPTS "-~BbC:c:Ddef:g:ij:K:kM:m:NnO:o:PpqRrSsTtuVvwx:"
918 # define SVR4_CMD_OPTS "-C:c:ef:g:ij:km:nO:o:pqrsTtVv"
921 * Added V in SVR4_CMD_OPTS also, which is going to be a hidden
922 * option, just to make sure that the getopt doesn't fail when some
923 * users leave their USE_SVR4_MAKE set and try to use the makefiles
924 * that are designed to issue commands like $(MAKE) -V. Anyway it
925 * sets the same flag but ensures that getopt doesn't fail.
931 last_optind
=optind
; /* Save optind and current_optind values */
932 last_current_optind
=current_optind
; /* in case we have to repeat this round. */
934 CMD_OPTS
=SVR4_CMD_OPTS
;
935 ch
= getopt(argc
, argv
, SVR4_CMD_OPTS
);
937 CMD_OPTS
=SUNPRO_CMD_OPTS
;
938 ch
= getopt(argc
, argv
, SUNPRO_CMD_OPTS
);
943 * Fixing bug 4102537:
944 * Strange behaviour of command make using -- option.
945 * Not all argv have been processed
946 * Skip non-flag argv and continue processing.
958 /* Bug 5060758: getopt() changed behavior (s10_60),
959 * and now we have to deal with cases when options
960 * with double hyphen appear here, from -$(MAKEFLAGS)
963 if (argv
[i
][0] == '-') {
964 if (argv
[i
][1] == '-') {
965 if (argv
[i
][2] != '\0') {
966 /* Check if this option is allowed */
967 tptr
= strchr(CMD_OPTS
, argv
[i
][2]);
969 if (last_optind_with_double_hyphen
!= current_optind
) {
970 /* This is first time we are trying to fix "--"
971 * problem with this option. If we come here second
972 * time, we will go to fatal error.
974 last_optind_with_double_hyphen
= current_optind
;
976 /* Eliminate first hyphen character */
977 for (j
=0; argv
[i
][j
] != '\0'; j
++) {
978 argv
[i
][j
] = argv
[i
][j
+1];
981 /* Repeat the processing of this argument */
983 current_optind
=last_current_optind
;
996 gettext("Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
998 gettext(" [ -j dmake_max_jobs ][ -m dmake_mode ][ -o dmake_odir ]...\n"));
1000 gettext(" [ -e ][ -i ][ -k ][ -n ][ -p ][ -q ][ -r ][ -s ][ -t ][ -v ]\n"));
1001 tptr
= strchr(SVR4_CMD_OPTS
, optopt
);
1004 gettext("Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1006 gettext(" [ -j dmake_max_jobs ][ -K statefile ][ -m dmake_mode ][ -x MODE_NAME=VALUE ][ -o dmake_odir ]...\n"));
1008 gettext(" [ -d ][ -dd ][ -D ][ -DD ][ -e ][ -i ][ -k ][ -n ][ -p ][ -P ][ -u ][ -w ]\n"));
1010 gettext(" [ -q ][ -r ][ -s ][ -S ][ -t ][ -v ][ -V ][ target... ][ macro=value... ][ \"macro +=value\"... ]\n"));
1011 tptr
= strchr(SUNPRO_CMD_OPTS
, optopt
);
1014 fatal(gettext("Unknown option `-%c'"), optopt
);
1016 fatal(gettext("Missing argument after `-%c'"), optopt
);
1021 working_dir
= optarg
;
1025 makefile_next
|= parse_command_option(ch
);
1027 * If we're done processing all of the options of
1028 * ONE argument string...
1030 if (current_optind
< optind
) {
1033 /* If there's an argument for an option... */
1034 if ((optind
- current_optind
) > 1) {
1037 switch (makefile_next
) {
1040 /* This shouldn't happen */
1045 case 1: /* -f seen */
1046 argv
[i
] = (char *)"-f";
1048 case 2: /* -c seen */
1049 argv
[i
] = (char *)"-c";
1051 case 4: /* -g seen */
1052 argv
[i
] = (char *)"-g";
1054 case 8: /* -j seen */
1055 argv
[i
] = (char *)"-j";
1057 case 16: /* -M seen */
1058 argv
[i
] = (char *)"-M";
1060 case 32: /* -m seen */
1061 argv
[i
] = (char *)"-m";
1063 case 128: /* -O seen */
1064 argv
[i
] = (char *)"-O";
1066 case 256: /* -K seen */
1067 argv
[i
] = (char *)"-K";
1069 case 512: /* -o seen */
1070 argv
[i
] = (char *)"-o";
1072 case 1024: /* -x seen */
1073 argv
[i
] = (char *)"-x";
1075 default: /* > 1 of -c, f, g, j, K, M, m, O, o, x seen */
1076 fatal(gettext("Illegal command line. More than one option requiring\nan argument given in the same argument group"));
1080 current_optind
= optind
;
1086 quote_str(char *str
, char *qstr
)
1092 for (from
= str
; *from
; from
++) {
1094 case ';': /* End of command */
1095 case '(': /* Start group */
1096 case ')': /* End group */
1097 case '{': /* Start group */
1098 case '}': /* End group */
1099 case '[': /* Reg expr - any of a set of chars */
1100 case ']': /* End of set of chars */
1101 case '|': /* Pipe or logical-or */
1102 case '^': /* Old-fashioned pipe */
1103 case '&': /* Background or logical-and */
1104 case '<': /* Redirect stdin */
1105 case '>': /* Redirect stdout */
1106 case '*': /* Reg expr - any sequence of chars */
1107 case '?': /* Reg expr - any single char */
1108 case '$': /* Variable substitution */
1109 case '\'': /* Singe quote - turn off all magic */
1110 case '"': /* Double quote - span whitespace */
1111 case '`': /* Backquote - run a command */
1112 case '#': /* Comment */
1113 case ' ': /* Space (for MACRO=value1 value2 */
1114 case '\\': /* Escape char - turn off magic of next char */
1127 unquote_str(char *str
, char *qstr
)
1133 for (from
= str
; *from
; from
++) {
1134 if (*from
== '\\') {
1143 * Convert the MAKEFLAGS string value into a vector of char *, similar
1147 setup_makeflags_argv()
1159 cp
= getenv(makeflags
->string_mb
);
1164 * If new MAKEFLAGS format, no need to add hyphen.
1165 * If old MAKEFLAGS format, add hyphen before flags.
1168 if ((strchr(cp
, (int) hyphen_char
) != NULL
) ||
1169 (strchr(cp
, (int) equal_char
) != NULL
)) {
1171 /* New MAKEFLAGS format */
1175 /* Check if MAKEFLAGS value begins with multiple
1176 * hyphen characters, and remove all duplicates.
1177 * Usually it happens when the next command is
1178 * used: $(MAKE) -$(MAKEFLAGS)
1180 * This was a workaround for BugID 5060758, but
1181 * appears to have survived as a fix in make.
1184 if (*cp
!= (int) hyphen_char
) {
1188 if (*cp
== (int) hyphen_char
) {
1189 /* There are two hyphens. Skip one */
1194 /* There are hyphens only. Skip all */
1201 /* Old MAKEFLAGS format */
1207 /* Find the number of arguments in MAKEFLAGS */
1209 /* Skip white spaces */
1210 while (cp
&& *cp
&& isspace(*cp
)) {
1214 /* Increment arg count */
1216 /* Go to next white space */
1217 while (cp
&& *cp
&& !isspace(*cp
)) {
1218 if(*cp
== (int) backslash_char
) {
1225 /* Allocate memory for the new MAKEFLAGS argv */
1226 mf_argv
= (char **) malloc((mf_argc
+ 1) * sizeof(char *));
1227 mf_argv
[0] = (char *)"MAKEFLAGS";
1229 * Convert the MAKEFLAGS string value into a vector of char *,
1233 for (i
= 1; i
< mf_argc
; i
++) {
1234 /* Skip white spaces */
1235 while (cp
&& *cp
&& isspace(*cp
)) {
1240 /* Go to next white space */
1241 while (cp
&& *cp
&& !isspace(*cp
)) {
1242 if(*cp
== (int) backslash_char
) {
1248 *cp
= (int) nul_char
;
1250 mf_argv
[i
] = getmem(2 + strlen(cp_orig
));
1251 mf_argv
[i
][0] = '\0';
1252 (void) strcat(mf_argv
[i
], "-");
1253 // (void) strcat(mf_argv[i], cp_orig);
1254 unquote_str(cp_orig
, mf_argv
[i
]+1);
1256 mf_argv
[i
] = getmem(2 + strlen(cp_orig
));
1257 //mf_argv[i] = strdup(cp_orig);
1258 unquote_str(cp_orig
, mf_argv
[i
]);
1267 * parse_command_option(ch)
1269 * Parse make command line options.
1272 * Indicates if any -f -c or -M were seen
1275 * ch The character to parse
1277 * Static variables used:
1278 * dmake_group_specified Set for make -g
1279 * dmake_max_jobs_specified Set for make -j
1280 * dmake_mode_specified Set for make -m
1281 * dmake_add_mode_specified Set for make -x
1282 * dmake_compat_mode_specified Set for make -x SUN_MAKE_COMPAT_MODE=
1283 * dmake_output_mode_specified Set for make -x DMAKE_OUTPUT_MODE=
1284 * dmake_odir_specified Set for make -o
1285 * dmake_rcfile_specified Set for make -c
1286 * env_wins Set for make -e
1287 * ignore_default_mk Set for make -r
1288 * trace_status Set for make -p
1290 * Global variables used:
1291 * .make.state path & name set for make -K
1292 * continue_after_error Set for make -k
1293 * debug_level Set for make -d
1294 * do_not_exec_rule Set for make -n
1295 * filter_stderr Set for make -X
1296 * ignore_errors_all Set for make -i
1297 * no_parallel Set for make -R
1298 * quest Set for make -q
1299 * read_trace_level Set for make -D
1300 * report_dependencies Set for make -P
1301 * silent_all Set for make -s
1302 * touch Set for make -t
1305 parse_command_option(register char ch
)
1307 static int invert_next
= 0;
1308 int invert_this
= invert_next
;
1312 case '-': /* Ignore "--" */
1314 case '~': /* Invert next option */
1317 case 'B': /* Obsolete */
1319 case 'b': /* Obsolete */
1321 case 'C': /* Change directory */
1323 case 'c': /* Read alternative dmakerc file */
1325 dmake_rcfile_specified
= false;
1327 dmake_rcfile_specified
= true;
1330 case 'D': /* Show lines read */
1337 case 'd': /* Debug flag */
1344 case 'e': /* Environment override flag */
1351 case 'f': /* Read alternative makefile(s) */
1353 case 'g': /* Use alternative DMake group */
1355 dmake_group_specified
= false;
1357 dmake_group_specified
= true;
1360 case 'i': /* Ignore errors */
1362 ignore_errors_all
= false;
1364 ignore_errors_all
= true;
1367 case 'j': /* Use alternative DMake max jobs */
1369 dmake_max_jobs_specified
= false;
1371 dmake_mode_type
= parallel_mode
;
1372 no_parallel
= false;
1373 dmake_max_jobs_specified
= true;
1376 case 'K': /* Read alternative .make.state */
1378 case 'k': /* Keep making even after errors */
1380 continue_after_error
= false;
1382 continue_after_error
= true;
1383 continue_after_error_ever_seen
= true;
1386 case 'M': /* Read alternative make.machines file */
1388 pmake_machinesfile_specified
= false;
1390 pmake_machinesfile_specified
= true;
1391 dmake_mode_type
= parallel_mode
;
1392 no_parallel
= false;
1395 case 'm': /* Use alternative DMake build mode */
1397 dmake_mode_specified
= false;
1399 dmake_mode_specified
= true;
1402 case 'x': /* Use alternative DMake mode */
1404 dmake_add_mode_specified
= false;
1406 dmake_add_mode_specified
= true;
1409 case 'N': /* Reverse -n */
1411 do_not_exec_rule
= true;
1413 do_not_exec_rule
= false;
1416 case 'n': /* Print, not exec commands */
1418 do_not_exec_rule
= false;
1420 do_not_exec_rule
= true;
1423 case 'O': /* Integrate with maketool, obsolete */
1425 case 'o': /* Use alternative dmake output dir */
1427 dmake_odir_specified
= false;
1429 dmake_odir_specified
= true;
1432 case 'P': /* Print for selected targets */
1434 report_dependencies_level
--;
1436 report_dependencies_level
++;
1439 case 'p': /* Print description */
1441 trace_status
= false;
1442 do_not_exec_rule
= false;
1444 trace_status
= true;
1445 do_not_exec_rule
= true;
1448 case 'q': /* Question flag */
1455 case 'R': /* Don't run in parallel */
1457 pmake_cap_r_specified
= false;
1458 no_parallel
= false;
1460 pmake_cap_r_specified
= true;
1461 dmake_mode_type
= serial_mode
;
1465 case 'r': /* Turn off internal rules */
1467 ignore_default_mk
= false;
1469 ignore_default_mk
= true;
1472 case 'S': /* Reverse -k */
1474 continue_after_error
= true;
1476 continue_after_error
= false;
1477 stop_after_error_ever_seen
= true;
1480 case 's': /* Silent flag */
1487 case 'T': /* Print target list */
1489 list_all_targets
= false;
1490 do_not_exec_rule
= false;
1492 list_all_targets
= true;
1493 do_not_exec_rule
= true;
1496 case 't': /* Touch flag */
1503 case 'u': /* Unconditional flag */
1505 build_unconditional
= false;
1507 build_unconditional
= true;
1510 case 'V': /* SVR4 mode */
1513 case 'v': /* Version flag */
1516 fprintf(stdout
, "%s: %s\n", getprogname(), verstring
);
1521 case 'w': /* Unconditional flag */
1529 case 'X': /* Filter stdout */
1531 filter_stderr
= false;
1533 filter_stderr
= true;
1544 * setup_for_projectdir()
1546 * Read the PROJECTDIR variable, if defined, and set the sccs path
1550 * Global variables used:
1551 * sccs_dir_path Set to point to SCCS dir to use
1554 setup_for_projectdir(void)
1556 static char path
[MAXPATHLEN
];
1557 char cwdpath
[MAXPATHLEN
];
1561 /* Check if we should use PROJECTDIR when reading the SCCS dir. */
1562 sccs_dir_path
= getenv("PROJECTDIR");
1563 if ((sccs_dir_path
!= NULL
) &&
1564 (sccs_dir_path
[0] != (int) slash_char
)) {
1565 struct passwd
*pwent
;
1569 pwent
= getpwuid(uid
);
1570 if (pwent
== NULL
) {
1571 fatal(gettext("Bogus USERID "));
1573 if ((pwent
= getpwnam(sccs_dir_path
)) == NULL
) {
1574 /*empty block : it'll go & check cwd */
1577 (void) sprintf(path
, "%s/src", pwent
->pw_dir
);
1578 if (access(path
, F_OK
) == 0) {
1579 sccs_dir_path
= path
;
1582 (void) sprintf(path
, "%s/source", pwent
->pw_dir
);
1583 if (access(path
, F_OK
) == 0) {
1584 sccs_dir_path
= path
;
1590 if (getcwd(cwdpath
, MAXPATHLEN
- 1 )) {
1592 (void) sprintf(path
, "%s/%s", cwdpath
,sccs_dir_path
);
1593 if (access(path
, F_OK
) == 0) {
1594 sccs_dir_path
= path
;
1597 fatal(gettext("Bogus PROJECTDIR '%s'"), sccs_dir_path
);
1606 make_install_prefix(void)
1609 char origin
[PATH_MAX
];
1612 if ((ret
= readlink("/proc/self/path/a.out", origin
,
1614 fatal("failed to read origin from /proc\n");
1618 return strdup(dirname(origin
));
1622 add_to_env(const char *var
, const char *value
, const char *fallback
)
1624 const char *oldpath
;
1627 oldpath
= getenv(var
);
1628 if (oldpath
== NULL
) {
1629 if (value
!= NULL
) {
1630 asprintf(&newpath
, "%s=%s",
1633 asprintf(&newpath
, "%s=%s",
1637 if (value
!= NULL
) {
1638 asprintf(&newpath
, "%s=%s:%s",
1639 var
, oldpath
, value
);
1641 asprintf(&newpath
, "%s=%s:%s",
1642 var
, oldpath
, fallback
);
1652 * Add the libmakestate.so.1 lib to the env var SGS_SUPPORT
1653 * if it's not already in there.
1654 * The SGS_SUPPORT env var and libmakestate.so.1 is used by
1655 * the linker ld to report .make.state info back to make.
1657 * In the new world we always will set the 32-bit and 64-bit versions of this
1658 * variable explicitly so that we can take into account the correct isa and our
1659 * prefix. So say that the prefix was /opt/local. Then we would want to search
1660 * /opt/local/lib/libmakestate.so.1:libmakestate.so.1. We still want to search
1661 * the original location just as a safety measure.
1667 char *newpath
, *newpath64
;
1668 char *lib32
, *lib64
;
1669 static char *prev_path
, *prev_path64
;
1670 char *origin
= make_install_prefix();
1673 asprintf(&lib32
, "%s/%s/%s", origin
, "../lib",
1674 LD_SUPPORT_MAKE_LIB
);
1676 if (stat(lib32
, &st
) != 0) {
1678 // Try the tools path
1679 asprintf(&lib32
, "%s/%s/%s/%s", origin
, "../../lib/",
1680 LD_SUPPORT_MAKE_ARCH
, LD_SUPPORT_MAKE_LIB
);
1682 if (stat(lib32
, &st
) != 0) {
1688 asprintf(&lib64
, "%s/%s/64/%s", origin
, "../lib",
1689 LD_SUPPORT_MAKE_LIB
);
1691 if (stat(lib64
, &st
) != 0) {
1693 // Try the tools path
1694 asprintf(&lib64
, "%s/%s/%s/64/%s", origin
, "../../lib/",
1695 LD_SUPPORT_MAKE_ARCH
, LD_SUPPORT_MAKE_LIB
);
1697 if (stat(lib64
, &st
) != 0) {
1703 newpath
= add_to_env(LD_SUPPORT_ENV_VAR_32
, lib32
, LD_SUPPORT_MAKE_LIB
);
1704 newpath64
= add_to_env(LD_SUPPORT_ENV_VAR_64
, lib64
, LD_SUPPORT_MAKE_LIB
);
1710 prev_path
= newpath
;
1716 prev_path64
= newpath64
;
1723 * read_files_and_state(argc, argv)
1725 * Read the makefiles we care about and the environment
1726 * Also read the = style command line options
1729 * argc You know what this is
1730 * argv You know what this is
1732 * Static variables used:
1733 * env_wins make -e, determines if env vars are RO
1734 * ignore_default_mk make -r, determines if make.rules is read
1735 * not_auto_depen dwight
1737 * Global variables used:
1738 * default_target_to_build Set to first proper target from file
1739 * do_not_exec_rule Set to false when makfile is made
1740 * dot The Name ".", used to read current dir
1741 * empty_name The Name "", use as macro value
1742 * keep_state Set if KEEP_STATE is in environment
1743 * make_state The Name ".make.state", used to read file
1744 * makefile_type Set to type of file being read
1745 * makeflags The Name "MAKEFLAGS", used to set macro value
1747 * read_trace_level Checked to se if the reader should trace
1748 * report_dependencies If -P is on we do not read .make.state
1749 * trace_reader Set if reader should trace
1750 * virtual_root The Name "VIRTUAL_ROOT", used to check value
1753 read_files_and_state(int argc
, char **argv
)
1755 wchar_t buffer
[1000];
1756 wchar_t buffer_posix
[1000];
1759 Property def_make_macro
= NULL
;
1761 Name default_makefile
;
1763 wchar_t destbuffer
[STRING_BUFFER_LENGTH
];
1766 Name keep_state_name
;
1769 register Property macro
;
1770 struct stat make_state_stat
;
1772 register int makefile_next
= 0;
1773 register Boolean makefile_read
= false;
1774 String_rec makeflags_string
;
1775 String_rec makeflags_string_posix
;
1776 String_rec
* makeflags_string_current
;
1777 Name makeflags_value_saved
;
1779 Name new_make_value
;
1780 Boolean save_do_not_exec_rule
;
1782 Name sdotmakefile_name
;
1783 static wchar_t state_file_str
;
1784 static char state_file_str_mb
[MAXPATHLEN
];
1785 static struct _Name state_filename
;
1788 wchar_t *tmp_wcs_buffer
;
1789 register Name value
;
1790 ASCII_Dyn_Array makeflags_and_macro
;
1794 * Remember current mode. It may be changed after reading makefile
1795 * and we will have to correct MAKEFLAGS variable.
1799 MBSTOWCS(wcs_buffer
, "KEEP_STATE");
1800 keep_state_name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
1801 MBSTOWCS(wcs_buffer
, "Makefile");
1802 Makefile
= GETNAME(wcs_buffer
, FIND_LENGTH
);
1803 MBSTOWCS(wcs_buffer
, "makefile");
1804 makefile_name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
1805 MBSTOWCS(wcs_buffer
, "s.makefile");
1806 sdotmakefile_name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
1807 MBSTOWCS(wcs_buffer
, "s.Makefile");
1808 sdotMakefile
= GETNAME(wcs_buffer
, FIND_LENGTH
);
1811 * initialize global dependency entry for .NOT_AUTO
1813 not_auto_depen
->next
= NULL
;
1814 not_auto_depen
->name
= not_auto
;
1815 not_auto_depen
->automatic
= not_auto_depen
->stale
= false;
1818 * Read internal definitions and rules.
1820 if (read_trace_level
> 1) {
1821 trace_reader
= true;
1823 if (!ignore_default_mk
) {
1825 MBSTOWCS(wcs_buffer
, "svr4.make.rules");
1826 default_makefile
= GETNAME(wcs_buffer
, FIND_LENGTH
);
1828 MBSTOWCS(wcs_buffer
, "make.rules");
1829 default_makefile
= GETNAME(wcs_buffer
, FIND_LENGTH
);
1831 default_makefile
->stat
.is_file
= true;
1833 (void) read_makefile(default_makefile
,
1840 * If the user did not redefine the MAKE macro in the
1841 * default makefile (make.rules), then we'd like to
1842 * change the macro value of MAKE to be some form
1843 * of argv[0] for recursive MAKE builds.
1845 MBSTOWCS(wcs_buffer
, "MAKE");
1846 def_make_name
= GETNAME(wcs_buffer
, wcslen(wcs_buffer
));
1847 def_make_macro
= get_prop(def_make_name
->prop
, macro_prop
);
1848 if ((def_make_macro
!= NULL
) &&
1849 (IS_EQUAL(def_make_macro
->body
.macro
.value
->string_mb
,
1851 MBSTOWCS(wcs_buffer
, argv_zero_string
);
1852 new_make_value
= GETNAME(wcs_buffer
, wcslen(wcs_buffer
));
1853 (void) SETVAR(def_make_name
,
1858 default_target_to_build
= NULL
;
1859 trace_reader
= false;
1862 * Read environment args. Let file args which follow override unless
1863 * -e option seen. If -e option is not mentioned.
1865 read_environment(env_wins
);
1866 if (getvar(virtual_root
)->hash
.length
== 0) {
1867 maybe_append_prop(virtual_root
, macro_prop
)
1868 ->body
.macro
.exported
= true;
1869 MBSTOWCS(wcs_buffer
, "/");
1870 (void) SETVAR(virtual_root
,
1871 GETNAME(wcs_buffer
, FIND_LENGTH
),
1876 * We now scan mf_argv and argv to see if we need to set
1877 * any of the DMake-added options/variables in MAKEFLAGS.
1880 makeflags_and_macro
.start
= 0;
1881 makeflags_and_macro
.size
= 0;
1882 enter_argv_values(mf_argc
, mf_argv
, &makeflags_and_macro
);
1883 enter_argv_values(argc
, argv
, &makeflags_and_macro
);
1886 * Set MFLAGS and MAKEFLAGS
1888 * Before reading makefile we do not know exactly which mode
1889 * (posix or not) is used. So prepare two MAKEFLAGS strings
1890 * for both posix and solaris modes because they are different.
1892 INIT_STRING_FROM_STACK(makeflags_string
, buffer
);
1893 INIT_STRING_FROM_STACK(makeflags_string_posix
, buffer_posix
);
1894 append_char((int) hyphen_char
, &makeflags_string
);
1895 append_char((int) hyphen_char
, &makeflags_string_posix
);
1897 switch (read_trace_level
) {
1899 append_char('D', &makeflags_string
);
1900 append_char('D', &makeflags_string_posix
);
1902 append_char('D', &makeflags_string
);
1903 append_char('D', &makeflags_string_posix
);
1905 switch (debug_level
) {
1907 append_char('d', &makeflags_string
);
1908 append_char('d', &makeflags_string_posix
);
1910 append_char('d', &makeflags_string
);
1911 append_char('d', &makeflags_string_posix
);
1914 append_char('e', &makeflags_string
);
1915 append_char('e', &makeflags_string_posix
);
1917 if (ignore_errors_all
) {
1918 append_char('i', &makeflags_string
);
1919 append_char('i', &makeflags_string_posix
);
1921 if (continue_after_error
) {
1922 if (stop_after_error_ever_seen
) {
1923 append_char('S', &makeflags_string_posix
);
1924 append_char((int) space_char
, &makeflags_string_posix
);
1925 append_char((int) hyphen_char
, &makeflags_string_posix
);
1927 append_char('k', &makeflags_string
);
1928 append_char('k', &makeflags_string_posix
);
1930 if (stop_after_error_ever_seen
1931 && continue_after_error_ever_seen
) {
1932 append_char('k', &makeflags_string_posix
);
1933 append_char((int) space_char
, &makeflags_string_posix
);
1934 append_char((int) hyphen_char
, &makeflags_string_posix
);
1935 append_char('S', &makeflags_string_posix
);
1938 if (do_not_exec_rule
) {
1939 append_char('n', &makeflags_string
);
1940 append_char('n', &makeflags_string_posix
);
1942 switch (report_dependencies_level
) {
1944 append_char('P', &makeflags_string
);
1945 append_char('P', &makeflags_string_posix
);
1947 append_char('P', &makeflags_string
);
1948 append_char('P', &makeflags_string_posix
);
1950 append_char('P', &makeflags_string
);
1951 append_char('P', &makeflags_string_posix
);
1953 append_char('P', &makeflags_string
);
1954 append_char('P', &makeflags_string_posix
);
1957 append_char('p', &makeflags_string
);
1958 append_char('p', &makeflags_string_posix
);
1961 append_char('q', &makeflags_string
);
1962 append_char('q', &makeflags_string_posix
);
1965 append_char('s', &makeflags_string
);
1966 append_char('s', &makeflags_string_posix
);
1969 append_char('t', &makeflags_string
);
1970 append_char('t', &makeflags_string_posix
);
1972 if (build_unconditional
) {
1973 append_char('u', &makeflags_string
);
1974 append_char('u', &makeflags_string_posix
);
1977 append_char('w', &makeflags_string
);
1978 append_char('w', &makeflags_string_posix
);
1980 /* -c dmake_rcfile */
1981 if (dmake_rcfile_specified
) {
1982 MBSTOWCS(wcs_buffer
, "DMAKE_RCFILE");
1983 dmake_rcfile
= GETNAME(wcs_buffer
, FIND_LENGTH
);
1984 append_makeflags_string(dmake_rcfile
, &makeflags_string
);
1985 append_makeflags_string(dmake_rcfile
, &makeflags_string_posix
);
1987 /* -g dmake_group */
1988 if (dmake_group_specified
) {
1989 MBSTOWCS(wcs_buffer
, "DMAKE_GROUP");
1990 dmake_group
= GETNAME(wcs_buffer
, FIND_LENGTH
);
1991 append_makeflags_string(dmake_group
, &makeflags_string
);
1992 append_makeflags_string(dmake_group
, &makeflags_string_posix
);
1994 /* -j dmake_max_jobs */
1995 if (dmake_max_jobs_specified
) {
1996 MBSTOWCS(wcs_buffer
, "DMAKE_MAX_JOBS");
1997 dmake_max_jobs
= GETNAME(wcs_buffer
, FIND_LENGTH
);
1998 append_makeflags_string(dmake_max_jobs
, &makeflags_string
);
1999 append_makeflags_string(dmake_max_jobs
, &makeflags_string_posix
);
2002 if (dmake_mode_specified
) {
2003 MBSTOWCS(wcs_buffer
, "DMAKE_MODE");
2004 dmake_mode
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2005 append_makeflags_string(dmake_mode
, &makeflags_string
);
2006 append_makeflags_string(dmake_mode
, &makeflags_string_posix
);
2008 /* -x dmake_compat_mode */
2009 // if (dmake_compat_mode_specified) {
2010 // MBSTOWCS(wcs_buffer, "SUN_MAKE_COMPAT_MODE");
2011 // dmake_compat_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2012 // append_makeflags_string(dmake_compat_mode, &makeflags_string);
2013 // append_makeflags_string(dmake_compat_mode, &makeflags_string_posix);
2015 /* -x dmake_output_mode */
2016 if (dmake_output_mode_specified
) {
2017 MBSTOWCS(wcs_buffer
, "DMAKE_OUTPUT_MODE");
2018 dmake_output_mode
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2019 append_makeflags_string(dmake_output_mode
, &makeflags_string
);
2020 append_makeflags_string(dmake_output_mode
, &makeflags_string_posix
);
2023 if (dmake_odir_specified
) {
2024 MBSTOWCS(wcs_buffer
, "DMAKE_ODIR");
2025 dmake_odir
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2026 append_makeflags_string(dmake_odir
, &makeflags_string
);
2027 append_makeflags_string(dmake_odir
, &makeflags_string_posix
);
2029 /* -M pmake_machinesfile */
2030 if (pmake_machinesfile_specified
) {
2031 MBSTOWCS(wcs_buffer
, "PMAKE_MACHINESFILE");
2032 pmake_machinesfile
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2033 append_makeflags_string(pmake_machinesfile
, &makeflags_string
);
2034 append_makeflags_string(pmake_machinesfile
, &makeflags_string_posix
);
2037 if (pmake_cap_r_specified
) {
2038 append_char((int) space_char
, &makeflags_string
);
2039 append_char((int) hyphen_char
, &makeflags_string
);
2040 append_char('R', &makeflags_string
);
2041 append_char((int) space_char
, &makeflags_string_posix
);
2042 append_char((int) hyphen_char
, &makeflags_string_posix
);
2043 append_char('R', &makeflags_string_posix
);
2047 * Make sure MAKEFLAGS is exported
2049 maybe_append_prop(makeflags
, macro_prop
)->
2050 body
.macro
.exported
= true;
2052 if (makeflags_string
.buffer
.start
[1] != (int) nul_char
) {
2053 if (makeflags_string
.buffer
.start
[1] != (int) space_char
) {
2054 MBSTOWCS(wcs_buffer
, "MFLAGS");
2055 (void) SETVAR(GETNAME(wcs_buffer
, FIND_LENGTH
),
2056 GETNAME(makeflags_string
.buffer
.start
,
2060 MBSTOWCS(wcs_buffer
, "MFLAGS");
2061 (void) SETVAR(GETNAME(wcs_buffer
, FIND_LENGTH
),
2062 GETNAME(makeflags_string
.buffer
.start
+ 2,
2069 * Add command line macro to POSIX makeflags_string
2071 if (makeflags_and_macro
.start
) {
2072 tmp_char
= (char) space_char
;
2073 cp
= makeflags_and_macro
.start
;
2075 append_char(tmp_char
, &makeflags_string_posix
);
2076 } while ( tmp_char
= *cp
++ );
2077 retmem_mb(makeflags_and_macro
.start
);
2081 * Now set the value of MAKEFLAGS macro in accordance
2082 * with current mode.
2084 macro
= maybe_append_prop(makeflags
, macro_prop
);
2085 temp
= (Boolean
) macro
->body
.macro
.read_only
;
2086 macro
->body
.macro
.read_only
= false;
2087 if(posix
|| gnu_style
) {
2088 makeflags_string_current
= &makeflags_string_posix
;
2090 makeflags_string_current
= &makeflags_string
;
2092 if (makeflags_string_current
->buffer
.start
[1] == (int) nul_char
) {
2093 makeflags_value_saved
=
2094 GETNAME( makeflags_string_current
->buffer
.start
+ 1
2098 if (makeflags_string_current
->buffer
.start
[1] != (int) space_char
) {
2099 makeflags_value_saved
=
2100 GETNAME( makeflags_string_current
->buffer
.start
2104 makeflags_value_saved
=
2105 GETNAME( makeflags_string_current
->buffer
.start
+ 2
2110 (void) SETVAR( makeflags
2111 , makeflags_value_saved
2114 macro
->body
.macro
.read_only
= temp
;
2117 * Read command line "-f" arguments and ignore -c, g, j, K, M, m, O and o args.
2119 save_do_not_exec_rule
= do_not_exec_rule
;
2120 do_not_exec_rule
= false;
2121 if (read_trace_level
> 0) {
2122 trace_reader
= true;
2125 for (i
= 1; i
< argc
; i
++) {
2127 (argv
[i
][0] == (int) hyphen_char
) &&
2128 (argv
[i
][1] == 'f') &&
2129 (argv
[i
][2] == (int) nul_char
)) {
2130 argv
[i
] = NULL
; /* Remove -f */
2131 if (i
>= argc
- 1) {
2132 fatal(gettext("No filename argument after -f flag"));
2134 MBSTOWCS(wcs_buffer
, argv
[++i
]);
2135 primary_makefile
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2136 (void) read_makefile(primary_makefile
, true, true, true);
2137 argv
[i
] = NULL
; /* Remove filename */
2138 makefile_read
= true;
2139 } else if (argv
[i
] &&
2140 (argv
[i
][0] == (int) hyphen_char
) &&
2141 (argv
[i
][1] == 'c' ||
2142 argv
[i
][1] == 'g' ||
2143 argv
[i
][1] == 'j' ||
2144 argv
[i
][1] == 'K' ||
2145 argv
[i
][1] == 'M' ||
2146 argv
[i
][1] == 'm' ||
2147 argv
[i
][1] == 'O' ||
2148 argv
[i
][1] == 'o') &&
2149 (argv
[i
][2] == (int) nul_char
)) {
2156 * If no command line "-f" args then look for "makefile", and then for
2157 * "Makefile" if "makefile" isn't found.
2159 if (!makefile_read
) {
2160 (void) read_dir(dot
,
2165 if (makefile_name
->stat
.is_file
) {
2166 if (Makefile
->stat
.is_file
) {
2167 warning(gettext("Both `makefile' and `Makefile' exist"));
2169 primary_makefile
= makefile_name
;
2170 makefile_read
= read_makefile(makefile_name
,
2175 if (!makefile_read
&&
2176 Makefile
->stat
.is_file
) {
2177 primary_makefile
= Makefile
;
2178 makefile_read
= read_makefile(Makefile
,
2185 enum sccs_stat save_m_has_sccs
= NO_SCCS
;
2186 enum sccs_stat save_M_has_sccs
= NO_SCCS
;
2188 if (makefile_name
->stat
.is_file
) {
2189 if (Makefile
->stat
.is_file
) {
2190 warning(gettext("Both `makefile' and `Makefile' exist"));
2193 if (makefile_name
->stat
.is_file
) {
2194 if (makefile_name
->stat
.has_sccs
== NO_SCCS
) {
2195 primary_makefile
= makefile_name
;
2196 makefile_read
= read_makefile(makefile_name
,
2201 save_m_has_sccs
= makefile_name
->stat
.has_sccs
;
2202 makefile_name
->stat
.has_sccs
= NO_SCCS
;
2203 primary_makefile
= makefile_name
;
2204 makefile_read
= read_makefile(makefile_name
,
2210 if (!makefile_read
&&
2211 Makefile
->stat
.is_file
) {
2212 if (Makefile
->stat
.has_sccs
== NO_SCCS
) {
2213 primary_makefile
= Makefile
;
2214 makefile_read
= read_makefile(Makefile
,
2219 save_M_has_sccs
= Makefile
->stat
.has_sccs
;
2220 Makefile
->stat
.has_sccs
= NO_SCCS
;
2221 primary_makefile
= Makefile
;
2222 makefile_read
= read_makefile(Makefile
,
2228 if (!makefile_read
&&
2229 makefile_name
->stat
.is_file
) {
2230 makefile_name
->stat
.has_sccs
= save_m_has_sccs
;
2231 primary_makefile
= makefile_name
;
2232 makefile_read
= read_makefile(makefile_name
,
2237 if (!makefile_read
&&
2238 Makefile
->stat
.is_file
) {
2239 Makefile
->stat
.has_sccs
= save_M_has_sccs
;
2240 primary_makefile
= Makefile
;
2241 makefile_read
= read_makefile(Makefile
,
2248 do_not_exec_rule
= save_do_not_exec_rule
;
2249 allrules_read
= makefile_read
;
2250 trace_reader
= false;
2253 * Now get current value of MAKEFLAGS and compare it with
2254 * the saved value we set before reading makefile.
2255 * If they are different then MAKEFLAGS is subsequently set by
2256 * makefile, just leave it there. Otherwise, if make mode
2257 * is changed by using .POSIX target in makefile we need
2258 * to correct MAKEFLAGS value.
2260 Name mf_val
= getvar(makeflags
);
2261 if( (posix
!= is_xpg4
)
2262 && (!strcmp(mf_val
->string_mb
, makeflags_value_saved
->string_mb
)))
2264 if (makeflags_string_posix
.buffer
.start
[1] == (int) nul_char
) {
2265 (void) SETVAR(makeflags
,
2266 GETNAME(makeflags_string_posix
.buffer
.start
+ 1,
2270 if (makeflags_string_posix
.buffer
.start
[1] != (int) space_char
) {
2271 (void) SETVAR(makeflags
,
2272 GETNAME(makeflags_string_posix
.buffer
.start
,
2276 (void) SETVAR(makeflags
,
2277 GETNAME(makeflags_string_posix
.buffer
.start
+ 2,
2284 if (makeflags_string
.free_after_use
) {
2285 retmem(makeflags_string
.buffer
.start
);
2287 if (makeflags_string_posix
.free_after_use
) {
2288 retmem(makeflags_string_posix
.buffer
.start
);
2290 makeflags_string
.buffer
.start
= NULL
;
2291 makeflags_string_posix
.buffer
.start
= NULL
;
2295 * If the user did not redefine the ARFLAGS macro in the
2296 * default makefile (make.rules), then we'd like to
2297 * change the macro value of ARFLAGS to be in accordance
2298 * with "POSIX" requirements.
2300 MBSTOWCS(wcs_buffer
, "ARFLAGS");
2301 name
= GETNAME(wcs_buffer
, wcslen(wcs_buffer
));
2302 macro
= get_prop(name
->prop
, macro_prop
);
2303 if ((macro
!= NULL
) && /* Maybe (macro == NULL) || ? */
2304 (IS_EQUAL(macro
->body
.macro
.value
->string_mb
,
2306 MBSTOWCS(wcs_buffer
, "-rv");
2307 value
= GETNAME(wcs_buffer
, wcslen(wcs_buffer
));
2314 if (!posix
&& !svr4
) {
2320 * Make sure KEEP_STATE is in the environment if KEEP_STATE is on.
2322 macro
= get_prop(keep_state_name
->prop
, macro_prop
);
2323 if ((macro
!= NULL
) &&
2324 macro
->body
.macro
.exported
) {
2328 if (macro
== NULL
) {
2329 macro
= maybe_append_prop(keep_state_name
,
2332 macro
->body
.macro
.exported
= true;
2333 (void) SETVAR(keep_state_name
,
2341 /* Before we read state, let's make sure we have
2342 ** right state file.
2344 /* just in case macro references are used in make_state file
2345 ** name, we better expand them at this stage using expand_value.
2347 INIT_STRING_FROM_STACK(dest
, destbuffer
);
2348 expand_value(make_state
, &dest
, false);
2350 make_state
= GETNAME(dest
.buffer
.start
, FIND_LENGTH
);
2352 if(!stat(make_state
->string_mb
, &make_state_stat
)) {
2353 if(!(make_state_stat
.st_mode
& S_IFREG
) ) {
2354 /* copy the make_state structure to the other
2355 ** and then let make_state point to the new
2358 memcpy(&state_filename
, make_state
,sizeof(state_filename
));
2359 state_filename
.string_mb
= state_file_str_mb
;
2360 /* Just a kludge to avoid two slashes back to back */
2361 if((make_state
->hash
.length
== 1)&&
2362 (make_state
->string_mb
[0] == '/')) {
2363 make_state
->hash
.length
= 0;
2364 make_state
->string_mb
[0] = '\0';
2366 sprintf(state_file_str_mb
,"%s%s",
2367 make_state
->string_mb
,"/.make.state");
2368 make_state
= &state_filename
;
2369 /* adjust the length to reflect the appended string */
2370 make_state
->hash
.length
+= 12;
2372 } else { /* the file doesn't exist or no permission */
2373 char tmp_path
[MAXPATHLEN
];
2376 if (slashp
= strrchr(make_state
->string_mb
, '/')) {
2377 strncpy(tmp_path
, make_state
->string_mb
,
2378 (slashp
- make_state
->string_mb
));
2379 tmp_path
[slashp
- make_state
->string_mb
]=0;
2380 if(strlen(tmp_path
)) {
2381 if(stat(tmp_path
, &make_state_stat
)) {
2382 warning(gettext("directory %s for .KEEP_STATE_FILE does not exist"),tmp_path
);
2384 if (access(tmp_path
, F_OK
) != 0) {
2385 warning(gettext("can't access dir %s"),tmp_path
);
2390 if (report_dependencies_level
!= 1) {
2391 Makefile_type makefile_type_temp
= makefile_type
;
2392 makefile_type
= reading_statefile
;
2393 if (read_trace_level
> 1) {
2394 trace_reader
= true;
2396 (void) read_simple_file(make_state
,
2403 trace_reader
= false;
2404 makefile_type
= makefile_type_temp
;
2410 * Scan the argv for options and "=" type args and make them readonly.
2413 enter_argv_values(int argc
, char *argv
[], ASCII_Dyn_Array
*makeflags_and_macro
)
2419 int opt_separator
= argc
;
2421 wchar_t *tmp_wcs_buffer
;
2422 register Name value
;
2423 Boolean append
= false;
2425 struct stat statbuf
;
2428 /* Read argv options and "=" type args and make them readonly. */
2429 makefile_type
= reading_nothing
;
2430 for (i
= 1; i
< argc
; ++i
) {
2432 if (argv
[i
] == NULL
) {
2434 } else if (((argv
[i
][0] == '-') && (argv
[i
][1] == '-')) ||
2435 ((argv
[i
][0] == (int) ' ') &&
2436 (argv
[i
][1] == (int) '-') &&
2437 (argv
[i
][2] == (int) ' ') &&
2438 (argv
[i
][3] == (int) '-'))) {
2442 } else if ((i
< opt_separator
) && (argv
[i
][0] == (int) hyphen_char
)) {
2443 switch (parse_command_option(argv
[i
][1])) {
2444 case 1: /* -f seen */
2447 case 2: /* -c seen */
2448 if (argv
[i
+1] == NULL
) {
2449 fatal(gettext("No dmake rcfile argument after -c flag"));
2451 MBSTOWCS(wcs_buffer
, "DMAKE_RCFILE");
2452 name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2454 case 4: /* -g seen */
2455 if (argv
[i
+1] == NULL
) {
2456 fatal(gettext("No dmake group argument after -g flag"));
2458 MBSTOWCS(wcs_buffer
, "DMAKE_GROUP");
2459 name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2461 case 8: /* -j seen */
2462 if (argv
[i
+1] == NULL
) {
2463 fatal(gettext("No dmake max jobs argument after -j flag"));
2465 MBSTOWCS(wcs_buffer
, "DMAKE_MAX_JOBS");
2466 name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2468 case 16: /* -M seen */
2469 if (argv
[i
+1] == NULL
) {
2470 fatal(gettext("No pmake machinesfile argument after -M flag"));
2472 MBSTOWCS(wcs_buffer
, "PMAKE_MACHINESFILE");
2473 name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2475 case 32: /* -m seen */
2476 if (argv
[i
+1] == NULL
) {
2477 fatal(gettext("No dmake mode argument after -m flag"));
2479 MBSTOWCS(wcs_buffer
, "DMAKE_MODE");
2480 name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2482 case 256: /* -K seen */
2483 if (argv
[i
+1] == NULL
) {
2484 fatal(gettext("No makestate filename argument after -K flag"));
2486 MBSTOWCS(wcs_buffer
, argv
[i
+1]);
2487 make_state
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2492 case 512: /* -o seen */
2493 if (argv
[i
+1] == NULL
) {
2494 fatal(gettext("No dmake output dir argument after -o flag"));
2496 MBSTOWCS(wcs_buffer
, "DMAKE_ODIR");
2497 name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2499 case 1024: /* -x seen */
2500 if (argv
[i
+1] == NULL
) {
2501 fatal(gettext("No argument after -x flag"));
2503 length
= strlen( "SUN_MAKE_COMPAT_MODE=");
2504 if (strncmp(argv
[i
+1], "SUN_MAKE_COMPAT_MODE=", length
) == 0) {
2505 argv
[i
+1] = &argv
[i
+1][length
];
2506 MBSTOWCS(wcs_buffer
, "SUN_MAKE_COMPAT_MODE");
2507 name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2508 dmake_compat_mode_specified
= dmake_add_mode_specified
;
2511 length
= strlen( "DMAKE_OUTPUT_MODE=");
2512 if (strncmp(argv
[i
+1], "DMAKE_OUTPUT_MODE=", length
) == 0) {
2513 argv
[i
+1] = &argv
[i
+1][length
];
2514 MBSTOWCS(wcs_buffer
, "DMAKE_OUTPUT_MODE");
2515 name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2516 dmake_output_mode_specified
= dmake_add_mode_specified
;
2518 warning(gettext("Unknown argument `%s' after -x flag (ignored)"),
2520 argv
[i
] = argv
[i
+ 1] = NULL
;
2524 default: /* Shouldn't reach here */
2529 if (i
== (argc
- 1)) {
2532 if ((length
= strlen(argv
[i
+1])) >= MAXPATHLEN
) {
2533 tmp_wcs_buffer
= ALLOC_WC(length
+ 1);
2534 (void) mbstowcs(tmp_wcs_buffer
, argv
[i
+1], length
+ 1);
2535 value
= GETNAME(tmp_wcs_buffer
, FIND_LENGTH
);
2536 retmem(tmp_wcs_buffer
);
2538 MBSTOWCS(wcs_buffer
, argv
[i
+1]);
2539 value
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2542 } else if ((cp
= strchr(argv
[i
], (int) equal_char
)) != NULL
) {
2544 * Combine all macro in dynamic array
2546 if(*(cp
-1) == (int) plus_char
)
2548 if(isspace(*(cp
-2))) {
2554 append_or_replace_macro_in_dyn_array(makeflags_and_macro
, argv
[i
]);
2556 while (isspace(*(cp
-1))) {
2560 *cp
= (int) nul_char
;
2561 MBSTOWCS(wcs_buffer
, argv
[i
]);
2563 name
= GETNAME(wcs_buffer
, wcslen(wcs_buffer
));
2564 while (*cp
!= (int) equal_char
) {
2568 while (isspace(*cp
) && (*cp
!= (int) nul_char
)) {
2571 if ((length
= strlen(cp
)) >= MAXPATHLEN
) {
2572 tmp_wcs_buffer
= ALLOC_WC(length
+ 1);
2573 (void) mbstowcs(tmp_wcs_buffer
, cp
, length
+ 1);
2574 value
= GETNAME(tmp_wcs_buffer
, FIND_LENGTH
);
2575 retmem(tmp_wcs_buffer
);
2577 MBSTOWCS(wcs_buffer
, cp
);
2578 value
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2582 /* Illegal MAKEFLAGS argument */
2586 setvar_append(name
, value
);
2589 macro
= maybe_append_prop(name
, macro_prop
);
2590 macro
->body
.macro
.exported
= true;
2591 SETVAR(name
, value
, false)->body
.macro
.read_only
= true;
2597 * Append the DMake option and value to the MAKEFLAGS string.
2600 append_makeflags_string(Name name
, register String makeflags_string
)
2604 if (strcmp(name
->string_mb
, "DMAKE_GROUP") == 0) {
2606 } else if (strcmp(name
->string_mb
, "DMAKE_MAX_JOBS") == 0) {
2608 } else if (strcmp(name
->string_mb
, "DMAKE_MODE") == 0) {
2610 } else if (strcmp(name
->string_mb
, "DMAKE_ODIR") == 0) {
2612 } else if (strcmp(name
->string_mb
, "DMAKE_RCFILE") == 0) {
2614 } else if (strcmp(name
->string_mb
, "PMAKE_MACHINESFILE") == 0) {
2616 } else if (strcmp(name
->string_mb
, "DMAKE_OUTPUT_MODE") == 0) {
2617 option
= " -x DMAKE_OUTPUT_MODE=";
2618 } else if (strcmp(name
->string_mb
, "SUN_MAKE_COMPAT_MODE") == 0) {
2619 option
= " -x SUN_MAKE_COMPAT_MODE=";
2621 fatal(gettext("Internal error: name not recognized in append_makeflags_string()"));
2623 Property prop
= maybe_append_prop(name
, macro_prop
);
2624 if( prop
== 0 || prop
->body
.macro
.value
== 0 ||
2625 prop
->body
.macro
.value
->string_mb
== 0 ) {
2628 char mbs_value
[MAXPATHLEN
+ 100];
2629 strcpy(mbs_value
, option
);
2630 strcat(mbs_value
, prop
->body
.macro
.value
->string_mb
);
2631 MBSTOWCS(wcs_buffer
, mbs_value
);
2632 append_string(wcs_buffer
, makeflags_string
, FIND_LENGTH
);
2636 * read_environment(read_only)
2638 * This routine reads the process environment when make starts and enters
2639 * it as make macros. The environment variable SHELL is ignored.
2642 * read_only Should we make env vars read only?
2644 * Global variables used:
2645 * report_pwd Set if this make was started by other make
2648 read_environment(Boolean read_only
)
2650 register char **environment
;
2652 wchar_t *tmp_wcs_buffer
;
2653 Boolean alloced_tmp_wcs_buffer
= false;
2654 register wchar_t *name
;
2655 register wchar_t *value
;
2656 register Name macro
;
2658 Boolean read_only_saved
;
2660 reading_environment
= true;
2661 environment
= environ
;
2662 for (; *environment
; environment
++) {
2663 read_only_saved
= read_only
;
2664 if ((length
= strlen(*environment
)) >= MAXPATHLEN
) {
2665 tmp_wcs_buffer
= ALLOC_WC(length
+ 1);
2666 alloced_tmp_wcs_buffer
= true;
2667 (void) mbstowcs(tmp_wcs_buffer
, *environment
, length
+ 1);
2668 name
= tmp_wcs_buffer
;
2670 MBSTOWCS(wcs_buffer
, *environment
);
2673 value
= (wchar_t *) wcschr(name
, (int) equal_char
);
2676 * Looks like there's a bug in the system, but sometimes
2677 * you can get blank lines in *environment.
2682 MBSTOWCS(wcs_buffer2
, "SHELL=");
2683 if (IS_WEQUALN(name
, wcs_buffer2
, wcslen(wcs_buffer2
))) {
2686 MBSTOWCS(wcs_buffer2
, "MAKEFLAGS=");
2687 if (IS_WEQUALN(name
, wcs_buffer2
, wcslen(wcs_buffer2
))) {
2690 * In POSIX mode we do not want MAKEFLAGS to be readonly.
2691 * If the MAKEFLAGS macro is subsequently set by the makefile,
2692 * it replaces the MAKEFLAGS variable currently found in the
2694 * See Assertion 50 in section 6.2.5.3 of standard P1003.3.2/D8.
2697 read_only_saved
= false;
2702 * We ignore SUNPRO_DEPENDENCIES. This environment variable is
2703 * set by make and read by cpp which then writes info to
2704 * .make.dependency.xxx. When make is invoked by another make
2705 * (recursive make), we don't want to read this because then
2706 * the child make will end up writing to the parent
2707 * directory's .make.state and clobbering them.
2709 MBSTOWCS(wcs_buffer2
, "SUNPRO_DEPENDENCIES");
2710 if (IS_WEQUALN(name
, wcs_buffer2
, wcslen(wcs_buffer2
))) {
2714 macro
= GETNAME(name
, value
- name
);
2715 maybe_append_prop(macro
, macro_prop
)->body
.macro
.exported
=
2717 if ((value
== NULL
) || ((value
+ 1)[0] == (int) nul_char
)) {
2718 val
= setvar_daemon(macro
,
2720 false, no_daemon
, false, debug_level
);
2722 val
= setvar_daemon(macro
,
2723 GETNAME(value
+ 1, FIND_LENGTH
),
2724 false, no_daemon
, false, debug_level
);
2726 val
->body
.macro
.read_only
= read_only_saved
;
2727 if (alloced_tmp_wcs_buffer
) {
2728 retmem(tmp_wcs_buffer
);
2729 alloced_tmp_wcs_buffer
= false;
2732 reading_environment
= false;
2736 * read_makefile(makefile, complain, must_exist, report_file)
2738 * Read one makefile and check the result
2741 * false is the read failed
2744 * makefile The file to read
2745 * complain Passed thru to read_simple_file()
2746 * must_exist Passed thru to read_simple_file()
2747 * report_file Passed thru to read_simple_file()
2749 * Global variables used:
2750 * makefile_type Set to indicate we are reading main file
2751 * recursion_level Initialized
2754 read_makefile(register Name makefile
, Boolean complain
, Boolean must_exist
, Boolean report_file
)
2758 makefile_type
= reading_makefile
;
2759 recursion_level
= 0;
2760 reading_dependencies
= true;
2761 b
= read_simple_file(makefile
, true, true, complain
,
2762 must_exist
, report_file
, false);
2763 reading_dependencies
= false;
2768 * make_targets(argc, argv, parallel_flag)
2770 * Call doname on the specified targets
2773 * argc You know what this is
2774 * argv You know what this is
2775 * parallel_flag True if building in parallel
2777 * Global variables used:
2778 * build_failed_seen Used to generated message after failed -k
2779 * commands_done Used to generate message "Up to date"
2780 * default_target_to_build First proper target in makefile
2781 * init The Name ".INIT", use to run command
2782 * parallel Global parallel building flag
2783 * quest make -q, suppresses messages
2784 * recursion_level Initialized, used for tracing
2785 * report_dependencies make -P, regroves whole process
2788 make_targets(int argc
, char **argv
, Boolean parallel_flag
)
2793 register Boolean target_to_make_found
= false;
2795 (void) doname(init
, true, true);
2796 recursion_level
= 1;
2797 parallel
= parallel_flag
;
2799 * make remaining args
2802 if ((report_dependencies_level == 0) && parallel) {
2806 * If building targets in parallel, start all of the
2807 * remaining args to build in parallel.
2809 for (i
= 1; i
< argc
; i
++) {
2810 if ((cp
= argv
[i
]) != NULL
) {
2811 commands_done
= false;
2812 if ((cp
[0] == (int) period_char
) &&
2813 (cp
[1] == (int) slash_char
)) {
2816 if((cp
[0] == (int) ' ') &&
2817 (cp
[1] == (int) '-') &&
2818 (cp
[2] == (int) ' ') &&
2819 (cp
[3] == (int) '-')) {
2823 MBSTOWCS(wcs_buffer
, cp
);
2824 //default_target_to_build = GETNAME(wcs_buffer,
2826 default_target_to_build
= normalize_name(wcs_buffer
,
2827 wcslen(wcs_buffer
));
2828 if (default_target_to_build
== wait_name
) {
2829 if (parallel_process_cnt
> 0) {
2834 top_level_target
= get_wstring(default_target_to_build
->string_mb
);
2836 * If we can't execute the current target in
2837 * parallel, hold off the target processing
2838 * to preserve the order of the targets as they appeared
2841 if (!parallel_ok(default_target_to_build
, false)
2842 && parallel_process_cnt
> 0) {
2845 result
= doname_check(default_target_to_build
,
2849 gather_recursive_deps();
2850 if (/* !commands_done && */
2851 (result
== build_ok
) &&
2853 (report_dependencies_level
== 0) /* &&
2854 (exists(default_target_to_build) > file_doesnt_exist) */) {
2856 if (!commands_done
) {
2857 (void) printf(gettext("`%s' is updated.\n"),
2858 default_target_to_build
->string_mb
);
2860 if (no_action_was_taken
) {
2861 (void) printf(gettext("`%s': no action was taken.\n"),
2862 default_target_to_build
->string_mb
);
2866 default_target_to_build
->stat
.time
= file_no_time
;
2867 if (!commands_done
&&
2868 (exists(default_target_to_build
) > file_doesnt_exist
)) {
2869 (void) printf(gettext("`%s' is up to date.\n"),
2870 default_target_to_build
->string_mb
);
2876 /* Now wait for all of the targets to finish running */
2878 // setjmp(jmpbuffer);
2881 for (i
= 1; i
< argc
; i
++) {
2882 if ((cp
= argv
[i
]) != NULL
) {
2883 target_to_make_found
= true;
2884 if ((cp
[0] == (int) period_char
) &&
2885 (cp
[1] == (int) slash_char
)) {
2888 if((cp
[0] == (int) ' ') &&
2889 (cp
[1] == (int) '-') &&
2890 (cp
[2] == (int) ' ') &&
2891 (cp
[3] == (int) '-')) {
2895 MBSTOWCS(wcs_buffer
, cp
);
2896 default_target_to_build
= normalize_name(wcs_buffer
, wcslen(wcs_buffer
));
2897 top_level_target
= get_wstring(default_target_to_build
->string_mb
);
2898 report_recursion(default_target_to_build
);
2899 commands_done
= false;
2901 result
= (Doname
) default_target_to_build
->state
;
2903 result
= doname_check(default_target_to_build
,
2908 gather_recursive_deps();
2909 if (build_failed_seen
) {
2910 build_failed_ever_seen
= true;
2911 warning(gettext("Target `%s' not remade because of errors"),
2912 default_target_to_build
->string_mb
);
2914 build_failed_seen
= false;
2915 if (report_dependencies_level
> 0) {
2916 print_dependencies(default_target_to_build
,
2917 get_prop(default_target_to_build
->prop
,
2920 default_target_to_build
->stat
.time
=
2922 if (default_target_to_build
->colon_splits
> 0) {
2923 default_target_to_build
->state
=
2927 /* !commands_done && */
2928 (result
== build_ok
) &&
2930 (report_dependencies_level
== 0) /* &&
2931 (exists(default_target_to_build) > file_doesnt_exist) */) {
2933 if (!commands_done
) {
2934 (void) printf(gettext("`%s' is updated.\n"),
2935 default_target_to_build
->string_mb
);
2937 if (no_action_was_taken
) {
2938 (void) printf(gettext("`%s': no action was taken.\n"),
2939 default_target_to_build
->string_mb
);
2943 if (!commands_done
&&
2944 (exists(default_target_to_build
) > file_doesnt_exist
)) {
2945 (void) printf(gettext("`%s' is up to date.\n"),
2946 default_target_to_build
->string_mb
);
2954 * If no file arguments have been encountered,
2955 * make the first name encountered that doesnt start with a dot
2957 if (!target_to_make_found
) {
2958 if (default_target_to_build
== NULL
) {
2959 fatal(gettext("No arguments to build"));
2961 commands_done
= false;
2962 top_level_target
= get_wstring(default_target_to_build
->string_mb
);
2963 report_recursion(default_target_to_build
);
2966 if (getenv("SPRO_EXPAND_ERRORS")){
2967 (void) printf("::(%s)\n",
2968 default_target_to_build
->string_mb
);
2972 result
= doname_parallel(default_target_to_build
, true, false);
2973 gather_recursive_deps();
2974 if (build_failed_seen
) {
2975 build_failed_ever_seen
= true;
2976 warning(gettext("Target `%s' not remade because of errors"),
2977 default_target_to_build
->string_mb
);
2979 build_failed_seen
= false;
2980 if (report_dependencies_level
> 0) {
2981 print_dependencies(default_target_to_build
,
2982 get_prop(default_target_to_build
->
2986 default_target_to_build
->stat
.time
= file_no_time
;
2987 if (default_target_to_build
->colon_splits
> 0) {
2988 default_target_to_build
->state
= build_dont_know
;
2990 if (/* !commands_done && */
2991 (result
== build_ok
) &&
2993 (report_dependencies_level
== 0) /* &&
2994 (exists(default_target_to_build) > file_doesnt_exist) */) {
2996 if (!commands_done
) {
2997 (void) printf(gettext("`%s' is updated.\n"),
2998 default_target_to_build
->string_mb
);
3000 if (no_action_was_taken
) {
3001 (void) printf(gettext("`%s': no action was taken.\n"),
3002 default_target_to_build
->string_mb
);
3006 if (!commands_done
&&
3007 (exists(default_target_to_build
) > file_doesnt_exist
)) {
3008 (void) printf(gettext("`%s' is up to date.\n"),
3009 default_target_to_build
->string_mb
);
3017 * report_recursion(target)
3019 * If this is a recursive make and the parent make has KEEP_STATE on
3020 * this routine reports the dependency to the parent make
3023 * target Target to report
3025 * Global variables used:
3026 * makefiles_used List of makefiles read
3027 * recursive_name The Name ".RECURSIVE", printed
3028 * report_dependency dwight
3031 report_recursion(register Name target
)
3033 register FILE *report_file
= get_report_file();
3035 if ((report_file
== NULL
) || (report_file
== (FILE*)-1)) {
3038 if (primary_makefile
== NULL
) {
3040 * This can happen when there is no makefile and
3041 * only implicit rules are being used.
3045 (void) fprintf(report_file
,
3047 get_target_being_reported_for(),
3048 recursive_name
->string_mb
);
3049 report_dependency(get_current_path());
3050 report_dependency(target
->string_mb
);
3051 report_dependency(primary_makefile
->string_mb
);
3052 (void) fprintf(report_file
, "\n");
3055 /* Next function "append_or_replace_macro_in_dyn_array" must be in "misc.cc". */
3058 append_or_replace_macro_in_dyn_array(ASCII_Dyn_Array
*Ar
, char *macro
)
3060 register char *cp0
; /* work pointer in macro */
3061 register char *cp1
; /* work pointer in array */
3062 register char *cp2
; /* work pointer in array */
3063 register char *cp3
; /* work pointer in array */
3064 register char *name
; /* macro name */
3065 register char *value
; /* macro value */
3066 register int len_array
;
3067 register int len_macro
;
3069 char * esc_value
= NULL
;
3072 if (!(len_macro
= strlen(macro
))) return;
3074 while (isspace(*(name
))) {
3077 if (!(value
= strchr(name
, (int) equal_char
))) {
3078 /* no '=' in macro */
3083 while (isspace(*(value
))) {
3086 while (isspace(*(cp0
-1))) {
3089 if (cp0
<= name
) goto ERROR_MACRO
; /* no name */
3090 if (!(Ar
->size
)) goto ALLOC_ARRAY
;
3094 if (!(cp1
= strchr(cp1
, name
[0]))) goto APPEND_MACRO
;
3095 if (!(cp2
= strchr(cp1
, (int) equal_char
))) goto APPEND_MACRO
;
3096 if (strncmp(cp1
, name
, (size_t)(cp0
-name
))) {
3101 if (cp1
!= Ar
->start
) {
3102 if (!isspace(*(cp1
-1))) {
3108 for (cp3
= cp1
+ (cp0
-name
); cp3
< cp2
; cp3
++) {
3109 if (isspace(*cp3
)) continue;
3110 /* else: another name */
3114 /* Look for the next macro name in array */
3116 if (*cp3
!= (int) doublequote_char
) {
3117 /* internal error */
3120 if (!(cp3
= strchr(cp3
+1, (int) doublequote_char
))) {
3121 /* internal error */
3125 while (isspace(*cp3
)) {
3129 cp2
= cp1
; /* remove old macro */
3130 if ((*cp3
) && (cp3
< Ar
->start
+ Ar
->size
)) {
3131 for (; cp3
< Ar
->start
+ Ar
->size
; cp3
++) {
3135 for (; cp2
< Ar
->start
+ Ar
->size
; cp2
++) {
3139 /* check next name */
3151 Ar
->start
= getmem(Ar
->size
);
3152 for (len_array
=0; len_array
< Ar
->size
; len_array
++) {
3153 Ar
->start
[len_array
] = 0;
3156 strcpy(Ar
->start
, cp1
);
3157 retmem((wchar_t *) cp1
);
3161 len_array
= strlen(Ar
->start
);
3162 esc_value
= (char*)malloc(strlen(value
)*2 + 1);
3163 quote_str(value
, esc_value
);
3164 esc_len
= strlen(esc_value
) - strlen(value
);
3165 if (len_array
+ len_macro
+ esc_len
+ 5 >= Ar
->size
) goto ALLOC_ARRAY
;
3166 strcat(Ar
->start
, " ");
3167 strncat(Ar
->start
, name
, cp0
-name
);
3168 strcat(Ar
->start
, "=");
3169 strncat(Ar
->start
, esc_value
, strlen(esc_value
));
3173 /* Macro without '=' or with invalid left/right part */
3178 report_dir_enter_leave(Boolean entering
)
3180 char rcwd
[MAXPATHLEN
];
3181 static char * mlev
= NULL
;
3182 char * make_level_str
= NULL
;
3183 int make_level_val
= 0;
3185 make_level_str
= getenv("MAKELEVEL");
3186 if(make_level_str
) {
3187 make_level_val
= atoi(make_level_str
);
3190 mlev
= (char*) malloc(MAXPATHLEN
);
3193 sprintf(mlev
, "MAKELEVEL=%d", make_level_val
+ 1);
3196 sprintf(mlev
, "MAKELEVEL=%d", make_level_val
);
3201 if(make_level_val
<= 0) {
3204 gettext("%s: Entering directory `%s'\n"),
3206 get_current_path());
3209 gettext("%s: Leaving directory `%s'\n"),
3211 get_current_path());
3216 gettext("%s[%d]: Entering directory `%s'\n"),
3218 make_level_val
, get_current_path());
3221 gettext("%s[%d]: Leaving directory `%s'\n"),
3223 make_level_val
, get_current_path());