2001-11-02 18:37:41 +03:00
|
|
|
/* $NetBSD: main.c,v 1.76 2001/11/02 15:37:41 tv Exp $ */
|
1995-06-14 19:18:37 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
* Copyright (c) 1988, 1989, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
* Copyright (c) 1989 by Berkeley Softworks
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Adam de Boor.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-09-28 07:30:58 +04:00
|
|
|
#ifdef MAKE_BOOTSTRAP
|
2001-11-02 18:37:41 +03:00
|
|
|
static char rcsid[] = "$NetBSD: main.c,v 1.76 2001/11/02 15:37:41 tv Exp $";
|
1997-09-28 07:30:58 +04:00
|
|
|
#else
|
1997-07-02 01:17:00 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1997-07-02 01:17:00 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-06-14 19:18:37 +04:00
|
|
|
#if 0
|
1996-11-06 20:58:58 +03:00
|
|
|
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
|
1995-06-14 19:18:37 +04:00
|
|
|
#else
|
2001-11-02 18:37:41 +03:00
|
|
|
__RCSID("$NetBSD: main.c,v 1.76 2001/11/02 15:37:41 tv Exp $");
|
1995-06-14 19:18:37 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
1997-09-28 07:30:58 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* main.c --
|
|
|
|
* The main file for this entire program. Exit routines etc
|
|
|
|
* reside here.
|
|
|
|
*
|
|
|
|
* Utility functions defined in this file:
|
|
|
|
* Main_ParseArgLine Takes a line of arguments, breaks them and
|
|
|
|
* treats them as if they were given when first
|
|
|
|
* invoked. Used by the parse module to implement
|
|
|
|
* the .MFLAGS target.
|
|
|
|
*
|
|
|
|
* Error Print a tagged error message. The global
|
|
|
|
* MAKE variable must have been defined. This
|
|
|
|
* takes a format string and two optional
|
|
|
|
* arguments for it.
|
|
|
|
*
|
|
|
|
* Fatal Print an error message and exit. Also takes
|
|
|
|
* a format string and two arguments.
|
|
|
|
*
|
|
|
|
* Punt Aborts all jobs and exits with a message. Also
|
|
|
|
* takes a format string and two arguments.
|
|
|
|
*
|
|
|
|
* Finish Finish things up by printing the number of
|
2001-09-16 20:34:23 +04:00
|
|
|
* errors which occurred, as passed to it, and
|
1993-03-21 12:45:37 +03:00
|
|
|
* exiting.
|
|
|
|
*/
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <sys/param.h>
|
1994-03-05 03:34:29 +03:00
|
|
|
#include <sys/resource.h>
|
1995-11-03 02:54:35 +03:00
|
|
|
#include <sys/signal.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <sys/stat.h>
|
1997-03-24 23:56:36 +03:00
|
|
|
#ifndef MAKE_BOOTSTRAP
|
1994-09-30 06:14:21 +03:00
|
|
|
#include <sys/utsname.h>
|
1996-11-06 20:58:58 +03:00
|
|
|
#endif
|
1996-05-29 03:34:35 +04:00
|
|
|
#include <sys/wait.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
1996-12-31 20:54:16 +03:00
|
|
|
#include <stdlib.h>
|
1998-04-02 14:33:17 +04:00
|
|
|
#include <time.h>
|
1996-12-31 20:54:16 +03:00
|
|
|
#ifdef __STDC__
|
1994-03-05 03:34:29 +03:00
|
|
|
#include <stdarg.h>
|
|
|
|
#else
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <varargs.h>
|
1994-03-05 03:34:29 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "make.h"
|
1994-03-05 03:34:29 +03:00
|
|
|
#include "hash.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "job.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "pathnames.h"
|
2000-12-30 05:05:20 +03:00
|
|
|
#include "trace.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-05-29 21:37:51 +04:00
|
|
|
#ifdef USE_IOVEC
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#endif
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef DEFMAXLOCAL
|
|
|
|
#define DEFMAXLOCAL DEFMAXJOBS
|
1996-02-05 01:20:27 +03:00
|
|
|
#endif /* DEFMAXLOCAL */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
Lst create; /* Targets to be made */
|
|
|
|
time_t now; /* Time at start of make */
|
|
|
|
GNode *DEFAULT; /* .DEFAULT node */
|
|
|
|
Boolean allPrecious; /* .PRECIOUS given on line by itself */
|
|
|
|
|
|
|
|
static Boolean noBuiltins; /* -r flag */
|
|
|
|
static Lst makefiles; /* ordered list of makefiles to read */
|
1996-11-06 20:58:58 +03:00
|
|
|
static Boolean printVars; /* print value of one or more vars */
|
|
|
|
static Lst variables; /* list of variables to print */
|
1995-11-03 02:54:35 +03:00
|
|
|
int maxJobs; /* -j argument */
|
1993-03-21 12:45:37 +03:00
|
|
|
static int maxLocal; /* -L argument */
|
1994-03-05 03:34:29 +03:00
|
|
|
Boolean compatMake; /* -B argument */
|
1993-03-21 12:45:37 +03:00
|
|
|
Boolean debug; /* -d flag */
|
|
|
|
Boolean noExecute; /* -n flag */
|
2001-01-01 18:47:37 +03:00
|
|
|
Boolean noRecursiveExecute; /* -N flag */
|
1993-03-21 12:45:37 +03:00
|
|
|
Boolean keepgoing; /* -k flag */
|
|
|
|
Boolean queryFlag; /* -q flag */
|
|
|
|
Boolean touchFlag; /* -t flag */
|
|
|
|
Boolean usePipes; /* !-P flag */
|
|
|
|
Boolean ignoreErrors; /* -i flag */
|
|
|
|
Boolean beSilent; /* -s flag */
|
|
|
|
Boolean oldVars; /* variable substitution style */
|
|
|
|
Boolean checkEnvFirst; /* -e flag */
|
2001-01-10 18:54:00 +03:00
|
|
|
Boolean parseWarnFatal; /* -W flag */
|
2000-12-30 05:05:20 +03:00
|
|
|
Boolean jobServer; /* -J flag */
|
1993-03-21 12:45:37 +03:00
|
|
|
static Boolean jobsRunning; /* TRUE if the jobs might be running */
|
2000-12-30 05:05:20 +03:00
|
|
|
static const char * tracefile;
|
2000-04-20 15:23:25 +04:00
|
|
|
static char * Check_Cwd_av __P((int, char **, int));
|
1996-11-06 20:58:58 +03:00
|
|
|
static void MainParseArgs __P((int, char **));
|
|
|
|
static int ReadMakefile __P((ClientData, ClientData));
|
|
|
|
static void usage __P((void));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
static char curdir[MAXPATHLEN + 1]; /* startup directory */
|
|
|
|
static char objdir[MAXPATHLEN + 1]; /* where we chdir'ed to */
|
2001-01-10 18:54:00 +03:00
|
|
|
char *progname; /* the program name */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-12-30 05:05:20 +03:00
|
|
|
Boolean forceJobs = FALSE;
|
|
|
|
|
2001-01-10 18:54:00 +03:00
|
|
|
extern Lst parseIncPath;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
|
|
|
* MainParseArgs --
|
|
|
|
* Parse a given argument vector. Called from main() and from
|
|
|
|
* Main_ParseArgLine() when the .MAKEFLAGS target is used.
|
|
|
|
*
|
|
|
|
* XXX: Deal with command line overriding .MAKEFLAGS in makefile
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Various global and local flags will be set depending on the flags
|
|
|
|
* given
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
MainParseArgs(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
1999-08-02 21:23:58 +04:00
|
|
|
char *p;
|
|
|
|
int c;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
optind = 1; /* since we're called more than once */
|
1995-11-03 02:54:35 +03:00
|
|
|
#ifdef REMOTE
|
2001-01-14 08:33:53 +03:00
|
|
|
# define OPTFLAGS "BD:I:J:L:NPST:V:Wd:ef:ij:km:nqrst"
|
1994-03-05 03:34:29 +03:00
|
|
|
#else
|
2001-01-14 08:33:53 +03:00
|
|
|
# define OPTFLAGS "BD:I:J:NPST:V:Wd:ef:ij:km:nqrst"
|
1994-03-05 03:34:29 +03:00
|
|
|
#endif
|
1997-11-08 12:33:15 +03:00
|
|
|
rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
|
1993-03-21 12:45:37 +03:00
|
|
|
switch(c) {
|
|
|
|
case 'D':
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set(optarg, "1", VAR_GLOBAL, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
Var_Append(MAKEFLAGS, "-D", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
Parse_AddIncludeDir(optarg);
|
|
|
|
Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
2000-12-30 05:05:20 +03:00
|
|
|
case 'J':
|
|
|
|
if (sscanf(optarg, "%d,%d", &job_pipe[0], &job_pipe[1]) != 2) {
|
2001-01-16 05:37:03 +03:00
|
|
|
/* backslash to avoid trigraph ??) */
|
2001-01-10 18:54:00 +03:00
|
|
|
(void)fprintf(stderr,
|
2001-01-16 05:37:03 +03:00
|
|
|
"%s: internal error -- J option malformed (%s?\?)\n",
|
2001-01-10 18:54:00 +03:00
|
|
|
progname, optarg);
|
2000-12-30 05:05:20 +03:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
if ((fcntl(job_pipe[0], F_GETFD, 0) < 0) ||
|
|
|
|
(fcntl(job_pipe[1], F_GETFD, 0) < 0)) {
|
2001-01-01 18:47:37 +03:00
|
|
|
#if 0
|
2000-12-30 05:05:20 +03:00
|
|
|
(void)fprintf(stderr,
|
2001-01-10 18:54:00 +03:00
|
|
|
"%s: warning -- J descriptors were closed!\n",
|
|
|
|
progname);
|
2001-01-01 18:47:37 +03:00
|
|
|
#endif
|
2000-12-30 05:05:20 +03:00
|
|
|
job_pipe[0] = -1;
|
|
|
|
job_pipe[1] = -1;
|
2001-01-01 18:47:37 +03:00
|
|
|
compatMake = TRUE;
|
2000-12-30 05:05:20 +03:00
|
|
|
} else {
|
|
|
|
Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
jobServer = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
1996-11-06 20:58:58 +03:00
|
|
|
case 'V':
|
|
|
|
printVars = TRUE;
|
|
|
|
(void)Lst_AtEnd(variables, (ClientData)optarg);
|
|
|
|
Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
1994-03-05 03:34:29 +03:00
|
|
|
case 'B':
|
|
|
|
compatMake = TRUE;
|
|
|
|
break;
|
1995-11-03 02:54:35 +03:00
|
|
|
#ifdef REMOTE
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'L':
|
1999-08-02 21:23:58 +04:00
|
|
|
maxLocal = strtol(optarg, &p, 0);
|
|
|
|
if (*p != '\0' || maxLocal < 1) {
|
2001-01-10 18:54:00 +03:00
|
|
|
(void) fprintf(stderr, "%s: illegal argument to -L -- must be positive integer!\n",
|
|
|
|
progname);
|
|
|
|
exit(1);
|
1999-08-02 19:23:11 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
Var_Append(MAKEFLAGS, "-L", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
1995-11-03 02:54:35 +03:00
|
|
|
#endif
|
2001-01-01 18:47:37 +03:00
|
|
|
case 'N':
|
|
|
|
noExecute = TRUE;
|
|
|
|
noRecursiveExecute = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-N", VAR_GLOBAL);
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'P':
|
|
|
|
usePipes = FALSE;
|
|
|
|
Var_Append(MAKEFLAGS, "-P", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
keepgoing = FALSE;
|
|
|
|
Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL);
|
|
|
|
break;
|
2000-12-30 05:05:20 +03:00
|
|
|
case 'T':
|
2000-12-30 05:52:03 +03:00
|
|
|
tracefile = estrdup(optarg);
|
2000-12-30 05:05:20 +03:00
|
|
|
Var_Append(MAKEFLAGS, "-T", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
2001-01-10 18:54:00 +03:00
|
|
|
case 'W':
|
|
|
|
parseWarnFatal = TRUE;
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'd': {
|
|
|
|
char *modules = optarg;
|
|
|
|
|
|
|
|
for (; *modules; ++modules)
|
|
|
|
switch (*modules) {
|
|
|
|
case 'A':
|
|
|
|
debug = ~0;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
debug |= DEBUG_ARCH;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
debug |= DEBUG_COND;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
debug |= DEBUG_DIR;
|
|
|
|
break;
|
1994-03-05 03:34:29 +03:00
|
|
|
case 'f':
|
|
|
|
debug |= DEBUG_FOR;
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'g':
|
|
|
|
if (modules[1] == '1') {
|
|
|
|
debug |= DEBUG_GRAPH1;
|
|
|
|
++modules;
|
|
|
|
}
|
|
|
|
else if (modules[1] == '2') {
|
|
|
|
debug |= DEBUG_GRAPH2;
|
|
|
|
++modules;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
debug |= DEBUG_JOB;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
debug |= DEBUG_MAKE;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
debug |= DEBUG_SUFF;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
debug |= DEBUG_TARG;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
debug |= DEBUG_VAR;
|
|
|
|
break;
|
2001-06-02 00:33:37 +04:00
|
|
|
case 'x':
|
|
|
|
debug |= DEBUG_SHELL;
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
|
|
|
(void)fprintf(stderr,
|
2001-01-10 18:54:00 +03:00
|
|
|
"%s: illegal argument to d option -- %c\n",
|
|
|
|
progname, *modules);
|
1993-03-21 12:45:37 +03:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
Var_Append(MAKEFLAGS, "-d", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'e':
|
|
|
|
checkEnvFirst = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
(void)Lst_AtEnd(makefiles, (ClientData)optarg);
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
ignoreErrors = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 'j':
|
1995-11-08 05:30:53 +03:00
|
|
|
forceJobs = TRUE;
|
1999-08-02 21:23:58 +04:00
|
|
|
maxJobs = strtol(optarg, &p, 0);
|
|
|
|
if (*p != '\0' || maxJobs < 1) {
|
2001-01-10 18:54:00 +03:00
|
|
|
(void) fprintf(stderr, "%s: illegal argument to -j -- must be positive integer!\n",
|
|
|
|
progname);
|
1999-08-02 19:23:11 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
#ifndef REMOTE
|
|
|
|
maxLocal = maxJobs;
|
|
|
|
#endif
|
1993-12-15 21:26:40 +03:00
|
|
|
Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL);
|
1993-03-21 12:45:37 +03:00
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
keepgoing = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-k", VAR_GLOBAL);
|
|
|
|
break;
|
1996-03-06 03:15:17 +03:00
|
|
|
case 'm':
|
1997-05-09 01:24:41 +04:00
|
|
|
(void) Dir_AddDir(sysIncPath, optarg);
|
1996-03-06 03:15:17 +03:00
|
|
|
Var_Append(MAKEFLAGS, "-m", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'n':
|
|
|
|
noExecute = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-n", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
queryFlag = TRUE;
|
|
|
|
/* Kind of nonsensical, wot? */
|
|
|
|
Var_Append(MAKEFLAGS, "-q", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
noBuiltins = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-r", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
beSilent = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-s", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
touchFlag = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-t", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
oldVars = TRUE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if the rest of the arguments are variable assignments and
|
|
|
|
* perform them if so. Else take them to be targets and stuff them
|
|
|
|
* on the end of the "create" list.
|
|
|
|
*/
|
|
|
|
for (argv += optind, argc -= optind; *argv; ++argv, --argc)
|
2001-06-02 00:33:37 +04:00
|
|
|
if (Parse_IsVar(*argv)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
Parse_DoVar(*argv, VAR_CMD);
|
2001-06-02 00:33:37 +04:00
|
|
|
} else {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!**argv)
|
|
|
|
Punt("illegal (null) argument.");
|
|
|
|
if (**argv == '-') {
|
1994-03-05 03:34:29 +03:00
|
|
|
if ((*argv)[1])
|
|
|
|
optind = 0; /* -flag... */
|
|
|
|
else
|
|
|
|
optind = 1; /* - */
|
1993-03-21 12:45:37 +03:00
|
|
|
goto rearg;
|
|
|
|
}
|
1996-08-13 20:42:00 +04:00
|
|
|
(void)Lst_AtEnd(create, (ClientData)estrdup(*argv));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Main_ParseArgLine --
|
|
|
|
* Used by the parse module when a .MFLAGS or .MAKEFLAGS target
|
|
|
|
* is encountered and by main() when reading the .MAKEFLAGS envariable.
|
|
|
|
* Takes a line of arguments and breaks it into its
|
|
|
|
* component words and passes those words and the number of them to the
|
|
|
|
* MainParseArgs function.
|
|
|
|
* The line should have all its leading whitespace removed.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Only those that come from the various arguments.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Main_ParseArgLine(line)
|
|
|
|
char *line; /* Line to fracture */
|
|
|
|
{
|
|
|
|
char **argv; /* Manufactured argument vector */
|
|
|
|
int argc; /* Number of arguments in argv */
|
1998-03-26 22:20:36 +03:00
|
|
|
char *args; /* Space used by the args */
|
|
|
|
char *buf, *p1;
|
|
|
|
char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &p1);
|
1999-09-04 08:21:28 +04:00
|
|
|
size_t len;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (line == NULL)
|
|
|
|
return;
|
1994-03-05 03:34:29 +03:00
|
|
|
for (; *line == ' '; ++line)
|
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!*line)
|
|
|
|
return;
|
|
|
|
|
1999-09-04 08:21:28 +04:00
|
|
|
buf = emalloc(len = strlen(line) + strlen(argv0) + 2);
|
|
|
|
(void)snprintf(buf, len, "%s %s", argv0, line);
|
1998-03-26 22:20:36 +03:00
|
|
|
if (p1)
|
|
|
|
free(p1);
|
|
|
|
|
1998-03-29 01:29:04 +03:00
|
|
|
argv = brk_string(buf, &argc, TRUE, &args);
|
1998-11-01 06:07:33 +03:00
|
|
|
free(buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
MainParseArgs(argc, argv);
|
1998-03-26 22:20:36 +03:00
|
|
|
|
|
|
|
free(args);
|
|
|
|
free(argv);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
Boolean
|
|
|
|
Main_SetObjdir(path)
|
|
|
|
const char *path;
|
1996-11-06 20:58:58 +03:00
|
|
|
{
|
|
|
|
struct stat sb;
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
char *p = NULL;
|
|
|
|
char buf[MAXPATHLEN + 1];
|
2001-11-02 18:37:41 +03:00
|
|
|
Boolean rc = FALSE;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
/* expand variable substitutions */
|
2000-02-08 15:43:25 +03:00
|
|
|
if (strchr(path, '$') != 0) {
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
snprintf(buf, MAXPATHLEN, "%s", path);
|
|
|
|
path = p = Var_Subst(NULL, buf, VAR_GLOBAL, 0);
|
2000-02-08 15:43:25 +03:00
|
|
|
}
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
|
|
|
|
if (path[0] != '/') {
|
|
|
|
snprintf(buf, MAXPATHLEN, "%s/%s", curdir, path);
|
|
|
|
path = buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for the directory and try to chdir there */
|
1996-11-06 20:58:58 +03:00
|
|
|
if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
|
|
|
|
if (chdir(path)) {
|
|
|
|
(void)fprintf(stderr, "make warning: %s: %s.\n",
|
|
|
|
path, strerror(errno));
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
} else {
|
|
|
|
strncpy(objdir, path, MAXPATHLEN);
|
|
|
|
Var_Set(".OBJDIR", objdir, VAR_GLOBAL, 0);
|
|
|
|
setenv("PWD", objdir, 1);
|
|
|
|
rc = TRUE;
|
1996-11-06 20:58:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
if (p)
|
|
|
|
free(p);
|
|
|
|
return rc;
|
1996-11-06 20:58:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
|
|
|
* main --
|
|
|
|
* The main function, for obvious reasons. Initializes variables
|
|
|
|
* and a few modules, then parses the arguments give it in the
|
|
|
|
* environment and on the command line. Reads the system makefile
|
|
|
|
* followed by either Makefile, makefile or the file given by the
|
|
|
|
* -f argument. Sets the .MAKEFLAGS PMake variable based on all the
|
|
|
|
* flags it has received by then uses either the Make or the Compat
|
|
|
|
* module to create the initial list of targets.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* If -q was given, exits -1 if anything was out-of-date. Else it exits
|
|
|
|
* 0.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The program exits when done. Targets are created. etc. etc. etc.
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
Lst targs; /* target nodes to create -- passed to Make_Init */
|
1994-03-05 03:34:29 +03:00
|
|
|
Boolean outOfDate = TRUE; /* FALSE if all targets up to date */
|
2001-11-02 06:52:21 +03:00
|
|
|
struct stat sb;
|
|
|
|
char *p1, *path;
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
char mdpath[MAXPATHLEN];
|
1995-01-06 22:57:27 +03:00
|
|
|
char *machine = getenv("MACHINE");
|
1997-01-29 02:58:00 +03:00
|
|
|
char *machine_arch = getenv("MACHINE_ARCH");
|
2000-04-29 16:15:16 +04:00
|
|
|
char *syspath = getenv("MAKESYSPATH");
|
1996-03-06 03:15:17 +03:00
|
|
|
Lst sysMkPath; /* Path of sys.mk */
|
|
|
|
char *cp = NULL, *start;
|
|
|
|
/* avoid faults on read-only strings */
|
2000-04-29 16:15:16 +04:00
|
|
|
static char defsyspath[] = _PATH_DEFSYSPATH;
|
|
|
|
|
2000-04-17 03:24:23 +04:00
|
|
|
if ((progname = strrchr(argv[0], '/')) != NULL)
|
|
|
|
progname++;
|
|
|
|
else
|
|
|
|
progname = argv[0];
|
1995-11-03 02:54:35 +03:00
|
|
|
#ifdef RLIMIT_NOFILE
|
|
|
|
/*
|
|
|
|
* get rid of resource limit on file descriptors
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct rlimit rl;
|
|
|
|
if (getrlimit(RLIMIT_NOFILE, &rl) != -1 &&
|
|
|
|
rl.rlim_cur != rl.rlim_max) {
|
|
|
|
rl.rlim_cur = rl.rlim_max;
|
|
|
|
(void) setrlimit(RLIMIT_NOFILE, &rl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1994-03-05 03:34:29 +03:00
|
|
|
/*
|
|
|
|
* Find where we are and take care of PWD for the automounter...
|
|
|
|
* All this code is so that we know where we are when we start up
|
|
|
|
* on a different machine with pmake.
|
|
|
|
*/
|
1994-09-23 13:33:21 +04:00
|
|
|
if (getcwd(curdir, MAXPATHLEN) == NULL) {
|
2001-01-10 18:54:00 +03:00
|
|
|
(void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
|
1994-03-05 03:34:29 +03:00
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2001-11-02 06:52:21 +03:00
|
|
|
if (stat(curdir, &sb) == -1) {
|
2001-01-10 18:54:00 +03:00
|
|
|
(void)fprintf(stderr, "%s: %s: %s.\n",
|
|
|
|
progname, curdir, strerror(errno));
|
1994-03-05 03:34:29 +03:00
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
1994-09-30 06:14:21 +03:00
|
|
|
/*
|
|
|
|
* Get the name of this type of MACHINE from utsname
|
|
|
|
* so we can share an executable for similar machines.
|
|
|
|
* (i.e. m68k: amiga hp300, mac68k, sun3, ...)
|
|
|
|
*
|
1997-01-29 02:58:00 +03:00
|
|
|
* Note that both MACHINE and MACHINE_ARCH are decided at
|
|
|
|
* run-time.
|
1994-09-30 06:14:21 +03:00
|
|
|
*/
|
1997-03-24 23:56:36 +03:00
|
|
|
if (!machine) {
|
|
|
|
#ifndef MAKE_BOOTSTRAP
|
1996-11-06 20:58:58 +03:00
|
|
|
struct utsname utsname;
|
|
|
|
|
1995-11-22 20:39:53 +03:00
|
|
|
if (uname(&utsname) == -1) {
|
2001-01-10 18:54:00 +03:00
|
|
|
(void)fprintf(stderr, "%s: uname failed (%s).\n", progname,
|
|
|
|
strerror(errno));
|
|
|
|
exit(2);
|
1995-01-06 22:57:27 +03:00
|
|
|
}
|
|
|
|
machine = utsname.machine;
|
1996-03-11 16:45:31 +03:00
|
|
|
#else
|
|
|
|
machine = MACHINE;
|
|
|
|
#endif
|
1994-09-30 06:14:21 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-01-29 02:58:00 +03:00
|
|
|
if (!machine_arch) {
|
|
|
|
#ifndef MACHINE_ARCH
|
1998-10-13 21:08:34 +04:00
|
|
|
#ifdef __ARCHITECTURE__
|
|
|
|
machine_arch = __ARCHITECTURE__;
|
|
|
|
#else
|
1997-01-29 02:58:00 +03:00
|
|
|
machine_arch = "unknown"; /* XXX: no uname -p yet */
|
1998-10-13 21:08:34 +04:00
|
|
|
#endif
|
1997-01-29 02:58:00 +03:00
|
|
|
#else
|
|
|
|
machine_arch = MACHINE_ARCH;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-02-08 15:43:25 +03:00
|
|
|
/*
|
|
|
|
* Just in case MAKEOBJDIR wants us to do something tricky.
|
|
|
|
*/
|
|
|
|
Var_Init(); /* Initialize the lists of variables for
|
|
|
|
* parsing arguments */
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set(".CURDIR", curdir, VAR_GLOBAL, 0);
|
|
|
|
Var_Set("MACHINE", machine, VAR_GLOBAL, 0);
|
|
|
|
Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL, 0);
|
2001-06-02 00:33:37 +04:00
|
|
|
#ifdef MAKE_VERSION
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL, 0);
|
2001-06-02 00:33:37 +04:00
|
|
|
#endif
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set(".newline", "\n", VAR_GLOBAL, 0); /* handy for :@ loops */
|
2000-02-08 15:43:25 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
* Find the .OBJDIR. If MAKEOBJDIRPREFIX, or failing that,
|
|
|
|
* MAKEOBJDIR is set in the environment, try only that value
|
|
|
|
* and fall back to .CURDIR if it does not exist.
|
1996-11-06 20:58:58 +03:00
|
|
|
*
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
* Otherwise, try _PATH_OBJDIR.MACHINE, _PATH_OBJDIR, and
|
|
|
|
* finally _PATH_OBJDIRPREFIX`pwd`, in that order. If none
|
|
|
|
* of these paths exist, just use .CURDIR.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
(void) Main_SetObjdir(curdir);
|
|
|
|
if ((path = getenv("MAKEOBJDIRPREFIX")) != NULL) {
|
|
|
|
(void) snprintf(mdpath, MAXPATHLEN, "%s%s", path, curdir);
|
|
|
|
(void) Main_SetObjdir(mdpath);
|
|
|
|
} else if ((path = getenv("MAKEOBJDIR")) != NULL) {
|
|
|
|
(void) Main_SetObjdir(path);
|
|
|
|
} else {
|
|
|
|
(void) snprintf(mdpath, MAXPATHLEN, "%s.%s", _PATH_OBJDIR, machine);
|
|
|
|
if (!Main_SetObjdir(mdpath) && !Main_SetObjdir(_PATH_OBJDIR)) {
|
|
|
|
(void) snprintf(mdpath, MAXPATHLEN, "%s%s",
|
|
|
|
_PATH_OBJDIRPREFIX, curdir);
|
|
|
|
(void) Main_SetObjdir(mdpath);
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
create = Lst_Init(FALSE);
|
|
|
|
makefiles = Lst_Init(FALSE);
|
1996-11-06 20:58:58 +03:00
|
|
|
printVars = FALSE;
|
|
|
|
variables = Lst_Init(FALSE);
|
1993-03-21 12:45:37 +03:00
|
|
|
beSilent = FALSE; /* Print commands as executed */
|
|
|
|
ignoreErrors = FALSE; /* Pay attention to non-zero returns */
|
|
|
|
noExecute = FALSE; /* Execute all commands */
|
2001-01-01 18:47:37 +03:00
|
|
|
noRecursiveExecute = FALSE; /* Execute all .MAKE targets */
|
1993-03-21 12:45:37 +03:00
|
|
|
keepgoing = FALSE; /* Stop on error */
|
|
|
|
allPrecious = FALSE; /* Remove targets when interrupted */
|
|
|
|
queryFlag = FALSE; /* This is not just a check-run */
|
|
|
|
noBuiltins = FALSE; /* Read the built-in rules */
|
|
|
|
touchFlag = FALSE; /* Actually update targets */
|
|
|
|
usePipes = TRUE; /* Catch child output in pipes */
|
|
|
|
debug = 0; /* No debug verbosity, please. */
|
|
|
|
jobsRunning = FALSE;
|
|
|
|
|
|
|
|
maxLocal = DEFMAXLOCAL; /* Set default local max concurrency */
|
1995-11-03 02:54:35 +03:00
|
|
|
#ifdef REMOTE
|
|
|
|
maxJobs = DEFMAXJOBS; /* Set default max concurrency */
|
1994-03-05 03:34:29 +03:00
|
|
|
#else
|
1995-11-03 02:54:35 +03:00
|
|
|
maxJobs = maxLocal;
|
1994-03-05 03:34:29 +03:00
|
|
|
#endif
|
1995-11-03 02:54:35 +03:00
|
|
|
compatMake = FALSE; /* No compat mode */
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Initialize the parsing, directory and variable modules to prepare
|
|
|
|
* for the reading of inclusion paths and variable settings on the
|
|
|
|
* command line
|
|
|
|
*/
|
1997-05-09 01:24:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize directory structures so -I flags can be processed
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
* correctly.
|
1997-05-09 01:24:41 +04:00
|
|
|
*/
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
Dir_Init(curdir);
|
1993-03-21 12:45:37 +03:00
|
|
|
Parse_Init(); /* Need to initialize the paths of #include
|
|
|
|
* directories */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize various variables.
|
|
|
|
* MAKE also gets this name, for compatibility
|
|
|
|
* .MAKEFLAGS gets set to the empty string just in case.
|
|
|
|
* MFLAGS also gets initialized empty, for compatibility.
|
|
|
|
*/
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set("MAKE", argv[0], VAR_GLOBAL, 0);
|
|
|
|
Var_Set(".MAKE", argv[0], VAR_GLOBAL, 0);
|
|
|
|
Var_Set(MAKEFLAGS, "", VAR_GLOBAL, 0);
|
|
|
|
Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL, 0);
|
|
|
|
Var_Set("MFLAGS", "", VAR_GLOBAL, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First snag any flags out of the MAKE environment variable.
|
|
|
|
* (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
|
|
|
|
* in a different format).
|
|
|
|
*/
|
|
|
|
#ifdef POSIX
|
|
|
|
Main_ParseArgLine(getenv("MAKEFLAGS"));
|
|
|
|
#else
|
|
|
|
Main_ParseArgLine(getenv("MAKE"));
|
|
|
|
#endif
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
MainParseArgs(argc, argv);
|
|
|
|
|
2000-12-30 05:05:20 +03:00
|
|
|
/*
|
|
|
|
* Be compatible if user did not specify -j and did not explicitly
|
|
|
|
* turned compatibility on
|
|
|
|
*/
|
|
|
|
if (!compatMake && !forceJobs) {
|
|
|
|
compatMake = TRUE;
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Initialize archive, target and suffix modules in preparation for
|
|
|
|
* parsing the makefile(s)
|
|
|
|
*/
|
|
|
|
Arch_Init();
|
|
|
|
Targ_Init();
|
|
|
|
Suff_Init();
|
2000-12-30 05:05:20 +03:00
|
|
|
Trace_Init(tracefile);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
DEFAULT = NILGNODE;
|
|
|
|
(void)time(&now);
|
|
|
|
|
2000-12-30 05:05:20 +03:00
|
|
|
Trace_Log(MAKESTART, NULL);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Set up the .TARGETS variable to contain the list of targets to be
|
|
|
|
* created. If none specified, make the variable empty -- the parser
|
|
|
|
* will fill the thing in with the default or .MAIN target.
|
|
|
|
*/
|
|
|
|
if (!Lst_IsEmpty(create)) {
|
|
|
|
LstNode ln;
|
|
|
|
|
|
|
|
for (ln = Lst_First(create); ln != NILLNODE;
|
|
|
|
ln = Lst_Succ(ln)) {
|
|
|
|
char *name = (char *)Lst_Datum(ln);
|
|
|
|
|
|
|
|
Var_Append(".TARGETS", name, VAR_GLOBAL);
|
|
|
|
}
|
|
|
|
} else
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set(".TARGETS", "", VAR_GLOBAL, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-03-06 03:15:17 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1996-03-06 03:15:17 +03:00
|
|
|
* If no user-supplied system path was given (through the -m option)
|
|
|
|
* add the directories from the DEFSYSPATH (more than one may be given
|
|
|
|
* as dir1:...:dirn) to the system include path.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2001-10-31 04:15:57 +03:00
|
|
|
if (syspath == NULL || *syspath == '\0')
|
|
|
|
syspath = defsyspath;
|
|
|
|
else
|
|
|
|
syspath = strdup(syspath);
|
|
|
|
|
|
|
|
for (start = syspath; *start != '\0'; start = cp) {
|
|
|
|
for (cp = start; *cp != '\0' && *cp != ':'; cp++)
|
|
|
|
continue;
|
|
|
|
if (*cp == '\0') {
|
|
|
|
(void) Dir_AddDir(defIncPath, start);
|
|
|
|
} else {
|
|
|
|
*cp++ = '\0';
|
|
|
|
(void) Dir_AddDir(defIncPath, start);
|
1996-03-06 03:15:17 +03:00
|
|
|
}
|
|
|
|
}
|
2001-10-31 04:15:57 +03:00
|
|
|
if (syspath != defsyspath)
|
|
|
|
free(syspath);
|
1996-03-06 03:15:17 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in the built-in rules first, followed by the specified
|
|
|
|
* makefile, if it was (makefile != (char *) NULL), or the default
|
|
|
|
* Makefile and makefile, in that order, if it wasn't.
|
|
|
|
*/
|
|
|
|
if (!noBuiltins) {
|
|
|
|
LstNode ln;
|
|
|
|
|
|
|
|
sysMkPath = Lst_Init (FALSE);
|
2001-10-31 04:15:57 +03:00
|
|
|
Dir_Expand(_PATH_DEFSYSMK,
|
|
|
|
Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath,
|
|
|
|
sysMkPath);
|
1996-03-06 03:15:17 +03:00
|
|
|
if (Lst_IsEmpty(sysMkPath))
|
2001-01-10 18:54:00 +03:00
|
|
|
Fatal("%s: no system rules (%s).", progname,
|
|
|
|
_PATH_DEFSYSMK);
|
1996-03-06 03:15:17 +03:00
|
|
|
ln = Lst_Find(sysMkPath, (ClientData)NULL, ReadMakefile);
|
|
|
|
if (ln != NILLNODE)
|
2001-01-10 18:54:00 +03:00
|
|
|
Fatal("%s: cannot open %s.", progname,
|
|
|
|
(char *)Lst_Datum(ln));
|
1996-03-06 03:15:17 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (!Lst_IsEmpty(makefiles)) {
|
|
|
|
LstNode ln;
|
|
|
|
|
|
|
|
ln = Lst_Find(makefiles, (ClientData)NULL, ReadMakefile);
|
|
|
|
if (ln != NILLNODE)
|
2001-01-10 18:54:00 +03:00
|
|
|
Fatal("%s: cannot open %s.", progname,
|
|
|
|
(char *)Lst_Datum(ln));
|
1996-11-06 20:58:58 +03:00
|
|
|
} else if (!ReadMakefile("makefile", NULL))
|
|
|
|
(void)ReadMakefile("Makefile", NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
(void)ReadMakefile(".depend", NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-07 02:45:17 +04:00
|
|
|
Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
|
|
|
|
if (p1)
|
|
|
|
free(p1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-12-30 05:05:20 +03:00
|
|
|
if (!jobServer && !compatMake)
|
|
|
|
Job_ServerStart(maxJobs);
|
|
|
|
if (DEBUG(JOB))
|
|
|
|
printf("job_pipe %d %d, maxjobs %d maxlocal %d compat %d\n", job_pipe[0], job_pipe[1], maxJobs,
|
|
|
|
maxLocal, compatMake);
|
|
|
|
|
2001-10-31 04:15:57 +03:00
|
|
|
Main_ExportMAKEFLAGS(TRUE); /* initial export */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-04-20 15:23:25 +04:00
|
|
|
Check_Cwd_av(0, NULL, 0); /* initialize it */
|
|
|
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* For compatibility, look at the directories in the VPATH variable
|
|
|
|
* and add them to the search path, if the variable is defined. The
|
|
|
|
* variable's value is in the same format as the PATH envariable, i.e.
|
|
|
|
* <directory>:<directory>:<directory>...
|
|
|
|
*/
|
|
|
|
if (Var_Exists("VPATH", VAR_CMD)) {
|
|
|
|
char *vpath, *path, *cp, savec;
|
|
|
|
/*
|
|
|
|
* GCC stores string constants in read-only memory, but
|
|
|
|
* Var_Subst will want to write this thing, so store it
|
|
|
|
* in an array
|
|
|
|
*/
|
|
|
|
static char VPATH[] = "${VPATH}";
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
vpath = Var_Subst(NULL, VPATH, VAR_CMD, FALSE);
|
1993-03-21 12:45:37 +03:00
|
|
|
path = vpath;
|
|
|
|
do {
|
|
|
|
/* skip to end of directory */
|
1994-03-05 03:34:29 +03:00
|
|
|
for (cp = path; *cp != ':' && *cp != '\0'; cp++)
|
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
/* Save terminator character so know when to stop */
|
|
|
|
savec = *cp;
|
|
|
|
*cp = '\0';
|
|
|
|
/* Add directory to search path */
|
1997-05-09 01:24:41 +04:00
|
|
|
(void) Dir_AddDir(dirSearchPath, path);
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = savec;
|
|
|
|
path = cp + 1;
|
|
|
|
} while (savec == ':');
|
|
|
|
(void)free((Address)vpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that all search paths have been read for suffixes et al, it's
|
|
|
|
* time to add the default search path to their lists...
|
|
|
|
*/
|
|
|
|
Suff_DoPaths();
|
|
|
|
|
1999-09-15 14:47:37 +04:00
|
|
|
/*
|
|
|
|
* Propagate attributes through :: dependency lists.
|
|
|
|
*/
|
|
|
|
Targ_Propagate();
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* print the initial graph, if the user requested it */
|
|
|
|
if (DEBUG(GRAPH1))
|
|
|
|
Targ_PrintGraph(1);
|
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
/* print the values of any variables requested by the user */
|
|
|
|
if (printVars) {
|
|
|
|
LstNode ln;
|
|
|
|
|
|
|
|
for (ln = Lst_First(variables); ln != NILLNODE;
|
|
|
|
ln = Lst_Succ(ln)) {
|
|
|
|
char *value = Var_Value((char *)Lst_Datum(ln),
|
|
|
|
VAR_GLOBAL, &p1);
|
|
|
|
|
|
|
|
printf("%s\n", value ? value : "");
|
|
|
|
if (p1)
|
|
|
|
free(p1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Have now read the entire graph and need to make a list of targets
|
|
|
|
* to create. If none was given on the command line, we consult the
|
|
|
|
* parsing module to find the main target(s) to create.
|
|
|
|
*/
|
|
|
|
if (Lst_IsEmpty(create))
|
|
|
|
targs = Parse_MainName();
|
|
|
|
else
|
|
|
|
targs = Targ_FindList(create, TARG_CREATE);
|
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
if (!compatMake && !printVars) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Initialize job module before traversing the graph, now that
|
|
|
|
* any .BEGIN and .END targets have been read. This is done
|
|
|
|
* only if the -q flag wasn't given (to prevent the .BEGIN from
|
|
|
|
* being executed should it exist).
|
|
|
|
*/
|
|
|
|
if (!queryFlag) {
|
|
|
|
if (maxLocal == -1)
|
|
|
|
maxLocal = maxJobs;
|
|
|
|
Job_Init(maxJobs, maxLocal);
|
|
|
|
jobsRunning = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Traverse the graph, checking on all the targets */
|
|
|
|
outOfDate = Make_Run(targs);
|
1996-11-06 20:58:58 +03:00
|
|
|
} else if (!printVars) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Compat_Init will take care of creating all the targets as
|
|
|
|
* well as initializing the module.
|
|
|
|
*/
|
|
|
|
Compat_Run(targs);
|
1996-11-06 20:58:58 +03:00
|
|
|
}
|
|
|
|
|
1999-09-15 12:48:17 +04:00
|
|
|
#ifdef CLEANUP
|
1994-06-07 02:45:17 +04:00
|
|
|
Lst_Destroy(targs, NOFREE);
|
1996-11-06 20:58:58 +03:00
|
|
|
Lst_Destroy(variables, NOFREE);
|
1994-06-07 02:45:17 +04:00
|
|
|
Lst_Destroy(makefiles, NOFREE);
|
|
|
|
Lst_Destroy(create, (void (*) __P((ClientData))) free);
|
1999-09-15 12:48:17 +04:00
|
|
|
#endif
|
1994-06-07 02:45:17 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* print the graph now it's been processed if the user requested it */
|
|
|
|
if (DEBUG(GRAPH2))
|
|
|
|
Targ_PrintGraph(2);
|
|
|
|
|
2000-12-30 05:05:20 +03:00
|
|
|
Trace_Log(MAKEEND, 0);
|
|
|
|
|
1994-06-07 02:45:17 +04:00
|
|
|
Suff_End();
|
|
|
|
Targ_End();
|
|
|
|
Arch_End();
|
|
|
|
Var_End();
|
|
|
|
Parse_End();
|
|
|
|
Dir_End();
|
1998-03-26 22:20:36 +03:00
|
|
|
Job_End();
|
2000-12-30 05:05:20 +03:00
|
|
|
Trace_End();
|
1994-06-07 02:45:17 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (queryFlag && outOfDate)
|
1994-03-05 03:34:29 +03:00
|
|
|
return(1);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1994-03-05 03:34:29 +03:00
|
|
|
return(0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* ReadMakefile --
|
|
|
|
* Open and parse the given makefile.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* TRUE if ok. FALSE if couldn't open file.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* lots
|
|
|
|
*/
|
|
|
|
static Boolean
|
1996-11-06 20:58:58 +03:00
|
|
|
ReadMakefile(p, q)
|
|
|
|
ClientData p, q;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1996-11-06 20:58:58 +03:00
|
|
|
char *fname = p; /* makefile to read */
|
1993-03-21 12:45:37 +03:00
|
|
|
FILE *stream;
|
1999-09-04 08:21:28 +04:00
|
|
|
size_t len = MAXPATHLEN;
|
|
|
|
char *name, *path = emalloc(len);
|
2001-06-02 00:33:37 +04:00
|
|
|
int setMAKEFILE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (!strcmp(fname, "-")) {
|
|
|
|
Parse_File("(stdin)", stdin);
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set("MAKEFILE", "", VAR_GLOBAL, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
2001-06-02 00:33:37 +04:00
|
|
|
setMAKEFILE = strcmp(fname, ".depend");
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* if we've chdir'd, rebuild the path name */
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
if (strcmp(curdir, objdir) && *fname != '/') {
|
1999-09-04 08:21:28 +04:00
|
|
|
size_t plen = strlen(curdir) + strlen(fname) + 2;
|
|
|
|
if (len < plen)
|
|
|
|
path = erealloc(path, len = 2 * plen);
|
|
|
|
|
|
|
|
(void)snprintf(path, len, "%s/%s", curdir, fname);
|
1994-03-05 03:34:29 +03:00
|
|
|
if ((stream = fopen(path, "r")) != NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
fname = path;
|
|
|
|
goto found;
|
|
|
|
}
|
2001-01-07 09:16:02 +03:00
|
|
|
} else if ((stream = fopen(fname, "r")) != NULL)
|
|
|
|
goto found;
|
1993-03-21 12:45:37 +03:00
|
|
|
/* look in -I and system include directories. */
|
|
|
|
name = Dir_FindFile(fname, parseIncPath);
|
|
|
|
if (!name)
|
2001-10-31 04:15:57 +03:00
|
|
|
name = Dir_FindFile(fname,
|
|
|
|
Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
|
1999-09-04 08:21:28 +04:00
|
|
|
if (!name || !(stream = fopen(name, "r"))) {
|
|
|
|
free(path);
|
1993-03-21 12:45:37 +03:00
|
|
|
return(FALSE);
|
1999-09-04 08:21:28 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
fname = name;
|
|
|
|
/*
|
|
|
|
* set the MAKEFILE variable desired by System V fans -- the
|
|
|
|
* placement of the setting here means it gets set to the last
|
|
|
|
* makefile specified, as it is set by SysV make.
|
|
|
|
*/
|
2001-06-02 00:33:37 +04:00
|
|
|
found:
|
|
|
|
if (setMAKEFILE)
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set("MAKEFILE", fname, VAR_GLOBAL, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
Parse_File(fname, stream);
|
|
|
|
(void)fclose(stream);
|
|
|
|
}
|
1999-09-04 08:21:28 +04:00
|
|
|
free(path);
|
1993-03-21 12:45:37 +03:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2000-04-20 15:23:25 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If MAKEOBJDIRPREFIX is in use, make ends up not in .CURDIR
|
|
|
|
* in situations that would not arrise with ./obj (links or not).
|
|
|
|
* This tends to break things like:
|
|
|
|
*
|
|
|
|
* build:
|
|
|
|
* ${MAKE} includes
|
|
|
|
*
|
|
|
|
* This function spots when ${.MAKE:T} or ${.MAKE} is a command (as
|
|
|
|
* opposed to an argument) in a command line and if so returns
|
|
|
|
* ${.CURDIR} so caller can chdir() so that the assumptions made by
|
|
|
|
* the Makefile hold true.
|
|
|
|
*
|
|
|
|
* If ${.MAKE} does not contain any '/', then ${.MAKE:T} is skipped.
|
|
|
|
*
|
|
|
|
* The chdir() only happens in the child process, and does nothing if
|
|
|
|
* MAKEOBJDIRPREFIX and MAKEOBJDIR are not in the environment so it
|
|
|
|
* should not break anything. Also if NOCHECKMAKECHDIR is set we
|
|
|
|
* do nothing - to ensure historic semantics can be retained.
|
|
|
|
*/
|
|
|
|
static int Check_Cwd_Off = 0;
|
|
|
|
|
|
|
|
static char *
|
|
|
|
Check_Cwd_av(ac, av, copy)
|
|
|
|
int ac;
|
|
|
|
char **av;
|
|
|
|
int copy;
|
|
|
|
{
|
|
|
|
static char *make[4];
|
|
|
|
static char *curdir = NULL;
|
|
|
|
char *cp, **mp;
|
|
|
|
int is_cmd, next_cmd;
|
|
|
|
int i;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (Check_Cwd_Off)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (make[0] == NULL) {
|
|
|
|
if (Var_Exists("NOCHECKMAKECHDIR", VAR_GLOBAL)) {
|
|
|
|
Check_Cwd_Off = 1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
make[1] = Var_Value(".MAKE", VAR_GLOBAL, &cp);
|
|
|
|
if ((make[0] = strrchr(make[1], '/')) == NULL) {
|
|
|
|
make[0] = make[1];
|
|
|
|
make[1] = NULL;
|
|
|
|
} else
|
|
|
|
++make[0];
|
|
|
|
make[2] = NULL;
|
|
|
|
curdir = Var_Value(".CURDIR", VAR_GLOBAL, &cp);
|
|
|
|
}
|
|
|
|
if (ac == 0 || av == NULL)
|
|
|
|
return NULL; /* initialization only */
|
|
|
|
|
|
|
|
if (getenv("MAKEOBJDIR") == NULL &&
|
|
|
|
getenv("MAKEOBJDIRPREFIX") == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
next_cmd = 1;
|
|
|
|
for (i = 0; i < ac; ++i) {
|
|
|
|
is_cmd = next_cmd;
|
|
|
|
|
|
|
|
n = strlen(av[i]);
|
|
|
|
cp = &(av[i])[n - 1];
|
|
|
|
if (strspn(av[i], "|&;") == n) {
|
|
|
|
next_cmd = 1;
|
|
|
|
continue;
|
|
|
|
} else if (*cp == ';' || *cp == '&' || *cp == '|' || *cp == ')') {
|
|
|
|
next_cmd = 1;
|
|
|
|
if (copy) {
|
|
|
|
do {
|
|
|
|
*cp-- = '\0';
|
|
|
|
} while (*cp == ';' || *cp == '&' || *cp == '|' ||
|
|
|
|
*cp == ')' || *cp == '}') ;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* XXX this should not happen.
|
|
|
|
*/
|
|
|
|
fprintf(stderr, "WARNING: raw arg ends in shell meta '%s'\n",
|
|
|
|
av[i]);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
next_cmd = 0;
|
|
|
|
|
|
|
|
cp = av[i];
|
|
|
|
if (*cp == ';' || *cp == '&' || *cp == '|')
|
|
|
|
is_cmd = 1;
|
|
|
|
|
|
|
|
#ifdef check_cwd_debug
|
|
|
|
fprintf(stderr, "av[%d] == %s '%s'",
|
|
|
|
i, (is_cmd) ? "cmd" : "arg", av[i]);
|
|
|
|
#endif
|
|
|
|
if (is_cmd != 0) {
|
2000-06-06 07:00:11 +04:00
|
|
|
if (*cp == '(' || *cp == '{' ||
|
|
|
|
*cp == ';' || *cp == '&' || *cp == '|') {
|
|
|
|
do {
|
|
|
|
++cp;
|
|
|
|
} while (*cp == '(' || *cp == '{' ||
|
|
|
|
*cp == ';' || *cp == '&' || *cp == '|');
|
|
|
|
if (*cp == '\0') {
|
|
|
|
next_cmd = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2000-04-20 15:23:25 +04:00
|
|
|
if (strcmp(cp, "cd") == 0 || strcmp(cp, "chdir") == 0) {
|
|
|
|
#ifdef check_cwd_debug
|
|
|
|
fprintf(stderr, " == cd, done.\n");
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (mp = make; *mp != NULL; ++mp) {
|
|
|
|
n = strlen(*mp);
|
|
|
|
if (strcmp(cp, *mp) == 0) {
|
|
|
|
#ifdef check_cwd_debug
|
|
|
|
fprintf(stderr, " %s == '%s', chdir(%s)\n",
|
|
|
|
cp, *mp, curdir);
|
|
|
|
#endif
|
|
|
|
return curdir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef check_cwd_debug
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
Check_Cwd_Cmd(cmd)
|
|
|
|
char *cmd;
|
|
|
|
{
|
|
|
|
char *cp, *bp, **av;
|
|
|
|
int ac;
|
|
|
|
|
|
|
|
if (Check_Cwd_Off)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (cmd) {
|
|
|
|
av = brk_string(cmd, &ac, TRUE, &bp);
|
|
|
|
#ifdef check_cwd_debug
|
|
|
|
fprintf(stderr, "splitting: '%s' -> %d words\n",
|
|
|
|
cmd, ac);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
ac = 0;
|
|
|
|
av = NULL;
|
|
|
|
bp = NULL;
|
|
|
|
}
|
|
|
|
cp = Check_Cwd_av(ac, av, 1);
|
|
|
|
if (bp) {
|
|
|
|
free(av);
|
|
|
|
free(bp);
|
|
|
|
}
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Check_Cwd(argv)
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
int ac;
|
|
|
|
|
|
|
|
if (Check_Cwd_Off)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (ac = 0; argv[ac] != NULL; ++ac)
|
|
|
|
/* NOTHING */;
|
|
|
|
if (ac == 3 && *argv[1] == '-') {
|
|
|
|
cp = Check_Cwd_Cmd(argv[2]);
|
|
|
|
} else {
|
|
|
|
cp = Check_Cwd_av(ac, argv, 0);
|
|
|
|
}
|
|
|
|
if (cp) {
|
|
|
|
chdir(cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-29 03:34:35 +04:00
|
|
|
/*-
|
|
|
|
* Cmd_Exec --
|
|
|
|
* Execute the command in cmd, and return the output of that command
|
|
|
|
* in a string.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* A string containing the output of the command, or the empty string
|
|
|
|
* If err is not NULL, it contains the reason for the command failure
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The string must be freed by the caller.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
Cmd_Exec(cmd, err)
|
|
|
|
char *cmd;
|
|
|
|
char **err;
|
|
|
|
{
|
|
|
|
char *args[4]; /* Args for invoking the shell */
|
|
|
|
int fds[2]; /* Pipe streams */
|
|
|
|
int cpid; /* Child PID */
|
|
|
|
int pid; /* PID from wait() */
|
|
|
|
char *res; /* result */
|
|
|
|
int status; /* command exit status */
|
|
|
|
Buffer buf; /* buffer to store the result */
|
|
|
|
char *cp;
|
|
|
|
int cc;
|
|
|
|
|
|
|
|
|
|
|
|
*err = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up arguments for shell
|
|
|
|
*/
|
|
|
|
args[0] = "sh";
|
|
|
|
args[1] = "-c";
|
|
|
|
args[2] = cmd;
|
|
|
|
args[3] = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open a pipe for fetching its output
|
|
|
|
*/
|
|
|
|
if (pipe(fds) == -1) {
|
|
|
|
*err = "Couldn't create pipe for \"%s\"";
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fork
|
|
|
|
*/
|
|
|
|
switch (cpid = vfork()) {
|
|
|
|
case 0:
|
|
|
|
/*
|
|
|
|
* Close input side of pipe
|
|
|
|
*/
|
|
|
|
(void) close(fds[0]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Duplicate the output stream to the shell's output, then
|
|
|
|
* shut the extra thing down. Note we don't fetch the error
|
|
|
|
* stream...why not? Why?
|
|
|
|
*/
|
|
|
|
(void) dup2(fds[1], 1);
|
|
|
|
(void) close(fds[1]);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1996-05-29 03:34:35 +04:00
|
|
|
(void) execv("/bin/sh", args);
|
|
|
|
_exit(1);
|
|
|
|
/*NOTREACHED*/
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
*err = "Couldn't exec \"%s\"";
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* No need for the writing half
|
|
|
|
*/
|
|
|
|
(void) close(fds[1]);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1996-05-29 03:34:35 +04:00
|
|
|
buf = Buf_Init (MAKE_BSIZE);
|
|
|
|
|
|
|
|
do {
|
|
|
|
char result[BUFSIZ];
|
|
|
|
cc = read(fds[0], result, sizeof(result));
|
1996-11-06 20:58:58 +03:00
|
|
|
if (cc > 0)
|
1996-05-29 03:34:35 +04:00
|
|
|
Buf_AddBytes(buf, cc, (Byte *) result);
|
|
|
|
}
|
|
|
|
while (cc > 0 || (cc == -1 && errno == EINTR));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close the input side of the pipe.
|
|
|
|
*/
|
|
|
|
(void) close(fds[0]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the process to exit.
|
|
|
|
*/
|
|
|
|
while(((pid = wait(&status)) != cpid) && (pid >= 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
res = (char *)Buf_GetAll (buf, &cc);
|
|
|
|
Buf_Destroy (buf, FALSE);
|
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
if (cc == 0)
|
1996-05-29 03:34:35 +04:00
|
|
|
*err = "Couldn't read shell's output for \"%s\"";
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
*err = "\"%s\" returned non-zero status";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Null-terminate the result, convert newlines to spaces and
|
|
|
|
* install it in the variable.
|
|
|
|
*/
|
|
|
|
res[cc] = '\0';
|
1998-11-01 06:01:53 +03:00
|
|
|
cp = &res[cc];
|
1996-05-29 03:34:35 +04:00
|
|
|
|
1998-11-01 06:01:53 +03:00
|
|
|
if (cc > 0 && *--cp == '\n') {
|
1996-05-29 03:34:35 +04:00
|
|
|
/*
|
|
|
|
* A final newline is just stripped
|
|
|
|
*/
|
|
|
|
*cp-- = '\0';
|
|
|
|
}
|
|
|
|
while (cp >= res) {
|
|
|
|
if (*cp == '\n') {
|
|
|
|
*cp = ' ';
|
|
|
|
}
|
|
|
|
cp--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
bad:
|
|
|
|
res = emalloc(1);
|
|
|
|
*res = '\0';
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
|
|
|
* Error --
|
|
|
|
* Print an error message given its format.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The message is printed.
|
|
|
|
*/
|
|
|
|
/* VARARGS */
|
|
|
|
void
|
1996-12-31 20:54:16 +03:00
|
|
|
#ifdef __STDC__
|
1994-03-05 03:34:29 +03:00
|
|
|
Error(char *fmt, ...)
|
|
|
|
#else
|
1993-03-21 12:45:37 +03:00
|
|
|
Error(va_alist)
|
|
|
|
va_dcl
|
1994-03-05 03:34:29 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
1996-12-31 20:54:16 +03:00
|
|
|
#ifdef __STDC__
|
1994-03-05 03:34:29 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
#else
|
1993-03-21 12:45:37 +03:00
|
|
|
char *fmt;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
fmt = va_arg(ap, char *);
|
1994-03-05 03:34:29 +03:00
|
|
|
#endif
|
2000-04-17 03:24:23 +04:00
|
|
|
fprintf(stderr, "%s: ", progname);
|
1993-03-21 12:45:37 +03:00
|
|
|
(void)vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
(void)fprintf(stderr, "\n");
|
|
|
|
(void)fflush(stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Fatal --
|
|
|
|
* Produce a Fatal error message. If jobs are running, waits for them
|
|
|
|
* to finish.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The program exits
|
|
|
|
*/
|
|
|
|
/* VARARGS */
|
|
|
|
void
|
1996-12-31 20:54:16 +03:00
|
|
|
#ifdef __STDC__
|
1994-03-05 03:34:29 +03:00
|
|
|
Fatal(char *fmt, ...)
|
|
|
|
#else
|
1993-03-21 12:45:37 +03:00
|
|
|
Fatal(va_alist)
|
|
|
|
va_dcl
|
1994-03-05 03:34:29 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
1996-12-31 20:54:16 +03:00
|
|
|
#ifdef __STDC__
|
1994-03-05 03:34:29 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
#else
|
1993-03-21 12:45:37 +03:00
|
|
|
char *fmt;
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
va_start(ap);
|
|
|
|
fmt = va_arg(ap, char *);
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
if (jobsRunning)
|
|
|
|
Job_Wait();
|
2000-12-30 17:21:22 +03:00
|
|
|
Job_TokenFlush();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
(void)vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
(void)fprintf(stderr, "\n");
|
|
|
|
(void)fflush(stderr);
|
|
|
|
|
2001-06-02 00:33:37 +04:00
|
|
|
PrintOnError(NULL);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (DEBUG(GRAPH2))
|
|
|
|
Targ_PrintGraph(2);
|
2000-12-30 05:05:20 +03:00
|
|
|
Trace_Log(MAKEERROR, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(2); /* Not 1 so -q can distinguish error */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Punt --
|
|
|
|
* Major exception once jobs are being created. Kills all jobs, prints
|
|
|
|
* a message and exits.
|
|
|
|
*
|
|
|
|
* Results:
|
1996-11-06 20:58:58 +03:00
|
|
|
* None
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* All children are killed indiscriminately and the program Lib_Exits
|
|
|
|
*/
|
|
|
|
/* VARARGS */
|
|
|
|
void
|
1996-12-31 20:54:16 +03:00
|
|
|
#ifdef __STDC__
|
1994-03-05 03:34:29 +03:00
|
|
|
Punt(char *fmt, ...)
|
|
|
|
#else
|
1993-03-21 12:45:37 +03:00
|
|
|
Punt(va_alist)
|
|
|
|
va_dcl
|
1994-03-05 03:34:29 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
1996-12-31 20:54:16 +03:00
|
|
|
#ifdef __STDC__
|
1994-03-05 03:34:29 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
#else
|
1993-03-21 12:45:37 +03:00
|
|
|
char *fmt;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
fmt = va_arg(ap, char *);
|
1994-03-05 03:34:29 +03:00
|
|
|
#endif
|
|
|
|
|
2001-01-10 18:54:00 +03:00
|
|
|
(void)fprintf(stderr, "%s: ", progname);
|
1993-03-21 12:45:37 +03:00
|
|
|
(void)vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
(void)fprintf(stderr, "\n");
|
|
|
|
(void)fflush(stderr);
|
|
|
|
|
2001-06-02 00:33:37 +04:00
|
|
|
PrintOnError(NULL);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
DieHorribly();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* DieHorribly --
|
|
|
|
* Exit without giving a message.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* A big one...
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
DieHorribly()
|
|
|
|
{
|
|
|
|
if (jobsRunning)
|
|
|
|
Job_AbortAll();
|
|
|
|
if (DEBUG(GRAPH2))
|
|
|
|
Targ_PrintGraph(2);
|
2000-12-30 05:05:20 +03:00
|
|
|
Trace_Log(MAKEERROR, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(2); /* Not 1, so -q can distinguish error */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish --
|
|
|
|
* Called when aborting due to errors in child shell to signal
|
1996-11-06 20:58:58 +03:00
|
|
|
* abnormal exit.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Results:
|
1996-11-06 20:58:58 +03:00
|
|
|
* None
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The program exits
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Finish(errors)
|
|
|
|
int errors; /* number of errors encountered in Make_Make */
|
|
|
|
{
|
|
|
|
Fatal("%d error%s", errors, errors == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* emalloc --
|
|
|
|
* malloc, but die on error.
|
|
|
|
*/
|
1996-04-01 01:30:05 +04:00
|
|
|
void *
|
1993-03-21 12:45:37 +03:00
|
|
|
emalloc(len)
|
1994-06-07 02:45:17 +04:00
|
|
|
size_t len;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1996-04-01 01:30:05 +04:00
|
|
|
void *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-04-01 01:30:05 +04:00
|
|
|
if ((p = malloc(len)) == NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
enomem();
|
|
|
|
return(p);
|
|
|
|
}
|
|
|
|
|
1996-08-13 20:42:00 +04:00
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
* estrdup --
|
1996-08-13 20:42:00 +04:00
|
|
|
* strdup, but die on error.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
estrdup(str)
|
|
|
|
const char *str;
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if ((p = strdup(str)) == NULL)
|
|
|
|
enomem();
|
|
|
|
return(p);
|
|
|
|
}
|
|
|
|
|
1996-03-29 05:17:13 +03:00
|
|
|
/*
|
|
|
|
* erealloc --
|
|
|
|
* realloc, but die on error.
|
|
|
|
*/
|
1996-04-01 01:30:05 +04:00
|
|
|
void *
|
1996-03-29 05:17:13 +03:00
|
|
|
erealloc(ptr, size)
|
1996-04-01 01:30:05 +04:00
|
|
|
void *ptr;
|
1996-03-29 05:17:13 +03:00
|
|
|
size_t size;
|
|
|
|
{
|
1996-04-01 01:30:05 +04:00
|
|
|
if ((ptr = realloc(ptr, size)) == NULL)
|
1996-03-29 05:17:13 +03:00
|
|
|
enomem();
|
1996-04-01 01:30:05 +04:00
|
|
|
return(ptr);
|
1996-03-29 05:17:13 +03:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* enomem --
|
|
|
|
* die when out of memory.
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
enomem()
|
|
|
|
{
|
2001-01-10 18:54:00 +03:00
|
|
|
(void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
/*
|
|
|
|
* enunlink --
|
|
|
|
* Remove a file carefully, avoiding directories.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
eunlink(file)
|
|
|
|
const char *file;
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (lstat(file, &st) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (S_ISDIR(st.st_mode)) {
|
|
|
|
errno = EISDIR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return unlink(file);
|
|
|
|
}
|
|
|
|
|
2001-05-29 21:37:51 +04:00
|
|
|
/*
|
|
|
|
* execError --
|
|
|
|
* Print why exec failed, avoiding stdio.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
execError(av)
|
|
|
|
const char *av;
|
|
|
|
{
|
|
|
|
#ifdef USE_IOVEC
|
|
|
|
int i = 0;
|
|
|
|
struct iovec iov[6];
|
|
|
|
#define IOADD(s) \
|
|
|
|
(void)(iov[i].iov_base = (s), \
|
|
|
|
iov[i].iov_len = strlen(iov[i].iov_base), \
|
|
|
|
i++)
|
|
|
|
#else
|
|
|
|
#define IOADD (void)write(2, s, strlen(s))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
IOADD(progname);
|
|
|
|
IOADD(": Exec of `");
|
|
|
|
IOADD((char *)av);
|
|
|
|
IOADD("' failed (");
|
|
|
|
IOADD(strerror(errno));
|
|
|
|
IOADD(")\n");
|
|
|
|
|
|
|
|
#ifdef USE_IOVEC
|
|
|
|
(void)writev(2, iov, 6);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* usage --
|
|
|
|
* exit with usage message
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
static void
|
1993-03-21 12:45:37 +03:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
(void)fprintf(stderr,
|
2001-05-29 21:37:51 +04:00
|
|
|
"Usage: %s [-Beiknqrst] [-D variable] [-d flags] [-f makefile ]\n\
|
1996-11-06 20:58:58 +03:00
|
|
|
[-I directory] [-j max_jobs] [-m directory] [-V variable]\n\
|
2001-05-29 21:37:51 +04:00
|
|
|
[variable=value] [target ...]\n", progname);
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(2);
|
|
|
|
}
|
1994-06-07 02:45:17 +04:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
PrintAddr(a, b)
|
|
|
|
ClientData a;
|
|
|
|
ClientData b;
|
|
|
|
{
|
|
|
|
printf("%lx ", (unsigned long) a);
|
|
|
|
return b ? 0 : 0;
|
|
|
|
}
|
2001-06-02 00:33:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintOnError(s)
|
|
|
|
char *s;
|
|
|
|
{
|
|
|
|
char tmp[64];
|
|
|
|
|
|
|
|
if (s)
|
|
|
|
printf("%s", s);
|
|
|
|
|
|
|
|
printf("\n%s: stopped in %s\n", progname, curdir);
|
|
|
|
strncpy(tmp, "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}",
|
|
|
|
sizeof(tmp) - 1);
|
|
|
|
s = Var_Subst(NULL, tmp, VAR_GLOBAL, 0);
|
|
|
|
if (s && *s)
|
|
|
|
printf("%s", s);
|
|
|
|
}
|
2001-06-09 09:22:47 +04:00
|
|
|
|
|
|
|
void
|
2001-10-31 04:15:57 +03:00
|
|
|
Main_ExportMAKEFLAGS(first)
|
|
|
|
Boolean first;
|
2001-06-09 09:22:47 +04:00
|
|
|
{
|
|
|
|
static int once = 1;
|
|
|
|
char tmp[64];
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (once != first)
|
|
|
|
return;
|
|
|
|
once = 0;
|
|
|
|
|
2001-06-10 06:31:00 +04:00
|
|
|
strncpy(tmp, "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}",
|
|
|
|
sizeof(tmp));
|
|
|
|
s = Var_Subst(NULL, tmp, VAR_CMD, 0);
|
2001-06-09 09:22:47 +04:00
|
|
|
if (s && *s) {
|
|
|
|
#ifdef POSIX
|
|
|
|
setenv("MAKEFLAGS", s, 1);
|
|
|
|
#else
|
|
|
|
setenv("MAKE", s, 1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|