1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988, 1989, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* 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.
|
2000-07-09 02:54:54 +00:00
|
|
|
*
|
|
|
|
* @(#)main.c 8.3 (Berkeley) 3/19/94
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
|
2002-04-13 10:17:18 +00:00
|
|
|
#ifndef lint
|
2002-04-13 12:20:51 +00:00
|
|
|
#if 0
|
2002-04-13 10:57:56 +00:00
|
|
|
static char copyright[] =
|
|
|
|
"@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
2002-04-13 12:20:51 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
2002-04-13 10:57:56 +00:00
|
|
|
#include <sys/cdefs.h>
|
2002-04-13 10:17:18 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/stat.h>
|
1998-09-09 14:58:30 +00:00
|
|
|
#if defined(__i386__)
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
1996-10-06 02:35:38 +00:00
|
|
|
#ifndef MACHINE
|
1995-01-23 21:03:17 +00:00
|
|
|
#include <sys/utsname.h>
|
1996-10-06 02:35:38 +00:00
|
|
|
#endif
|
|
|
|
#include <sys/wait.h>
|
1997-07-24 06:58:08 +00:00
|
|
|
#include <err.h>
|
1997-09-29 03:53:53 +00:00
|
|
|
#include <stdlib.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
1999-07-31 20:40:23 +00:00
|
|
|
#include <sysexits.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <stdarg.h>
|
2000-07-28 06:50:25 +00:00
|
|
|
#include <unistd.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include "make.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "job.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
2002-10-03 04:32:47 +00:00
|
|
|
#define WANT_ENV_MKLVL 1
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#ifndef DEFMAXLOCAL
|
|
|
|
#define DEFMAXLOCAL DEFMAXJOBS
|
1996-10-06 02:35:38 +00:00
|
|
|
#endif /* DEFMAXLOCAL */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#define MAKEFLAGS ".MAKEFLAGS"
|
|
|
|
|
|
|
|
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 */
|
2000-09-25 18:44:30 +00:00
|
|
|
static Boolean expandVars; /* fully expand printed variables */
|
1996-07-17 11:02:43 +00:00
|
|
|
static Lst variables; /* list of variables to print */
|
1996-10-06 02:35:38 +00:00
|
|
|
int maxJobs; /* -j argument */
|
1997-08-14 19:24:11 +00:00
|
|
|
static Boolean forceJobs; /* -j argument given */
|
1994-05-27 12:33:43 +00:00
|
|
|
static int maxLocal; /* -L argument */
|
|
|
|
Boolean compatMake; /* -B argument */
|
|
|
|
Boolean debug; /* -d flag */
|
|
|
|
Boolean noExecute; /* -n flag */
|
|
|
|
Boolean keepgoing; /* -k flag */
|
|
|
|
Boolean queryFlag; /* -q flag */
|
|
|
|
Boolean touchFlag; /* -t flag */
|
|
|
|
Boolean usePipes; /* !-P flag */
|
|
|
|
Boolean ignoreErrors; /* -i flag */
|
|
|
|
Boolean beSilent; /* -s flag */
|
1998-11-14 16:15:04 +00:00
|
|
|
Boolean beVerbose; /* -v flag */
|
1994-05-27 12:33:43 +00:00
|
|
|
Boolean oldVars; /* variable substitution style */
|
|
|
|
Boolean checkEnvFirst; /* -e flag */
|
1999-07-31 20:53:02 +00:00
|
|
|
Lst envFirstVars; /* (-E) vars to override from env */
|
2002-10-10 19:27:48 +00:00
|
|
|
Boolean jobsRunning; /* TRUE if the jobs might be running */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-03-22 01:33:25 +00:00
|
|
|
static void MainParseArgs(int, char **);
|
|
|
|
char * chdir_verify_path(char *, char *);
|
|
|
|
static int ReadMakefile(void *, void *);
|
|
|
|
static void usage(void);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
static char *curdir; /* startup directory */
|
|
|
|
static char *objdir; /* where we chdir'ed to */
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* 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
|
2002-10-09 03:42:10 +00:00
|
|
|
MainParseArgs(int argc, char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1998-06-13 11:55:57 +00:00
|
|
|
char *p;
|
1995-01-23 21:03:17 +00:00
|
|
|
int c;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
optind = 1; /* since we're called more than once */
|
1996-10-06 02:35:38 +00:00
|
|
|
#ifdef REMOTE
|
2002-08-25 02:45:04 +00:00
|
|
|
# define OPTFLAGS "BC:D:E:I:L:PSV:Xd:ef:ij:km:nqrstv"
|
1994-05-27 12:33:43 +00:00
|
|
|
#else
|
2002-08-25 02:45:04 +00:00
|
|
|
# define OPTFLAGS "BC:D:E:I:PSV:Xd:ef:ij:km:nqrstv"
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif
|
1997-03-29 04:34:07 +00:00
|
|
|
rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
|
1994-05-27 12:33:43 +00:00
|
|
|
switch(c) {
|
2002-08-25 02:45:04 +00:00
|
|
|
case 'C':
|
2002-12-17 04:26:22 +00:00
|
|
|
if (chdir(optarg) == -1)
|
|
|
|
err(1, "chdir %s", optarg);
|
2002-08-25 02:45:04 +00:00
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'D':
|
|
|
|
Var_Set(optarg, "1", VAR_GLOBAL);
|
|
|
|
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;
|
1996-07-17 11:02:43 +00:00
|
|
|
case 'V':
|
2000-12-02 20:24:42 +00:00
|
|
|
(void)Lst_AtEnd(variables, (void *)optarg);
|
1996-07-17 11:02:43 +00:00
|
|
|
Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
2000-09-25 18:44:30 +00:00
|
|
|
case 'X':
|
|
|
|
expandVars = FALSE;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'B':
|
|
|
|
compatMake = TRUE;
|
1997-08-25 21:35:44 +00:00
|
|
|
Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
1996-10-06 02:35:38 +00:00
|
|
|
#ifdef REMOTE
|
1999-07-31 20:40:23 +00:00
|
|
|
case 'L': {
|
|
|
|
char *endptr;
|
|
|
|
|
|
|
|
maxLocal = strtol(optarg, &endptr, 10);
|
|
|
|
if (maxLocal < 0 || *endptr != '\0') {
|
1999-08-17 00:39:26 +00:00
|
|
|
warnx("illegal number, -L argument -- %s",
|
|
|
|
optarg);
|
|
|
|
usage();
|
1999-07-31 20:40:23 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
Var_Append(MAKEFLAGS, "-L", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
1999-07-31 20:40:23 +00:00
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'P':
|
|
|
|
usePipes = FALSE;
|
|
|
|
Var_Append(MAKEFLAGS, "-P", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
keepgoing = FALSE;
|
|
|
|
Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
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;
|
|
|
|
case 'f':
|
|
|
|
debug |= DEBUG_FOR;
|
|
|
|
break;
|
|
|
|
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;
|
2000-05-14 22:24:28 +00:00
|
|
|
case 'l':
|
|
|
|
debug |= DEBUG_LOUD;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'm':
|
|
|
|
debug |= DEBUG_MAKE;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
debug |= DEBUG_SUFF;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
debug |= DEBUG_TARG;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
debug |= DEBUG_VAR;
|
|
|
|
break;
|
|
|
|
default:
|
1997-07-24 06:58:08 +00:00
|
|
|
warnx("illegal argument to d option -- %c", *modules);
|
1994-05-27 12:33:43 +00:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
Var_Append(MAKEFLAGS, "-d", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
}
|
1999-07-31 20:53:02 +00:00
|
|
|
case 'E':
|
2002-04-12 13:23:33 +00:00
|
|
|
p = emalloc(strlen(optarg) + 1);
|
1999-07-31 20:53:02 +00:00
|
|
|
(void)strcpy(p, optarg);
|
2000-12-02 20:24:42 +00:00
|
|
|
(void)Lst_AtEnd(envFirstVars, (void *)p);
|
1999-07-31 20:53:02 +00:00
|
|
|
Var_Append(MAKEFLAGS, "-E", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'e':
|
|
|
|
checkEnvFirst = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
case 'f':
|
2000-12-02 20:24:42 +00:00
|
|
|
(void)Lst_AtEnd(makefiles, (void *)optarg);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
ignoreErrors = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL);
|
|
|
|
break;
|
1999-07-31 20:40:23 +00:00
|
|
|
case 'j': {
|
|
|
|
char *endptr;
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
forceJobs = TRUE;
|
1999-07-31 20:40:23 +00:00
|
|
|
maxJobs = strtol(optarg, &endptr, 10);
|
|
|
|
if (maxJobs <= 0 || *endptr != '\0') {
|
1999-08-17 00:39:26 +00:00
|
|
|
warnx("illegal number, -j argument -- %s",
|
|
|
|
optarg);
|
|
|
|
usage();
|
1999-07-31 20:40:23 +00:00
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
#ifndef REMOTE
|
|
|
|
maxLocal = maxJobs;
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
1999-07-31 20:40:23 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'k':
|
|
|
|
keepgoing = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-k", VAR_GLOBAL);
|
|
|
|
break;
|
1996-10-06 02:35:38 +00:00
|
|
|
case 'm':
|
|
|
|
Dir_AddDir(sysIncPath, optarg);
|
|
|
|
Var_Append(MAKEFLAGS, "-m", VAR_GLOBAL);
|
|
|
|
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
|
|
|
|
break;
|
1994-05-27 12:33:43 +00: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;
|
1998-11-14 16:15:04 +00:00
|
|
|
case 'v':
|
|
|
|
beVerbose = TRUE;
|
|
|
|
Var_Append(MAKEFLAGS, "-v", VAR_GLOBAL);
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
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)
|
|
|
|
if (Parse_IsVar(*argv))
|
|
|
|
Parse_DoVar(*argv, VAR_CMD);
|
|
|
|
else {
|
|
|
|
if (!**argv)
|
|
|
|
Punt("illegal (null) argument.");
|
|
|
|
if (**argv == '-') {
|
|
|
|
if ((*argv)[1])
|
|
|
|
optind = 0; /* -flag... */
|
|
|
|
else
|
|
|
|
optind = 1; /* - */
|
|
|
|
goto rearg;
|
|
|
|
}
|
2000-12-02 20:24:42 +00:00
|
|
|
(void)Lst_AtEnd(create, (void *)estrdup(*argv));
|
1994-05-27 12:33:43 +00: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
|
2002-10-09 03:42:10 +00:00
|
|
|
Main_ParseArgLine(char *line)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char **argv; /* Manufactured argument vector */
|
|
|
|
int argc; /* Number of arguments in argv */
|
|
|
|
|
|
|
|
if (line == NULL)
|
|
|
|
return;
|
|
|
|
for (; *line == ' '; ++line)
|
|
|
|
continue;
|
|
|
|
if (!*line)
|
|
|
|
return;
|
|
|
|
|
1995-01-23 21:03:17 +00:00
|
|
|
argv = brk_string(line, &argc, TRUE);
|
1994-05-27 12:33:43 +00:00
|
|
|
MainParseArgs(argc, argv);
|
|
|
|
}
|
|
|
|
|
1996-09-18 06:06:39 +00:00
|
|
|
char *
|
2002-10-09 03:42:10 +00:00
|
|
|
chdir_verify_path(char *path, char *obpath)
|
1996-09-18 06:06:39 +00:00
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
|
2001-04-25 14:22:38 +00:00
|
|
|
if (chdir(path) == -1 || getcwd(obpath, MAXPATHLEN) == NULL) {
|
1997-07-24 06:58:08 +00:00
|
|
|
warn("warning: %s", path);
|
1996-09-18 06:06:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-04-25 14:22:38 +00:00
|
|
|
return obpath;
|
1996-09-18 06:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-12-13 15:26:27 +00:00
|
|
|
void
|
|
|
|
catch_child(int sig)
|
|
|
|
{
|
|
|
|
}
|
1996-09-18 06:06:39 +00:00
|
|
|
|
1994-05-27 12:33:43 +00: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.
|
|
|
|
*/
|
|
|
|
int
|
2002-10-09 03:42:10 +00:00
|
|
|
main(int argc, char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
Lst targs; /* target nodes to create -- passed to Make_Init */
|
|
|
|
Boolean outOfDate = TRUE; /* FALSE if all targets up to date */
|
1998-10-18 00:51:46 +00:00
|
|
|
struct stat sa;
|
|
|
|
char *p, *p1, *path, *pathp;
|
2002-10-03 04:32:47 +00:00
|
|
|
#ifdef WANT_ENV_MKLVL
|
|
|
|
#define MKLVL_MAXVAL 500
|
|
|
|
#define MKLVL_ENVVAR "__MKLVL__"
|
|
|
|
int iMkLvl = 0;
|
|
|
|
char *szMkLvl = getenv(MKLVL_ENVVAR);
|
|
|
|
#endif /* WANT_ENV_MKLVL */
|
2001-03-01 06:03:17 +00:00
|
|
|
char mdpath[MAXPATHLEN];
|
|
|
|
char obpath[MAXPATHLEN];
|
|
|
|
char cdpath[MAXPATHLEN];
|
1995-01-23 21:03:17 +00:00
|
|
|
char *machine = getenv("MACHINE");
|
1999-03-01 06:01:05 +00:00
|
|
|
char *machine_arch = getenv("MACHINE_ARCH");
|
2001-02-19 03:59:05 +00:00
|
|
|
char *machine_cpu = getenv("MACHINE_CPU");
|
1996-10-06 02:35:38 +00:00
|
|
|
Lst sysMkPath; /* Path of sys.mk */
|
|
|
|
char *cp = NULL, *start;
|
|
|
|
/* avoid faults on read-only strings */
|
|
|
|
static char syspath[] = _PATH_DEFSYSPATH;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2003-12-13 15:26:27 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Catch SIGCHLD so that we get kicked out of select() when we
|
|
|
|
* need to look at a child. This is only known to matter for the
|
|
|
|
* -j case (perhaps without -P).
|
|
|
|
*
|
|
|
|
* XXX this is intentionally misplaced.
|
|
|
|
*/
|
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = SA_RESTART | SA_NOCLDSTOP;
|
|
|
|
sa.sa_handler = catch_child;
|
|
|
|
sigaction(SIGCHLD, &sa, NULL);
|
|
|
|
}
|
|
|
|
|
2002-10-03 04:32:47 +00:00
|
|
|
#ifdef WANT_ENV_MKLVL
|
|
|
|
if ((iMkLvl = szMkLvl ? atoi(szMkLvl) : 0) < 0) {
|
|
|
|
iMkLvl = 0;
|
|
|
|
}
|
|
|
|
if (iMkLvl++ > MKLVL_MAXVAL) {
|
|
|
|
errc(2, EAGAIN,
|
|
|
|
"Max recursion level (%d) exceeded.", MKLVL_MAXVAL);
|
|
|
|
}
|
|
|
|
bzero(szMkLvl = emalloc(32), 32);
|
|
|
|
sprintf(szMkLvl, "%d", iMkLvl);
|
|
|
|
setenv(MKLVL_ENVVAR, szMkLvl, 1);
|
|
|
|
#endif /* WANT_ENV_MKLVL */
|
|
|
|
|
2000-08-16 23:31:43 +00:00
|
|
|
#if DEFSHELL == 2
|
|
|
|
/*
|
|
|
|
* Turn off ENV to make ksh happier.
|
|
|
|
*/
|
|
|
|
unsetenv("ENV");
|
|
|
|
#endif
|
|
|
|
|
1996-10-06 02:35:38 +00: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-05-27 12:33:43 +00:00
|
|
|
|
1998-09-09 14:58:30 +00:00
|
|
|
/*
|
|
|
|
* PC-98 kernel sets the `i386' string to the utsname.machine and
|
|
|
|
* it cannot be distinguished from IBM-PC by uname(3). Therefore,
|
|
|
|
* we check machine.ispc98 and adjust the machine variable before
|
|
|
|
* using usname(3) below.
|
1999-11-23 10:35:24 +00:00
|
|
|
* NOTE: machdep.ispc98 was defined on 1998/8/31. At that time,
|
|
|
|
* __FreeBSD_version was defined as 300003. So, this check can
|
|
|
|
* safely be done with any kernel with version > 300003.
|
1998-09-09 14:58:30 +00:00
|
|
|
*/
|
|
|
|
if (!machine) {
|
|
|
|
int ispc98;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = sizeof(ispc98);
|
|
|
|
if (!sysctlbyname("machdep.ispc98", &ispc98, &len, NULL, 0)) {
|
|
|
|
if (ispc98)
|
|
|
|
machine = "pc98";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-01-23 21:03:17 +00: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, ...)
|
|
|
|
*
|
|
|
|
* Note that while MACHINE is decided at run-time,
|
|
|
|
* MACHINE_ARCH is always known at compile time.
|
|
|
|
*/
|
1996-10-11 03:55:29 +00:00
|
|
|
if (!machine) {
|
1996-09-18 06:06:39 +00:00
|
|
|
#ifndef MACHINE
|
1996-10-06 02:35:38 +00:00
|
|
|
struct utsname utsname;
|
|
|
|
|
2002-04-12 13:23:33 +00:00
|
|
|
if (uname(&utsname) == -1)
|
|
|
|
err(2, "uname");
|
1995-01-23 21:03:17 +00:00
|
|
|
machine = utsname.machine;
|
1996-09-18 06:06:39 +00:00
|
|
|
#else
|
|
|
|
machine = MACHINE;
|
|
|
|
#endif
|
1995-01-23 21:03:17 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1999-03-01 06:01:05 +00:00
|
|
|
if (!machine_arch) {
|
|
|
|
#ifndef MACHINE_ARCH
|
|
|
|
machine_arch = "unknown";
|
|
|
|
#else
|
|
|
|
machine_arch = MACHINE_ARCH;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-02-19 03:59:05 +00:00
|
|
|
/*
|
|
|
|
* Set machine_cpu to the minumum supported CPU revision based
|
|
|
|
* on the target architecture, if not already set.
|
|
|
|
*/
|
|
|
|
if (!machine_cpu) {
|
|
|
|
if (!strcmp(machine_arch, "i386"))
|
|
|
|
machine_cpu = "i386";
|
|
|
|
else if (!strcmp(machine_arch, "alpha"))
|
|
|
|
machine_cpu = "ev4";
|
|
|
|
else
|
|
|
|
machine_cpu = "unknown";
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
create = Lst_Init(FALSE);
|
|
|
|
makefiles = Lst_Init(FALSE);
|
1999-07-31 20:53:02 +00:00
|
|
|
envFirstVars = Lst_Init(FALSE);
|
2000-09-25 18:44:30 +00:00
|
|
|
expandVars = TRUE;
|
1996-07-17 11:02:43 +00:00
|
|
|
variables = Lst_Init(FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
beSilent = FALSE; /* Print commands as executed */
|
|
|
|
ignoreErrors = FALSE; /* Pay attention to non-zero returns */
|
|
|
|
noExecute = FALSE; /* Execute all commands */
|
|
|
|
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 */
|
1996-10-06 02:35:38 +00:00
|
|
|
#ifdef REMOTE
|
|
|
|
maxJobs = DEFMAXJOBS; /* Set default max concurrency */
|
1994-05-27 12:33:43 +00:00
|
|
|
#else
|
1996-10-06 02:35:38 +00:00
|
|
|
maxJobs = maxLocal;
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif
|
1997-08-14 19:24:11 +00:00
|
|
|
forceJobs = FALSE; /* No -j flag */
|
1996-10-06 02:35:38 +00:00
|
|
|
compatMake = FALSE; /* No compat mode */
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the parsing, directory and variable modules to prepare
|
|
|
|
* for the reading of inclusion paths and variable settings on the
|
|
|
|
* command line
|
|
|
|
*/
|
|
|
|
Dir_Init(); /* Initialize directory structures so -I flags
|
|
|
|
* can be processed correctly */
|
|
|
|
Parse_Init(); /* Need to initialize the paths of #include
|
|
|
|
* directories */
|
|
|
|
Var_Init(); /* As well as the lists of variables for
|
|
|
|
* parsing arguments */
|
1995-01-23 21:03:17 +00:00
|
|
|
str_init();
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
Var_Set("MAKE", argv[0], VAR_GLOBAL);
|
|
|
|
Var_Set(MAKEFLAGS, "", VAR_GLOBAL);
|
|
|
|
Var_Set("MFLAGS", "", VAR_GLOBAL);
|
1995-01-23 21:03:17 +00:00
|
|
|
Var_Set("MACHINE", machine, VAR_GLOBAL);
|
1999-03-01 06:01:05 +00:00
|
|
|
Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL);
|
2001-02-19 03:59:05 +00:00
|
|
|
Var_Set("MACHINE_CPU", machine_cpu, VAR_GLOBAL);
|
2002-05-22 14:35:47 +00:00
|
|
|
#ifdef MAKE_VERSION
|
|
|
|
Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL);
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00: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
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
MainParseArgs(argc, argv);
|
|
|
|
|
2003-09-14 12:31:33 +00:00
|
|
|
/*
|
|
|
|
* Find where we are...
|
|
|
|
* All this code is so that we know where we are when we start up
|
|
|
|
* on a different machine with pmake.
|
|
|
|
*/
|
|
|
|
curdir = cdpath;
|
|
|
|
if (getcwd(curdir, MAXPATHLEN) == NULL)
|
|
|
|
err(2, NULL);
|
|
|
|
|
|
|
|
if (stat(curdir, &sa) == -1)
|
|
|
|
err(2, "%s", curdir);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The object directory location is determined using the
|
|
|
|
* following order of preference:
|
|
|
|
*
|
|
|
|
* 1. MAKEOBJDIRPREFIX`cwd`
|
|
|
|
* 2. MAKEOBJDIR
|
|
|
|
* 3. _PATH_OBJDIR.${MACHINE}
|
|
|
|
* 4. _PATH_OBJDIR
|
|
|
|
* 5. _PATH_OBJDIRPREFIX`cwd`
|
|
|
|
*
|
|
|
|
* If one of the first two fails, use the current directory.
|
|
|
|
* If the remaining three all fail, use the current directory.
|
|
|
|
*
|
|
|
|
* Once things are initted,
|
|
|
|
* have to add the original directory to the search path,
|
|
|
|
* and modify the paths for the Makefiles apropriately. The
|
|
|
|
* current directory is also placed as a variable for make scripts.
|
|
|
|
*/
|
|
|
|
if (!(pathp = getenv("MAKEOBJDIRPREFIX"))) {
|
|
|
|
if (!(path = getenv("MAKEOBJDIR"))) {
|
|
|
|
path = _PATH_OBJDIR;
|
|
|
|
pathp = _PATH_OBJDIRPREFIX;
|
|
|
|
(void) snprintf(mdpath, MAXPATHLEN, "%s.%s",
|
|
|
|
path, machine);
|
|
|
|
if (!(objdir = chdir_verify_path(mdpath, obpath)))
|
|
|
|
if (!(objdir=chdir_verify_path(path, obpath))) {
|
|
|
|
(void) snprintf(mdpath, MAXPATHLEN,
|
|
|
|
"%s%s", pathp, curdir);
|
|
|
|
if (!(objdir=chdir_verify_path(mdpath,
|
|
|
|
obpath)))
|
|
|
|
objdir = curdir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!(objdir = chdir_verify_path(path, obpath)))
|
|
|
|
objdir = curdir;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
(void) snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir);
|
|
|
|
if (!(objdir = chdir_verify_path(mdpath, obpath)))
|
|
|
|
objdir = curdir;
|
|
|
|
}
|
|
|
|
Dir_InitDot(); /* Initialize the "." directory */
|
|
|
|
if (objdir != curdir)
|
|
|
|
Dir_AddDir(dirSearchPath, curdir);
|
|
|
|
Var_Set(".CURDIR", curdir, VAR_GLOBAL);
|
|
|
|
Var_Set(".OBJDIR", objdir, VAR_GLOBAL);
|
|
|
|
|
1997-08-14 19:24:11 +00:00
|
|
|
/*
|
|
|
|
* Be compatible if user did not specify -j and did not explicitly
|
|
|
|
* turned compatibility on
|
|
|
|
*/
|
|
|
|
if (!compatMake && !forceJobs)
|
|
|
|
compatMake = TRUE;
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Initialize archive, target and suffix modules in preparation for
|
|
|
|
* parsing the makefile(s)
|
|
|
|
*/
|
|
|
|
Arch_Init();
|
|
|
|
Targ_Init();
|
|
|
|
Suff_Init();
|
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
DEFAULT = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)time(&now);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
for (ln = Lst_First(create); ln != NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
ln = Lst_Succ(ln)) {
|
|
|
|
char *name = (char *)Lst_Datum(ln);
|
|
|
|
|
|
|
|
Var_Append(".TARGETS", name, VAR_GLOBAL);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
Var_Set(".TARGETS", "", VAR_GLOBAL);
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
1996-10-06 02:35:38 +00: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.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
if (Lst_IsEmpty(sysIncPath)) {
|
|
|
|
for (start = syspath; *start != '\0'; start = cp) {
|
|
|
|
for (cp = start; *cp != '\0' && *cp != ':'; cp++)
|
|
|
|
continue;
|
|
|
|
if (*cp == '\0') {
|
|
|
|
Dir_AddDir(sysIncPath, start);
|
|
|
|
} else {
|
|
|
|
*cp++ = '\0';
|
|
|
|
Dir_AddDir(sysIncPath, start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
Dir_Expand (_PATH_DEFSYSMK, sysIncPath, sysMkPath);
|
|
|
|
if (Lst_IsEmpty(sysMkPath))
|
|
|
|
Fatal("make: no system rules (%s).", _PATH_DEFSYSMK);
|
2000-12-02 20:24:42 +00:00
|
|
|
ln = Lst_Find(sysMkPath, (void *)NULL, ReadMakefile);
|
2000-12-02 18:58:01 +00:00
|
|
|
if (ln != NULL)
|
1996-10-06 02:35:38 +00:00
|
|
|
Fatal("make: cannot open %s.", (char *)Lst_Datum(ln));
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (!Lst_IsEmpty(makefiles)) {
|
|
|
|
LstNode ln;
|
|
|
|
|
2000-12-02 20:24:42 +00:00
|
|
|
ln = Lst_Find(makefiles, (void *)NULL, ReadMakefile);
|
2000-12-02 18:58:01 +00:00
|
|
|
if (ln != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
Fatal("make: cannot open %s.", (char *)Lst_Datum(ln));
|
2002-04-13 12:18:00 +00:00
|
|
|
} else if (!ReadMakefile("BSDmakefile", NULL))
|
|
|
|
if (!ReadMakefile("makefile", NULL))
|
1996-10-06 02:35:38 +00:00
|
|
|
(void)ReadMakefile("Makefile", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
(void)ReadMakefile(".depend", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1995-01-23 21:03:17 +00:00
|
|
|
Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
|
2002-10-23 23:16:43 +00:00
|
|
|
free(p1);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/* Install all the flags into the MAKE envariable. */
|
1995-01-23 21:03:17 +00:00
|
|
|
if (((p = Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1)) != NULL) && *p)
|
1994-05-27 12:33:43 +00:00
|
|
|
#ifdef POSIX
|
|
|
|
setenv("MAKEFLAGS", p, 1);
|
|
|
|
#else
|
|
|
|
setenv("MAKE", p, 1);
|
|
|
|
#endif
|
2002-10-23 23:16:43 +00:00
|
|
|
free(p1);
|
1994-05-27 12:33:43 +00: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)) {
|
2002-10-09 01:51:00 +00:00
|
|
|
char *vpath, savec;
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* 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}";
|
|
|
|
|
|
|
|
vpath = Var_Subst(NULL, VPATH, VAR_CMD, FALSE);
|
2002-10-09 01:51:00 +00:00
|
|
|
path = vpath;
|
1994-05-27 12:33:43 +00:00
|
|
|
do {
|
|
|
|
/* skip to end of directory */
|
2002-10-09 01:51:00 +00:00
|
|
|
for (cp = path; *cp != ':' && *cp != '\0'; cp++)
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
/* Save terminator character so know when to stop */
|
2002-10-09 01:51:00 +00:00
|
|
|
savec = *cp;
|
|
|
|
*cp = '\0';
|
1994-05-27 12:33:43 +00:00
|
|
|
/* Add directory to search path */
|
2002-10-09 01:51:00 +00:00
|
|
|
Dir_AddDir(dirSearchPath, path);
|
|
|
|
*cp = savec;
|
|
|
|
path = cp + 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
} while (savec == ':');
|
2000-12-02 20:24:42 +00:00
|
|
|
(void)free(vpath);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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();
|
|
|
|
|
|
|
|
/* print the initial graph, if the user requested it */
|
|
|
|
if (DEBUG(GRAPH1))
|
|
|
|
Targ_PrintGraph(1);
|
|
|
|
|
1996-07-17 11:02:43 +00:00
|
|
|
/* print the values of any variables requested by the user */
|
2002-08-07 13:25:51 +00:00
|
|
|
if (!Lst_IsEmpty(variables)) {
|
1996-07-17 11:02:43 +00:00
|
|
|
LstNode ln;
|
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
for (ln = Lst_First(variables); ln != NULL;
|
1996-07-17 11:02:43 +00:00
|
|
|
ln = Lst_Succ(ln)) {
|
2000-09-25 18:44:30 +00:00
|
|
|
char *value;
|
|
|
|
if (expandVars) {
|
2002-04-12 13:23:33 +00:00
|
|
|
p1 = emalloc(strlen((char *)Lst_Datum(ln)) + 1 + 3);
|
2000-09-25 18:44:30 +00:00
|
|
|
/* This sprintf is safe, because of the malloc above */
|
|
|
|
(void)sprintf(p1, "${%s}", (char *)Lst_Datum(ln));
|
|
|
|
value = Var_Subst(NULL, p1, VAR_GLOBAL, FALSE);
|
|
|
|
} else {
|
|
|
|
value = Var_Value((char *)Lst_Datum(ln),
|
|
|
|
VAR_GLOBAL, &p1);
|
|
|
|
}
|
1996-07-17 11:02:43 +00:00
|
|
|
printf("%s\n", value ? value : "");
|
2000-09-25 18:44:30 +00:00
|
|
|
if (p1)
|
|
|
|
free(p1);
|
1996-07-17 11:02:43 +00:00
|
|
|
}
|
2002-08-07 13:25:51 +00:00
|
|
|
} else {
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
2002-08-07 13:25:51 +00: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.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2002-08-07 13:25:51 +00:00
|
|
|
if (Lst_IsEmpty(create))
|
|
|
|
targs = Parse_MainName();
|
|
|
|
else
|
|
|
|
targs = Targ_FindList(create, TARG_CREATE);
|
|
|
|
|
|
|
|
if (!compatMake) {
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-08-07 13:25:51 +00:00
|
|
|
/* Traverse the graph, checking on all the targets */
|
|
|
|
outOfDate = Make_Run(targs);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Compat_Init will take care of creating all the targets as
|
|
|
|
* well as initializing the module.
|
|
|
|
*/
|
|
|
|
Compat_Run(targs);
|
2003-10-03 21:33:39 +00:00
|
|
|
outOfDate = 0;
|
2002-08-07 13:25:51 +00:00
|
|
|
}
|
2002-08-11 11:10:43 +00:00
|
|
|
Lst_Destroy(targs, NOFREE);
|
1996-07-17 11:02:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1996-07-17 11:02:43 +00:00
|
|
|
Lst_Destroy(variables, NOFREE);
|
1995-01-23 21:03:17 +00:00
|
|
|
Lst_Destroy(makefiles, NOFREE);
|
2002-03-22 01:33:25 +00:00
|
|
|
Lst_Destroy(create, (void (*)(void *)) free);
|
1995-01-23 21:03:17 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/* print the graph now it's been processed if the user requested it */
|
|
|
|
if (DEBUG(GRAPH2))
|
|
|
|
Targ_PrintGraph(2);
|
|
|
|
|
1995-01-23 21:03:17 +00:00
|
|
|
Suff_End();
|
|
|
|
Targ_End();
|
|
|
|
Arch_End();
|
|
|
|
str_end();
|
|
|
|
Var_End();
|
|
|
|
Parse_End();
|
|
|
|
Dir_End();
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (queryFlag && outOfDate)
|
|
|
|
return(1);
|
|
|
|
else
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* ReadMakefile --
|
|
|
|
* Open and parse the given makefile.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* TRUE if ok. FALSE if couldn't open file.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* lots
|
|
|
|
*/
|
|
|
|
static Boolean
|
2002-10-09 03:42:10 +00:00
|
|
|
ReadMakefile(void *p, void *q __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-10-09 03:42:10 +00:00
|
|
|
char *fname; /* makefile to read */
|
1994-05-27 12:33:43 +00:00
|
|
|
FILE *stream;
|
2001-03-01 06:03:17 +00:00
|
|
|
char *name, path[MAXPATHLEN];
|
2002-05-23 12:01:54 +00:00
|
|
|
char *MAKEFILE;
|
2002-04-18 12:04:34 +00:00
|
|
|
int setMAKEFILE;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-10-09 03:42:10 +00:00
|
|
|
fname = p;
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (!strcmp(fname, "-")) {
|
|
|
|
Parse_File("(stdin)", stdin);
|
|
|
|
Var_Set("MAKEFILE", "", VAR_GLOBAL);
|
|
|
|
} else {
|
2002-04-18 12:04:34 +00:00
|
|
|
setMAKEFILE = strcmp(fname, ".depend");
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/* if we've chdir'd, rebuild the path name */
|
|
|
|
if (curdir != objdir && *fname != '/') {
|
2000-11-30 13:56:19 +00:00
|
|
|
(void)snprintf(path, MAXPATHLEN, "%s/%s", curdir, fname);
|
2002-07-26 21:50:36 +00:00
|
|
|
/*
|
|
|
|
* XXX The realpath stuff breaks relative includes
|
|
|
|
* XXX in some cases. The problem likely is in
|
|
|
|
* XXX parse.c where it does special things in
|
|
|
|
* XXX ParseDoInclude if the file is relateive
|
|
|
|
* XXX or absolute and not a system file. There
|
|
|
|
* XXX it assumes that if the current file that's
|
|
|
|
* XXX being included is absolute, that any files
|
|
|
|
* XXX that it includes shouldn't do the -I path
|
|
|
|
* XXX stuff, which is inconsistant with historical
|
|
|
|
* XXX behavior. However, I can't pentrate the mists
|
|
|
|
* XXX further, so I'm putting this workaround in
|
|
|
|
* XXX here until such time as the underlying bug
|
|
|
|
* XXX can be fixed.
|
|
|
|
*/
|
|
|
|
#if THIS_BREAKS_THINGS
|
2002-05-21 20:24:46 +00:00
|
|
|
if (realpath(path, path) != NULL &&
|
|
|
|
(stream = fopen(path, "r")) != NULL) {
|
2002-05-23 12:01:54 +00:00
|
|
|
MAKEFILE = fname;
|
1994-05-27 12:33:43 +00:00
|
|
|
fname = path;
|
|
|
|
goto found;
|
|
|
|
}
|
2002-05-21 20:24:46 +00:00
|
|
|
} else if (realpath(fname, path) != NULL) {
|
2002-05-23 12:01:54 +00:00
|
|
|
MAKEFILE = fname;
|
2002-05-21 20:24:46 +00:00
|
|
|
fname = path;
|
|
|
|
if ((stream = fopen(fname, "r")) != NULL)
|
|
|
|
goto found;
|
|
|
|
}
|
2002-07-26 21:50:36 +00:00
|
|
|
#else
|
|
|
|
if ((stream = fopen(path, "r")) != NULL) {
|
|
|
|
MAKEFILE = fname;
|
|
|
|
fname = path;
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MAKEFILE = fname;
|
|
|
|
if ((stream = fopen(fname, "r")) != NULL)
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
/* look in -I and system include directories. */
|
|
|
|
name = Dir_FindFile(fname, parseIncPath);
|
|
|
|
if (!name)
|
|
|
|
name = Dir_FindFile(fname, sysIncPath);
|
|
|
|
if (!name || !(stream = fopen(name, "r")))
|
|
|
|
return(FALSE);
|
2002-05-23 12:01:54 +00:00
|
|
|
MAKEFILE = fname = name;
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2002-04-18 12:04:34 +00:00
|
|
|
found:
|
|
|
|
if (setMAKEFILE)
|
2002-05-23 12:01:54 +00:00
|
|
|
Var_Set("MAKEFILE", MAKEFILE, VAR_GLOBAL);
|
1994-05-27 12:33:43 +00:00
|
|
|
Parse_File(fname, stream);
|
|
|
|
(void)fclose(stream);
|
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
1996-10-06 02:35:38 +00: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
|
2002-09-28 23:35:07 +00:00
|
|
|
* If error is not NULL, it contains the reason for the command failure
|
1996-10-06 02:35:38 +00:00
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The string must be freed by the caller.
|
|
|
|
*/
|
|
|
|
char *
|
2002-10-09 03:42:10 +00:00
|
|
|
Cmd_Exec(char *cmd, char **error)
|
1996-10-06 02:35:38 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2002-09-28 23:35:07 +00:00
|
|
|
*error = NULL;
|
1996-10-06 02:35:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
2002-09-28 23:35:07 +00:00
|
|
|
*error = "Couldn't create pipe for \"%s\"";
|
1996-10-06 02:35:38 +00:00
|
|
|
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]);
|
|
|
|
|
2002-09-29 00:02:04 +00:00
|
|
|
#if defined(DEFSHELL) && DEFSHELL == 0
|
|
|
|
(void) execv("/bin/csh", args);
|
|
|
|
#elif DEFSHELL == 1
|
2002-05-24 15:51:27 +00:00
|
|
|
(void) execv("/bin/sh", args);
|
2000-08-16 23:31:43 +00:00
|
|
|
#elif DEFSHELL == 2
|
2002-05-24 15:51:27 +00:00
|
|
|
(void) execv("/bin/ksh", args);
|
2000-08-16 23:31:43 +00:00
|
|
|
#else
|
|
|
|
#error "DEFSHELL must be 1 or 2."
|
|
|
|
#endif
|
1996-10-06 02:35:38 +00:00
|
|
|
_exit(1);
|
|
|
|
/*NOTREACHED*/
|
|
|
|
|
|
|
|
case -1:
|
2002-09-28 23:35:07 +00:00
|
|
|
*error = "Couldn't exec \"%s\"";
|
1996-10-06 02:35:38 +00:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* No need for the writing half
|
|
|
|
*/
|
|
|
|
(void) close(fds[1]);
|
|
|
|
|
|
|
|
buf = Buf_Init (MAKE_BSIZE);
|
|
|
|
|
|
|
|
do {
|
|
|
|
char result[BUFSIZ];
|
|
|
|
cc = read(fds[0], result, sizeof(result));
|
|
|
|
if (cc > 0)
|
|
|
|
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;
|
|
|
|
|
1996-10-12 02:15:30 +00:00
|
|
|
if (cc == -1)
|
2002-09-28 23:35:07 +00:00
|
|
|
*error = "Error reading shell's output for \"%s\"";
|
1996-10-11 03:55:29 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
res = (char *)Buf_GetAll (buf, &cc);
|
|
|
|
Buf_Destroy (buf, FALSE);
|
|
|
|
|
|
|
|
if (status)
|
2002-09-28 23:35:07 +00:00
|
|
|
*error = "\"%s\" returned non-zero status";
|
1996-10-06 02:35:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Null-terminate the result, convert newlines to spaces and
|
|
|
|
* install it in the variable.
|
|
|
|
*/
|
|
|
|
res[cc] = '\0';
|
|
|
|
cp = &res[cc] - 1;
|
|
|
|
|
|
|
|
if (*cp == '\n') {
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* usage --
|
|
|
|
* exit with usage message
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
usage(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1997-07-24 06:58:08 +00:00
|
|
|
(void)fprintf(stderr, "%s\n%s\n%s\n",
|
2003-04-15 14:27:21 +00:00
|
|
|
"usage: make [-BPSXeiknqrstv] [-C directory] [-D variable] [-d flags]",
|
|
|
|
" [-E variable] [-f makefile] [-I directory] [-j max_jobs]",
|
|
|
|
" [-m directory] [-V variable] [variable=value] [target ...]");
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(2);
|
|
|
|
}
|