Formerly expand.c.~8~
[make.git] / main.c
blob0996ed666b28f20945507ad273f4148402377a30
1 /* Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
2 This file is part of GNU Make.
4 GNU Make is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 GNU Make is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with GNU Make; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
18 #include "make.h"
19 #include "commands.h"
20 #include "dep.h"
21 #include "file.h"
22 #include "variable.h"
23 #include "job.h"
24 #include "getopt.h"
27 extern char *version_string;
29 extern struct dep *read_all_makefiles ();
31 extern void print_variable_data_base ();
32 extern void print_dir_data_base ();
33 extern void print_rule_data_base ();
34 extern void print_file_data_base ();
35 extern void print_vpath_data_base ();
37 #ifndef HAVE_UNISTD_H
38 extern int chdir ();
39 #endif
40 #ifndef STDC_HEADERS
41 #ifndef sun /* Sun has an incorrect decl in a header. */
42 extern void exit ();
43 #endif
44 extern double atof ();
45 #endif
46 extern char *mktemp ();
48 static void log_working_directory ();
49 static void print_data_base (), print_version ();
50 static void decode_switches (), decode_env_switches ();
51 static void define_makeflags ();
54 #if 0 /* dummy tag */
55 flags () {}
56 #endif
57 /* Flags:
58 * -b ignored for compatibility with System V Make
59 * -C change directory
60 * -d debug
61 * -e env_overrides
62 * -f makefile
63 * -i ignore_errors
64 * -j job_slots
65 * -k keep_going
66 * -l max_load_average
67 * -m ignored for compatibility with something or other
68 * -n just_print
69 * -o consider file old
70 * -p print_data_base
71 * -q question
72 * -r no_builtin_rules
73 * -s silent
74 * -S turn off -k
75 * -t touch
76 * -v print version information
77 * -w log working directory
78 * -W consider file new (with -n, `what' if effect)
81 /* The structure that describes an accepted command switch. */
83 struct command_switch
85 char c; /* The switch character. */
87 enum /* Type of the value. */
89 flag, /* Turn int flag on. */
90 flag_off, /* Turn int flag off. */
91 string, /* One string per switch. */
92 positive_int, /* A positive integer. */
93 floating, /* A floating-point number (double). */
94 ignore, /* Ignored. */
95 usage_and_exit /* Ignored; exit after processing switches. */
96 } type;
98 char *value_ptr; /* Pointer to the value-holding variable. */
100 unsigned int env:1; /* Can come from MAKEFLAGS. */
101 unsigned int toenv:1; /* Should be put in MAKEFLAGS. */
102 unsigned int no_makefile:1; /* Don't propagate when remaking makefiles. */
104 char *noarg_value; /* Pointer to value used if no argument is given. */
105 char *default_value;/* Pointer to default value. */
107 char *long_name; /* Long option name. */
108 char *argdesc; /* Descriptive word for argument. */
109 char *description; /* Description for usage message. */
113 /* The structure used to hold the list of strings given
114 in command switches of a type that takes string arguments. */
116 struct stringlist
118 char **list; /* Nil-terminated list of strings. */
119 unsigned int idx; /* Index into above. */
120 unsigned int max; /* Number of pointers allocated. */
124 /* The recognized command switches. */
126 /* Nonzero means do not print commands to be executed (-s). */
128 int silent_flag;
130 /* Nonzero means just touch the files
131 that would appear to need remaking (-t) */
133 int touch_flag;
135 /* Nonzero means just print what commands would need to be executed,
136 don't actually execute them (-n). */
138 int just_print_flag;
140 /* Print debugging trace info (-d). */
142 int debug_flag = 0;
144 /* Environment variables override makefile definitions. */
146 int env_overrides = 0;
148 /* Nonzero means ignore status codes returned by commands
149 executed to remake files. Just treat them all as successful (-i). */
151 int ignore_errors_flag = 0;
153 /* Nonzero means don't remake anything, just print the data base
154 that results from reading the makefile (-p). */
156 int print_data_base_flag = 0;
158 /* Nonzero means don't remake anything; just return a nonzero status
159 if the specified targets are not up to date (-q). */
161 int question_flag = 0;
163 /* Nonzero means do not use any of the builtin rules (-r). */
165 int no_builtin_rules_flag = 0;
167 /* Nonzero means keep going even if remaking some file fails (-k). */
169 int keep_going_flag;
170 int default_keep_going_flag = 0;
172 /* Nonzero means print directory before starting and when done (-w). */
174 int print_directory_flag = 0;
176 /* Nonzero means ignore print_directory_flag and never print the directory.
177 This is necessary because print_directory_flag is set implicitly. */
179 int inhibit_print_directory_flag = 0;
181 /* Nonzero means print version information. */
183 int print_version_flag = 0;
185 /* List of makefiles given with -f switches. */
187 static struct stringlist *makefiles = 0;
190 /* Number of job slots (commands that can be run at once). */
192 unsigned int job_slots = 1;
193 unsigned int default_job_slots = 1;
195 /* Value of job_slots that means no limit. */
197 static unsigned int inf_jobs = 0;
199 /* Maximum load average at which multiple jobs will be run.
200 Negative values mean unlimited, while zero means limit to
201 zero load (which could be useful to start infinite jobs remotely
202 but one at a time locally). */
204 double max_load_average = -1.0;
205 double default_load_average = -1.0;
207 /* List of directories given with -c switches. */
209 static struct stringlist *directories = 0;
211 /* List of include directories given with -I switches. */
213 static struct stringlist *include_directories = 0;
215 /* List of files given with -o switches. */
217 static struct stringlist *old_files = 0;
219 /* List of files given with -W switches. */
221 static struct stringlist *new_files = 0;
223 /* The table of command switches. */
225 static const struct command_switch switches[] =
227 { 'b', ignore, 0, 0, 0, 0, 0, 0,
228 0, 0,
229 "Ignored for compatibility" },
230 { 'C', string, (char *) &directories, 0, 0, 0, 0, 0,
231 "directory", "DIRECTORY",
232 "Change to DIRECTORY before doing anything" },
233 { 'd', flag, (char *) &debug_flag, 1, 1, 0, 0, 0,
234 "debug", 0,
235 "Print lots of debugging information" },
236 { 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0,
237 "environment-overrides", 0,
238 "Environment variables override makefiles" },
239 { 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0,
240 "file", "FILE",
241 "Read FILE as a makefile" },
242 { 'h', usage_and_exit, 0, 0, 0, 0, 0, 0,
243 "help", 0,
244 "Print this message and exit" },
245 { 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0,
246 "ignore-errors", 0,
247 "Ignore errors from commands" },
248 { 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0,
249 "include-dir", "DIRECTORY",
250 "Search DIRECTORY for included makefiles" },
251 { 'j', positive_int, (char *) &job_slots, 1, 1, 0,
252 (char *) &inf_jobs, (char *) &default_job_slots,
253 "jobs", "N",
254 "Allow N jobs at once; infinite jobs with no arg" },
255 { 'k', flag, (char *) &keep_going_flag, 1, 1, 0,
256 0, (char *) &default_keep_going_flag,
257 "keep-going", 0,
258 "Keep going when some targets can't be made" },
259 { 'l', floating, (char *) &max_load_average, 1, 1, 0,
260 (char *) &default_load_average, (char *) &default_load_average,
261 "load-average", "N",
262 "Don't start multiple jobs unless load is below N" },
263 { 'm', ignore, 0, 0, 0, 0, 0, 0,
264 0, 0,
265 "-b" },
266 { 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0,
267 "just-print", 0,
268 "Don't actually run any commands; just print them" },
269 { 'o', string, (char *) &old_files, 0, 0, 0, 0, 0,
270 "old-file", "FILE",
271 "Consider FILE to be very old and don't remake it" },
272 { 'p', flag, (char *) &print_data_base_flag, 1, 1, 0, 0, 0,
273 "print-data-base", 0,
274 "Print make's internal database" },
275 { 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0,
276 "question", 0,
277 "Run no commands; exit status says if up to date" },
278 { 'r', flag, (char *) &no_builtin_rules_flag, 1, 1, 0, 0, 0,
279 "no-builtin-rules", 0,
280 "Disable the built-in implicit rules" },
281 { 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0,
282 "silent", 0,
283 "Don't echo commands" },
284 { 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0,
285 0, (char *) &default_keep_going_flag,
286 "no-keep-going", 0,
287 "Turns off -k" },
288 { 't', flag, (char *) &touch_flag, 1, 1, 1, 0, 0,
289 "touch", 0,
290 "Touch targets instead of remaking them" },
291 { 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0,
292 "version", 0,
293 "Print the version number of make" },
294 { 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0,
295 "print-directory", 0,
296 "Print the current directory" },
297 { 1, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
298 "no-print-directory", 0,
299 "Turn off -w, even if it was turned on implicitly" },
300 { 'W', string, (char *) &new_files, 0, 0, 0, 0, 0,
301 "what-if", "FILE",
302 "Consider FILE to be infinitely new" },
303 { '\0', }
306 /* Secondary long names for options. */
308 static struct option long_option_aliases[] =
310 { "quiet", no_argument, 0, 's' },
311 { "stop", no_argument, 0, 'S' },
312 { "new-file", required_argument, 0, 'W' },
313 { "assume-new", required_argument, 0, 'W' },
314 { "assume-old", required_argument, 0, 'o' },
315 { "max-load", optional_argument, 0, 'l' },
316 { "dry-run", no_argument, 0, 'n' },
317 { "recon", no_argument, 0, 'n' },
318 { "makefile", required_argument, 0, 'f' },
321 /* The usage message prints the descriptions of options starting in
322 this column. Make sure it leaves enough room for the longest
323 description to fit in less than 80 characters. */
325 #define DESCRIPTION_COLUMN 30
327 /* List of non-switch arguments. */
329 struct stringlist *other_args = 0;
331 /* The name we were invoked with. */
333 char *program;
335 /* Our current directory after processing all -C options. */
337 char *starting_directory;
339 /* Value of the MAKELEVEL variable at startup (or 0). */
341 unsigned int makelevel;
343 /* First file defined in the makefile whose name does not
344 start with `.'. This is the default to remake if the
345 command line does not specify. */
347 struct file *default_goal_file;
349 /* Pointer to structure for the file .DEFAULT
350 whose commands are used for any file that has none of its own.
351 This is zero if the makefiles do not define .DEFAULT. */
353 struct file *default_file;
355 /* Mask of signals that are being caught with fatal_error_signal. */
357 #ifdef POSIX
358 sigset_t fatal_signal_set;
359 #else
360 #ifdef HAVE_SIGSETMASK
361 int fatal_signal_mask;
362 #endif
363 #endif
366 main (argc, argv, envp)
367 int argc;
368 char **argv;
369 char **envp;
371 extern void init_dir ();
372 extern RETSIGTYPE fatal_error_signal (), child_handler ();
373 register struct file *f;
374 register unsigned int i;
375 register char *cmd_defs;
376 register unsigned int cmd_defs_len, cmd_defs_idx;
377 char **p;
378 time_t now;
379 struct dep *goals = 0;
380 register struct dep *lastgoal;
381 struct dep *read_makefiles;
382 PATH_VAR (current_directory);
383 char *directory_before_chdir;
385 default_goal_file = 0;
386 reading_filename = 0;
387 reading_lineno_ptr = 0;
389 #ifndef HAVE_SYS_SIGLIST
390 signame_init ();
391 #endif
393 #ifdef POSIX
394 sigemptyset (&fatal_signal_set);
395 #define ADD_SIG(sig) sigaddset (&fatal_signal_set, sig)
396 #else
397 #ifdef HAVE_SIGSETMASK
398 fatal_signal_mask = 0;
399 #define ADD_SIG(sig) fatal_signal_mask |= sigmask (sig)
400 #else
401 #define ADD_SIG(sig)
402 #endif
403 #endif
405 #define FATAL_SIG(sig) \
406 if (signal ((sig), fatal_error_signal) == SIG_IGN) \
407 (void) signal ((sig), SIG_IGN); \
408 else \
409 ADD_SIG (sig);
411 FATAL_SIG (SIGHUP);
412 FATAL_SIG (SIGQUIT);
413 FATAL_SIG (SIGINT);
414 FATAL_SIG (SIGTERM);
416 #ifdef SIGDANGER
417 FATAL_SIG (SIGDANGER);
418 #endif
419 #ifdef SIGXCPU
420 FATAL_SIG (SIGXCPU);
421 #endif
422 #ifdef SIGXFSZ
423 FATAL_SIG (SIGXFSZ);
424 #endif
426 #undef FATAL_SIG
428 /* Make sure stdout is line-buffered. */
430 #ifdef HAVE_SETLINEBUF
431 setlinebuf (stdout);
432 #else
433 #ifndef SETVBUF_REVERSED
434 setvbuf (stdout, (char *) 0, _IOLBF, BUFSIZ);
435 #else /* setvbuf not reversed. */
436 /* Some buggy systems lose if we pass 0 instead of allocating ourselves. */
437 setvbuf (stdout, _IOLBF, xmalloc (BUFSIZ), BUFSIZ);
438 #endif /* setvbuf reversed. */
439 #endif /* setlinebuf missing. */
441 /* Initialize the directory hashing code. */
442 init_dir ();
444 /* Set up to access user data (files). */
445 user_access ();
447 /* Figure out where this program lives. */
449 if (argv[0] == 0)
450 argv[0] = "";
451 if (argv[0][0] == '\0')
452 program = "make";
453 else
455 program = rindex (argv[0], '/');
456 if (program == 0)
457 program = argv[0];
458 else
459 ++program;
462 /* Figure out where we are. */
464 if (getcwd (current_directory, GET_PATH_MAX) == 0)
466 #ifdef HAVE_GETCWD
467 perror_with_name ("getcwd: ", "");
468 #else
469 error ("getwd: %s", current_directory);
470 #endif
471 current_directory[0] = '\0';
472 directory_before_chdir = 0;
474 else
475 directory_before_chdir = savestring (current_directory,
476 strlen (current_directory));
478 /* Read in variables from the environment. It is important that this be
479 done before `MAKE' and `MAKEOVERRIDES' are figured out so their
480 definitions will not be ones from the environment. */
482 for (i = 0; envp[i] != 0; ++i)
484 register char *ep = envp[i];
485 while (*ep++ != '=')
487 (void) define_variable (envp[i], ep - envp[i] - 1, ep, o_env, 1);
490 /* Decode the switches. */
492 decode_env_switches ("MAKEFLAGS", 9);
493 decode_env_switches ("MFLAGS", 6);
494 decode_switches (argc, argv, 0);
496 /* Print version information. */
498 if (print_version_flag || print_data_base_flag || debug_flag)
499 print_version ();
501 /* Search for command line arguments that define variables,
502 and do the definitions. Also save up the text of these
503 arguments in CMD_DEFS so we can put them into the values
504 of $(MAKEOVERRIDES) and $(MAKE). */
506 cmd_defs_len = 200;
507 cmd_defs = (char *) xmalloc (cmd_defs_len);
508 cmd_defs_idx = 0;
510 for (i = 1; other_args->list[i] != 0; ++i)
512 if (other_args->list[i][0] == '\0')
513 /* Ignore empty arguments, so they can't kill enter_file. */
514 continue;
516 /* Try a variable definition. */
517 if (try_variable_definition ((char *) 0, 0,
518 other_args->list[i], o_command))
520 /* It succeeded. The variable is already defined.
521 Backslash-quotify it and append it to CMD_DEFS, then clobber it
522 to 0 in the list so that it won't be taken for a goal target. */
523 register char *p = other_args->list[i];
524 unsigned int l = strlen (p);
525 if (cmd_defs_idx + (l * 2) + 1 > cmd_defs_len)
527 if (l * 2 > cmd_defs_len)
528 cmd_defs_len += l * 2;
529 else
530 cmd_defs_len *= 2;
531 cmd_defs = (char *) xrealloc (cmd_defs, cmd_defs_len);
534 while (*p != '\0')
536 if (index (";'\"*?[]$<>(){}|&~`\\ \t\r\n\f\v", *p) != 0)
537 cmd_defs[cmd_defs_idx++] = '\\';
538 cmd_defs[cmd_defs_idx++] = *p++;
540 cmd_defs[cmd_defs_idx++] = ' ';
542 else
544 /* It was not a variable definition, so it is a target to be made.
545 Enter it as a file and add it to the dep chain of goals. */
546 f = enter_file (other_args->list[i]);
547 f->cmd_target = 1;
549 if (goals == 0)
551 goals = (struct dep *) xmalloc (sizeof (struct dep));
552 lastgoal = goals;
554 else
556 lastgoal->next = (struct dep *) xmalloc (sizeof (struct dep));
557 lastgoal = lastgoal->next;
559 lastgoal->name = 0;
560 lastgoal->file = f;
564 if (cmd_defs_idx > 0)
566 cmd_defs[cmd_defs_idx - 1] = '\0';
567 (void) define_variable ("MAKEOVERRIDES", 13, cmd_defs, o_default, 0);
569 free (cmd_defs);
571 /* Set the "MAKE_COMMAND" variable to the name we were invoked with.
572 (If it is a relative pathname with a slash, prepend our directory name
573 so the result will run the same program regardless of the current dir.
574 If it is a name with no slash, we can only hope that PATH did not
575 find it in the current directory.) */
577 if (current_directory[0] != '\0'
578 && argv[0] != 0 && argv[0][0] != '/' && index (argv[0], '/') != 0)
579 argv[0] = concat (current_directory, "/", argv[0]);
581 (void) define_variable ("MAKE_COMMAND", 12, argv[0], o_default, 0);
583 /* Append the command-line variable definitions gathered above
584 so sub-makes will get them as command-line definitions. */
586 (void) define_variable ("MAKE", 4,
587 "$(MAKE_COMMAND) $(MAKEOVERRIDES)", o_default, 1);
589 /* If there were -C flags, move ourselves about. */
591 if (directories != 0)
592 for (i = 0; directories->list[i] != 0; ++i)
594 char *dir = directories->list[i];
595 if (chdir (dir) < 0)
596 pfatal_with_name (dir);
599 /* Figure out the level of recursion. */
601 struct variable *v = lookup_variable ("MAKELEVEL", 9);
602 if (v != 0 && *v->value != '\0' && *v->value != '-')
603 makelevel = (unsigned int) atoi (v->value);
604 else
605 makelevel = 0;
608 /* Except under -s, always do -w in sub-makes and under -C. */
609 if (!silent_flag && (directories != 0 || makelevel > 0))
610 print_directory_flag = 1;
612 /* Let the user disable that with --no-print-directory. */
613 if (inhibit_print_directory_flag)
614 print_directory_flag = 0;
616 /* Construct the list of include directories to search. */
618 construct_include_path (include_directories == 0 ? (char **) 0
619 : include_directories->list);
621 /* Figure out where we are now, after chdir'ing. */
622 if (directories == 0)
623 /* We didn't move, so we're still in the same place. */
624 starting_directory = current_directory;
625 else
627 if (getcwd (current_directory, GET_PATH_MAX) == 0)
629 #ifdef HAVE_GETCWD
630 perror_with_name ("getcwd: ", "");
631 #else
632 error ("getwd: %s", current_directory);
633 #endif
634 starting_directory = 0;
636 else
637 starting_directory = current_directory;
640 /* Tell the user where he is. */
642 if (print_directory_flag)
643 log_working_directory (1);
645 /* Read any stdin makefiles into temporary files. */
647 if (makefiles != 0)
649 register unsigned int i;
650 for (i = 0; i < makefiles->idx; ++i)
651 if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0')
653 /* This makefile is standard input. Since we may re-exec
654 and thus re-read the makefiles, we read standard input
655 into a temporary file and read from that. */
656 static char name[] = "/tmp/GmXXXXXX";
657 FILE *outfile;
659 /* Free the storage allocated for "-". */
660 free (makefiles->list[i]);
662 /* Make a unique filename. */
663 (void) mktemp (name);
665 outfile = fopen (name, "w");
666 if (outfile == 0)
667 pfatal_with_name ("fopen (temporary file)");
668 while (!feof (stdin))
670 char buf[2048];
671 int n = fread (buf, 1, sizeof(buf), stdin);
672 if (n > 0 && fwrite (buf, 1, n, outfile) != n)
673 pfatal_with_name ("fwrite (temporary file)");
675 /* Try to make sure we won't remake the temporary
676 file when we are re-exec'd. Kludge-o-matic! */
677 fprintf (outfile, "%s:;\n", name);
678 (void) fclose (outfile);
680 /* Replace the name that read_all_makefiles will
681 see with the name of the temporary file. */
682 makefiles->list[i] = savestring (name, sizeof name - 1);
684 /* Make sure the temporary file will not be remade. */
685 f = enter_file (savestring (name, sizeof name - 1));
686 f->updated = 1;
687 f->update_status = 0;
688 f->command_state = cs_finished;
689 /* Let it be removed when we're done. */
690 f->intermediate = 1;
691 /* But don't mention it. */
692 f->dontcare = 1;
696 /* Set up to handle children dying. This must be done before
697 reading in the makefiles so that `shell' function calls will work. */
699 #ifdef SIGCHLD
700 (void) signal (SIGCHLD, child_handler);
701 #endif
702 #ifdef SIGCLD
703 (void) signal (SIGCLD, child_handler);
704 #endif
706 /* Define the initial list of suffixes for old-style rules. */
708 set_default_suffixes ();
710 /* Define some internal and special variables. */
712 define_automatic_variables ();
714 /* Set up the MAKEFLAGS and MFLAGS variables
715 so makefiles can look at them. */
717 define_makeflags (0, 0);
719 /* Define the default variables. */
720 define_default_variables ();
722 /* Read all the makefiles. */
724 default_file = enter_file (".DEFAULT");
726 read_makefiles
727 = read_all_makefiles (makefiles == 0 ? (char **) 0 : makefiles->list);
729 /* Decode switches again, in case the variables were set by the makefile. */
730 decode_env_switches ("MAKEFLAGS", 9);
731 decode_env_switches ("MFLAGS", 6);
733 /* Set up MAKEFLAGS and MFLAGS again, so they will be right. */
735 define_makeflags (1, 0);
737 ignore_errors_flag |= lookup_file (".IGNORE") != 0;
739 silent_flag |= lookup_file (".SILENT") != 0;
741 /* Make each `struct dep' point at the
742 `struct file' for the file depended on. */
744 snap_deps ();
746 /* Install the default implicit rules.
747 This used to be done before reading the makefiles.
748 But in that case, built-in pattern rules were in the chain
749 before user-defined ones, so they matched first. */
751 install_default_implicit_rules ();
753 /* Convert old-style suffix rules to pattern rules. */
755 convert_to_pattern ();
757 /* Compute implicit rule limits. */
759 count_implicit_rule_limits ();
761 /* Construct the listings of directories in VPATH lists. */
763 build_vpath_lists ();
765 /* Mark files given with -o flags as very old (00:00:01.00 Jan 1, 1970)
766 and as having been updated already, and files given with -W flags
767 as brand new (time-stamp of now). */
769 if (old_files != 0)
770 for (p = old_files->list; *p != 0; ++p)
772 f = enter_file (*p);
773 f->last_mtime = (time_t) 1;
774 f->updated = 1;
775 f->update_status = 0;
776 f->command_state = cs_finished;
779 if (new_files != 0)
781 now = time ((time_t *) 0);
782 for (p = new_files->list; *p != 0; ++p)
784 f = enter_file (*p);
785 f->last_mtime = now;
789 if (read_makefiles != 0)
791 /* Update any makefiles if necessary. */
793 time_t *makefile_mtimes = 0;
794 unsigned int mm_idx = 0;
796 if (debug_flag)
797 puts ("Updating makefiles....");
799 /* Remove any makefiles we don't want to try to update.
800 Also record the current modtimes so we can compare them later. */
802 register struct dep *d, *last;
803 last = 0;
804 d = read_makefiles;
805 while (d != 0)
807 register struct file *f = d->file;
808 if (f->double_colon)
811 if (f->deps == 0 && f->cmds != 0)
813 /* This makefile is a :: target with commands, but
814 no dependencies. So, it will always be remade.
815 This might well cause an infinite loop, so don't
816 try to remake it. (This will only happen if
817 your makefiles are written exceptionally
818 stupidly; but if you work for Athena, that's how
819 you write your makefiles.) */
821 if (debug_flag)
822 printf ("Makefile `%s' might loop; not remaking it.\n",
823 f->name);
825 if (last == 0)
826 read_makefiles = d->next;
827 else
828 last->next = d->next;
830 /* Free the storage. */
831 free ((char *) d);
833 d = last == 0 ? 0 : last->next;
835 break;
837 f = f->prev;
839 while (f != NULL);
840 if (f == NULL || !f->double_colon)
842 if (makefile_mtimes == 0)
843 makefile_mtimes = (time_t *) xmalloc (sizeof (time_t));
844 else
845 makefile_mtimes = (time_t *)
846 xrealloc ((char *) makefile_mtimes,
847 (mm_idx + 1) * sizeof (time_t));
848 makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file);
849 last = d;
850 d = d->next;
855 /* Set up `MAKEFLAGS' specially while remaking makefiles. */
856 define_makeflags (1, 1);
858 switch (update_goal_chain (read_makefiles, 1))
860 default:
861 abort ();
863 case -1:
864 /* Did nothing. */
865 break;
867 case 1:
868 /* Failed to update. Figure out if we care. */
870 /* Nonzero if any makefile was successfully remade. */
871 int any_remade = 0;
872 /* Nonzero if any makefile we care about failed
873 in updating or could not be found at all. */
874 int any_failed = 0;
875 register unsigned int i;
877 for (i = 0; read_makefiles != 0; ++i)
879 struct dep *d = read_makefiles;
880 read_makefiles = d->next;
881 if (d->file->updated)
883 /* This makefile was updated. */
884 if (d->file->update_status == 0)
886 /* It was successfully updated. */
887 any_remade |= (file_mtime_no_search (d->file)
888 != makefile_mtimes[i]);
890 else if (d->changed != 1)
892 time_t mtime;
893 /* The update failed and this makefile was not
894 from the MAKEFILES variable, so we care. */
895 error ("Failed to remake makefile `%s'.",
896 d->file->name);
897 mtime = file_mtime_no_search (d->file);
898 any_remade |= (mtime != (time_t) -1
899 && mtime != makefile_mtimes[i]);
902 else
903 /* This makefile was not found at all. */
904 switch (d->changed)
906 case 0:
907 /* A normal makefile. We must die later. */
908 error ("Makefile `%s' was not found", dep_name (d));
909 any_failed = 1;
910 break;
911 case 1:
912 /* A makefile from the MAKEFILES variable.
913 We don't care. */
914 break;
915 case 2:
916 /* An included makefile. We don't need
917 to die, but we do want to complain. */
918 error ("Included makefile `%s' was not found.",
919 dep_name (d));
920 break;
923 free ((char *) d);
926 if (any_remade)
927 goto re_exec;
928 else if (any_failed)
929 die (1);
930 else
931 break;
934 case 0:
935 re_exec:;
936 /* Updated successfully. Re-exec ourselves. */
937 if (print_directory_flag)
938 log_working_directory (0);
939 if (debug_flag)
940 puts ("Re-execing myself....");
941 if (makefiles != 0)
943 /* These names might have changed. */
944 register unsigned int i, j = 0;
945 for (i = 1; i < argc; ++i)
946 if (!strcmp (argv[i], "-f"))
948 char *p = &argv[i][2];
949 if (*p == '\0')
950 argv[++i] = makefiles->list[j];
951 else
952 argv[i] = concat ("-f", makefiles->list[j], "");
953 ++j;
956 if (directories != 0 && directories->idx > 0)
958 char bad;
959 if (directory_before_chdir != 0)
961 if (chdir (directory_before_chdir) < 0)
963 perror_with_name ("chdir", "");
964 bad = 1;
966 else
967 bad = 0;
969 else
970 bad = 1;
971 if (bad)
972 fatal ("Couldn't change back to original directory.");
974 fflush (stdout);
975 fflush (stderr);
976 for (p = environ; *p != 0; ++p)
977 if (!strncmp (*p, "MAKELEVEL=", 10))
979 /* The SGI compiler apparently can't understand
980 the concept of storing the result of a function
981 in something other than a local variable. */
982 char *sgi_loses;
983 sgi_loses = (char *) alloca (40);
984 *p = sgi_loses;
985 sprintf (*p, "MAKELEVEL=%u", makelevel);
986 break;
988 exec_command (argv, environ);
989 /* NOTREACHED */
993 /* Set up `MAKEFLAGS' again for the normal targets. */
994 define_makeflags (1, 0);
997 int status;
999 /* If there were no command-line goals, use the default. */
1000 if (goals == 0)
1002 if (default_goal_file != 0)
1004 goals = (struct dep *) xmalloc (sizeof (struct dep));
1005 goals->next = 0;
1006 goals->name = 0;
1007 goals->file = default_goal_file;
1010 else
1011 lastgoal->next = 0;
1013 if (goals != 0)
1015 /* Update the goals. */
1017 if (debug_flag)
1018 puts ("Updating goal targets....");
1020 switch (update_goal_chain (goals, 0))
1022 case -1:
1023 /* Nothing happened. */
1024 case 0:
1025 /* Updated successfully. */
1026 status = 0;
1027 break;
1028 case 1:
1029 /* Updating failed. */
1030 status = 1;
1031 break;
1032 default:
1033 abort ();
1036 else
1038 if (read_makefiles == 0)
1039 fatal ("No targets specified and no makefile found");
1040 else
1041 fatal ("No targets");
1044 /* Exit. */
1045 die (status);
1048 return 0;
1051 /* Parsing of arguments, decoding of switches. */
1053 static char options[sizeof (switches) / sizeof (switches[0]) * 3];
1054 static struct option long_options[(sizeof (switches) / sizeof (switches[0])) +
1055 (sizeof (long_option_aliases) /
1056 sizeof (long_option_aliases[0]))];
1058 /* Fill in the string and vector for getopt. */
1059 static void
1060 init_switches ()
1062 register char *p;
1063 register int c;
1064 register unsigned int i;
1066 if (options[0] != '\0')
1067 /* Already done. */
1068 return;
1070 p = options;
1071 for (i = 0; switches[i].c != '\0'; ++i)
1073 long_options[i].name = (switches[i].long_name == 0 ? "" :
1074 switches[i].long_name);
1075 long_options[i].flag = 0;
1076 long_options[i].val = switches[i].c;
1077 if (isalnum (switches[i].c))
1078 *p++ = switches[i].c;
1079 switch (switches[i].type)
1081 case flag:
1082 case flag_off:
1083 case ignore:
1084 case usage_and_exit:
1085 long_options[i].has_arg = no_argument;
1086 break;
1088 case string:
1089 case positive_int:
1090 case floating:
1091 if (isalnum (switches[i].c))
1092 *p++ = ':';
1093 if (switches[i].noarg_value != 0)
1095 if (isalnum (switches[i].c))
1096 *p++ = ':';
1097 long_options[i].has_arg = optional_argument;
1099 else
1100 long_options[i].has_arg = required_argument;
1101 break;
1104 *p = '\0';
1105 for (c = 0; c < (sizeof (long_option_aliases) /
1106 sizeof (long_option_aliases[0]));
1107 ++c)
1108 long_options[i++] = long_option_aliases[c];
1109 long_options[i].name = 0;
1112 /* Decode switches from ARGC and ARGV.
1113 They came from the environment if ENV is nonzero. */
1115 static void
1116 decode_switches (argc, argv, env)
1117 int argc;
1118 char **argv;
1119 int env;
1121 int bad = 0;
1122 register const struct command_switch *cs;
1123 register struct stringlist *sl;
1124 register int c;
1126 if (!env)
1128 other_args = (struct stringlist *) xmalloc (sizeof (struct stringlist));
1129 other_args->max = argc + 1;
1130 other_args->list = (char **) xmalloc ((argc + 1) * sizeof (char *));
1131 other_args->idx = 1;
1132 other_args->list[0] = savestring (argv[0], strlen (argv[0]));
1135 /* getopt does most of the parsing for us.
1136 First, get its vectors set up. */
1138 init_switches ();
1140 /* Let getopt produce error messages for the command line,
1141 but not for options from the environment. */
1142 opterr = !env;
1143 /* Reset getopt's state. */
1144 optind = 0;
1146 while ((c = getopt_long (argc, argv,
1147 options, long_options, (int *) 0)) != EOF)
1149 if (c == '?')
1150 /* Bad option. We will print a usage message and die later.
1151 But continue to parse the other options so the user can
1152 see all he did wrong. */
1153 bad = 1;
1154 else
1155 for (cs = switches; cs->c != '\0'; ++cs)
1156 if (cs->c == c)
1158 /* Whether or not we will actually do anything with
1159 this switch. We test this individually inside the
1160 switch below rather than just once outside it, so that
1161 options which are to be ignored still consume args. */
1162 int doit = !env || cs->env;
1164 switch (cs->type)
1166 default:
1167 abort ();
1169 case ignore:
1170 break;
1172 case usage_and_exit:
1173 bad = 1;
1174 break;
1176 case flag:
1177 case flag_off:
1178 if (doit)
1179 *(int *) cs->value_ptr = cs->type == flag;
1180 break;
1182 case string:
1183 if (!doit)
1184 break;
1186 if (optarg == 0)
1187 optarg = cs->noarg_value;
1189 sl = *(struct stringlist **) cs->value_ptr;
1190 if (sl == 0)
1192 sl = (struct stringlist *)
1193 xmalloc (sizeof (struct stringlist));
1194 sl->max = 5;
1195 sl->idx = 0;
1196 sl->list = (char **) xmalloc (5 * sizeof (char *));
1197 *(struct stringlist **) cs->value_ptr = sl;
1199 else if (sl->idx == sl->max - 1)
1201 sl->max += 5;
1202 sl->list = (char **)
1203 xrealloc ((char *) sl->list,
1204 sl->max * sizeof (char *));
1206 sl->list[sl->idx++] = savestring (optarg, strlen (optarg));
1207 sl->list[sl->idx] = 0;
1208 break;
1210 case positive_int:
1211 if (optarg == 0 && argc > optind
1212 && isdigit (argv[optind][0]))
1213 optarg = argv[optind++];
1215 if (!doit)
1216 break;
1218 if (optarg != 0)
1220 int i = atoi (optarg);
1221 if (i < 1)
1223 if (doit)
1224 error ("the `-%c' option requires a \
1225 positive integral argument",
1226 cs->c);
1227 bad = 1;
1229 else
1230 *(unsigned int *) cs->value_ptr = i;
1232 else
1233 *(unsigned int *) cs->value_ptr
1234 = *(unsigned int *) cs->noarg_value;
1235 break;
1237 case floating:
1238 if (optarg == 0 && optind < argc
1239 && (isdigit (argv[optind][0]) || argv[optind][0] == '.'))
1240 optarg = argv[optind++];
1242 if (doit)
1243 *(double *) cs->value_ptr
1244 = (optarg != 0 ? atof (optarg)
1245 : *(double *) cs->noarg_value);
1247 break;
1250 /* We've found the switch. Stop looking. */
1251 break;
1255 if (!env)
1257 /* Collect the remaining args in the `other_args' string list. */
1259 while (optind < argc)
1261 char *arg = argv[optind++];
1262 if (arg[0] != '-' || arg[1] != '\0')
1263 other_args->list[other_args->idx++] = arg;
1265 other_args->list[other_args->idx] = 0;
1268 if (bad && !env)
1270 /* Print a nice usage message. */
1272 if (print_version_flag)
1273 print_version ();
1275 fprintf (stderr, "Usage: %s [options] [target] ...\n", program);
1277 fputs ("Options:\n", stderr);
1278 for (cs = switches; cs->c != '\0'; ++cs)
1280 char buf[1024], arg[50], *p;
1282 if (cs->description[0] == '-')
1283 continue;
1285 switch (long_options[cs - switches].has_arg)
1287 case no_argument:
1288 arg[0] = '\0';
1289 break;
1290 case required_argument:
1291 sprintf (arg, " %s", cs->argdesc);
1292 break;
1293 case optional_argument:
1294 sprintf (arg, " [%s]", cs->argdesc);
1295 break;
1298 p = buf;
1300 if (isalnum (cs->c))
1302 sprintf (buf, " -%c%s", cs->c, arg);
1303 p += strlen (p);
1305 if (cs->long_name != 0)
1307 unsigned int i;
1308 sprintf (p, "%s--%s%s",
1309 !isalnum (cs->c) ? " " : ", ",
1310 cs->long_name, arg);
1311 p += strlen (p);
1312 for (i = 0; i < (sizeof (long_option_aliases) /
1313 sizeof (long_option_aliases[0]));
1314 ++i)
1315 if (long_option_aliases[i].val == cs->c)
1317 sprintf (p, ", --%s%s", long_option_aliases[i].name, arg);
1318 p += strlen (p);
1322 const struct command_switch *ncs = cs;
1323 while ((++ncs)->c != '\0')
1324 if (ncs->description[0] == '-' &&
1325 ncs->description[1] == cs->c)
1327 /* This is another switch that does the same
1328 one as the one we are processing. We want
1329 to list them all together on one line. */
1330 sprintf (p, ", -%c%s", ncs->c, arg);
1331 p += strlen (p);
1332 if (ncs->long_name != 0)
1334 sprintf (p, ", --%s%s", ncs->long_name, arg);
1335 p += strlen (p);
1340 if (p - buf > DESCRIPTION_COLUMN - 2)
1341 /* The list of option names is too long to fit on the same
1342 line with the description, leaving at least two spaces.
1343 Print it on its own line instead. */
1345 fprintf (stderr, "%s\n", buf);
1346 buf[0] = '\0';
1349 fprintf (stderr, "%*s%s.\n",
1350 - DESCRIPTION_COLUMN,
1351 buf, cs->description);
1354 die (1);
1358 /* Decode switches from environment variable ENVAR (which is LEN chars long).
1359 We do this by chopping the value into a vector of words, prepending a
1360 dash to the first word if it lacks one, and passing the vector to
1361 decode_switches. */
1363 static void
1364 decode_env_switches (envar, len)
1365 char *envar;
1366 unsigned int len;
1368 char *varref = (char *) alloca (2 + len + 2);
1369 char *value, *args;
1370 int argc;
1371 char **argv;
1373 /* Get the variable's value. */
1374 varref[0] = '$';
1375 varref[1] = '(';
1376 bcopy (envar, &varref[2], len);
1377 varref[2 + len] = ')';
1378 varref[2 + len + 1] = '\0';
1379 value = variable_expand (varref);
1381 /* Skip whitespace, and check for an empty value. */
1382 value = next_token (value);
1383 len = strlen (value);
1384 if (len == 0)
1385 return;
1387 /* Make a copy of the value in ARGS, where we will munge it.
1388 If it does not begin with a dash, prepend one. */
1389 args = (char *) alloca (1 + len + 2);
1390 if (value[0] != '-')
1391 args[0] = '-';
1392 bcopy (value, value[0] == '-' ? args : &args[1], len + 1);
1393 /* Write an extra null terminator so our loop below will
1394 never be in danger of looking past the end of the string. */
1395 args[(value[0] == '-' ? 0 : 1) + len + 1] = '\0';
1397 /* Allocate a vector that is definitely big enough. */
1398 argv = (char **) alloca ((1 + len + 1) * sizeof (char *));
1400 /* getopt will look at the arguments starting at ARGV[1].
1401 Prepend a spacer word. */
1402 argv[0] = 0;
1403 argc = 1;
1406 argv[argc++] = args;
1407 args = end_of_token (args);
1408 *args++ = '\0';
1409 } while (*args != '\0');
1410 argv[argc] = 0;
1412 /* Parse those words. */
1413 decode_switches (argc, argv, 1);
1416 /* Define the MAKEFLAGS and MFLAGS variables to reflect the settings of the
1417 command switches. Include options with args if ALL is nonzero.
1418 Don't include options with the `no_makefile' flag set if MAKEFILE. */
1420 static void
1421 define_makeflags (all, makefile)
1422 int all, makefile;
1424 register const struct command_switch *cs;
1425 char *flagstring;
1427 /* We will construct a linked list of `struct flag's describing
1428 all the flags which need to go in MAKEFLAGS. Then, once we
1429 know how many there are and their lengths, we can put them all
1430 together in a string. */
1432 struct flag
1434 struct flag *next;
1435 const struct command_switch *cs;
1436 char *arg;
1437 unsigned int arglen;
1439 struct flag *flags = 0;
1440 unsigned int flagslen = 0;
1441 #define ADD_FLAG(ARG, LEN) \
1442 do { \
1443 struct flag *new = (struct flag *) alloca (sizeof (struct flag)); \
1444 new->cs = cs; \
1445 new->arg = (ARG); \
1446 new->arglen = (LEN); \
1447 new->next = flags; \
1448 flags = new; \
1449 if (new->arg == 0) \
1450 ++flagslen; /* Just a single flag letter. */ \
1451 else \
1452 flagslen += 1 + 1 + 1 + 1 + new->arglen; /* " -x foo" */ \
1453 if (!isalnum (cs->c)) \
1454 /* This switch has no single-letter version, so we use the long. */ \
1455 flagslen += 2 + strlen (cs->long_name); \
1456 } while (0)
1458 for (cs = switches; cs->c != '\0'; ++cs)
1459 if (cs->toenv && (!makefile || !cs->no_makefile))
1460 switch (cs->type)
1462 default:
1463 abort ();
1465 case ignore:
1466 break;
1468 case flag:
1469 case flag_off:
1470 if (!*(int *) cs->value_ptr == (cs->type == flag_off)
1471 && (cs->default_value == 0
1472 || *(int *) cs->value_ptr != *(int *) cs->default_value))
1473 ADD_FLAG (0, 0);
1474 break;
1476 case positive_int:
1477 if (all)
1479 if ((cs->default_value != 0
1480 && (*(unsigned int *) cs->value_ptr
1481 == *(unsigned int *) cs->default_value)))
1482 break;
1483 else if (cs->noarg_value != 0
1484 && (*(unsigned int *) cs->value_ptr ==
1485 *(unsigned int *) cs->noarg_value))
1486 ADD_FLAG ("", 0); /* Optional value omitted; see below. */
1487 else if (cs->c == 'j')
1488 /* Special case for `-j'. */
1489 ADD_FLAG ("1", 1);
1490 else
1492 char *buf = (char *) alloca (30);
1493 sprintf (buf, "%u", *(unsigned int *) cs->value_ptr);
1494 ADD_FLAG (buf, strlen (buf));
1497 break;
1499 case floating:
1500 if (all)
1502 if (cs->default_value != 0
1503 && (*(double *) cs->value_ptr
1504 == *(double *) cs->default_value))
1505 break;
1506 else if (cs->noarg_value != 0
1507 && (*(double *) cs->value_ptr
1508 == *(double *) cs->noarg_value))
1509 ADD_FLAG ("", 0); /* Optional value omitted; see below. */
1510 else
1512 char *buf = (char *) alloca (100);
1513 sprintf (buf, "%g", *(double *) cs->value_ptr);
1514 ADD_FLAG (buf, strlen (buf));
1517 break;
1519 case string:
1520 if (all)
1522 struct stringlist *sl = *(struct stringlist **) cs->value_ptr;
1523 if (sl != 0)
1525 /* Add the elements in reverse order, because
1526 all the flags get reversed below; and the order
1527 matters for some switches (like -I). */
1528 register unsigned int i = sl->idx;
1529 while (i-- > 0)
1530 ADD_FLAG (sl->list[i], strlen (sl->list[i]));
1533 break;
1536 #undef ADD_FLAG
1538 if (flags == 0)
1539 /* No flags. Use a string of two nulls so [1] works below. */
1540 flagstring = "\0";
1541 else
1543 /* Construct the value in FLAGSTRING.
1544 We allocate enough space for a preceding dash and trailing null. */
1545 register char *p;
1546 flagstring = (char *) alloca (1 + flagslen + 1);
1547 p = flagstring;
1548 *p++ = '-';
1551 /* Add the flag letter or name to the string. */
1552 if (!isalnum (flags->cs->c))
1554 *p++ = '-';
1555 strcpy (p, flags->cs->long_name);
1556 p += strlen (p);
1558 else
1559 *p++ = flags->cs->c;
1560 if (flags->arg != 0)
1562 /* A flag that takes an optional argument which in this case
1563 is omitted is specified by ARG being "" and ARGLEN being 0.
1564 We must distinguish because a following flag appended without
1565 an intervening " -" is considered the arg for the first. */
1566 if (flags->arglen > 0)
1568 /* Add its argument too. */
1569 *p++ = !isalnum (flags->cs->c) ? '=' : ' ';
1570 bcopy (flags->arg, p, flags->arglen);
1571 p += flags->arglen;
1573 /* Write a following space and dash, for the next flag. */
1574 *p++ = ' ';
1575 *p++ = '-';
1577 else if (!isalnum (flags->cs->c))
1579 /* Long options must each go in their own word,
1580 so we write the following space and dash. */
1581 *p++ = ' ';
1582 *p++ = '-';
1584 flags = flags->next;
1585 } while (flags != 0);
1587 if (p[-1] == '-')
1588 /* Kill the final space and dash. */
1589 p -= 2;
1591 /* Terminate the string. */
1592 *p = '\0';
1595 (void) define_variable ("MAKEFLAGS", 9,
1596 /* On Sun, the value of MFLAGS starts with a `-' but
1597 the value of MAKEFLAGS lacks the `-'.
1598 Be compatible with this unless FLAGSTRING starts
1599 with a long option `--foo', since removing the
1600 first dash would result in the bogus `-foo'. */
1601 flagstring[1] == '-' ? flagstring : &flagstring[1],
1602 o_env, 0);
1603 (void) define_variable ("MFLAGS", 6, flagstring, o_env, 0);
1606 /* Print version information. */
1608 static void
1609 print_version ()
1611 static int printed_version = 0;
1613 extern char *remote_description;
1614 char *precede = print_data_base_flag ? "# " : "";
1616 if (printed_version)
1617 /* Do it only once. */
1618 return;
1620 printf ("%sGNU Make version %s", precede, version_string);
1621 if (remote_description != 0 && *remote_description != '\0')
1622 printf ("-%s", remote_description);
1624 printf (", by Richard Stallman and Roland McGrath.\n\
1625 %sCopyright (C) 1988, 89, 90, 91, 92, 93 Free Software Foundation, Inc.\n\
1626 %sThis is free software; see the source for copying conditions.\n\
1627 %sThere is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n\
1628 %sPARTICULAR PURPOSE.\n\n", precede, precede, precede, precede);
1630 printed_version = 1;
1632 /* Flush stdout so the user doesn't have to wait to see the
1633 version information while things are thought about. */
1634 fflush (stdout);
1637 /* Print a bunch of information about this and that. */
1639 static void
1640 print_data_base ()
1642 extern char *ctime ();
1643 time_t when;
1645 when = time ((time_t *) 0);
1646 printf ("\n# Make data base, printed on %s", ctime (&when));
1648 print_variable_data_base ();
1649 print_dir_data_base ();
1650 print_rule_data_base ();
1651 print_file_data_base ();
1652 print_vpath_data_base ();
1654 when = time ((time_t *) 0);
1655 printf ("\n# Finished Make data base on %s\n", ctime (&when));
1658 /* Exit with STATUS, cleaning up as necessary. */
1660 void
1661 die (status)
1662 int status;
1664 static char dying = 0;
1666 if (!dying)
1668 int err;
1670 dying = 1;
1672 if (print_version_flag)
1673 print_version ();
1675 /* Wait for children to die. */
1676 for (err = status != 0; job_slots_used > 0; err = 0)
1677 reap_children (1, err);
1679 /* Remove the intermediate files. */
1680 remove_intermediates (0);
1682 if (print_data_base_flag)
1683 print_data_base ();
1685 if (print_directory_flag)
1686 log_working_directory (0);
1689 exit (status);
1692 /* Write a message indicating that we've just entered or
1693 left (according to ENTERING) the current directory. */
1695 static void
1696 log_working_directory (entering)
1697 int entering;
1699 static int entered = 0;
1700 char *message = entering ? "Entering" : "Leaving";
1702 if (entering)
1703 entered = 1;
1704 else if (!entered)
1705 /* Don't print the leaving message if we
1706 haven't printed the entering message. */
1707 return;
1709 if (print_data_base_flag)
1710 fputs ("# ", stdout);
1712 if (makelevel == 0)
1713 printf ("%s: %s ", program, message);
1714 else
1715 printf ("%s[%u]: %s ", program, makelevel, message);
1717 if (starting_directory == 0)
1718 puts ("an unknown directory");
1719 else
1720 printf ("directory `%s'\n", starting_directory);