1 /* $NetBSD: main.c,v 1.250 2016/08/11 19:53:17 sjg 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.250 2016/08/11 19:53:17 sjg 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.250 2016/08/11 19:53:17 sjg 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 */
159 static Boolean noBuiltins; /* -r flag */
160 static Lst makefiles; /* ordered list of makefiles to read */
161 static Boolean printVars; /* print value of one or more vars */
162 static Lst variables; /* list of variables to print */
163 int maxJobs; /* -j argument */
164 static int maxJobTokens; /* -j argument */
165 Boolean compatMake; /* -B argument */
166 int debug; /* -d argument */
167 Boolean debugVflag; /* -dV */
168 Boolean noExecute; /* -n flag */
169 Boolean noRecursiveExecute; /* -N flag */
170 Boolean keepgoing; /* -k flag */
171 Boolean queryFlag; /* -q flag */
172 Boolean touchFlag; /* -t flag */
173 Boolean enterFlag; /* -w flag */
174 Boolean enterFlagObj; /* -w and objdir != srcdir */
175 Boolean ignoreErrors; /* -i flag */
176 Boolean beSilent; /* -s flag */
177 Boolean oldVars; /* variable substitution style */
178 Boolean checkEnvFirst; /* -e flag */
179 Boolean parseWarnFatal; /* -W flag */
180 Boolean jobServer; /* -J flag */
181 static int jp_0 = -1, jp_1 = -1; /* ends of parent job pipe */
182 Boolean varNoExportEnv; /* -X flag */
183 Boolean doing_depend; /* Set while reading .depend */
184 static Boolean jobsRunning; /* TRUE if the jobs might be running */
185 static const char * tracefile;
186 static void MainParseArgs(int, char **);
187 static int ReadMakefile(const void *, const void *);
188 static void usage(void) MAKE_ATTR_DEAD;
190 static Boolean ignorePWD; /* if we use -C, PWD is meaningless */
191 static char objdir[MAXPATHLEN + 1]; /* where we chdir'ed to */
192 char curdir[MAXPATHLEN + 1]; /* Startup directory */
193 char *progname; /* the program name */
194 char *makeDependfile;
198 Boolean forceJobs = FALSE;
201 * On some systems MACHINE is defined as something other than
206 # define MACHINE FORCE_MACHINE
209 extern Lst parseIncPath;
212 * For compatibility with the POSIX version of MAKEFLAGS that includes
213 * all the options with out -, convert flags to -f -l -a -g -s.
216 explode(const char *flags)
225 for (f = flags; *f; f++)
226 if (!isalpha((unsigned char)*f))
230 return bmake_strdup(flags);
233 st = nf = bmake_malloc(len * 3 + 1);
244 parse_debug_options(const char *argvalue)
251 for (modules = argvalue; *modules; ++modules) {
269 debug |= DEBUG_ERROR;
275 if (modules[1] == '1') {
276 debug |= DEBUG_GRAPH1;
279 else if (modules[1] == '2') {
280 debug |= DEBUG_GRAPH2;
283 else if (modules[1] == '3') {
284 debug |= DEBUG_GRAPH3;
301 debug |= DEBUG_SCRIPT;
304 debug |= DEBUG_PARSE;
319 debug |= DEBUG_SHELL;
322 if (debug_file != stdout && debug_file != stderr)
324 if (*++modules == '+') {
329 if (strcmp(modules, "stdout") == 0) {
333 if (strcmp(modules, "stderr") == 0) {
337 len = strlen(modules);
338 fname = malloc(len + 20);
339 memcpy(fname, modules, len + 1);
340 /* Let the filename be modified by the pid */
341 if (strcmp(fname + len - 3, ".%d") == 0)
342 snprintf(fname + len - 2, 20, "%d", getpid());
343 debug_file = fopen(fname, mode);
345 fprintf(stderr, "Cannot open debug file %s\n",
352 (void)fprintf(stderr,
353 "%s: illegal argument to d option -- %c\n",
360 * Make the debug_file unbuffered, and make
361 * stdout line buffered (unless debugfile == stdout).
363 setvbuf(debug_file, NULL, _IONBF, 0);
364 if (debug_file != stdout) {
365 setvbuf(stdout, NULL, _IOLBF, 0);
371 * Parse a given argument vector. Called from main() and from
372 * Main_ParseArgLine() when the .MAKEFLAGS target is used.
374 * XXX: Deal with command line overriding .MAKEFLAGS in makefile
380 * Various global and local flags will be set depending on the flags
384 MainParseArgs(int argc, char **argv)
390 const char *getopt_def;
392 Boolean inOption, dashDash = FALSE;
393 char found_path[MAXPATHLEN + 1]; /* for searching for sys.mk */
395 #define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrstw"
396 /* Can't actually use getopt(3) because rescanning is not portable */
398 getopt_def = OPTFLAGS;
416 if (c != '-' || dashDash)
421 /* '-' found at some earlier point */
422 getopt_spec = strchr(getopt_def, c);
423 if(c != '\0' && getopt_spec != NULL && getopt_spec[1] == ':') {
424 /* -<something> found, and <something> should have an arg */
428 if(*argvalue == '\0') {
444 Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL);
445 Var_Set(MAKE_MODE, "compat", VAR_GLOBAL, 0);
448 if (chdir(argvalue) == -1) {
449 (void)fprintf(stderr,
450 "%s: chdir %s: %s\n",
455 if (getcwd(curdir, MAXPATHLEN) == NULL) {
456 (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
462 if (argvalue == NULL || argvalue[0] == 0) goto noarg;
463 Var_Set(argvalue, "1", VAR_GLOBAL, 0);
464 Var_Append(MAKEFLAGS, "-D", VAR_GLOBAL);
465 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
468 if (argvalue == NULL) goto noarg;
469 Parse_AddIncludeDir(argvalue);
470 Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL);
471 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
474 if (argvalue == NULL) goto noarg;
475 if (sscanf(argvalue, "%d,%d", &jp_0, &jp_1) != 2) {
476 (void)fprintf(stderr,
477 "%s: internal error -- J option malformed (%s)\n",
481 if ((fcntl(jp_0, F_GETFD, 0) < 0) ||
482 (fcntl(jp_1, F_GETFD, 0) < 0)) {
484 (void)fprintf(stderr,
485 "%s: ###### warning -- J descriptors were closed!\n",
493 Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL);
494 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
500 noRecursiveExecute = TRUE;
501 Var_Append(MAKEFLAGS, "-N", VAR_GLOBAL);
505 Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL);
508 if (argvalue == NULL) goto noarg;
509 tracefile = bmake_strdup(argvalue);
510 Var_Append(MAKEFLAGS, "-T", VAR_GLOBAL);
511 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
514 if (argvalue == NULL) goto noarg;
516 (void)Lst_AtEnd(variables, argvalue);
517 Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
518 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
521 parseWarnFatal = TRUE;
524 varNoExportEnv = TRUE;
525 Var_Append(MAKEFLAGS, "-X", VAR_GLOBAL);
528 if (argvalue == NULL) goto noarg;
529 /* If '-d-opts' don't pass to children */
530 if (argvalue[0] == '-')
533 Var_Append(MAKEFLAGS, "-d", VAR_GLOBAL);
534 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
536 parse_debug_options(argvalue);
539 checkEnvFirst = TRUE;
540 Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL);
543 if (argvalue == NULL) goto noarg;
544 (void)Lst_AtEnd(makefiles, argvalue);
548 Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL);
551 if (argvalue == NULL) goto noarg;
553 maxJobs = strtol(argvalue, &p, 0);
554 if (*p != '\0' || maxJobs < 1) {
555 (void)fprintf(stderr, "%s: illegal argument to -j -- must be positive integer!\n",
559 Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL);
560 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
561 Var_Set(".MAKE.JOBS", argvalue, VAR_GLOBAL, 0);
562 maxJobTokens = maxJobs;
566 Var_Append(MAKEFLAGS, "-k", VAR_GLOBAL);
569 if (argvalue == NULL) goto noarg;
570 /* look for magic parent directory search string */
571 if (strncmp(".../", argvalue, 4) == 0) {
572 if (!Dir_FindHereOrAbove(curdir, argvalue+4,
573 found_path, sizeof(found_path)))
574 break; /* nothing doing */
575 (void)Dir_AddDir(sysIncPath, found_path);
577 (void)Dir_AddDir(sysIncPath, argvalue);
579 Var_Append(MAKEFLAGS, "-m", VAR_GLOBAL);
580 Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
584 Var_Append(MAKEFLAGS, "-n", VAR_GLOBAL);
588 /* Kind of nonsensical, wot? */
589 Var_Append(MAKEFLAGS, "-q", VAR_GLOBAL);
593 Var_Append(MAKEFLAGS, "-r", VAR_GLOBAL);
597 Var_Append(MAKEFLAGS, "-s", VAR_GLOBAL);
601 Var_Append(MAKEFLAGS, "-t", VAR_GLOBAL);
605 Var_Append(MAKEFLAGS, "-w", VAR_GLOBAL);
613 fprintf(stderr, "getopt(%s) -> %d (%c)\n",
625 * See if the rest of the arguments are variable assignments and
626 * perform them if so. Else take them to be targets and stuff them
627 * on the end of the "create" list.
629 for (; argc > 1; ++argv, --argc)
630 if (Parse_IsVar(argv[1])) {
631 Parse_DoVar(argv[1], VAR_CMD);
634 Punt("illegal (null) argument.");
635 if (*argv[1] == '-' && !dashDash)
637 (void)Lst_AtEnd(create, bmake_strdup(argv[1]));
642 (void)fprintf(stderr, "%s: option requires an argument -- %c\n",
648 * Main_ParseArgLine --
649 * Used by the parse module when a .MFLAGS or .MAKEFLAGS target
650 * is encountered and by main() when reading the .MAKEFLAGS envariable.
651 * Takes a line of arguments and breaks it into its
652 * component words and passes those words and the number of them to the
653 * MainParseArgs function.
654 * The line should have all its leading whitespace removed.
657 * line Line to fracture
663 * Only those that come from the various arguments.
666 Main_ParseArgLine(const char *line)
668 char **argv; /* Manufactured argument vector */
669 int argc; /* Number of arguments in argv */
670 char *args; /* Space used by the args */
672 char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &p1);
677 for (; *line == ' '; ++line)
685 * $MAKE may simply be naming the make(1) binary
689 if (!(cp = strrchr(line, '/')))
691 if ((cp = strstr(cp, "make")) &&
692 strcmp(cp, "make") == 0)
696 buf = bmake_malloc(len = strlen(line) + strlen(argv0) + 2);
697 (void)snprintf(buf, len, "%s %s", argv0, line);
700 argv = brk_string(buf, &argc, TRUE, &args);
702 Error("Unterminated quoted string [%s]", buf);
707 MainParseArgs(argc, argv);
714 Main_SetObjdir(const char *path)
718 char buf[MAXPATHLEN + 1];
721 /* expand variable substitutions */
722 if (strchr(path, '$') != 0) {
723 snprintf(buf, MAXPATHLEN, "%s", path);
724 path = p = Var_Subst(NULL, buf, VAR_GLOBAL, VARF_WANTRES);
727 if (path[0] != '/') {
728 snprintf(buf, MAXPATHLEN, "%s/%s", curdir, path);
732 /* look for the directory and try to chdir there */
733 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
735 (void)fprintf(stderr, "make warning: %s: %s.\n",
736 path, strerror(errno));
738 strncpy(objdir, path, MAXPATHLEN);
739 Var_Set(".OBJDIR", objdir, VAR_GLOBAL, 0);
740 setenv("PWD", objdir, 1);
743 if (enterFlag && strcmp(objdir, curdir) != 0)
753 * ReadAllMakefiles --
754 * wrapper around ReadMakefile() to read all.
757 * TRUE if ok, FALSE on error
760 ReadAllMakefiles(const void *p, const void *q)
762 return (ReadMakefile(p, q) == 0);
766 str2Lst_Append(Lst lp, char *str, const char *sep)
774 for (n = 0, cp = strtok(str, sep); cp; cp = strtok(NULL, sep)) {
775 (void)Lst_AtEnd(lp, cp);
784 siginfo(int signo MAKE_ATTR_UNUSED)
786 char dir[MAXPATHLEN];
787 char str[2 * MAXPATHLEN];
789 if (getcwd(dir, sizeof(dir)) == NULL)
791 len = snprintf(str, sizeof(str), "%s: Working in: %s\n", progname, dir);
793 (void)write(STDERR_FILENO, str, (size_t)len);
798 * Allow makefiles some control over the mode we run in.
801 MakeMode(const char *mode)
806 mode = mp = Var_Subst(NULL, "${" MAKE_MODE ":tl}",
807 VAR_GLOBAL, VARF_WANTRES);
810 if (strstr(mode, "compat")) {
815 if (strstr(mode, "meta"))
816 meta_mode_init(mode);
825 * The main function, for obvious reasons. Initializes variables
826 * and a few modules, then parses the arguments give it in the
827 * environment and on the command line. Reads the system makefile
828 * followed by either Makefile, makefile or the file given by the
829 * -f argument. Sets the .MAKEFLAGS PMake variable based on all the
830 * flags it has received by then uses either the Make or the Compat
831 * module to create the initial list of targets.
834 * If -q was given, exits -1 if anything was out-of-date. Else it exits
838 * The program exits when done. Targets are created. etc. etc. etc.
841 main(int argc, char **argv)
843 Lst targs; /* target nodes to create -- passed to Make_Init */
844 Boolean outOfDate = FALSE; /* FALSE if all targets up to date */
847 char mdpath[MAXPATHLEN];
849 const char *machine = FORCE_MACHINE;
851 const char *machine = getenv("MACHINE");
853 const char *machine_arch = getenv("MACHINE_ARCH");
854 char *syspath = getenv("MAKESYSPATH");
855 Lst sysMkPath; /* Path of sys.mk */
856 char *cp = NULL, *start;
857 /* avoid faults on read-only strings */
858 static char defsyspath[] = _PATH_DEFSYSPATH;
859 char found_path[MAXPATHLEN + 1]; /* for searching for sys.mk */
860 struct timeval rightnow; /* to initialize random seed */
861 struct utsname utsname;
863 /* default to writing debug to stderr */
867 (void)bmake_signal(SIGINFO, siginfo);
870 * Set the seed to produce a different random sequence
871 * on each program execution.
873 gettimeofday(&rightnow, NULL);
874 srandom(rightnow.tv_sec + rightnow.tv_usec);
876 if ((progname = strrchr(argv[0], '/')) != NULL)
880 #if defined(MAKE_NATIVE) || (defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE))
882 * get rid of resource limit on file descriptors
886 if (getrlimit(RLIMIT_NOFILE, &rl) != -1 &&
887 rl.rlim_cur != rl.rlim_max) {
888 rl.rlim_cur = rl.rlim_max;
889 (void)setrlimit(RLIMIT_NOFILE, &rl);
894 if (uname(&utsname) == -1) {
895 (void)fprintf(stderr, "%s: uname failed (%s).\n", progname,
901 * Get the name of this type of MACHINE from utsname
902 * so we can share an executable for similar machines.
903 * (i.e. m68k: amiga hp300, mac68k, sun3, ...)
905 * Note that both MACHINE and MACHINE_ARCH are decided at
910 machine = utsname.machine;
913 machine = MAKE_MACHINE;
921 #if defined(MAKE_NATIVE) && defined(HAVE_SYSCTL) && defined(CTL_HW) && defined(HW_MACHINE_ARCH)
922 static char machine_arch_buf[sizeof(utsname.machine)];
923 int mib[2] = { CTL_HW, HW_MACHINE_ARCH };
924 size_t len = sizeof(machine_arch_buf);
926 if (sysctl(mib, __arraycount(mib), machine_arch_buf,
927 &len, NULL, 0) < 0) {
928 (void)fprintf(stderr, "%s: sysctl failed (%s).\n", progname,
933 machine_arch = machine_arch_buf;
936 #ifdef MAKE_MACHINE_ARCH
937 machine_arch = MAKE_MACHINE_ARCH;
939 machine_arch = "unknown";
942 machine_arch = MACHINE_ARCH;
947 myPid = getpid(); /* remember this for vFork() */
950 * Just in case MAKEOBJDIR wants us to do something tricky.
952 Var_Init(); /* Initialize the lists of variables for
953 * parsing arguments */
954 Var_Set(".MAKE.OS", utsname.sysname, VAR_GLOBAL, 0);
955 Var_Set("MACHINE", machine, VAR_GLOBAL, 0);
956 Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL, 0);
958 Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL, 0);
960 Var_Set(".newline", "\n", VAR_GLOBAL, 0); /* handy for :@ loops */
962 * This is the traditional preference for makefiles.
964 #ifndef MAKEFILE_PREFERENCE_LIST
965 # define MAKEFILE_PREFERENCE_LIST "makefile Makefile"
967 Var_Set(MAKEFILE_PREFERENCE, MAKEFILE_PREFERENCE_LIST,
969 Var_Set(MAKE_DEPENDFILE, ".depend", VAR_GLOBAL, 0);
971 create = Lst_Init(FALSE);
972 makefiles = Lst_Init(FALSE);
975 variables = Lst_Init(FALSE);
976 beSilent = FALSE; /* Print commands as executed */
977 ignoreErrors = FALSE; /* Pay attention to non-zero returns */
978 noExecute = FALSE; /* Execute all commands */
979 noRecursiveExecute = FALSE; /* Execute all .MAKE targets */
980 keepgoing = FALSE; /* Stop on error */
981 allPrecious = FALSE; /* Remove targets when interrupted */
982 queryFlag = FALSE; /* This is not just a check-run */
983 noBuiltins = FALSE; /* Read the built-in rules */
984 touchFlag = FALSE; /* Actually update targets */
985 debug = 0; /* No debug verbosity, please. */
988 maxJobs = DEFMAXLOCAL; /* Set default local max concurrency */
989 maxJobTokens = maxJobs;
990 compatMake = FALSE; /* No compat mode */
994 * Initialize the parsing, directory and variable modules to prepare
995 * for the reading of inclusion paths and variable settings on the
1000 * Initialize various variables.
1001 * MAKE also gets this name, for compatibility
1002 * .MAKEFLAGS gets set to the empty string just in case.
1003 * MFLAGS also gets initialized empty, for compatibility.
1006 if (argv[0][0] == '/' || strchr(argv[0], '/') == NULL) {
1008 * Leave alone if it is an absolute path, or if it does
1009 * not contain a '/' in which case we need to find it in
1010 * the path, like execvp(3) and the shells do.
1015 * A relative path, canonicalize it.
1017 p1 = cached_realpath(argv[0], mdpath);
1018 if (!p1 || *p1 != '/' || stat(p1, &sb) < 0) {
1019 p1 = argv[0]; /* realpath failed */
1022 Var_Set("MAKE", p1, VAR_GLOBAL, 0);
1023 Var_Set(".MAKE", p1, VAR_GLOBAL, 0);
1024 Var_Set(MAKEFLAGS, "", VAR_GLOBAL, 0);
1025 Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL, 0);
1026 Var_Set("MFLAGS", "", VAR_GLOBAL, 0);
1027 Var_Set(".ALLTARGETS", "", VAR_GLOBAL, 0);
1028 /* some makefiles need to know this */
1029 Var_Set(MAKE_LEVEL ".ENV", MAKE_LEVEL_ENV, VAR_CMD, 0);
1032 * Set some other useful macros
1037 makelevel = ((ep = getenv(MAKE_LEVEL_ENV)) && *ep) ? atoi(ep) : 0;
1040 snprintf(tmp, sizeof(tmp), "%d", makelevel);
1041 Var_Set(MAKE_LEVEL, tmp, VAR_GLOBAL, 0);
1042 snprintf(tmp, sizeof(tmp), "%u", myPid);
1043 Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0);
1044 snprintf(tmp, sizeof(tmp), "%u", getppid());
1045 Var_Set(".MAKE.PPID", tmp, VAR_GLOBAL, 0);
1047 if (makelevel > 0) {
1049 snprintf(pn, sizeof(pn), "%s[%d]", progname, makelevel);
1050 progname = bmake_strdup(pn);
1057 * First snag any flags out of the MAKE environment variable.
1058 * (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
1059 * in a different format).
1062 p1 = explode(getenv("MAKEFLAGS"));
1063 Main_ParseArgLine(p1);
1066 Main_ParseArgLine(getenv("MAKE"));
1070 * Find where we are (now).
1071 * We take care of PWD for the automounter below...
1073 if (getcwd(curdir, MAXPATHLEN) == NULL) {
1074 (void)fprintf(stderr, "%s: getcwd: %s.\n",
1075 progname, strerror(errno));
1079 MainParseArgs(argc, argv);
1082 printf("%s: Entering directory `%s'\n", progname, curdir);
1085 * Verify that cwd is sane.
1087 if (stat(curdir, &sa) == -1) {
1088 (void)fprintf(stderr, "%s: %s: %s.\n",
1089 progname, curdir, strerror(errno));
1094 * All this code is so that we know where we are when we start up
1095 * on a different machine with pmake.
1096 * Overriding getcwd() with $PWD totally breaks MAKEOBJDIRPREFIX
1097 * since the value of curdir can vary depending on how we got
1098 * here. Ie sitting at a shell prompt (shell that provides $PWD)
1099 * or via subdir.mk in which case its likely a shell which does
1101 * So, to stop it breaking this case only, we ignore PWD if
1102 * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a transform.
1104 #ifndef NO_PWD_OVERRIDE
1106 char *pwd, *ptmp1 = NULL, *ptmp2 = NULL;
1108 if ((pwd = getenv("PWD")) != NULL &&
1109 Var_Value("MAKEOBJDIRPREFIX", VAR_CMD, &ptmp1) == NULL) {
1110 const char *makeobjdir = Var_Value("MAKEOBJDIR",
1113 if (makeobjdir == NULL || !strchr(makeobjdir, '$')) {
1114 if (stat(pwd, &sb) == 0 &&
1115 sa.st_ino == sb.st_ino &&
1116 sa.st_dev == sb.st_dev)
1117 (void)strncpy(curdir, pwd, MAXPATHLEN);
1124 Var_Set(".CURDIR", curdir, VAR_GLOBAL, 0);
1127 * Find the .OBJDIR. If MAKEOBJDIRPREFIX, or failing that,
1128 * MAKEOBJDIR is set in the environment, try only that value
1129 * and fall back to .CURDIR if it does not exist.
1131 * Otherwise, try _PATH_OBJDIR.MACHINE, _PATH_OBJDIR, and
1132 * finally _PATH_OBJDIRPREFIX`pwd`, in that order. If none
1133 * of these paths exist, just use .CURDIR.
1136 (void)Main_SetObjdir(curdir);
1138 if ((path = Var_Value("MAKEOBJDIRPREFIX", VAR_CMD, &p1)) != NULL) {
1139 (void)snprintf(mdpath, MAXPATHLEN, "%s%s", path, curdir);
1140 (void)Main_SetObjdir(mdpath);
1142 } else if ((path = Var_Value("MAKEOBJDIR", VAR_CMD, &p1)) != NULL) {
1143 (void)Main_SetObjdir(path);
1146 (void)snprintf(mdpath, MAXPATHLEN, "%s.%s", _PATH_OBJDIR, machine);
1147 if (!Main_SetObjdir(mdpath) && !Main_SetObjdir(_PATH_OBJDIR)) {
1148 (void)snprintf(mdpath, MAXPATHLEN, "%s%s",
1149 _PATH_OBJDIRPREFIX, curdir);
1150 (void)Main_SetObjdir(mdpath);
1155 * Initialize archive, target and suffix modules in preparation for
1156 * parsing the makefile(s)
1161 Trace_Init(tracefile);
1166 Trace_Log(MAKESTART, NULL);
1169 * Set up the .TARGETS variable to contain the list of targets to be
1170 * created. If none specified, make the variable empty -- the parser
1171 * will fill the thing in with the default or .MAIN target.
1173 if (!Lst_IsEmpty(create)) {
1176 for (ln = Lst_First(create); ln != NULL;
1177 ln = Lst_Succ(ln)) {
1178 char *name = (char *)Lst_Datum(ln);
1180 Var_Append(".TARGETS", name, VAR_GLOBAL);
1183 Var_Set(".TARGETS", "", VAR_GLOBAL, 0);
1187 * If no user-supplied system path was given (through the -m option)
1188 * add the directories from the DEFSYSPATH (more than one may be given
1189 * as dir1:...:dirn) to the system include path.
1191 if (syspath == NULL || *syspath == '\0')
1192 syspath = defsyspath;
1194 syspath = bmake_strdup(syspath);
1196 for (start = syspath; *start != '\0'; start = cp) {
1197 for (cp = start; *cp != '\0' && *cp != ':'; cp++)
1202 /* look for magic parent directory search string */
1203 if (strncmp(".../", start, 4) != 0) {
1204 (void)Dir_AddDir(defIncPath, start);
1206 if (Dir_FindHereOrAbove(curdir, start+4,
1207 found_path, sizeof(found_path))) {
1208 (void)Dir_AddDir(defIncPath, found_path);
1212 if (syspath != defsyspath)
1216 * Read in the built-in rules first, followed by the specified
1217 * makefile, if it was (makefile != NULL), or the default
1218 * makefile and Makefile, in that order, if it wasn't.
1223 sysMkPath = Lst_Init(FALSE);
1224 Dir_Expand(_PATH_DEFSYSMK,
1225 Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath,
1227 if (Lst_IsEmpty(sysMkPath))
1228 Fatal("%s: no system rules (%s).", progname,
1230 ln = Lst_Find(sysMkPath, NULL, ReadMakefile);
1232 Fatal("%s: cannot open %s.", progname,
1233 (char *)Lst_Datum(ln));
1236 if (!Lst_IsEmpty(makefiles)) {
1239 ln = Lst_Find(makefiles, NULL, ReadAllMakefiles);
1241 Fatal("%s: cannot open %s.", progname,
1242 (char *)Lst_Datum(ln));
1244 p1 = Var_Subst(NULL, "${" MAKEFILE_PREFERENCE "}",
1245 VAR_CMD, VARF_WANTRES);
1247 (void)str2Lst_Append(makefiles, p1, NULL);
1248 (void)Lst_Find(makefiles, NULL, ReadMakefile);
1253 /* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
1254 if (!noBuiltins || !printVars) {
1255 makeDependfile = Var_Subst(NULL, "${.MAKE.DEPENDFILE:T}",
1256 VAR_CMD, VARF_WANTRES);
1257 doing_depend = TRUE;
1258 (void)ReadMakefile(makeDependfile, NULL);
1259 doing_depend = FALSE;
1263 printf("%s: Entering directory `%s'\n", progname, objdir);
1267 Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
1270 if (!forceJobs && !compatMake &&
1271 Var_Exists(".MAKE.JOBS", VAR_GLOBAL)) {
1275 value = Var_Subst(NULL, "${.MAKE.JOBS}", VAR_GLOBAL, VARF_WANTRES);
1276 n = strtol(value, NULL, 0);
1278 (void)fprintf(stderr, "%s: illegal value for .MAKE.JOBS -- must be positive integer!\n",
1283 Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL);
1284 Var_Append(MAKEFLAGS, value, VAR_GLOBAL);
1287 maxJobTokens = maxJobs;
1293 * Be compatible if user did not specify -j and did not explicitly
1294 * turned compatibility on
1296 if (!compatMake && !forceJobs) {
1301 Job_ServerStart(maxJobTokens, jp_0, jp_1);
1303 fprintf(debug_file, "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n",
1304 jp_0, jp_1, maxJobs, maxJobTokens, compatMake);
1306 Main_ExportMAKEFLAGS(TRUE); /* initial export */
1309 * For compatibility, look at the directories in the VPATH variable
1310 * and add them to the search path, if the variable is defined. The
1311 * variable's value is in the same format as the PATH envariable, i.e.
1312 * <directory>:<directory>:<directory>...
1314 if (Var_Exists("VPATH", VAR_CMD)) {
1317 * GCC stores string constants in read-only memory, but
1318 * Var_Subst will want to write this thing, so store it
1321 static char VPATH[] = "${VPATH}";
1323 vpath = Var_Subst(NULL, VPATH, VAR_CMD, VARF_WANTRES);
1326 /* skip to end of directory */
1327 for (cp = path; *cp != ':' && *cp != '\0'; cp++)
1329 /* Save terminator character so know when to stop */
1332 /* Add directory to search path */
1333 (void)Dir_AddDir(dirSearchPath, path);
1336 } while (savec == ':');
1341 * Now that all search paths have been read for suffixes et al, it's
1342 * time to add the default search path to their lists...
1347 * Propagate attributes through :: dependency lists.
1351 /* print the initial graph, if the user requested it */
1355 /* print the values of any variables requested by the user */
1363 expandVars = getBoolean(".MAKE.EXPAND_VARIABLES", FALSE);
1364 for (ln = Lst_First(variables); ln != NULL;
1365 ln = Lst_Succ(ln)) {
1366 char *var = (char *)Lst_Datum(ln);
1369 if (strchr(var, '$')) {
1370 value = p1 = Var_Subst(NULL, var, VAR_GLOBAL,
1372 } else if (expandVars) {
1375 if (snprintf(tmp, sizeof(tmp), "${%s}", var) >= (int)(sizeof(tmp)))
1376 Fatal("%s: variable name too big: %s",
1378 value = p1 = Var_Subst(NULL, tmp, VAR_GLOBAL,
1381 value = Var_Value(var, VAR_GLOBAL, &p1);
1383 printf("%s\n", value ? value : "");
1388 * Have now read the entire graph and need to make a list of
1389 * targets to create. If none was given on the command line,
1390 * we consult the parsing module to find the main target(s)
1393 if (Lst_IsEmpty(create))
1394 targs = Parse_MainName();
1396 targs = Targ_FindList(create, TARG_CREATE);
1400 * Initialize job module before traversing the graph
1401 * now that any .BEGIN and .END targets have been read.
1402 * This is done only if the -q flag wasn't given
1403 * (to prevent the .BEGIN from being executed should
1411 /* Traverse the graph, checking on all the targets */
1412 outOfDate = Make_Run(targs);
1415 * Compat_Init will take care of creating all the
1416 * targets as well as initializing the module.
1423 Lst_Destroy(targs, NULL);
1424 Lst_Destroy(variables, NULL);
1425 Lst_Destroy(makefiles, NULL);
1426 Lst_Destroy(create, (FreeProc *)free);
1429 /* print the graph now it's been processed if the user requested it */
1433 Trace_Log(MAKEEND, 0);
1436 printf("%s: Leaving directory `%s'\n", progname, objdir);
1438 printf("%s: Leaving directory `%s'\n", progname, curdir);
1452 return outOfDate ? 1 : 0;
1457 * Open and parse the given makefile.
1460 * 0 if ok. -1 if couldn't open file.
1466 ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED)
1468 const char *fname = p; /* makefile to read */
1470 size_t len = MAXPATHLEN;
1471 char *name, *path = bmake_malloc(len);
1473 if (!strcmp(fname, "-")) {
1474 Parse_File(NULL /*stdin*/, -1);
1475 Var_Set("MAKEFILE", "", VAR_INTERNAL, 0);
1477 /* if we've chdir'd, rebuild the path name */
1478 if (strcmp(curdir, objdir) && *fname != '/') {
1479 size_t plen = strlen(curdir) + strlen(fname) + 2;
1481 path = bmake_realloc(path, len = 2 * plen);
1483 (void)snprintf(path, len, "%s/%s", curdir, fname);
1484 fd = open(path, O_RDONLY);
1490 /* If curdir failed, try objdir (ala .depend) */
1491 plen = strlen(objdir) + strlen(fname) + 2;
1493 path = bmake_realloc(path, len = 2 * plen);
1494 (void)snprintf(path, len, "%s/%s", objdir, fname);
1495 fd = open(path, O_RDONLY);
1501 fd = open(fname, O_RDONLY);
1505 /* look in -I and system include directories. */
1506 name = Dir_FindFile(fname, parseIncPath);
1508 name = Dir_FindFile(fname,
1509 Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
1510 if (!name || (fd = open(name, O_RDONLY)) == -1) {
1517 * set the MAKEFILE variable desired by System V fans -- the
1518 * placement of the setting here means it gets set to the last
1519 * makefile specified, as it is set by SysV make.
1523 Var_Set("MAKEFILE", fname, VAR_INTERNAL, 0);
1524 Parse_File(fname, fd);
1534 * Execute the command in cmd, and return the output of that command
1538 * A string containing the output of the command, or the empty string
1539 * If errnum is not NULL, it contains the reason for the command failure
1542 * The string must be freed by the caller.
1545 Cmd_Exec(const char *cmd, const char **errnum)
1547 const char *args[4]; /* Args for invoking the shell */
1548 int fds[2]; /* Pipe streams */
1549 int cpid; /* Child PID */
1550 int pid; /* PID from wait() */
1551 char *res; /* result */
1552 WAIT_T status; /* command exit status */
1553 Buffer buf; /* buffer to store the result */
1555 int cc; /* bytes read, or -1 */
1556 int savederr; /* saved errno */
1564 * Set up arguments for shell
1566 args[0] = shellName;
1572 * Open a pipe for fetching its output
1574 if (pipe(fds) == -1) {
1575 *errnum = "Couldn't create pipe for \"%s\"";
1582 switch (cpid = vFork()) {
1585 * Close input side of pipe
1587 (void)close(fds[0]);
1590 * Duplicate the output stream to the shell's output, then
1591 * shut the extra thing down. Note we don't fetch the error
1592 * stream...why not? Why?
1594 (void)dup2(fds[1], 1);
1595 (void)close(fds[1]);
1599 (void)execv(shellPath, UNCONST(args));
1604 *errnum = "Couldn't exec \"%s\"";
1609 * No need for the writing half
1611 (void)close(fds[1]);
1617 char result[BUFSIZ];
1618 cc = read(fds[0], result, sizeof(result));
1620 Buf_AddBytes(&buf, cc, result);
1622 while (cc > 0 || (cc == -1 && errno == EINTR));
1627 * Close the input side of the pipe.
1629 (void)close(fds[0]);
1632 * Wait for the process to exit.
1634 while(((pid = waitpid(cpid, &status, 0)) != cpid) && (pid >= 0)) {
1635 JobReapChild(pid, status, FALSE);
1638 cc = Buf_Size(&buf);
1639 res = Buf_Destroy(&buf, FALSE);
1642 *errnum = "Couldn't read shell's output for \"%s\"";
1644 if (WIFSIGNALED(status))
1645 *errnum = "\"%s\" exited on a signal";
1646 else if (WEXITSTATUS(status) != 0)
1647 *errnum = "\"%s\" returned non-zero status";
1650 * Null-terminate the result, convert newlines to spaces and
1651 * install it in the variable.
1656 if (cc > 0 && *--cp == '\n') {
1658 * A final newline is just stripped
1672 res = bmake_malloc(1);
1679 * Print an error message given its format.
1685 * The message is printed.
1689 Error(const char *fmt, ...)
1694 err_file = debug_file;
1695 if (err_file == stdout)
1697 (void)fflush(stdout);
1700 fprintf(err_file, "%s: ", progname);
1701 (void)vfprintf(err_file, fmt, ap);
1703 (void)fprintf(err_file, "\n");
1704 (void)fflush(err_file);
1705 if (err_file == stderr)
1713 * Produce a Fatal error message. If jobs are running, waits for them
1724 Fatal(const char *fmt, ...)
1732 (void)fflush(stdout);
1733 (void)vfprintf(stderr, fmt, ap);
1735 (void)fprintf(stderr, "\n");
1736 (void)fflush(stderr);
1738 PrintOnError(NULL, NULL);
1740 if (DEBUG(GRAPH2) || DEBUG(GRAPH3))
1742 Trace_Log(MAKEERROR, 0);
1743 exit(2); /* Not 1 so -q can distinguish error */
1748 * Major exception once jobs are being created. Kills all jobs, prints
1749 * a message and exits.
1755 * All children are killed indiscriminately and the program Lib_Exits
1759 Punt(const char *fmt, ...)
1764 (void)fflush(stdout);
1765 (void)fprintf(stderr, "%s: ", progname);
1766 (void)vfprintf(stderr, fmt, ap);
1768 (void)fprintf(stderr, "\n");
1769 (void)fflush(stderr);
1771 PrintOnError(NULL, NULL);
1778 * Exit without giving a message.
1793 Trace_Log(MAKEERROR, 0);
1794 exit(2); /* Not 1, so -q can distinguish error */
1799 * Called when aborting due to errors in child shell to signal
1810 /* number of errors encountered in Make_Make */
1812 Fatal("%d error%s", errors, errors == 1 ? "" : "s");
1817 * Remove a file carefully, avoiding directories.
1820 eunlink(const char *file)
1824 if (lstat(file, &st) == -1)
1827 if (S_ISDIR(st.st_mode)) {
1831 return unlink(file);
1836 * Print why exec failed, avoiding stdio.
1839 execError(const char *af, const char *av)
1843 struct iovec iov[8];
1845 (void)(iov[i].iov_base = UNCONST(s), \
1846 iov[i].iov_len = strlen(iov[i].iov_base), \
1849 #define IOADD(s) (void)write(2, s, strlen(s))
1857 IOADD(") failed (");
1858 IOADD(strerror(errno));
1862 while (writev(2, iov, 8) == -1 && errno == EAGAIN)
1869 * exit with usage message
1875 if ((p = strchr(progname, '[')) != NULL)
1878 (void)fprintf(stderr,
1879 "usage: %s [-BeikNnqrstWwX] \n\
1880 [-C directory] [-D variable] [-d flags] [-f makefile]\n\
1881 [-I directory] [-J private] [-j max_jobs] [-m directory] [-T file]\n\
1882 [-V variable] [variable=value] [target ...]\n", progname);
1888 * realpath(3) can get expensive, cache results...
1891 cached_realpath(const char *pathname, char *resolved)
1893 static GNode *cache;
1896 if (!pathname || !pathname[0])
1900 cache = Targ_NewGN("Realpath");
1901 #ifndef DEBUG_REALPATH_CACHE
1902 cache->flags = INTERNAL;
1906 if ((rp = Var_Value(pathname, cache, &cp)) != NULL) {
1908 strlcpy(resolved, rp, MAXPATHLEN);
1909 } else if ((rp = realpath(pathname, resolved)) != NULL) {
1910 Var_Set(pathname, rp, cache, 0);
1913 return rp ? resolved : NULL;
1917 PrintAddr(void *a, void *b)
1919 printf("%lx ", (unsigned long) a);
1925 addErrorCMD(void *cmdp, void *gnp)
1928 return 1; /* stop */
1929 Var_Append(".ERROR_CMD", cmdp, VAR_GLOBAL);
1934 PrintOnError(GNode *gn, const char *s)
1936 static GNode *en = NULL;
1943 printf("\n%s: stopped in %s\n", progname, curdir);
1946 return; /* we've been here! */
1949 * We can print this even if there is no .ERROR target.
1951 Var_Set(".ERROR_TARGET", gn->name, VAR_GLOBAL, 0);
1952 Var_Delete(".ERROR_CMD", VAR_GLOBAL);
1953 Lst_ForEach(gn->commands, addErrorCMD, gn);
1955 strncpy(tmp, "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}",
1957 cp = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES);
1966 * Finally, see if there is a .ERROR target, and run it if so.
1968 en = Targ_FindNode(".ERROR", TARG_NOCREATE);
1970 en->type |= OP_SPECIAL;
1971 Compat_Make(en, en);
1976 Main_ExportMAKEFLAGS(Boolean first)
1978 static int once = 1;
1986 strncpy(tmp, "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}",
1988 s = Var_Subst(NULL, tmp, VAR_CMD, VARF_WANTRES);
1991 setenv("MAKEFLAGS", s, 1);
1993 setenv("MAKE", s, 1);
2001 static char *tmpdir = NULL;
2007 * Honor $TMPDIR but only if it is valid.
2008 * Ensure it ends with /.
2010 tmpdir = Var_Subst(NULL, "${TMPDIR:tA:U" _PATH_TMP "}/", VAR_GLOBAL,
2012 if (stat(tmpdir, &st) < 0 || !S_ISDIR(st.st_mode)) {
2014 tmpdir = bmake_strdup(_PATH_TMP);
2021 * Create and open a temp file using "pattern".
2022 * If "fnamep" is provided set it to a copy of the filename created.
2023 * Otherwise unlink the file once open.
2026 mkTempFile(const char *pattern, char **fnamep)
2028 static char *tmpdir = NULL;
2029 char tfile[MAXPATHLEN];
2035 tmpdir = getTmpdir();
2036 if (pattern[0] == '/') {
2037 snprintf(tfile, sizeof(tfile), "%s", pattern);
2039 snprintf(tfile, sizeof(tfile), "%s%s", tmpdir, pattern);
2041 if ((fd = mkstemp(tfile)) < 0)
2042 Punt("Could not create temporary file %s: %s", tfile, strerror(errno));
2044 *fnamep = bmake_strdup(tfile);
2046 unlink(tfile); /* we just want the descriptor */
2052 * Convert a string representation of a boolean.
2053 * Anything that looks like "No", "False", "Off", "0" etc,
2054 * is FALSE, otherwise TRUE.
2057 s2Boolean(const char *s, Boolean bf)
2061 case '\0': /* not set - the default wins */
2091 * Return a Boolean based on setting of a knob.
2093 * If the knob is not set, the supplied default is the return value.
2094 * If set, anything that looks or smells like "No", "False", "Off", "0" etc,
2095 * is FALSE, otherwise TRUE.
2098 getBoolean(const char *name, Boolean bf)
2103 if (snprintf(tmp, sizeof(tmp), "${%s:U:tl}", name) < (int)(sizeof(tmp))) {
2104 cp = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES);
2107 bf = s2Boolean(cp, bf);