1 /* $NetBSD: main.c,v 1.254 2016/12/10 23:12:39 christos Exp $ */
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * Copyright (c) 1989 by Berkeley Softworks
37 * All rights reserved.
39 * This code is derived from software contributed to Berkeley by
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by the University of
53 * California, Berkeley and its contributors.
54 * 4. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 static char rcsid[] = "$NetBSD: main.c,v 1.254 2016/12/10 23:12:39 christos Exp $";
74 #include <sys/cdefs.h>
76 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
77 The Regents of the University of California. All rights reserved.");
82 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
84 __RCSID("$NetBSD: main.c,v 1.254 2016/12/10 23:12:39 christos Exp $");
91 * The main file for this entire program. Exit routines etc
94 * Utility functions defined in this file:
95 * Main_ParseArgLine Takes a line of arguments, breaks them and
96 * treats them as if they were given when first
97 * invoked. Used by the parse module to implement
100 * Error Print a tagged error message. The global
101 * MAKE variable must have been defined. This
102 * takes a format string and optional arguments
105 * Fatal Print an error message and exit. Also takes
106 * a format string and arguments for it.
108 * Punt Aborts all jobs and exits with a message. Also
109 * takes a format string and arguments for it.
111 * Finish Finish things up by printing the number of
112 * errors which occurred, as passed to it, and
116 #include <sys/types.h>
117 #include <sys/time.h>
118 #include <sys/param.h>
119 #include <sys/resource.h>
120 #include <sys/stat.h>
121 #if defined(MAKE_NATIVE) && defined(HAVE_SYSCTL)
122 #include <sys/sysctl.h>
124 #include <sys/utsname.h>
139 #include "pathnames.h"
147 #define DEFMAXLOCAL DEFMAXJOBS
148 #endif /* DEFMAXLOCAL */
151 # define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
154 Lst create; /* Targets to be made */
155 time_t now; /* Time at start of make */
156 GNode *DEFAULT; /* .DEFAULT node */
157 Boolean allPrecious; /* .PRECIOUS given on line by itself */
158 Boolean deleteOnError; /* .DELETE_ON_ERROR: set */
160 static Boolean noBuiltins; /* -r flag */
161 static Lst makefiles; /* ordered list of makefiles to read */
162 static Boolean printVars; /* print value of one or more vars */
163 static Lst variables; /* list of variables to print */
164 int maxJobs; /* -j argument */
165 static int maxJobTokens; /* -j argument */
166 Boolean compatMake; /* -B argument */
167 int debug; /* -d argument */
168 Boolean debugVflag; /* -dV */
169 Boolean noExecute; /* -n flag */
170 Boolean noRecursiveExecute; /* -N flag */
171 Boolean keepgoing; /* -k flag */
172 Boolean queryFlag; /* -q flag */
173 Boolean touchFlag; /* -t flag */
174 Boolean enterFlag; /* -w flag */
175 Boolean enterFlagObj; /* -w and objdir != srcdir */
176 Boolean ignoreErrors; /* -i flag */
177 Boolean beSilent; /* -s flag */
178 Boolean oldVars; /* variable substitution style */
179 Boolean checkEnvFirst; /* -e flag */
180 Boolean parseWarnFatal; /* -W flag */
181 Boolean jobServer; /* -J flag */
182 static int jp_0 = -1, jp_1 = -1; /* ends of parent job pipe */
183 Boolean varNoExportEnv; /* -X flag */
184 Boolean doing_depend; /* Set while reading .depend */
185 static Boolean jobsRunning; /* TRUE if the jobs might be running */
186 static const char * tracefile;
187 static void MainParseArgs(int, char **);
188 static int ReadMakefile(const void *, const void *);
189 static void usage(void) MAKE_ATTR_DEAD;
191 static Boolean ignorePWD; /* if we use -C, PWD is meaningless */
192 static char objdir[MAXPATHLEN + 1]; /* where we chdir'ed to */
193 char curdir[MAXPATHLEN + 1]; /* Startup directory */
194 char *progname; /* the program name */
195 char *makeDependfile;
199 Boolean forceJobs = FALSE;
202 * On some systems MACHINE is defined as something other than
207 # define MACHINE FORCE_MACHINE
210 extern Lst parseIncPath;
213 * For compatibility with the POSIX version of MAKEFLAGS that includes
214 * all the options with out -, convert flags to -f -l -a -g -s.
217 explode(const char *flags)
226 for (f = flags; *f; f++)
227 if (!isalpha((unsigned char)*f))
231 return bmake_strdup(flags);
234 st = nf = bmake_malloc(len * 3 + 1);
245 parse_debug_options(const char *argvalue)
252 for (modules = argvalue; *modules; ++modules) {
270 debug |= DEBUG_ERROR;
276 if (modules[1] == '1') {
277 debug |= DEBUG_GRAPH1;
280 else if (modules[1] == '2') {
281 debug |= DEBUG_GRAPH2;
284 else if (modules[1] == '3') {
285 debug |= DEBUG_GRAPH3;
302 debug |= DEBUG_SCRIPT;
305 debug |= DEBUG_PARSE;
320 debug |= DEBUG_SHELL;
323 if (debug_file != stdout && debug_file != stderr)
325 if (*++modules == '+') {
330 if (strcmp(modules, "stdout") == 0) {
334 if (strcmp(modules, "stderr") == 0) {
338 len = strlen(modules);
339 fname = malloc(len + 20);
340 memcpy(fname, modules, len + 1);
341 /* Let the filename be modified by the pid */
342 if (strcmp(fname + len - 3, ".%d") == 0)
343 snprintf(fname + len - 2, 20, "%d", getpid());
344 debug_file = fopen(fname, mode);
346 fprintf(stderr, "Cannot open debug file %s\n",
353 (void)fprintf(stderr,
354 "%s: illegal argument to d option -- %c\n",
361 * Make the debug_file unbuffered, and make
362 * stdout line buffered (unless debugfile == stdout).
364 setvbuf(debug_file, NULL, _IONBF, 0);
365 if (debug_file != stdout) {
366 setvbuf(stdout, NULL, _IOLBF, 0);
372 * Parse a given argument vector. Called from main() and from
373 * Main_ParseArgLine() when the .MAKEFLAGS target is used.
375 * XXX: Deal with command line overriding .MAKEFLAGS in makefile
381 * Various global and local flags will be set depending on the flags
385 MainParseArgs(int argc, char **argv)
391 const char *getopt_def;
393 Boolean inOption, dashDash = FALSE;
394 char found_path[MAXPATHLEN + 1]; /* for searching for sys.mk */
396 #define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrstw"
397 /* Can't actually use getopt(3) because rescanning is not portable */
399 getopt_def = OPTFLAGS;
417 if (c != '-' || dashDash)
422 /* '-' found at some earlier point */
423 getopt_spec = strchr(getopt_def, c);
424 if(c != '\0' && getopt_spec != NULL && getopt_spec[1] == ':') {
425 /* -<something> found, and <something> should have an arg */
429 if(*argvalue == '\0') {
445 Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL);
446 Var_Set(MAKE_MODE, "compat", VAR_GLOBAL, 0);
449 if (chdir(argvalue) == -1) {
450 (void)fprintf(stderr,
451 "%s: chdir %s: %s\n",
456 if (getcwd(curdir, MAXPATHLEN) == NULL) {
457 (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
463 if (argvalue == NULL || argvalue[0] == 0) goto noarg;
464 Var_Set(argvalue, "1", VAR_GLOBAL, 0);
465 Var_Append(MAKEFLAGS, "-D", VAR_GLOBAL);
466 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
469 if (argvalue == NULL) goto noarg;
470 Parse_AddIncludeDir(argvalue);
471 Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL);
472 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
475 if (argvalue == NULL) goto noarg;
476 if (sscanf(argvalue, "%d,%d", &jp_0, &jp_1) != 2) {
477 (void)fprintf(stderr,
478 "%s: internal error -- J option malformed (%s)\n",
482 if ((fcntl(jp_0, F_GETFD, 0) < 0) ||
483 (fcntl(jp_1, F_GETFD, 0) < 0)) {
485 (void)fprintf(stderr,
486 "%s: ###### warning -- J descriptors were closed!\n",
494 Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL);
495 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
501 noRecursiveExecute = TRUE;
502 Var_Append(MAKEFLAGS, "-N", VAR_GLOBAL);
506 Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL);
509 if (argvalue == NULL) goto noarg;
510 tracefile = bmake_strdup(argvalue);
511 Var_Append(MAKEFLAGS, "-T", VAR_GLOBAL);
512 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
515 if (argvalue == NULL) goto noarg;
517 (void)Lst_AtEnd(variables, argvalue);
518 Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
519 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
522 parseWarnFatal = TRUE;
525 varNoExportEnv = TRUE;
526 Var_Append(MAKEFLAGS, "-X", VAR_GLOBAL);
529 if (argvalue == NULL) goto noarg;
530 /* If '-d-opts' don't pass to children */
531 if (argvalue[0] == '-')
534 Var_Append(MAKEFLAGS, "-d", VAR_GLOBAL);
535 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
537 parse_debug_options(argvalue);
540 checkEnvFirst = TRUE;
541 Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL);
544 if (argvalue == NULL) goto noarg;
545 (void)Lst_AtEnd(makefiles, argvalue);
549 Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL);
552 if (argvalue == NULL) goto noarg;
554 maxJobs = strtol(argvalue, &p, 0);
555 if (*p != '\0' || maxJobs < 1) {
556 (void)fprintf(stderr, "%s: illegal argument to -j -- must be positive integer!\n",
560 Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL);
561 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
562 Var_Set(".MAKE.JOBS", argvalue, VAR_GLOBAL, 0);
563 maxJobTokens = maxJobs;
567 Var_Append(MAKEFLAGS, "-k", VAR_GLOBAL);
570 if (argvalue == NULL) goto noarg;
571 /* look for magic parent directory search string */
572 if (strncmp(".../", argvalue, 4) == 0) {
573 if (!Dir_FindHereOrAbove(curdir, argvalue+4,
574 found_path, sizeof(found_path)))
575 break; /* nothing doing */
576 (void)Dir_AddDir(sysIncPath, found_path);
578 (void)Dir_AddDir(sysIncPath, argvalue);
580 Var_Append(MAKEFLAGS, "-m", VAR_GLOBAL);
581 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
585 Var_Append(MAKEFLAGS, "-n", VAR_GLOBAL);
589 /* Kind of nonsensical, wot? */
590 Var_Append(MAKEFLAGS, "-q", VAR_GLOBAL);
594 Var_Append(MAKEFLAGS, "-r", VAR_GLOBAL);
598 Var_Append(MAKEFLAGS, "-s", VAR_GLOBAL);
602 Var_Append(MAKEFLAGS, "-t", VAR_GLOBAL);
606 Var_Append(MAKEFLAGS, "-w", VAR_GLOBAL);
614 fprintf(stderr, "getopt(%s) -> %d (%c)\n",
626 * See if the rest of the arguments are variable assignments and
627 * perform them if so. Else take them to be targets and stuff them
628 * on the end of the "create" list.
630 for (; argc > 1; ++argv, --argc)
631 if (Parse_IsVar(argv[1])) {
632 Parse_DoVar(argv[1], VAR_CMD);
635 Punt("illegal (null) argument.");
636 if (*argv[1] == '-' && !dashDash)
638 (void)Lst_AtEnd(create, bmake_strdup(argv[1]));
643 (void)fprintf(stderr, "%s: option requires an argument -- %c\n",
649 * Main_ParseArgLine --
650 * Used by the parse module when a .MFLAGS or .MAKEFLAGS target
651 * is encountered and by main() when reading the .MAKEFLAGS envariable.
652 * Takes a line of arguments and breaks it into its
653 * component words and passes those words and the number of them to the
654 * MainParseArgs function.
655 * The line should have all its leading whitespace removed.
658 * line Line to fracture
664 * Only those that come from the various arguments.
667 Main_ParseArgLine(const char *line)
669 char **argv; /* Manufactured argument vector */
670 int argc; /* Number of arguments in argv */
671 char *args; /* Space used by the args */
673 char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &p1);
678 for (; *line == ' '; ++line)
686 * $MAKE may simply be naming the make(1) binary
690 if (!(cp = strrchr(line, '/')))
692 if ((cp = strstr(cp, "make")) &&
693 strcmp(cp, "make") == 0)
697 buf = bmake_malloc(len = strlen(line) + strlen(argv0) + 2);
698 (void)snprintf(buf, len, "%s %s", argv0, line);
701 argv = brk_string(buf, &argc, TRUE, &args);
703 Error("Unterminated quoted string [%s]", buf);
708 MainParseArgs(argc, argv);
715 Main_SetObjdir(const char *fmt, ...)
719 char buf[MAXPATHLEN + 1], pbuf[MAXPATHLEN + 1];
724 vsnprintf(path = pbuf, MAXPATHLEN, fmt, ap);
727 /* expand variable substitutions */
728 if (strchr(path, '$') != 0) {
729 snprintf(buf, MAXPATHLEN, "%s", path);
730 path = p = Var_Subst(NULL, buf, VAR_GLOBAL, VARF_WANTRES);
734 if (path[0] != '/') {
735 snprintf(buf, MAXPATHLEN, "%s/%s", curdir, path);
739 /* look for the directory and try to chdir there */
740 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
742 (void)fprintf(stderr, "make warning: %s: %s.\n",
743 path, strerror(errno));
745 strncpy(objdir, path, MAXPATHLEN);
746 Var_Set(".OBJDIR", objdir, VAR_GLOBAL, 0);
747 setenv("PWD", objdir, 1);
750 if (enterFlag && strcmp(objdir, curdir) != 0)
760 Main_SetVarObjdir(const char *var, const char *suffix)
763 if ((path = Var_Value(var, VAR_CMD, &p1)) == NULL)
766 (void)Main_SetObjdir("%s%s", path, suffix);
772 * ReadAllMakefiles --
773 * wrapper around ReadMakefile() to read all.
776 * TRUE if ok, FALSE on error
779 ReadAllMakefiles(const void *p, const void *q)
781 return (ReadMakefile(p, q) == 0);
785 str2Lst_Append(Lst lp, char *str, const char *sep)
793 for (n = 0, cp = strtok(str, sep); cp; cp = strtok(NULL, sep)) {
794 (void)Lst_AtEnd(lp, cp);
803 siginfo(int signo MAKE_ATTR_UNUSED)
805 char dir[MAXPATHLEN];
806 char str[2 * MAXPATHLEN];
808 if (getcwd(dir, sizeof(dir)) == NULL)
810 len = snprintf(str, sizeof(str), "%s: Working in: %s\n", progname, dir);
812 (void)write(STDERR_FILENO, str, (size_t)len);
817 * Allow makefiles some control over the mode we run in.
820 MakeMode(const char *mode)
825 mode = mp = Var_Subst(NULL, "${" MAKE_MODE ":tl}",
826 VAR_GLOBAL, VARF_WANTRES);
829 if (strstr(mode, "compat")) {
834 if (strstr(mode, "meta"))
835 meta_mode_init(mode);
844 * The main function, for obvious reasons. Initializes variables
845 * and a few modules, then parses the arguments give it in the
846 * environment and on the command line. Reads the system makefile
847 * followed by either Makefile, makefile or the file given by the
848 * -f argument. Sets the .MAKEFLAGS PMake variable based on all the
849 * flags it has received by then uses either the Make or the Compat
850 * module to create the initial list of targets.
853 * If -q was given, exits -1 if anything was out-of-date. Else it exits
857 * The program exits when done. Targets are created. etc. etc. etc.
860 main(int argc, char **argv)
862 Lst targs; /* target nodes to create -- passed to Make_Init */
863 Boolean outOfDate = FALSE; /* FALSE if all targets up to date */
866 char mdpath[MAXPATHLEN];
868 const char *machine = FORCE_MACHINE;
870 const char *machine = getenv("MACHINE");
872 const char *machine_arch = getenv("MACHINE_ARCH");
873 char *syspath = getenv("MAKESYSPATH");
874 Lst sysMkPath; /* Path of sys.mk */
875 char *cp = NULL, *start;
876 /* avoid faults on read-only strings */
877 static char defsyspath[] = _PATH_DEFSYSPATH;
878 char found_path[MAXPATHLEN + 1]; /* for searching for sys.mk */
879 struct timeval rightnow; /* to initialize random seed */
880 struct utsname utsname;
882 /* default to writing debug to stderr */
886 (void)bmake_signal(SIGINFO, siginfo);
889 * Set the seed to produce a different random sequence
890 * on each program execution.
892 gettimeofday(&rightnow, NULL);
893 srandom(rightnow.tv_sec + rightnow.tv_usec);
895 if ((progname = strrchr(argv[0], '/')) != NULL)
899 #if defined(MAKE_NATIVE) || (defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE))
901 * get rid of resource limit on file descriptors
905 if (getrlimit(RLIMIT_NOFILE, &rl) != -1 &&
906 rl.rlim_cur != rl.rlim_max) {
907 rl.rlim_cur = rl.rlim_max;
908 (void)setrlimit(RLIMIT_NOFILE, &rl);
913 if (uname(&utsname) == -1) {
914 (void)fprintf(stderr, "%s: uname failed (%s).\n", progname,
920 * Get the name of this type of MACHINE from utsname
921 * so we can share an executable for similar machines.
922 * (i.e. m68k: amiga hp300, mac68k, sun3, ...)
924 * Note that both MACHINE and MACHINE_ARCH are decided at
929 machine = utsname.machine;
932 machine = MAKE_MACHINE;
940 #if defined(MAKE_NATIVE) && defined(HAVE_SYSCTL) && defined(CTL_HW) && defined(HW_MACHINE_ARCH)
941 static char machine_arch_buf[sizeof(utsname.machine)];
942 int mib[2] = { CTL_HW, HW_MACHINE_ARCH };
943 size_t len = sizeof(machine_arch_buf);
945 if (sysctl(mib, __arraycount(mib), machine_arch_buf,
946 &len, NULL, 0) < 0) {
947 (void)fprintf(stderr, "%s: sysctl failed (%s).\n", progname,
952 machine_arch = machine_arch_buf;
955 #ifdef MAKE_MACHINE_ARCH
956 machine_arch = MAKE_MACHINE_ARCH;
958 machine_arch = "unknown";
961 machine_arch = MACHINE_ARCH;
966 myPid = getpid(); /* remember this for vFork() */
969 * Just in case MAKEOBJDIR wants us to do something tricky.
971 Var_Init(); /* Initialize the lists of variables for
972 * parsing arguments */
973 Var_Set(".MAKE.OS", utsname.sysname, VAR_GLOBAL, 0);
974 Var_Set("MACHINE", machine, VAR_GLOBAL, 0);
975 Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL, 0);
977 Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL, 0);
979 Var_Set(".newline", "\n", VAR_GLOBAL, 0); /* handy for :@ loops */
981 * This is the traditional preference for makefiles.
983 #ifndef MAKEFILE_PREFERENCE_LIST
984 # define MAKEFILE_PREFERENCE_LIST "makefile Makefile"
986 Var_Set(MAKEFILE_PREFERENCE, MAKEFILE_PREFERENCE_LIST,
988 Var_Set(MAKE_DEPENDFILE, ".depend", VAR_GLOBAL, 0);
990 create = Lst_Init(FALSE);
991 makefiles = Lst_Init(FALSE);
994 variables = Lst_Init(FALSE);
995 beSilent = FALSE; /* Print commands as executed */
996 ignoreErrors = FALSE; /* Pay attention to non-zero returns */
997 noExecute = FALSE; /* Execute all commands */
998 noRecursiveExecute = FALSE; /* Execute all .MAKE targets */
999 keepgoing = FALSE; /* Stop on error */
1000 allPrecious = FALSE; /* Remove targets when interrupted */
1001 deleteOnError = FALSE; /* Historical default behavior */
1002 queryFlag = FALSE; /* This is not just a check-run */
1003 noBuiltins = FALSE; /* Read the built-in rules */
1004 touchFlag = FALSE; /* Actually update targets */
1005 debug = 0; /* No debug verbosity, please. */
1006 jobsRunning = FALSE;
1008 maxJobs = DEFMAXLOCAL; /* Set default local max concurrency */
1009 maxJobTokens = maxJobs;
1010 compatMake = FALSE; /* No compat mode */
1014 * Initialize the parsing, directory and variable modules to prepare
1015 * for the reading of inclusion paths and variable settings on the
1020 * Initialize various variables.
1021 * MAKE also gets this name, for compatibility
1022 * .MAKEFLAGS gets set to the empty string just in case.
1023 * MFLAGS also gets initialized empty, for compatibility.
1026 if (argv[0][0] == '/' || strchr(argv[0], '/') == NULL) {
1028 * Leave alone if it is an absolute path, or if it does
1029 * not contain a '/' in which case we need to find it in
1030 * the path, like execvp(3) and the shells do.
1035 * A relative path, canonicalize it.
1037 p1 = cached_realpath(argv[0], mdpath);
1038 if (!p1 || *p1 != '/' || stat(p1, &sb) < 0) {
1039 p1 = argv[0]; /* realpath failed */
1042 Var_Set("MAKE", p1, VAR_GLOBAL, 0);
1043 Var_Set(".MAKE", p1, VAR_GLOBAL, 0);
1044 Var_Set(MAKEFLAGS, "", VAR_GLOBAL, 0);
1045 Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL, 0);
1046 Var_Set("MFLAGS", "", VAR_GLOBAL, 0);
1047 Var_Set(".ALLTARGETS", "", VAR_GLOBAL, 0);
1048 /* some makefiles need to know this */
1049 Var_Set(MAKE_LEVEL ".ENV", MAKE_LEVEL_ENV, VAR_CMD, 0);
1052 * Set some other useful macros
1057 makelevel = ((ep = getenv(MAKE_LEVEL_ENV)) && *ep) ? atoi(ep) : 0;
1060 snprintf(tmp, sizeof(tmp), "%d", makelevel);
1061 Var_Set(MAKE_LEVEL, tmp, VAR_GLOBAL, 0);
1062 snprintf(tmp, sizeof(tmp), "%u", myPid);
1063 Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0);
1064 snprintf(tmp, sizeof(tmp), "%u", getppid());
1065 Var_Set(".MAKE.PPID", tmp, VAR_GLOBAL, 0);
1067 if (makelevel > 0) {
1069 snprintf(pn, sizeof(pn), "%s[%d]", progname, makelevel);
1070 progname = bmake_strdup(pn);
1077 * First snag any flags out of the MAKE environment variable.
1078 * (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
1079 * in a different format).
1082 p1 = explode(getenv("MAKEFLAGS"));
1083 Main_ParseArgLine(p1);
1086 Main_ParseArgLine(getenv("MAKE"));
1090 * Find where we are (now).
1091 * We take care of PWD for the automounter below...
1093 if (getcwd(curdir, MAXPATHLEN) == NULL) {
1094 (void)fprintf(stderr, "%s: getcwd: %s.\n",
1095 progname, strerror(errno));
1099 MainParseArgs(argc, argv);
1102 printf("%s: Entering directory `%s'\n", progname, curdir);
1105 * Verify that cwd is sane.
1107 if (stat(curdir, &sa) == -1) {
1108 (void)fprintf(stderr, "%s: %s: %s.\n",
1109 progname, curdir, strerror(errno));
1114 * All this code is so that we know where we are when we start up
1115 * on a different machine with pmake.
1116 * Overriding getcwd() with $PWD totally breaks MAKEOBJDIRPREFIX
1117 * since the value of curdir can vary depending on how we got
1118 * here. Ie sitting at a shell prompt (shell that provides $PWD)
1119 * or via subdir.mk in which case its likely a shell which does
1121 * So, to stop it breaking this case only, we ignore PWD if
1122 * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a transform.
1124 #ifndef NO_PWD_OVERRIDE
1126 char *pwd, *ptmp1 = NULL, *ptmp2 = NULL;
1128 if ((pwd = getenv("PWD")) != NULL &&
1129 Var_Value("MAKEOBJDIRPREFIX", VAR_CMD, &ptmp1) == NULL) {
1130 const char *makeobjdir = Var_Value("MAKEOBJDIR",
1133 if (makeobjdir == NULL || !strchr(makeobjdir, '$')) {
1134 if (stat(pwd, &sb) == 0 &&
1135 sa.st_ino == sb.st_ino &&
1136 sa.st_dev == sb.st_dev)
1137 (void)strncpy(curdir, pwd, MAXPATHLEN);
1144 Var_Set(".CURDIR", curdir, VAR_GLOBAL, 0);
1147 * Find the .OBJDIR. If MAKEOBJDIRPREFIX, or failing that,
1148 * MAKEOBJDIR is set in the environment, try only that value
1149 * and fall back to .CURDIR if it does not exist.
1151 * Otherwise, try _PATH_OBJDIR.MACHINE-MACHINE_ARCH, _PATH_OBJDIR.MACHINE,
1152 * and * finally _PATH_OBJDIRPREFIX`pwd`, in that order. If none
1153 * of these paths exist, just use .CURDIR.
1156 (void)Main_SetObjdir("%s", curdir);
1158 if (!Main_SetVarObjdir("MAKEOBJDIRPREFIX", curdir) &&
1159 !Main_SetVarObjdir("MAKEOBJDIR", "") &&
1160 !Main_SetObjdir("%s.%s-%s", _PATH_OBJDIR, machine, machine_arch) &&
1161 !Main_SetObjdir("%s.%s", _PATH_OBJDIR, machine) &&
1162 !Main_SetObjdir("%s", _PATH_OBJDIR))
1163 (void)Main_SetObjdir("%s%s", _PATH_OBJDIRPREFIX, curdir);
1166 * Initialize archive, target and suffix modules in preparation for
1167 * parsing the makefile(s)
1172 Trace_Init(tracefile);
1177 Trace_Log(MAKESTART, NULL);
1180 * Set up the .TARGETS variable to contain the list of targets to be
1181 * created. If none specified, make the variable empty -- the parser
1182 * will fill the thing in with the default or .MAIN target.
1184 if (!Lst_IsEmpty(create)) {
1187 for (ln = Lst_First(create); ln != NULL;
1188 ln = Lst_Succ(ln)) {
1189 char *name = (char *)Lst_Datum(ln);
1191 Var_Append(".TARGETS", name, VAR_GLOBAL);
1194 Var_Set(".TARGETS", "", VAR_GLOBAL, 0);
1198 * If no user-supplied system path was given (through the -m option)
1199 * add the directories from the DEFSYSPATH (more than one may be given
1200 * as dir1:...:dirn) to the system include path.
1202 if (syspath == NULL || *syspath == '\0')
1203 syspath = defsyspath;
1205 syspath = bmake_strdup(syspath);
1207 for (start = syspath; *start != '\0'; start = cp) {
1208 for (cp = start; *cp != '\0' && *cp != ':'; cp++)
1213 /* look for magic parent directory search string */
1214 if (strncmp(".../", start, 4) != 0) {
1215 (void)Dir_AddDir(defIncPath, start);
1217 if (Dir_FindHereOrAbove(curdir, start+4,
1218 found_path, sizeof(found_path))) {
1219 (void)Dir_AddDir(defIncPath, found_path);
1223 if (syspath != defsyspath)
1227 * Read in the built-in rules first, followed by the specified
1228 * makefile, if it was (makefile != NULL), or the default
1229 * makefile and Makefile, in that order, if it wasn't.
1234 sysMkPath = Lst_Init(FALSE);
1235 Dir_Expand(_PATH_DEFSYSMK,
1236 Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath,
1238 if (Lst_IsEmpty(sysMkPath))
1239 Fatal("%s: no system rules (%s).", progname,
1241 ln = Lst_Find(sysMkPath, NULL, ReadMakefile);
1243 Fatal("%s: cannot open %s.", progname,
1244 (char *)Lst_Datum(ln));
1247 if (!Lst_IsEmpty(makefiles)) {
1250 ln = Lst_Find(makefiles, NULL, ReadAllMakefiles);
1252 Fatal("%s: cannot open %s.", progname,
1253 (char *)Lst_Datum(ln));
1255 p1 = Var_Subst(NULL, "${" MAKEFILE_PREFERENCE "}",
1256 VAR_CMD, VARF_WANTRES);
1258 (void)str2Lst_Append(makefiles, p1, NULL);
1259 (void)Lst_Find(makefiles, NULL, ReadMakefile);
1264 /* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
1265 if (!noBuiltins || !printVars) {
1266 makeDependfile = Var_Subst(NULL, "${.MAKE.DEPENDFILE:T}",
1267 VAR_CMD, VARF_WANTRES);
1268 doing_depend = TRUE;
1269 (void)ReadMakefile(makeDependfile, NULL);
1270 doing_depend = FALSE;
1274 printf("%s: Entering directory `%s'\n", progname, objdir);
1278 Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
1281 if (!forceJobs && !compatMake &&
1282 Var_Exists(".MAKE.JOBS", VAR_GLOBAL)) {
1286 value = Var_Subst(NULL, "${.MAKE.JOBS}", VAR_GLOBAL, VARF_WANTRES);
1287 n = strtol(value, NULL, 0);
1289 (void)fprintf(stderr, "%s: illegal value for .MAKE.JOBS -- must be positive integer!\n",
1294 Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL);
1295 Var_Append(MAKEFLAGS, value, VAR_GLOBAL);
1298 maxJobTokens = maxJobs;
1304 * Be compatible if user did not specify -j and did not explicitly
1305 * turned compatibility on
1307 if (!compatMake && !forceJobs) {
1312 Job_ServerStart(maxJobTokens, jp_0, jp_1);
1314 fprintf(debug_file, "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n",
1315 jp_0, jp_1, maxJobs, maxJobTokens, compatMake);
1317 Main_ExportMAKEFLAGS(TRUE); /* initial export */
1320 * For compatibility, look at the directories in the VPATH variable
1321 * and add them to the search path, if the variable is defined. The
1322 * variable's value is in the same format as the PATH envariable, i.e.
1323 * <directory>:<directory>:<directory>...
1325 if (Var_Exists("VPATH", VAR_CMD)) {
1328 * GCC stores string constants in read-only memory, but
1329 * Var_Subst will want to write this thing, so store it
1332 static char VPATH[] = "${VPATH}";
1334 vpath = Var_Subst(NULL, VPATH, VAR_CMD, VARF_WANTRES);
1337 /* skip to end of directory */
1338 for (cp = path; *cp != ':' && *cp != '\0'; cp++)
1340 /* Save terminator character so know when to stop */
1343 /* Add directory to search path */
1344 (void)Dir_AddDir(dirSearchPath, path);
1347 } while (savec == ':');
1352 * Now that all search paths have been read for suffixes et al, it's
1353 * time to add the default search path to their lists...
1358 * Propagate attributes through :: dependency lists.
1362 /* print the initial graph, if the user requested it */
1366 /* print the values of any variables requested by the user */
1374 expandVars = getBoolean(".MAKE.EXPAND_VARIABLES", FALSE);
1375 for (ln = Lst_First(variables); ln != NULL;
1376 ln = Lst_Succ(ln)) {
1377 char *var = (char *)Lst_Datum(ln);
1380 if (strchr(var, '$')) {
1381 value = p1 = Var_Subst(NULL, var, VAR_GLOBAL,
1383 } else if (expandVars) {
1386 if (snprintf(tmp, sizeof(tmp), "${%s}", var) >= (int)(sizeof(tmp)))
1387 Fatal("%s: variable name too big: %s",
1389 value = p1 = Var_Subst(NULL, tmp, VAR_GLOBAL,
1392 value = Var_Value(var, VAR_GLOBAL, &p1);
1394 printf("%s\n", value ? value : "");
1399 * Have now read the entire graph and need to make a list of
1400 * targets to create. If none was given on the command line,
1401 * we consult the parsing module to find the main target(s)
1404 if (Lst_IsEmpty(create))
1405 targs = Parse_MainName();
1407 targs = Targ_FindList(create, TARG_CREATE);
1411 * Initialize job module before traversing the graph
1412 * now that any .BEGIN and .END targets have been read.
1413 * This is done only if the -q flag wasn't given
1414 * (to prevent the .BEGIN from being executed should
1422 /* Traverse the graph, checking on all the targets */
1423 outOfDate = Make_Run(targs);
1426 * Compat_Init will take care of creating all the
1427 * targets as well as initializing the module.
1434 Lst_Destroy(targs, NULL);
1435 Lst_Destroy(variables, NULL);
1436 Lst_Destroy(makefiles, NULL);
1437 Lst_Destroy(create, (FreeProc *)free);
1440 /* print the graph now it's been processed if the user requested it */
1444 Trace_Log(MAKEEND, 0);
1447 printf("%s: Leaving directory `%s'\n", progname, objdir);
1449 printf("%s: Leaving directory `%s'\n", progname, curdir);
1463 return outOfDate ? 1 : 0;
1468 * Open and parse the given makefile.
1471 * 0 if ok. -1 if couldn't open file.
1477 ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED)
1479 const char *fname = p; /* makefile to read */
1481 size_t len = MAXPATHLEN;
1482 char *name, *path = bmake_malloc(len);
1484 if (!strcmp(fname, "-")) {
1485 Parse_File(NULL /*stdin*/, -1);
1486 Var_Set("MAKEFILE", "", VAR_INTERNAL, 0);
1488 /* if we've chdir'd, rebuild the path name */
1489 if (strcmp(curdir, objdir) && *fname != '/') {
1490 size_t plen = strlen(curdir) + strlen(fname) + 2;
1492 path = bmake_realloc(path, len = 2 * plen);
1494 (void)snprintf(path, len, "%s/%s", curdir, fname);
1495 fd = open(path, O_RDONLY);
1501 /* If curdir failed, try objdir (ala .depend) */
1502 plen = strlen(objdir) + strlen(fname) + 2;
1504 path = bmake_realloc(path, len = 2 * plen);
1505 (void)snprintf(path, len, "%s/%s", objdir, fname);
1506 fd = open(path, O_RDONLY);
1512 fd = open(fname, O_RDONLY);
1516 /* look in -I and system include directories. */
1517 name = Dir_FindFile(fname, parseIncPath);
1519 name = Dir_FindFile(fname,
1520 Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
1521 if (!name || (fd = open(name, O_RDONLY)) == -1) {
1528 * set the MAKEFILE variable desired by System V fans -- the
1529 * placement of the setting here means it gets set to the last
1530 * makefile specified, as it is set by SysV make.
1534 Var_Set("MAKEFILE", fname, VAR_INTERNAL, 0);
1535 Parse_File(fname, fd);
1545 * Execute the command in cmd, and return the output of that command
1549 * A string containing the output of the command, or the empty string
1550 * If errnum is not NULL, it contains the reason for the command failure
1553 * The string must be freed by the caller.
1556 Cmd_Exec(const char *cmd, const char **errnum)
1558 const char *args[4]; /* Args for invoking the shell */
1559 int fds[2]; /* Pipe streams */
1560 int cpid; /* Child PID */
1561 int pid; /* PID from wait() */
1562 char *res; /* result */
1563 WAIT_T status; /* command exit status */
1564 Buffer buf; /* buffer to store the result */
1566 int cc; /* bytes read, or -1 */
1567 int savederr; /* saved errno */
1575 * Set up arguments for shell
1577 args[0] = shellName;
1583 * Open a pipe for fetching its output
1585 if (pipe(fds) == -1) {
1586 *errnum = "Couldn't create pipe for \"%s\"";
1593 switch (cpid = vFork()) {
1596 * Close input side of pipe
1598 (void)close(fds[0]);
1601 * Duplicate the output stream to the shell's output, then
1602 * shut the extra thing down. Note we don't fetch the error
1603 * stream...why not? Why?
1605 (void)dup2(fds[1], 1);
1606 (void)close(fds[1]);
1610 (void)execv(shellPath, UNCONST(args));
1615 *errnum = "Couldn't exec \"%s\"";
1620 * No need for the writing half
1622 (void)close(fds[1]);
1628 char result[BUFSIZ];
1629 cc = read(fds[0], result, sizeof(result));
1631 Buf_AddBytes(&buf, cc, result);
1633 while (cc > 0 || (cc == -1 && errno == EINTR));
1638 * Close the input side of the pipe.
1640 (void)close(fds[0]);
1643 * Wait for the process to exit.
1645 while(((pid = waitpid(cpid, &status, 0)) != cpid) && (pid >= 0)) {
1646 JobReapChild(pid, status, FALSE);
1649 cc = Buf_Size(&buf);
1650 res = Buf_Destroy(&buf, FALSE);
1653 *errnum = "Couldn't read shell's output for \"%s\"";
1655 if (WIFSIGNALED(status))
1656 *errnum = "\"%s\" exited on a signal";
1657 else if (WEXITSTATUS(status) != 0)
1658 *errnum = "\"%s\" returned non-zero status";
1661 * Null-terminate the result, convert newlines to spaces and
1662 * install it in the variable.
1667 if (cc > 0 && *--cp == '\n') {
1669 * A final newline is just stripped
1683 res = bmake_malloc(1);
1690 * Print an error message given its format.
1696 * The message is printed.
1700 Error(const char *fmt, ...)
1705 err_file = debug_file;
1706 if (err_file == stdout)
1708 (void)fflush(stdout);
1711 fprintf(err_file, "%s: ", progname);
1712 (void)vfprintf(err_file, fmt, ap);
1714 (void)fprintf(err_file, "\n");
1715 (void)fflush(err_file);
1716 if (err_file == stderr)
1724 * Produce a Fatal error message. If jobs are running, waits for them
1735 Fatal(const char *fmt, ...)
1743 (void)fflush(stdout);
1744 (void)vfprintf(stderr, fmt, ap);
1746 (void)fprintf(stderr, "\n");
1747 (void)fflush(stderr);
1749 PrintOnError(NULL, NULL);
1751 if (DEBUG(GRAPH2) || DEBUG(GRAPH3))
1753 Trace_Log(MAKEERROR, 0);
1754 exit(2); /* Not 1 so -q can distinguish error */
1759 * Major exception once jobs are being created. Kills all jobs, prints
1760 * a message and exits.
1766 * All children are killed indiscriminately and the program Lib_Exits
1770 Punt(const char *fmt, ...)
1775 (void)fflush(stdout);
1776 (void)fprintf(stderr, "%s: ", progname);
1777 (void)vfprintf(stderr, fmt, ap);
1779 (void)fprintf(stderr, "\n");
1780 (void)fflush(stderr);
1782 PrintOnError(NULL, NULL);
1789 * Exit without giving a message.
1804 Trace_Log(MAKEERROR, 0);
1805 exit(2); /* Not 1, so -q can distinguish error */
1810 * Called when aborting due to errors in child shell to signal
1821 /* number of errors encountered in Make_Make */
1823 Fatal("%d error%s", errors, errors == 1 ? "" : "s");
1828 * Remove a file carefully, avoiding directories.
1831 eunlink(const char *file)
1835 if (lstat(file, &st) == -1)
1838 if (S_ISDIR(st.st_mode)) {
1842 return unlink(file);
1847 * Print why exec failed, avoiding stdio.
1850 execError(const char *af, const char *av)
1854 struct iovec iov[8];
1856 (void)(iov[i].iov_base = UNCONST(s), \
1857 iov[i].iov_len = strlen(iov[i].iov_base), \
1860 #define IOADD(s) (void)write(2, s, strlen(s))
1868 IOADD(") failed (");
1869 IOADD(strerror(errno));
1873 while (writev(2, iov, 8) == -1 && errno == EAGAIN)
1880 * exit with usage message
1886 if ((p = strchr(progname, '[')) != NULL)
1889 (void)fprintf(stderr,
1890 "usage: %s [-BeikNnqrstWwX] \n\
1891 [-C directory] [-D variable] [-d flags] [-f makefile]\n\
1892 [-I directory] [-J private] [-j max_jobs] [-m directory] [-T file]\n\
1893 [-V variable] [variable=value] [target ...]\n", progname);
1899 * realpath(3) can get expensive, cache results...
1902 cached_realpath(const char *pathname, char *resolved)
1904 static GNode *cache;
1907 if (!pathname || !pathname[0])
1911 cache = Targ_NewGN("Realpath");
1912 #ifndef DEBUG_REALPATH_CACHE
1913 cache->flags = INTERNAL;
1917 if ((rp = Var_Value(pathname, cache, &cp)) != NULL) {
1919 strlcpy(resolved, rp, MAXPATHLEN);
1920 } else if ((rp = realpath(pathname, resolved)) != NULL) {
1921 Var_Set(pathname, rp, cache, 0);
1924 return rp ? resolved : NULL;
1928 PrintAddr(void *a, void *b)
1930 printf("%lx ", (unsigned long) a);
1936 addErrorCMD(void *cmdp, void *gnp)
1939 return 1; /* stop */
1940 Var_Append(".ERROR_CMD", cmdp, VAR_GLOBAL);
1945 PrintOnError(GNode *gn, const char *s)
1947 static GNode *en = NULL;
1954 printf("\n%s: stopped in %s\n", progname, curdir);
1957 return; /* we've been here! */
1960 * We can print this even if there is no .ERROR target.
1962 Var_Set(".ERROR_TARGET", gn->name, VAR_GLOBAL, 0);
1963 Var_Delete(".ERROR_CMD", VAR_GLOBAL);
1964 Lst_ForEach(gn->commands, addErrorCMD, gn);
1966 strncpy(tmp, "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}",
1968 cp = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES);
1977 * Finally, see if there is a .ERROR target, and run it if so.
1979 en = Targ_FindNode(".ERROR", TARG_NOCREATE);
1981 en->type |= OP_SPECIAL;
1982 Compat_Make(en, en);
1987 Main_ExportMAKEFLAGS(Boolean first)
1989 static int once = 1;
1997 strncpy(tmp, "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}",
1999 s = Var_Subst(NULL, tmp, VAR_CMD, VARF_WANTRES);
2002 setenv("MAKEFLAGS", s, 1);
2004 setenv("MAKE", s, 1);
2012 static char *tmpdir = NULL;
2018 * Honor $TMPDIR but only if it is valid.
2019 * Ensure it ends with /.
2021 tmpdir = Var_Subst(NULL, "${TMPDIR:tA:U" _PATH_TMP "}/", VAR_GLOBAL,
2023 if (stat(tmpdir, &st) < 0 || !S_ISDIR(st.st_mode)) {
2025 tmpdir = bmake_strdup(_PATH_TMP);
2032 * Create and open a temp file using "pattern".
2033 * If "fnamep" is provided set it to a copy of the filename created.
2034 * Otherwise unlink the file once open.
2037 mkTempFile(const char *pattern, char **fnamep)
2039 static char *tmpdir = NULL;
2040 char tfile[MAXPATHLEN];
2046 tmpdir = getTmpdir();
2047 if (pattern[0] == '/') {
2048 snprintf(tfile, sizeof(tfile), "%s", pattern);
2050 snprintf(tfile, sizeof(tfile), "%s%s", tmpdir, pattern);
2052 if ((fd = mkstemp(tfile)) < 0)
2053 Punt("Could not create temporary file %s: %s", tfile, strerror(errno));
2055 *fnamep = bmake_strdup(tfile);
2057 unlink(tfile); /* we just want the descriptor */
2063 * Convert a string representation of a boolean.
2064 * Anything that looks like "No", "False", "Off", "0" etc,
2065 * is FALSE, otherwise TRUE.
2068 s2Boolean(const char *s, Boolean bf)
2072 case '\0': /* not set - the default wins */
2102 * Return a Boolean based on setting of a knob.
2104 * If the knob is not set, the supplied default is the return value.
2105 * If set, anything that looks or smells like "No", "False", "Off", "0" etc,
2106 * is FALSE, otherwise TRUE.
2109 getBoolean(const char *name, Boolean bf)
2114 if (snprintf(tmp, sizeof(tmp), "${%s:U:tl}", name) < (int)(sizeof(tmp))) {
2115 cp = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES);
2118 bf = s2Boolean(cp, bf);