home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bsd
/
src
/
make
/
make-amiga
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-23
|
20KB
|
793 lines
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* Copyright (c) 1988, 1989 by Adam de Boor
* 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.
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)main.c 5.25 (Berkeley) 4/1/91";
#endif /* not lint */
/*-
* 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
* errors which occured, as passed to it, and
* exiting.
*/
#include <sys/param.h>
#include <sys/signal.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <varargs.h>
#include "make.h"
#include "pathnames.h"
#ifndef DEFMAXLOCAL
#define DEFMAXLOCAL DEFMAXJOBS
#endif DEFMAXLOCAL
#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 */
int maxJobs; /* -J argument */
static int maxLocal; /* -L 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 */
Boolean oldVars; /* variable substitution style */
Boolean checkEnvFirst; /* -e flag */
static Boolean jobsRunning; /* TRUE if the jobs might be running */
static Boolean ReadMakefile();
static char *curdir; /* if chdir'd for an architecture */
/*-
* 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;
{
extern int optind;
extern char *optarg;
register int i;
register char *cp;
char c;
optind = 1; /* since we're called more than once */
rearg: while((c = getopt(argc, argv, "D:I:d:ef:ij:knqrst")) != EOF) {
switch(c) {
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;
#ifdef notdef
case 'L':
maxLocal = atoi(optarg);
Var_Append(MAKEFLAGS, "-L", VAR_GLOBAL);
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
break;
case 'P':
usePipes = FALSE;
Var_Append(MAKEFLAGS, "-P", VAR_GLOBAL);
break;
case 'S':
keepgoing = FALSE;
Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL);
break;
#endif
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 '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;
default:
(void)fprintf(stderr,
"make: illegal argument to d option -- %c\n",
*modules);
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':
maxJobs = atoi(optarg);
Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL);
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
break;
case 'k':
keepgoing = TRUE;
Var_Append(MAKEFLAGS, "-k", VAR_GLOBAL);
break;
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)
if (Parse_IsVar(*argv))
Parse_DoVar(*argv, VAR_CMD);
else {
if (!**argv)
Punt("illegal (null) argument.");
if (**argv == '-') {
optind = 0;
goto rearg;
}
(void)Lst_AtEnd(create, (ClientData)*argv);
}
}
/*-
* Main_ParseArgLine --
* Used by the parse module when a .MFLAGS or .MAKEFLAGS target
* is encountered and by main() when reading the .MAKEFLAGS envariable.
* Take