2005-02-01 10:50:37 +00:00
|
|
|
/*-
|
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
|
|
|
|
2005-04-01 12:42:03 +00:00
|
|
|
/*
|
|
|
|
* main.c
|
1994-05-27 12:33:43 +00:00
|
|
|
* The main file for this entire program. Exit routines etc
|
|
|
|
* reside here.
|
|
|
|
*
|
|
|
|
* Utility functions defined in this file:
|
2005-04-01 12:42:03 +00:00
|
|
|
* 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.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
1998-09-09 14:58:30 +00:00
|
|
|
#include <sys/sysctl.h>
|
2004-04-05 06:16:48 +00:00
|
|
|
#include <sys/time.h>
|
2005-03-23 12:56:15 +00:00
|
|
|
#include <sys/queue.h>
|
2004-04-05 17:02:08 +00:00
|
|
|
#include <sys/resource.h>
|
2005-12-05 14:22:12 +00:00
|
|
|
#include <sys/utsname.h>
|
1996-10-06 02:35:38 +00:00
|
|
|
#include <sys/wait.h>
|
1997-07-24 06:58:08 +00:00
|
|
|
#include <err.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <errno.h>
|
2004-04-05 06:16:48 +00:00
|
|
|
#include <stdlib.h>
|
2005-02-01 10:50:37 +00:00
|
|
|
#include <string.h>
|
2000-07-28 06:50:25 +00:00
|
|
|
#include <unistd.h>
|
2004-04-05 06:16:48 +00:00
|
|
|
|
2005-02-01 10:50:37 +00:00
|
|
|
#include "arch.h"
|
2005-02-02 07:36:18 +00:00
|
|
|
#include "buf.h"
|
2005-02-01 10:50:37 +00:00
|
|
|
#include "config.h"
|
1994-05-27 12:33:43 +00:00
|
|
|
#include "dir.h"
|
2005-02-01 10:50:37 +00:00
|
|
|
#include "globals.h"
|
1994-05-27 12:33:43 +00:00
|
|
|
#include "job.h"
|
2005-02-01 10:50:37 +00:00
|
|
|
#include "make.h"
|
|
|
|
#include "parse.h"
|
1994-05-27 12:33:43 +00:00
|
|
|
#include "pathnames.h"
|
2005-05-24 15:30:03 +00:00
|
|
|
#include "shell.h"
|
2005-02-01 10:50:37 +00:00
|
|
|
#include "str.h"
|
|
|
|
#include "suff.h"
|
|
|
|
#include "targ.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "var.h"
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2005-05-12 15:04:14 +00:00
|
|
|
extern char **environ; /* XXX what header declares this variable? */
|
|
|
|
|
2006-07-17 19:16:12 +00:00
|
|
|
#define WANT_ENV_MKLVL 1
|
2004-11-24 22:03:45 +00:00
|
|
|
#define MKLVL_MAXVAL 500
|
|
|
|
#define MKLVL_ENVVAR "__MKLVL__"
|
2002-10-03 04:32:47 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
/* ordered list of makefiles to read */
|
|
|
|
static Lst makefiles = Lst_Initializer(makefiles);
|
|
|
|
|
|
|
|
/* list of variables to print */
|
|
|
|
static Lst variables = Lst_Initializer(variables);
|
|
|
|
|
2005-05-12 15:04:14 +00:00
|
|
|
static Boolean expandVars; /* fully expand printed variables */
|
|
|
|
static Boolean noBuiltins; /* -r flag */
|
2006-07-17 19:16:12 +00:00
|
|
|
static Boolean forceJobs; /* -j argument given */
|
2005-05-12 15:04:14 +00:00
|
|
|
static char *curdir; /* startup directory */
|
|
|
|
static char *objdir; /* where we chdir'ed to */
|
|
|
|
|
|
|
|
/* (-E) vars to override from env */
|
|
|
|
Lst envFirstVars = Lst_Initializer(envFirstVars);
|
|
|
|
|
|
|
|
/* Targets to be made */
|
|
|
|
Lst create = Lst_Initializer(create);
|
|
|
|
|
|
|
|
Boolean allPrecious; /* .PRECIOUS given on line by itself */
|
|
|
|
Boolean beSilent; /* -s flag */
|
|
|
|
Boolean beVerbose; /* -v flag */
|
2005-04-01 12:42:03 +00:00
|
|
|
Boolean compatMake; /* -B argument */
|
2005-09-07 07:34:24 +00:00
|
|
|
int debug; /* -d flag */
|
2005-05-12 15:04:14 +00:00
|
|
|
Boolean ignoreErrors; /* -i flag */
|
|
|
|
int jobLimit; /* -j argument */
|
|
|
|
Boolean jobsRunning; /* TRUE if the jobs might be running */
|
2005-04-01 12:42:03 +00:00
|
|
|
Boolean keepgoing; /* -k flag */
|
2005-05-12 15:04:14 +00:00
|
|
|
Boolean noExecute; /* -n flag */
|
2005-04-01 12:42:03 +00:00
|
|
|
Boolean queryFlag; /* -q flag */
|
|
|
|
Boolean touchFlag; /* -t flag */
|
|
|
|
Boolean usePipes; /* !-P flag */
|
2005-05-12 15:04:14 +00:00
|
|
|
uint32_t warn_cmd; /* command line warning flags */
|
|
|
|
uint32_t warn_flags; /* actual warning flags */
|
|
|
|
uint32_t warn_nocmd; /* command line no-warning flags */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2005-05-12 15:04:14 +00:00
|
|
|
time_t now; /* Time at start of make */
|
|
|
|
struct GNode *DEFAULT; /* .DEFAULT node */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2005-05-12 14:35:01 +00:00
|
|
|
/**
|
|
|
|
* Exit with usage message.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"usage: make [-BPSXeiknqrstv] [-C directory] [-D variable]\n"
|
|
|
|
"\t[-d flags] [-E variable] [-f makefile] [-I directory]\n"
|
|
|
|
"\t[-j max_jobs] [-m directory] [-V variable]\n"
|
|
|
|
"\t[variable=value] [target ...]\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2005-04-01 12:42:03 +00:00
|
|
|
/**
|
|
|
|
* MFLAGS_append
|
|
|
|
* Append a flag with an optional argument to MAKEFLAGS and MFLAGS
|
2004-08-03 18:56:31 +00:00
|
|
|
*/
|
|
|
|
static void
|
2005-02-04 07:51:00 +00:00
|
|
|
MFLAGS_append(const char *flag, char *arg)
|
2004-08-03 18:56:31 +00:00
|
|
|
{
|
2005-01-26 18:19:39 +00:00
|
|
|
char *str;
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2005-05-12 15:04:14 +00:00
|
|
|
Var_Append(".MAKEFLAGS", flag, VAR_GLOBAL);
|
2005-01-26 18:19:39 +00:00
|
|
|
if (arg != NULL) {
|
|
|
|
str = MAKEFLAGS_quote(arg);
|
2005-05-12 15:04:14 +00:00
|
|
|
Var_Append(".MAKEFLAGS", str, VAR_GLOBAL);
|
2005-01-26 18:19:39 +00:00
|
|
|
free(str);
|
|
|
|
}
|
2004-08-03 18:56:31 +00:00
|
|
|
|
|
|
|
Var_Append("MFLAGS", flag, VAR_GLOBAL);
|
2005-01-26 18:19:39 +00:00
|
|
|
if (arg != NULL) {
|
|
|
|
str = MAKEFLAGS_quote(arg);
|
|
|
|
Var_Append("MFLAGS", str, VAR_GLOBAL);
|
|
|
|
free(str);
|
|
|
|
}
|
2004-08-03 18:56:31 +00:00
|
|
|
}
|
|
|
|
|
2005-04-29 14:37:44 +00:00
|
|
|
/**
|
|
|
|
* Main_ParseWarn
|
|
|
|
*
|
|
|
|
* Handle argument to warning option.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
Main_ParseWarn(const char *arg, int iscmd)
|
|
|
|
{
|
|
|
|
int i, neg;
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
const char *option;
|
|
|
|
uint32_t flag;
|
|
|
|
} options[] = {
|
|
|
|
{ "dirsyntax", WARN_DIRSYNTAX },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
neg = 0;
|
|
|
|
if (arg[0] == 'n' && arg[1] == 'o') {
|
|
|
|
neg = 1;
|
|
|
|
arg += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; options[i].option != NULL; i++)
|
|
|
|
if (strcmp(arg, options[i].option) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (options[i].option == NULL)
|
|
|
|
/* unknown option */
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
if (iscmd) {
|
|
|
|
if (!neg) {
|
|
|
|
warn_cmd |= options[i].flag;
|
|
|
|
warn_nocmd &= ~options[i].flag;
|
|
|
|
warn_flags |= options[i].flag;
|
|
|
|
} else {
|
|
|
|
warn_nocmd |= options[i].flag;
|
|
|
|
warn_cmd &= ~options[i].flag;
|
|
|
|
warn_flags &= ~options[i].flag;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!neg) {
|
|
|
|
warn_flags |= (options[i].flag & ~warn_nocmd);
|
|
|
|
} else {
|
|
|
|
warn_flags &= ~(options[i].flag | warn_cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-05-12 14:35:01 +00:00
|
|
|
/**
|
|
|
|
* Open and parse the given makefile.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* TRUE if ok. FALSE if couldn't open file.
|
|
|
|
*/
|
|
|
|
static Boolean
|
|
|
|
ReadMakefile(const char p[])
|
|
|
|
{
|
2005-12-01 05:59:45 +00:00
|
|
|
char *fname, *fnamesave; /* makefile to read */
|
2005-05-12 14:35:01 +00:00
|
|
|
FILE *stream;
|
|
|
|
char *name, path[MAXPATHLEN];
|
|
|
|
char *MAKEFILE;
|
|
|
|
int setMAKEFILE;
|
|
|
|
|
|
|
|
/* XXX - remove this once constification is done */
|
2005-12-01 05:59:45 +00:00
|
|
|
fnamesave = fname = estrdup(p);
|
2005-05-12 14:35:01 +00:00
|
|
|
|
|
|
|
if (!strcmp(fname, "-")) {
|
|
|
|
Parse_File("(stdin)", stdin);
|
2005-05-12 14:47:22 +00:00
|
|
|
Var_SetGlobal("MAKEFILE", "");
|
2005-05-12 14:35:01 +00:00
|
|
|
} else {
|
|
|
|
setMAKEFILE = strcmp(fname, ".depend");
|
|
|
|
|
|
|
|
/* if we've chdir'd, rebuild the path name */
|
|
|
|
if (curdir != objdir && *fname != '/') {
|
|
|
|
snprintf(path, MAXPATHLEN, "%s/%s", curdir, fname);
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
if (realpath(path, path) != NULL &&
|
|
|
|
(stream = fopen(path, "r")) != NULL) {
|
|
|
|
MAKEFILE = fname;
|
|
|
|
fname = path;
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
} else if (realpath(fname, path) != NULL) {
|
|
|
|
MAKEFILE = fname;
|
|
|
|
fname = path;
|
|
|
|
if ((stream = fopen(fname, "r")) != NULL)
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
#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
|
|
|
|
/* look in -I and system include directories. */
|
|
|
|
name = Path_FindFile(fname, &parseIncPath);
|
|
|
|
if (!name)
|
|
|
|
name = Path_FindFile(fname, &sysIncPath);
|
2005-11-30 20:38:03 +00:00
|
|
|
if (!name || !(stream = fopen(name, "r"))) {
|
2005-12-01 05:59:45 +00:00
|
|
|
free(fnamesave);
|
2005-05-12 14:35:01 +00:00
|
|
|
return (FALSE);
|
2005-11-30 20:38:03 +00:00
|
|
|
}
|
2005-05-12 14:35:01 +00:00
|
|
|
MAKEFILE = 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.
|
|
|
|
*/
|
|
|
|
found:
|
|
|
|
if (setMAKEFILE)
|
2005-05-12 14:47:22 +00:00
|
|
|
Var_SetGlobal("MAKEFILE", MAKEFILE);
|
2005-05-12 14:35:01 +00:00
|
|
|
Parse_File(fname, stream);
|
|
|
|
}
|
2005-12-01 05:59:45 +00:00
|
|
|
free(fnamesave);
|
2005-05-12 14:35:01 +00:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2005-04-01 12:42:03 +00:00
|
|
|
/**
|
|
|
|
* MainParseArgs
|
1994-05-27 12:33:43 +00:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
1995-01-23 21:03:17 +00:00
|
|
|
int c;
|
2005-05-10 08:06:13 +00:00
|
|
|
Boolean found_dd = FALSE;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2005-04-11 07:32:49 +00:00
|
|
|
rearg:
|
1994-05-27 12:33:43 +00:00
|
|
|
optind = 1; /* since we're called more than once */
|
2005-04-11 07:32:49 +00:00
|
|
|
optreset = 1;
|
2005-04-28 15:37:25 +00:00
|
|
|
#define OPTFLAGS "ABC:D:E:I:PSV:Xd:ef:ij:km:nqrstvx:"
|
2005-05-10 08:06:13 +00:00
|
|
|
for (;;) {
|
|
|
|
if ((optind < argc) && strcmp(argv[optind], "--") == 0) {
|
|
|
|
found_dd = TRUE;
|
|
|
|
}
|
|
|
|
if ((c = getopt(argc, argv, OPTFLAGS)) == -1) {
|
|
|
|
break;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
switch(c) {
|
2005-03-31 11:35:56 +00:00
|
|
|
|
|
|
|
case 'A':
|
|
|
|
arch_fatal = FALSE;
|
|
|
|
MFLAGS_append("-A", NULL);
|
|
|
|
break;
|
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':
|
2005-05-12 14:47:22 +00:00
|
|
|
Var_SetGlobal(optarg, "1");
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-D", optarg);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
Parse_AddIncludeDir(optarg);
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-I", optarg);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
1996-07-17 11:02:43 +00:00
|
|
|
case 'V':
|
2004-12-16 19:46:50 +00:00
|
|
|
Lst_AtEnd(&variables, estrdup(optarg));
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-V", optarg);
|
1996-07-17 11:02:43 +00:00
|
|
|
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;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-B", NULL);
|
2004-11-12 20:37:27 +00:00
|
|
|
unsetenv("MAKE_JOBS_FIFO");
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
usePipes = FALSE;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-P", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
keepgoing = FALSE;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-S", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
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:
|
2005-04-01 12:42:03 +00:00
|
|
|
warnx("illegal argument to d option "
|
|
|
|
"-- %c", *modules);
|
1994-05-27 12:33:43 +00:00
|
|
|
usage();
|
|
|
|
}
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-d", optarg);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-07-31 20:53:02 +00:00
|
|
|
case 'E':
|
2004-12-16 19:46:50 +00:00
|
|
|
Lst_AtEnd(&envFirstVars, estrdup(optarg));
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-E", optarg);
|
1999-07-31 20:53:02 +00:00
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'e':
|
|
|
|
checkEnvFirst = TRUE;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-e", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
2004-12-16 19:46:50 +00:00
|
|
|
Lst_AtEnd(&makefiles, estrdup(optarg));
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
ignoreErrors = TRUE;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-i", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
1999-07-31 20:40:23 +00:00
|
|
|
case 'j': {
|
|
|
|
char *endptr;
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
forceJobs = TRUE;
|
2005-05-12 14:16:44 +00:00
|
|
|
jobLimit = strtol(optarg, &endptr, 10);
|
|
|
|
if (jobLimit <= 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
|
|
|
}
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-j", optarg);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
1999-07-31 20:40:23 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'k':
|
|
|
|
keepgoing = TRUE;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-k", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
1996-10-06 02:35:38 +00:00
|
|
|
case 'm':
|
2005-03-23 12:56:15 +00:00
|
|
|
Path_AddDir(&sysIncPath, optarg);
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-m", optarg);
|
1996-10-06 02:35:38 +00:00
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'n':
|
|
|
|
noExecute = TRUE;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-n", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
queryFlag = TRUE;
|
|
|
|
/* Kind of nonsensical, wot? */
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-q", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
noBuiltins = TRUE;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-r", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
beSilent = TRUE;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-s", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
touchFlag = TRUE;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-t", NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
1998-11-14 16:15:04 +00:00
|
|
|
case 'v':
|
|
|
|
beVerbose = TRUE;
|
2004-08-03 18:56:31 +00:00
|
|
|
MFLAGS_append("-v", NULL);
|
1998-11-14 16:15:04 +00:00
|
|
|
break;
|
2005-04-28 15:37:25 +00:00
|
|
|
case 'x':
|
2005-04-29 14:37:44 +00:00
|
|
|
if (Main_ParseWarn(optarg, 1) != -1)
|
2005-04-28 15:37:25 +00:00
|
|
|
MFLAGS_append("-x", optarg);
|
|
|
|
break;
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
default:
|
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
2005-04-11 07:32:49 +00:00
|
|
|
argv += optind;
|
|
|
|
argc -= optind;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
oldVars = TRUE;
|
|
|
|
|
|
|
|
/*
|
2005-04-11 07:32:49 +00:00
|
|
|
* Parse the rest of the arguments.
|
|
|
|
* o Check for variable assignments and perform them if so.
|
|
|
|
* o Check for more flags and restart getopt if so.
|
2006-07-17 19:16:12 +00:00
|
|
|
* o Anything else is taken to be a target and added
|
2005-04-11 07:32:49 +00:00
|
|
|
* to the end of the "create" list.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2005-04-11 07:32:49 +00:00
|
|
|
for (; *argv != NULL; ++argv, --argc) {
|
2004-08-12 11:49:55 +00:00
|
|
|
if (Parse_IsVar(*argv)) {
|
2005-01-26 18:19:39 +00:00
|
|
|
char *ptr = MAKEFLAGS_quote(*argv);
|
2004-08-12 11:49:55 +00:00
|
|
|
|
2005-05-12 15:04:14 +00:00
|
|
|
Var_Append(".MAKEFLAGS", ptr, VAR_GLOBAL);
|
2005-04-11 07:32:49 +00:00
|
|
|
Parse_DoVar(*argv, VAR_CMD);
|
2004-08-12 11:49:55 +00:00
|
|
|
free(ptr);
|
|
|
|
|
2005-04-11 07:32:49 +00:00
|
|
|
} else if ((*argv)[0] == '-') {
|
|
|
|
if ((*argv)[1] == '\0') {
|
|
|
|
/*
|
|
|
|
* (*argv) is a single dash, so we
|
|
|
|
* just ignore it.
|
|
|
|
*/
|
2005-05-10 08:06:13 +00:00
|
|
|
} else if (found_dd) {
|
|
|
|
/*
|
|
|
|
* Double dash has been found, ignore
|
|
|
|
* any more options. But what do we do
|
|
|
|
* with it? For now treat it like a target.
|
|
|
|
*/
|
|
|
|
Lst_AtEnd(&create, estrdup(*argv));
|
2005-04-11 07:32:49 +00:00
|
|
|
} else {
|
|
|
|
/*
|
2005-05-10 08:06:13 +00:00
|
|
|
* (*argv) is a -flag, so backup argv and
|
|
|
|
* argc. getopt() expects options to start
|
|
|
|
* in the 2nd position.
|
2005-04-11 07:32:49 +00:00
|
|
|
*/
|
|
|
|
argc++;
|
|
|
|
argv--;
|
1994-05-27 12:33:43 +00:00
|
|
|
goto rearg;
|
|
|
|
}
|
2005-04-11 07:32:49 +00:00
|
|
|
|
|
|
|
} else if ((*argv)[0] == '\0') {
|
|
|
|
Punt("illegal (null) argument.");
|
|
|
|
|
|
|
|
} else {
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&create, estrdup(*argv));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2005-04-11 07:32:49 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2005-04-01 12:42:03 +00:00
|
|
|
/**
|
|
|
|
* Main_ParseArgLine
|
2006-07-17 19:16:12 +00:00
|
|
|
* Used by the parse module when a .MFLAGS or .MAKEFLAGS target
|
1994-05-27 12:33:43 +00:00
|
|
|
* is encountered and by main() when reading the .MAKEFLAGS envariable.
|
|
|
|
* Takes a line of arguments and breaks it into its
|
2006-07-17 19:16:12 +00:00
|
|
|
* component words and passes those words and the number of them to the
|
1994-05-27 12:33:43 +00:00
|
|
|
* MainParseArgs function.
|
|
|
|
* The line should have all its leading whitespace removed.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Only those that come from the various arguments.
|
|
|
|
*/
|
|
|
|
void
|
2005-01-26 18:19:39 +00:00
|
|
|
Main_ParseArgLine(char *line, int mflags)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2005-05-18 14:50:35 +00:00
|
|
|
ArgArray aa;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (line == NULL)
|
|
|
|
return;
|
|
|
|
for (; *line == ' '; ++line)
|
|
|
|
continue;
|
|
|
|
if (!*line)
|
|
|
|
return;
|
|
|
|
|
2005-01-26 18:19:39 +00:00
|
|
|
if (mflags)
|
2005-05-18 14:50:35 +00:00
|
|
|
MAKEFLAGS_break(&aa, line);
|
2005-01-26 18:19:39 +00:00
|
|
|
else
|
2005-05-18 14:50:35 +00:00
|
|
|
brk_string(&aa, line, TRUE);
|
2005-01-26 18:19:39 +00:00
|
|
|
|
2005-05-18 14:50:35 +00:00
|
|
|
MainParseArgs(aa.argc, aa.argv);
|
|
|
|
ArgArray_Done(&aa);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 15:04:14 +00:00
|
|
|
static char *
|
2005-02-04 07:51:00 +00:00
|
|
|
chdir_verify_path(const 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);
|
2005-02-04 07:51:00 +00:00
|
|
|
return (NULL);
|
1996-09-18 06:06:39 +00:00
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
return (obpath);
|
1996-09-18 06:06:39 +00:00
|
|
|
}
|
|
|
|
|
2005-02-04 07:51:00 +00:00
|
|
|
return (NULL);
|
1996-09-18 06:06:39 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 14:43:32 +00:00
|
|
|
/**
|
|
|
|
* In lieu of a good way to prevent every possible looping in make(1), stop
|
|
|
|
* there from being more than MKLVL_MAXVAL processes forked by make(1), to
|
|
|
|
* prevent a forkbomb from happening, in a dumb and mechanical way.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Creates or modifies enviornment variable MKLVL_ENVVAR via setenv().
|
2004-11-24 22:03:45 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
check_make_level(void)
|
|
|
|
{
|
|
|
|
#ifdef WANT_ENV_MKLVL
|
|
|
|
char *value = getenv(MKLVL_ENVVAR);
|
|
|
|
int level = (value == NULL) ? 0 : atoi(value);
|
|
|
|
|
|
|
|
if (level < 0) {
|
2005-04-01 12:42:03 +00:00
|
|
|
errc(2, EAGAIN, "Invalid value for recursion level (%d).",
|
|
|
|
level);
|
2004-11-24 22:03:45 +00:00
|
|
|
} else if (level > MKLVL_MAXVAL) {
|
2005-04-01 12:42:03 +00:00
|
|
|
errc(2, EAGAIN, "Max recursion level (%d) exceeded.",
|
|
|
|
MKLVL_MAXVAL);
|
2004-11-24 22:03:45 +00:00
|
|
|
} else {
|
|
|
|
char new_value[32];
|
|
|
|
sprintf(new_value, "%d", level + 1);
|
|
|
|
setenv(MKLVL_ENVVAR, new_value, 1);
|
|
|
|
}
|
|
|
|
#endif /* WANT_ENV_MKLVL */
|
|
|
|
}
|
|
|
|
|
2005-04-01 12:42:03 +00:00
|
|
|
/**
|
|
|
|
* main
|
1994-05-27 12:33:43 +00:00
|
|
|
* 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
|
|
|
{
|
2006-07-17 19:16:12 +00:00
|
|
|
const char *machine;
|
2005-05-12 14:43:32 +00:00
|
|
|
const char *machine_arch;
|
|
|
|
const char *machine_cpu;
|
2006-07-17 19:16:12 +00:00
|
|
|
Boolean outOfDate = TRUE; /* FALSE if all targets up to date */
|
2005-05-24 16:05:51 +00:00
|
|
|
const char *p;
|
2005-05-12 15:54:52 +00:00
|
|
|
const char *pathp;
|
|
|
|
const char *path;
|
2001-03-01 06:03:17 +00:00
|
|
|
char mdpath[MAXPATHLEN];
|
|
|
|
char obpath[MAXPATHLEN];
|
|
|
|
char cdpath[MAXPATHLEN];
|
1996-10-06 02:35:38 +00:00
|
|
|
char *cp = NULL, *start;
|
2005-02-04 07:51:00 +00:00
|
|
|
|
2005-05-12 15:04:14 +00:00
|
|
|
/*
|
|
|
|
* Initialize file global variables.
|
|
|
|
*/
|
|
|
|
expandVars = TRUE;
|
|
|
|
noBuiltins = FALSE; /* Read the built-in rules */
|
2006-07-17 19:16:12 +00:00
|
|
|
forceJobs = FALSE; /* No -j flag */
|
2005-05-12 15:04:14 +00:00
|
|
|
curdir = cdpath;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize program global variables.
|
|
|
|
*/
|
|
|
|
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 */
|
|
|
|
touchFlag = FALSE; /* Actually update targets */
|
|
|
|
usePipes = TRUE; /* Catch child output in pipes */
|
|
|
|
debug = 0; /* No debug verbosity, please. */
|
|
|
|
jobsRunning = FALSE;
|
|
|
|
|
|
|
|
jobLimit = DEFMAXJOBS;
|
|
|
|
compatMake = FALSE; /* No compat mode */
|
|
|
|
|
2004-11-24 22:03:45 +00:00
|
|
|
check_make_level();
|
2002-10-03 04:32:47 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
#ifdef RLIMIT_NOFILE
|
|
|
|
/*
|
|
|
|
* get rid of resource limit on file descriptors
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct rlimit rl;
|
2005-05-12 14:43:32 +00:00
|
|
|
if (getrlimit(RLIMIT_NOFILE, &rl) == -1) {
|
|
|
|
err(2, "getrlimit");
|
|
|
|
}
|
|
|
|
rl.rlim_cur = rl.rlim_max;
|
|
|
|
if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
|
|
|
|
err(2, "setrlimit");
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1998-09-09 14:58:30 +00:00
|
|
|
/*
|
2005-12-05 14:22:12 +00:00
|
|
|
* FreeBSD/pc98 kernel used to set the utsname.machine to
|
|
|
|
* "i386", and MACHINE was defined as "i386", so it could
|
|
|
|
* not be distinguished from FreeBSD/i386. Therefore, we
|
|
|
|
* had to check machine.ispc98 and adjust the MACHINE
|
|
|
|
* variable.
|
|
|
|
* NOTE: The code is still here to be able to compile new
|
|
|
|
* make binary on old FreeBSD/pc98 systems, and have the
|
|
|
|
* MACHINE variable set properly.
|
1998-09-09 14:58:30 +00:00
|
|
|
*/
|
2005-05-12 15:54:52 +00:00
|
|
|
if ((machine = getenv("MACHINE")) == NULL) {
|
1998-09-09 14:58:30 +00:00
|
|
|
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, ...)
|
|
|
|
*
|
2005-12-05 14:22:12 +00:00
|
|
|
* Note that both MACHINE and MACHINE_ARCH are decided at
|
|
|
|
* run-time.
|
1995-01-23 21:03:17 +00:00
|
|
|
*/
|
2005-05-12 15:54:52 +00:00
|
|
|
if (machine == NULL) {
|
2005-04-01 12:42:03 +00:00
|
|
|
static struct utsname utsname;
|
1996-10-06 02:35:38 +00:00
|
|
|
|
2005-04-01 12:42:03 +00:00
|
|
|
if (uname(&utsname) == -1)
|
|
|
|
err(2, "uname");
|
|
|
|
machine = utsname.machine;
|
1995-01-23 21:03:17 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2005-05-12 14:43:32 +00:00
|
|
|
if ((machine_arch = getenv("MACHINE_ARCH")) == NULL) {
|
|
|
|
#ifdef MACHINE_ARCH
|
1999-03-01 06:01:05 +00:00
|
|
|
machine_arch = MACHINE_ARCH;
|
2005-05-12 14:43:32 +00:00
|
|
|
#else
|
|
|
|
machine_arch = "unknown";
|
1999-03-01 06:01:05 +00:00
|
|
|
#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.
|
|
|
|
*/
|
2005-05-12 14:43:32 +00:00
|
|
|
if ((machine_cpu = getenv("MACHINE_CPU")) == NULL) {
|
2001-02-19 03:59:05 +00:00
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the parsing, directory and variable modules to prepare
|
|
|
|
* for the reading of inclusion paths and variable settings on the
|
|
|
|
* command line
|
|
|
|
*/
|
2005-05-12 14:43:32 +00:00
|
|
|
Proc_Init();
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
Dir_Init(); /* Initialize directory structures so -I flags
|
|
|
|
* can be processed correctly */
|
2005-05-06 18:30:06 +00:00
|
|
|
Var_Init(environ); /* As well as the lists of variables for
|
1994-05-27 12:33:43 +00:00
|
|
|
* parsing arguments */
|
2005-05-24 09:14:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the Shell so that we have a shell for != assignments
|
|
|
|
* on the command line.
|
|
|
|
*/
|
|
|
|
Shell_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.
|
|
|
|
*/
|
2005-05-12 14:47:22 +00:00
|
|
|
Var_SetGlobal("MAKE", argv[0]);
|
2005-05-12 15:04:14 +00:00
|
|
|
Var_SetGlobal(".MAKEFLAGS", "");
|
2005-05-12 14:47:22 +00:00
|
|
|
Var_SetGlobal("MFLAGS", "");
|
|
|
|
Var_SetGlobal("MACHINE", machine);
|
|
|
|
Var_SetGlobal("MACHINE_ARCH", machine_arch);
|
|
|
|
Var_SetGlobal("MACHINE_CPU", machine_cpu);
|
2002-05-22 14:35:47 +00:00
|
|
|
#ifdef MAKE_VERSION
|
2005-05-12 14:47:22 +00:00
|
|
|
Var_SetGlobal("MAKE_VERSION", MAKE_VERSION);
|
2002-05-22 14:35:47 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
2005-04-11 07:32:49 +00:00
|
|
|
* First snag things out of the MAKEFLAGS environment
|
|
|
|
* variable. Then parse the command line arguments.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2005-01-26 18:19:39 +00:00
|
|
|
Main_ParseArgLine(getenv("MAKEFLAGS"), 1);
|
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...
|
|
|
|
*/
|
|
|
|
if (getcwd(curdir, MAXPATHLEN) == NULL)
|
|
|
|
err(2, NULL);
|
|
|
|
|
2005-02-04 07:51:00 +00:00
|
|
|
{
|
|
|
|
struct stat sa;
|
|
|
|
|
2003-09-14 12:31:33 +00:00
|
|
|
if (stat(curdir, &sa) == -1)
|
|
|
|
err(2, "%s", curdir);
|
2005-02-04 07:51:00 +00:00
|
|
|
}
|
2003-09-14 12:31:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The object directory location is determined using the
|
|
|
|
* following order of preference:
|
|
|
|
*
|
|
|
|
* 1. MAKEOBJDIRPREFIX`cwd`
|
|
|
|
* 2. MAKEOBJDIR
|
2005-03-11 13:02:38 +00:00
|
|
|
* 3. PATH_OBJDIR.${MACHINE}
|
|
|
|
* 4. PATH_OBJDIR
|
|
|
|
* 5. PATH_OBJDIRPREFIX`cwd`
|
2003-09-14 12:31:33 +00:00
|
|
|
*
|
|
|
|
* 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"))) {
|
2005-03-11 13:02:38 +00:00
|
|
|
path = PATH_OBJDIR;
|
|
|
|
pathp = PATH_OBJDIRPREFIX;
|
2005-05-12 14:47:22 +00:00
|
|
|
snprintf(mdpath, MAXPATHLEN, "%s.%s", path, machine);
|
2003-09-14 12:31:33 +00:00
|
|
|
if (!(objdir = chdir_verify_path(mdpath, obpath)))
|
|
|
|
if (!(objdir=chdir_verify_path(path, obpath))) {
|
2004-11-30 17:46:29 +00:00
|
|
|
snprintf(mdpath, MAXPATHLEN,
|
2003-09-14 12:31:33 +00:00
|
|
|
"%s%s", pathp, curdir);
|
|
|
|
if (!(objdir=chdir_verify_path(mdpath,
|
|
|
|
obpath)))
|
|
|
|
objdir = curdir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!(objdir = chdir_verify_path(path, obpath)))
|
|
|
|
objdir = curdir;
|
|
|
|
}
|
|
|
|
else {
|
2004-11-30 17:46:29 +00:00
|
|
|
snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir);
|
2003-09-14 12:31:33 +00:00
|
|
|
if (!(objdir = chdir_verify_path(mdpath, obpath)))
|
|
|
|
objdir = curdir;
|
|
|
|
}
|
|
|
|
Dir_InitDot(); /* Initialize the "." directory */
|
|
|
|
if (objdir != curdir)
|
2005-03-23 12:56:15 +00:00
|
|
|
Path_AddDir(&dirSearchPath, curdir);
|
2005-05-12 14:47:22 +00:00
|
|
|
Var_SetGlobal(".ST_EXPORTVAR", "YES");
|
|
|
|
Var_SetGlobal(".CURDIR", curdir);
|
|
|
|
Var_SetGlobal(".OBJDIR", objdir);
|
2003-09-14 12:31:33 +00:00
|
|
|
|
2004-11-12 08:58:07 +00:00
|
|
|
if (getenv("MAKE_JOBS_FIFO") != NULL)
|
|
|
|
forceJobs = TRUE;
|
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
|
|
|
/*
|
2005-03-31 11:35:56 +00:00
|
|
|
* Initialize target and suffix modules in preparation for
|
1994-05-27 12:33:43 +00:00
|
|
|
* parsing the makefile(s)
|
|
|
|
*/
|
|
|
|
Targ_Init();
|
|
|
|
Suff_Init();
|
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
DEFAULT = NULL;
|
2004-11-30 17:46:29 +00:00
|
|
|
time(&now);
|
1994-05-27 12:33:43 +00: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.
|
|
|
|
*/
|
2005-05-12 14:47:22 +00:00
|
|
|
if (Lst_IsEmpty(&create)) {
|
|
|
|
Var_SetGlobal(".TARGETS", "");
|
|
|
|
} else {
|
2004-12-07 13:49:13 +00:00
|
|
|
LstNode *ln;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
for (ln = Lst_First(&create); ln != NULL; ln = Lst_Succ(ln)) {
|
2004-12-01 10:29:20 +00:00
|
|
|
char *name = Lst_Datum(ln);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
Var_Append(".TARGETS", name, VAR_GLOBAL);
|
|
|
|
}
|
2005-05-12 14:47:22 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
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
|
|
|
*/
|
2005-03-23 12:56:15 +00:00
|
|
|
if (TAILQ_EMPTY(&sysIncPath)) {
|
2005-05-12 14:43:32 +00:00
|
|
|
char syspath[] = PATH_DEFSYSPATH;
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
for (start = syspath; *start != '\0'; start = cp) {
|
|
|
|
for (cp = start; *cp != '\0' && *cp != ':'; cp++)
|
|
|
|
continue;
|
|
|
|
if (*cp == '\0') {
|
2005-03-23 12:56:15 +00:00
|
|
|
Path_AddDir(&sysIncPath, start);
|
1996-10-06 02:35:38 +00:00
|
|
|
} else {
|
|
|
|
*cp++ = '\0';
|
2005-03-23 12:56:15 +00:00
|
|
|
Path_AddDir(&sysIncPath, start);
|
1996-10-06 02:35:38 +00: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) {
|
2004-12-16 16:14:16 +00:00
|
|
|
/* Path of sys.mk */
|
|
|
|
Lst sysMkPath = Lst_Initializer(sysMkPath);
|
2004-12-07 13:49:13 +00:00
|
|
|
LstNode *ln;
|
2005-05-10 14:23:31 +00:00
|
|
|
char defsysmk[] = PATH_DEFSYSMK;
|
1996-10-06 02:35:38 +00:00
|
|
|
|
2005-05-10 14:23:31 +00:00
|
|
|
Path_Expand(defsysmk, &sysIncPath, &sysMkPath);
|
2004-12-16 16:14:16 +00:00
|
|
|
if (Lst_IsEmpty(&sysMkPath))
|
2005-03-11 13:02:38 +00:00
|
|
|
Fatal("make: no system rules (%s).", PATH_DEFSYSMK);
|
2005-03-18 15:23:49 +00:00
|
|
|
LST_FOREACH(ln, &sysMkPath) {
|
|
|
|
if (!ReadMakefile(Lst_Datum(ln)))
|
|
|
|
break;
|
|
|
|
}
|
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));
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_Destroy(&sysMkPath, free);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
if (!Lst_IsEmpty(&makefiles)) {
|
2004-12-07 13:49:13 +00:00
|
|
|
LstNode *ln;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2005-03-18 15:23:49 +00:00
|
|
|
LST_FOREACH(ln, &makefiles) {
|
|
|
|
if (!ReadMakefile(Lst_Datum(ln)))
|
|
|
|
break;
|
|
|
|
}
|
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));
|
2005-03-18 15:23:49 +00:00
|
|
|
} else if (!ReadMakefile("BSDmakefile"))
|
|
|
|
if (!ReadMakefile("makefile"))
|
|
|
|
ReadMakefile("Makefile");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2005-03-18 15:23:49 +00:00
|
|
|
ReadMakefile(".depend");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/* Install all the flags into the MAKE envariable. */
|
2005-05-24 15:58:35 +00:00
|
|
|
if (((p = Var_Value(".MAKEFLAGS", VAR_GLOBAL)) != NULL) && *p)
|
1994-05-27 12:33:43 +00:00
|
|
|
setenv("MAKEFLAGS", p, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)) {
|
|
|
|
/*
|
|
|
|
* 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}";
|
2005-02-25 13:16:56 +00:00
|
|
|
Buffer *buf;
|
|
|
|
char *vpath;
|
|
|
|
char *ptr;
|
|
|
|
char savec;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2005-05-09 14:06:04 +00:00
|
|
|
buf = Var_Subst(VPATH, VAR_CMD, FALSE);
|
2005-02-25 13:16:56 +00:00
|
|
|
|
2005-03-22 07:50:40 +00:00
|
|
|
vpath = Buf_Data(buf);
|
1994-05-27 12:33:43 +00:00
|
|
|
do {
|
|
|
|
/* skip to end of directory */
|
2005-02-25 13:16:56 +00:00
|
|
|
for (ptr = vpath; *ptr != ':' && *ptr != '\0'; ptr++)
|
2005-02-16 12:39:32 +00:00
|
|
|
;
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/* Save terminator character so know when to stop */
|
2005-02-16 12:39:32 +00:00
|
|
|
savec = *ptr;
|
|
|
|
*ptr = '\0';
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/* Add directory to search path */
|
2005-03-23 12:56:15 +00:00
|
|
|
Path_AddDir(&dirSearchPath, vpath);
|
2005-02-16 12:39:32 +00:00
|
|
|
|
2005-02-25 13:16:56 +00:00
|
|
|
vpath = ptr + 1;
|
2005-02-16 12:39:32 +00:00
|
|
|
} while (savec != '\0');
|
2005-02-25 13:16:56 +00:00
|
|
|
|
|
|
|
Buf_Destroy(buf, TRUE);
|
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 */
|
2005-02-16 17:20:09 +00:00
|
|
|
if (Lst_IsEmpty(&variables)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
2005-02-16 17:20:09 +00:00
|
|
|
* Since the user has not requested that any variables
|
2005-02-17 09:09:34 +00:00
|
|
|
* be printed, we can build targets.
|
2005-02-16 17:20:09 +00:00
|
|
|
*
|
2005-02-17 09:09:34 +00:00
|
|
|
* Have read the entire graph and need to make a list of targets
|
2005-02-16 17:20:09 +00:00
|
|
|
* 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
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst targs = Lst_Initializer(targs);
|
|
|
|
|
|
|
|
if (Lst_IsEmpty(&create))
|
|
|
|
Parse_MainName(&targs);
|
2002-08-07 13:25:51 +00:00
|
|
|
else
|
2004-12-16 16:14:16 +00:00
|
|
|
Targ_FindList(&targs, &create, TARG_CREATE);
|
2002-08-07 13:25:51 +00:00
|
|
|
|
2005-02-16 17:20:09 +00:00
|
|
|
if (compatMake) {
|
|
|
|
/*
|
|
|
|
* Compat_Init will take care of creating
|
|
|
|
* all the targets as well as initializing
|
|
|
|
* the module.
|
|
|
|
*/
|
|
|
|
Compat_Run(&targs);
|
|
|
|
outOfDate = 0;
|
|
|
|
} else {
|
2002-08-07 13:25:51 +00:00
|
|
|
/*
|
2005-02-16 17:20:09 +00: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).
|
2002-08-07 13:25:51 +00:00
|
|
|
*/
|
|
|
|
if (!queryFlag) {
|
2005-05-12 14:16:44 +00:00
|
|
|
Job_Init(jobLimit);
|
2002-08-07 13:25:51 +00:00
|
|
|
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 */
|
2004-12-16 16:14:16 +00:00
|
|
|
outOfDate = Make_Run(&targs);
|
2002-08-07 13:25:51 +00:00
|
|
|
}
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_Destroy(&targs, NOFREE);
|
2005-02-16 17:20:09 +00:00
|
|
|
|
|
|
|
} else {
|
2005-05-12 14:31:42 +00:00
|
|
|
Var_Print(&variables, expandVars);
|
1996-07-17 11:02:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-12-16 19:46:50 +00:00
|
|
|
Lst_Destroy(&variables, free);
|
|
|
|
Lst_Destroy(&makefiles, free);
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_Destroy(&create, 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);
|
|
|
|
|
|
|
|
if (queryFlag && outOfDate)
|
2004-11-30 17:46:29 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
2004-11-30 17:46:29 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|