2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1989 by Berkeley Softworks
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)main.c 8.3 (Berkeley) 3/19/94
43 static char copyright[] =
44 "@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
45 The Regents of the University of California. All rights reserved.\n";
48 #include <sys/cdefs.h>
49 __FBSDID("$FreeBSD$");
53 * The main file for this entire program. Exit routines etc
56 * Utility functions defined in this file:
58 * Takes a line of arguments, breaks them and
59 * treats them as if they were given when first
60 * invoked. Used by the parse module to implement
64 #include <sys/param.h>
66 #include <sys/sysctl.h>
68 #include <sys/queue.h>
69 #include <sys/resource.h>
70 #include <sys/utsname.h>
87 #include "pathnames.h"
95 extern char **environ; /* XXX what header declares this variable? */
97 #define WANT_ENV_MKLVL 1
98 #define MKLVL_MAXVAL 500
99 #define MKLVL_ENVVAR "__MKLVL__"
101 /* ordered list of makefiles to read */
102 static Lst makefiles = Lst_Initializer(makefiles);
104 /* ordered list of source makefiles */
105 static Lst source_makefiles = Lst_Initializer(source_makefiles);
107 /* list of variables to print */
108 static Lst variables = Lst_Initializer(variables);
110 static Boolean expandVars; /* fully expand printed variables */
111 static Boolean noBuiltins; /* -r flag */
112 static Boolean forceJobs; /* -j argument given */
113 static char *curdir; /* startup directory */
114 static char *objdir; /* where we chdir'ed to */
115 static char **save_argv; /* saved argv */
116 static char *save_makeflags;/* saved MAKEFLAGS */
118 /* (-E) vars to override from env */
119 Lst envFirstVars = Lst_Initializer(envFirstVars);
121 /* Targets to be made */
122 Lst create = Lst_Initializer(create);
124 Boolean allPrecious; /* .PRECIOUS given on line by itself */
125 Boolean is_posix; /* .POSIX target seen */
126 Boolean mfAutoDeps; /* .MAKEFILEDEPS target seen */
127 Boolean beSilent; /* -s flag */
128 Boolean beVerbose; /* -v flag */
129 Boolean compatMake; /* -B argument */
130 int debug; /* -d flag */
131 Boolean ignoreErrors; /* -i flag */
132 int jobLimit; /* -j argument */
133 Boolean jobsRunning; /* TRUE if the jobs might be running */
134 Boolean keepgoing; /* -k flag */
135 Boolean noExecute; /* -n flag */
136 Boolean printGraphOnly; /* -p flag */
137 Boolean queryFlag; /* -q flag */
138 Boolean touchFlag; /* -t flag */
139 Boolean usePipes; /* !-P flag */
140 uint32_t warn_cmd; /* command line warning flags */
141 uint32_t warn_flags; /* actual warning flags */
142 uint32_t warn_nocmd; /* command line no-warning flags */
144 time_t now; /* Time at start of make */
145 struct GNode *DEFAULT; /* .DEFAULT node */
148 * Exit with usage message.
154 "usage: make [-BPSXeiknpqrstv] [-C directory] [-D variable]\n"
155 "\t[-d flags] [-E variable] [-f makefile] [-I directory]\n"
156 "\t[-j max_jobs] [-m directory] [-V variable]\n"
157 "\t[variable=value] [target ...]\n");
163 * Append a flag with an optional argument to MAKEFLAGS and MFLAGS
166 MFLAGS_append(const char *flag, char *arg)
170 Var_Append(".MAKEFLAGS", flag, VAR_GLOBAL);
172 str = MAKEFLAGS_quote(arg);
173 Var_Append(".MAKEFLAGS", str, VAR_GLOBAL);
177 Var_Append("MFLAGS", flag, VAR_GLOBAL);
179 str = MAKEFLAGS_quote(arg);
180 Var_Append("MFLAGS", str, VAR_GLOBAL);
188 * Handle argument to warning option.
191 Main_ParseWarn(const char *arg, int iscmd)
195 static const struct {
199 { "dirsyntax", WARN_DIRSYNTAX },
204 if (arg[0] == 'n' && arg[1] == 'o') {
209 for (i = 0; options[i].option != NULL; i++)
210 if (strcmp(arg, options[i].option) == 0)
213 if (options[i].option == NULL)
219 warn_cmd |= options[i].flag;
220 warn_nocmd &= ~options[i].flag;
221 warn_flags |= options[i].flag;
223 warn_nocmd |= options[i].flag;
224 warn_cmd &= ~options[i].flag;
225 warn_flags &= ~options[i].flag;
229 warn_flags |= (options[i].flag & ~warn_nocmd);
231 warn_flags &= ~(options[i].flag | warn_cmd);
238 * Open and parse the given makefile.
241 * TRUE if ok. FALSE if couldn't open file.
244 ReadMakefile(const char p[])
246 char *fname, *fnamesave; /* makefile to read */
248 char *name, path[MAXPATHLEN];
252 /* XXX - remove this once constification is done */
253 fnamesave = fname = estrdup(p);
255 if (!strcmp(fname, "-")) {
256 Parse_File("(stdin)", stdin);
257 Var_SetGlobal("MAKEFILE", "");
259 setMAKEFILE = strcmp(fname, ".depend");
261 /* if we've chdir'd, rebuild the path name */
262 if (curdir != objdir && *fname != '/') {
263 snprintf(path, MAXPATHLEN, "%s/%s", curdir, fname);
265 * XXX The realpath stuff breaks relative includes
266 * XXX in some cases. The problem likely is in
267 * XXX parse.c where it does special things in
268 * XXX ParseDoInclude if the file is relateive
269 * XXX or absolute and not a system file. There
270 * XXX it assumes that if the current file that's
271 * XXX being included is absolute, that any files
272 * XXX that it includes shouldn't do the -I path
273 * XXX stuff, which is inconsistant with historical
274 * XXX behavior. However, I can't pentrate the mists
275 * XXX further, so I'm putting this workaround in
276 * XXX here until such time as the underlying bug
279 #if THIS_BREAKS_THINGS
280 if (realpath(path, path) != NULL &&
281 (stream = fopen(path, "r")) != NULL) {
286 } else if (realpath(fname, path) != NULL) {
289 if ((stream = fopen(fname, "r")) != NULL)
293 if ((stream = fopen(path, "r")) != NULL) {
300 if ((stream = fopen(fname, "r")) != NULL)
304 /* look in -I and system include directories. */
305 name = Path_FindFile(fname, &parseIncPath);
307 name = Path_FindFile(fname, &sysIncPath);
308 if (!name || !(stream = fopen(name, "r"))) {
312 MAKEFILE = fname = name;
314 * set the MAKEFILE variable desired by System V fans -- the
315 * placement of the setting here means it gets set to the last
316 * makefile specified, as it is set by SysV make.
320 Var_SetGlobal("MAKEFILE", MAKEFILE);
321 Parse_File(fname, stream);
328 * Open and parse the given makefile.
329 * If open is successful add it to the list of makefiles.
332 * TRUE if ok. FALSE if couldn't open file.
335 TryReadMakefile(const char p[])
338 LstNode *last = Lst_Last(&source_makefiles);
340 if (!ReadMakefile(p))
345 LstNode *first = Lst_First(&source_makefiles);
346 Lst_Insert(&source_makefiles, first, data);
348 Lst_Append(&source_makefiles, last, estrdup(p));
354 * Parse a given argument vector. Called from main() and from
355 * Main_ParseArgLine() when the .MAKEFLAGS target is used.
357 * XXX: Deal with command line overriding .MAKEFLAGS in makefile
360 * Various global and local flags will be set depending on the flags
364 MainParseArgs(int argc, char **argv)
367 Boolean found_dd = FALSE;
370 optind = 1; /* since we're called more than once */
372 #define OPTFLAGS "ABC:D:E:I:PSV:Xd:ef:ij:km:npqrstvx:"
374 if ((optind < argc) && strcmp(argv[optind], "--") == 0) {
377 if ((c = getopt(argc, argv, OPTFLAGS)) == -1) {
384 MFLAGS_append("-A", NULL);
387 if (chdir(optarg) == -1)
388 err(1, "chdir %s", optarg);
391 Var_SetGlobal(optarg, "1");
392 MFLAGS_append("-D", optarg);
395 Parse_AddIncludeDir(optarg);
396 MFLAGS_append("-I", optarg);
399 Lst_AtEnd(&variables, estrdup(optarg));
400 MFLAGS_append("-V", optarg);
407 MFLAGS_append("-B", NULL);
408 unsetenv("MAKE_JOBS_FIFO");
412 MFLAGS_append("-P", NULL);
416 MFLAGS_append("-S", NULL);
419 char *modules = optarg;
421 for (; *modules; ++modules)
439 if (modules[1] == '1') {
440 debug |= DEBUG_GRAPH1;
443 else if (modules[1] == '2') {
444 debug |= DEBUG_GRAPH2;
467 warnx("illegal argument to d option "
471 MFLAGS_append("-d", optarg);
475 Lst_AtEnd(&envFirstVars, estrdup(optarg));
476 MFLAGS_append("-E", optarg);
479 checkEnvFirst = TRUE;
480 MFLAGS_append("-e", NULL);
483 Lst_AtEnd(&makefiles, estrdup(optarg));
487 MFLAGS_append("-i", NULL);
493 jobLimit = strtol(optarg, &endptr, 10);
494 if (jobLimit <= 0 || *endptr != '\0') {
495 warnx("illegal number, -j argument -- %s",
499 MFLAGS_append("-j", optarg);
504 MFLAGS_append("-k", NULL);
507 Path_AddDir(&sysIncPath, optarg);
508 MFLAGS_append("-m", optarg);
512 MFLAGS_append("-n", NULL);
515 printGraphOnly = TRUE;
516 debug |= DEBUG_GRAPH1;
520 /* Kind of nonsensical, wot? */
521 MFLAGS_append("-q", NULL);
525 MFLAGS_append("-r", NULL);
529 MFLAGS_append("-s", NULL);
533 MFLAGS_append("-t", NULL);
537 MFLAGS_append("-v", NULL);
540 if (Main_ParseWarn(optarg, 1) != -1)
541 MFLAGS_append("-x", optarg);
555 * Parse the rest of the arguments.
556 * o Check for variable assignments and perform them if so.
557 * o Check for more flags and restart getopt if so.
558 * o Anything else is taken to be a target and added
559 * to the end of the "create" list.
561 for (; *argv != NULL; ++argv, --argc) {
562 if (Parse_IsVar(*argv)) {
563 char *ptr = MAKEFLAGS_quote(*argv);
564 char *v = estrdup(*argv);
566 Var_Append(".MAKEFLAGS", ptr, VAR_GLOBAL);
567 Parse_DoVar(v, VAR_CMD);
571 } else if ((*argv)[0] == '-') {
572 if ((*argv)[1] == '\0') {
574 * (*argv) is a single dash, so we
577 } else if (found_dd) {
579 * Double dash has been found, ignore
580 * any more options. But what do we do
581 * with it? For now treat it like a target.
583 Lst_AtEnd(&create, estrdup(*argv));
586 * (*argv) is a -flag, so backup argv and
587 * argc. getopt() expects options to start
588 * in the 2nd position.
595 } else if ((*argv)[0] == '\0') {
596 Punt("illegal (null) argument.");
599 Lst_AtEnd(&create, estrdup(*argv));
606 * Used by the parse module when a .MFLAGS or .MAKEFLAGS target
607 * is encountered and by main() when reading the .MAKEFLAGS envariable.
608 * Takes a line of arguments and breaks it into its
609 * component words and passes those words and the number of them to the
610 * MainParseArgs function.
611 * The line should have all its leading whitespace removed.
614 * Only those that come from the various arguments.
617 Main_ParseArgLine(char *line, int mflags)
623 for (; *line == ' '; ++line)
629 MAKEFLAGS_break(&aa, line);
631 brk_string(&aa, line, TRUE);
633 MainParseArgs(aa.argc, aa.argv);
638 chdir_verify_path(const char *path, char *obpath)
642 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
643 if (chdir(path) == -1 || getcwd(obpath, MAXPATHLEN) == NULL) {
644 warn("warning: %s", path);
654 * In lieu of a good way to prevent every possible looping in make(1), stop
655 * there from being more than MKLVL_MAXVAL processes forked by make(1), to
656 * prevent a forkbomb from happening, in a dumb and mechanical way.
659 * Creates or modifies enviornment variable MKLVL_ENVVAR via setenv().
662 check_make_level(void)
664 #ifdef WANT_ENV_MKLVL
665 char *value = getenv(MKLVL_ENVVAR);
666 int level = (value == NULL) ? 0 : atoi(value);
669 errc(2, EAGAIN, "Invalid value for recursion level (%d).",
671 } else if (level > MKLVL_MAXVAL) {
672 errc(2, EAGAIN, "Max recursion level (%d) exceeded.",
676 sprintf(new_value, "%d", level + 1);
677 setenv(MKLVL_ENVVAR, new_value, 1);
679 #endif /* WANT_ENV_MKLVL */
683 * Main_AddSourceMakefile
684 * Add a file to the list of source makefiles
687 Main_AddSourceMakefile(const char *name)
690 Lst_AtEnd(&source_makefiles, estrdup(name));
695 * Remake all the makefiles
698 Remake_Makefiles(void)
704 Compat_InstallSignalHandlers();
705 if (curdir != objdir) {
706 if (chdir(curdir) < 0)
707 Fatal("Failed to change directory to %s.", curdir);
710 LST_FOREACH(ln, &source_makefiles) {
713 const char *name = Lst_Datum(ln);
714 Boolean saveTouchFlag = touchFlag;
715 Boolean saveQueryFlag = queryFlag;
716 Boolean saveNoExecute = noExecute;
722 gn = Targ_FindNode(name, TARG_CREATE);
723 DEBUGF(MAKE, ("Checking %s...", gn->name));
727 * ! dependencies as well as
728 * dependencies with .FORCE, .EXEC and .PHONY attributes
729 * are skipped to prevent infinite loops
731 if (gn->type & (OP_FORCE | OP_EXEC | OP_PHONY)) {
732 DEBUGF(MAKE, ("skipping (force, exec or phony).\n",
738 * Skip :: targets that have commands and no children
739 * because such targets are always out-of-date
741 if ((gn->type & OP_DOUBLEDEP) &&
742 !Lst_IsEmpty(&gn->commands) &&
743 Lst_IsEmpty(&gn->children)) {
744 DEBUGF(MAKE, ("skipping (doubledep, no sources "
745 "and has commands).\n"));
750 * Skip targets without sources and without commands
752 if (Lst_IsEmpty(&gn->commands) &&
753 Lst_IsEmpty(&gn->children)) {
755 ("skipping (no sources and no commands).\n"));
759 DEBUGF(MAKE, ("\n"));
762 * -t, -q and -n has no effect unless the makefile is
763 * specified as one of the targets explicitly in the
766 LST_FOREACH(ln2, &create) {
767 if (!strcmp(gn->name, Lst_Datum(ln2))) {
768 /* found as a target */
779 * Check and remake the makefile
781 mtime = Dir_MTime(gn);
785 * Restore -t, -q and -n behaviour
787 touchFlag = saveTouchFlag;
788 queryFlag = saveQueryFlag;
789 noExecute = saveNoExecute;
792 * Compat_Make will leave the 'made' field of gn
793 * in one of the following states:
794 * UPTODATE gn was already up-to-date
795 * MADE gn was recreated successfully
796 * ERROR An error occurred while gn was being created
797 * ABORTED gn was not remade because one of its inferiors
798 * could not be made due to errors.
800 if (gn->made == MADE) {
801 if (mtime != Dir_MTime(gn)) {
803 ("%s updated (%d -> %d).\n",
804 gn->name, mtime, gn->mtime));
808 ("%s not updated: skipping restart.\n",
811 } else if (gn->made == ERROR)
813 else if (gn->made == ABORTED) {
814 printf("`%s' not remade because of errors.\n",
817 } else if (gn->made == UPTODATE) {
821 Lst_EnQueue(&examine, gn);
822 while (!Lst_IsEmpty(&examine)) {
824 GNode *egn = Lst_DeQueue(&examine);
827 LST_FOREACH(eln, &egn->children) {
828 GNode *cgn = Lst_Datum(eln);
830 Lst_EnQueue(&examine, cgn);
837 Fatal("Failed to remake Makefiles.");
838 if (remade_cnt > 0) {
839 DEBUGF(MAKE, ("Restarting `%s'.\n", save_argv[0]));
842 * Some of makefiles were remade -- restart from clean state
844 if (save_makeflags != NULL)
845 setenv("MAKEFLAGS", save_makeflags, 1);
847 unsetenv("MAKEFLAGS");
848 if (execvp(save_argv[0], save_argv) < 0) {
849 Fatal("Can't restart `%s': %s.",
850 save_argv[0], strerror(errno));
854 if (curdir != objdir) {
855 if (chdir(objdir) < 0)
856 Fatal("Failed to change directory to %s.", objdir);
862 * The main function, for obvious reasons. Initializes variables
863 * and a few modules, then parses the arguments give it in the
864 * environment and on the command line. Reads the system makefile
865 * followed by either Makefile, makefile or the file given by the
866 * -f argument. Sets the .MAKEFLAGS PMake variable based on all the
867 * flags it has received by then uses either the Make or the Compat
868 * module to create the initial list of targets.
871 * If -q was given, exits -1 if anything was out-of-date. Else it exits
875 * The program exits when done. Targets are created. etc. etc. etc.
878 main(int argc, char **argv)
881 const char *machine_arch;
882 const char *machine_cpu;
883 Boolean outOfDate = TRUE; /* FALSE if all targets up to date */
887 char mdpath[MAXPATHLEN];
888 char obpath[MAXPATHLEN];
889 char cdpath[MAXPATHLEN];
890 char *cp = NULL, *start;
893 save_makeflags = getenv("MAKEFLAGS");
894 if (save_makeflags != NULL)
895 save_makeflags = estrdup(save_makeflags);
898 * Initialize file global variables.
901 noBuiltins = FALSE; /* Read the built-in rules */
902 forceJobs = FALSE; /* No -j flag */
906 * Initialize program global variables.
908 beSilent = FALSE; /* Print commands as executed */
909 ignoreErrors = FALSE; /* Pay attention to non-zero returns */
910 noExecute = FALSE; /* Execute all commands */
911 printGraphOnly = FALSE; /* Don't stop after printing graph */
912 keepgoing = FALSE; /* Stop on error */
913 allPrecious = FALSE; /* Remove targets when interrupted */
914 queryFlag = FALSE; /* This is not just a check-run */
915 touchFlag = FALSE; /* Actually update targets */
916 usePipes = TRUE; /* Catch child output in pipes */
917 debug = 0; /* No debug verbosity, please. */
920 jobLimit = DEFMAXJOBS;
921 compatMake = FALSE; /* No compat mode */
927 * get rid of resource limit on file descriptors
931 if (getrlimit(RLIMIT_NOFILE, &rl) == -1) {
934 rl.rlim_cur = rl.rlim_max;
935 if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
942 * Prior to 7.0, FreeBSD/pc98 kernel used to set the
943 * utsname.machine to "i386", and MACHINE was defined as
944 * "i386", so it could not be distinguished from FreeBSD/i386.
945 * Therefore, we had to check machine.ispc98 and adjust the
946 * MACHINE variable. NOTE: The code is still here to be able
947 * to compile new make binary on old FreeBSD/pc98 systems, and
948 * have the MACHINE variable set properly.
950 if ((machine = getenv("MACHINE")) == NULL) {
954 len = sizeof(ispc98);
955 if (!sysctlbyname("machdep.ispc98", &ispc98, &len, NULL, 0)) {
962 * Get the name of this type of MACHINE from utsname
963 * so we can share an executable for similar machines.
964 * (i.e. m68k: amiga hp300, mac68k, sun3, ...)
966 * Note that both MACHINE and MACHINE_ARCH are decided at
969 if (machine == NULL) {
970 static struct utsname utsname;
972 if (uname(&utsname) == -1)
974 machine = utsname.machine;
977 if ((machine_arch = getenv("MACHINE_ARCH")) == NULL) {
979 machine_arch = MACHINE_ARCH;
981 machine_arch = "unknown";
986 * Set machine_cpu to the minumum supported CPU revision based
987 * on the target architecture, if not already set.
989 if ((machine_cpu = getenv("MACHINE_CPU")) == NULL) {
990 if (!strcmp(machine_arch, "i386"))
991 machine_cpu = "i386";
992 else if (!strcmp(machine_arch, "alpha"))
995 machine_cpu = "unknown";
999 * Initialize the parsing, directory and variable modules to prepare
1000 * for the reading of inclusion paths and variable settings on the
1005 Dir_Init(); /* Initialize directory structures so -I flags
1006 * can be processed correctly */
1007 Var_Init(environ); /* As well as the lists of variables for
1008 * parsing arguments */
1011 * Initialize the Shell so that we have a shell for != assignments
1012 * on the command line.
1017 * Initialize various variables.
1018 * MAKE also gets this name, for compatibility
1019 * .MAKEFLAGS gets set to the empty string just in case.
1020 * MFLAGS also gets initialized empty, for compatibility.
1022 Var_SetGlobal("MAKE", argv[0]);
1023 Var_SetGlobal(".MAKEFLAGS", "");
1024 Var_SetGlobal("MFLAGS", "");
1025 Var_SetGlobal("MACHINE", machine);
1026 Var_SetGlobal("MACHINE_ARCH", machine_arch);
1027 Var_SetGlobal("MACHINE_CPU", machine_cpu);
1029 Var_SetGlobal("MAKE_VERSION", MAKE_VERSION);
1033 * First snag things out of the MAKEFLAGS environment
1034 * variable. Then parse the command line arguments.
1036 Main_ParseArgLine(getenv("MAKEFLAGS"), 1);
1038 MainParseArgs(argc, argv);
1041 * Find where we are...
1043 if (getcwd(curdir, MAXPATHLEN) == NULL)
1049 if (stat(curdir, &sa) == -1)
1050 err(2, "%s", curdir);
1054 * The object directory location is determined using the
1055 * following order of preference:
1057 * 1. MAKEOBJDIRPREFIX`cwd`
1059 * 3. PATH_OBJDIR.${MACHINE}
1061 * 5. PATH_OBJDIRPREFIX`cwd`
1063 * If one of the first two fails, use the current directory.
1064 * If the remaining three all fail, use the current directory.
1066 * Once things are initted,
1067 * have to add the original directory to the search path,
1068 * and modify the paths for the Makefiles apropriately. The
1069 * current directory is also placed as a variable for make scripts.
1071 if (!(pathp = getenv("MAKEOBJDIRPREFIX"))) {
1072 if (!(path = getenv("MAKEOBJDIR"))) {
1074 pathp = PATH_OBJDIRPREFIX;
1075 snprintf(mdpath, MAXPATHLEN, "%s.%s", path, machine);
1076 if (!(objdir = chdir_verify_path(mdpath, obpath)))
1077 if (!(objdir=chdir_verify_path(path, obpath))) {
1078 snprintf(mdpath, MAXPATHLEN,
1079 "%s%s", pathp, curdir);
1080 if (!(objdir=chdir_verify_path(mdpath,
1085 else if (!(objdir = chdir_verify_path(path, obpath)))
1089 snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir);
1090 if (!(objdir = chdir_verify_path(mdpath, obpath)))
1093 Dir_InitDot(); /* Initialize the "." directory */
1094 if (objdir != curdir)
1095 Path_AddDir(&dirSearchPath, curdir);
1096 Var_SetGlobal(".ST_EXPORTVAR", "YES");
1097 Var_SetGlobal(".CURDIR", curdir);
1098 Var_SetGlobal(".OBJDIR", objdir);
1100 if (getenv("MAKE_JOBS_FIFO") != NULL)
1103 * Be compatible if user did not specify -j and did not explicitly
1104 * turned compatibility on
1106 if (!compatMake && !forceJobs)
1110 * Initialize target and suffix modules in preparation for
1111 * parsing the makefile(s)
1120 * Set up the .TARGETS variable to contain the list of targets to be
1121 * created. If none specified, make the variable empty -- the parser
1122 * will fill the thing in with the default or .MAIN target.
1124 if (Lst_IsEmpty(&create)) {
1125 Var_SetGlobal(".TARGETS", "");
1129 for (ln = Lst_First(&create); ln != NULL; ln = Lst_Succ(ln)) {
1130 char *name = Lst_Datum(ln);
1132 Var_Append(".TARGETS", name, VAR_GLOBAL);
1138 * If no user-supplied system path was given (through the -m option)
1139 * add the directories from the DEFSYSPATH (more than one may be given
1140 * as dir1:...:dirn) to the system include path.
1142 if (TAILQ_EMPTY(&sysIncPath)) {
1143 char syspath[] = PATH_DEFSYSPATH;
1145 for (start = syspath; *start != '\0'; start = cp) {
1146 for (cp = start; *cp != '\0' && *cp != ':'; cp++)
1149 Path_AddDir(&sysIncPath, start);
1152 Path_AddDir(&sysIncPath, start);
1158 * Read in the built-in rules first, followed by the specified
1159 * makefile, if it was (makefile != (char *) NULL), or the default
1160 * Makefile and makefile, in that order, if it wasn't.
1163 /* Path of sys.mk */
1164 Lst sysMkPath = Lst_Initializer(sysMkPath);
1166 char defsysmk[] = PATH_DEFSYSMK;
1168 Path_Expand(defsysmk, &sysIncPath, &sysMkPath);
1169 if (Lst_IsEmpty(&sysMkPath))
1170 Fatal("make: no system rules (%s).", PATH_DEFSYSMK);
1171 LST_FOREACH(ln, &sysMkPath) {
1172 if (!ReadMakefile(Lst_Datum(ln)))
1176 Fatal("make: cannot open %s.", (char *)Lst_Datum(ln));
1177 Lst_Destroy(&sysMkPath, free);
1180 if (!Lst_IsEmpty(&makefiles)) {
1183 LST_FOREACH(ln, &makefiles) {
1184 if (!TryReadMakefile(Lst_Datum(ln)))
1188 Fatal("make: cannot open %s.", (char *)Lst_Datum(ln));
1189 } else if (!TryReadMakefile("BSDmakefile"))
1190 if (!TryReadMakefile("makefile"))
1191 TryReadMakefile("Makefile");
1193 ReadMakefile(".depend");
1195 /* Install all the flags into the MAKEFLAGS envariable. */
1196 if (((p = Var_Value(".MAKEFLAGS", VAR_GLOBAL)) != NULL) && *p)
1197 setenv("MAKEFLAGS", p, 1);
1199 setenv("MAKEFLAGS", "", 1);
1202 * For compatibility, look at the directories in the VPATH variable
1203 * and add them to the search path, if the variable is defined. The
1204 * variable's value is in the same format as the PATH envariable, i.e.
1205 * <directory>:<directory>:<directory>...
1207 if (Var_Exists("VPATH", VAR_CMD)) {
1209 * GCC stores string constants in read-only memory, but
1210 * Var_Subst will want to write this thing, so store it
1213 static char VPATH[] = "${VPATH}";
1219 buf = Var_Subst(VPATH, VAR_CMD, FALSE);
1221 vpath = Buf_Data(buf);
1223 /* skip to end of directory */
1224 for (ptr = vpath; *ptr != ':' && *ptr != '\0'; ptr++)
1227 /* Save terminator character so know when to stop */
1231 /* Add directory to search path */
1232 Path_AddDir(&dirSearchPath, vpath);
1235 } while (savec != '\0');
1237 Buf_Destroy(buf, TRUE);
1241 * Now that all search paths have been read for suffixes et al, it's
1242 * time to add the default search path to their lists...
1246 /* print the initial graph, if the user requested it */
1250 /* print the values of any variables requested by the user */
1251 if (Lst_IsEmpty(&variables) && !printGraphOnly) {
1253 * Since the user has not requested that any variables
1254 * be printed, we can build targets.
1256 * Have read the entire graph and need to make a list of targets
1257 * to create. If none was given on the command line, we consult
1258 * the parsing module to find the main target(s) to create.
1260 Lst targs = Lst_Initializer(targs);
1262 if (!is_posix && mfAutoDeps) {
1264 * Check if any of the makefiles are out-of-date.
1269 if (Lst_IsEmpty(&create))
1270 Parse_MainName(&targs);
1272 Targ_FindList(&targs, &create, TARG_CREATE);
1276 * Compat_Init will take care of creating
1277 * all the targets as well as initializing
1284 * Initialize job module before traversing
1285 * the graph, now that any .BEGIN and .END
1286 * targets have been read. This is done
1287 * only if the -q flag wasn't given (to
1288 * prevent the .BEGIN from being executed
1296 /* Traverse the graph, checking on all the targets */
1297 outOfDate = Make_Run(&targs);
1299 Lst_Destroy(&targs, NOFREE);
1302 Var_Print(&variables, expandVars);
1305 Lst_Destroy(&variables, free);
1306 Lst_Destroy(&makefiles, free);
1307 Lst_Destroy(&source_makefiles, free);
1308 Lst_Destroy(&create, free);
1310 /* print the graph now it's been processed if the user requested it */
1314 if (queryFlag && outOfDate)