1 /* $NetBSD: main.c,v 1.233 2015/09/10 17:15:11 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.233 2015/09/10 17:15:11 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.233 2015/09/10 17:15:11 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>
122 #include <sys/sysctl.h>
124 #include <sys/utsname.h>
125 #include <sys/wait.h>
140 #include "pathnames.h"
148 #define DEFMAXLOCAL DEFMAXJOBS
149 #endif /* DEFMAXLOCAL */
151 Lst create
; /* Targets to be made */
152 time_t now
; /* Time at start of make */
153 GNode
*DEFAULT
; /* .DEFAULT node */
154 Boolean allPrecious
; /* .PRECIOUS given on line by itself */
156 static Boolean noBuiltins
; /* -r flag */
157 static Lst makefiles
; /* ordered list of makefiles to read */
158 static Boolean printVars
; /* print value of one or more vars */
159 static Lst variables
; /* list of variables to print */
160 int maxJobs
; /* -j argument */
161 static int maxJobTokens
; /* -j argument */
162 Boolean compatMake
; /* -B argument */
163 int debug
; /* -d argument */
164 Boolean debugVflag
; /* -dV */
165 Boolean noExecute
; /* -n flag */
166 Boolean noRecursiveExecute
; /* -N flag */
167 Boolean keepgoing
; /* -k flag */
168 Boolean queryFlag
; /* -q flag */
169 Boolean touchFlag
; /* -t flag */
170 Boolean enterFlag
; /* -w flag */
171 Boolean enterFlagObj
; /* -w and objdir != srcdir */
172 Boolean ignoreErrors
; /* -i flag */
173 Boolean beSilent
; /* -s flag */
174 Boolean oldVars
; /* variable substitution style */
175 Boolean checkEnvFirst
; /* -e flag */
176 Boolean parseWarnFatal
; /* -W flag */
177 Boolean jobServer
; /* -J flag */
178 static int jp_0
= -1, jp_1
= -1; /* ends of parent job pipe */
179 Boolean varNoExportEnv
; /* -X flag */
180 Boolean doing_depend
; /* Set while reading .depend */
181 static Boolean jobsRunning
; /* TRUE if the jobs might be running */
182 static const char * tracefile
;
183 static void MainParseArgs(int, char **);
184 static int ReadMakefile(const void *, const void *);
185 static void usage(void) MAKE_ATTR_DEAD
;
187 static Boolean ignorePWD
; /* if we use -C, PWD is meaningless */
188 static char objdir
[MAXPATHLEN
+ 1]; /* where we chdir'ed to */
189 char curdir
[MAXPATHLEN
+ 1]; /* Startup directory */
190 char *progname
; /* the program name */
191 char *makeDependfile
;
195 Boolean forceJobs
= FALSE
;
197 extern Lst parseIncPath
;
200 * For compatibility with the POSIX version of MAKEFLAGS that includes
201 * all the options with out -, convert flags to -f -l -a -g -s.
204 explode(const char *flags
)
213 for (f
= flags
; *f
; f
++)
214 if (!isalpha((unsigned char)*f
))
218 return bmake_strdup(flags
);
221 st
= nf
= bmake_malloc(len
* 3 + 1);
232 parse_debug_options(const char *argvalue
)
239 for (modules
= argvalue
; *modules
; ++modules
) {
257 debug
|= DEBUG_ERROR
;
263 if (modules
[1] == '1') {
264 debug
|= DEBUG_GRAPH1
;
267 else if (modules
[1] == '2') {
268 debug
|= DEBUG_GRAPH2
;
271 else if (modules
[1] == '3') {
272 debug
|= DEBUG_GRAPH3
;
289 debug
|= DEBUG_SCRIPT
;
292 debug
|= DEBUG_PARSE
;
307 debug
|= DEBUG_SHELL
;
310 if (debug_file
!= stdout
&& debug_file
!= stderr
)
312 if (*++modules
== '+') {
317 if (strcmp(modules
, "stdout") == 0) {
321 if (strcmp(modules
, "stderr") == 0) {
325 len
= strlen(modules
);
326 fname
= malloc(len
+ 20);
327 memcpy(fname
, modules
, len
+ 1);
328 /* Let the filename be modified by the pid */
329 if (strcmp(fname
+ len
- 3, ".%d") == 0)
330 snprintf(fname
+ len
- 2, 20, "%d", getpid());
331 debug_file
= fopen(fname
, mode
);
333 fprintf(stderr
, "Cannot open debug file %s\n",
340 (void)fprintf(stderr
,
341 "%s: illegal argument to d option -- %c\n",
348 * Make the debug_file unbuffered, and make
349 * stdout line buffered (unless debugfile == stdout).
351 setvbuf(debug_file
, NULL
, _IONBF
, 0);
352 if (debug_file
!= stdout
) {
353 setvbuf(stdout
, NULL
, _IOLBF
, 0);
359 * Parse a given argument vector. Called from main() and from
360 * Main_ParseArgLine() when the .MAKEFLAGS target is used.
362 * XXX: Deal with command line overriding .MAKEFLAGS in makefile
368 * Various global and local flags will be set depending on the flags
372 MainParseArgs(int argc
, char **argv
)
378 const char *getopt_def
;
380 Boolean inOption
, dashDash
= FALSE
;
381 char found_path
[MAXPATHLEN
+ 1]; /* for searching for sys.mk */
383 #define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrstw"
384 /* Can't actually use getopt(3) because rescanning is not portable */
386 getopt_def
= OPTFLAGS
;
404 if (c
!= '-' || dashDash
)
409 /* '-' found at some earlier point */
410 getopt_spec
= strchr(getopt_def
, c
);
411 if(c
!= '\0' && getopt_spec
!= NULL
&& getopt_spec
[1] == ':') {
412 /* -<something> found, and <something> should have an arg */
416 if(*argvalue
== '\0') {
432 Var_Append(MAKEFLAGS
, "-B", VAR_GLOBAL
);
433 Var_Set(MAKE_MODE
, "compat", VAR_GLOBAL
, 0);
436 if (chdir(argvalue
) == -1) {
437 (void)fprintf(stderr
,
438 "%s: chdir %s: %s\n",
443 if (getcwd(curdir
, MAXPATHLEN
) == NULL
) {
444 (void)fprintf(stderr
, "%s: %s.\n", progname
, strerror(errno
));
450 if (argvalue
== NULL
|| argvalue
[0] == 0) goto noarg
;
451 Var_Set(argvalue
, "1", VAR_GLOBAL
, 0);
452 Var_Append(MAKEFLAGS
, "-D", VAR_GLOBAL
);
453 Var_Append(MAKEFLAGS
, argvalue
, VAR_GLOBAL
);
456 if (argvalue
== NULL
) goto noarg
;
457 Parse_AddIncludeDir(argvalue
);
458 Var_Append(MAKEFLAGS
, "-I", VAR_GLOBAL
);
459 Var_Append(MAKEFLAGS
, argvalue
, VAR_GLOBAL
);
462 if (argvalue
== NULL
) goto noarg
;
463 if (sscanf(argvalue
, "%d,%d", &jp_0
, &jp_1
) != 2) {
464 (void)fprintf(stderr
,
465 "%s: internal error -- J option malformed (%s)\n",
469 if ((fcntl(jp_0
, F_GETFD
, 0) < 0) ||
470 (fcntl(jp_1
, F_GETFD
, 0) < 0)) {
472 (void)fprintf(stderr
,
473 "%s: ###### warning -- J descriptors were closed!\n",
481 Var_Append(MAKEFLAGS
, "-J", VAR_GLOBAL
);
482 Var_Append(MAKEFLAGS
, argvalue
, VAR_GLOBAL
);
488 noRecursiveExecute
= TRUE
;
489 Var_Append(MAKEFLAGS
, "-N", VAR_GLOBAL
);
493 Var_Append(MAKEFLAGS
, "-S", VAR_GLOBAL
);
496 if (argvalue
== NULL
) goto noarg
;
497 tracefile
= bmake_strdup(argvalue
);
498 Var_Append(MAKEFLAGS
, "-T", VAR_GLOBAL
);
499 Var_Append(MAKEFLAGS
, argvalue
, VAR_GLOBAL
);
502 if (argvalue
== NULL
) goto noarg
;
504 (void)Lst_AtEnd(variables
, argvalue
);
505 Var_Append(MAKEFLAGS
, "-V", VAR_GLOBAL
);
506 Var_Append(MAKEFLAGS
, argvalue
, VAR_GLOBAL
);
509 parseWarnFatal
= TRUE
;
512 varNoExportEnv
= TRUE
;
513 Var_Append(MAKEFLAGS
, "-X", VAR_GLOBAL
);
516 if (argvalue
== NULL
) goto noarg
;
517 /* If '-d-opts' don't pass to children */
518 if (argvalue
[0] == '-')
521 Var_Append(MAKEFLAGS
, "-d", VAR_GLOBAL
);
522 Var_Append(MAKEFLAGS
, argvalue
, VAR_GLOBAL
);
524 parse_debug_options(argvalue
);
527 checkEnvFirst
= TRUE
;
528 Var_Append(MAKEFLAGS
, "-e", VAR_GLOBAL
);
531 if (argvalue
== NULL
) goto noarg
;
532 (void)Lst_AtEnd(makefiles
, argvalue
);
536 Var_Append(MAKEFLAGS
, "-i", VAR_GLOBAL
);
539 if (argvalue
== NULL
) goto noarg
;
541 maxJobs
= strtol(argvalue
, &p
, 0);
542 if (*p
!= '\0' || maxJobs
< 1) {
543 (void)fprintf(stderr
, "%s: illegal argument to -j -- must be positive integer!\n",
547 Var_Append(MAKEFLAGS
, "-j", VAR_GLOBAL
);
548 Var_Append(MAKEFLAGS
, argvalue
, VAR_GLOBAL
);
549 Var_Set(".MAKE.JOBS", argvalue
, VAR_GLOBAL
, 0);
550 maxJobTokens
= maxJobs
;
554 Var_Append(MAKEFLAGS
, "-k", VAR_GLOBAL
);
557 if (argvalue
== NULL
) goto noarg
;
558 /* look for magic parent directory search string */
559 if (strncmp(".../", argvalue
, 4) == 0) {
560 if (!Dir_FindHereOrAbove(curdir
, argvalue
+4,
561 found_path
, sizeof(found_path
)))
562 break; /* nothing doing */
563 (void)Dir_AddDir(sysIncPath
, found_path
);
565 (void)Dir_AddDir(sysIncPath
, argvalue
);
567 Var_Append(MAKEFLAGS
, "-m", VAR_GLOBAL
);
568 Var_Append(MAKEFLAGS
, argvalue
, VAR_GLOBAL
);
572 Var_Append(MAKEFLAGS
, "-n", VAR_GLOBAL
);
576 /* Kind of nonsensical, wot? */
577 Var_Append(MAKEFLAGS
, "-q", VAR_GLOBAL
);
581 Var_Append(MAKEFLAGS
, "-r", VAR_GLOBAL
);
585 Var_Append(MAKEFLAGS
, "-s", VAR_GLOBAL
);
589 Var_Append(MAKEFLAGS
, "-t", VAR_GLOBAL
);
593 Var_Append(MAKEFLAGS
, "-w", VAR_GLOBAL
);
609 * See if the rest of the arguments are variable assignments and
610 * perform them if so. Else take them to be targets and stuff them
611 * on the end of the "create" list.
613 for (; argc
> 1; ++argv
, --argc
)
614 if (Parse_IsVar(argv
[1])) {
615 Parse_DoVar(argv
[1], VAR_CMD
);
618 Punt("illegal (null) argument.");
619 if (*argv
[1] == '-' && !dashDash
)
621 (void)Lst_AtEnd(create
, bmake_strdup(argv
[1]));
626 (void)fprintf(stderr
, "%s: option requires an argument -- %c\n",
632 * Main_ParseArgLine --
633 * Used by the parse module when a .MFLAGS or .MAKEFLAGS target
634 * is encountered and by main() when reading the .MAKEFLAGS envariable.
635 * Takes a line of arguments and breaks it into its
636 * component words and passes those words and the number of them to the
637 * MainParseArgs function.
638 * The line should have all its leading whitespace removed.
641 * line Line to fracture
647 * Only those that come from the various arguments.
650 Main_ParseArgLine(const char *line
)
652 char **argv
; /* Manufactured argument vector */
653 int argc
; /* Number of arguments in argv */
654 char *args
; /* Space used by the args */
656 char *argv0
= Var_Value(".MAKE", VAR_GLOBAL
, &p1
);
661 for (; *line
== ' '; ++line
)
666 buf
= bmake_malloc(len
= strlen(line
) + strlen(argv0
) + 2);
667 (void)snprintf(buf
, len
, "%s %s", argv0
, line
);
671 argv
= brk_string(buf
, &argc
, TRUE
, &args
);
673 Error("Unterminated quoted string [%s]", buf
);
678 MainParseArgs(argc
, argv
);
685 Main_SetObjdir(const char *path
)
689 char buf
[MAXPATHLEN
+ 1];
692 /* expand variable substitutions */
693 if (strchr(path
, '$') != 0) {
694 snprintf(buf
, MAXPATHLEN
, "%s", path
);
695 path
= p
= Var_Subst(NULL
, buf
, VAR_GLOBAL
, 0);
698 if (path
[0] != '/') {
699 snprintf(buf
, MAXPATHLEN
, "%s/%s", curdir
, path
);
703 /* look for the directory and try to chdir there */
704 if (stat(path
, &sb
) == 0 && S_ISDIR(sb
.st_mode
)) {
706 (void)fprintf(stderr
, "make warning: %s: %s.\n",
707 path
, strerror(errno
));
709 strncpy(objdir
, path
, MAXPATHLEN
);
710 Var_Set(".OBJDIR", objdir
, VAR_GLOBAL
, 0);
711 setenv("PWD", objdir
, 1);
714 if (enterFlag
&& strcmp(objdir
, curdir
) != 0)
725 * ReadAllMakefiles --
726 * wrapper around ReadMakefile() to read all.
729 * TRUE if ok, FALSE on error
732 ReadAllMakefiles(const void *p
, const void *q
)
734 return (ReadMakefile(p
, q
) == 0);
738 str2Lst_Append(Lst lp
, char *str
, const char *sep
)
746 for (n
= 0, cp
= strtok(str
, sep
); cp
; cp
= strtok(NULL
, sep
)) {
747 (void)Lst_AtEnd(lp
, cp
);
756 siginfo(int signo MAKE_ATTR_UNUSED
)
758 char dir
[MAXPATHLEN
];
759 char str
[2 * MAXPATHLEN
];
761 if (getcwd(dir
, sizeof(dir
)) == NULL
)
763 len
= snprintf(str
, sizeof(str
), "%s: Working in: %s\n", progname
, dir
);
765 (void)write(STDERR_FILENO
, str
, (size_t)len
);
770 * Allow makefiles some control over the mode we run in.
773 MakeMode(const char *mode
)
778 mode
= mp
= Var_Subst(NULL
, "${" MAKE_MODE
":tl}", VAR_GLOBAL
, 0);
781 if (strstr(mode
, "compat")) {
786 if (strstr(mode
, "meta"))
787 meta_mode_init(mode
);
796 * The main function, for obvious reasons. Initializes variables
797 * and a few modules, then parses the arguments give it in the
798 * environment and on the command line. Reads the system makefile
799 * followed by either Makefile, makefile or the file given by the
800 * -f argument. Sets the .MAKEFLAGS PMake variable based on all the
801 * flags it has received by then uses either the Make or the Compat
802 * module to create the initial list of targets.
805 * If -q was given, exits -1 if anything was out-of-date. Else it exits
809 * The program exits when done. Targets are created. etc. etc. etc.
812 main(int argc
, char **argv
)
814 Lst targs
; /* target nodes to create -- passed to Make_Init */
815 Boolean outOfDate
= FALSE
; /* FALSE if all targets up to date */
818 char mdpath
[MAXPATHLEN
];
819 const char *machine
= getenv("MACHINE");
820 const char *machine_arch
= getenv("MACHINE_ARCH");
821 char *syspath
= getenv("MAKESYSPATH");
822 Lst sysMkPath
; /* Path of sys.mk */
823 char *cp
= NULL
, *start
;
824 /* avoid faults on read-only strings */
825 static char defsyspath
[] = _PATH_DEFSYSPATH
;
826 char found_path
[MAXPATHLEN
+ 1]; /* for searching for sys.mk */
827 struct timeval rightnow
; /* to initialize random seed */
828 struct utsname utsname
;
830 /* default to writing debug to stderr */
834 (void)bmake_signal(SIGINFO
, siginfo
);
837 * Set the seed to produce a different random sequence
838 * on each program execution.
840 gettimeofday(&rightnow
, NULL
);
841 srandom(rightnow
.tv_sec
+ rightnow
.tv_usec
);
843 if ((progname
= strrchr(argv
[0], '/')) != NULL
)
847 #if defined(MAKE_NATIVE) || (defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE))
849 * get rid of resource limit on file descriptors
853 if (getrlimit(RLIMIT_NOFILE
, &rl
) != -1 &&
854 rl
.rlim_cur
!= rl
.rlim_max
) {
855 rl
.rlim_cur
= rl
.rlim_max
;
856 (void)setrlimit(RLIMIT_NOFILE
, &rl
);
861 if (uname(&utsname
) == -1) {
862 (void)fprintf(stderr
, "%s: uname failed (%s).\n", progname
,
868 * Get the name of this type of MACHINE from utsname
869 * so we can share an executable for similar machines.
870 * (i.e. m68k: amiga hp300, mac68k, sun3, ...)
872 * Note that both MACHINE and MACHINE_ARCH are decided at
877 machine
= utsname
.machine
;
880 machine
= MAKE_MACHINE
;
888 #if defined(MAKE_NATIVE)
889 static char machine_arch_buf
[sizeof(utsname
.machine
)];
890 const int mib
[2] = { CTL_HW
, HW_MACHINE_ARCH
};
891 size_t len
= sizeof(machine_arch_buf
);
893 if (sysctl(mib
, __arraycount(mib
), machine_arch_buf
,
894 &len
, NULL
, 0) < 0) {
895 (void)fprintf(stderr
, "%s: sysctl failed (%s).\n", progname
,
900 machine_arch
= machine_arch_buf
;
903 #ifdef MAKE_MACHINE_ARCH
904 machine_arch
= MAKE_MACHINE_ARCH
;
906 machine_arch
= "unknown";
909 machine_arch
= MACHINE_ARCH
;
914 myPid
= getpid(); /* remember this for vFork() */
917 * Just in case MAKEOBJDIR wants us to do something tricky.
919 Var_Init(); /* Initialize the lists of variables for
920 * parsing arguments */
921 Var_Set(".MAKE.OS", utsname
.sysname
, VAR_GLOBAL
, 0);
922 Var_Set("MACHINE", machine
, VAR_GLOBAL
, 0);
923 Var_Set("MACHINE_ARCH", machine_arch
, VAR_GLOBAL
, 0);
925 Var_Set("MAKE_VERSION", MAKE_VERSION
, VAR_GLOBAL
, 0);
927 Var_Set(".newline", "\n", VAR_GLOBAL
, 0); /* handy for :@ loops */
929 * This is the traditional preference for makefiles.
931 #ifndef MAKEFILE_PREFERENCE_LIST
932 # define MAKEFILE_PREFERENCE_LIST "makefile Makefile"
934 Var_Set(MAKEFILE_PREFERENCE
, MAKEFILE_PREFERENCE_LIST
,
936 Var_Set(MAKE_DEPENDFILE
, ".depend", VAR_GLOBAL
, 0);
938 create
= Lst_Init(FALSE
);
939 makefiles
= Lst_Init(FALSE
);
942 variables
= Lst_Init(FALSE
);
943 beSilent
= FALSE
; /* Print commands as executed */
944 ignoreErrors
= FALSE
; /* Pay attention to non-zero returns */
945 noExecute
= FALSE
; /* Execute all commands */
946 noRecursiveExecute
= FALSE
; /* Execute all .MAKE targets */
947 keepgoing
= FALSE
; /* Stop on error */
948 allPrecious
= FALSE
; /* Remove targets when interrupted */
949 queryFlag
= FALSE
; /* This is not just a check-run */
950 noBuiltins
= FALSE
; /* Read the built-in rules */
951 touchFlag
= FALSE
; /* Actually update targets */
952 debug
= 0; /* No debug verbosity, please. */
955 maxJobs
= DEFMAXLOCAL
; /* Set default local max concurrency */
956 maxJobTokens
= maxJobs
;
957 compatMake
= FALSE
; /* No compat mode */
961 * Initialize the parsing, directory and variable modules to prepare
962 * for the reading of inclusion paths and variable settings on the
967 * Initialize various variables.
968 * MAKE also gets this name, for compatibility
969 * .MAKEFLAGS gets set to the empty string just in case.
970 * MFLAGS also gets initialized empty, for compatibility.
973 if (argv
[0][0] == '/' || strchr(argv
[0], '/') == NULL
) {
975 * Leave alone if it is an absolute path, or if it does
976 * not contain a '/' in which case we need to find it in
977 * the path, like execvp(3) and the shells do.
982 * A relative path, canonicalize it.
984 p1
= realpath(argv
[0], mdpath
);
985 if (!p1
|| *p1
!= '/' || stat(p1
, &sb
) < 0) {
986 p1
= argv
[0]; /* realpath failed */
989 Var_Set("MAKE", p1
, VAR_GLOBAL
, 0);
990 Var_Set(".MAKE", p1
, VAR_GLOBAL
, 0);
991 Var_Set(MAKEFLAGS
, "", VAR_GLOBAL
, 0);
992 Var_Set(MAKEOVERRIDES
, "", VAR_GLOBAL
, 0);
993 Var_Set("MFLAGS", "", VAR_GLOBAL
, 0);
994 Var_Set(".ALLTARGETS", "", VAR_GLOBAL
, 0);
995 /* some makefiles need to know this */
996 Var_Set(MAKE_LEVEL
".ENV", MAKE_LEVEL_ENV
, VAR_CMD
, 0);
999 * Set some other useful macros
1004 makelevel
= ((ep
= getenv(MAKE_LEVEL_ENV
)) && *ep
) ? atoi(ep
) : 0;
1007 snprintf(tmp
, sizeof(tmp
), "%d", makelevel
);
1008 Var_Set(MAKE_LEVEL
, tmp
, VAR_GLOBAL
, 0);
1009 snprintf(tmp
, sizeof(tmp
), "%u", myPid
);
1010 Var_Set(".MAKE.PID", tmp
, VAR_GLOBAL
, 0);
1011 snprintf(tmp
, sizeof(tmp
), "%u", getppid());
1012 Var_Set(".MAKE.PPID", tmp
, VAR_GLOBAL
, 0);
1014 if (makelevel
> 0) {
1016 snprintf(pn
, sizeof(pn
), "%s[%d]", progname
, makelevel
);
1017 progname
= bmake_strdup(pn
);
1024 * First snag any flags out of the MAKE environment variable.
1025 * (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
1026 * in a different format).
1029 p1
= explode(getenv("MAKEFLAGS"));
1030 Main_ParseArgLine(p1
);
1033 Main_ParseArgLine(getenv("MAKE"));
1037 * Find where we are (now).
1038 * We take care of PWD for the automounter below...
1040 if (getcwd(curdir
, MAXPATHLEN
) == NULL
) {
1041 (void)fprintf(stderr
, "%s: getcwd: %s.\n",
1042 progname
, strerror(errno
));
1046 MainParseArgs(argc
, argv
);
1049 printf("%s: Entering directory `%s'\n", progname
, curdir
);
1052 * Verify that cwd is sane.
1054 if (stat(curdir
, &sa
) == -1) {
1055 (void)fprintf(stderr
, "%s: %s: %s.\n",
1056 progname
, curdir
, strerror(errno
));
1061 * All this code is so that we know where we are when we start up
1062 * on a different machine with pmake.
1063 * Overriding getcwd() with $PWD totally breaks MAKEOBJDIRPREFIX
1064 * since the value of curdir can vary depending on how we got
1065 * here. Ie sitting at a shell prompt (shell that provides $PWD)
1066 * or via subdir.mk in which case its likely a shell which does
1068 * So, to stop it breaking this case only, we ignore PWD if
1069 * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a transform.
1071 #ifndef NO_PWD_OVERRIDE
1073 char *pwd
, *ptmp1
= NULL
, *ptmp2
= NULL
;
1075 if ((pwd
= getenv("PWD")) != NULL
&&
1076 Var_Value("MAKEOBJDIRPREFIX", VAR_CMD
, &ptmp1
) == NULL
) {
1077 const char *makeobjdir
= Var_Value("MAKEOBJDIR",
1080 if (makeobjdir
== NULL
|| !strchr(makeobjdir
, '$')) {
1081 if (stat(pwd
, &sb
) == 0 &&
1082 sa
.st_ino
== sb
.st_ino
&&
1083 sa
.st_dev
== sb
.st_dev
)
1084 (void)strncpy(curdir
, pwd
, MAXPATHLEN
);
1091 Var_Set(".CURDIR", curdir
, VAR_GLOBAL
, 0);
1094 * Find the .OBJDIR. If MAKEOBJDIRPREFIX, or failing that,
1095 * MAKEOBJDIR is set in the environment, try only that value
1096 * and fall back to .CURDIR if it does not exist.
1098 * Otherwise, try _PATH_OBJDIR.MACHINE, _PATH_OBJDIR, and
1099 * finally _PATH_OBJDIRPREFIX`pwd`, in that order. If none
1100 * of these paths exist, just use .CURDIR.
1103 (void)Main_SetObjdir(curdir
);
1105 if ((path
= Var_Value("MAKEOBJDIRPREFIX", VAR_CMD
, &p1
)) != NULL
) {
1106 (void)snprintf(mdpath
, MAXPATHLEN
, "%s%s", path
, curdir
);
1107 (void)Main_SetObjdir(mdpath
);
1109 } else if ((path
= Var_Value("MAKEOBJDIR", VAR_CMD
, &p1
)) != NULL
) {
1110 (void)Main_SetObjdir(path
);
1113 (void)snprintf(mdpath
, MAXPATHLEN
, "%s.%s", _PATH_OBJDIR
, machine
);
1114 if (!Main_SetObjdir(mdpath
) && !Main_SetObjdir(_PATH_OBJDIR
)) {
1115 (void)snprintf(mdpath
, MAXPATHLEN
, "%s%s",
1116 _PATH_OBJDIRPREFIX
, curdir
);
1117 (void)Main_SetObjdir(mdpath
);
1122 * Be compatible if user did not specify -j and did not explicitly
1123 * turned compatibility on
1125 if (!compatMake
&& !forceJobs
) {
1130 * Initialize archive, target and suffix modules in preparation for
1131 * parsing the makefile(s)
1136 Trace_Init(tracefile
);
1141 Trace_Log(MAKESTART
, NULL
);
1144 * Set up the .TARGETS variable to contain the list of targets to be
1145 * created. If none specified, make the variable empty -- the parser
1146 * will fill the thing in with the default or .MAIN target.
1148 if (!Lst_IsEmpty(create
)) {
1151 for (ln
= Lst_First(create
); ln
!= NULL
;
1152 ln
= Lst_Succ(ln
)) {
1153 char *name
= (char *)Lst_Datum(ln
);
1155 Var_Append(".TARGETS", name
, VAR_GLOBAL
);
1158 Var_Set(".TARGETS", "", VAR_GLOBAL
, 0);
1162 * If no user-supplied system path was given (through the -m option)
1163 * add the directories from the DEFSYSPATH (more than one may be given
1164 * as dir1:...:dirn) to the system include path.
1166 if (syspath
== NULL
|| *syspath
== '\0')
1167 syspath
= defsyspath
;
1169 syspath
= bmake_strdup(syspath
);
1171 for (start
= syspath
; *start
!= '\0'; start
= cp
) {
1172 for (cp
= start
; *cp
!= '\0' && *cp
!= ':'; cp
++)
1177 /* look for magic parent directory search string */
1178 if (strncmp(".../", start
, 4) != 0) {
1179 (void)Dir_AddDir(defIncPath
, start
);
1181 if (Dir_FindHereOrAbove(curdir
, start
+4,
1182 found_path
, sizeof(found_path
))) {
1183 (void)Dir_AddDir(defIncPath
, found_path
);
1187 if (syspath
!= defsyspath
)
1191 * Read in the built-in rules first, followed by the specified
1192 * makefile, if it was (makefile != NULL), or the default
1193 * makefile and Makefile, in that order, if it wasn't.
1198 sysMkPath
= Lst_Init(FALSE
);
1199 Dir_Expand(_PATH_DEFSYSMK
,
1200 Lst_IsEmpty(sysIncPath
) ? defIncPath
: sysIncPath
,
1202 if (Lst_IsEmpty(sysMkPath
))
1203 Fatal("%s: no system rules (%s).", progname
,
1205 ln
= Lst_Find(sysMkPath
, NULL
, ReadMakefile
);
1207 Fatal("%s: cannot open %s.", progname
,
1208 (char *)Lst_Datum(ln
));
1211 if (!Lst_IsEmpty(makefiles
)) {
1214 ln
= Lst_Find(makefiles
, NULL
, ReadAllMakefiles
);
1216 Fatal("%s: cannot open %s.", progname
,
1217 (char *)Lst_Datum(ln
));
1219 p1
= Var_Subst(NULL
, "${" MAKEFILE_PREFERENCE
"}",
1222 (void)str2Lst_Append(makefiles
, p1
, NULL
);
1223 (void)Lst_Find(makefiles
, NULL
, ReadMakefile
);
1228 /* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
1229 if (!noBuiltins
|| !printVars
) {
1230 makeDependfile
= Var_Subst(NULL
, "${.MAKE.DEPENDFILE:T}",
1232 doing_depend
= TRUE
;
1233 (void)ReadMakefile(makeDependfile
, NULL
);
1234 doing_depend
= FALSE
;
1238 printf("%s: Entering directory `%s'\n", progname
, objdir
);
1242 Var_Append("MFLAGS", Var_Value(MAKEFLAGS
, VAR_GLOBAL
, &p1
), VAR_GLOBAL
);
1247 Job_ServerStart(maxJobTokens
, jp_0
, jp_1
);
1249 fprintf(debug_file
, "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n",
1250 jp_0
, jp_1
, maxJobs
, maxJobTokens
, compatMake
);
1252 Main_ExportMAKEFLAGS(TRUE
); /* initial export */
1256 * For compatibility, look at the directories in the VPATH variable
1257 * and add them to the search path, if the variable is defined. The
1258 * variable's value is in the same format as the PATH envariable, i.e.
1259 * <directory>:<directory>:<directory>...
1261 if (Var_Exists("VPATH", VAR_CMD
)) {
1264 * GCC stores string constants in read-only memory, but
1265 * Var_Subst will want to write this thing, so store it
1268 static char VPATH
[] = "${VPATH}";
1270 vpath
= Var_Subst(NULL
, VPATH
, VAR_CMD
, FALSE
);
1273 /* skip to end of directory */
1274 for (cp
= path
; *cp
!= ':' && *cp
!= '\0'; cp
++)
1276 /* Save terminator character so know when to stop */
1279 /* Add directory to search path */
1280 (void)Dir_AddDir(dirSearchPath
, path
);
1283 } while (savec
== ':');
1288 * Now that all search paths have been read for suffixes et al, it's
1289 * time to add the default search path to their lists...
1294 * Propagate attributes through :: dependency lists.
1298 /* print the initial graph, if the user requested it */
1302 /* print the values of any variables requested by the user */
1310 expandVars
= getBoolean(".MAKE.EXPAND_VARIABLES", FALSE
);
1311 for (ln
= Lst_First(variables
); ln
!= NULL
;
1312 ln
= Lst_Succ(ln
)) {
1313 char *var
= (char *)Lst_Datum(ln
);
1316 if (strchr(var
, '$')) {
1317 value
= p1
= Var_Subst(NULL
, var
, VAR_GLOBAL
, 0);
1318 } else if (expandVars
) {
1321 if (snprintf(tmp
, sizeof(tmp
), "${%s}", var
) >= (int)(sizeof(tmp
)))
1322 Fatal("%s: variable name too big: %s",
1324 value
= p1
= Var_Subst(NULL
, tmp
, VAR_GLOBAL
, 0);
1326 value
= Var_Value(var
, VAR_GLOBAL
, &p1
);
1328 printf("%s\n", value
? value
: "");
1334 * Have now read the entire graph and need to make a list of
1335 * targets to create. If none was given on the command line,
1336 * we consult the parsing module to find the main target(s)
1339 if (Lst_IsEmpty(create
))
1340 targs
= Parse_MainName();
1342 targs
= Targ_FindList(create
, TARG_CREATE
);
1346 * Initialize job module before traversing the graph
1347 * now that any .BEGIN and .END targets have been read.
1348 * This is done only if the -q flag wasn't given
1349 * (to prevent the .BEGIN from being executed should
1357 /* Traverse the graph, checking on all the targets */
1358 outOfDate
= Make_Run(targs
);
1361 * Compat_Init will take care of creating all the
1362 * targets as well as initializing the module.
1369 Lst_Destroy(targs
, NULL
);
1370 Lst_Destroy(variables
, NULL
);
1371 Lst_Destroy(makefiles
, NULL
);
1372 Lst_Destroy(create
, (FreeProc
*)free
);
1375 /* print the graph now it's been processed if the user requested it */
1379 Trace_Log(MAKEEND
, 0);
1382 printf("%s: Leaving directory `%s'\n", progname
, objdir
);
1384 printf("%s: Leaving directory `%s'\n", progname
, curdir
);
1395 return outOfDate
? 1 : 0;
1400 * Open and parse the given makefile.
1403 * 0 if ok. -1 if couldn't open file.
1409 ReadMakefile(const void *p
, const void *q MAKE_ATTR_UNUSED
)
1411 const char *fname
= p
; /* makefile to read */
1413 size_t len
= MAXPATHLEN
;
1414 char *name
, *path
= bmake_malloc(len
);
1416 if (!strcmp(fname
, "-")) {
1417 Parse_File(NULL
/*stdin*/, -1);
1418 Var_Set("MAKEFILE", "", VAR_INTERNAL
, 0);
1420 /* if we've chdir'd, rebuild the path name */
1421 if (strcmp(curdir
, objdir
) && *fname
!= '/') {
1422 size_t plen
= strlen(curdir
) + strlen(fname
) + 2;
1424 path
= bmake_realloc(path
, len
= 2 * plen
);
1426 (void)snprintf(path
, len
, "%s/%s", curdir
, fname
);
1427 fd
= open(path
, O_RDONLY
);
1433 /* If curdir failed, try objdir (ala .depend) */
1434 plen
= strlen(objdir
) + strlen(fname
) + 2;
1436 path
= bmake_realloc(path
, len
= 2 * plen
);
1437 (void)snprintf(path
, len
, "%s/%s", objdir
, fname
);
1438 fd
= open(path
, O_RDONLY
);
1444 fd
= open(fname
, O_RDONLY
);
1448 /* look in -I and system include directories. */
1449 name
= Dir_FindFile(fname
, parseIncPath
);
1451 name
= Dir_FindFile(fname
,
1452 Lst_IsEmpty(sysIncPath
) ? defIncPath
: sysIncPath
);
1453 if (!name
|| (fd
= open(name
, O_RDONLY
)) == -1) {
1461 * set the MAKEFILE variable desired by System V fans -- the
1462 * placement of the setting here means it gets set to the last
1463 * makefile specified, as it is set by SysV make.
1467 Var_Set("MAKEFILE", fname
, VAR_INTERNAL
, 0);
1468 Parse_File(fname
, fd
);
1478 * Execute the command in cmd, and return the output of that command
1482 * A string containing the output of the command, or the empty string
1483 * If errnum is not NULL, it contains the reason for the command failure
1486 * The string must be freed by the caller.
1489 Cmd_Exec(const char *cmd
, const char **errnum
)
1491 const char *args
[4]; /* Args for invoking the shell */
1492 int fds
[2]; /* Pipe streams */
1493 int cpid
; /* Child PID */
1494 int pid
; /* PID from wait() */
1495 char *res
; /* result */
1496 int status
; /* command exit status */
1497 Buffer buf
; /* buffer to store the result */
1499 int cc
; /* bytes read, or -1 */
1500 int savederr
; /* saved errno */
1508 * Set up arguments for shell
1510 args
[0] = shellName
;
1516 * Open a pipe for fetching its output
1518 if (pipe(fds
) == -1) {
1519 *errnum
= "Couldn't create pipe for \"%s\"";
1526 switch (cpid
= vFork()) {
1529 * Close input side of pipe
1531 (void)close(fds
[0]);
1534 * Duplicate the output stream to the shell's output, then
1535 * shut the extra thing down. Note we don't fetch the error
1536 * stream...why not? Why?
1538 (void)dup2(fds
[1], 1);
1539 (void)close(fds
[1]);
1543 (void)execv(shellPath
, UNCONST(args
));
1548 *errnum
= "Couldn't exec \"%s\"";
1553 * No need for the writing half
1555 (void)close(fds
[1]);
1561 char result
[BUFSIZ
];
1562 cc
= read(fds
[0], result
, sizeof(result
));
1564 Buf_AddBytes(&buf
, cc
, result
);
1566 while (cc
> 0 || (cc
== -1 && errno
== EINTR
));
1571 * Close the input side of the pipe.
1573 (void)close(fds
[0]);
1576 * Wait for the process to exit.
1578 while(((pid
= waitpid(cpid
, &status
, 0)) != cpid
) && (pid
>= 0)) {
1579 JobReapChild(pid
, status
, FALSE
);
1582 cc
= Buf_Size(&buf
);
1583 res
= Buf_Destroy(&buf
, FALSE
);
1586 *errnum
= "Couldn't read shell's output for \"%s\"";
1588 if (WIFSIGNALED(status
))
1589 *errnum
= "\"%s\" exited on a signal";
1590 else if (WEXITSTATUS(status
) != 0)
1591 *errnum
= "\"%s\" returned non-zero status";
1594 * Null-terminate the result, convert newlines to spaces and
1595 * install it in the variable.
1600 if (cc
> 0 && *--cp
== '\n') {
1602 * A final newline is just stripped
1616 res
= bmake_malloc(1);
1623 * Print an error message given its format.
1629 * The message is printed.
1633 Error(const char *fmt
, ...)
1638 err_file
= debug_file
;
1639 if (err_file
== stdout
)
1641 (void)fflush(stdout
);
1644 fprintf(err_file
, "%s: ", progname
);
1645 (void)vfprintf(err_file
, fmt
, ap
);
1647 (void)fprintf(err_file
, "\n");
1648 (void)fflush(err_file
);
1649 if (err_file
== stderr
)
1657 * Produce a Fatal error message. If jobs are running, waits for them
1668 Fatal(const char *fmt
, ...)
1676 (void)fflush(stdout
);
1677 (void)vfprintf(stderr
, fmt
, ap
);
1679 (void)fprintf(stderr
, "\n");
1680 (void)fflush(stderr
);
1682 PrintOnError(NULL
, NULL
);
1684 if (DEBUG(GRAPH2
) || DEBUG(GRAPH3
))
1686 Trace_Log(MAKEERROR
, 0);
1687 exit(2); /* Not 1 so -q can distinguish error */
1692 * Major exception once jobs are being created. Kills all jobs, prints
1693 * a message and exits.
1699 * All children are killed indiscriminately and the program Lib_Exits
1703 Punt(const char *fmt
, ...)
1708 (void)fflush(stdout
);
1709 (void)fprintf(stderr
, "%s: ", progname
);
1710 (void)vfprintf(stderr
, fmt
, ap
);
1712 (void)fprintf(stderr
, "\n");
1713 (void)fflush(stderr
);
1715 PrintOnError(NULL
, NULL
);
1722 * Exit without giving a message.
1737 Trace_Log(MAKEERROR
, 0);
1738 exit(2); /* Not 1, so -q can distinguish error */
1743 * Called when aborting due to errors in child shell to signal
1754 /* number of errors encountered in Make_Make */
1756 Fatal("%d error%s", errors
, errors
== 1 ? "" : "s");
1761 * Remove a file carefully, avoiding directories.
1764 eunlink(const char *file
)
1768 if (lstat(file
, &st
) == -1)
1771 if (S_ISDIR(st
.st_mode
)) {
1775 return unlink(file
);
1780 * Print why exec failed, avoiding stdio.
1783 execError(const char *af
, const char *av
)
1787 struct iovec iov
[8];
1789 (void)(iov[i].iov_base = UNCONST(s), \
1790 iov[i].iov_len = strlen(iov[i].iov_base), \
1793 #define IOADD(void)write(2, s, strlen(s))
1801 IOADD(") failed (");
1802 IOADD(strerror(errno
));
1806 while (writev(2, iov
, 8) == -1 && errno
== EAGAIN
)
1813 * exit with usage message
1819 if ((p
= strchr(progname
, '[')) != NULL
)
1822 (void)fprintf(stderr
,
1823 "usage: %s [-BeikNnqrstWwX] \n\
1824 [-C directory] [-D variable] [-d flags] [-f makefile]\n\
1825 [-I directory] [-J private] [-j max_jobs] [-m directory] [-T file]\n\
1826 [-V variable] [variable=value] [target ...]\n", progname
);
1832 PrintAddr(void *a
, void *b
)
1834 printf("%lx ", (unsigned long) a
);
1841 PrintOnError(GNode
*gn
, const char *s
)
1843 static GNode
*en
= NULL
;
1850 printf("\n%s: stopped in %s\n", progname
, curdir
);
1853 return; /* we've been here! */
1856 * We can print this even if there is no .ERROR target.
1858 Var_Set(".ERROR_TARGET", gn
->name
, VAR_GLOBAL
, 0);
1860 strncpy(tmp
, "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}",
1862 cp
= Var_Subst(NULL
, tmp
, VAR_GLOBAL
, 0);
1869 * Finally, see if there is a .ERROR target, and run it if so.
1871 en
= Targ_FindNode(".ERROR", TARG_NOCREATE
);
1873 en
->type
|= OP_SPECIAL
;
1874 Compat_Make(en
, en
);
1879 Main_ExportMAKEFLAGS(Boolean first
)
1881 static int once
= 1;
1889 strncpy(tmp
, "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}",
1891 s
= Var_Subst(NULL
, tmp
, VAR_CMD
, 0);
1894 setenv("MAKEFLAGS", s
, 1);
1896 setenv("MAKE", s
, 1);
1904 static char *tmpdir
= NULL
;
1910 * Honor $TMPDIR but only if it is valid.
1911 * Ensure it ends with /.
1913 tmpdir
= Var_Subst(NULL
, "${TMPDIR:tA:U" _PATH_TMP
"}/", VAR_GLOBAL
, 0);
1914 if (stat(tmpdir
, &st
) < 0 || !S_ISDIR(st
.st_mode
)) {
1916 tmpdir
= bmake_strdup(_PATH_TMP
);
1923 * Create and open a temp file using "pattern".
1924 * If "fnamep" is provided set it to a copy of the filename created.
1925 * Otherwise unlink the file once open.
1928 mkTempFile(const char *pattern
, char **fnamep
)
1930 static char *tmpdir
= NULL
;
1931 char tfile
[MAXPATHLEN
];
1937 tmpdir
= getTmpdir();
1938 if (pattern
[0] == '/') {
1939 snprintf(tfile
, sizeof(tfile
), "%s", pattern
);
1941 snprintf(tfile
, sizeof(tfile
), "%s%s", tmpdir
, pattern
);
1943 if ((fd
= mkstemp(tfile
)) < 0)
1944 Punt("Could not create temporary file %s: %s", tfile
, strerror(errno
));
1946 *fnamep
= bmake_strdup(tfile
);
1948 unlink(tfile
); /* we just want the descriptor */
1955 * Return a Boolean based on setting of a knob.
1957 * If the knob is not set, the supplied default is the return value.
1958 * If set, anything that looks or smells like "No", "False", "Off", "0" etc,
1959 * is FALSE, otherwise TRUE.
1962 getBoolean(const char *name
, Boolean bf
)
1967 if (snprintf(tmp
, sizeof(tmp
), "${%s:tl}", name
) < (int)(sizeof(tmp
))) {
1968 cp
= Var_Subst(NULL
, tmp
, VAR_GLOBAL
, 0);
1972 case '\0': /* not set - the default wins */